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' ;
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-05-09 18:54:39 +12:00
$cli = new CLI ();
2019-10-02 07:03:52 +13:00
$version = '0.2.0' ; // 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' )
2019-10-04 11:05:12 +13:00
-> action ( function () use ( $warning ) {
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 ;
}
$clients = [
'php' => [
2019-10-02 07:05:28 +13:00
'version' => '1.0.9' ,
2019-09-07 05:08:14 +12:00
'result' => __DIR__ . '/../sdks/php/' ,
'gitURL' => 'https://github.com/appwrite/sdk-for-php.git' ,
'gitRepo' => 'git@github.com:appwrite/sdk-for-php.git' ,
'gitRepoName' => 'sdk-for-php' ,
'gitUserName' => 'appwrite' ,
2019-10-04 11:05:12 +13:00
'warning' => $warning ,
2019-10-10 07:55:28 +13:00
'readme' => false ,
2019-09-21 06:44:32 +12:00
'platform' => 'server' ,
2019-05-09 18:54:39 +12:00
],
'js' => [
2019-10-09 21:40:02 +13:00
'version' => '1.0.23' ,
2019-09-07 05:08:14 +12:00
'result' => __DIR__ . '/../sdks/js/' ,
'gitURL' => 'https://github.com/appwrite/sdk-for-js.git' ,
'gitRepo' => 'git@github.com:appwrite/sdk-for-js.git' ,
'gitRepoName' => 'sdk-for-js' ,
'gitUserName' => 'appwrite' ,
2019-10-04 11:05:12 +13:00
'warning' => $warning ,
2019-10-10 07:55:28 +13:00
'readme' => realpath ( __DIR__ . '/../../docs/sdks/js.md' ),
2019-09-21 06:44:32 +12:00
'platform' => 'client' ,
2019-05-09 18:54:39 +12:00
],
2019-06-04 09:41:34 +12:00
'node' => [
2019-10-02 07:05:28 +13:00
'version' => '1.0.26' ,
2019-09-07 05:08:14 +12:00
'result' => __DIR__ . '/../sdks/node/' ,
'gitURL' => 'https://github.com/appwrite/sdk-for-node.git' ,
'gitRepo' => 'git@github.com:appwrite/sdk-for-node.git' ,
'gitRepoName' => 'sdk-for-node' ,
'gitUserName' => 'appwrite' ,
2019-10-04 11:05:12 +13:00
'warning' => $warning ,
2019-10-10 07:55:28 +13:00
'readme' => false ,
2019-09-21 06:44:32 +12:00
'platform' => 'server' ,
2019-06-04 09:41:34 +12:00
],
2019-05-24 17:27:16 +12:00
'python' => [
2019-09-21 21:36:44 +12:00
'version' => '1.0.0' ,
2019-09-07 05:08:14 +12:00
'result' => __DIR__ . '/../sdks/python/' ,
'gitURL' => 'https://github.com/appwrite/sdk-for-python.git' ,
'gitRepo' => 'git@github.com:appwrite/sdk-for-python.git' ,
'gitRepoName' => 'sdk-for-python' ,
'gitUserName' => 'appwrite' ,
'warning' => '**WORK IN PROGRESS - NOT READY FOR USAGE - Want to help us improve this client SDK? Send a pull request to Appwrite [SDK generator repository](https://github.com/appwrite/sdk-generator).**' ,
2019-10-10 07:55:28 +13:00
'readme' => false ,
2019-09-21 06:44:32 +12:00
'platform' => 'server' ,
2019-05-24 17:27:16 +12:00
],
'ruby' => [
2019-09-21 21:36:44 +12:00
'version' => '1.0.1' ,
2019-09-07 05:08:14 +12:00
'result' => __DIR__ . '/../sdks/ruby/' ,
'gitURL' => 'https://github.com/appwrite/sdk-for-ruby.git' ,
'gitRepo' => 'git@github.com:appwrite/sdk-for-ruby.git' ,
'gitRepoName' => 'sdk-for-ruby' ,
'gitUserName' => 'appwrite' ,
'warning' => '**WORK IN PROGRESS - NOT READY FOR USAGE - Want to help us improve this client SDK? Send a pull request to Appwrite [SDK generator repository](https://github.com/appwrite/sdk-generator).**' ,
2019-10-10 07:55:28 +13:00
'readme' => false ,
2019-09-21 06:44:32 +12:00
'platform' => 'server' ,
2019-05-24 17:27:16 +12:00
],
2019-09-20 18:33:11 +12:00
'dart' => [
2019-09-21 21:36:44 +12:00
'version' => '0.0.2' ,
2019-09-20 18:33:11 +12:00
'result' => __DIR__ . '/../sdks/dart/' ,
'gitURL' => 'https://github.com/appwrite/sdk-for-dart' ,
'gitRepo' => 'git@github.com:appwrite/sdk-for-dart.git' ,
'gitRepoName' => 'sdk-for-dart' ,
'gitUserName' => 'appwrite' ,
'warning' => '**WORK IN PROGRESS - NOT READY FOR USAGE - Want to help us improve this client SDK? Send a pull request to Appwrite [SDK generator repository](https://github.com/appwrite/sdk-generator).**' ,
2019-10-10 07:55:28 +13:00
'readme' => false ,
2019-09-21 06:44:32 +12:00
'platform' => 'client' ,
2019-09-20 18:33:11 +12:00
],
2019-05-09 18:54:39 +12:00
];
foreach ( $clients as $name => $client ) {
2019-10-01 18:00:27 +13:00
Console :: info ( 'Fetching API Spec for ' . $name . ' (' . $client [ 'platform' ] . ')' );
$spec = getSSLPage ( 'https://appwrite.io/v1/open-api-2.json?extensions=1&platform=' . $client [ 'platform' ]);
$spec = getSSLPage ( 'https://appwrite.test/v1/open-api-2.json?extensions=1&platform=' . $client [ 'platform' ]);
2019-09-21 06:44:32 +12:00
2019-05-09 18:54:39 +12:00
switch ( $name ) {
case 'php' :
$language = new PHP ();
$language
-> setComposerVendor ( 'appwrite' )
-> setComposerPackage ( 'appwrite' )
;
2019-05-24 17:27:16 +12:00
break ;
2019-05-09 18:54:39 +12:00
case 'js' :
$language = new JS ();
$language
-> setNPMPackage ( 'appwrite' )
-> setBowerPackage ( 'appwrite' )
;
2019-05-24 17:27:16 +12:00
break ;
2019-06-04 09:41:34 +12:00
case 'node' :
$language = new Node ();
$language
-> setNPMPackage ( 'node-appwrite' )
-> setBowerPackage ( 'appwrite' )
;
break ;
2019-05-24 17:27:16 +12:00
case 'python' :
$language = new Python ();
$language
-> setPipPackage ( 'appwrite' )
;
break ;
case 'ruby' :
$language = new Ruby ();
$language
-> setGemPackage ( 'appwrite' )
;
break ;
2019-09-20 18:33:11 +12:00
case 'dart' :
$language = new Dart ();
$language
-> setPackageName ( 'appwrite' )
;
break ;
2019-05-09 18:54:39 +12:00
default :
throw new Exception ( 'Language not supported' );
2019-05-24 17:27:16 +12:00
break ;
2019-05-09 18:54:39 +12:00
}
$sdk = new SDK ( $language , new Swagger2 ( $spec ));
$sdk
2019-06-10 17:29:16 +12:00
-> setLicense ( 'BSD-3-Clause' )
2019-09-07 05:08:14 +12:00
-> setLicenseContent ( ' Copyright ( c ) 2019 Appwrite ( https :// appwrite . io ) and individual contributors .
2019-06-10 17:29:16 +12: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 .
2019-09-07 05:08:14 +12: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 . ' )
2019-05-09 18:54:39 +12:00
-> setVersion ( $client [ 'version' ])
-> setGitRepo ( $client [ 'gitRepo' ])
-> setGitURL ( $client [ 'gitURL' ])
-> setGitRepoName ( $client [ 'gitRepoName' ])
-> setGitUserName ( $client [ 'gitUserName' ])
2019-08-23 05:20:27 +12:00
-> setLogo ( 'https://appwrite.io/images/github.png' )
2019-05-09 18:54:39 +12:00
-> 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' )
-> setShareVia ( 'appwrite_io' )
2019-08-30 18:10:29 +12:00
-> setWarning ( $client [ 'warning' ])
2019-10-10 07:55:28 +13:00
-> setReadme (( $client [ 'readme' ] && file_exists ( $client [ 'readme' ])) ? file_get_contents ( $client [ 'readme' ]) : '' )
2019-05-09 18:54:39 +12:00
;
2019-09-07 05:08:14 +12:00
$target = __DIR__ . '/../sdks/git/' . $name ;
2019-05-09 18:54:39 +12:00
Console :: success ( " Generating { $name } SDK " );
try {
$sdk -> generate ( $client [ 'result' ]);
2019-09-07 05:08:14 +12:00
} catch ( Exception $exception ) {
echo $exception -> getMessage () . " \n " ;
} catch ( Throwable $exception ) {
echo $exception -> getMessage () . " \n " ;
2019-05-09 18:54:39 +12:00
}
2019-09-21 07:31:46 +12:00
exec ( 'rm -rf ' . $target . ' && \
mkdir - p '.$target.' && \
cd '.$target.' && \
git init && \
git remote add origin '.$client[' gitRepo '].' && \
git fetch && \
git pull '.$client[' gitRepo '].' && \
rm - rf '.$target.' /* && \
cp - r '.$client[' result '].' '.$target.' && \
git add . && \
git commit - m " Initial commit " && \
git push - u origin master ' );
2019-05-09 18:54:39 +12:00
Console :: success ( " Pushing { $name } SDK to { $client [ 'gitRepo' ] } " );
2019-09-07 05:08:14 +12:00
exec ( 'rm -rf ' . $target );
2019-05-09 18:54:39 +12:00
Console :: success ( " Remove temp directory ' { $target } ' for { $name } SDK " );
}
});
2019-09-30 19:13:40 +13:00
$cli -> run ();