Skip to content

Commit 0e75cf6

Browse files
committed
Reject task if format argument is unknown
1 parent c279d6e commit 0e75cf6

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

packages/angular-cli/tasks/extract-i18n.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import {Extractor} from '@angular/compiler-cli';
55
import * as tsc from '@angular/tsc-wrapped';
66
import * as ts from 'typescript';
77
import * as path from 'path';
8+
import * as chalk from 'chalk';
89

910
export const Extracti18nTask = Task.extend({
1011
run: function () {
12+
const ui = this.ui;
1113
const project = path.resolve(this.project.root, 'src');
1214
const cliOptions = new tsc.I18nExtractionCliOptions({
1315
i18nFormat: this.i18nFormat
@@ -35,26 +37,29 @@ export const Extracti18nTask = Task.extend({
3537
let ext: string;
3638
let serializer: compiler.Serializer;
3739
const format = (cliOptions.i18nFormat || 'xlf').toLowerCase();
38-
3940
switch (format) {
4041
case 'xmb':
4142
ext = 'xmb';
4243
serializer = new compiler.Xmb();
4344
break;
4445
case 'xliff':
4546
case 'xlf':
46-
default:
4747
const htmlParser = new compiler.I18NHtmlParser(new compiler.HtmlParser());
4848
ext = 'xlf';
4949
serializer = new compiler.Xliff(htmlParser, compiler.DEFAULT_INTERPOLATION_CONFIG);
5050
break;
51+
default:
52+
throw new Error('Unknown i18n output format. For available formats, see \`ng help\`.');
5153
}
5254

5355
const dstPath = path.join(ngOptions.genDir, `messages.${ext}`);
5456
host.writeFile(dstPath, messageBundle.write(serializer), false);
5557
});
5658
}
5759

58-
return tsc.main(project, cliOptions, extract);
60+
return tsc.main(project, cliOptions, extract)
61+
.catch((e) => {
62+
ui.writeLine(chalk.red(e.message));
63+
});
5964
}
6065
});

0 commit comments

Comments
 (0)