js-style-kit 0.4.1 → 0.5.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/bin/{index.js → index.cjs} +429 -194
- package/dist/bin/index.cjs.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/package.json +26 -25
- package/dist/bin/index.js.map +0 -1
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var
|
|
9
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
10
|
-
}) : x)(function(x) {
|
|
11
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
12
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
13
|
-
});
|
|
14
|
-
var __commonJS = (cb, mod) => function __require2() {
|
|
9
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
15
10
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
16
11
|
};
|
|
17
12
|
var __copyProps = (to, from, except, desc) => {
|
|
@@ -33,7 +28,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
33
28
|
|
|
34
29
|
// ../../node_modules/commander/lib/error.js
|
|
35
30
|
var require_error = __commonJS({
|
|
36
|
-
"../../node_modules/commander/lib/error.js"(
|
|
31
|
+
"../../node_modules/commander/lib/error.js"(exports2) {
|
|
37
32
|
"use strict";
|
|
38
33
|
var CommanderError2 = class extends Error {
|
|
39
34
|
/**
|
|
@@ -62,14 +57,14 @@ var require_error = __commonJS({
|
|
|
62
57
|
this.name = this.constructor.name;
|
|
63
58
|
}
|
|
64
59
|
};
|
|
65
|
-
|
|
66
|
-
|
|
60
|
+
exports2.CommanderError = CommanderError2;
|
|
61
|
+
exports2.InvalidArgumentError = InvalidArgumentError2;
|
|
67
62
|
}
|
|
68
63
|
});
|
|
69
64
|
|
|
70
65
|
// ../../node_modules/commander/lib/argument.js
|
|
71
66
|
var require_argument = __commonJS({
|
|
72
|
-
"../../node_modules/commander/lib/argument.js"(
|
|
67
|
+
"../../node_modules/commander/lib/argument.js"(exports2) {
|
|
73
68
|
"use strict";
|
|
74
69
|
var { InvalidArgumentError: InvalidArgumentError2 } = require_error();
|
|
75
70
|
var Argument2 = class {
|
|
@@ -190,14 +185,14 @@ var require_argument = __commonJS({
|
|
|
190
185
|
const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
|
|
191
186
|
return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
|
|
192
187
|
}
|
|
193
|
-
|
|
194
|
-
|
|
188
|
+
exports2.Argument = Argument2;
|
|
189
|
+
exports2.humanReadableArgName = humanReadableArgName;
|
|
195
190
|
}
|
|
196
191
|
});
|
|
197
192
|
|
|
198
193
|
// ../../node_modules/commander/lib/help.js
|
|
199
194
|
var require_help = __commonJS({
|
|
200
|
-
"../../node_modules/commander/lib/help.js"(
|
|
195
|
+
"../../node_modules/commander/lib/help.js"(exports2) {
|
|
201
196
|
"use strict";
|
|
202
197
|
var { humanReadableArgName } = require_argument();
|
|
203
198
|
var Help2 = class {
|
|
@@ -475,7 +470,11 @@ var require_help = __commonJS({
|
|
|
475
470
|
extraInfo.push(`env: ${option.envVar}`);
|
|
476
471
|
}
|
|
477
472
|
if (extraInfo.length > 0) {
|
|
478
|
-
|
|
473
|
+
const extraDescription = `(${extraInfo.join(", ")})`;
|
|
474
|
+
if (option.description) {
|
|
475
|
+
return `${option.description} ${extraDescription}`;
|
|
476
|
+
}
|
|
477
|
+
return extraDescription;
|
|
479
478
|
}
|
|
480
479
|
return option.description;
|
|
481
480
|
}
|
|
@@ -507,6 +506,41 @@ var require_help = __commonJS({
|
|
|
507
506
|
}
|
|
508
507
|
return argument.description;
|
|
509
508
|
}
|
|
509
|
+
/**
|
|
510
|
+
* Format a list of items, given a heading and an array of formatted items.
|
|
511
|
+
*
|
|
512
|
+
* @param {string} heading
|
|
513
|
+
* @param {string[]} items
|
|
514
|
+
* @param {Help} helper
|
|
515
|
+
* @returns string[]
|
|
516
|
+
*/
|
|
517
|
+
formatItemList(heading, items, helper) {
|
|
518
|
+
if (items.length === 0) return [];
|
|
519
|
+
return [helper.styleTitle(heading), ...items, ""];
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Group items by their help group heading.
|
|
523
|
+
*
|
|
524
|
+
* @param {Command[] | Option[]} unsortedItems
|
|
525
|
+
* @param {Command[] | Option[]} visibleItems
|
|
526
|
+
* @param {Function} getGroup
|
|
527
|
+
* @returns {Map<string, Command[] | Option[]>}
|
|
528
|
+
*/
|
|
529
|
+
groupItems(unsortedItems, visibleItems, getGroup) {
|
|
530
|
+
const result = /* @__PURE__ */ new Map();
|
|
531
|
+
unsortedItems.forEach((item) => {
|
|
532
|
+
const group = getGroup(item);
|
|
533
|
+
if (!result.has(group)) result.set(group, []);
|
|
534
|
+
});
|
|
535
|
+
visibleItems.forEach((item) => {
|
|
536
|
+
const group = getGroup(item);
|
|
537
|
+
if (!result.has(group)) {
|
|
538
|
+
result.set(group, []);
|
|
539
|
+
}
|
|
540
|
+
result.get(group).push(item);
|
|
541
|
+
});
|
|
542
|
+
return result;
|
|
543
|
+
}
|
|
510
544
|
/**
|
|
511
545
|
* Generate the built-in help text.
|
|
512
546
|
*
|
|
@@ -540,26 +574,23 @@ var require_help = __commonJS({
|
|
|
540
574
|
helper.styleArgumentDescription(helper.argumentDescription(argument))
|
|
541
575
|
);
|
|
542
576
|
});
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
577
|
+
output = output.concat(
|
|
578
|
+
this.formatItemList("Arguments:", argumentList, helper)
|
|
579
|
+
);
|
|
580
|
+
const optionGroups = this.groupItems(
|
|
581
|
+
cmd.options,
|
|
582
|
+
helper.visibleOptions(cmd),
|
|
583
|
+
(option) => option.helpGroupHeading ?? "Options:"
|
|
584
|
+
);
|
|
585
|
+
optionGroups.forEach((options, group) => {
|
|
586
|
+
const optionList = options.map((option) => {
|
|
587
|
+
return callFormatItem(
|
|
588
|
+
helper.styleOptionTerm(helper.optionTerm(option)),
|
|
589
|
+
helper.styleOptionDescription(helper.optionDescription(option))
|
|
590
|
+
);
|
|
591
|
+
});
|
|
592
|
+
output = output.concat(this.formatItemList(group, optionList, helper));
|
|
555
593
|
});
|
|
556
|
-
if (optionList.length > 0) {
|
|
557
|
-
output = output.concat([
|
|
558
|
-
helper.styleTitle("Options:"),
|
|
559
|
-
...optionList,
|
|
560
|
-
""
|
|
561
|
-
]);
|
|
562
|
-
}
|
|
563
594
|
if (helper.showGlobalOptions) {
|
|
564
595
|
const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
|
|
565
596
|
return callFormatItem(
|
|
@@ -567,27 +598,24 @@ var require_help = __commonJS({
|
|
|
567
598
|
helper.styleOptionDescription(helper.optionDescription(option))
|
|
568
599
|
);
|
|
569
600
|
});
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
helper.styleTitle("Global Options:"),
|
|
573
|
-
...globalOptionList,
|
|
574
|
-
""
|
|
575
|
-
]);
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
const commandList = helper.visibleCommands(cmd).map((cmd2) => {
|
|
579
|
-
return callFormatItem(
|
|
580
|
-
helper.styleSubcommandTerm(helper.subcommandTerm(cmd2)),
|
|
581
|
-
helper.styleSubcommandDescription(helper.subcommandDescription(cmd2))
|
|
601
|
+
output = output.concat(
|
|
602
|
+
this.formatItemList("Global Options:", globalOptionList, helper)
|
|
582
603
|
);
|
|
583
|
-
});
|
|
584
|
-
if (commandList.length > 0) {
|
|
585
|
-
output = output.concat([
|
|
586
|
-
helper.styleTitle("Commands:"),
|
|
587
|
-
...commandList,
|
|
588
|
-
""
|
|
589
|
-
]);
|
|
590
604
|
}
|
|
605
|
+
const commandGroups = this.groupItems(
|
|
606
|
+
cmd.commands,
|
|
607
|
+
helper.visibleCommands(cmd),
|
|
608
|
+
(sub) => sub.helpGroup() || "Commands:"
|
|
609
|
+
);
|
|
610
|
+
commandGroups.forEach((commands, group) => {
|
|
611
|
+
const commandList = commands.map((sub) => {
|
|
612
|
+
return callFormatItem(
|
|
613
|
+
helper.styleSubcommandTerm(helper.subcommandTerm(sub)),
|
|
614
|
+
helper.styleSubcommandDescription(helper.subcommandDescription(sub))
|
|
615
|
+
);
|
|
616
|
+
});
|
|
617
|
+
output = output.concat(this.formatItemList(group, commandList, helper));
|
|
618
|
+
});
|
|
591
619
|
return output.join("\n");
|
|
592
620
|
}
|
|
593
621
|
/**
|
|
@@ -760,14 +788,14 @@ ${itemIndentStr}`);
|
|
|
760
788
|
const sgrPattern = /\x1b\[\d*(;\d*)*m/g;
|
|
761
789
|
return str.replace(sgrPattern, "");
|
|
762
790
|
}
|
|
763
|
-
|
|
764
|
-
|
|
791
|
+
exports2.Help = Help2;
|
|
792
|
+
exports2.stripColor = stripColor;
|
|
765
793
|
}
|
|
766
794
|
});
|
|
767
795
|
|
|
768
796
|
// ../../node_modules/commander/lib/option.js
|
|
769
797
|
var require_option = __commonJS({
|
|
770
|
-
"../../node_modules/commander/lib/option.js"(
|
|
798
|
+
"../../node_modules/commander/lib/option.js"(exports2) {
|
|
771
799
|
"use strict";
|
|
772
800
|
var { InvalidArgumentError: InvalidArgumentError2 } = require_error();
|
|
773
801
|
var Option2 = class {
|
|
@@ -800,6 +828,7 @@ var require_option = __commonJS({
|
|
|
800
828
|
this.argChoices = void 0;
|
|
801
829
|
this.conflictsWith = [];
|
|
802
830
|
this.implied = void 0;
|
|
831
|
+
this.helpGroupHeading = void 0;
|
|
803
832
|
}
|
|
804
833
|
/**
|
|
805
834
|
* Set the default value, and optionally supply the description to be displayed in the help.
|
|
@@ -960,6 +989,16 @@ var require_option = __commonJS({
|
|
|
960
989
|
}
|
|
961
990
|
return camelcase(this.name());
|
|
962
991
|
}
|
|
992
|
+
/**
|
|
993
|
+
* Set the help group heading.
|
|
994
|
+
*
|
|
995
|
+
* @param {string} heading
|
|
996
|
+
* @return {Option}
|
|
997
|
+
*/
|
|
998
|
+
helpGroup(heading) {
|
|
999
|
+
this.helpGroupHeading = heading;
|
|
1000
|
+
return this;
|
|
1001
|
+
}
|
|
963
1002
|
/**
|
|
964
1003
|
* Check if `arg` matches the short or long flag.
|
|
965
1004
|
*
|
|
@@ -1062,14 +1101,14 @@ var require_option = __commonJS({
|
|
|
1062
1101
|
);
|
|
1063
1102
|
return { shortFlag, longFlag };
|
|
1064
1103
|
}
|
|
1065
|
-
|
|
1066
|
-
|
|
1104
|
+
exports2.Option = Option2;
|
|
1105
|
+
exports2.DualOptions = DualOptions;
|
|
1067
1106
|
}
|
|
1068
1107
|
});
|
|
1069
1108
|
|
|
1070
1109
|
// ../../node_modules/commander/lib/suggestSimilar.js
|
|
1071
1110
|
var require_suggestSimilar = __commonJS({
|
|
1072
|
-
"../../node_modules/commander/lib/suggestSimilar.js"(
|
|
1111
|
+
"../../node_modules/commander/lib/suggestSimilar.js"(exports2) {
|
|
1073
1112
|
"use strict";
|
|
1074
1113
|
var maxDistance = 3;
|
|
1075
1114
|
function editDistance(a, b) {
|
|
@@ -1144,19 +1183,19 @@ var require_suggestSimilar = __commonJS({
|
|
|
1144
1183
|
}
|
|
1145
1184
|
return "";
|
|
1146
1185
|
}
|
|
1147
|
-
|
|
1186
|
+
exports2.suggestSimilar = suggestSimilar;
|
|
1148
1187
|
}
|
|
1149
1188
|
});
|
|
1150
1189
|
|
|
1151
1190
|
// ../../node_modules/commander/lib/command.js
|
|
1152
1191
|
var require_command = __commonJS({
|
|
1153
|
-
"../../node_modules/commander/lib/command.js"(
|
|
1192
|
+
"../../node_modules/commander/lib/command.js"(exports2) {
|
|
1154
1193
|
"use strict";
|
|
1155
|
-
var EventEmitter =
|
|
1156
|
-
var childProcess =
|
|
1157
|
-
var
|
|
1158
|
-
var
|
|
1159
|
-
var process2 =
|
|
1194
|
+
var EventEmitter = require("events").EventEmitter;
|
|
1195
|
+
var childProcess = require("child_process");
|
|
1196
|
+
var path3 = require("path");
|
|
1197
|
+
var fs8 = require("fs");
|
|
1198
|
+
var process2 = require("process");
|
|
1160
1199
|
var { Argument: Argument2, humanReadableArgName } = require_argument();
|
|
1161
1200
|
var { CommanderError: CommanderError2 } = require_error();
|
|
1162
1201
|
var { Help: Help2, stripColor } = require_help();
|
|
@@ -1217,6 +1256,9 @@ var require_command = __commonJS({
|
|
|
1217
1256
|
this._addImplicitHelpCommand = void 0;
|
|
1218
1257
|
this._helpCommand = void 0;
|
|
1219
1258
|
this._helpConfiguration = {};
|
|
1259
|
+
this._helpGroupHeading = void 0;
|
|
1260
|
+
this._defaultCommandGroup = void 0;
|
|
1261
|
+
this._defaultOptionGroup = void 0;
|
|
1220
1262
|
}
|
|
1221
1263
|
/**
|
|
1222
1264
|
* Copy settings that are useful to have in common across root command and subcommands.
|
|
@@ -1356,7 +1398,11 @@ var require_command = __commonJS({
|
|
|
1356
1398
|
*/
|
|
1357
1399
|
configureOutput(configuration) {
|
|
1358
1400
|
if (configuration === void 0) return this._outputConfiguration;
|
|
1359
|
-
Object.assign(
|
|
1401
|
+
this._outputConfiguration = Object.assign(
|
|
1402
|
+
{},
|
|
1403
|
+
this._outputConfiguration,
|
|
1404
|
+
configuration
|
|
1405
|
+
);
|
|
1360
1406
|
return this;
|
|
1361
1407
|
}
|
|
1362
1408
|
/**
|
|
@@ -1427,16 +1473,16 @@ var require_command = __commonJS({
|
|
|
1427
1473
|
*
|
|
1428
1474
|
* @param {string} name
|
|
1429
1475
|
* @param {string} [description]
|
|
1430
|
-
* @param {(Function|*)} [
|
|
1476
|
+
* @param {(Function|*)} [parseArg] - custom argument processing function or default value
|
|
1431
1477
|
* @param {*} [defaultValue]
|
|
1432
1478
|
* @return {Command} `this` command for chaining
|
|
1433
1479
|
*/
|
|
1434
|
-
argument(name, description,
|
|
1480
|
+
argument(name, description, parseArg, defaultValue) {
|
|
1435
1481
|
const argument = this.createArgument(name, description);
|
|
1436
|
-
if (typeof
|
|
1437
|
-
argument.default(defaultValue).argParser(
|
|
1482
|
+
if (typeof parseArg === "function") {
|
|
1483
|
+
argument.default(defaultValue).argParser(parseArg);
|
|
1438
1484
|
} else {
|
|
1439
|
-
argument.default(
|
|
1485
|
+
argument.default(parseArg);
|
|
1440
1486
|
}
|
|
1441
1487
|
this.addArgument(argument);
|
|
1442
1488
|
return this;
|
|
@@ -1495,10 +1541,13 @@ var require_command = __commonJS({
|
|
|
1495
1541
|
helpCommand(enableOrNameAndArgs, description) {
|
|
1496
1542
|
if (typeof enableOrNameAndArgs === "boolean") {
|
|
1497
1543
|
this._addImplicitHelpCommand = enableOrNameAndArgs;
|
|
1544
|
+
if (enableOrNameAndArgs && this._defaultCommandGroup) {
|
|
1545
|
+
this._initCommandGroup(this._getHelpCommand());
|
|
1546
|
+
}
|
|
1498
1547
|
return this;
|
|
1499
1548
|
}
|
|
1500
|
-
|
|
1501
|
-
const [, helpName, helpArgs] =
|
|
1549
|
+
const nameAndArgs = enableOrNameAndArgs ?? "help [command]";
|
|
1550
|
+
const [, helpName, helpArgs] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
1502
1551
|
const helpDescription = description ?? "display help for command";
|
|
1503
1552
|
const helpCommand = this.createCommand(helpName);
|
|
1504
1553
|
helpCommand.helpOption(false);
|
|
@@ -1506,6 +1555,7 @@ var require_command = __commonJS({
|
|
|
1506
1555
|
if (helpDescription) helpCommand.description(helpDescription);
|
|
1507
1556
|
this._addImplicitHelpCommand = true;
|
|
1508
1557
|
this._helpCommand = helpCommand;
|
|
1558
|
+
if (enableOrNameAndArgs || description) this._initCommandGroup(helpCommand);
|
|
1509
1559
|
return this;
|
|
1510
1560
|
}
|
|
1511
1561
|
/**
|
|
@@ -1522,6 +1572,7 @@ var require_command = __commonJS({
|
|
|
1522
1572
|
}
|
|
1523
1573
|
this._addImplicitHelpCommand = true;
|
|
1524
1574
|
this._helpCommand = helpCommand;
|
|
1575
|
+
this._initCommandGroup(helpCommand);
|
|
1525
1576
|
return this;
|
|
1526
1577
|
}
|
|
1527
1578
|
/**
|
|
@@ -1670,6 +1721,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1670
1721
|
throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
|
|
1671
1722
|
- already used by option '${matchingOption.flags}'`);
|
|
1672
1723
|
}
|
|
1724
|
+
this._initOptionGroup(option);
|
|
1673
1725
|
this.options.push(option);
|
|
1674
1726
|
}
|
|
1675
1727
|
/**
|
|
@@ -1693,6 +1745,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1693
1745
|
`cannot add command '${newCmd}' as already have command '${existingCmd}'`
|
|
1694
1746
|
);
|
|
1695
1747
|
}
|
|
1748
|
+
this._initCommandGroup(command);
|
|
1696
1749
|
this.commands.push(command);
|
|
1697
1750
|
}
|
|
1698
1751
|
/**
|
|
@@ -2136,7 +2189,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2136
2189
|
* @param {string} subcommandName
|
|
2137
2190
|
*/
|
|
2138
2191
|
_checkForMissingExecutable(executableFile, executableDir, subcommandName) {
|
|
2139
|
-
if (
|
|
2192
|
+
if (fs8.existsSync(executableFile)) return;
|
|
2140
2193
|
const executableDirMessage = executableDir ? `searched for local subcommand relative to directory '${executableDir}'` : "no directory for search for local subcommand, use .executableDir() to supply a custom directory";
|
|
2141
2194
|
const executableMissing = `'${executableFile}' does not exist
|
|
2142
2195
|
- if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
@@ -2154,11 +2207,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2154
2207
|
let launchWithNode = false;
|
|
2155
2208
|
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
2156
2209
|
function findFile(baseDir, baseName) {
|
|
2157
|
-
const localBin =
|
|
2158
|
-
if (
|
|
2159
|
-
if (sourceExt.includes(
|
|
2210
|
+
const localBin = path3.resolve(baseDir, baseName);
|
|
2211
|
+
if (fs8.existsSync(localBin)) return localBin;
|
|
2212
|
+
if (sourceExt.includes(path3.extname(baseName))) return void 0;
|
|
2160
2213
|
const foundExt = sourceExt.find(
|
|
2161
|
-
(ext) =>
|
|
2214
|
+
(ext) => fs8.existsSync(`${localBin}${ext}`)
|
|
2162
2215
|
);
|
|
2163
2216
|
if (foundExt) return `${localBin}${foundExt}`;
|
|
2164
2217
|
return void 0;
|
|
@@ -2170,21 +2223,21 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2170
2223
|
if (this._scriptPath) {
|
|
2171
2224
|
let resolvedScriptPath;
|
|
2172
2225
|
try {
|
|
2173
|
-
resolvedScriptPath =
|
|
2226
|
+
resolvedScriptPath = fs8.realpathSync(this._scriptPath);
|
|
2174
2227
|
} catch {
|
|
2175
2228
|
resolvedScriptPath = this._scriptPath;
|
|
2176
2229
|
}
|
|
2177
|
-
executableDir =
|
|
2178
|
-
|
|
2230
|
+
executableDir = path3.resolve(
|
|
2231
|
+
path3.dirname(resolvedScriptPath),
|
|
2179
2232
|
executableDir
|
|
2180
2233
|
);
|
|
2181
2234
|
}
|
|
2182
2235
|
if (executableDir) {
|
|
2183
2236
|
let localFile = findFile(executableDir, executableFile);
|
|
2184
2237
|
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
2185
|
-
const legacyName =
|
|
2238
|
+
const legacyName = path3.basename(
|
|
2186
2239
|
this._scriptPath,
|
|
2187
|
-
|
|
2240
|
+
path3.extname(this._scriptPath)
|
|
2188
2241
|
);
|
|
2189
2242
|
if (legacyName !== this._name) {
|
|
2190
2243
|
localFile = findFile(
|
|
@@ -2195,7 +2248,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2195
2248
|
}
|
|
2196
2249
|
executableFile = localFile || executableFile;
|
|
2197
2250
|
}
|
|
2198
|
-
launchWithNode = sourceExt.includes(
|
|
2251
|
+
launchWithNode = sourceExt.includes(path3.extname(executableFile));
|
|
2199
2252
|
let proc;
|
|
2200
2253
|
if (process2.platform !== "win32") {
|
|
2201
2254
|
if (launchWithNode) {
|
|
@@ -2604,6 +2657,12 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2604
2657
|
function maybeOption(arg) {
|
|
2605
2658
|
return arg.length > 1 && arg[0] === "-";
|
|
2606
2659
|
}
|
|
2660
|
+
const negativeNumberArg = (arg) => {
|
|
2661
|
+
if (!/^-\d*\.?\d+(e[+-]?\d+)?$/.test(arg)) return false;
|
|
2662
|
+
return !this._getCommandAndAncestors().some(
|
|
2663
|
+
(cmd) => cmd.options.map((opt) => opt.short).some((short) => /^-\d$/.test(short))
|
|
2664
|
+
);
|
|
2665
|
+
};
|
|
2607
2666
|
let activeVariadicOption = null;
|
|
2608
2667
|
while (args.length) {
|
|
2609
2668
|
const arg = args.shift();
|
|
@@ -2612,7 +2671,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2612
2671
|
dest.push(...args);
|
|
2613
2672
|
break;
|
|
2614
2673
|
}
|
|
2615
|
-
if (activeVariadicOption && !maybeOption(arg)) {
|
|
2674
|
+
if (activeVariadicOption && (!maybeOption(arg) || negativeNumberArg(arg))) {
|
|
2616
2675
|
this.emit(`option:${activeVariadicOption.name()}`, arg);
|
|
2617
2676
|
continue;
|
|
2618
2677
|
}
|
|
@@ -2626,7 +2685,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2626
2685
|
this.emit(`option:${option.name()}`, value);
|
|
2627
2686
|
} else if (option.optional) {
|
|
2628
2687
|
let value = null;
|
|
2629
|
-
if (args.length > 0 && !maybeOption(args[0])) {
|
|
2688
|
+
if (args.length > 0 && (!maybeOption(args[0]) || negativeNumberArg(args[0]))) {
|
|
2630
2689
|
value = args.shift();
|
|
2631
2690
|
}
|
|
2632
2691
|
this.emit(`option:${option.name()}`, value);
|
|
@@ -2657,7 +2716,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2657
2716
|
continue;
|
|
2658
2717
|
}
|
|
2659
2718
|
}
|
|
2660
|
-
if (maybeOption(arg)) {
|
|
2719
|
+
if (dest === operands && maybeOption(arg) && !(this.commands.length === 0 && negativeNumberArg(arg))) {
|
|
2661
2720
|
dest = unknown;
|
|
2662
2721
|
}
|
|
2663
2722
|
if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
|
|
@@ -3029,6 +3088,69 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3029
3088
|
this._name = str;
|
|
3030
3089
|
return this;
|
|
3031
3090
|
}
|
|
3091
|
+
/**
|
|
3092
|
+
* Set/get the help group heading for this subcommand in parent command's help.
|
|
3093
|
+
*
|
|
3094
|
+
* @param {string} [heading]
|
|
3095
|
+
* @return {Command | string}
|
|
3096
|
+
*/
|
|
3097
|
+
helpGroup(heading) {
|
|
3098
|
+
if (heading === void 0) return this._helpGroupHeading ?? "";
|
|
3099
|
+
this._helpGroupHeading = heading;
|
|
3100
|
+
return this;
|
|
3101
|
+
}
|
|
3102
|
+
/**
|
|
3103
|
+
* Set/get the default help group heading for subcommands added to this command.
|
|
3104
|
+
* (This does not override a group set directly on the subcommand using .helpGroup().)
|
|
3105
|
+
*
|
|
3106
|
+
* @example
|
|
3107
|
+
* program.commandsGroup('Development Commands:);
|
|
3108
|
+
* program.command('watch')...
|
|
3109
|
+
* program.command('lint')...
|
|
3110
|
+
* ...
|
|
3111
|
+
*
|
|
3112
|
+
* @param {string} [heading]
|
|
3113
|
+
* @returns {Command | string}
|
|
3114
|
+
*/
|
|
3115
|
+
commandsGroup(heading) {
|
|
3116
|
+
if (heading === void 0) return this._defaultCommandGroup ?? "";
|
|
3117
|
+
this._defaultCommandGroup = heading;
|
|
3118
|
+
return this;
|
|
3119
|
+
}
|
|
3120
|
+
/**
|
|
3121
|
+
* Set/get the default help group heading for options added to this command.
|
|
3122
|
+
* (This does not override a group set directly on the option using .helpGroup().)
|
|
3123
|
+
*
|
|
3124
|
+
* @example
|
|
3125
|
+
* program
|
|
3126
|
+
* .optionsGroup('Development Options:')
|
|
3127
|
+
* .option('-d, --debug', 'output extra debugging')
|
|
3128
|
+
* .option('-p, --profile', 'output profiling information')
|
|
3129
|
+
*
|
|
3130
|
+
* @param {string} [heading]
|
|
3131
|
+
* @returns {Command | string}
|
|
3132
|
+
*/
|
|
3133
|
+
optionsGroup(heading) {
|
|
3134
|
+
if (heading === void 0) return this._defaultOptionGroup ?? "";
|
|
3135
|
+
this._defaultOptionGroup = heading;
|
|
3136
|
+
return this;
|
|
3137
|
+
}
|
|
3138
|
+
/**
|
|
3139
|
+
* @param {Option} option
|
|
3140
|
+
* @private
|
|
3141
|
+
*/
|
|
3142
|
+
_initOptionGroup(option) {
|
|
3143
|
+
if (this._defaultOptionGroup && !option.helpGroupHeading)
|
|
3144
|
+
option.helpGroup(this._defaultOptionGroup);
|
|
3145
|
+
}
|
|
3146
|
+
/**
|
|
3147
|
+
* @param {Command} cmd
|
|
3148
|
+
* @private
|
|
3149
|
+
*/
|
|
3150
|
+
_initCommandGroup(cmd) {
|
|
3151
|
+
if (this._defaultCommandGroup && !cmd.helpGroup())
|
|
3152
|
+
cmd.helpGroup(this._defaultCommandGroup);
|
|
3153
|
+
}
|
|
3032
3154
|
/**
|
|
3033
3155
|
* Set the name of the command from script filename, such as process.argv[1],
|
|
3034
3156
|
* or require.main.filename, or __filename.
|
|
@@ -3042,7 +3164,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3042
3164
|
* @return {Command}
|
|
3043
3165
|
*/
|
|
3044
3166
|
nameFromFilename(filename) {
|
|
3045
|
-
this._name =
|
|
3167
|
+
this._name = path3.basename(filename, path3.extname(filename));
|
|
3046
3168
|
return this;
|
|
3047
3169
|
}
|
|
3048
3170
|
/**
|
|
@@ -3056,9 +3178,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3056
3178
|
* @param {string} [path]
|
|
3057
3179
|
* @return {(string|null|Command)}
|
|
3058
3180
|
*/
|
|
3059
|
-
executableDir(
|
|
3060
|
-
if (
|
|
3061
|
-
this._executableDir =
|
|
3181
|
+
executableDir(path4) {
|
|
3182
|
+
if (path4 === void 0) return this._executableDir;
|
|
3183
|
+
this._executableDir = path4;
|
|
3062
3184
|
return this;
|
|
3063
3185
|
}
|
|
3064
3186
|
/**
|
|
@@ -3163,15 +3285,20 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3163
3285
|
helpOption(flags, description) {
|
|
3164
3286
|
if (typeof flags === "boolean") {
|
|
3165
3287
|
if (flags) {
|
|
3166
|
-
this._helpOption
|
|
3288
|
+
if (this._helpOption === null) this._helpOption = void 0;
|
|
3289
|
+
if (this._defaultOptionGroup) {
|
|
3290
|
+
this._initOptionGroup(this._getHelpOption());
|
|
3291
|
+
}
|
|
3167
3292
|
} else {
|
|
3168
3293
|
this._helpOption = null;
|
|
3169
3294
|
}
|
|
3170
3295
|
return this;
|
|
3171
3296
|
}
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3297
|
+
this._helpOption = this.createOption(
|
|
3298
|
+
flags ?? "-h, --help",
|
|
3299
|
+
description ?? "display help for command"
|
|
3300
|
+
);
|
|
3301
|
+
if (flags || description) this._initOptionGroup(this._helpOption);
|
|
3175
3302
|
return this;
|
|
3176
3303
|
}
|
|
3177
3304
|
/**
|
|
@@ -3196,6 +3323,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3196
3323
|
*/
|
|
3197
3324
|
addHelpOption(option) {
|
|
3198
3325
|
this._helpOption = option;
|
|
3326
|
+
this._initOptionGroup(option);
|
|
3199
3327
|
return this;
|
|
3200
3328
|
}
|
|
3201
3329
|
/**
|
|
@@ -3303,31 +3431,31 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3303
3431
|
return true;
|
|
3304
3432
|
return void 0;
|
|
3305
3433
|
}
|
|
3306
|
-
|
|
3307
|
-
|
|
3434
|
+
exports2.Command = Command2;
|
|
3435
|
+
exports2.useColor = useColor;
|
|
3308
3436
|
}
|
|
3309
3437
|
});
|
|
3310
3438
|
|
|
3311
3439
|
// ../../node_modules/commander/index.js
|
|
3312
3440
|
var require_commander = __commonJS({
|
|
3313
|
-
"../../node_modules/commander/index.js"(
|
|
3441
|
+
"../../node_modules/commander/index.js"(exports2) {
|
|
3314
3442
|
"use strict";
|
|
3315
3443
|
var { Argument: Argument2 } = require_argument();
|
|
3316
3444
|
var { Command: Command2 } = require_command();
|
|
3317
3445
|
var { CommanderError: CommanderError2, InvalidArgumentError: InvalidArgumentError2 } = require_error();
|
|
3318
3446
|
var { Help: Help2 } = require_help();
|
|
3319
3447
|
var { Option: Option2 } = require_option();
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3448
|
+
exports2.program = new Command2();
|
|
3449
|
+
exports2.createCommand = (name) => new Command2(name);
|
|
3450
|
+
exports2.createOption = (flags, description) => new Option2(flags, description);
|
|
3451
|
+
exports2.createArgument = (name, description) => new Argument2(name, description);
|
|
3452
|
+
exports2.Command = Command2;
|
|
3453
|
+
exports2.Option = Option2;
|
|
3454
|
+
exports2.Argument = Argument2;
|
|
3455
|
+
exports2.Help = Help2;
|
|
3456
|
+
exports2.CommanderError = CommanderError2;
|
|
3457
|
+
exports2.InvalidArgumentError = InvalidArgumentError2;
|
|
3458
|
+
exports2.InvalidOptionArgumentError = InvalidArgumentError2;
|
|
3331
3459
|
}
|
|
3332
3460
|
});
|
|
3333
3461
|
|
|
@@ -3349,44 +3477,147 @@ var {
|
|
|
3349
3477
|
} = import_index.default;
|
|
3350
3478
|
|
|
3351
3479
|
// bin/index.ts
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
var
|
|
3356
|
-
program2.name("js-style-kit").description(
|
|
3357
|
-
"Initialize JavaScript/TypeScript project with style configurations"
|
|
3358
|
-
).version("1.0.0");
|
|
3480
|
+
var import_node_fs7 = __toESM(require("fs"), 1);
|
|
3481
|
+
|
|
3482
|
+
// bin/lib/detect-package-manager.ts
|
|
3483
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
3359
3484
|
var detectPackageManager = () => {
|
|
3360
|
-
|
|
3361
|
-
|
|
3485
|
+
try {
|
|
3486
|
+
if (import_node_fs.default.existsSync("bun.lock") || import_node_fs.default.existsSync("bun.lockb")) {
|
|
3487
|
+
return "bun";
|
|
3488
|
+
}
|
|
3489
|
+
if (import_node_fs.default.existsSync("pnpm-lock.yaml")) {
|
|
3490
|
+
return "pnpm";
|
|
3491
|
+
}
|
|
3492
|
+
if (import_node_fs.default.existsSync("yarn.lock")) {
|
|
3493
|
+
return "yarn";
|
|
3494
|
+
}
|
|
3495
|
+
} catch {
|
|
3362
3496
|
}
|
|
3363
|
-
|
|
3364
|
-
|
|
3497
|
+
return "npm";
|
|
3498
|
+
};
|
|
3499
|
+
|
|
3500
|
+
// bin/lib/setup-config-files.ts
|
|
3501
|
+
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
3502
|
+
var setupConfigFiles = () => {
|
|
3503
|
+
console.info("Creating configuration files...");
|
|
3504
|
+
let extension = ".js";
|
|
3505
|
+
try {
|
|
3506
|
+
const packageJson = JSON.parse(import_node_fs2.default.readFileSync("package.json", "utf8"));
|
|
3507
|
+
const isEsm = packageJson.type === "module";
|
|
3508
|
+
extension = isEsm ? ".js" : ".mjs";
|
|
3509
|
+
const prettierConfigContent = `//@ts-check
|
|
3510
|
+
import { prettierConfig } from "js-style-kit";
|
|
3511
|
+
|
|
3512
|
+
export default prettierConfig({});
|
|
3513
|
+
`;
|
|
3514
|
+
const eslintConfigContent = `//@ts-check
|
|
3515
|
+
import { eslintConfig } from "js-style-kit";
|
|
3516
|
+
|
|
3517
|
+
export default eslintConfig({});
|
|
3518
|
+
`;
|
|
3519
|
+
import_node_fs2.default.writeFileSync(`prettier.config${extension}`, prettierConfigContent);
|
|
3520
|
+
import_node_fs2.default.writeFileSync(`eslint.config${extension}`, eslintConfigContent);
|
|
3521
|
+
console.info(`Created configuration files with ${extension} extension`);
|
|
3522
|
+
} catch (error) {
|
|
3523
|
+
console.error("Failed to create configuration files:", error);
|
|
3524
|
+
process.exit(1);
|
|
3365
3525
|
}
|
|
3366
|
-
|
|
3367
|
-
|
|
3526
|
+
return extension;
|
|
3527
|
+
};
|
|
3528
|
+
|
|
3529
|
+
// bin/lib/setup-dependencies.ts
|
|
3530
|
+
var import_node_child_process = require("child_process");
|
|
3531
|
+
var import_node_fs4 = __toESM(require("fs"), 1);
|
|
3532
|
+
|
|
3533
|
+
// bin/lib/get-dependencies.ts
|
|
3534
|
+
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
3535
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
3536
|
+
var getDependencies = () => {
|
|
3537
|
+
const nodeModulesPath = import_node_path.default.join(
|
|
3538
|
+
process.cwd(),
|
|
3539
|
+
"node_modules",
|
|
3540
|
+
"js-style-kit",
|
|
3541
|
+
"package.json"
|
|
3542
|
+
);
|
|
3543
|
+
try {
|
|
3544
|
+
if (import_node_fs3.default.existsSync(nodeModulesPath)) {
|
|
3545
|
+
const jsStyleKitPackageJson = JSON.parse(
|
|
3546
|
+
import_node_fs3.default.readFileSync(nodeModulesPath, "utf8")
|
|
3547
|
+
);
|
|
3548
|
+
const dependencies = Object.keys(
|
|
3549
|
+
jsStyleKitPackageJson.dependencies || {}
|
|
3550
|
+
);
|
|
3551
|
+
console.info(
|
|
3552
|
+
`Found ${dependencies.length} dependencies in js-style-kit to remove`
|
|
3553
|
+
);
|
|
3554
|
+
return dependencies;
|
|
3555
|
+
}
|
|
3556
|
+
} catch {
|
|
3557
|
+
console.warn(
|
|
3558
|
+
"Could not read js-style-kit package.json from node_modules, using fallback list"
|
|
3559
|
+
);
|
|
3368
3560
|
}
|
|
3369
|
-
return
|
|
3561
|
+
return [
|
|
3562
|
+
"eslint",
|
|
3563
|
+
"prettier",
|
|
3564
|
+
"@prettier/plugin-oxc",
|
|
3565
|
+
"@typescript-eslint/parser",
|
|
3566
|
+
"eslint-import-resolver-typescript",
|
|
3567
|
+
"eslint-plugin-import-x",
|
|
3568
|
+
"eslint-plugin-jest",
|
|
3569
|
+
"eslint-plugin-jsdoc",
|
|
3570
|
+
"eslint-plugin-nextjs",
|
|
3571
|
+
"eslint-plugin-perfectionist",
|
|
3572
|
+
"eslint-plugin-prefer-arrow-functions",
|
|
3573
|
+
"eslint-plugin-react",
|
|
3574
|
+
"eslint-plugin-react-hooks",
|
|
3575
|
+
"eslint-plugin-react-refresh",
|
|
3576
|
+
"eslint-plugin-storybook",
|
|
3577
|
+
"eslint-plugin-turbo",
|
|
3578
|
+
"eslint-plugin-unicorn",
|
|
3579
|
+
"eslint-plugin-vitest",
|
|
3580
|
+
"globals",
|
|
3581
|
+
"prettier-plugin-css-order",
|
|
3582
|
+
"prettier-plugin-curly",
|
|
3583
|
+
"prettier-plugin-packagejson",
|
|
3584
|
+
"prettier-plugin-sort-json",
|
|
3585
|
+
"prettier-plugin-tailwindcss",
|
|
3586
|
+
"typescript-eslint"
|
|
3587
|
+
];
|
|
3370
3588
|
};
|
|
3371
|
-
|
|
3589
|
+
|
|
3590
|
+
// bin/lib/setup-dependencies.ts
|
|
3591
|
+
var setupDependencies = (packageManager, dryRun = false) => {
|
|
3372
3592
|
console.info(`Using package manager: ${packageManager}`);
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3593
|
+
if (dryRun) {
|
|
3594
|
+
console.info("Would install js-style-kit (dry run)");
|
|
3595
|
+
} else {
|
|
3596
|
+
console.info("Installing js-style-kit...");
|
|
3597
|
+
const installCommands = {
|
|
3598
|
+
bun: "bun add --dev js-style-kit",
|
|
3599
|
+
npm: "npm install --save-dev js-style-kit",
|
|
3600
|
+
pnpm: "pnpm add --save-dev js-style-kit",
|
|
3601
|
+
yarn: "yarn add --dev js-style-kit"
|
|
3602
|
+
};
|
|
3603
|
+
const installCmd = installCommands[packageManager];
|
|
3604
|
+
(0, import_node_child_process.execSync)(installCmd, { stdio: "inherit" });
|
|
3605
|
+
}
|
|
3382
3606
|
try {
|
|
3383
|
-
const overlappingDeps =
|
|
3607
|
+
const overlappingDeps = getDependencies();
|
|
3384
3608
|
console.info("Removing overlapping dependencies...");
|
|
3385
|
-
const packageJson = JSON.parse(
|
|
3609
|
+
const packageJson = JSON.parse(import_node_fs4.default.readFileSync("package.json", "utf8"));
|
|
3610
|
+
packageJson.dependencies = packageJson.dependencies ?? {};
|
|
3386
3611
|
packageJson.devDependencies = packageJson.devDependencies ?? {};
|
|
3612
|
+
const newDeps = { ...packageJson.dependencies };
|
|
3387
3613
|
const newDevDeps = { ...packageJson.devDependencies };
|
|
3388
3614
|
let hasChanges = false;
|
|
3389
3615
|
overlappingDeps.forEach((dep) => {
|
|
3616
|
+
if (Object.prototype.hasOwnProperty.call(newDeps, dep)) {
|
|
3617
|
+
delete newDeps[dep];
|
|
3618
|
+
hasChanges = true;
|
|
3619
|
+
console.info(`Removed ${dep} from dependencies`);
|
|
3620
|
+
}
|
|
3390
3621
|
if (Object.prototype.hasOwnProperty.call(newDevDeps, dep)) {
|
|
3391
3622
|
delete newDevDeps[dep];
|
|
3392
3623
|
hasChanges = true;
|
|
@@ -3394,8 +3625,9 @@ var setupDependencies = (packageManager) => {
|
|
|
3394
3625
|
}
|
|
3395
3626
|
});
|
|
3396
3627
|
if (hasChanges) {
|
|
3628
|
+
packageJson.dependencies = newDeps;
|
|
3397
3629
|
packageJson.devDependencies = newDevDeps;
|
|
3398
|
-
|
|
3630
|
+
import_node_fs4.default.writeFileSync(
|
|
3399
3631
|
"package.json",
|
|
3400
3632
|
JSON.stringify(packageJson, null, 2).concat("\n")
|
|
3401
3633
|
);
|
|
@@ -3405,18 +3637,21 @@ var setupDependencies = (packageManager) => {
|
|
|
3405
3637
|
process.exit(1);
|
|
3406
3638
|
}
|
|
3407
3639
|
};
|
|
3640
|
+
|
|
3641
|
+
// bin/lib/setup-scripts.ts
|
|
3642
|
+
var import_node_fs5 = __toESM(require("fs"), 1);
|
|
3408
3643
|
var setupScripts = () => {
|
|
3409
3644
|
console.info("Setting up package.json scripts...");
|
|
3410
3645
|
try {
|
|
3411
|
-
const packageJson = JSON.parse(
|
|
3646
|
+
const packageJson = JSON.parse(import_node_fs5.default.readFileSync("package.json", "utf8"));
|
|
3412
3647
|
packageJson.scripts = {
|
|
3413
3648
|
...packageJson.scripts,
|
|
3414
|
-
format: "prettier
|
|
3415
|
-
"format:check": "prettier
|
|
3416
|
-
lint: "eslint
|
|
3417
|
-
"lint:fix": "eslint
|
|
3649
|
+
format: "prettier . --write --cache",
|
|
3650
|
+
"format:check": "prettier . --check --cache",
|
|
3651
|
+
lint: "eslint .",
|
|
3652
|
+
"lint:fix": "eslint . --fix"
|
|
3418
3653
|
};
|
|
3419
|
-
|
|
3654
|
+
import_node_fs5.default.writeFileSync(
|
|
3420
3655
|
"package.json",
|
|
3421
3656
|
JSON.stringify(packageJson, null, 2).concat("\n")
|
|
3422
3657
|
);
|
|
@@ -3426,47 +3661,26 @@ var setupScripts = () => {
|
|
|
3426
3661
|
process.exit(1);
|
|
3427
3662
|
}
|
|
3428
3663
|
};
|
|
3429
|
-
var setupConfigFiles = () => {
|
|
3430
|
-
console.info("Creating configuration files...");
|
|
3431
|
-
let extension = ".js";
|
|
3432
|
-
try {
|
|
3433
|
-
const packageJson = JSON.parse(fs.readFileSync("package.json", "utf8"));
|
|
3434
|
-
const isEsm = packageJson.type === "module";
|
|
3435
|
-
extension = isEsm ? ".js" : ".mjs";
|
|
3436
|
-
const prettierConfigContent = `
|
|
3437
|
-
import { prettierConfig } from "js-style-kit";
|
|
3438
|
-
|
|
3439
|
-
export default prettierConfig({});
|
|
3440
|
-
`;
|
|
3441
|
-
const eslintConfigContent = `
|
|
3442
|
-
import { eslintConfig } from "js-style-kit";
|
|
3443
3664
|
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
fs.writeFileSync(`eslint.config${extension}`, eslintConfigContent);
|
|
3448
|
-
console.info(`Created configuration files with ${extension} extension`);
|
|
3449
|
-
} catch (error) {
|
|
3450
|
-
console.error("Failed to create configuration files:", error);
|
|
3451
|
-
process.exit(1);
|
|
3452
|
-
}
|
|
3453
|
-
return extension;
|
|
3454
|
-
};
|
|
3665
|
+
// bin/lib/setup-vscode-settings.ts
|
|
3666
|
+
var import_node_fs6 = __toESM(require("fs"), 1);
|
|
3667
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
3455
3668
|
var setupVSCodeSettings = () => {
|
|
3456
3669
|
console.info("Setting up VS Code settings...");
|
|
3457
3670
|
try {
|
|
3458
|
-
const vscodeDir =
|
|
3459
|
-
const settingsPath =
|
|
3460
|
-
if (!
|
|
3461
|
-
|
|
3671
|
+
const vscodeDir = import_node_path2.default.join(process.cwd(), ".vscode");
|
|
3672
|
+
const settingsPath = import_node_path2.default.join(vscodeDir, "settings.json");
|
|
3673
|
+
if (!import_node_fs6.default.existsSync(vscodeDir)) {
|
|
3674
|
+
import_node_fs6.default.mkdirSync(vscodeDir);
|
|
3462
3675
|
}
|
|
3463
3676
|
let settings = {};
|
|
3464
|
-
if (
|
|
3465
|
-
settings = JSON.parse(
|
|
3677
|
+
if (import_node_fs6.default.existsSync(settingsPath)) {
|
|
3678
|
+
settings = JSON.parse(import_node_fs6.default.readFileSync(settingsPath, "utf8"));
|
|
3466
3679
|
}
|
|
3467
3680
|
settings = {
|
|
3468
3681
|
...settings,
|
|
3469
3682
|
"editor.codeActionsOnSave": {
|
|
3683
|
+
...settings["editor.codeActionsOnSave"] || {},
|
|
3470
3684
|
"source.fixAll.eslint": "explicit"
|
|
3471
3685
|
},
|
|
3472
3686
|
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
|
@@ -3474,7 +3688,7 @@ var setupVSCodeSettings = () => {
|
|
|
3474
3688
|
"eslint.runtime": "node",
|
|
3475
3689
|
"tailwindCSS.classFunctions": ["cn", "cva", "clsx"]
|
|
3476
3690
|
};
|
|
3477
|
-
|
|
3691
|
+
import_node_fs6.default.writeFileSync(
|
|
3478
3692
|
settingsPath,
|
|
3479
3693
|
JSON.stringify(settings, null, 2).concat("\n")
|
|
3480
3694
|
);
|
|
@@ -3484,17 +3698,31 @@ var setupVSCodeSettings = () => {
|
|
|
3484
3698
|
process.exit(1);
|
|
3485
3699
|
}
|
|
3486
3700
|
};
|
|
3487
|
-
|
|
3488
|
-
|
|
3701
|
+
|
|
3702
|
+
// bin/index.ts
|
|
3703
|
+
var program2 = new Command();
|
|
3704
|
+
program2.name("js-style-kit").description(
|
|
3705
|
+
"Initialize JavaScript/TypeScript project with style configurations"
|
|
3706
|
+
).version("1.0.0");
|
|
3707
|
+
program2.command("init").description("Initialize project with js-style-kit configurations").option(
|
|
3708
|
+
"--dry-run",
|
|
3709
|
+
"Create configuration files but skip dependency installation"
|
|
3710
|
+
).action((options) => {
|
|
3711
|
+
const dryRun = options.dryRun ?? false;
|
|
3712
|
+
if (dryRun) {
|
|
3713
|
+
console.info("Initializing js-style-kit (dry run mode)...");
|
|
3714
|
+
} else {
|
|
3715
|
+
console.info("Initializing js-style-kit...");
|
|
3716
|
+
}
|
|
3489
3717
|
try {
|
|
3490
3718
|
const packageManager = detectPackageManager();
|
|
3491
|
-
if (!
|
|
3719
|
+
if (!import_node_fs7.default.existsSync("package.json")) {
|
|
3492
3720
|
console.error(
|
|
3493
3721
|
"package.json not found. Please initialize your project first."
|
|
3494
3722
|
);
|
|
3495
3723
|
process.exit(1);
|
|
3496
3724
|
}
|
|
3497
|
-
setupDependencies(packageManager);
|
|
3725
|
+
setupDependencies(packageManager, dryRun);
|
|
3498
3726
|
setupScripts();
|
|
3499
3727
|
setupConfigFiles();
|
|
3500
3728
|
setupVSCodeSettings();
|
|
@@ -3504,20 +3732,27 @@ program2.command("init").description("Initialize project with js-style-kit confi
|
|
|
3504
3732
|
pnpm: "pnpm run",
|
|
3505
3733
|
yarn: "yarn"
|
|
3506
3734
|
};
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3735
|
+
if (dryRun) {
|
|
3736
|
+
console.info("\n\u2705 js-style-kit dry run completed successfully!");
|
|
3737
|
+
console.info(
|
|
3738
|
+
"Configuration files created, but dependencies were not installed."
|
|
3739
|
+
);
|
|
3740
|
+
} else {
|
|
3741
|
+
console.info("\n\u2705 js-style-kit initialized successfully!");
|
|
3742
|
+
console.info("\nYou can now use the following npm scripts:");
|
|
3743
|
+
console.info(
|
|
3744
|
+
` - ${runCmd[packageManager]} lint - Check code for linting issues`
|
|
3745
|
+
);
|
|
3746
|
+
console.info(
|
|
3747
|
+
` - ${runCmd[packageManager]} lint:fix - Automatically fix linting issues`
|
|
3748
|
+
);
|
|
3749
|
+
console.info(
|
|
3750
|
+
` - ${runCmd[packageManager]} format - Format code with Prettier`
|
|
3751
|
+
);
|
|
3752
|
+
console.info(
|
|
3753
|
+
` - ${runCmd[packageManager]} format:check - Check if code is properly formatted`
|
|
3754
|
+
);
|
|
3755
|
+
}
|
|
3521
3756
|
} catch (error) {
|
|
3522
3757
|
console.error("Failed to initialize js-style-kit:", { cause: error });
|
|
3523
3758
|
process.exit(1);
|
|
@@ -3527,4 +3762,4 @@ program2.parse();
|
|
|
3527
3762
|
if (!process.argv.slice(2).length) {
|
|
3528
3763
|
program2.outputHelp();
|
|
3529
3764
|
}
|
|
3530
|
-
//# sourceMappingURL=index.
|
|
3765
|
+
//# sourceMappingURL=index.cjs.map
|