diff --git a/common/changes/@autorest/core/fix-message-format_2021-10-05-17-04.json b/common/changes/@autorest/core/fix-message-format_2021-10-05-17-04.json new file mode 100644 index 000000000..895c2cfb9 --- /dev/null +++ b/common/changes/@autorest/core/fix-message-format_2021-10-05-17-04.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@autorest/core", + "comment": "", + "type": "none" + } + ], + "packageName": "@autorest/core", + "email": "tiguerin@microsoft.com" +} \ No newline at end of file diff --git a/packages/apps/autorest/CHANGELOG.json b/packages/apps/autorest/CHANGELOG.json index 9c2fd6c51..13b02352d 100644 --- a/packages/apps/autorest/CHANGELOG.json +++ b/packages/apps/autorest/CHANGELOG.json @@ -1,6 +1,18 @@ { "name": "autorest", "entries": [ + { + "version": "3.4.1", + "tag": "autorest_v3.4.1", + "date": "Tue, 05 Oct 2021 17:04:21 GMT", + "comments": { + "patch": [ + { + "comment": "**fix** Respect `message-format` option" + } + ] + } + }, { "version": "3.4.0", "tag": "autorest_v3.4.0", diff --git a/packages/apps/autorest/CHANGELOG.md b/packages/apps/autorest/CHANGELOG.md index ba985f522..9d53d8e23 100644 --- a/packages/apps/autorest/CHANGELOG.md +++ b/packages/apps/autorest/CHANGELOG.md @@ -1,6 +1,13 @@ # Change Log - autorest -This log was last generated on Wed, 08 Sep 2021 15:39:22 GMT and should not be manually modified. +This log was last generated on Tue, 05 Oct 2021 17:04:21 GMT and should not be manually modified. + +## 3.4.1 +Tue, 05 Oct 2021 17:04:21 GMT + +### Patches + +- **fix** Respect `message-format` option ## 3.4.0 Wed, 08 Sep 2021 15:39:22 GMT @@ -105,7 +112,7 @@ Thu, 11 Feb 2021 18:03:07 GMT ### Patches -- **Update** @azure-tools/extension to ~3.1.272 +- **Update** @azure-tools/extension to ~3.1.272 - **Internals** Update chalk dependency to ^4.1.0 ## 3.0.6338 @@ -143,7 +150,7 @@ Mon, 10 Feb 2020 00:00:00 GMT - drop unreferenced requestBodies during merge - supports v2 generators (and will by default, fall back to a v2 core unless overriden with `--version:` - if a v3 generator is loaded via `--use:` , it should not attempt to load v2 generator even if `--[generator]` is specified (ie, `--python` `--use:./python` ) should be perfectly fine -- the v3 generator name in `package.json` should be `@autorest/[name]` - ie `@autorest/csharp` -- it will only assume `--tag=all-api-versions` if either `--profile:`... or `--api-version:`... is specified. +- the v3 generator name in `package.json` should be `@autorest/[name]` - ie `@autorest/csharp` +- it will only assume `--tag=all-api-versions` if either `--profile:`... or `--api-version:`... is specified. - rebuild to pick up newer extension library that supports python interpreter detection diff --git a/packages/apps/autorest/package.json b/packages/apps/autorest/package.json index 1f81f9c4a..b5665ef6d 100644 --- a/packages/apps/autorest/package.json +++ b/packages/apps/autorest/package.json @@ -1,6 +1,6 @@ { "name": "autorest", - "version": "3.4.0", + "version": "3.4.1", "description": "The AutoRest tool generates client libraries for accessing RESTful web services. Input to AutoRest is an OpenAPI spec that describes the REST API.", "engines": { "node": ">=12.0.0" @@ -41,7 +41,7 @@ "typings": "./dist/exports.d.ts", "devDependencies": { "@autorest/configuration": "~1.7.2", - "@autorest/core": "~3.6.3", + "@autorest/core": "~3.6.4", "@autorest/common": "~1.3.0", "@azure-tools/async-io": "~3.0.0", "@azure-tools/extension": "~3.3.1", diff --git a/packages/apps/autorest/src/app.ts b/packages/apps/autorest/src/app.ts index 829f2cf0a..3501df1f8 100644 --- a/packages/apps/autorest/src/app.ts +++ b/packages/apps/autorest/src/app.ts @@ -9,6 +9,7 @@ import "source-map-support/register"; declare const isDebuggerEnabled: boolean; const cwd = process.cwd(); +import { AutorestSyncLogger, ConsoleLoggerSink } from "@autorest/common"; import chalk from "chalk"; import { clearTempData } from "./actions"; import { parseAutorestArgs } from "./args"; @@ -96,7 +97,15 @@ async function main() { } catch { // We have a chance to fail again later if this proves problematic. } - const config = await loadConfig(args); + const sink = new ConsoleLoggerSink({ format: args["message-format"] }); + const logger = new AutorestSyncLogger({ + sinks: [sink], + }); + const config = await loadConfig(sink, args); + if (config?.version) { + logger.info(`AutoRest core version selected from configuration: ${chalk.yellow.bold(config.version)}.`); + } + const coreVersionPath = await resolveCoreVersion(config); // let's strip the extra stuff from the command line before we require the core module. @@ -132,7 +141,7 @@ async function main() { process.argv = newArgs; if (args.debug) { - console.log(`Starting ${newCorePackage} from ${coreVersionPath}`); + logger.debug(`Starting ${newCorePackage} from ${coreVersionPath}`); } // reset the working folder to the correct place. diff --git a/packages/apps/autorest/src/utils.ts b/packages/apps/autorest/src/utils.ts index eedba9723..c1fa60de1 100644 --- a/packages/apps/autorest/src/utils.ts +++ b/packages/apps/autorest/src/utils.ts @@ -1,5 +1,5 @@ import { dirname, join, resolve } from "path"; -import { AutorestSyncLogger, ConsoleLoggerSink } from "@autorest/common"; +import { AutorestLogger, AutorestSyncLogger, ConsoleLoggerSink, IAutorestLogger, LoggerSink } from "@autorest/common"; import { AutorestConfiguration, AutorestNormalizedConfiguration, ConfigurationLoader } from "@autorest/configuration"; import { isFile } from "@azure-tools/async-io"; import { createFileOrFolderUri, createFolderUri, resolveUri } from "@azure-tools/uri"; @@ -33,12 +33,11 @@ const cwd = process.cwd(); * Tries to load the configuration of autorest. * @param args CLI args. */ -export async function loadConfig(args: AutorestArgs): Promise { +export async function loadConfig(sink: LoggerSink, args: AutorestArgs): Promise { const configFileOrFolder = resolveUri(createFolderUri(cwd), args.configFileOrFolder || "."); const enableLogging = args["debug-cli-config-loading"]; - const logger = new AutorestSyncLogger({ - sinks: enableLogging ? [new ConsoleLoggerSink()] : [], + sinks: enableLogging ? [sink] : [], }); const loader = new ConfigurationLoader(logger, defaultConfigUri, configFileOrFolder, { @@ -46,12 +45,6 @@ export async function loadConfig(args: AutorestArgs): Promise=12.0.0" diff --git a/packages/extensions/core/src/app.ts b/packages/extensions/core/src/app.ts index d3c639377..2ab0133e8 100644 --- a/packages/extensions/core/src/app.ts +++ b/packages/extensions/core/src/app.ts @@ -14,6 +14,7 @@ import { AutorestLogger, AutorestSyncLogger, Exception, + IAutorestLogger, } from "@autorest/common"; import { AutorestCliArgs, parseAutorestCliArgs } from "@autorest/configuration"; @@ -103,9 +104,9 @@ csharp: let exitcode = 0; let cleared = false; -async function doClearFolders(protectFiles: Set, clearFolders: Set) { +async function doClearFolders(protectFiles: Set, clearFolders: Set, logger: IAutorestLogger) { if (!cleared) { - timestampDebugLog("Clearing Folders."); + logger.debug("Clearing Folders."); cleared = true; for (const folder of clearFolders) { try { @@ -120,32 +121,7 @@ async function doClearFolders(protectFiles: Set, clearFolders: Set): Promise { - if (autorestArgs[0] === "init") { - await autorestInit(); - return 0; - } - - // add probes for readme.*.md files when a standalone arg is given. - const more = []; - for (const each of autorestArgs) { - const match = /^--([^=:]+)([=:](.+))?$/g.exec(each); - if (match && !match[3]) { - // it's a solitary --foo (ie, no specified value) argument - more.push(`--try-require=readme.${match[1]}.md`); - } - } - - // We need to check if verbose logging should be enabled before parsing the args. - verbose = verbose || autorestArgs.indexOf("--verbose") !== -1; - - const args = parseAutorestCliArgs([...autorestArgs, ...more]); - - const logger = new AutorestSyncLogger({ - sinks: [new ConsoleLogger()], - processors: [new FilterLogger({ level: getLogLevel(args.options) })], - }); - +async function currentMain(logger: IAutorestLogger, args: AutorestCliArgs): Promise { if (!args.options["message-format"] || args.options["message-format"] === "regular") { logger.info(`> Loading AutoRest core '${__dirname}' (${VERSION})`); } @@ -202,7 +178,7 @@ async function currentMain(autorestArgs: Array): Promise { } if (context.config["batch"]) { - await batch(api, args, logger); + await batch(api, logger); } else { const result = await api.Process().finish; if (result !== true) { @@ -252,12 +228,12 @@ async function currentMain(autorestArgs: Array): Promise { } } else { // perform file system operations. - await doClearFolders(protectFiles, clearFolders); + await doClearFolders(protectFiles, clearFolders, logger); - timestampDebugLog("Writing Outputs."); + logger.debug("Writing Outputs."); await artifactWriter.wait(); } - timestampLog("Generation Complete"); + logger.info("Generation Complete"); // return the exit code to the caller. return exitcode; } @@ -296,7 +272,7 @@ function getRds(schema: any, path: string): Array { return result; } -async function resourceSchemaBatch(api: AutoRest, logger: AutorestLogger): Promise { +async function resourceSchemaBatch(api: AutoRest, logger: IAutorestLogger): Promise { // get the configuration const outputs = new Map(); const schemas = new Array(); @@ -364,15 +340,12 @@ async function resourceSchemaBatch(api: AutoRest, logger: AutorestLogger): Promi return exitcode; } -async function batch(api: AutoRest, args: AutorestCliArgs, logger: AutorestLogger): Promise { +async function batch(api: AutoRest, logger: IAutorestLogger): Promise { const config = await api.view; const batchTaskConfigReference: any = {}; api.AddConfiguration(batchTaskConfigReference); for (const batchTaskConfig of config.GetEntry("batch")) { - const isjson = args.options["message-format"] === "json"; - if (!isjson) { - logger.info(`Processing batch task - ${JSON.stringify(batchTaskConfig)} .`); - } + logger.info(`Processing batch task - ${JSON.stringify(batchTaskConfig)} .`); // update batch task config section for (const key of Object.keys(batchTaskConfigReference)) { delete batchTaskConfigReference[key]; @@ -391,61 +364,64 @@ async function batch(api: AutoRest, args: AutorestCliArgs, logger: AutorestLogge } } -/** - * Entry point - */ -async function mainImpl(): Promise { - let autorestArgs: Array = []; - const exitcode = 0; +async function main() { + const argv = process.argv.slice(2); + if (argv[0] === "init") { + await autorestInit(); + return; + } + const args = await getCliArgs(argv); + const logger = new AutorestSyncLogger({ + sinks: [new ConsoleLogger({ format: args.options["message-format"] })], + processors: [new FilterLogger({ level: getLogLevel(args.options) })], + }); + + let exitCode = 0; try { - autorestArgs = process.argv.slice(2); - - return await currentMain(autorestArgs); + return await currentMain(logger, args); } catch (e) { // be very careful about the following check: // - doing the inversion (instanceof Error) doesn't reliably work since that seems to return false on Errors marshalled from safeEval if (e instanceof Exception) { - console.log(e.message); - return e.exitCode; + logger.log({ level: "error", message: e.message }); + exitCode = e.exitCode; } if (e !== false) { - console.error(color(`!${e}`)); + logger.log({ level: "error", message: `!${e}` }); } - } - return 1; -} - -function timestampLog(content: string) { - console.log(color(`[${Math.floor(process.uptime() * 100) / 100} s] ${content}`)); -} - -function timestampDebugLog(content: string) { - if (debug) { - console.log(color(`[${Math.floor(process.uptime() * 100) / 100} s] ${content}`)); - } -} - -async function main() { - let exitcode = 0; - try { - exitcode = await mainImpl(); - } catch { - exitcode = 102; } finally { try { - timestampDebugLog("Shutting Down."); + logger.debug("Shutting Down."); await Shutdown(); } catch { - timestampDebugLog("Shutting Down: (trouble?)"); + logger.debug("Shutting Down: (trouble?)"); } finally { - timestampDebugLog("Exiting."); + logger.debug("Exiting."); // eslint-disable-next-line no-process-exit process.exit(exitcode); } } } +async function getCliArgs(argv: string[]) { + // add probes for readme.*.md files when a standalone arg is given. + const more = []; + for (const each of argv) { + const match = /^--([^=:]+)([=:](.+))?$/g.exec(each); + if (match && !match[3]) { + // it's a solitary --foo (ie, no specified value) argument + more.push(`--try-require=readme.${match[1]}.md`); + } + } + + // We need to check if verbose logging should be enabled before parsing the args. + verbose = verbose || argv.indexOf("--verbose") !== -1; + + return parseAutorestCliArgs([...argv, ...more]); +} + +// Run void main(); process.on("exit", () => { diff --git a/packages/testing/test-public-packages/package.json b/packages/testing/test-public-packages/package.json index 43b8d32f0..14b2647ae 100644 --- a/packages/testing/test-public-packages/package.json +++ b/packages/testing/test-public-packages/package.json @@ -30,8 +30,8 @@ }, "homepage": "https://github.com/Azure/autorest#readme", "dependencies": { - "@autorest/core": "~3.6.3", - "autorest": "~3.4.0", + "@autorest/core": "~3.6.4", + "autorest": "~3.4.1", "source-map-support": "^0.5.19" }, "devDependencies": { diff --git a/packages/tools/compare/package.json b/packages/tools/compare/package.json index fbf45e61c..21cf904a4 100644 --- a/packages/tools/compare/package.json +++ b/packages/tools/compare/package.json @@ -32,7 +32,7 @@ }, "homepage": "https://github.com/Azure/autorest.compare#readme", "dependencies": { - "autorest": "~3.4.0", + "autorest": "~3.4.1", "chalk": "^4.1.0", "diff": "^4.0.1", "js-yaml": "~4.0.0",