2019-05-09 18:54:39 +12:00
#!/bin/env php
< ? php
2019-09-07 05:08:14 +12:00
require_once __DIR__ . '/../../vendor/autoload.php' ;
2020-02-10 18:54:26 +13:00
require_once __DIR__ . '/../../app/init.php' ;
2019-05-09 18:54:39 +12:00
2020-03-29 01:42:16 +13:00
use Utopia\Config\Config ;
2019-05-09 18:54:39 +12:00
use Utopia\CLI\CLI ;
use Utopia\CLI\Console ;
2019-05-24 17:27:16 +12:00
use Appwrite\Spec\Swagger2 ;
use Appwrite\SDK\SDK ;
use Appwrite\SDK\Language\PHP ;
use Appwrite\SDK\Language\JS ;
2019-06-04 09:41:34 +12:00
use Appwrite\SDK\Language\Node ;
2019-05-24 17:27:16 +12:00
use Appwrite\SDK\Language\Python ;
use Appwrite\SDK\Language\Ruby ;
2019-09-20 18:33:11 +12:00
use Appwrite\SDK\Language\Dart ;
2019-10-14 09:19:06 +13:00
use Appwrite\SDK\Language\Go ;
2020-03-28 06:07:10 +13:00
use Appwrite\SDK\Language\Typescript ;
2019-05-09 18:54:39 +12:00
$cli = new CLI ();
2020-02-10 18:54:26 +13:00
$version = APP_VERSION_STABLE ; // Server version
2019-10-04 18:14:22 +13:00
$warning = '**This SDK is compatible with Appwrite server version ' . $version . '. For older versions, please check previous releases.**' ;
2019-10-02 07:03:52 +13:00
2019-05-09 18:54:39 +12:00
$cli
-> task ( 'generate' )
2020-04-06 02:49:28 +12:00
-> action ( function () use ( $warning , $version ) {
2019-09-07 05:08:14 +12:00
function getSSLPage ( $url )
{
2019-05-09 18:54:39 +12:00
$ch = curl_init ();
curl_setopt ( $ch , CURLOPT_HEADER , false );
curl_setopt ( $ch , CURLOPT_URL , $url );
curl_setopt ( $ch , CURLOPT_SSL_VERIFYPEER , false );
curl_setopt ( $ch , CURLOPT_SSL_VERIFYHOST , false );
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , true );
$result = curl_exec ( $ch );
curl_close ( $ch );
2019-09-07 05:08:14 +12:00
2019-05-09 18:54:39 +12:00
return $result ;
}
2020-03-29 01:42:16 +13:00
$platforms = Config :: getParam ( 'platforms' );
2020-01-28 10:50:41 +13:00
$message = Console :: confirm ( 'Please enter your commit message:' );
2020-03-27 02:20:07 +13:00
$production = ( Console :: confirm ( 'Type "Appwrite" to deploy for production' ) == 'Appwrite' );
2020-01-28 10:50:41 +13:00
2020-02-24 07:09:34 +13:00
foreach ( $platforms as $key => $platform ) {
2020-01-28 10:50:41 +13:00
foreach ( $platform [ 'languages' ] as $language ) {
if ( ! $language [ 'enabled' ]) {
Console :: warning ( $language [ 'name' ] . ' for ' . $platform [ 'name' ] . ' is disabled' );
continue ;
}
Console :: info ( 'Fetching API Spec for ' . $language [ 'name' ] . ' for ' . $platform [ 'name' ]);
2020-01-29 02:16:33 +13:00
2020-03-20 04:03:30 +13:00
//$spec = getSSLPage('http://localhost/v1/open-api-2.json?extensions=1&platform='.$language['family']);
2020-03-27 02:20:07 +13:00
$spec = getSSLPage ( 'https://appwrite.io/v1/open-api-2.json?extensions=1&platform=' . $language [ 'family' ]);
2020-04-12 00:31:03 +12:00
$spec = getSSLPage ( 'https://localhost:2444/v1/open-api-2.json?extensions=1&platform=' . $language [ 'family' ]);
2020-01-28 10:50:41 +13:00
2020-02-24 07:09:34 +13:00
$result = realpath ( __DIR__ . '/..' ) . '/sdks/' . $key . '-' . $language [ 'key' ];
2020-01-28 12:07:03 +13:00
$target = realpath ( __DIR__ . '/..' ) . '/sdks/git/' . $language [ 'key' ] . '/' ;
2020-04-06 08:39:45 +12:00
$readme = realpath ( __DIR__ . '/../../docs/sdks/' . $language [ 'key' ] . '/README.md' );
2020-01-28 10:50:41 +13:00
$readme = ( $readme ) ? file_get_contents ( $readme ) : '' ;
2020-04-12 18:15:33 +12:00
$examples = realpath ( __DIR__ . '/../../docs/sdks/' . $language [ 'key' ] . '/EXAMPLES.md' );
$examples = ( $examples ) ? file_get_contents ( $examples ) : '' ;
2020-04-06 08:39:45 +12:00
$changelog = realpath ( __DIR__ . '/../../docs/sdks/' . $language [ 'key' ] . '/CHANGELOG.md' );
$changelog = ( $changelog ) ? file_get_contents ( $changelog ) : '# Change Log' ;
2020-01-28 10:50:41 +13:00
$warning = ( $language [ 'beta' ]) ? '**This SDK is compatible with Appwrite server version ' . $version . '. For older versions, please check previous releases.**' : '' ;
$license = 'BSD-3-Clause' ;
$licenseContent = ' Copyright ( c ) 2019 Appwrite ( https :// appwrite . io ) and individual contributors .
2019-11-21 07:49:35 +13:00
All rights reserved .
Redistribution and use in source and binary forms , with or without modification , are permitted provided that the following conditions are met :
1. Redistributions of source code must retain the above copyright notice , this list of conditions and the following disclaimer .
2. Redistributions in binary form must reproduce the above copyright notice , this list of conditions and the following disclaimer in the documentation and / or other materials provided with the distribution .
3. Neither the name Appwrite nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission .
2020-01-28 10:50:41 +13:00
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS " AS IS " AND ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE . ' ;
switch ( $language [ 'key' ]) {
case 'php' :
$config = new PHP ();
$config
-> setComposerVendor ( 'appwrite' )
-> setComposerPackage ( 'appwrite' )
;
break ;
case 'javascript' :
$config = new JS ();
$config
-> setNPMPackage ( 'appwrite' )
-> setBowerPackage ( 'appwrite' )
;
break ;
2020-03-28 06:07:10 +13:00
case 'typescript' :
$config = new Typescript ();
$config
-> setNPMPackage ( 'appwrite' )
-> setBowerPackage ( 'appwrite' )
;
break ;
2020-01-28 10:50:41 +13:00
case 'nodejs' :
$config = new Node ();
$config
-> setNPMPackage ( 'node-appwrite' )
-> setBowerPackage ( 'appwrite' )
;
break ;
case 'python' :
$config = new Python ();
$config
-> setPipPackage ( 'appwrite' )
;
$license = 'BSD License' ; // license edited due to classifiers in pypi
break ;
case 'ruby' :
$config = new Ruby ();
$config
-> setGemPackage ( 'appwrite' )
;
break ;
case 'dart' :
$config = new Dart ();
break ;
case 'go' :
$config = new Go ();
break ;
default :
throw new Exception ( 'Language "' . $language [ 'key' ] . '" not supported' );
break ;
}
Console :: info ( " Generating { $language [ 'name' ] } SDK... " );
$sdk = new SDK ( $config , new Swagger2 ( $spec ));
$sdk
2020-04-06 16:55:38 +12:00
-> setDescription ( " Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way.
Use the { $language [ 'name' ]} SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools .
For full API documentation and tutorials go to [ https :// appwrite . io / docs ]( https :// appwrite . io / docs ) " )
2020-04-13 22:50:47 +12:00
-> setShortDescription ( 'Appwrite is an open-source self-hosted backend as a service that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API' )
2020-01-28 10:50:41 +13:00
-> setLicense ( $license )
-> setLicenseContent ( $licenseContent )
-> setVersion ( $language [ 'version' ])
-> setGitURL ( $language [ 'url' ])
-> setGitRepo ( $language [ 'gitUrl' ])
-> setGitRepoName ( $language [ 'gitRepoName' ])
-> setGitUserName ( $language [ 'gitUserName' ])
-> setLogo ( 'https://appwrite.io/images/github.png' )
-> setURL ( 'https://appwrite.io' )
-> setShareText ( 'Appwrite is a backend as a service for building web or mobile apps' )
-> setShareURL ( 'http://appwrite.io' )
-> setShareTags ( 'JS,javascript,reactjs,angular,ios,android,serverless' )
-> setShareVia ( 'appwrite_io' )
-> setWarning ( $warning )
-> setReadme ( $readme )
2020-04-06 08:39:45 +12:00
-> setChangelog ( $changelog )
2020-04-12 18:15:33 +12:00
-> setExamples ( $examples )
2020-01-28 10:50:41 +13:00
;
try {
$sdk -> generate ( $result );
} catch ( Exception $exception ) {
Console :: error ( $exception -> getMessage ());
} catch ( Throwable $exception ) {
Console :: error ( $exception -> getMessage ());
}
2020-01-28 12:07:03 +13:00
$gitUrl = $language [ 'gitUrl' ];
2020-02-24 19:43:21 +13:00
if ( empty ( $gitUrl )) {
continue ;
}
2020-03-27 02:20:07 +13:00
if ( ! $production ) {
$gitUrl = 'git@github.com:aw-tests/' . $language [ 'gitRepoName' ] . '.git' ;
}
2020-01-28 12:07:03 +13:00
exec ( 'rm -rf ' . $target . ' && \
2020-01-28 10:50:41 +13:00
mkdir - p '.$target.' && \
cd '.$target.' && \
git init && \
2020-01-28 12:07:03 +13:00
git remote add origin '.$gitUrl.' && \
2020-01-28 10:50:41 +13:00
git fetch && \
2020-01-28 12:07:03 +13:00
git pull '.$gitUrl.' && \
2020-01-28 10:50:41 +13:00
rm - rf '.$target.' /* && \
2020-01-28 12:07:03 +13:00
cp - r '.$result.' / '.$target.' / && \
2020-01-28 10:50:41 +13:00
git add . && \
git commit - m " '. $message .' " && \
git push - u origin master ' );
2020-01-28 12:07:03 +13:00
Console :: success ( " Pushed { $language [ 'name' ] } SDK to { $gitUrl } " );
exec ( 'rm -rf ' . $target );
2020-01-28 10:50:41 +13:00
2020-01-28 12:07:03 +13:00
Console :: success ( " Remove temp directory ' { $target } ' for { $language [ 'name' ] } SDK " );
2019-05-09 18:54:39 +12:00
}
}
2020-01-28 12:07:03 +13:00
exit ();
2019-05-09 18:54:39 +12:00
});
2019-09-30 19:13:40 +13:00
$cli -> run ();