Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions bin/create-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,25 @@ 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 { values: argv } = parseArgs({
options: {
config: {
type: "string"
},
eslintrc: {
type: "boolean"
}
},
args: process.argv,
strict: false
});

log.log(`${pkg.name}: v${pkg.version}`);

process.on("uncaughtException", error => {
if (error instanceof Error && error.code === "ERR_USE_AFTER_CLOSE") {
Expand All @@ -32,10 +47,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();
Expand All @@ -44,8 +56,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 });

Expand Down