NativeScript / NativeScript/nativescript-cli

Feature Request: Use schematics for project transformations

未關閉
#3,860 2 則留言 3 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

feature
主要語言
JavaScript
星號
1.1k
分支
204
平均合併
1 天 9 小時
30 天內合併 PR
8

描述

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:

  • ng new - generates the files for a new Angular project, initializes a git repository and installs the node dependencies. It supports a large range of options, such as routing - whether routing configuration should be generated, styling - what css preprocessor should be used, skipTests - whether test setup should be generated, etc.
  • ng generate - performs project transformations using a provided rule name and collection.
  • ng add - installs a plugin and executes the setup logic provided by the plugin. For example - 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:

  • Perform the project modifications. The advantage over the current implementation is that with 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.
  • Execute setup rules distributed by the plugins, similarly to ng add. This will simplify the setup of plugins which currently rely on executing postinstall scripts, such as nativescript-dev-webpack and nativescript-plugin-firebase.
    It will also allow every NativeScript plugin to add a rule to automate the setup of the plugin. For example, the nativescript-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:

  • a lot of the common parts (such as package.json) will be reused;
  • new project options will be trivial to add (routing, style, sidedrawer, tabview, etc.);
  • the rules will be hosted in a monorepo instead of separated repos for each template.

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!

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

檢視現有的 tns generatetns plugin addtns create 指令實作,以及 NativeScript 範本和外掛程式設定目前的運作方式。將其與所描述的 Schematics 工作流程進行比較,並定義整合範圍;完成表示受影響的指令支援所提議的 schematic 式轉換和工作執行。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
javascript
領域
cli, mobile
Issue 類型
功能
難度
5/5
預估耗時
一週以上
活躍度
停滯
描述清晰度
需要釐清
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。