Skip to content

"Choose-template" functionality #374

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

Closed
ErjanGavalji opened this issue Mar 25, 2015 · 12 comments
Closed

"Choose-template" functionality #374

ErjanGavalji opened this issue Mar 25, 2015 · 12 comments
Assignees
Labels
Milestone

Comments

@ErjanGavalji
Copy link
Contributor

Easing the learning of NativeScript can be done by providing various start-templates. Once there are a number of predefined templates available at npmjs.org, the CLI can list these to the user and ask them for a selection upon a tns create call.

An additional parameter to the tns create call can be added, e.g. --template. If that provided, no question will get asked.

A new verb, listing the available templates should be added as well.

related to #372 and #254

@vakrilov
Copy link

Great! IMO the parameter should be --template-name or just --template.

@rosen-vladimirov
Copy link
Contributor

Really good idea.
Appbuilder-cli is using --template, so I vote for this suggestion.

@teobugslayer
Copy link
Contributor

besides, --template is shorter to write (for us poor souls without command line auto completion)

@ErjanGavalji
Copy link
Contributor Author

thanks, updating the main post...

@rosen-vladimirov
Copy link
Contributor

I've started researching the best way to implement this feature and I have one major question:
Which part of the project can be considered as template? Is this only the app folder? In case we consider the "app" folder as "templated" (so when you write --template typescript for example, the app folder will be replaced with the one from typescript template), what happens if the template requires npm module to be added to package.json, for example typescript or lodash? Who will add it to the root package.json?

@rosen-vladimirov
Copy link
Contributor

Just to add my idea for implementing this - each template will have its own package.json file and when tns create app --template templateName is executed, CLI will copy all dependencies and devDependencies from template's package.json to root's package.json.
This way only app folder will be considered as template and you'll be able to include whatever module you need in your template.

What do you think about this?

@ErjanGavalji
Copy link
Contributor Author

@rosen-vladimirov Yes. The app folder ONLY should be considered as a template. It should not include the tns-core-modules package, though it should be dependent on a SemVer-obedient version of them. Additionally, the App_Resources folder should be a separate package to be downloaded during project creation too.
As per the package.json modification - the template dependencies should be added to the { nativescript } section of the package, hence the CLI should be able to modify the package.json of the target project (if not even directly replace it)

And yes, I find the idea in your second comment perfect :)

@teobugslayer
Copy link
Contributor

Yeah, looks good to me too.

@rosen-vladimirov
Copy link
Contributor

Ok, this is already merged in master. The usage details are described below:

The value for --template can be anything that you can npm install. For example valid calls are:

  • tns create app1 --template tns-template-hello-world
  • tns create app1 --template https://github.com/NativeScript/template-hello-world-ts/tarball/master
  • tns create app1 --template ../myTemplate
  • tns create app1 --template https://github.com/NativeScript/template-hello-world-ts.git
  • tns create app1 --template https://github.com/NativeScript/template-hello-world-ts.git#master

In case you use:
tns create app1 --template typescript or tns create app1 --template tsc, CLI will try to install tns-template-hello-world-ts template.
In case you use tns create app1 --template [email protected] we will install version 1.2.0 of tns-template-hello-world-ts.

When a custom template is used, CLI will extend its App_Resources with the ones from default template in case any of them is missing.

@ErjanGavalji
Copy link
Contributor Author

@nraboy
Copy link

nraboy commented Feb 7, 2016

Has this made it into the CLI yet? 1.5.2 is giving me the following:

macbookpro:Desktop nraboy$ tns create MyProject --template tsc
The option 'template' is not supported. To see command's options, use '$ tns help create'. To see all commands use '$ tns help'.

@teobugslayer
Copy link
Contributor

it is part of 1.6, which will be released later this month.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants