@@ -5,9 +5,11 @@ import {Extractor} from '@angular/compiler-cli';
5
5
import * as tsc from '@angular/tsc-wrapped' ;
6
6
import * as ts from 'typescript' ;
7
7
import * as path from 'path' ;
8
+ import * as chalk from 'chalk' ;
8
9
9
10
export const Extracti18nTask = Task . extend ( {
10
11
run : function ( ) {
12
+ const ui = this . ui ;
11
13
const project = path . resolve ( this . project . root , 'src' ) ;
12
14
const cliOptions = new tsc . I18nExtractionCliOptions ( {
13
15
i18nFormat : this . i18nFormat
@@ -35,26 +37,29 @@ export const Extracti18nTask = Task.extend({
35
37
let ext : string ;
36
38
let serializer : compiler . Serializer ;
37
39
const format = ( cliOptions . i18nFormat || 'xlf' ) . toLowerCase ( ) ;
38
-
39
40
switch ( format ) {
40
41
case 'xmb' :
41
42
ext = 'xmb' ;
42
43
serializer = new compiler . Xmb ( ) ;
43
44
break ;
44
45
case 'xliff' :
45
46
case 'xlf' :
46
- default :
47
47
const htmlParser = new compiler . I18NHtmlParser ( new compiler . HtmlParser ( ) ) ;
48
48
ext = 'xlf' ;
49
49
serializer = new compiler . Xliff ( htmlParser , compiler . DEFAULT_INTERPOLATION_CONFIG ) ;
50
50
break ;
51
+ default :
52
+ throw new Error ( 'Unknown i18n output format. For available formats, see \`ng help\`.' ) ;
51
53
}
52
54
53
55
const dstPath = path . join ( ngOptions . genDir , `messages.${ ext } ` ) ;
54
56
host . writeFile ( dstPath , messageBundle . write ( serializer ) , false ) ;
55
57
} ) ;
56
58
}
57
59
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
+ } ) ;
59
64
}
60
65
} ) ;
0 commit comments