nsg
NativeScript + Angular 的 CLI 工具
npm i --save nsg

nsg

Angular CLI 的 NativeScript & Angular 项目的变种,运行 nsg 命令就像运行 ng 命令一样。

安装

npm install -g nsg

用法

与 Angular CLI 中的 ng 命令相同,除了 nsg 会生成 NativeScript 所需的项目/组件/服务/...。

示例

  1. 创建新项目:nsg new hello

  2. 生成名为 item 的组件:nsg generate component item

大多数 ng 命令的选项在 nsg 中也可用,如 --inline-style--flat ...

使用 tns

编码完成后,运行 tns run android|ios 来运行。

nsgng 的区别

  • nsg 使用 nsg-cli.json 作为配置文件名
  • nsg 创建绝对 templateUrl 和 styleUrls,以符合 NativeScript 的要求
  • nsg 使用 NativeScriptModule 而不是 RouterModule
  • nsg 尝试使项目结构看起来既像 ng 又像 tns
  • 默认选择器以 'ns' 为前缀而不是 'app'

nsg 生成的项目结构

+ hello/
+ .git/
+ app/
+ ns
- app.module.ts
- app.component.ts
- app.component.html
- app.component.css
- app.css
- main.ts
- package.json
- package.json
- tsconfig.json
- nsg-cli.json
- README.md
- .gitignore

nsgsrc 文件夹替换为 app,就像 tns 一样。由于 app 被使用,所以 src 中的此文件夹被更改为 ns