Skip to content

Commit

Permalink
Merge pull request #72 from appwrite/feat-js-to-web
Browse files Browse the repository at this point in the history
Changed all refs from JS to Web
  • Loading branch information
eldadfux authored Dec 23, 2020
2 parents 21f3254 + bc6c15e commit 6b564fe
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 132 deletions.
10 changes: 5 additions & 5 deletions example.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -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')
Expand All @@ -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));
Expand Down
128 changes: 1 addition & 127 deletions src/SDK/Language/JS.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Appwrite\SDK\Language;

class JS extends Language {
abstract class JS extends Language {

protected $params = [
'npmPackage' => 'packageName',
Expand Down Expand Up @@ -33,14 +33,6 @@ public function setBowerPackage($name)
return $this;
}

/**
* @return string
*/
public function getName()
{
return 'JavaScript';
}

/**
* Get Language Keywords List
*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
132 changes: 132 additions & 0 deletions src/SDK/Language/Web.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?php

namespace Appwrite\SDK\Language;

class Web extends JS {

/**
* @return string
*/
public function getName()
{
return 'Web';
}

/**
* @return array
*/
public function getFiles()
{
return [
[
'scope' => '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;
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 6b564fe

Please sign in to comment.