Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion tools/tsp-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,17 @@ async function generate({
args.push("--force");
}
await npmCommand(srcDir, args);
await compileTsp({ emitterPackage: emitter, outputPath: rootUrl, resolvedMainFilePath, saveInputs: noCleanup, additionalEmitterOptions });
const succeeded = await compileTsp({ emitterPackage: emitter, outputPath: rootUrl, resolvedMainFilePath, saveInputs: noCleanup, additionalEmitterOptions });

if (noCleanup) {
Logger.debug(`Skipping cleanup of temp directory: ${tempRoot}`);
} else {
Logger.debug("Cleaning up temp directory");
await removeDirectory(tempRoot);
}
if (!succeeded) {
process.exit(1);
}
}


Expand Down
14 changes: 8 additions & 6 deletions tools/tsp-client/src/typespec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export async function compileTsp({
resolvedMainFilePath: string;
additionalEmitterOptions?: string;
saveInputs?: boolean;
}) {
}): Promise<boolean> {
const parsedEntrypoint = getDirectoryPath(resolvedMainFilePath);
const { compile, NodeHost, resolveCompilerOptions } = await importTsp(parsedEntrypoint);

Expand Down Expand Up @@ -100,19 +100,21 @@ export async function compileTsp({
Logger.debug(`Compiler options: ${JSON.stringify(options)}`);
if (diagnostics.length > 0) {
// This should not happen, but if it does, we should log it.
Logger.debug(`Compiler options diagnostic information: ${JSON.stringify(diagnostics)}`);
Logger.error("Diagnostics were reported while resolving compiler options...")
diagnostics.forEach((diagnostic) => { Logger.error(formatDiagnostic(diagnostic)); });
return false;
}

const program = await compile(NodeHost, resolvedMainFilePath, options);

if (program.diagnostics.length > 0) {
for (const diagnostic of program.diagnostics) {
Logger.error(formatDiagnostic(diagnostic));
}
process.exit(1);
Logger.error("Diagnostics were reported during compilation...");
program.diagnostics.forEach((diagnostic) => { Logger.error(formatDiagnostic(diagnostic)); });
return false;
} else {
Logger.success("generation complete");
}
return true;
}

export async function importTsp(baseDir: string): Promise<typeof import("@typespec/compiler")> {
Expand Down