import 'reflect-metadata' ; import * as ts from 'typescript' ; import { argv } from 'yargs' ; import { join } from 'path' ; import { writeFileSync , readFileSync } from 'fs' ; import { CodeGenerator , AngularCompilerOptions , NgcCliOptions , main } from '@angular/compiler-cli' ; import Config from '../../config' ; function codegen ( ngOptions , cliOptions , program , host ) { return CodeGenerator . create ( ngOptions , cliOptions , program , host ) . codegen ( { transitiveModules : true } ) ; } const modifyFile = ( path , mod = ( f ) => f ) => { const file = readFileSync ( path ) ; writeFileSync ( path , mod ( file . toString ( ) ) ) ; } ; export = ( done ) => { modifyFile ( join ( Config . TMP_DIR , 'tsconfig.json' ) , ( content ) => { const parsed = JSON . parse ( content ) ; parsed . files = parsed . files || [ ] ; parsed . files . push ( join ( Config . BOOTSTRAP_DIR , 'main.ts' ) ) ; return JSON . stringify ( parsed , null , 2 ) ; } ) ; const args = argv ; if ( args . lang ) { args [ 'i18nFile' ] = `./src/client/assets/locale/messages.${ args . lang }.xlf` ; args [ 'locale' ] = args . lang ; args [ 'i18nFormat' ] = 'xlf' ; } const cliOptions = new NgcCliOptions ( args ) ; main ( Config . TMP_DIR , cliOptions , codegen ) . then ( done ) . catch ( e => { console . error ( e . stack ) ; console . error ( 'Compilation failed' ) ; process . exit ( 1 ) ; } ) ; } ;