From 9745b5248e6027d889d14d9e7ab1e614e188aedd Mon Sep 17 00:00:00 2001 From: hyperz111 Date: Thu, 23 Oct 2025 04:20:41 +0700 Subject: [PATCH 1/3] add parseArgs --- bin/create-config.js | 59 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/bin/create-config.js b/bin/create-config.js index 7808a24..120b60d 100755 --- a/bin/create-config.js +++ b/bin/create-config.js @@ -10,10 +10,58 @@ import { findPackageJson } from "../lib/utils/npm-utils.js"; import * as log from "../lib/utils/logging.js"; import process from "node:process"; import fs from "node:fs/promises"; +// eslint-disable-next-line n/no-unsupported-features/node-builtins -- Using built-in parseArgs +import { parseArgs } from "node:util"; const pkg = JSON.parse(await fs.readFile(new URL("../package.json", import.meta.url), "utf8")); -log.log(`${pkg.name}: v${pkg.version}\n`); +const VERSION_TEXT = `${pkg.name}: v${pkg.version}`; +const HELP_TEXT = ` +Usage: ${pkg.name} [options] + +Options: + --config [String] Specify shareable config that is hosted on npm + --eslintrc Use an eslintrc-style (legacy) shared config + -h, --help Show help + -v, --version Show version +`.trim(); + +const { values: argv } = parseArgs({ + options: { + config: { + type: "string" + }, + eslintrc: { + type: "boolean" + }, + help: { + type: "boolean", + short: "h" + }, + version: { + type: "boolean", + short: "v" + } + }, + args: process.argv, + strict: false +}); + +/* eslint-disable n/no-process-exit, no-console -- show help & version menu */ + +if (argv.help) { + console.log(HELP_TEXT); + process.exit(0); +} + +if (argv.version) { + console.log(VERSION_TEXT); + process.exit(0); +} + +/* eslint-enable -- enable again */ + +log.log(VERSION_TEXT); process.on("uncaughtException", error => { if (error instanceof Error && error.code === "ERR_USE_AFTER_CLOSE") { @@ -32,10 +80,7 @@ if (packageJsonPath === null) { throw new Error("A package.json file is necessary to initialize ESLint. Run `npm init` to create a package.json file and try again."); } -const argv = process.argv; -const sharedConfigIndex = process.argv.indexOf("--config"); - -if (sharedConfigIndex === -1) { +if (!argv.config) { const generator = new ConfigGenerator({ cwd, packageJsonPath }); await generator.prompt(); @@ -44,8 +89,8 @@ if (sharedConfigIndex === -1) { } else { // passed "--config" - const packageName = argv[sharedConfigIndex + 1]; - const type = argv.includes("--eslintrc") ? "eslintrc" : "flat"; + const packageName = argv.config; + const type = argv.eslintrc ? "eslintrc" : "flat"; const answers = { config: { packageName, type } }; const generator = new ConfigGenerator({ cwd, packageJsonPath, answers }); From 47aecb05f12caa98d77afb36c28482962fb8592f Mon Sep 17 00:00:00 2001 From: hyperz111 Date: Thu, 23 Oct 2025 04:24:40 +0700 Subject: [PATCH 2/3] change version text --- bin/create-config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/create-config.js b/bin/create-config.js index 120b60d..082b138 100755 --- a/bin/create-config.js +++ b/bin/create-config.js @@ -15,7 +15,7 @@ import { parseArgs } from "node:util"; const pkg = JSON.parse(await fs.readFile(new URL("../package.json", import.meta.url), "utf8")); -const VERSION_TEXT = `${pkg.name}: v${pkg.version}`; +const VERSION_TEXT = `v${pkg.version}`; const HELP_TEXT = ` Usage: ${pkg.name} [options] @@ -61,7 +61,7 @@ if (argv.version) { /* eslint-enable -- enable again */ -log.log(VERSION_TEXT); +log.log(`${pkg.name}: ${VERSION_TEXT}`); process.on("uncaughtException", error => { if (error instanceof Error && error.code === "ERR_USE_AFTER_CLOSE") { From de457684c8eef7b36c4220c383060170f30a73ab Mon Sep 17 00:00:00 2001 From: hyperz111 Date: Sun, 26 Oct 2025 20:53:58 +0700 Subject: [PATCH 3/3] remove unrelated changes --- bin/create-config.js | 35 +---------------------------------- 1 file changed, 1 insertion(+), 34 deletions(-) diff --git a/bin/create-config.js b/bin/create-config.js index 082b138..b0006d6 100755 --- a/bin/create-config.js +++ b/bin/create-config.js @@ -15,17 +15,6 @@ import { parseArgs } from "node:util"; const pkg = JSON.parse(await fs.readFile(new URL("../package.json", import.meta.url), "utf8")); -const VERSION_TEXT = `v${pkg.version}`; -const HELP_TEXT = ` -Usage: ${pkg.name} [options] - -Options: - --config [String] Specify shareable config that is hosted on npm - --eslintrc Use an eslintrc-style (legacy) shared config - -h, --help Show help - -v, --version Show version -`.trim(); - const { values: argv } = parseArgs({ options: { config: { @@ -33,35 +22,13 @@ const { values: argv } = parseArgs({ }, eslintrc: { type: "boolean" - }, - help: { - type: "boolean", - short: "h" - }, - version: { - type: "boolean", - short: "v" } }, args: process.argv, strict: false }); -/* eslint-disable n/no-process-exit, no-console -- show help & version menu */ - -if (argv.help) { - console.log(HELP_TEXT); - process.exit(0); -} - -if (argv.version) { - console.log(VERSION_TEXT); - process.exit(0); -} - -/* eslint-enable -- enable again */ - -log.log(`${pkg.name}: ${VERSION_TEXT}`); +log.log(`${pkg.name}: v${pkg.version}`); process.on("uncaughtException", error => { if (error instanceof Error && error.code === "ERR_USE_AFTER_CLOSE") {