Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#!/usr/bin/env node
"use strict";
require('reflect-metadata');
var tsc = require('@angular/tsc-wrapped');
var codegen_1 = require('./codegen');
function codegen(ngOptions, cliOptions, program, host) {
return codegen_1.CodeGenerator.create(ngOptions, cliOptions, program, host).codegen();
}
// CLI entry point
if (require.main === module) {
var args = require('minimist')(process.argv.slice(2));
var project = args.p || args.project || '.';
var cliOptions = new tsc.NgcCliOptions(args);
tsc.main(project, cliOptions, codegen).then(function (exitCode) { return process.exit(exitCode); }).catch(function (e) {
console.error(e.stack);
console.error('Compilation failed');
process.exit(1);
});
}
//# sourceMappingURL=main.js.map
function main(args, consoleError) {
if (consoleError === void 0) { consoleError = console.error; }
var project = args.p || args.project || '.';
var cliOptions = new tsc.NgcCliOptions(args);
return tsc.main(project, cliOptions, codegen).then(function () { return 0; }).catch(function (e) {
if (e instanceof tsc.UserError || e instanceof compiler_1.SyntaxError) {
consoleError(e.message);
return Promise.resolve(1);
}
else {
consoleError(e.stack);
consoleError('Compilation failed');
return Promise.resolve(1);
}
});
}
exports.main = main;
function main(args, consoleError) {
if (consoleError === void 0) { consoleError = console.error; }
var project = args.p || args.project || '.';
var cliOptions = new tsc.NgcCliOptions(args);
return tsc.main(project, cliOptions, codegen).then(function () { return 0; }).catch(function (e) {
if (e instanceof tsc.UserError || compiler_1.isSyntaxError(e)) {
consoleError(e.message);
return Promise.resolve(1);
}
else {
consoleError(e.stack);
consoleError('Compilation failed');
return Promise.resolve(1);
}
});
}
exports.main = main;
function disabledTransformerPipelineNgcMain(
args: any, consoleError: (s: string) => void = console.error): Promise {
const cliOptions = new tsc.NgcCliOptions(args);
const project = args.p || args.project || '.';
return tsc.main(project, cliOptions, disabledTransformerPipelineCodegen)
.then(() => 0)
.catch(e => {
if (e instanceof tsc.UserError || isSyntaxError(e)) {
consoleError(e.message);
} else {
consoleError(e.stack);
}
return Promise.resolve(1);
});
}
function main(args, consoleError) {
if (consoleError === void 0) { consoleError = console.error; }
var project = args.p || args.project || '.';
var cliOptions = new tsc.NgcCliOptions(args);
return tsc.main(project, cliOptions, codegen).then(function () { return 0; }).catch(function (e) {
if (e instanceof tsc.UserError || compiler_1.isSyntaxError(e)) {
consoleError(e.message);
return Promise.resolve(1);
}
else {
consoleError(e.stack);
consoleError('Compilation failed');
return Promise.resolve(1);
}
});
}
exports.main = main;
return Observable.create(observer => {
let start: Date = new Date();
const cliOptions = new tsc.NgcCliOptions({});
spinner.start('Building...');
tsc.main(path.resolve(__dirname, `../../${config}`), cliOptions, this.codegen)
.then(() => {
let time: number = new Date().getTime() - start.getTime();
spinner.stop();
observer.next(`${chalk.green('✔')} AoT Build Time: ${timeHuman(time)}`);
observer.complete();
})
.catch(err => {
observer.next(chalk.red(`✖ Compile error: ${err}`));
observer.error();
});
});
}
export const compileTemplates = async (options: CompileOptions, program: Program, compilerHost: TsCompilerHost): Promise<[TsCompilerHost, Array]> => {
const hostContext = new NodeCompilerHostContext();
const ngCompiler = compilerFactory(program, options.angular, hostContext);
const cli = new NgcCliOptions({
i18nFormat: null,
i18nFile: null,
locale: null,
basePath: options.angular.basePath
});
const generatedModules = await generateAngularCode(program, ngCompiler, compilerHost, cli);
const metadataWriter = new MetadataWriterHost(compilerHost, options.angular);
metadataWriter.writeFile = compilerHost.writeFile;
return [metadataWriter, generatedModules];
};
private async generateTemplates(): Promise<[CompilerHost, Array]> {
const hostContext = new NodeCompilerHostContext();
const compiler = this.compilerFactory(hostContext);
const cli = new NgcCliOptions({
i18nFormat: null,
i18nFile: null,
locale: null,
basePath: this.ng.basePath
});
const generatedModules = await this.generateTemplateCode(compiler, cli);
const metadataWriter = new MetadataWriterHost(this.compilerHost, this.ng, true);
return [metadataWriter, generatedModules];
}