Skip to content
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

fix: default to nodejs10.x on init #1275

Merged
merged 3 commits into from
Jul 30, 2019
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 samcli/commands/init/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from samcli.cli.main import pass_context, common_options
from samcli.commands.exceptions import UserException
from samcli.local.common.runtime_template import INIT_RUNTIMES, SUPPORTED_DEP_MANAGERS
from samcli.local.common.runtime_template import INIT_RUNTIMES, SUPPORTED_DEP_MANAGERS, DEFAULT_RUNTIME
from samcli.local.init import generate_project
from samcli.local.init.exceptions import GenerateProjectFailedError

Expand All @@ -17,7 +17,7 @@

@click.command(context_settings=dict(help_option_names=[u'-h', u'--help']))
@click.option('-l', '--location', help="Template location (git, mercurial, http(s), zip, path)")
@click.option('-r', '--runtime', type=click.Choice(INIT_RUNTIMES), default="nodejs8.10",
@click.option('-r', '--runtime', type=click.Choice(INIT_RUNTIMES), default=DEFAULT_RUNTIME,
help="Lambda Runtime of your app")
@click.option('-d', '--dependency-manager', type=click.Choice(SUPPORTED_DEP_MANAGERS), default=None,
help="Dependency manager of your Lambda runtime", required=False)
Expand Down
11 changes: 8 additions & 3 deletions samcli/local/common/runtime_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
_init_path = str(pathlib.Path(os.path.dirname(__file__)).parent)
_templates = os.path.join(_init_path, 'init', 'templates')


# Note(TheSriram): The ordering of the runtimes list per language is based on the latest to oldest.
RUNTIME_DEP_TEMPLATE_MAPPING = {
"python": [
{
"runtimes": ["python2.7", "python3.6", "python3.7"],
"runtimes": ["python3.7", "python3.6", "python2.7"],
"dependency_manager": "pip",
"init_location": os.path.join(_templates, "cookiecutter-aws-sam-hello-python"),
"build": True
Expand All @@ -32,7 +34,7 @@
],
"nodejs": [
{
"runtimes": ["nodejs8.10", "nodejs10.x"],
"runtimes": ["nodejs10.x", "nodejs8.10"],
"dependency_manager": "npm",
"init_location": os.path.join(_templates, "cookiecutter-aws-sam-hello-nodejs"),
"build": True
Expand All @@ -46,7 +48,7 @@
],
"dotnet": [
{
"runtimes": ["dotnetcore", "dotnetcore1.0", "dotnetcore2.0", "dotnetcore2.1"],
"runtimes": ["dotnetcore2.1", "dotnetcore2.0", "dotnetcore1.0", "dotnetcore"],
"dependency_manager": "cli-package",
"init_location": os.path.join(_templates, "cookiecutter-aws-sam-hello-dotnet"),
"build": True
Expand Down Expand Up @@ -81,3 +83,6 @@
RUNTIMES = set(itertools.chain(*[c['runtimes'] for c in list(
itertools.chain(*(RUNTIME_DEP_TEMPLATE_MAPPING.values())))]))
INIT_RUNTIMES = RUNTIMES.union(RUNTIME_DEP_TEMPLATE_MAPPING.keys())

# NOTE(TheSriram): Default Runtime Choice when runtime is not chosen
DEFAULT_RUNTIME = RUNTIME_DEP_TEMPLATE_MAPPING['nodejs'][0]['runtimes'][0]
6 changes: 2 additions & 4 deletions samcli/local/init/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


def generate_project(
location=None, runtime="nodejs", dependency_manager=None,
location=None, runtime="nodejs10.x", dependency_manager=None,
output_dir=".", name='sam-sample-app', no_input=False):
"""Generates project using cookiecutter and options given

Expand Down Expand Up @@ -51,11 +51,9 @@ def generate_project(

for mapping in list(itertools.chain(*(RUNTIME_DEP_TEMPLATE_MAPPING.values()))):
if runtime in mapping['runtimes'] or any([r.startswith(runtime) for r in mapping['runtimes']]):
if not dependency_manager:
if not dependency_manager or dependency_manager == mapping['dependency_manager']:
template = mapping['init_location']
break
elif dependency_manager == mapping['dependency_manager']:
template = mapping['init_location']

if not template:
msg = "Lambda Runtime {} does not support dependency manager: {}".format(runtime, dependency_manager)
Expand Down