2019-05-09 18:54:39 +12:00
< ? php
2022-10-28 10:06:09 +13:00
use Appwrite\SDK\Language\Android ;
2021-02-09 08:30:57 +13:00
use Appwrite\SDK\Language\CLI ;
2019-09-20 18:33:11 +12:00
use Appwrite\SDK\Language\Dart ;
2020-05-28 18:00:07 +12:00
use Appwrite\SDK\Language\Deno ;
2021-01-05 04:20:41 +13:00
use Appwrite\SDK\Language\DotNet ;
2020-07-10 19:11:42 +12:00
use Appwrite\SDK\Language\Flutter ;
2019-10-14 09:19:06 +13:00
use Appwrite\SDK\Language\Go ;
2022-10-28 10:06:09 +13:00
use Appwrite\SDK\Language\GraphQL ;
2021-06-10 00:45:38 +12:00
use Appwrite\SDK\Language\Kotlin ;
2022-10-28 10:06:09 +13:00
use Appwrite\SDK\Language\Node ;
use Appwrite\SDK\Language\PHP ;
use Appwrite\SDK\Language\Python ;
use Appwrite\SDK\Language\REST ;
use Appwrite\SDK\Language\Ruby ;
2020-08-31 04:23:15 +12:00
use Appwrite\SDK\Language\Swift ;
2022-12-19 19:05:35 +13:00
use Appwrite\SDK\Language\Apple ;
2022-10-28 10:06:09 +13:00
use Appwrite\SDK\Language\Web ;
use Appwrite\SDK\SDK ;
use Appwrite\Spec\Swagger2 ;
use Utopia\CLI\Console ;
use Utopia\Config\Config ;
2019-05-09 18:54:39 +12:00
$cli
2020-10-15 21:00:14 +13:00
-> task ( 'sdks' )
2020-09-09 00:31:35 +12:00
-> action ( function () {
2020-03-29 01:42:16 +13:00
$platforms = Config :: getParam ( 'platforms' );
2020-06-20 23:20:49 +12:00
$selected = \strtolower ( Console :: confirm ( 'Choose SDK ("*" for all):' ));
2020-09-09 00:31:35 +12:00
$version = Console :: confirm ( 'Choose an Appwrite version' );
2020-12-24 11:39:48 +13:00
$git = ( Console :: confirm ( 'Should we use git push? (yes/no)' ) == 'yes' );
$production = ( $git ) ? ( Console :: confirm ( 'Type "Appwrite" to push code to production git repos' ) == 'Appwrite' ) : false ;
$message = ( $git ) ? Console :: confirm ( 'Please enter your commit message:' ) : '' ;
2020-09-09 00:31:35 +12:00
2022-10-20 16:21:16 +13:00
if ( ! in_array ( $version , [ '0.6.x' , '0.7.x' , '0.8.x' , '0.9.x' , '0.10.x' , '0.11.x' , '0.12.x' , '0.13.x' , '0.14.x' , '0.15.x' , '1.0.x' , '1.1.x' , '1.2.x' , 'latest' ])) {
2020-09-09 00:31:35 +12:00
throw new Exception ( 'Unknown version given' );
}
2020-01-28 10:50:41 +13:00
2022-01-03 22:41:47 +13:00
foreach ( $platforms as $key => $platform ) {
foreach ( $platform [ 'languages' ] as $language ) {
if ( $selected !== $language [ 'key' ] && $selected !== '*' ) {
2020-05-17 23:51:57 +12:00
continue ;
}
2020-05-18 02:17:55 +12:00
2022-01-03 22:41:47 +13:00
if ( ! $language [ 'enabled' ]) {
Console :: warning ( $language [ 'name' ] . ' for ' . $platform [ 'name' ] . ' is disabled' );
2020-01-28 10:50:41 +13:00
continue ;
}
2022-01-03 22:41:47 +13:00
Console :: info ( 'Fetching API Spec for ' . $language [ 'name' ] . ' for ' . $platform [ 'name' ] . ' (version: ' . $version . ')' );
$spec = file_get_contents ( __DIR__ . '/../config/specs/swagger2-' . $version . '-' . $language [ 'family' ] . '.json' );
2020-01-28 10:50:41 +13:00
2021-01-05 06:45:35 +13:00
$cover = 'https://appwrite.io/images/github.png' ;
2022-01-03 22:41:47 +13:00
$result = \realpath ( __DIR__ . '/..' ) . '/sdks/' . $key . '-' . $language [ 'key' ];
$resultExamples = \realpath ( __DIR__ . '/../..' ) . '/docs/examples/' . $version . '/' . $key . '-' . $language [ 'key' ];
$target = \realpath ( __DIR__ . '/..' ) . '/sdks/git/' . $language [ 'key' ] . '/' ;
$readme = \realpath ( __DIR__ . '/../../docs/sdks/' . $language [ 'key' ] . '/README.md' );
2020-06-20 23:20:49 +12:00
$readme = ( $readme ) ? \file_get_contents ( $readme ) : '' ;
2022-01-03 22:41:47 +13:00
$gettingStarted = \realpath ( __DIR__ . '/../../docs/sdks/' . $language [ 'key' ] . '/GETTING_STARTED.md' );
2021-03-09 00:15:39 +13:00
$gettingStarted = ( $gettingStarted ) ? \file_get_contents ( $gettingStarted ) : '' ;
2022-01-03 22:41:47 +13:00
$examples = \realpath ( __DIR__ . '/../../docs/sdks/' . $language [ 'key' ] . '/EXAMPLES.md' );
2020-06-20 23:20:49 +12:00
$examples = ( $examples ) ? \file_get_contents ( $examples ) : '' ;
2022-01-03 22:41:47 +13:00
$changelog = \realpath ( __DIR__ . '/../../docs/sdks/' . $language [ 'key' ] . '/CHANGELOG.md' );
2020-06-20 23:20:49 +12:00
$changelog = ( $changelog ) ? \file_get_contents ( $changelog ) : '# Change Log' ;
2022-01-03 22:41:47 +13:00
$warning = '**This SDK is compatible with Appwrite server version ' . $version . '. For older versions, please check [previous releases](' . $language [ 'url' ] . '/releases).**' ;
2020-01-28 10:50:41 +13:00
$license = 'BSD-3-Clause' ;
2021-01-09 04:00:30 +13:00
$licenseContent = 'Copyright (c) ' . date ( 'Y' ) . ' 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 .
2022-10-13 05:53:46 +13:00
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission .
2019-11-21 07:49:35 +13:00
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' ]) {
2020-05-17 21:13:48 +12:00
case 'web' :
2020-12-24 11:39:48 +13:00
$config = new Web ();
2023-02-28 21:35:40 +13:00
if ( $platform [ 'key' ] === APP_PLATFORM_CONSOLE ) {
$config -> setNPMPackage ( '@appwrite.io/console' );
$config -> setBowerPackage ( '@appwrite.io/console' );
} else {
$config -> setNPMPackage ( 'appwrite' );
$config -> setBowerPackage ( 'appwrite' );
}
2020-01-28 10:50:41 +13:00
break ;
2021-02-09 08:30:57 +13:00
case 'cli' :
$config = new CLI ();
2022-02-25 23:50:34 +13:00
$config -> setNPMPackage ( 'appwrite-cli' );
2021-03-03 22:08:05 +13:00
$config -> setExecutableName ( 'appwrite' );
2022-02-25 23:50:34 +13:00
$config -> setLogo ( json_encode ( "
2021-03-03 22:08:05 +13:00
_ _ _ ___ __ _____
/ _\ _ __ _ ____ ___ __ ( _ ) | _ ___ / __\ / / \_ \
2022-02-25 23:50:34 +13:00
//_\\\| '_ \| '_ \ \ /\ / / '__| | __/ _ \ / / / / / /\/
2021-03-03 22:08:05 +13:00
/ _ \ | _ ) | | _ ) \ V V /| | | | || __ / / / ___ / / ___ / \ / / _
\_ / \_ / . __ /| . __ / \_ / \_ / | _ | | _ | \__\___ | \____ / \____ / \____ /
2022-02-25 23:50:34 +13:00
| _ | | _ |
" ));
$config -> setLogoUnescaped ( "
_ _ _ ___ __ _____
/ _\ _ __ _ ____ ___ __ ( _ ) | _ ___ / __\ / / \_ \
//_\\\| '_ \| '_ \ \ /\ / / '__| | __/ _ \ / / / / / /\/
/ _ \ | _ ) | | _ ) \ V V /| | | | || __ / / / ___ / / ___ / \ / / _
\_ / \_ / . __ /| . __ / \_ / \_ / | _ | | _ | \__\___ | \____ / \____ / \____ /
| _ | | _ | " );
2021-02-09 08:30:57 +13:00
break ;
2020-05-17 21:13:48 +12:00
case 'php' :
$config = new PHP ();
2020-07-10 19:11:42 +12:00
$config -> setComposerVendor ( 'appwrite' );
$config -> setComposerPackage ( 'appwrite' );
2020-03-28 06:07:10 +13:00
break ;
2020-01-28 10:50:41 +13:00
case 'nodejs' :
$config = new Node ();
2020-07-10 19:11:42 +12:00
$config -> setNPMPackage ( 'node-appwrite' );
$config -> setBowerPackage ( 'appwrite' );
2022-01-03 22:41:47 +13:00
$warning = $warning . " \n \n > This is the Node.js SDK for integrating with Appwrite from your Node.js server-side code.
2021-01-29 02:47:33 +13:00
If you ' re looking to integrate from the browser , you should check [ appwrite / sdk - for - web ]( https :// github . com / appwrite / sdk - for - web ) " ;
2020-01-28 10:50:41 +13:00
break ;
2020-05-28 18:00:07 +12:00
case 'deno' :
$config = new Deno ();
break ;
2020-01-28 10:50:41 +13:00
case 'python' :
$config = new Python ();
2020-07-10 19:11:42 +12:00
$config -> setPipPackage ( 'appwrite' );
2020-01-28 10:50:41 +13:00
$license = 'BSD License' ; // license edited due to classifiers in pypi
2022-01-03 22:41:47 +13:00
break ;
2020-01-28 10:50:41 +13:00
case 'ruby' :
$config = new Ruby ();
2020-07-10 19:11:42 +12:00
$config -> setGemPackage ( 'appwrite' );
2020-01-28 10:50:41 +13:00
break ;
2020-05-17 18:47:01 +12:00
case 'flutter' :
2020-07-10 19:11:42 +12:00
$config = new Flutter ();
$config -> setPackageName ( 'appwrite' );
break ;
2020-07-10 17:07:47 +12:00
case 'flutter-dev' :
2020-07-10 19:11:42 +12:00
$config = new Flutter ();
2020-09-03 22:54:19 +12:00
$config -> setPackageName ( 'appwrite_dev' );
2020-07-10 19:11:42 +12:00
break ;
2020-01-28 10:50:41 +13:00
case 'dart' :
$config = new Dart ();
2021-01-07 02:02:00 +13:00
$config -> setPackageName ( 'dart_appwrite' );
2022-01-03 22:41:47 +13:00
$warning = $warning . " \n \n > This is the Dart SDK for integrating with Appwrite from your Dart server-side code. If you're looking for the Flutter SDK you should check [appwrite/sdk-for-flutter](https://github.com/appwrite/sdk-for-flutter) " ;
2020-01-28 10:50:41 +13:00
break ;
case 'go' :
$config = new Go ();
break ;
2020-08-31 04:23:15 +12:00
case 'swift' :
$config = new Swift ();
2022-01-03 22:41:47 +13:00
$warning = $warning . " \n \n > This is the Swift SDK for integrating with Appwrite from your Swift server-side code. If you're looking for the Apple SDK you should check [appwrite/sdk-for-apple](https://github.com/appwrite/sdk-for-apple) " ;
2021-10-14 01:22:04 +13:00
break ;
case 'apple' :
2022-12-19 19:05:35 +13:00
$config = new Apple ();
2020-08-31 04:23:15 +12:00
break ;
2021-01-05 04:20:41 +13:00
case 'dotnet' :
2021-01-05 06:45:35 +13:00
$cover = '' ;
2021-01-05 04:20:41 +13:00
$config = new DotNet ();
break ;
2021-06-10 00:45:38 +12:00
case 'android' :
2021-07-01 03:16:07 +12:00
$config = new Android ();
break ;
case 'kotlin' :
2021-06-10 00:45:38 +12:00
$config = new Kotlin ();
2022-01-03 22:41:47 +13:00
$warning = $warning . " \n \n > This is the Kotlin SDK for integrating with Appwrite from your Kotlin server-side code. If you're looking for the Android SDK you should check [appwrite/sdk-for-android](https://github.com/appwrite/sdk-for-android) " ;
2021-06-10 00:45:38 +12:00
break ;
2022-10-20 16:21:16 +13:00
case 'graphql' :
$config = new GraphQL ();
break ;
2022-10-26 16:19:30 +13:00
case 'rest' :
$config = new REST ();
break ;
2020-01-28 10:50:41 +13:00
default :
2022-01-03 22:41:47 +13:00
throw new Exception ( 'Language "' . $language [ 'key' ] . '" not supported' );
2020-01-28 10:50:41 +13:00
}
Console :: info ( " Generating { $language [ 'name' ] } SDK... " );
$sdk = new SDK ( $config , new Swagger2 ( $spec ));
$sdk
2020-05-18 02:17:55 +12:00
-> setName ( $language [ 'name' ])
2021-06-10 03:30:52 +12:00
-> setNamespace ( 'io appwrite' )
2021-06-10 00:45: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-19 16:04:00 +12:00
-> setShortDescription ( 'Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API' )
2020-01-28 10:50:41 +13:00
-> setLicense ( $license )
-> setLicenseContent ( $licenseContent )
-> setVersion ( $language [ 'version' ])
2022-08-11 01:00:57 +12:00
-> setPlatform ( $key )
2020-01-28 10:50:41 +13:00
-> setGitURL ( $language [ 'url' ])
-> setGitRepo ( $language [ 'gitUrl' ])
-> setGitRepoName ( $language [ 'gitRepoName' ])
-> setGitUserName ( $language [ 'gitUserName' ])
2021-01-05 06:45:35 +13:00
-> setLogo ( $cover )
2020-01-28 10:50:41 +13: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,serverless' )
2021-12-12 09:17:33 +13:00
-> setShareVia ( 'appwrite' )
2020-01-28 10:50:41 +13:00
-> setWarning ( $warning )
-> setReadme ( $readme )
2021-03-09 00:15:39 +13:00
-> setGettingStarted ( $gettingStarted )
2020-04-06 08:39:45 +12:00
-> setChangelog ( $changelog )
2020-04-12 18:15:33 +12:00
-> setExamples ( $examples )
2021-04-11 04:14:15 +12:00
-> setTwitter ( APP_SOCIAL_TWITTER_HANDLE )
-> setDiscord ( APP_SOCIAL_DISCORD_CHANNEL , APP_SOCIAL_DISCORD )
2021-05-18 17:32:03 +12:00
-> setDefaultHeaders ([
2022-09-14 08:29:15 +12:00
'X-Appwrite-Response-Format' => '1.0.0' ,
2022-01-03 22:41:47 +13:00
]);
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' ];
2021-10-18 20:37:09 +13:00
$gitBranch = $language [ 'gitBranch' ];
2022-01-03 22:41:47 +13:00
if ( ! $production ) {
$gitUrl = 'git@github.com:aw-tests/' . $language [ 'gitRepoName' ] . '.git' ;
2020-03-27 02:20:07 +13:00
}
2022-01-03 22:41:47 +13:00
if ( $git && ! empty ( $gitUrl )) {
\exec ( 'rm -rf ' . $target . ' && \
mkdir - p ' . $target . ' && \
cd ' . $target . ' && \
git init -- initial - branch = ' . $gitBranch . ' && \
git remote add origin ' . $gitUrl . ' && \
2020-12-24 11:43:05 +13:00
git fetch && \
2022-01-03 22:41:47 +13:00
git pull ' . $gitUrl . ' && \
rm - rf ' . $target . ' /* && \
2022-01-04 01:44:28 +13:00
cp - r ' . $result . ' /* ' . $target . ' / && \
2020-12-24 11:43:05 +13:00
git add . && \
2022-01-03 22:41:47 +13:00
git commit - m " ' . $message . ' " && \
git push - u origin ' . $gitBranch . '
2020-12-24 11:43:05 +13:00
' );
2020-12-24 11:39:48 +13:00
Console :: success ( " Pushed { $language [ 'name' ] } SDK to { $gitUrl } " );
2020-12-25 20:43:59 +13:00
2022-01-03 22:41:47 +13:00
\exec ( 'rm -rf ' . $target );
2020-12-24 12:18:11 +13:00
Console :: success ( " Remove temp directory ' { $target } ' for { $language [ 'name' ] } SDK " );
2020-12-24 11:39:48 +13:00
}
2020-01-28 12:07:03 +13:00
2021-07-07 00:05:45 +12:00
$docDirectories = $language [ 'docDirectories' ] ? ? [ '' ];
2022-01-03 22:41:47 +13:00
2022-01-04 01:44:28 +13:00
if ( $version === 'latest' ) {
2022-01-03 22:41:47 +13:00
continue ;
}
2021-07-07 00:05:45 +12:00
foreach ( $docDirectories as $languageTitle => $path ) {
2022-01-03 22:41:47 +13:00
$languagePath = strtolower ( $languageTitle !== 0 ? '/' . $languageTitle : '' );
2021-07-07 00:05:45 +12:00
\exec (
2022-01-03 22:41:47 +13:00
'mkdir -p ' . $resultExamples . $languagePath . ' && \
cp - r ' . $result . ' / docs / examples ' . $languagePath . ' ' . $resultExamples
2021-07-07 00:05:45 +12:00
);
Console :: success ( " Copied code examples for { $language [ 'name' ] } SDK to: { $resultExamples } " );
}
2019-05-09 18:54:39 +12:00
}
}
2020-01-28 12:07:03 +13:00
2021-01-29 21:39:42 +13:00
Console :: exit ();
2020-12-24 11:39:48 +13:00
});