Skip to content

Commit

Permalink
Generate TypeScript typings from Stone specification for NPM distribu…
Browse files Browse the repository at this point in the history
…tion

Future publications of the dropbox NPM module will now include TypeScript typings
generated using the new TypeScript stone generator. Typings contain TSDoc annotations
for better IDE integration.
  • Loading branch information
John Vilk committed Jan 22, 2017
1 parent 0980d7e commit 51a3363
Show file tree
Hide file tree
Showing 15 changed files with 9,743 additions and 9 deletions.
37 changes: 33 additions & 4 deletions generator/generate_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import sys

cmdline_desc = """\
Runs Stone to generate JS routes for the Dropbox client.
Runs Stone to generate JS routes for the Dropbox client.
"""

_cmdline_parser = argparse.ArgumentParser(description=cmdline_desc)
Expand Down Expand Up @@ -56,27 +56,32 @@ def main():
os.path.join(os.path.dirname(sys.argv[0]), '../src'))
if verbose:
print('Dropbox package path: %s' % dropbox_pkg_path)

typescript_template_path = os.path.abspath(
os.path.join(os.path.dirname(sys.argv[0]), 'typescript'))
if verbose:
print('Generating JS client routes for user routes')
print('TypeScript template path: %s' % typescript_template_path)

upload_arg = {
"match": ["style", "upload"],
"arg_name": "contents",
"arg_type": "Object",
"arg_docstring": "The file contents to be uploaded."
}

if verbose:
print('Generating JS types')
subprocess.check_output(
(['python', '-m', 'stone.cli', 'js_types', dropbox_pkg_path] +
specs + ['-b', 'team'] + ['-a', 'host', '-a', 'style', '-a', 'auth'] +
['--', 'types.js', '-e', json.dumps(upload_arg)]),
cwd=stone_path)

if verbose:
print('Generating JS client routes for user routes')
subprocess.check_output(
(['python', '-m', 'stone.cli', 'js_client', dropbox_pkg_path] +
specs + ['-b', 'team'] + ['-a', 'host', '-a', 'style', '-a', 'auth'] +
['--', 'routes.js', '-c', 'Dropbox']),
# '-e', json.dumps(upload_arg)]),
cwd=stone_path)

if verbose:
Expand All @@ -87,5 +92,29 @@ def main():
['-a', 'host', '-a', 'style', '-a', 'auth'] + ['--', 'routes-team.js', '-c', 'DropboxTeam']),
cwd=stone_path)

if verbose:
print('Generating TSD types')
subprocess.check_output(
(['python', '-m', 'stone.cli', 'tsd_types', typescript_template_path] +
specs + ['-b', 'team'] + ['-a', 'host', '-a', 'style'] +
['--', 'dropbox_types.d.tstemplate', 'dropbox_types.d.ts', '-e', json.dumps(upload_arg)]),
cwd=stone_path)

if verbose:
print('Generating TSD client routes for user routes')
subprocess.check_output(
(['python', '-m', 'stone.cli', 'tsd_client', typescript_template_path] +
specs + ['-b', 'team'] + ['-a', 'host', '-a', 'style'] +
['--', 'dropbox.d.tstemplate', 'dropbox.d.ts']),
cwd=stone_path)

if verbose:
print('Generating TSD client routes for team routes')
subprocess.check_output(
(['python', '-m', 'stone.cli', 'tsd_client', typescript_template_path] +
specs + ['-w', 'team', '-f', 'style!="upload" and style!="download"'] +
['-a', 'host', '-a', 'style'] + ['--', 'dropbox_team.d.tstemplate', 'dropbox_team.d.ts']),
cwd=stone_path)

if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion generator/stone
Submodule stone updated 59 files
+13 −10 .gitignore
+6 −0 .pylintrc
+17 −2 .travis.yml
+5 −10 README.rst
+3 −2 doc/builtin_generators.rst
+0 −0 example/__init__.py
+0 −0 example/generator/__init__.py
+0 −0 example/generator/ex1/__init__.py
+0 −0 example/generator/ex2/__init__.py
+1 −1 example/generator/ex2/ex2.stoneg.py
+0 −0 example/generator/ex3/__init__.py
+3 −8 example/generator/ex3/ex3.stoneg.py
+0 −0 example/generator/unstone/__init__.py
+23 −23 example/generator/unstone/unstone.stoneg.py
+5 −4 mypy-run.sh
+5 −0 mypy.ini
+0 −3 setup.cfg
+7 −3 setup.py
+48 −40 stone/api.py
+14 −3 stone/cli.py
+2 −2 stone/cli_helpers.py
+5 −4 stone/compiler.py
+34 −6 stone/data_type.py
+44 −45 stone/generator.py
+1 −0 stone/lang/exception.py
+3 −4 stone/lang/lexer.py
+20 −10 stone/lang/tower.py
+10 −7 stone/target/js_client.py
+1 −1 stone/target/js_helpers.py
+78 −41 stone/target/js_types.py
+15 −57 stone/target/obj_c.py
+86 −61 stone/target/obj_c_client.py
+11 −21 stone/target/obj_c_helpers.py
+2 −2 stone/target/obj_c_rsrc/DBSerializableProtocol.h
+13 −0 stone/target/obj_c_rsrc/DBStoneSerializers.h
+9 −9 stone/target/obj_c_rsrc/DBStoneSerializers.m
+6 −6 stone/target/obj_c_rsrc/DBStoneValidators.m
+8 −5 stone/target/obj_c_rsrc/jazzy.json
+0 −241 stone/target/obj_c_tests.py
+136 −120 stone/target/obj_c_types.py
+20 −6 stone/target/python_client.py
+17 −1 stone/target/python_rsrc/stone_base.py
+399 −221 stone/target/python_rsrc/stone_serializers.py
+14 −11 stone/target/python_rsrc/stone_validators.py
+11 −2 stone/target/python_types.py
+5 −14 stone/target/swift.py
+18 −12 stone/target/swift_client.py
+4 −4 stone/target/swift_helpers.py
+41 −30 stone/target/swift_types.py
+127 −0 stone/target/tsd_client.py
+130 −0 stone/target/tsd_helpers.py
+395 −0 stone/target/tsd_types.py
+0 −0 test/__init__.py
+6 −0 test/test_cli.py
+22 −8 test/test_generator.py
+173 −8 test/test_python_gen.py
+10 −2 test/test_stone.py
+6 −0 test/test_stone_internal.py
+51 −3 tox.ini
3 changes: 3 additions & 0 deletions generator/typescript/Dropbox-sdk.min.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// <reference path="./dropbox.d.ts" />
export = DropboxTypes.Dropbox;
export as namespace Dropbox;
3 changes: 3 additions & 0 deletions generator/typescript/DropboxTeam-sdk.min.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// <reference path="./dropbox_team.d.ts" />
export = DropboxTypes.DropboxTeam;
export as namespace DropboxTeam;
2 changes: 2 additions & 0 deletions generator/typescript/dropbox-sdk.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// <reference path="./dropbox.d.ts" />
export = DropboxTypes.Dropbox;
Loading

0 comments on commit 51a3363

Please sign in to comment.