Skip to content

Commit

Permalink
fix(schematic:ng-add): fix import path in theme file (#1611)
Browse files Browse the repository at this point in the history
feat(schematic:ng-add): rename from locale to i18n

delete dynamically generated files
  • Loading branch information
hsuanxyz authored and vthinkxie committed Jun 6, 2018
1 parent 9ed3590 commit aa953dc
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 19 deletions.
2 changes: 0 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ echo 'Generate schematics by demos'
npm run schematic:demo

echo 'Building schematics'
node ./schematics_script/set-version.js
node ./schematics_script/set-theme.js
npm run schematic:demo
npm run schematic:build
rm -rf schematics/demo
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"site": "node site_scripts/generate-site",
"schematic:demo": "node schematics_script/demo2schematics",
"schematic:tsc": "tsc -p schematics/tsconfig.json",
"schematic:build": "npm run schematic:tsc && node schematics_script/copy-resources",
"schematic:build": "node ./schematics_script/set-theme.js && node ./schematics_script/set-version.js && npm run schematic:tsc && node schematics_script/copy-resources",
"ng": "ng",
"start": "ng serve -p 0",
"build": "node site_scripts/generate-site init && ng build",
Expand Down
13 changes: 7 additions & 6 deletions schematics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,21 @@ $ ng add ng-zorro-antd [--locale=zh-CN] [--theme] [--skipPackageJson]
- `node ./schematics_script/set-version.js` 从 package.json 设置版本号
- `node ./schematics_script/set-theme.js` 从 site_scripts/_site/src/theme.less 设置自定义样式内容

### 开发
### 首次运行

只有首次运行才需要以下步骤
生成 publish 之后,创建一个新的 ng 项目

1. 运行 `npm run generate` 生成 `publish` 文件夹
2. `cd publish && npm link`
3. `ng new schematic-debug`
4. `cd schematic-debug && npm link ng-zorro-antd`

调试
### 调试

1. `cd schematic-debug`
1. `git checkout . && git clean -fd`
1. `ng g ng-zorro-antd:[schematics]`
1. `schematic:build` 修改代码后编译
2 `cd schematic-debug` 切换到 ng 项目
3. `git checkout . && git clean -fd` 还原更改
4. `ng g ng-zorro-antd:[schematic]` 运行 schematic

发布

Expand Down
4 changes: 2 additions & 2 deletions schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ export default function (options: Schema): Rule {
]);
}

/** 添加 i18n 配置, 取决于 options.locale */
/** 添加 i18n 配置, 取决于 options.i18n */
function addI18n(options: Schema): (host: Tree) => Tree {
return function (host: Tree): Tree {
const workspace = getWorkspace(host);
const project = getProjectFromWorkspace(workspace, options.project);
const modulePath = getAppModulePath(host, project.architect.build.options.main);
const moduleSource = getSourceFile(host, modulePath);
const locale = options.locale;
const locale = options.i18n;
const localePrefix = locale.split('_')[0];

if (!moduleSource) {
Expand Down
2 changes: 1 addition & 1 deletion schematics/ng-add/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"default": false,
"description": "Do not add ng-zorro dependencies to package.json (e.g., --skipPackageJson)"
},
"locale": {
"i18n": {
"type": "string",
"default": "zh_CN",
"enum": ["ar_EG","bg_BG","ca_ES","cs_CZ","de_DE","el_GR","en_GB","en_US","es_ES","et_EE","fa_IR","fi_FI","fr_BE","fr_FR","is_IS","it_IT","ja_JP","ko_KR","nb_NO","nl_BE","nl_NL","pl_PL","pt_BR","pt_PT","sk_SK","sr_RS","sv_SE","th_TH","tr_TR","ru_RU","uk_UA","vi_VN","zh_CN","zh_TW"],
Expand Down
2 changes: 1 addition & 1 deletion schematics/ng-add/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export interface Schema {
/** Name of the project to target. */
project?: string;

locale: 'ar_EG' | 'bg_BG' | 'ca_ES' | 'cs_CZ' | 'de_DE' | 'el_GR' | 'en_GB' | 'en_US' | 'es_ES' | 'et_EE' | 'fa_IR' | 'fi_FI' | 'fr_BE' | 'fr_FR' | 'is_IS' | 'it_IT' | 'ja_JP' | 'ko_KR' | 'nb_NO' | 'nl_BE' | 'nl_NL' | 'pl_PL' | 'pt_BR' | 'pt_PT' | 'sk_SK' | 'sr_RS' | 'sv_SE' | 'th_TH' | 'tr_TR' | 'ru_RU' | 'uk_UA' | 'vi_VN' | 'zh_CN' | 'zh_TW';
i18n: 'ar_EG' | 'bg_BG' | 'ca_ES' | 'cs_CZ' | 'de_DE' | 'el_GR' | 'en_GB' | 'en_US' | 'es_ES' | 'et_EE' | 'fa_IR' | 'fi_FI' | 'fr_BE' | 'fr_FR' | 'is_IS' | 'it_IT' | 'ja_JP' | 'ko_KR' | 'nb_NO' | 'nl_BE' | 'nl_NL' | 'pl_PL' | 'pt_BR' | 'pt_PT' | 'sk_SK' | 'sr_RS' | 'sv_SE' | 'th_TH' | 'tr_TR' | 'ru_RU' | 'uk_UA' | 'vi_VN' | 'zh_CN' | 'zh_TW';
}
4 changes: 0 additions & 4 deletions schematics/utils/custom-theme.ts

This file was deleted.

1 change: 0 additions & 1 deletion schematics/utils/lib-versions.ts

This file was deleted.

2 changes: 1 addition & 1 deletion schematics_script/set-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const theme = fs.readFileSync(path.resolve(__dirname, `../site_scripts/_site/src
fs.outputFileSync(
path.resolve(__dirname, `../schematics/utils/custom-theme.ts`),
`export function createCustomTheme() {
return \`@import "~ng-zorro-antd/src/ng-zorro-antd.less";
return \`@import "../node_modules/ng-zorro-antd/src/ng-zorro-antd.less";

This comment has been minimized.

Copy link
@cipchk

cipchk Jun 7, 2018

Member

其实使用绝对路径会更安全一点。

${theme.replace(/`/g, '\\`')}
\`;
}
Expand Down

0 comments on commit aa953dc

Please sign in to comment.