@jsse/eslint-config 0.4.1 → 0.4.2

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