Skip to content

feat: Allow templates to be full applications #3542

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 4 commits into from
May 23, 2018

Conversation

rosen-vladimirov
Copy link
Contributor

Currently when a project is created the content of the template is placed inside the app directory of the newly created project.
This leads to some issues when you want to support more complex scenarios, for example it is difficult to add configuration file (like nsconfig.json or webpack.config.js) in the root of the project.
The suggested solution to allow templates to be the full application is to check the template from which the application is created. In case the template contains a nativescript key and templateVersion property in it, check its value.
In case it is v1, use the old way, i.e. place the content of the template in the app directory of the created project.
In case it is v2 place the content of the template at the root of the application.
In case it is anything else - throw an error.
In case it is missing, use v1 as default.

The solution ensures backwards compatiblity with existing templates and allows creating new types of templates.

PR Checklist

Fixes/Implements/Closes #[Issue Number].

@rosen-vladimirov rosen-vladimirov added this to the 4.1.0 milestone Apr 22, 2018
@rosen-vladimirov rosen-vladimirov force-pushed the vladimirov/templates-v2 branch from d050c7d to a9ee3de Compare April 22, 2018 21:29
@Fatme
Copy link
Contributor

Fatme commented Apr 24, 2018

run ci

2 similar comments
@rosen-vladimirov
Copy link
Contributor Author

run ci

@dtopuzov
Copy link
Contributor

run ci

this.$logger.trace(`Template version is ${templateVersion}`);
let destinationDir = "";
switch (templateVersion) {
case constants.TemplateVersions.v2:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we always defatult to v1 here, maybe will be better that the default case is v2 and above.

case constants.TemplateVersions.v1:
    const appDestinationPath = this.$projectData.getAppDirectoryPath(projectDir);
    this.$fs.createDirectory(appDestinationPath);
    destinationDir = appDestinationPath;
    break;
default:
   destinationDir = projectDir;

await this.$npm.uninstall(templatePackageJson.name, { save: true }, projectDir);
if (templateVersion === constants.TemplateVersions.v2) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (templateVersion !== constants.TemplateVersions.v2) will allow bumping versions without having to alter code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot be sure what will be required in the next versions, so I prefer keeping the strictness here - for v2 do this. In case we decide to use v3 and to make it work in a similar manner , we'll alter the code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it more likely that v3 will be derived from v2 structure rather than from the one of v1.

@KristianDD
Copy link
Contributor

Maybe we can use semver for templateVersion. Just curious why we chose custom versioning.

Currently when a project is created the content of the template is placed inside the `app` directory of the newly created project.
This leads to some issues when you want to support more complex scenarios, for example it is difficult to add configuration file (like nsconfig.json or webpack.config.js) in the root of the project.
The suggested solution to allow templates to be the full application is to check the template from which the application is created. In case the template contains a nativescript key and templateVersion property in it, check its value.
In case it is v1, use the old way, i.e. place the content of the template in the app directory of the created project.
In case it is v2 place the content of the template at the root of the application.
In case it is anything else - throw an error.
In case it is missing, use v1 as default.

The solution ensures backwards compatiblity with existing templates and allows creating new types of templates.
In case the used template does not have App_Resources, we need to copy them from the default template.
Ensure the location of the App_Resources in the default template is calculated correctly based on its templateVersion property.
Add `after-createProject` hook, so template authors will be able to execute different operations based on their requirements. The hook is called at the end of the project creation step.
Also remove usage of `$projectData` and use `$projectDataService` in order to ensure correct behavior in long living process
@rosen-vladimirov rosen-vladimirov force-pushed the vladimirov/templates-v2 branch from a9ee3de to cd3f6cb Compare May 21, 2018 20:23
@rosen-vladimirov
Copy link
Contributor Author

@KristianDD I've used REST API versioning as it seems more suitable for the current case where we do no have a specific logic for patches and minor versions. We have absolutely different logic for the two types of templates.
Using semver means we have different logic for minor and patch versions, which is not the case at the moment. Also I do not see why we would have a different logic for template's minor version for example.

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

Successfully merging this pull request may close these issues.

4 participants