diff --git a/example.php b/example.php index 1154abd89..fa9087fcf 100644 --- a/example.php +++ b/example.php @@ -4,7 +4,7 @@ use Appwrite\Spec\Swagger2; use Appwrite\SDK\SDK; -use Appwrite\SDK\Language\JS; +use Appwrite\SDK\Language\Web; use Appwrite\SDK\Language\Node; use Appwrite\SDK\Language\PHP; use Appwrite\SDK\Language\Python; @@ -19,7 +19,7 @@ use Appwrite\SDK\Language\CSharp; use Appwrite\SDK\Language\Flutter; -$languages = ['js', 'node', 'php', 'python', 'ruby', 'dart', 'go', 'java', 'swift', 'typescript', 'deno', 'http', 'csharp']; +$languages = ['web', 'node', 'php', 'python', 'ruby', 'dart', 'go', 'java', 'swift', 'typescript', 'deno', 'http', 'csharp']; try { @@ -63,8 +63,8 @@ function getSSLPage($url) { $sdk->generate(__DIR__ . '/examples/php'); - // JS - $sdk = new SDK(new JS(), new Swagger2($spec)); + // Web + $sdk = new SDK(new Web(), new Swagger2($spec)); $sdk ->setName('NAME') @@ -81,7 +81,7 @@ function getSSLPage($url) { ->setGitRepoName('reponame') ; - $sdk->generate(__DIR__ . '/examples/js'); + $sdk->generate(__DIR__ . '/examples/web'); // TypeScript $sdk = new SDK(new Typescript(), new Swagger2($spec)); diff --git a/src/SDK/Language/JS.php b/src/SDK/Language/JS.php index 07d1ff977..c74e5bc38 100644 --- a/src/SDK/Language/JS.php +++ b/src/SDK/Language/JS.php @@ -4,7 +4,7 @@ use Appwrite\SDK\Language; -class JS extends Language { +abstract class JS extends Language { protected $params = [ 'npmPackage' => 'packageName', @@ -33,14 +33,6 @@ public function setBowerPackage($name) return $this; } - /** - * @return string - */ - public function getName() - { - return 'JavaScript'; - } - /** * Get Language Keywords List * @@ -116,69 +108,6 @@ public function getKeywords() ]; } - /** - * @return array - */ - public function getFiles() - { - return [ - [ - 'scope' => 'default', - 'destination' => 'src/sdk.js', - 'template' => '/js/src/sdk.js.twig', - 'minify' => false, - ], - [ - 'scope' => 'default', - 'destination' => 'src/sdk.min.js', - 'template' => '/js/src/sdk.js.twig', - 'minify' => true, - ], - [ - 'scope' => 'default', - 'destination' => 'README.md', - 'template' => '/js/README.md.twig', - 'minify' => false, - ], - [ - 'scope' => 'default', - 'destination' => 'CHANGELOG.md', - 'template' => '/js/CHANGELOG.md.twig', - 'minify' => false, - ], - [ - 'scope' => 'default', - 'destination' => 'LICENSE', - 'template' => '/js/LICENSE.twig', - 'minify' => false, - ], - [ - 'scope' => 'default', - 'destination' => 'package.json', - 'template' => '/js/package.json.twig', - 'minify' => false, - ], - [ - 'scope' => 'method', - 'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseDash}}.md', - 'template' => '/js/docs/example.md.twig', - 'minify' => false, - ], - [ - 'scope' => 'default', - 'destination' => 'types/index.d.ts', - 'template' => '/js/types/index.d.ts.twig', - 'minify' => false, - ], - [ - 'scope' => 'default', - 'destination' => 'tsconfig.json', - 'template' => '/js/tsconfig.json.twig', - 'minify' => false, - ], - ]; - } - /** * @param $type * @return string @@ -253,59 +182,4 @@ public function getParamDefault(array $param) return $output; } - - /** - * @param array $param - * @return string - */ - public function getParamExample(array $param) - { - $type = $param['type'] ?? ''; - $example = $param['example'] ?? ''; - - $output = ''; - - if(empty($example) && $example !== 0 && $example !== false) { - switch ($type) { - case self::TYPE_NUMBER: - case self::TYPE_INTEGER: - case self::TYPE_BOOLEAN: - $output .= 'null'; - break; - case self::TYPE_STRING: - $output .= "''"; - break; - case self::TYPE_ARRAY: - $output .= '[]'; - break; - case self::TYPE_OBJECT: - $output .= '{}'; - break; - case self::TYPE_FILE: - $output .= "document.getElementById('uploader').files[0]"; - break; - } - } - else { - switch ($type) { - case self::TYPE_NUMBER: - case self::TYPE_INTEGER: - case self::TYPE_ARRAY: - case self::TYPE_OBJECT: - $output .= $example; - break; - case self::TYPE_BOOLEAN: - $output .= ($example) ? 'true' : 'false'; - break; - case self::TYPE_STRING: - $output .= "'{$example}'"; - break; - case self::TYPE_FILE: - $output .= "document.getElementById('uploader').files[0]"; - break; - } - } - - return $output; - } } diff --git a/src/SDK/Language/Web.php b/src/SDK/Language/Web.php new file mode 100644 index 000000000..590ef8206 --- /dev/null +++ b/src/SDK/Language/Web.php @@ -0,0 +1,132 @@ + 'default', + 'destination' => 'src/sdk.js', + 'template' => '/web/src/sdk.js.twig', + 'minify' => false, + ], + [ + 'scope' => 'default', + 'destination' => 'src/sdk.min.js', + 'template' => '/web/src/sdk.js.twig', + 'minify' => true, + ], + [ + 'scope' => 'default', + 'destination' => 'README.md', + 'template' => '/web/README.md.twig', + 'minify' => false, + ], + [ + 'scope' => 'default', + 'destination' => 'CHANGELOG.md', + 'template' => '/web/CHANGELOG.md.twig', + 'minify' => false, + ], + [ + 'scope' => 'default', + 'destination' => 'LICENSE', + 'template' => '/web/LICENSE.twig', + 'minify' => false, + ], + [ + 'scope' => 'default', + 'destination' => 'package.json', + 'template' => '/web/package.json.twig', + 'minify' => false, + ], + [ + 'scope' => 'method', + 'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseDash}}.md', + 'template' => '/web/docs/example.md.twig', + 'minify' => false, + ], + [ + 'scope' => 'default', + 'destination' => 'types/index.d.ts', + 'template' => '/web/types/index.d.ts.twig', + 'minify' => false, + ], + [ + 'scope' => 'default', + 'destination' => 'tsconfig.json', + 'template' => '/web/tsconfig.json.twig', + 'minify' => false, + ], + ]; + } + + /** + * @param array $param + * @return string + */ + public function getParamExample(array $param) + { + $type = $param['type'] ?? ''; + $example = $param['example'] ?? ''; + + $output = ''; + + if(empty($example) && $example !== 0 && $example !== false) { + switch ($type) { + case self::TYPE_NUMBER: + case self::TYPE_INTEGER: + case self::TYPE_BOOLEAN: + $output .= 'null'; + break; + case self::TYPE_STRING: + $output .= "''"; + break; + case self::TYPE_ARRAY: + $output .= '[]'; + break; + case self::TYPE_OBJECT: + $output .= '{}'; + break; + case self::TYPE_FILE: + $output .= "document.getElementById('uploader').files[0]"; + break; + } + } + else { + switch ($type) { + case self::TYPE_NUMBER: + case self::TYPE_INTEGER: + case self::TYPE_ARRAY: + case self::TYPE_OBJECT: + $output .= $example; + break; + case self::TYPE_BOOLEAN: + $output .= ($example) ? 'true' : 'false'; + break; + case self::TYPE_STRING: + $output .= "'{$example}'"; + break; + case self::TYPE_FILE: + $output .= "document.getElementById('uploader').files[0]"; + break; + } + } + + return $output; + } +} diff --git a/templates/js/CHANGELOG.md.twig b/templates/web/CHANGELOG.md.twig similarity index 100% rename from templates/js/CHANGELOG.md.twig rename to templates/web/CHANGELOG.md.twig diff --git a/templates/js/LICENSE.twig b/templates/web/LICENSE.twig similarity index 100% rename from templates/js/LICENSE.twig rename to templates/web/LICENSE.twig diff --git a/templates/js/README.md.twig b/templates/web/README.md.twig similarity index 100% rename from templates/js/README.md.twig rename to templates/web/README.md.twig diff --git a/templates/js/docs/example.md.twig b/templates/web/docs/example.md.twig similarity index 100% rename from templates/js/docs/example.md.twig rename to templates/web/docs/example.md.twig diff --git a/templates/js/package.json.twig b/templates/web/package.json.twig similarity index 100% rename from templates/js/package.json.twig rename to templates/web/package.json.twig diff --git a/templates/js/src/sdk.js.twig b/templates/web/src/sdk.js.twig similarity index 100% rename from templates/js/src/sdk.js.twig rename to templates/web/src/sdk.js.twig diff --git a/templates/js/tsconfig.json.twig b/templates/web/tsconfig.json.twig similarity index 100% rename from templates/js/tsconfig.json.twig rename to templates/web/tsconfig.json.twig diff --git a/templates/js/types/index.d.ts.twig b/templates/web/types/index.d.ts.twig similarity index 100% rename from templates/js/types/index.d.ts.twig rename to templates/web/types/index.d.ts.twig