Skip to content

feat(cli): Add in typescript language along with use-docker switch into the CLI #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ jobs:
run: |
mkdir "$LOG_PATH"
pip install --upgrade pip
pip install --use-feature=2020-resolver --upgrade setuptools wheel aws-sam-cli -r https://raw.githubusercontent.com/aws-cloudformation/cloudformation-cli/master/requirements.txt
pip install --use-feature=2020-resolver .
pip install --upgrade setuptools wheel aws-sam-cli -r https://raw.githubusercontent.com/aws-cloudformation/cloudformation-cli/master/requirements.txt
pip install .
- uses: actions/setup-node@v1
with:
node-version: 14
Expand Down
12 changes: 8 additions & 4 deletions python/rpdk/typescript/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,32 @@ def __init__(self):
self.namespace = None
self.package_name = None
self.package_root = None
self._use_docker = True
self._use_docker = None
self._protocol_version = "2.0.0"
self._build_command = None
self._lib_path = None

def _init_from_project(self, project):
self.namespace = tuple(s.lower() for s in project.type_info)
self.package_name = "-".join(self.namespace)
self._use_docker = project.settings.get("useDocker", True)
# Check config file for (legacy) 'useDocker' and use_docker settings
self._use_docker = project.settings.get("useDocker") or project.settings.get(
"use_docker"
)
self.package_root = project.root / "src"
self._build_command = project.settings.get("buildCommand", None)
self._lib_path = SUPPORT_LIB_VERSION

def _init_settings(self, project):
LOG.debug("Writing settings")
self._use_docker = input_with_validation(
self._use_docker = self._use_docker or input_with_validation(
"Use docker for platform-independent packaging (Y/n)?\n",
validate_no,
"This is highly recommended unless you are experienced \n"
"with cross-platform Typescript packaging.",
)
project.settings["useDocker"] = self._use_docker
# switched to 'use_docker' from 'useDocker' to be in line with python version
project.settings["use_docker"] = self._use_docker
project.settings["protocolVersion"] = self._protocol_version

def init(self, project):
Expand Down
18 changes: 18 additions & 0 deletions python/rpdk/typescript/parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def setup_subparser(subparsers, parents):
parser = subparsers.add_parser(
"typescript",
description="This sub command generates IDE and build files for TypeScript",
parents=parents,
)
parser.set_defaults(language="typescript")

parser.add_argument(
"-d",
"--use-docker",
action="store_true",
help="""Use docker for TypeScript platform-independent packaging.
This is highly recommended unless you are experienced
with cross-platform TypeScript packaging.""",
)

return parser
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ def find_version(*file_paths):
entry_points={
"rpdk.v1.languages": [
"typescript = rpdk.typescript.codegen:TypescriptLanguagePlugin",
]
],
"rpdk.v1.parsers": [
"typescript = rpdk.typescript.parser:setup_subparser",
],
},
license="Apache License 2.0",
classifiers=[
Expand Down
2 changes: 1 addition & 1 deletion tests/plugin/codegen_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test__remove_build_artifacts_file_not_found(tmp_path: str):

def test_initialize(project: Project):
lib_path = project._plugin._lib_path
assert project.settings == {"useDocker": False, "protocolVersion": "2.0.0"}
assert project.settings == {"use_docker": False, "protocolVersion": "2.0.0"}

files = get_files_in_project(project)
assert set(files) == {
Expand Down
22 changes: 22 additions & 0 deletions tests/plugin/parser_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import argparse

from rpdk.typescript.parser import setup_subparser


def test_setup_subparser():
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest="subparser_name")

sub_parser = setup_subparser(subparsers, [])

args = sub_parser.parse_args([])
assert args.language == "typescript"
assert args.use_docker is False

short_args = sub_parser.parse_args(["-d"])
assert short_args.language == "typescript"
assert short_args.use_docker is True

long_args = sub_parser.parse_args(["--use-docker"])
assert long_args.language == "typescript"
assert long_args.use_docker is True