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) {
clean(): void {
for (let i = 0; i < this.cleanDirs.length; i += 1) {
const cleanDir = path.resolve(this.baseDir, this.cleanDirs[i]);
const output = Unicode.stringOutput(OutputSettings.styled());
OutputStyle.greenBold(output);
output.write("deleting");
OutputStyle.reset(output);
output.write(" ");
output.write(cleanDir);
console.log(output.bind());
Project.rmdir(cleanDir);
}
}
clean(): void {
this.cleanTargets();
for (let i = 0; i < this.cleanDirs.length; i += 1) {
const cleanDir = path.resolve(this.baseDir, this.cleanDirs[i]);
const output = Unicode.stringOutput(OutputSettings.styled());
OutputStyle.greenBold(output);
output.write("deleting");
OutputStyle.reset(output);
output.write(" ");
output.write(cleanDir);
console.log(output.bind());
Project.rmdir(cleanDir);
}
}
}
const docTarget = doc.converter.getComponent("doc-target");
if (docTarget instanceof DocTarget) {
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");
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);
OutputStyle.redBold(output);
output.write("failed to test");
OutputStyle.reset(output);
output.write(" ");
OutputStyle.yellow(output);
output.write(this.uid);
OutputStyle.reset(output);
console.log(output.bind());
console.log();
}
resolve(0);
});
});
} else {
const output = Unicode.stringOutput(OutputSettings.styled());
OutputStyle.greenBold(output);
output.write("untested");
OutputStyle.reset(output);
output.write(" ");
OutputStyle.yellow(output);
output.write(this.uid);
OutputStyle.reset(output);
console.log(output.bind());
console.log();
return Promise.resolve(0);
}
}
compile(): Promise {
if (this.canCompile()) {
const output = Unicode.stringOutput(OutputSettings.styled());
OutputStyle.greenBold(output);
output.write("compiling");
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 incrementalProgram = ts.createIncrementalProgram({
rootNames: commandLine.fileNames,
options: commandLine.options,
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 onCompileSuccess() {
const dt = Date.now() - this.compileStart;
this.compileStart = 0;
const output = Unicode.stringOutput(OutputSettings.styled());
OutputStyle.greenBold(output);
output.write("compiled");
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();
}
}
const docTarget = doc.converter.getComponent("doc-target");
if (docTarget instanceof DocTarget) {
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");