Skip to content

Commit

Permalink
refactor(schematics): update API and schema options (#2667)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsuanxyz authored and vthinkxie committed Dec 24, 2018
1 parent f9a9649 commit c0ba991
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 66 deletions.
50 changes: 27 additions & 23 deletions docs/schematics.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,58 +43,62 @@ You can get component generation code in our doc after expand the code panel bel
### Command

```bash
ng g ng-zorro-antd:[template] --name=NAME [options]
ng g ng-zorro-antd:[schematic] <name> [options]
```

For example, you can generate an login form with the follow command.

```bash
ng g ng-zorro-antd:form-normal-login -p app --styleext=less --name=login
ng g ng-zorro-antd:form-normal-login login
```

### Options

***--name***
***--entry-component***

Specify the component name(required)
Specifies if the component is an entry component of declaring module.

***--styleext***
***--export***

The type of style file(default css).
Specifies if declaring module exports the component.

***--prefix***, ***-p***
***--flat***

The prefix name of the component.
Flag to indicate if a dir is created.

***--inlineStyle***, ***-s***
***--inline-style (-s)***

Using inline style.
Specifies if the style will be in the ts file.

***--inlineTemplate***, ***-t***
***--inline-template (-t)***

Using inline template.
Specifies if the template will be in the ts file.

***--path***
***--module (-m)***

Specify the path of the created component.
Allows specification of the declaring module.

***--spec***
***--prefix (-p)***

Create test file.
The prefix to apply to generated selectors.

***--skipImport***
***--project***

Skip module import.
The name of the project.

***--selector***

The name of selector.
The selector to use for the component.

***--export***
***--skip-import***

Should add component to `exports` part.
Flag to skip the module import.

***--module***, ***-m***
***--spec***

Specifies if a spec file is generated.

***--styleext***

Specify the module name.
The file extension to be used for style files.

56 changes: 29 additions & 27 deletions docs/schematics.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ title: 脚手架

自动完成 `ng-zorro-antd` 的初始化配置,包括引入国际化文件,导入模块,引入样式文件等工作。

### 初始化命令
### 命令

```bash
ng add ng-zorro-antd [options]
```

### 初始化参数
### 参数

***--theme***

Expand All @@ -41,62 +41,64 @@ ng add ng-zorro-antd [options]

快速生成模板代码,每个官网的代码演示都附有可生成的模板,开发者可以通过展开每个组件的代码演示部分获取其生成代码。

### 生成组件命令
### 命令

```bash
ng g ng-zorro-antd:[template] --name=NAME [options]
ng g ng-zorro-antd:[schematic] <name> [options]
```

例如通过以下代码可以快速生成一个登陆框组件

```bash
ng g ng-zorro-antd:form-normal-login -p app --styleext=less --name=login
ng g ng-zorro-antd:form-normal-login login
```

### 生成组件参数
### 参数

***--name***
***--entry-component***

组件名称(必选)
组件是否在模块的 `entryComponents` 声明

***--styleext***
***--export***

样式文件扩展名(默认 css)
组件是否在模块的 `exports` 声明

***--prefix***, ***-p***
***--flat***

组件选择器前缀
指定是否创建目录

***--inlineStyle***, ***-s***
***--inline-style (-s)***

使用行内样式
指定是否使用行内样式

***--inlineTemplate***, ***-t***
***--inline-template (-t)***

使用行内模版
指定是否使用行内模版

***--path***
***--module (-m)***

指定组件创建目录(相当于执行时所在的目录)
指定声明的模块

***--spec***
***--prefix (-p)***

是否生成 `.spec` 测试文件
组件选择器前缀

***--skipImport***
***--project***

是否跳过模块引入(及导入所属模块)
指定声明到的项目名

***--selector***

选择器名称(默认根据 `name` 自动生成)
组件的选择器名称

***--export***
***--skip-import***

是否将组件声明在模块的 `exports`
指定是否跳过模块引入

***--spec***

***--module***, ***-m***
指定是否生成 `.spec` 测试文件

指定要声明的模块名
***--styleext***

指定样式文件扩展名
5 changes: 4 additions & 1 deletion scripts/schematics/template/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { Schema } from './schema';

export default function (options: Schema): Rule {
return chain([
buildComponent({ ...options })
buildComponent({ ...options }, {
template: './__path__/__name@dasherize@if-flat__/__name@dasherize__.component.html',
stylesheet: './__path__/__name@dasherize@if-flat__/__name@dasherize__.component.__styleext__'
})
]);
}
34 changes: 22 additions & 12 deletions scripts/schematics/template/schema.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
{
"$schema": "http://json-schema.org/schema",
"id": "AddNgZorroTable",
"title": "Add NG-ZORRO Table",
"id": "PLACEHOLDER_SCHEMATICS_ID",
"title": "PLACEHOLDER_SCHEMATICS_TITLE",
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "The name of the component."
},
"path": {
"type": "string",
"format": "path",
Expand All @@ -17,7 +13,18 @@
"project": {
"type": "string",
"description": "The name of the project.",
"visible": false
"$default": {
"$source": "projectName"
}
},
"name": {
"type": "string",
"description": "The name of the component.",
"$default": {
"$source": "argv",
"index": 0
},
"x-prompt": "What should be the name of the component?"
},
"inlineStyle": {
"description": "Specifies if the style will be in the ts file.",
Expand All @@ -39,13 +46,11 @@
},
"styleext": {
"description": "The file extension to be used for style files.",
"type": "string",
"default": "css"
"type": "string"
},
"spec": {
"type": "boolean",
"description": "Specifies if a spec file is generated.",
"default": true
"description": "Specifies if a spec file is generated."
},
"flat": {
"type": "boolean",
Expand All @@ -62,7 +67,7 @@
"format": "html-selector",
"description": "The selector to use for the component."
},
"module": {
"module": {
"type": "string",
"description": "Allows specification of the declaring module.",
"alias": "m"
Expand All @@ -71,6 +76,11 @@
"type": "boolean",
"default": false,
"description": "Specifies if declaring module exports the component."
},
"entryComponent": {
"type": "boolean",
"default": false,
"description": "Specifies if the component is an entry component of declaring module."
}
},
"required": [
Expand Down
6 changes: 4 additions & 2 deletions scripts/schematics/template/schema.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {Schema as ComponentSchema} from '@schematics/angular/component/schema';
import { Schema as ComponentSchema } from '@schematics/angular/component/schema';

export interface Schema extends ComponentSchema {}
export interface Schema extends ComponentSchema {
[key: string]: string | boolean;
}
2 changes: 1 addition & 1 deletion scripts/site/utils/generate-code-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ module.exports = function generateCodeBox(component, key, title, doc, iframe) {
}
output = output.replace(/{{code}}/g, camelCase(key));
output = output.replace(/{{rawCode}}/g, `${camelCase(key)}Raw`);
output = output.replace(/{{nzGenerateCommand}}/g, `ng g ng-zorro-antd:${component}-${key} -p app --name=`);
output = output.replace(/{{nzGenerateCommand}}/g, `ng g ng-zorro-antd:${component}-${key} <name>`);
return output;
};

0 comments on commit c0ba991

Please sign in to comment.