Skip to content

Commit

Permalink
chore: update schematics config (#5038)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsuanxyz authored Apr 17, 2020
1 parent 7bc8279 commit 2c4c537
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 94 deletions.
2 changes: 1 addition & 1 deletion schematics/migration.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"migration-v9": {
"version": "9",
"description": "Updates NG-ZORRO to v9",
"description": "Updates NG-ZORRO to v9 [https://github.com/NG-ZORRO/ng-zorro-antd/issues/5035]",
"factory": "./ng-update/index#updateToV9"
},
"ng-post-update": {
Expand Down
9 changes: 0 additions & 9 deletions schematics/ng-add/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,6 @@ describe('ng-add schematic', () => {
expect(fileContent).toContain('registerLocaleData(zh)');
});

it('should have a deprecation `--i18n` warning', async () => {
const tree = await runner.runSchematicAsync('ng-add-setup-project', {i18n: 'zh_CN'}, appTree).toPromise();
const fileContent = getFileContent(tree, '/projects/ng-zorro/src/app/app.module.ts');

expect(fileContent).toContain('{ provide: NZ_I18N, useValue: zh_CN }');
expect(fileContent).toContain('registerLocaleData(zh)');

});

it('should not add locale id if locale id is set up', async () => {
await runner.runSchematicAsync('ng-add-setup-project', {}, appTree).toPromise();

Expand Down
107 changes: 40 additions & 67 deletions schematics/ng-add/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,58 +19,15 @@
"dynamicIcon": {
"type": "boolean",
"default": false,
"description": "Whether icon assets should be add.",
"x-prompt": "Add icon assets [ Detail: https://ng.ant.design/components/icon/en ]"
"description": "Whether icon should dynamic loading.",
"x-prompt": "Enable icon dynamic loading [ Detail: https://ng.ant.design/components/icon/en ]"
},
"theme": {
"type": "boolean",
"default": false,
"description": "Whether custom theme file should be set up.",
"x-prompt": "Set up custom theme file [ Detail: https://ng.ant.design/docs/customize-theme/en ]"
},
"i18n": {
"type": "string",
"default": "en_US",
"enum": [
"ar_EG",
"bg_BG",
"ca_ES",
"cs_CZ",
"da_DK",
"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",
"ka_GE",
"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"
],
"description": "add locale code to module (e.g., --locale=en_US)"
},
"locale": {
"type": "string",
"description": "Add locale code to module (e.g., --locale=en_US)",
Expand All @@ -80,40 +37,56 @@
"type": "list",
"items": [
"en_US",
"uk_UA",
"de_DE",
"fr_FR",
"zh_CN",
"zh_TW",
"ko_KR",
"ja_JP",
"ar_EG",
"bg_BG",
"ca_ES",
"cs_CZ",
"de_DE",
"el_GR",
"en_GB",
"es_ES",
"et_EE",
"hu_HU",
"it_IT",
"ms_MY",
"nl_NL",
"pt_PT",
"sl_SI",
"th_TH",
"vi_VN",
"bg_BG",
"da_DK",
"en_GB",
"fa_IR",
"he_IL",
"hy_AM",
"ku_IQ",
"nb_NO",
"ro_RO",
"sr_RS",
"ca_ES",
"fi_FI",
"hi_IN",
"id_ID",
"ka_GE",
"lv_LV",
"ne_NP",
"pl_PL",
"ru_RU",
"sv_SE",
"tr_TR",
"es_ES",
"fr_BE",
"fr_FR",
"hr_HR",
"is_IS",
"it_IT",
"ja_JP",
"ka_GE",
"ko_KR",
"nb_NO",
"kn_IN",
"mn_MN",
"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_TW"
"ta_IN"
]
}
},
Expand Down
18 changes: 1 addition & 17 deletions schematics/ng-add/setup-project/register-locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function registerLocale(options: Schema): Rule {
const appModulePath = getAppModulePath(host, getProjectMainFile(project));
const moduleSource = parseSourceFile(host, appModulePath);

const locale = getCompatibleLocal(options);
const locale = options.locale || 'en_US';
const localePrefix = locale.split('_')[ 0 ];

const recorder = host.beginUpdate(appModulePath);
Expand Down Expand Up @@ -52,22 +52,6 @@ export function registerLocale(options: Schema): Rule {
};
}

function getCompatibleLocal(options: Schema): string {
const defaultLocal = 'en_US';
if (options.locale === options.i18n) {
return options.locale;
} else if (options.locale === defaultLocal) {

console.log();
console.log(`${chalk.bgYellow('WARN')} ${chalk.cyan('--i18n')} option will be deprecated, ` +
`use ${chalk.cyan('--locale')} instead`);

return options.i18n;
} else {
return options.locale || defaultLocal;
}
}

function registerLocaleData(moduleSource: ts.SourceFile, modulePath: string, locale: string): Change {
const allImports = findNodes(moduleSource, ts.SyntaxKind.ImportDeclaration);
const allFun = findNodes(moduleSource, ts.SyntaxKind.ExpressionStatement);
Expand Down

0 comments on commit 2c4c537

Please sign in to comment.