anton/ng2-template

此包的最新版本(v1.0.0)没有提供许可证信息。

为ankor webpack angular 2 start kit生成CLI

安装: 17

依赖项: 0

建议者: 0

安全性: 0

星星: 1

观察者: 2

分支: 0

类型:项目

v1.0.0 2016-09-26 09:46 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:36:53 UTC


README

使用单元测试创建主要项目元素

安装

ln -s $(realpath ng-templator.php) ~/bin/ngt
chmod +x ~/bin/ngt

注意:应将~/bin添加到$PATH。

生成空白

组件

$ ngt component my-component

构建结构

.
└───my-component
    ├───index.ts
    ├───my-component.component.pug
    ├───my-component.component.less
    ├───my-component.component.ts
    ├───my-component.component.spec.ts

参数

  • -tp\--tag-prefix my - (注意!没有连字符)为组件标签选择器创建前缀 my-
    默认值是 app-
  • -s\--style less - 用 .less 格式生成样式,而不是 .scss

小型组件

$ ngt small-component my-component

生成具有内联样式和模板的组件

构建结构

.
├───my-component.component.ts
├───my-component.component.spec.ts

参数

  • -tp\--tag-prefix my - (注意!没有连字符)为组件标签选择器创建前缀 my-
    默认值是 app-
  • -s\--style less - 用 .less 格式生成样式,而不是 .scss

模块

$ ngt module my-module

构建结构

.
└───my-module
    ├───index.ts
    ├───my-routes.module.ts

参数

  • -wc\--with-component - 额外创建模块的主组件。
    文件结构

      .
      └───my-module
          ├───index.ts
          ├───my-routes.module.ts
          ├───my-component.component.pug
          ├───my-component.component.less
          ├───my-component.component.ts
          ├───my-component.component.spec.ts
    

    当使用模块创建组件时,也支持组件参数 -tp-s

指令

$ ngt directive super-highlight

构建结构

.
├───super-highlight.directive.ts
├───super-highlight.directive.spec.ts

参数

  • -sp\--selector-prefix my(值不带连字符)为指令选择器创建前缀 my
    结果将是 mySuperHighlight
    默认值是 app

管道

$ ngt pipe pretty

构建结构

.
├───pretty.pipe.ts
├───pretty.pipe.spec.ts

服务

$ ngt service auth

构建结构

.
├───auth.service.ts
├───auth.service.spec.ts

API服务

$ ngt api user

构建结构

.
├───user-api.service.ts
├───user-api.service.spec.ts

模型

$ ngt model user

构建结构

.
├───user.model.ts
├───user.model.spec.ts

参数

  • -f\--fields 为模型创建字段。
    可用修饰符

    • s - 字符串(默认值,如果没有指定)
    • b - 布尔值
    • n - 数字
    • a - 任何类型
    • MyClass - 自定义类型定义

    每个模型默认都有一个 id:n 字段。
    如果您不想使用 id,只需在字段中指定 -id。例如:-f '-id'。注意:将 -id 指定为首列将不起作用。

    示例:name;surname;email:s;age:n;isAdmin:b;currency:Currency;createdAt:a 结果将是

    • user.model.ts
      声明
      public id: number;
      public name: string;
      public surname: string;
      public email: string;
      public age: number;
      public isAdmin: boolean;
      public currency: Currency;
      public createdAt: any;
      
      初始化
      this.id        = +data.id || null;
      this.name      = data.name || null;
      this.surname   = data.surname || null;
      this.email     = data.email || null;
      this.age       = +data.age || null;
      this.isAdmin   = data.isAdmin !== undefined && data.isAdmin !== null ? Boolean(data.isAdmin) : null;
      this.currency  = data.currency || null;
      this.createdAt = data.createdAt || null;
      
      .spec.ts 中的数据
      id:         1,
      name:       'Test string 1',
      surname:    'Test string 2',
      email:      'Test string 3',
      age:        2,
      isAdmin:    true,
      currency:   'No generator. Using some string 1',
      createdAt:  'Any as string 1',