Open sis0k0 opened 6 years ago
Few more points and additions:
If played out right, the community should be able to contribute with schematics that will add functionality to (1. tns generate
) and (3. tns create
).
tns update
Updating dependencies, migrating code, handling breaking changes between versions can also be done with schematics in a robust and transactional manner.
What is
Schematics
?Schematics
is a workflow tool for project transformations, such as scaffolding, file updates and tasks execution (npm install
,git init
). It can apply rules* from predefined collections - for example generate a new Angular project using the@schematics/angular
collection or set up Kendo UI using the@progress/kendo-schematics
collection.* rules - should also be called schematics, but that's confusing, so I'll stick to the name rules instead.
Who uses
Schematics
?Schematics
is extensively used inside the Angular CLI. It's the backbone of the commands:routing
- whether routing configuration should be generated,styling
- what css preprocessor should be used,skipTests
- whether test setup should be generated, etc.ng add @nativescript/schematics
converts the project to a code-sharing structure by adding all necessary NativeScript dependencies and the minimal setup for running a mobile app.How can
Schematics
be used in the NativeScript CLI?1.
tns generate
Create a command that behaves similarly to
ng generate
. The@nativescript/schematics
collection can be extended with non-Angular rules (Vue.js, plain NativeScript). This will allow all NativeScript developers to use schematics in their projects.2.
tns plugin add
There is already a
tns plugin add
command in NativeScript CLI, which installs NativeScript plugins and performs project modifications. With schematics, the NativeScript CLI can:Schematics
all changes are recorded in memory and are executed only after they're confirmed to be valid. In other words - if the command fails, no changes will be applied to the project.ng add
. This will simplify the setup of plugins which currently rely on executingpostinstall
scripts, such asnativescript-dev-webpack
andnativescript-plugin-firebase
. It will also allow every NativeScript plugin to add a rule to automate the setup of the plugin. For example, thenativescript-pro-ui
plugin will be able to provide a rule, which imports its NgModule in the root NgModule if the project uses Angular.3.
tns create
Schematics
provides a powerful template engine. The NativeScript templates can be turned into schematic rules. The benefits:package.json
) will be reused;routing
,style
,sidedrawer
,tabview
, etc.);Also, the NativeScript CLI will be able to perform tasks, similarly to the Angular CLI - it could initialize a git repository for the project, install the project dependencies, etc.
Please share your feedback in the comments!