This commit is contained in:
Timothee Guerin 2021-10-05 10:58:18 -07:00 коммит произвёл GitHub
Родитель b0c66762f8
Коммит bf1ff432b9
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
12 изменённых файлов: 123 добавлений и 96 удалений

Просмотреть файл

@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@autorest/core",
"comment": "",
"type": "none"
}
],
"packageName": "@autorest/core",
"email": "tiguerin@microsoft.com"
}

Просмотреть файл

@ -1,6 +1,18 @@
{ {
"name": "autorest", "name": "autorest",
"entries": [ "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", "version": "3.4.0",
"tag": "autorest_v3.4.0", "tag": "autorest_v3.4.0",

Просмотреть файл

@ -1,6 +1,13 @@
# Change Log - autorest # 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 ## 3.4.0
Wed, 08 Sep 2021 15:39:22 GMT Wed, 08 Sep 2021 15:39:22 GMT
@ -105,7 +112,7 @@ Thu, 11 Feb 2021 18:03:07 GMT
### Patches ### 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 - **Internals** Update chalk dependency to ^4.1.0
## 3.0.6338 ## 3.0.6338
@ -143,7 +150,7 @@ Mon, 10 Feb 2020 00:00:00 GMT
- drop unreferenced requestBodies during merge - drop unreferenced requestBodies during merge
- supports v2 generators (and will by default, fall back to a v2 core unless overriden with `--version:` - 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 - 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` - 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. - 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 - rebuild to pick up newer extension library that supports python interpreter detection

Просмотреть файл

@ -1,6 +1,6 @@
{ {
"name": "autorest", "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.", "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": { "engines": {
"node": ">=12.0.0" "node": ">=12.0.0"
@ -41,7 +41,7 @@
"typings": "./dist/exports.d.ts", "typings": "./dist/exports.d.ts",
"devDependencies": { "devDependencies": {
"@autorest/configuration": "~1.7.2", "@autorest/configuration": "~1.7.2",
"@autorest/core": "~3.6.3", "@autorest/core": "~3.6.4",
"@autorest/common": "~1.3.0", "@autorest/common": "~1.3.0",
"@azure-tools/async-io": "~3.0.0", "@azure-tools/async-io": "~3.0.0",
"@azure-tools/extension": "~3.3.1", "@azure-tools/extension": "~3.3.1",

Просмотреть файл

@ -9,6 +9,7 @@ import "source-map-support/register";
declare const isDebuggerEnabled: boolean; declare const isDebuggerEnabled: boolean;
const cwd = process.cwd(); const cwd = process.cwd();
import { AutorestSyncLogger, ConsoleLoggerSink } from "@autorest/common";
import chalk from "chalk"; import chalk from "chalk";
import { clearTempData } from "./actions"; import { clearTempData } from "./actions";
import { parseAutorestArgs } from "./args"; import { parseAutorestArgs } from "./args";
@ -96,7 +97,15 @@ async function main() {
} catch { } catch {
// We have a chance to fail again later if this proves problematic. // 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); const coreVersionPath = await resolveCoreVersion(config);
// let's strip the extra stuff from the command line before we require the core module. // 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; process.argv = newArgs;
if (args.debug) { if (args.debug) {
console.log(`Starting ${newCorePackage} from ${coreVersionPath}`); logger.debug(`Starting ${newCorePackage} from ${coreVersionPath}`);
} }
// reset the working folder to the correct place. // reset the working folder to the correct place.

Просмотреть файл

@ -1,5 +1,5 @@
import { dirname, join, resolve } from "path"; 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 { AutorestConfiguration, AutorestNormalizedConfiguration, ConfigurationLoader } from "@autorest/configuration";
import { isFile } from "@azure-tools/async-io"; import { isFile } from "@azure-tools/async-io";
import { createFileOrFolderUri, createFolderUri, resolveUri } from "@azure-tools/uri"; import { createFileOrFolderUri, createFolderUri, resolveUri } from "@azure-tools/uri";
@ -33,12 +33,11 @@ const cwd = process.cwd();
* Tries to load the configuration of autorest. * Tries to load the configuration of autorest.
* @param args CLI args. * @param args CLI args.
*/ */
export async function loadConfig(args: AutorestArgs): Promise<AutorestConfiguration | undefined> { export async function loadConfig(sink: LoggerSink, args: AutorestArgs): Promise<AutorestConfiguration | undefined> {
const configFileOrFolder = resolveUri(createFolderUri(cwd), args.configFileOrFolder || "."); const configFileOrFolder = resolveUri(createFolderUri(cwd), args.configFileOrFolder || ".");
const enableLogging = args["debug-cli-config-loading"]; const enableLogging = args["debug-cli-config-loading"];
const logger = new AutorestSyncLogger({ const logger = new AutorestSyncLogger({
sinks: enableLogging ? [new ConsoleLoggerSink()] : [], sinks: enableLogging ? [sink] : [],
}); });
const loader = new ConfigurationLoader(logger, defaultConfigUri, configFileOrFolder, { const loader = new ConfigurationLoader(logger, defaultConfigUri, configFileOrFolder, {
@ -46,12 +45,6 @@ export async function loadConfig(args: AutorestArgs): Promise<AutorestConfigurat
}); });
try { try {
const { config } = await loader.load([args], true); const { config } = await loader.load([args], true);
if (config.version) {
// eslint-disable-next-line no-console
console.log(
chalk.yellow(`NOTE: AutoRest core version selected from configuration: ${chalk.yellow.bold(config.version)}.`),
);
}
return config; return config;
} catch (e) { } catch (e) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console

Просмотреть файл

@ -1,6 +1,18 @@
{ {
"name": "@autorest/core", "name": "@autorest/core",
"entries": [ "entries": [
{
"version": "3.6.4",
"tag": "@autorest/core_v3.6.4",
"date": "Tue, 05 Oct 2021 16:39:50 GMT",
"comments": {
"patch": [
{
"comment": "**Fix** `message-format` not being respected"
}
]
}
},
{ {
"version": "3.6.3", "version": "3.6.3",
"tag": "@autorest/core_v3.6.3", "tag": "@autorest/core_v3.6.3",

Просмотреть файл

@ -1,6 +1,13 @@
# Change Log - @autorest/core # Change Log - @autorest/core
This log was last generated on Thu, 23 Sep 2021 19:51:32 GMT and should not be manually modified. This log was last generated on Tue, 05 Oct 2021 16:39:50 GMT and should not be manually modified.
## 3.6.4
Tue, 05 Oct 2021 16:39:50 GMT
### Patches
- **Fix** `message-format` not being respected
## 3.6.3 ## 3.6.3
Thu, 23 Sep 2021 19:51:32 GMT Thu, 23 Sep 2021 19:51:32 GMT

Просмотреть файл

@ -1,6 +1,6 @@
{ {
"name": "@autorest/core", "name": "@autorest/core",
"version": "3.6.3", "version": "3.6.4",
"description": "AutoRest core module", "description": "AutoRest core module",
"engines": { "engines": {
"node": ">=12.0.0" "node": ">=12.0.0"

Просмотреть файл

@ -14,6 +14,7 @@ import {
AutorestLogger, AutorestLogger,
AutorestSyncLogger, AutorestSyncLogger,
Exception, Exception,
IAutorestLogger,
} from "@autorest/common"; } from "@autorest/common";
import { AutorestCliArgs, parseAutorestCliArgs } from "@autorest/configuration"; import { AutorestCliArgs, parseAutorestCliArgs } from "@autorest/configuration";
@ -103,9 +104,9 @@ csharp:
let exitcode = 0; let exitcode = 0;
let cleared = false; let cleared = false;
async function doClearFolders(protectFiles: Set<string>, clearFolders: Set<string>) { async function doClearFolders(protectFiles: Set<string>, clearFolders: Set<string>, logger: IAutorestLogger) {
if (!cleared) { if (!cleared) {
timestampDebugLog("Clearing Folders."); logger.debug("Clearing Folders.");
cleared = true; cleared = true;
for (const folder of clearFolders) { for (const folder of clearFolders) {
try { try {
@ -120,32 +121,7 @@ async function doClearFolders(protectFiles: Set<string>, clearFolders: Set<strin
} }
} }
async function currentMain(autorestArgs: Array<string>): Promise<number> { async function currentMain(logger: IAutorestLogger, args: AutorestCliArgs): Promise<number> {
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) })],
});
if (!args.options["message-format"] || args.options["message-format"] === "regular") { if (!args.options["message-format"] || args.options["message-format"] === "regular") {
logger.info(`> Loading AutoRest core '${__dirname}' (${VERSION})`); logger.info(`> Loading AutoRest core '${__dirname}' (${VERSION})`);
} }
@ -202,7 +178,7 @@ async function currentMain(autorestArgs: Array<string>): Promise<number> {
} }
if (context.config["batch"]) { if (context.config["batch"]) {
await batch(api, args, logger); await batch(api, logger);
} else { } else {
const result = await api.Process().finish; const result = await api.Process().finish;
if (result !== true) { if (result !== true) {
@ -252,12 +228,12 @@ async function currentMain(autorestArgs: Array<string>): Promise<number> {
} }
} else { } else {
// perform file system operations. // perform file system operations.
await doClearFolders(protectFiles, clearFolders); await doClearFolders(protectFiles, clearFolders, logger);
timestampDebugLog("Writing Outputs."); logger.debug("Writing Outputs.");
await artifactWriter.wait(); await artifactWriter.wait();
} }
timestampLog("Generation Complete"); logger.info("Generation Complete");
// return the exit code to the caller. // return the exit code to the caller.
return exitcode; return exitcode;
} }
@ -296,7 +272,7 @@ function getRds(schema: any, path: string): Array<string> {
return result; return result;
} }
async function resourceSchemaBatch(api: AutoRest, logger: AutorestLogger): Promise<number> { async function resourceSchemaBatch(api: AutoRest, logger: IAutorestLogger): Promise<number> {
// get the configuration // get the configuration
const outputs = new Map<string, string>(); const outputs = new Map<string, string>();
const schemas = new Array<string>(); const schemas = new Array<string>();
@ -364,15 +340,12 @@ async function resourceSchemaBatch(api: AutoRest, logger: AutorestLogger): Promi
return exitcode; return exitcode;
} }
async function batch(api: AutoRest, args: AutorestCliArgs, logger: AutorestLogger): Promise<void> { async function batch(api: AutoRest, logger: IAutorestLogger): Promise<void> {
const config = await api.view; const config = await api.view;
const batchTaskConfigReference: any = {}; const batchTaskConfigReference: any = {};
api.AddConfiguration(batchTaskConfigReference); api.AddConfiguration(batchTaskConfigReference);
for (const batchTaskConfig of config.GetEntry(<any>"batch")) { for (const batchTaskConfig of config.GetEntry(<any>"batch")) {
const isjson = args.options["message-format"] === "json"; logger.info(`Processing batch task - ${JSON.stringify(batchTaskConfig)} .`);
if (!isjson) {
logger.info(`Processing batch task - ${JSON.stringify(batchTaskConfig)} .`);
}
// update batch task config section // update batch task config section
for (const key of Object.keys(batchTaskConfigReference)) { for (const key of Object.keys(batchTaskConfigReference)) {
delete batchTaskConfigReference[key]; delete batchTaskConfigReference[key];
@ -391,61 +364,64 @@ async function batch(api: AutoRest, args: AutorestCliArgs, logger: AutorestLogge
} }
} }
/** async function main() {
* Entry point const argv = process.argv.slice(2);
*/ if (argv[0] === "init") {
async function mainImpl(): Promise<number> { await autorestInit();
let autorestArgs: Array<string> = []; return;
const exitcode = 0; }
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 { try {
autorestArgs = process.argv.slice(2); return await currentMain(logger, args);
return await currentMain(autorestArgs);
} catch (e) { } catch (e) {
// be very careful about the following check: // 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 // - doing the inversion (instanceof Error) doesn't reliably work since that seems to return false on Errors marshalled from safeEval
if (e instanceof Exception) { if (e instanceof Exception) {
console.log(e.message); logger.log({ level: "error", message: e.message });
return e.exitCode; exitCode = e.exitCode;
} }
if (e !== false) { 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 { } finally {
try { try {
timestampDebugLog("Shutting Down."); logger.debug("Shutting Down.");
await Shutdown(); await Shutdown();
} catch { } catch {
timestampDebugLog("Shutting Down: (trouble?)"); logger.debug("Shutting Down: (trouble?)");
} finally { } finally {
timestampDebugLog("Exiting."); logger.debug("Exiting.");
// eslint-disable-next-line no-process-exit // eslint-disable-next-line no-process-exit
process.exit(exitcode); 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(); void main();
process.on("exit", () => { process.on("exit", () => {

Просмотреть файл

@ -30,8 +30,8 @@
}, },
"homepage": "https://github.com/Azure/autorest#readme", "homepage": "https://github.com/Azure/autorest#readme",
"dependencies": { "dependencies": {
"@autorest/core": "~3.6.3", "@autorest/core": "~3.6.4",
"autorest": "~3.4.0", "autorest": "~3.4.1",
"source-map-support": "^0.5.19" "source-map-support": "^0.5.19"
}, },
"devDependencies": { "devDependencies": {

Просмотреть файл

@ -32,7 +32,7 @@
}, },
"homepage": "https://github.com/Azure/autorest.compare#readme", "homepage": "https://github.com/Azure/autorest.compare#readme",
"dependencies": { "dependencies": {
"autorest": "~3.4.0", "autorest": "~3.4.1",
"chalk": "^4.1.0", "chalk": "^4.1.0",
"diff": "^4.0.1", "diff": "^4.0.1",
"js-yaml": "~4.0.0", "js-yaml": "~4.0.0",