@jsse/eslint-config 0.2.32 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.cjs DELETED
@@ -1,723 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") {
10
- for (let key of __getOwnPropNames(from))
11
- if (!__hasOwnProp.call(to, key) && key !== except)
12
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
- }
14
- return to;
15
- };
16
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
- // If the importer is in node compatibility mode or this is not an ESM
18
- // file that has been converted to a CommonJS file using a Babel-
19
- // compatible transform (i.e. "__esModule" has not been set), then set
20
- // "default" to the CommonJS "module.exports" for node compatibility.
21
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
- mod
23
- ));
24
-
25
- // src/cli.ts
26
- var import_node_fs = __toESM(require("fs"), 1);
27
- var import_node_process = __toESM(require("process"), 1);
28
-
29
- // node_modules/.pnpm/cac@6.7.14/node_modules/cac/dist/index.mjs
30
- var import_events = require("events");
31
- function toArr(any) {
32
- return any == null ? [] : Array.isArray(any) ? any : [any];
33
- }
34
- function toVal(out, key, val, opts) {
35
- var x, old = out[key], nxt = !!~opts.string.indexOf(key) ? val == null || val === true ? "" : String(val) : typeof val === "boolean" ? val : !!~opts.boolean.indexOf(key) ? val === "false" ? false : val === "true" || (out._.push((x = +val, x * 0 === 0) ? x : val), !!val) : (x = +val, x * 0 === 0) ? x : val;
36
- out[key] = old == null ? nxt : Array.isArray(old) ? old.concat(nxt) : [old, nxt];
37
- }
38
- function mri2(args, opts) {
39
- args = args || [];
40
- opts = opts || {};
41
- var k, arr, arg, name, val, out = { _: [] };
42
- var i = 0, j = 0, idx = 0, len = args.length;
43
- const alibi = opts.alias !== void 0;
44
- const strict = opts.unknown !== void 0;
45
- const defaults = opts.default !== void 0;
46
- opts.alias = opts.alias || {};
47
- opts.string = toArr(opts.string);
48
- opts.boolean = toArr(opts.boolean);
49
- if (alibi) {
50
- for (k in opts.alias) {
51
- arr = opts.alias[k] = toArr(opts.alias[k]);
52
- for (i = 0; i < arr.length; i++) {
53
- (opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
54
- }
55
- }
56
- }
57
- for (i = opts.boolean.length; i-- > 0; ) {
58
- arr = opts.alias[opts.boolean[i]] || [];
59
- for (j = arr.length; j-- > 0; ) opts.boolean.push(arr[j]);
60
- }
61
- for (i = opts.string.length; i-- > 0; ) {
62
- arr = opts.alias[opts.string[i]] || [];
63
- for (j = arr.length; j-- > 0; ) opts.string.push(arr[j]);
64
- }
65
- if (defaults) {
66
- for (k in opts.default) {
67
- name = typeof opts.default[k];
68
- arr = opts.alias[k] = opts.alias[k] || [];
69
- if (opts[name] !== void 0) {
70
- opts[name].push(k);
71
- for (i = 0; i < arr.length; i++) {
72
- opts[name].push(arr[i]);
73
- }
74
- }
75
- }
76
- }
77
- const keys = strict ? Object.keys(opts.alias) : [];
78
- for (i = 0; i < len; i++) {
79
- arg = args[i];
80
- if (arg === "--") {
81
- out._ = out._.concat(args.slice(++i));
82
- break;
83
- }
84
- for (j = 0; j < arg.length; j++) {
85
- if (arg.charCodeAt(j) !== 45) break;
86
- }
87
- if (j === 0) {
88
- out._.push(arg);
89
- } else if (arg.substring(j, j + 3) === "no-") {
90
- name = arg.substring(j + 3);
91
- if (strict && !~keys.indexOf(name)) {
92
- return opts.unknown(arg);
93
- }
94
- out[name] = false;
95
- } else {
96
- for (idx = j + 1; idx < arg.length; idx++) {
97
- if (arg.charCodeAt(idx) === 61) break;
98
- }
99
- name = arg.substring(j, idx);
100
- val = arg.substring(++idx) || (i + 1 === len || ("" + args[i + 1]).charCodeAt(0) === 45 || args[++i]);
101
- arr = j === 2 ? [name] : name;
102
- for (idx = 0; idx < arr.length; idx++) {
103
- name = arr[idx];
104
- if (strict && !~keys.indexOf(name)) return opts.unknown("-".repeat(j) + name);
105
- toVal(out, name, idx + 1 < arr.length || val, opts);
106
- }
107
- }
108
- }
109
- if (defaults) {
110
- for (k in opts.default) {
111
- if (out[k] === void 0) {
112
- out[k] = opts.default[k];
113
- }
114
- }
115
- }
116
- if (alibi) {
117
- for (k in out) {
118
- arr = opts.alias[k] || [];
119
- while (arr.length > 0) {
120
- out[arr.shift()] = out[k];
121
- }
122
- }
123
- }
124
- return out;
125
- }
126
- var removeBrackets = (v) => v.replace(/[<[].+/, "").trim();
127
- var findAllBrackets = (v) => {
128
- const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
129
- const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
130
- const res = [];
131
- const parse = (match) => {
132
- let variadic = false;
133
- let value = match[1];
134
- if (value.startsWith("...")) {
135
- value = value.slice(3);
136
- variadic = true;
137
- }
138
- return {
139
- required: match[0].startsWith("<"),
140
- value,
141
- variadic
142
- };
143
- };
144
- let angledMatch;
145
- while (angledMatch = ANGLED_BRACKET_RE_GLOBAL.exec(v)) {
146
- res.push(parse(angledMatch));
147
- }
148
- let squareMatch;
149
- while (squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v)) {
150
- res.push(parse(squareMatch));
151
- }
152
- return res;
153
- };
154
- var getMriOptions = (options) => {
155
- const result = { alias: {}, boolean: [] };
156
- for (const [index, option] of options.entries()) {
157
- if (option.names.length > 1) {
158
- result.alias[option.names[0]] = option.names.slice(1);
159
- }
160
- if (option.isBoolean) {
161
- if (option.negated) {
162
- const hasStringTypeOption = options.some((o, i) => {
163
- return i !== index && o.names.some((name) => option.names.includes(name)) && typeof o.required === "boolean";
164
- });
165
- if (!hasStringTypeOption) {
166
- result.boolean.push(option.names[0]);
167
- }
168
- } else {
169
- result.boolean.push(option.names[0]);
170
- }
171
- }
172
- }
173
- return result;
174
- };
175
- var findLongest = (arr) => {
176
- return arr.sort((a, b) => {
177
- return a.length > b.length ? -1 : 1;
178
- })[0];
179
- };
180
- var padRight = (str, length) => {
181
- return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
182
- };
183
- var camelcase = (input) => {
184
- return input.replace(/([a-z])-([a-z])/g, (_, p1, p2) => {
185
- return p1 + p2.toUpperCase();
186
- });
187
- };
188
- var setDotProp = (obj, keys, val) => {
189
- let i = 0;
190
- let length = keys.length;
191
- let t = obj;
192
- let x;
193
- for (; i < length; ++i) {
194
- x = t[keys[i]];
195
- t = t[keys[i]] = i === length - 1 ? val : x != null ? x : !!~keys[i + 1].indexOf(".") || !(+keys[i + 1] > -1) ? {} : [];
196
- }
197
- };
198
- var setByType = (obj, transforms) => {
199
- for (const key of Object.keys(transforms)) {
200
- const transform = transforms[key];
201
- if (transform.shouldTransform) {
202
- obj[key] = Array.prototype.concat.call([], obj[key]);
203
- if (typeof transform.transformFunction === "function") {
204
- obj[key] = obj[key].map(transform.transformFunction);
205
- }
206
- }
207
- }
208
- };
209
- var getFileName = (input) => {
210
- const m = /([^\\\/]+)$/.exec(input);
211
- return m ? m[1] : "";
212
- };
213
- var camelcaseOptionName = (name) => {
214
- return name.split(".").map((v, i) => {
215
- return i === 0 ? camelcase(v) : v;
216
- }).join(".");
217
- };
218
- var CACError = class extends Error {
219
- constructor(message) {
220
- super(message);
221
- this.name = this.constructor.name;
222
- if (typeof Error.captureStackTrace === "function") {
223
- Error.captureStackTrace(this, this.constructor);
224
- } else {
225
- this.stack = new Error(message).stack;
226
- }
227
- }
228
- };
229
- var Option = class {
230
- constructor(rawName, description, config) {
231
- this.rawName = rawName;
232
- this.description = description;
233
- this.config = Object.assign({}, config);
234
- rawName = rawName.replace(/\.\*/g, "");
235
- this.negated = false;
236
- this.names = removeBrackets(rawName).split(",").map((v) => {
237
- let name = v.trim().replace(/^-{1,2}/, "");
238
- if (name.startsWith("no-")) {
239
- this.negated = true;
240
- name = name.replace(/^no-/, "");
241
- }
242
- return camelcaseOptionName(name);
243
- }).sort((a, b) => a.length > b.length ? 1 : -1);
244
- this.name = this.names[this.names.length - 1];
245
- if (this.negated && this.config.default == null) {
246
- this.config.default = true;
247
- }
248
- if (rawName.includes("<")) {
249
- this.required = true;
250
- } else if (rawName.includes("[")) {
251
- this.required = false;
252
- } else {
253
- this.isBoolean = true;
254
- }
255
- }
256
- };
257
- var processArgs = process.argv;
258
- var platformInfo = `${process.platform}-${process.arch} node-${process.version}`;
259
- var Command = class {
260
- constructor(rawName, description, config = {}, cli2) {
261
- this.rawName = rawName;
262
- this.description = description;
263
- this.config = config;
264
- this.cli = cli2;
265
- this.options = [];
266
- this.aliasNames = [];
267
- this.name = removeBrackets(rawName);
268
- this.args = findAllBrackets(rawName);
269
- this.examples = [];
270
- }
271
- usage(text) {
272
- this.usageText = text;
273
- return this;
274
- }
275
- allowUnknownOptions() {
276
- this.config.allowUnknownOptions = true;
277
- return this;
278
- }
279
- ignoreOptionDefaultValue() {
280
- this.config.ignoreOptionDefaultValue = true;
281
- return this;
282
- }
283
- version(version, customFlags = "-v, --version") {
284
- this.versionNumber = version;
285
- this.option(customFlags, "Display version number");
286
- return this;
287
- }
288
- example(example) {
289
- this.examples.push(example);
290
- return this;
291
- }
292
- option(rawName, description, config) {
293
- const option = new Option(rawName, description, config);
294
- this.options.push(option);
295
- return this;
296
- }
297
- alias(name) {
298
- this.aliasNames.push(name);
299
- return this;
300
- }
301
- action(callback) {
302
- this.commandAction = callback;
303
- return this;
304
- }
305
- isMatched(name) {
306
- return this.name === name || this.aliasNames.includes(name);
307
- }
308
- get isDefaultCommand() {
309
- return this.name === "" || this.aliasNames.includes("!");
310
- }
311
- get isGlobalCommand() {
312
- return this instanceof GlobalCommand;
313
- }
314
- hasOption(name) {
315
- name = name.split(".")[0];
316
- return this.options.find((option) => {
317
- return option.names.includes(name);
318
- });
319
- }
320
- outputHelp() {
321
- const { name, commands } = this.cli;
322
- const {
323
- versionNumber,
324
- options: globalOptions,
325
- helpCallback
326
- } = this.cli.globalCommand;
327
- let sections = [
328
- {
329
- body: `${name}${versionNumber ? `/${versionNumber}` : ""}`
330
- }
331
- ];
332
- sections.push({
333
- title: "Usage",
334
- body: ` $ ${name} ${this.usageText || this.rawName}`
335
- });
336
- const showCommands = (this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0;
337
- if (showCommands) {
338
- const longestCommandName = findLongest(commands.map((command) => command.rawName));
339
- sections.push({
340
- title: "Commands",
341
- body: commands.map((command) => {
342
- return ` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`;
343
- }).join("\n")
344
- });
345
- sections.push({
346
- title: `For more info, run any command with the \`--help\` flag`,
347
- body: commands.map((command) => ` $ ${name}${command.name === "" ? "" : ` ${command.name}`} --help`).join("\n")
348
- });
349
- }
350
- let options = this.isGlobalCommand ? globalOptions : [...this.options, ...globalOptions || []];
351
- if (!this.isGlobalCommand && !this.isDefaultCommand) {
352
- options = options.filter((option) => option.name !== "version");
353
- }
354
- if (options.length > 0) {
355
- const longestOptionName = findLongest(options.map((option) => option.rawName));
356
- sections.push({
357
- title: "Options",
358
- body: options.map((option) => {
359
- return ` ${padRight(option.rawName, longestOptionName.length)} ${option.description} ${option.config.default === void 0 ? "" : `(default: ${option.config.default})`}`;
360
- }).join("\n")
361
- });
362
- }
363
- if (this.examples.length > 0) {
364
- sections.push({
365
- title: "Examples",
366
- body: this.examples.map((example) => {
367
- if (typeof example === "function") {
368
- return example(name);
369
- }
370
- return example;
371
- }).join("\n")
372
- });
373
- }
374
- if (helpCallback) {
375
- sections = helpCallback(sections) || sections;
376
- }
377
- console.log(sections.map((section) => {
378
- return section.title ? `${section.title}:
379
- ${section.body}` : section.body;
380
- }).join("\n\n"));
381
- }
382
- outputVersion() {
383
- const { name } = this.cli;
384
- const { versionNumber } = this.cli.globalCommand;
385
- if (versionNumber) {
386
- console.log(`${name}/${versionNumber} ${platformInfo}`);
387
- }
388
- }
389
- checkRequiredArgs() {
390
- const minimalArgsCount = this.args.filter((arg) => arg.required).length;
391
- if (this.cli.args.length < minimalArgsCount) {
392
- throw new CACError(`missing required args for command \`${this.rawName}\``);
393
- }
394
- }
395
- checkUnknownOptions() {
396
- const { options, globalCommand } = this.cli;
397
- if (!this.config.allowUnknownOptions) {
398
- for (const name of Object.keys(options)) {
399
- if (name !== "--" && !this.hasOption(name) && !globalCommand.hasOption(name)) {
400
- throw new CACError(`Unknown option \`${name.length > 1 ? `--${name}` : `-${name}`}\``);
401
- }
402
- }
403
- }
404
- }
405
- checkOptionValue() {
406
- const { options: parsedOptions, globalCommand } = this.cli;
407
- const options = [...globalCommand.options, ...this.options];
408
- for (const option of options) {
409
- const value = parsedOptions[option.name.split(".")[0]];
410
- if (option.required) {
411
- const hasNegated = options.some((o) => o.negated && o.names.includes(option.name));
412
- if (value === true || value === false && !hasNegated) {
413
- throw new CACError(`option \`${option.rawName}\` value is missing`);
414
- }
415
- }
416
- }
417
- }
418
- };
419
- var GlobalCommand = class extends Command {
420
- constructor(cli2) {
421
- super("@@global@@", "", {}, cli2);
422
- }
423
- };
424
- var __assign = Object.assign;
425
- var CAC = class extends import_events.EventEmitter {
426
- constructor(name = "") {
427
- super();
428
- this.name = name;
429
- this.commands = [];
430
- this.rawArgs = [];
431
- this.args = [];
432
- this.options = {};
433
- this.globalCommand = new GlobalCommand(this);
434
- this.globalCommand.usage("<command> [options]");
435
- }
436
- usage(text) {
437
- this.globalCommand.usage(text);
438
- return this;
439
- }
440
- command(rawName, description, config) {
441
- const command = new Command(rawName, description || "", config, this);
442
- command.globalCommand = this.globalCommand;
443
- this.commands.push(command);
444
- return command;
445
- }
446
- option(rawName, description, config) {
447
- this.globalCommand.option(rawName, description, config);
448
- return this;
449
- }
450
- help(callback) {
451
- this.globalCommand.option("-h, --help", "Display this message");
452
- this.globalCommand.helpCallback = callback;
453
- this.showHelpOnExit = true;
454
- return this;
455
- }
456
- version(version, customFlags = "-v, --version") {
457
- this.globalCommand.version(version, customFlags);
458
- this.showVersionOnExit = true;
459
- return this;
460
- }
461
- example(example) {
462
- this.globalCommand.example(example);
463
- return this;
464
- }
465
- outputHelp() {
466
- if (this.matchedCommand) {
467
- this.matchedCommand.outputHelp();
468
- } else {
469
- this.globalCommand.outputHelp();
470
- }
471
- }
472
- outputVersion() {
473
- this.globalCommand.outputVersion();
474
- }
475
- setParsedInfo({ args, options }, matchedCommand, matchedCommandName) {
476
- this.args = args;
477
- this.options = options;
478
- if (matchedCommand) {
479
- this.matchedCommand = matchedCommand;
480
- }
481
- if (matchedCommandName) {
482
- this.matchedCommandName = matchedCommandName;
483
- }
484
- return this;
485
- }
486
- unsetMatchedCommand() {
487
- this.matchedCommand = void 0;
488
- this.matchedCommandName = void 0;
489
- }
490
- parse(argv = processArgs, {
491
- run = true
492
- } = {}) {
493
- this.rawArgs = argv;
494
- if (!this.name) {
495
- this.name = argv[1] ? getFileName(argv[1]) : "cli";
496
- }
497
- let shouldParse = true;
498
- for (const command of this.commands) {
499
- const parsed = this.mri(argv.slice(2), command);
500
- const commandName = parsed.args[0];
501
- if (command.isMatched(commandName)) {
502
- shouldParse = false;
503
- const parsedInfo = __assign(__assign({}, parsed), {
504
- args: parsed.args.slice(1)
505
- });
506
- this.setParsedInfo(parsedInfo, command, commandName);
507
- this.emit(`command:${commandName}`, command);
508
- }
509
- }
510
- if (shouldParse) {
511
- for (const command of this.commands) {
512
- if (command.name === "") {
513
- shouldParse = false;
514
- const parsed = this.mri(argv.slice(2), command);
515
- this.setParsedInfo(parsed, command);
516
- this.emit(`command:!`, command);
517
- }
518
- }
519
- }
520
- if (shouldParse) {
521
- const parsed = this.mri(argv.slice(2));
522
- this.setParsedInfo(parsed);
523
- }
524
- if (this.options.help && this.showHelpOnExit) {
525
- this.outputHelp();
526
- run = false;
527
- this.unsetMatchedCommand();
528
- }
529
- if (this.options.version && this.showVersionOnExit && this.matchedCommandName == null) {
530
- this.outputVersion();
531
- run = false;
532
- this.unsetMatchedCommand();
533
- }
534
- const parsedArgv = { args: this.args, options: this.options };
535
- if (run) {
536
- this.runMatchedCommand();
537
- }
538
- if (!this.matchedCommand && this.args[0]) {
539
- this.emit("command:*");
540
- }
541
- return parsedArgv;
542
- }
543
- mri(argv, command) {
544
- const cliOptions = [
545
- ...this.globalCommand.options,
546
- ...command ? command.options : []
547
- ];
548
- const mriOptions = getMriOptions(cliOptions);
549
- let argsAfterDoubleDashes = [];
550
- const doubleDashesIndex = argv.indexOf("--");
551
- if (doubleDashesIndex > -1) {
552
- argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
553
- argv = argv.slice(0, doubleDashesIndex);
554
- }
555
- let parsed = mri2(argv, mriOptions);
556
- parsed = Object.keys(parsed).reduce((res, name) => {
557
- return __assign(__assign({}, res), {
558
- [camelcaseOptionName(name)]: parsed[name]
559
- });
560
- }, { _: [] });
561
- const args = parsed._;
562
- const options = {
563
- "--": argsAfterDoubleDashes
564
- };
565
- const ignoreDefault = command && command.config.ignoreOptionDefaultValue ? command.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue;
566
- let transforms = /* @__PURE__ */ Object.create(null);
567
- for (const cliOption of cliOptions) {
568
- if (!ignoreDefault && cliOption.config.default !== void 0) {
569
- for (const name of cliOption.names) {
570
- options[name] = cliOption.config.default;
571
- }
572
- }
573
- if (Array.isArray(cliOption.config.type)) {
574
- if (transforms[cliOption.name] === void 0) {
575
- transforms[cliOption.name] = /* @__PURE__ */ Object.create(null);
576
- transforms[cliOption.name]["shouldTransform"] = true;
577
- transforms[cliOption.name]["transformFunction"] = cliOption.config.type[0];
578
- }
579
- }
580
- }
581
- for (const key of Object.keys(parsed)) {
582
- if (key !== "_") {
583
- const keys = key.split(".");
584
- setDotProp(options, keys, parsed[key]);
585
- setByType(options, transforms);
586
- }
587
- }
588
- return {
589
- args,
590
- options
591
- };
592
- }
593
- runMatchedCommand() {
594
- const { args, options, matchedCommand: command } = this;
595
- if (!command || !command.commandAction)
596
- return;
597
- command.checkUnknownOptions();
598
- command.checkOptionValue();
599
- command.checkRequiredArgs();
600
- const actionArgs = [];
601
- command.args.forEach((arg, index) => {
602
- if (arg.variadic) {
603
- actionArgs.push(args.slice(index));
604
- } else {
605
- actionArgs.push(args[index]);
606
- }
607
- });
608
- actionArgs.push(options);
609
- return command.commandAction.apply(this, actionArgs);
610
- }
611
- };
612
- var cac = (name = "") => new CAC(name);
613
-
614
- // src/generated/version.ts
615
- var VERSION = "0.2.32";
616
-
617
- // src/cli.ts
618
- var cli = cac("jsselint");
619
- var CONFIG_OPTIONS_STRING = `
620
- {
621
- /**
622
- * ===================
623
- * jsse eslint options
624
- * ===================
625
- */
626
- debug: false,
627
-
628
- /**
629
- * Enable TypeScript support.
630
- */
631
- // typescript: {
632
- // tsconfigPath: "tsconfig.json", // or ["tsconfig.json", "tsconfig.eslint.json", ...]
633
- // },
634
-
635
- /**
636
- * Enable React support.
637
- * @default false
638
- */
639
- // react: true,
640
- // reactRefresh: true,
641
-
642
- /**
643
- * Report unused disable directives
644
- * @default true
645
- */
646
- // reportUnusedDisableDirectives: false,
647
-
648
- /**
649
- * rules 2 turn off
650
- * @default []
651
- * @example ["super-annoying-rule"]
652
- */
653
- // off: [],
654
- }
655
- `;
656
- var CONFIG_STRING_CJS = `// @ts-check
657
-
658
- module.exports = require("@jsse/eslint-config").jsse(
659
- ${CONFIG_OPTIONS_STRING}
660
- )
661
- `;
662
- var CONFIG_STRING_ESM = `// @ts-check
663
- import jsse from "@jsse/eslint-config";
664
-
665
- export default jsse(
666
- ${CONFIG_OPTIONS_STRING}
667
- );
668
- `;
669
- cli.command("", "default command").action(() => {
670
- cli.outputHelp();
671
- import_node_process.default.exit(1);
672
- });
673
- cli.command("init", "create eslint config file").option("--force", "force create eslint config file").action(async (options) => {
674
- console.log("init");
675
- const configPath = "eslint.config.js";
676
- if (import_node_fs.default.existsSync(configPath)) {
677
- const msg = "eslint.config.js already exists";
678
- console.warn(msg);
679
- if (!options.force) {
680
- throw new Error(msg);
681
- }
682
- }
683
- if (!import_node_fs.default.existsSync("package.json")) {
684
- const msg = "package.json not found";
685
- console.warn(msg);
686
- throw new Error(msg);
687
- }
688
- const packageJson = JSON.parse(import_node_fs.default.readFileSync("package.json", "utf8"));
689
- const isModule = packageJson.type === "module";
690
- const eslintConfigString = [
691
- isModule ? CONFIG_STRING_ESM : CONFIG_STRING_CJS,
692
- "/* ALT */",
693
- (isModule ? CONFIG_STRING_CJS : CONFIG_STRING_ESM).split("\n").map((line) => `// ${line}`).join("\n")
694
- ];
695
- import_node_fs.default.writeFileSync(configPath, eslintConfigString.join("\n"));
696
- console.log(`made eslint.config.js (type: ${packageJson.type})`);
697
- });
698
- cli.command("version", "echo version").action(() => {
699
- console.log(VERSION);
700
- });
701
- cli.version(typeof VERSION === "string" ? VERSION : "unknown");
702
- cli.help();
703
- async function main(args) {
704
- const argv = args ?? import_node_process.default.argv.slice(2);
705
- try {
706
- const parsed = cli.parse(argv, { run: false });
707
- console.log("=====");
708
- console.log(parsed);
709
- console.log("=====");
710
- await cli.runMatchedCommand();
711
- } catch (error) {
712
- if (error instanceof Error) {
713
- console.error("Error: %s\n\n%s", error.message, error.stack);
714
- } else {
715
- console.error(error);
716
- }
717
- import_node_process.default.exit(1);
718
- }
719
- }
720
- main().catch((e) => {
721
- console.error(e);
722
- throw e;
723
- });