diff --git a/tools/tsp-client/CHANGELOG.md b/tools/tsp-client/CHANGELOG.md index ae897f2e830..b32831f367c 100644 --- a/tools/tsp-client/CHANGELOG.md +++ b/tools/tsp-client/CHANGELOG.md @@ -1,5 +1,9 @@ # Release +## 2024-11-08 - 0.14.1 + +- Print an example `tsp compile` call when the `--debug` flag is passed to a `tsp-client` command. + ## 2024-11-07 - 0.14.0 - Fix `init` command when using a local spec: diff --git a/tools/tsp-client/package-lock.json b/tools/tsp-client/package-lock.json index 42bd3128720..8e50d529e77 100644 --- a/tools/tsp-client/package-lock.json +++ b/tools/tsp-client/package-lock.json @@ -1,12 +1,12 @@ { "name": "@azure-tools/typespec-client-generator-cli", - "version": "0.14.0", + "version": "0.14.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@azure-tools/typespec-client-generator-cli", - "version": "0.14.0", + "version": "0.14.1", "license": "MIT", "dependencies": { "@autorest/core": "^3.10.2", diff --git a/tools/tsp-client/package.json b/tools/tsp-client/package.json index 5e886180818..e9874509693 100644 --- a/tools/tsp-client/package.json +++ b/tools/tsp-client/package.json @@ -1,6 +1,6 @@ { "name": "@azure-tools/typespec-client-generator-cli", - "version": "0.14.0", + "version": "0.14.1", "description": "A tool to generate Azure SDKs from TypeSpec", "main": "dist/index.js", "homepage": "https://github.com/Azure/azure-sdk-tools/tree/main/tools/tsp-client#readme", diff --git a/tools/tsp-client/src/commands.ts b/tools/tsp-client/src/commands.ts index f792decfd95..0dc3a35a826 100644 --- a/tools/tsp-client/src/commands.ts +++ b/tools/tsp-client/src/commands.ts @@ -276,7 +276,8 @@ export async function generateCommand(argv: any) { args.push("--force"); } await npmCommand(srcDir, args); - const success = await compileTsp({ + + const [success, exampleCmd] = await compileTsp({ emitterPackage: emitter, outputPath: outputDir, resolvedMainFilePath, @@ -284,6 +285,12 @@ export async function generateCommand(argv: any) { additionalEmitterOptions: emitterOptions, }); + if (argv["debug"]) { + Logger.warn(`Example of how to compile using the tsp commandline. NOTE: tsp-client does NOT directly run this command, results may vary: + ${exampleCmd} + `); + } + if (saveInputs) { Logger.debug(`Skipping cleanup of temp directory: ${tempRoot}`); } else { diff --git a/tools/tsp-client/src/typespec.ts b/tools/tsp-client/src/typespec.ts index 7037f483c83..c20ce39a1a6 100644 --- a/tools/tsp-client/src/typespec.ts +++ b/tools/tsp-client/src/typespec.ts @@ -68,7 +68,7 @@ export async function compileTsp({ resolvedMainFilePath: string; additionalEmitterOptions?: string; saveInputs?: boolean; -}): Promise { +}): Promise<[boolean, string]> { const parsedEntrypoint = getDirectoryPath(resolvedMainFilePath); const { compile, NodeHost, resolveCompilerOptions, formatDiagnostic } = await importTsp(parsedEntrypoint); @@ -103,6 +103,18 @@ export async function compileTsp({ overrides, }); Logger.debug(`Compiler options: ${JSON.stringify(options)}`); + + const cliOptions = Object.entries(options.options?.[emitterPackage] ?? {}) + .map(([key, value]) => { + if (typeof value === "object") { + value = JSON.stringify(value); + } + return `--option ${key}=${value}`; + }) + .join(" "); + + const exampleCmd = `npx tsp compile ${resolvedMainFilePath} --emit ${emitterPackage} ${cliOptions}`; + if (diagnostics.length > 0) { let errorDiagnostic = false; // This should not happen, but if it does, we should log it. @@ -118,7 +130,7 @@ export async function compileTsp({ } } if (errorDiagnostic) { - return false; + return [false, exampleCmd]; } } @@ -138,11 +150,11 @@ export async function compileTsp({ } } if (errorDiagnostic) { - return false; + return [false, exampleCmd]; } } Logger.success("generation complete"); - return true; + return [true, exampleCmd]; } export async function importTsp(baseDir: string): Promise { diff --git a/tools/tsp-client/test/typespec.spec.ts b/tools/tsp-client/test/typespec.spec.ts index ccdad96f70c..6a7f5bbe9e1 100644 --- a/tools/tsp-client/test/typespec.spec.ts +++ b/tools/tsp-client/test/typespec.spec.ts @@ -9,7 +9,7 @@ describe("Check diagnostic reporting", function () { resolvePath(process.cwd(), "test", "examples", "specification", "diagnostics"), ); try { - const succeeded = await compileTsp({ + const [succeeded, _] = await compileTsp({ emitterPackage: "@azure-tools/typespec-ts", outputPath: joinPaths(process.cwd(), "examples"), resolvedMainFilePath: mainFile,