From c9b4a7d96122a3d67f6c223f32909aaf471c1747 Mon Sep 17 00:00:00 2001 From: Catalina Peralta Date: Thu, 17 Oct 2024 18:05:46 -0700 Subject: [PATCH 1/6] print example command --- tools/tsp-client/src/typespec.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/tsp-client/src/typespec.ts b/tools/tsp-client/src/typespec.ts index ac0fed6bd71..b0d0df402dc 100644 --- a/tools/tsp-client/src/typespec.ts +++ b/tools/tsp-client/src/typespec.ts @@ -107,6 +107,16 @@ export async function compileTsp({ overrides, }); Logger.debug(`Compiler options: ${JSON.stringify(options)}`); + + const cliOptions = Object.entries(options.options?.[emitterPackage] ?? {}) + .map(([key, value]) => `--option ${key}=${value}`) + .join(" "); + + const exampleCmd = `npx tsp compile ${resolvedMainFilePath} --emit ${emitterPackage} ${cliOptions}`; + Logger.warn(`Example of how to compile using the tsp commandline. tsp-client does NOT directly run this command, results may vary: + ${exampleCmd} + `); + if (diagnostics.length > 0) { let errorDiagnostic = false; // This should not happen, but if it does, we should log it. From ef0742ed5ee603fbc59b6f589fee5545b25a5c0f Mon Sep 17 00:00:00 2001 From: Catalina Peralta Date: Thu, 17 Oct 2024 18:07:53 -0700 Subject: [PATCH 2/6] debug level --- tools/tsp-client/src/typespec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/tsp-client/src/typespec.ts b/tools/tsp-client/src/typespec.ts index b0d0df402dc..0e12f63a7ef 100644 --- a/tools/tsp-client/src/typespec.ts +++ b/tools/tsp-client/src/typespec.ts @@ -113,7 +113,7 @@ export async function compileTsp({ .join(" "); const exampleCmd = `npx tsp compile ${resolvedMainFilePath} --emit ${emitterPackage} ${cliOptions}`; - Logger.warn(`Example of how to compile using the tsp commandline. tsp-client does NOT directly run this command, results may vary: + Logger.debug(`Example of how to compile using the tsp commandline. tsp-client does NOT directly run this command, results may vary: ${exampleCmd} `); From 0cdde815ea5f66b9f12e77cceae2a94d500be03c Mon Sep 17 00:00:00 2001 From: Catalina Peralta Date: Tue, 29 Oct 2024 20:07:54 -0700 Subject: [PATCH 3/6] account for object options --- tools/tsp-client/src/typespec.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tools/tsp-client/src/typespec.ts b/tools/tsp-client/src/typespec.ts index 0e12f63a7ef..7c83d503725 100644 --- a/tools/tsp-client/src/typespec.ts +++ b/tools/tsp-client/src/typespec.ts @@ -73,7 +73,7 @@ export async function compileTsp({ resolvedMainFilePath: string; additionalEmitterOptions?: string; saveInputs?: boolean; -}): Promise { +}): Promise<[boolean, string]> { const parsedEntrypoint = getDirectoryPath(resolvedMainFilePath); const { compile, NodeHost, resolveCompilerOptions } = await importTsp(parsedEntrypoint); @@ -109,13 +109,15 @@ export async function compileTsp({ Logger.debug(`Compiler options: ${JSON.stringify(options)}`); const cliOptions = Object.entries(options.options?.[emitterPackage] ?? {}) - .map(([key, value]) => `--option ${key}=${value}`) + .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}`; - Logger.debug(`Example of how to compile using the tsp commandline. tsp-client does NOT directly run this command, results may vary: - ${exampleCmd} - `); if (diagnostics.length > 0) { let errorDiagnostic = false; @@ -132,7 +134,7 @@ export async function compileTsp({ } } if (errorDiagnostic) { - return false; + return [false, exampleCmd]; } } @@ -152,11 +154,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 { From 0778c5a0b961cc582def74c35c5f9e4f86c87f27 Mon Sep 17 00:00:00 2001 From: Catalina Peralta Date: Tue, 29 Oct 2024 20:08:19 -0700 Subject: [PATCH 4/6] print command later in program execution --- tools/tsp-client/src/commands.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/tsp-client/src/commands.ts b/tools/tsp-client/src/commands.ts index 45a0fee9dfc..e440cb4fcc7 100644 --- a/tools/tsp-client/src/commands.ts +++ b/tools/tsp-client/src/commands.ts @@ -268,7 +268,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, @@ -276,6 +277,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 { From c860eff48fa3bde4d336ac3e56f0e8818a9c35f4 Mon Sep 17 00:00:00 2001 From: Catalina Peralta Date: Fri, 8 Nov 2024 15:20:16 -0800 Subject: [PATCH 5/6] prep for release --- tools/tsp-client/CHANGELOG.md | 4 ++++ tools/tsp-client/package-lock.json | 4 ++-- tools/tsp-client/package.json | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) 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", From f7c282528ce54e38a66197632bc5078036a928b4 Mon Sep 17 00:00:00 2001 From: Catalina Peralta Date: Fri, 8 Nov 2024 15:33:52 -0800 Subject: [PATCH 6/6] fix test --- tools/tsp-client/test/typespec.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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,