Skip to content

Commit

Permalink
refactor(@angular/cli): rename ng xi18n to ng extract-i18n
Browse files Browse the repository at this point in the history
`ng i18n-extract` and `ng xi18n` has been deprecated in favor of `ng extract-i18n` to have a better intuitive naming and match the architect key in `angular.json`.

(cherry picked from commit 33e21e7)
  • Loading branch information
alan-agius4 committed Oct 21, 2020
1 parent 1d39966 commit d85ce56
Show file tree
Hide file tree
Showing 16 changed files with 31 additions and 26 deletions.
6 changes: 3 additions & 3 deletions packages/angular/cli/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ts_library(
"//packages/angular/cli:commands/update.ts",
"//packages/angular/cli:commands/version.ts",
"//packages/angular/cli:commands/run.ts",
"//packages/angular/cli:commands/xi18n.ts",
"//packages/angular/cli:commands/extract-i18n.ts",
# @external_end
],
data = glob(
Expand Down Expand Up @@ -223,8 +223,8 @@ ts_json_schema(
)

ts_json_schema(
name = "xi18n_schema",
src = "commands/xi18n.json",
name = "extract-i18n_schema",
src = "commands/extract-i18n.json",
data = [
"commands/definitions.json",
],
Expand Down
4 changes: 2 additions & 2 deletions packages/angular/cli/commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"deploy": "./commands/deploy.json",
"doc": "./commands/doc.json",
"e2e": "./commands/e2e.json",
"extract-i18n": "./commands/extract-i18n.json",
"make-this-awesome": "./commands/easter-egg.json",
"generate": "./commands/generate.json",
"help": "./commands/help.json",
Expand All @@ -15,6 +16,5 @@
"serve": "./commands/serve.json",
"test": "./commands/test.json",
"update": "./commands/update.json",
"version": "./commands/version.json",
"xi18n": "./commands/xi18n.json"
"version": "./commands/version.json"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

import { ArchitectCommand } from '../models/architect-command';
import { Arguments } from '../models/interface';
import { Schema as Xi18nCommandSchema } from './xi18n';
import { Schema as ExtractI18nCommandSchema } from './extract-i18n';

export class Xi18nCommand extends ArchitectCommand<Xi18nCommandSchema> {
export class ExtractI18nCommand extends ArchitectCommand<ExtractI18nCommandSchema> {
public readonly target = 'extract-i18n';

public async run(options: Xi18nCommandSchema & Arguments) {
public async run(options: ExtractI18nCommandSchema & Arguments) {
const version = process.version.substr(1).split('.');
if (Number(version[0]) === 12 && Number(version[1]) === 0) {
this.logger.error(
Expand All @@ -23,6 +23,11 @@ export class Xi18nCommand extends ArchitectCommand<Xi18nCommandSchema> {
return 1;
}

const commandName = process.argv[2];
if (['xi18n', 'i18n-extract'].includes(commandName)) {
this.logger.warn(`Warning: "ng ${commandName}" has been deprecated and will be removed in a future major version. Please use "ng extract-i18n" instead.`);
}

return this.runArchitectTarget(options);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"$schema": "http://json-schema.org/schema",
"$id": "ng-cli://commands/xi18n.json",
"$id": "ng-cli://commands/extract-i18n.json",
"description": "Extracts i18n messages from source code.",
"$longDescription": "",

"$aliases": ["i18n-extract"],
"$aliases": ["i18n-extract", "xi18n"],
"$scope": "in",
"$type": "architect",
"$impl": "./xi18n-impl#Xi18nCommand",
"$impl": "./extract-i18n-impl#ExtractI18nCommand",

"type": "object",
"allOf": [
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/cli/models/command-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const standardCommands = {
'config': '../commands/config.json',
'doc': '../commands/doc.json',
'e2e': '../commands/e2e.json',
'extract-i18n': '../commands/extract-i18n.json',
'make-this-awesome': '../commands/easter-egg.json',
'generate': '../commands/generate.json',
'help': '../commands/help.json',
Expand All @@ -49,7 +50,6 @@ const standardCommands = {
'test': '../commands/test.json',
'update': '../commands/update.json',
'version': '../commands/version.json',
'xi18n': '../commands/xi18n.json',
};

export interface CommandMapOptions {
Expand Down
2 changes: 1 addition & 1 deletion tests/legacy-cli/e2e/tests/i18n/extract-default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default async function() {
join('src/app/i18n-test', 'i18n-test.component.html'),
'<p i18n>Hello world</p>',
);
await ng('xi18n');
await ng('extract-i18n');
await expectFileToExist('messages.xlf');
await expectFileToMatch('messages.xlf', /Hello world/);
}
2 changes: 1 addition & 1 deletion tests/legacy-cli/e2e/tests/i18n/extract-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default async function () {
'<p i18n>Hello world <span i18n>inner</span></p>',
);

const { message } = await expectToFail(() => ng('xi18n'));
const { message } = await expectToFail(() => ng('extract-i18n'));

const veProject = getGlobalVariable('argv')['ve'];
const msg = veProject
Expand Down
2 changes: 1 addition & 1 deletion tests/legacy-cli/e2e/tests/i18n/extract-ivy-libraries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default async function() {
await installPackage(localizeVersion);

// Extract messages
await ng('xi18n', '--ivy');
await ng('extract-i18n', '--ivy');
await expectFileToMatch('messages.xlf', 'Hello world');
await expectFileToMatch('messages.xlf', 'i18n-lib-test works!');
await expectFileToMatch('messages.xlf', 'src/app/app.component.html');
Expand Down
8 changes: 4 additions & 4 deletions tests/legacy-cli/e2e/tests/i18n/extract-ivy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default async function() {
);

// Should fail with --ivy flag if `@angular/localize` is missing
const { message: message1 } = await expectToFail(() => ng('xi18n'));
const { message: message1 } = await expectToFail(() => ng('extract-i18n'));
if (!message1.includes(`Ivy extraction requires the '@angular/localize' package.`)) {
throw new Error('Expected localize package error message when missing');
}
Expand All @@ -34,13 +34,13 @@ export default async function() {
await installPackage(localizeVersion);

// Should show ivy enabled application warning without --ivy flag
const { stderr: message3 } = await ng('xi18n', '--no-ivy');
const { stderr: message3 } = await ng('extract-i18n', '--no-ivy');
if (!message3.includes(`Ivy extraction not enabled but application is Ivy enabled.`)) {
throw new Error('Expected ivy enabled application warning');
}

// Should not show any warnings when extracting
const { stderr: message5 } = await ng('xi18n', '--ivy');
const { stderr: message5 } = await ng('extract-i18n', '--ivy');
if (message5.includes('WARNING')) {
throw new Error('Expected no warnings to be shown');
}
Expand All @@ -53,7 +53,7 @@ export default async function() {
});

// Should show ivy disabled application warning with --ivy flag and enableIvy false
const { message: message4 } = await expectToFail(() => ng('xi18n', '--ivy'));
const { message: message4 } = await expectToFail(() => ng('extract-i18n', '--ivy'));
if (!message4.includes(`Ivy extraction enabled but application is not Ivy enabled.`)) {
throw new Error('Expected ivy disabled application warning');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/legacy-cli/e2e/tests/i18n/extract-locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function() {
.then(() => writeFile(
join('src/app/i18n-test', 'i18n-test.component.html'),
'<p i18n>Hello world</p>'))
.then(() => ng('xi18n', '--i18n-locale', 'fr'))
.then(() => ng('extract-i18n', '--i18n-locale', 'fr'))
.then((output) => {
if (!output.stderr.match(/starting from Angular v4/)) {
return expectFileToMatch('messages.xlf', 'source-language="fr"');
Expand Down
2 changes: 1 addition & 1 deletion tests/legacy-cli/e2e/tests/i18n/extract-outfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export default async function () {
join('src/app/i18n-test', 'i18n-test.component.html'),
'<p i18n>Hello world</p>',
);
await ng('xi18n', '--out-file', 'messages.fr.xlf');
await ng('extract-i18n', '--out-file', 'messages.fr.xlf');
await expectFileToMatch('messages.fr.xlf', 'Hello world');
}
2 changes: 1 addition & 1 deletion tests/legacy-cli/e2e/tests/i18n/extract-xmb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function() {
.then(() =>
writeFile(join('src/app/i18n-test', 'i18n-test.component.html'), '<p i18n>Hello world</p>'),
)
.then(() => ng('xi18n', '--format', 'xmb'))
.then(() => ng('extract-i18n', '--format', 'xmb'))
.then(() => expectFileToExist('messages.xmb'))
.then(() => expectFileToMatch('messages.xmb', /Hello world/));
}
2 changes: 1 addition & 1 deletion tests/legacy-cli/e2e/tests/i18n/ivy-localize-app-shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default async function () {
);

// Extract the translation messages and copy them for each language.
await ng('xi18n', '--output-path=src/locale');
await ng('extract-i18n', '--output-path=src/locale');
await expectFileToExist('src/locale/messages.xlf');
await expectFileToMatch('src/locale/messages.xlf', `source-language="en-US"`);
await expectFileToMatch('src/locale/messages.xlf', `An introduction header for this sample`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default async function() {
);

// Extract the translation messages and copy them for each language.
await ng('xi18n', '--output-path=src/locale');
await ng('extract-i18n', '--output-path=src/locale');
await expectFileToExist('src/locale/messages.xlf');
await expectFileToMatch('src/locale/messages.xlf', `source-language="en-US"`);
await expectFileToMatch('src/locale/messages.xlf', `An introduction header for this sample`);
Expand Down
2 changes: 1 addition & 1 deletion tests/legacy-cli/e2e/tests/i18n/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export async function setupI18nConfig(useLocalize = true, format: keyof typeof f

// Extract the translation messages.
await ng(
'xi18n',
'extract-i18n',
'--output-path=src/locale',
`--format=${format}`,
);
Expand Down
2 changes: 1 addition & 1 deletion tests/legacy-cli/e2e/utils/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export function execAndWaitForOutputToMatch(cmd: string, args: string[], match:
export function ng(...args: string[]) {
const argv = getGlobalVariable('argv');
const maybeSilentNg = argv['nosilent'] ? noSilentNg : silentNg;
if (['build', 'serve', 'test', 'e2e', 'xi18n'].indexOf(args[0]) != -1) {
if (['build', 'serve', 'test', 'e2e', 'extract-i18n'].indexOf(args[0]) != -1) {
if (args[0] == 'e2e') {
// Wait 1 second before running any end-to-end test.
return new Promise(resolve => setTimeout(resolve, 1000))
Expand Down

0 comments on commit d85ce56

Please sign in to comment.