-
Notifications
You must be signed in to change notification settings - Fork 445
/
Copy pathcompile.ahead.prod.ts
52 lines (46 loc) · 1.8 KB
/
compile.ahead.prod.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import 'reflect-metadata';
import * as ts from 'typescript';
import { argv } from 'yargs';
import { join } from 'path';
import { writeFileSync, readFileSync, readdirSync } from 'fs';
import { CodeGenerator, AngularCompilerOptions, NgcCliOptions, main } from '@angular/compiler-cli';
import Config from '../../config';
function codegen(
ngOptions: AngularCompilerOptions, cliOptions: NgcCliOptions, program: ts.Program,
host: ts.CompilerHost) {
return CodeGenerator.create(ngOptions, cliOptions, program, host).codegen();
}
const modifyFile = (path: string, mod: any = (f: string) => f) => {
const file = readFileSync(path);
writeFileSync(path, mod(file.toString()));
};
export = (done: any) => {
// Note: dirty hack until we're able to set config easier
modifyFile(join(Config.TMP_DIR, 'tsconfig.json'), (content: string) => {
const parsed = JSON.parse(content);
const path = join(Config.PROJECT_ROOT, Config.TOOLS_DIR, 'manual_typings', 'project');
parsed.files = parsed.files || [];
parsed.files = parsed.files.concat(
readdirSync(path)
.filter(f => f.endsWith('d.ts'))
.map(f => join(path, f)));
parsed.files = parsed.files.filter((f: string, i: number) => parsed.files.indexOf(f) === i);
parsed.files.push(join(Config.BOOTSTRAP_DIR, Config.BOOTSTRAP_PROD_MODULE+'.ts'));
return JSON.stringify(parsed, null, 2);
});
const args = argv;
// If a translation, tell the compiler
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);
});
};