Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
protected onCompileResult(status: ts.Diagnostic) {
if (this.canCompile()) {
if (status.code === 6031) {
// watching
this.failed = false;
this.compileStart = Date.now();
} else if (status.code === 6032) {
// change detected
this.failed = false;
this.compileStart = Date.now();
const output = Unicode.stringOutput(OutputSettings.styled());
OutputStyle.greenBold(output);
output.write("recompiling");
OutputStyle.reset(output);
output.write(" ");
OutputStyle.yellow(output);
output.write(this.uid);
OutputStyle.reset(output);
console.log(output.bind());
} else if (status.code === 6194) {
// complete
if (!this.failed) {
this.lint();
}
this.emittedSourceFiles.length = 0;
if (!this.failed) {
this.onCompileSuccess();
if (this.selected) {
this.throttleBundle();
}
} else {
this.onCompileFailure();
if (i < specifiers.length) {
const specifier = specifiers[i];
const [projectId] = specifier.split(":");
const project = this.projects[projectId];
if (project) {
const result = callback(project);
if (result) {
return result.then(this.forEachProject.bind(this, specifiers, callback, i + 1));
}
} else {
const output = Unicode.stringOutput(OutputSettings.styled());
OutputStyle.redBold(output);
output.write("unknown project");
OutputStyle.reset(output);
output.write(" ");
OutputStyle.yellow(output);
output.write(projectId);
OutputStyle.reset(output);
console.log(output.bind());
}
return Promise.resolve(void 0).then(this.forEachProject.bind(this, specifiers, callback, i + 1));
} else {
return Promise.resolve(void 0);
}
}
printProjects(): void {
const output = Unicode.stringOutput(OutputSettings.styled());
OutputStyle.greenBold(output);
output.write("projects");
OutputStyle.reset(output);
console.log(output.bind());
for (let i = 0; i < this.projectList.length; i += 1) {
const project = this.projectList[i];
const output = Unicode.stringOutput(OutputSettings.styled());
output.write(" - ");
OutputStyle.yellow(output);
output.write(project.id);
OutputStyle.reset(output);
console.log(output.bind());
}
}
protected onBundleError(error: Error): void {
let output = Unicode.stringOutput(OutputSettings.styled());
OutputStyle.redBold(output);
output.write("error:");
OutputStyle.reset(output);
output.write(" ");
output.write(error.message);
console.log(output.bind());
console.log();
output = Unicode.stringOutput(OutputSettings.styled());
OutputStyle.redBold(output);
output.write("failed to bundle");
OutputStyle.reset(output);
output.write(" ");
OutputStyle.yellow(output);
output.write(this.uid);
OutputStyle.reset(output);
console.log(output.bind());
}
bundle(): Promise {
this.cancelBundle();
this.bundleTimer = -1;
const output = Unicode.stringOutput(OutputSettings.styled());
OutputStyle.greenBold(output);
output.write("bundling");
OutputStyle.reset(output);
output.write(" ");
OutputStyle.yellow(output);
output.write(this.uid);
OutputStyle.reset(output);
console.log(output.bind());
const bundleConfig = this.project.bundleConfig[this.id] as rollup.RollupOptions | undefined;
if (bundleConfig) {
const t0 = Date.now();
const cwd = process.cwd();
process.chdir(this.project.baseDir);
return rollup.rollup(bundleConfig)
.then((build: rollup.RollupBuild): Promise => {
process.chdir(cwd);
if (this.watching) {
bundleConfig.cache = build.cache;
}
return build.generate(bundleConfig.output!);
docTarget.target = this;
docTarget.fileTargetMap = fileTargetMap;
}
const t0 = Date.now();
const project = doc.convert(fileNames);
if (project) {
doc.generateDocs(project, outDir);
const dt = Date.now() - t0;
output = Unicode.stringOutput(OutputSettings.styled());
OutputStyle.greenBold(output);
output.write("documented");
OutputStyle.reset(output);
output.write(" ");
OutputStyle.yellow(output);
output.write(this.uid);
OutputStyle.reset(output);
output.write(" in ");
output.debug(dt);
output.write("ms");
console.log(output.bind());
console.log();
return Promise.resolve();
} else {
const output = Unicode.stringOutput(OutputSettings.styled());
OutputStyle.redBold(output);
output.write("failed to document");
OutputStyle.reset(output);
output.write(" ");
OutputStyle.yellow(output);
output.write(this.uid);
docTarget.target = this;
docTarget.fileTargetMap = fileTargetMap;
}
const t0 = Date.now();
const project = doc.convert(fileNames);
if (project) {
doc.generateDocs(project, outDir);
const dt = Date.now() - t0;
output = Unicode.stringOutput(OutputSettings.styled());
OutputStyle.greenBold(output);
output.write("documented");
OutputStyle.reset(output);
output.write(" ");
OutputStyle.yellow(output);
output.write(this.uid);
OutputStyle.reset(output);
output.write(" in ");
output.debug(dt);
output.write("ms");
console.log(output.bind());
console.log();
return Promise.resolve();
} else {
const output = Unicode.stringOutput(OutputSettings.styled());
OutputStyle.redBold(output);
output.write("failed to document");
OutputStyle.reset(output);
output.write(" ");
OutputStyle.yellow(output);
output.write(this.uid);
watch(): void {
const output = Unicode.stringOutput(OutputSettings.styled());
OutputStyle.greenBold(output);
output.write("watching");
OutputStyle.reset(output);
output.write(" ");
OutputStyle.yellow(output);
output.write(this.uid);
OutputStyle.reset(output);
console.log(output.bind());
const configPath = ts.findConfigFile(this.baseDir, ts.sys.fileExists, "tsconfig.json");
const commandLine = ts.getParsedCommandLineOfConfigFile(configPath!, this.compilerOptions, ts.sys as any)!;
const projectReferences = this.injectProjectReferences(commandLine.projectReferences, commandLine.options);
this.injectCompilerOptions(commandLine.options);
const rootNames = projectReferences.map(ref => ref.path);
rootNames.push(this.baseDir);
const solutionBuilderHost = ts.createSolutionBuilderWithWatchHost(ts.sys, this.createWatchProgram, this.onCompileError,
this.onCompileUpdate, this.onCompileResult);
const solutionBuilder = ts.createSolutionBuilderWithWatch(solutionBuilderHost, rootNames, {incremental: true, watch: true});
this.watching = true;
printTargets(targets: Target[] | string | undefined): void {
if (!Array.isArray(targets)) {
targets = this.transitiveDeps(targets);
}
const output = Unicode.stringOutput(OutputSettings.styled());
OutputStyle.greenBold(output);
output.write("targets");
OutputStyle.reset(output);
console.log(output.bind());
for (let i = 0; i < targets.length; i += 1) {
const target = targets[i];
const output = Unicode.stringOutput(OutputSettings.styled());
output.write(" - ");
if (target.selected) {
OutputStyle.yellow(output);
}
output.write(target.uid);
if (target.selected) {
OutputStyle.reset(output);
}
console.log(output.bind());
}
}