From aa953dc108c35f55b337c36e21238ef10f07f05f Mon Sep 17 00:00:00 2001 From: Hsuan Lee Date: Wed, 6 Jun 2018 20:18:12 +0800 Subject: [PATCH] fix(schematic:ng-add): fix import path in theme file (#1611) feat(schematic:ng-add): rename from locale to i18n delete dynamically generated files --- build.sh | 2 -- package.json | 2 +- schematics/README.md | 13 +++++++------ schematics/ng-add/index.ts | 4 ++-- schematics/ng-add/schema.json | 2 +- schematics/ng-add/schema.ts | 2 +- schematics/utils/custom-theme.ts | 4 ---- schematics/utils/lib-versions.ts | 1 - schematics_script/set-theme.js | 2 +- 9 files changed, 13 insertions(+), 19 deletions(-) delete mode 100644 schematics/utils/custom-theme.ts delete mode 100755 schematics/utils/lib-versions.ts diff --git a/build.sh b/build.sh index 772c267ed2..feff90556c 100755 --- a/build.sh +++ b/build.sh @@ -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 diff --git a/package.json b/package.json index ae66e5245b..21aacbccb5 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/schematics/README.md b/schematics/README.md index 8929816716..7568110c0e 100644 --- a/schematics/README.md +++ b/schematics/README.md @@ -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 发布 diff --git a/schematics/ng-add/index.ts b/schematics/ng-add/index.ts index 9b03be7c2d..bb37d03fdf 100644 --- a/schematics/ng-add/index.ts +++ b/schematics/ng-add/index.ts @@ -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) { diff --git a/schematics/ng-add/schema.json b/schematics/ng-add/schema.json index 41747d523a..763e9c0351 100644 --- a/schematics/ng-add/schema.json +++ b/schematics/ng-add/schema.json @@ -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"], diff --git a/schematics/ng-add/schema.ts b/schematics/ng-add/schema.ts index ee150769bf..4eb8bb8702 100644 --- a/schematics/ng-add/schema.ts +++ b/schematics/ng-add/schema.ts @@ -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'; } diff --git a/schematics/utils/custom-theme.ts b/schematics/utils/custom-theme.ts deleted file mode 100644 index b36a256ef5..0000000000 --- a/schematics/utils/custom-theme.ts +++ /dev/null @@ -1,4 +0,0 @@ -export function createCustomTheme() { - return `@import "~ng-zorro-antd/src/ng-zorro-antd.less"; -{{content}}`; -} diff --git a/schematics/utils/lib-versions.ts b/schematics/utils/lib-versions.ts deleted file mode 100755 index 4b2f92b892..0000000000 --- a/schematics/utils/lib-versions.ts +++ /dev/null @@ -1 +0,0 @@ -export const zorroVersion = 'ZORRO_VERSION'; diff --git a/schematics_script/set-theme.js b/schematics_script/set-theme.js index 353c909a36..c6b84688b4 100644 --- a/schematics_script/set-theme.js +++ b/schematics_script/set-theme.js @@ -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"; ${theme.replace(/`/g, '\\`')} \`; }