@h3ravel/console 10.0.0 → 11.0.1

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.
Files changed (48) hide show
  1. package/README.md +13 -1
  2. package/dist/Commands/Command.cjs +104 -0
  3. package/dist/Commands/Command.js +7 -0
  4. package/dist/Commands/MakeCommand.cjs +433 -0
  5. package/dist/Commands/MakeCommand.js +9 -0
  6. package/dist/Commands/MigrateCommand.cjs +202 -0
  7. package/dist/Commands/MigrateCommand.js +8 -0
  8. package/dist/Commands/ServeCommand.cjs +159 -0
  9. package/dist/Commands/ServeCommand.js +8 -0
  10. package/dist/Contracts/ICommand.cjs +18 -0
  11. package/dist/Contracts/ICommand.js +1 -0
  12. package/dist/IO/app.cjs +934 -0
  13. package/dist/IO/app.js +17 -0
  14. package/dist/IO/providers.cjs +909 -0
  15. package/dist/IO/providers.js +16 -0
  16. package/dist/Kernel.cjs +892 -0
  17. package/dist/Kernel.js +14 -0
  18. package/dist/Musket.cjs +837 -0
  19. package/dist/Musket.js +13 -0
  20. package/dist/Providers/ConsoleServiceProvider.cjs +904 -0
  21. package/dist/Providers/ConsoleServiceProvider.js +15 -0
  22. package/dist/Signature.cjs +172 -0
  23. package/dist/Signature.js +7 -0
  24. package/dist/Utils.cjs +218 -0
  25. package/dist/Utils.js +9 -0
  26. package/dist/chunk-3FVPHQCH.js +151 -0
  27. package/dist/chunk-FOSDCKCR.js +106 -0
  28. package/dist/chunk-IGEFNODG.js +22 -0
  29. package/dist/chunk-KMIFCLXG.js +16 -0
  30. package/dist/chunk-NADN2PHB.js +0 -0
  31. package/dist/chunk-O45AB4MX.js +83 -0
  32. package/dist/chunk-PMV4TMFS.js +151 -0
  33. package/dist/chunk-POF4JGTX.js +186 -0
  34. package/dist/chunk-SHUYVCID.js +6 -0
  35. package/dist/chunk-SP4JKAUC.js +63 -0
  36. package/dist/chunk-TN5SV7LF.js +133 -0
  37. package/dist/chunk-UCOXL3OM.js +0 -0
  38. package/dist/chunk-URLTFJET.js +68 -0
  39. package/dist/chunk-XSL373TG.js +36 -0
  40. package/dist/index.cjs +892 -6
  41. package/dist/index.d.cts +306 -2
  42. package/dist/index.d.ts +306 -2
  43. package/dist/index.js +43 -15
  44. package/dist/run.cjs +1 -0
  45. package/dist/run.js +1 -0
  46. package/package.json +23 -6
  47. package/dist/index.cjs.map +0 -1
  48. package/dist/index.js.map +0 -1
@@ -0,0 +1,16 @@
1
+ import {
2
+ ConsoleServiceProvider
3
+ } from "./chunk-IGEFNODG.js";
4
+
5
+ // src/IO/providers.ts
6
+ import { ConfigServiceProvider } from "@h3ravel/config";
7
+ import { DatabaseServiceProvider } from "@h3ravel/database";
8
+ var providers_default = [
9
+ ConfigServiceProvider,
10
+ DatabaseServiceProvider,
11
+ ConsoleServiceProvider
12
+ ];
13
+
14
+ export {
15
+ providers_default
16
+ };
File without changes
@@ -0,0 +1,83 @@
1
+ import {
2
+ __name
3
+ } from "./chunk-SHUYVCID.js";
4
+
5
+ // src/Commands/Command.ts
6
+ var Command = class {
7
+ static {
8
+ __name(this, "Command");
9
+ }
10
+ app;
11
+ kernel;
12
+ constructor(app, kernel) {
13
+ this.app = app;
14
+ this.kernel = kernel;
15
+ }
16
+ /**
17
+ * The name and signature of the console command.
18
+ *
19
+ * @var string
20
+ */
21
+ signature;
22
+ /**
23
+ * A dictionary of signatures or what not.
24
+ *
25
+ * @var object
26
+ */
27
+ dictionary = {};
28
+ /**
29
+ * The console command description.
30
+ *
31
+ * @var string
32
+ */
33
+ description;
34
+ /**
35
+ * The console command input.
36
+ *
37
+ * @var object
38
+ */
39
+ input = {
40
+ options: {},
41
+ arguments: {}
42
+ };
43
+ /**
44
+ * Execute the console command.
45
+ */
46
+ async handle(..._args) {
47
+ }
48
+ setApplication(app) {
49
+ this.app = app;
50
+ }
51
+ setInput(options, args, regArgs, dictionary) {
52
+ this.dictionary = dictionary;
53
+ this.input.options = options;
54
+ this.input.arguments = regArgs.map((e, i) => ({
55
+ [e.name()]: args[i]
56
+ })).reduce((e, x) => Object.assign(e, x), {});
57
+ }
58
+ getSignature() {
59
+ return this.signature;
60
+ }
61
+ getDescription() {
62
+ return this.description;
63
+ }
64
+ option(key, def) {
65
+ return this.input.options[key] ?? def;
66
+ }
67
+ options(key) {
68
+ if (key) {
69
+ return this.input.options[key];
70
+ }
71
+ return this.input.options;
72
+ }
73
+ argument(key, def) {
74
+ return this.input.arguments[key] ?? def;
75
+ }
76
+ arguments() {
77
+ return this.input.arguments;
78
+ }
79
+ };
80
+
81
+ export {
82
+ Command
83
+ };
@@ -0,0 +1,151 @@
1
+ import {
2
+ TableGuesser,
3
+ Utils
4
+ } from "./chunk-POF4JGTX.js";
5
+ import {
6
+ Command
7
+ } from "./chunk-O45AB4MX.js";
8
+ import {
9
+ __name
10
+ } from "./chunk-SHUYVCID.js";
11
+
12
+ // src/Commands/MakeCommand.ts
13
+ import { readFile, writeFile } from "fs/promises";
14
+ import chalk from "chalk";
15
+ import dayjs from "dayjs";
16
+ import { existsSync } from "fs";
17
+ import nodepath from "path";
18
+ var MakeCommand = class extends Command {
19
+ static {
20
+ __name(this, "MakeCommand");
21
+ }
22
+ /**
23
+ * The name and signature of the console command.
24
+ *
25
+ * @var string
26
+ */
27
+ signature = `#make:
28
+ {controller : Generates a new controller class. | {--a|api : Generate an API resource controller} | {--force : Overide existing controller.} }
29
+ {resource : Generates a new API resource class.}
30
+ {migration : Generates a new database migration class. | {--l|type=ts : The file type to generate} | {--t|table : The table to migrate} | {--c|create : The table to be created} }
31
+ {factory : Generates a new database factory class.}
32
+ {seeder : Generates a new database seeder class.}
33
+ {model : Generates a new Arquebus model class. | {--t|type=ts : The file type to generate}}
34
+ {^name : The name of the [name] to generate}
35
+ `;
36
+ /**
37
+ * The console command description.
38
+ *
39
+ * @var string
40
+ */
41
+ description = "Generate component classes";
42
+ async handle() {
43
+ const command = this.dictionary.baseCommand;
44
+ const methods = {
45
+ controller: "makeController",
46
+ resource: "makeResource",
47
+ migration: "makeMigration",
48
+ factory: "makeFactory",
49
+ seeder: "makeSeeder",
50
+ model: "makeModel"
51
+ };
52
+ try {
53
+ await this?.[methods[command]]();
54
+ } catch (e) {
55
+ this.kernel.output.error(e);
56
+ }
57
+ }
58
+ /**
59
+ * Generate a new controller class.
60
+ */
61
+ async makeController() {
62
+ const type = this.option("api") ? "-resource" : "";
63
+ const name = this.argument("name");
64
+ const force = this.option("force");
65
+ const path = nodepath.join(app_path("Http/Controllers"), name + ".ts");
66
+ const dbPath = Utils.findModulePkg("@h3ravel/http", this.kernel.cwd) ?? "";
67
+ const stubPath = nodepath.join(dbPath, `dist/stubs/controller${type}.stub`);
68
+ if (!force && existsSync(path)) {
69
+ this.kernel.output.error(`ERORR: ${name} controller already exists`);
70
+ }
71
+ let stub = await readFile(stubPath, "utf-8");
72
+ stub = stub.replace(/{{ name }}/g, name);
73
+ await writeFile(path, stub);
74
+ this.kernel.output.split(`INFO: Controller Created`, chalk.gray(nodepath.basename(path)));
75
+ }
76
+ makeResource() {
77
+ this.kernel.output.success(`Resource support is not yet available`);
78
+ }
79
+ /**
80
+ * Generate a new database migration class
81
+ */
82
+ async makeMigration() {
83
+ const name = this.argument("name");
84
+ const datePrefix = dayjs().format("YYYY_MM_DD_HHmmss");
85
+ const path = nodepath.join(database_path("migrations"), `${datePrefix}_${name}.ts`);
86
+ const dbPath = Utils.findModulePkg("@h3ravel/database", this.kernel.cwd) ?? "";
87
+ let create = this.option("create", false);
88
+ let table = this.option("table");
89
+ if (!table && typeof create === "string") {
90
+ table = create;
91
+ create = true;
92
+ }
93
+ if (!table) {
94
+ const guessed = TableGuesser.guess(name);
95
+ table = guessed[0];
96
+ create = !!guessed[1];
97
+ }
98
+ const stubPath = nodepath.join(dbPath, this.getMigrationStubName(table, create));
99
+ let stub = await readFile(stubPath, "utf-8");
100
+ if (table !== null) {
101
+ stub = stub.replace(/DummyTable|{{\s*table\s*}}/g, table);
102
+ }
103
+ this.kernel.output.info("INFO: Creating Migration");
104
+ await this.kernel.ensureDirectoryExists(nodepath.dirname(path));
105
+ await writeFile(path, stub);
106
+ this.kernel.output.split(`INFO: Migration Created`, chalk.gray(nodepath.basename(path)));
107
+ }
108
+ makeFactory() {
109
+ this.kernel.output.success(`Factory support is not yet available`);
110
+ }
111
+ makeSeeder() {
112
+ this.kernel.output.success(`Seeder support is not yet available`);
113
+ }
114
+ /**
115
+ * Generate a new Arquebus model class
116
+ */
117
+ async makeModel() {
118
+ const type = this.option("type", "ts");
119
+ const name = this.argument("name");
120
+ const path = nodepath.join(app_path("Models"), name.toLowerCase() + "." + type);
121
+ const dbPath = Utils.findModulePkg("@h3ravel/database", this.kernel.cwd) ?? "";
122
+ const stubPath = nodepath.join(dbPath, `dist/stubs/model-${type}.stub`);
123
+ let stub = await readFile(stubPath, "utf-8");
124
+ stub = stub.replace(/{{ name }}/g, name);
125
+ await writeFile(path, stub);
126
+ this.kernel.output.split(`INFO: Model Created`, chalk.gray(nodepath.basename(path)));
127
+ }
128
+ /**
129
+ * Ge the database migration file name
130
+ *
131
+ * @param table
132
+ * @param create
133
+ * @param type
134
+ * @returns
135
+ */
136
+ getMigrationStubName(table, create = false, type = "ts") {
137
+ let stub;
138
+ if (!table) {
139
+ stub = `migration-${type}.stub`;
140
+ } else if (create) {
141
+ stub = `migration.create-${type}.stub`;
142
+ } else {
143
+ stub = `migration.update-${type}.stub`;
144
+ }
145
+ return "dist/stubs/" + stub;
146
+ }
147
+ };
148
+
149
+ export {
150
+ MakeCommand
151
+ };
@@ -0,0 +1,186 @@
1
+ import {
2
+ __name
3
+ } from "./chunk-SHUYVCID.js";
4
+
5
+ // src/Utils.ts
6
+ import { access } from "fs/promises";
7
+ import chalk from "chalk";
8
+
9
+ // ../../node_modules/.pnpm/escalade@3.2.0/node_modules/escalade/sync/index.mjs
10
+ import { dirname, resolve } from "path";
11
+ import { readdirSync, statSync } from "fs";
12
+ function sync_default(start, callback) {
13
+ let dir = resolve(".", start);
14
+ let tmp, stats = statSync(dir);
15
+ if (!stats.isDirectory()) {
16
+ dir = dirname(dir);
17
+ }
18
+ while (true) {
19
+ tmp = callback(dir, readdirSync(dir));
20
+ if (tmp) return resolve(dir, tmp);
21
+ dir = dirname(tmp = dir);
22
+ if (tmp === dir) break;
23
+ }
24
+ }
25
+ __name(sync_default, "default");
26
+
27
+ // src/Utils.ts
28
+ import path from "path";
29
+ var join = path.join;
30
+ var Utils = class {
31
+ static {
32
+ __name(this, "Utils");
33
+ }
34
+ /**
35
+ * Wraps text with chalk
36
+ *
37
+ * @param txt
38
+ * @param color
39
+ * @returns
40
+ */
41
+ static textFormat(txt, color) {
42
+ return String(txt).split(":").map((e, i, a) => i == 0 && a.length > 1 ? color(" " + e + ": ") : e).join("");
43
+ }
44
+ /**
45
+ * Ouput formater object
46
+ *
47
+ * @returns
48
+ */
49
+ static output() {
50
+ return {
51
+ success: /* @__PURE__ */ __name((msg, exit = false) => {
52
+ console.log(chalk.green("\u2713"), this.textFormat(msg, chalk.bgGreen), "\n");
53
+ if (exit) process.exit(0);
54
+ }, "success"),
55
+ info: /* @__PURE__ */ __name((msg, exit = false) => {
56
+ console.log(chalk.blue("\u2139"), this.textFormat(msg, chalk.bgBlue), "\n");
57
+ if (exit) process.exit(0);
58
+ }, "info"),
59
+ error: /* @__PURE__ */ __name((msg, exit = true) => {
60
+ if (msg instanceof Error) {
61
+ if (msg.message) {
62
+ console.error(chalk.red("\u2716"), this.textFormat("ERROR:" + msg.message, chalk.bgRed));
63
+ }
64
+ console.error(chalk.red(`${msg.detail ? `${msg.detail}
65
+ ` : ""}${msg.stack}`), "\n");
66
+ } else {
67
+ console.error(chalk.red("\u2716"), this.textFormat(msg, chalk.bgRed), "\n");
68
+ }
69
+ if (exit) process.exit(1);
70
+ }, "error"),
71
+ split: /* @__PURE__ */ __name((name, value, status, exit = false) => {
72
+ status ??= "info";
73
+ const color = {
74
+ success: chalk.bgGreen,
75
+ info: chalk.bgBlue,
76
+ error: chalk.bgRed
77
+ };
78
+ const regex = /\x1b\[\d+m/g;
79
+ const width = Math.min(process.stdout.columns, 100);
80
+ const dots = Math.max(width - name.replace(regex, "").length - value.replace(regex, "").length - 10, 0);
81
+ console.log(this.textFormat(name, color[status]), chalk.gray(".".repeat(dots)), value);
82
+ if (exit) process.exit(0);
83
+ }, "split"),
84
+ quiet: /* @__PURE__ */ __name(() => {
85
+ process.exit(0);
86
+ }, "quiet")
87
+ };
88
+ }
89
+ static findModulePkg(moduleId, cwd) {
90
+ const parts = moduleId.replace(/\\/g, "/").split("/");
91
+ let packageName = "";
92
+ if (parts.length > 0 && parts[0][0] === "@") {
93
+ packageName += parts.shift() + "/";
94
+ }
95
+ packageName += parts.shift();
96
+ const packageJson = path.join(cwd ?? process.cwd(), "node_modules", packageName);
97
+ const resolved = this.findUpConfig(packageJson, "package", [
98
+ "json"
99
+ ]);
100
+ if (!resolved) {
101
+ return;
102
+ }
103
+ return path.join(path.dirname(resolved), parts.join("/"));
104
+ }
105
+ static async getMigrationPaths(cwd, migrator, defaultPath, path2) {
106
+ if (path2) {
107
+ return [
108
+ join(cwd, path2)
109
+ ];
110
+ }
111
+ return [
112
+ ...migrator.getPaths(),
113
+ join(cwd, defaultPath)
114
+ ];
115
+ }
116
+ static twoColumnDetail(name, value) {
117
+ const regex = /\x1b\[\d+m/g;
118
+ const width = Math.min(process.stdout.columns, 100);
119
+ const dots = Math.max(width - name.replace(regex, "").length - value.replace(regex, "").length - 10, 0);
120
+ return console.log(name, chalk.gray(".".repeat(dots)), value);
121
+ }
122
+ /**
123
+ * Check if file exists
124
+ *
125
+ * @param path
126
+ * @returns
127
+ */
128
+ static async fileExists(path2) {
129
+ try {
130
+ await access(path2);
131
+ return true;
132
+ } catch {
133
+ return false;
134
+ }
135
+ }
136
+ static findUpConfig(cwd, name, extensions) {
137
+ return sync_default(cwd, (_dir, names) => {
138
+ for (const ext of extensions) {
139
+ const filename = `${name}.${ext}`;
140
+ if (names.includes(filename)) {
141
+ return filename;
142
+ }
143
+ }
144
+ return false;
145
+ });
146
+ }
147
+ };
148
+ var TableGuesser = class TableGuesser2 {
149
+ static {
150
+ __name(this, "TableGuesser");
151
+ }
152
+ static CREATE_PATTERNS = [
153
+ /^create_(\w+)_table$/,
154
+ /^create_(\w+)$/
155
+ ];
156
+ static CHANGE_PATTERNS = [
157
+ /.+_(to|from|in)_(\w+)_table$/,
158
+ /.+_(to|from|in)_(\w+)$/
159
+ ];
160
+ static guess(migration) {
161
+ for (const pattern of TableGuesser2.CREATE_PATTERNS) {
162
+ const matches = migration.match(pattern);
163
+ if (matches) {
164
+ return [
165
+ matches[1],
166
+ true
167
+ ];
168
+ }
169
+ }
170
+ for (const pattern of TableGuesser2.CHANGE_PATTERNS) {
171
+ const matches = migration.match(pattern);
172
+ if (matches) {
173
+ return [
174
+ matches[2],
175
+ false
176
+ ];
177
+ }
178
+ }
179
+ return [];
180
+ }
181
+ };
182
+
183
+ export {
184
+ Utils,
185
+ TableGuesser
186
+ };
@@ -0,0 +1,6 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ export {
5
+ __name
6
+ };
@@ -0,0 +1,63 @@
1
+ import {
2
+ Command
3
+ } from "./chunk-O45AB4MX.js";
4
+ import {
5
+ __name
6
+ } from "./chunk-SHUYVCID.js";
7
+
8
+ // src/Commands/ServeCommand.ts
9
+ import { spawn } from "child_process";
10
+ var ServeCommand = class extends Command {
11
+ static {
12
+ __name(this, "ServeCommand");
13
+ }
14
+ /**
15
+ * The name and signature of the console command.
16
+ *
17
+ * @var string
18
+ */
19
+ signature = "serve";
20
+ /**
21
+ * The console command description.
22
+ *
23
+ * @var string
24
+ */
25
+ description = "Start the Developement Server";
26
+ async handle() {
27
+ try {
28
+ await this.serve();
29
+ } catch (e) {
30
+ this.kernel.output.error(e);
31
+ }
32
+ }
33
+ async serve() {
34
+ const child = spawn("tsup-node", {
35
+ stdio: "inherit",
36
+ shell: true,
37
+ env: Object.assign({}, process.env, {
38
+ NODE_ENV: "development"
39
+ }),
40
+ detached: true
41
+ });
42
+ const cleanup = /* @__PURE__ */ __name(() => {
43
+ console.log(111);
44
+ if (child.pid) {
45
+ process.kill(child.pid, "SIGTERM");
46
+ }
47
+ }, "cleanup");
48
+ process.on("SIGINT", () => child.kill("SIGINT"));
49
+ process.on("SIGTERM", () => child.kill("SIGTERM"));
50
+ process.on("SIGINT", () => {
51
+ cleanup();
52
+ process.exit(0);
53
+ });
54
+ process.on("SIGTERM", () => {
55
+ cleanup();
56
+ process.exit(0);
57
+ });
58
+ }
59
+ };
60
+
61
+ export {
62
+ ServeCommand
63
+ };
@@ -0,0 +1,133 @@
1
+ import {
2
+ MigrateCommand
3
+ } from "./chunk-FOSDCKCR.js";
4
+ import {
5
+ ServeCommand
6
+ } from "./chunk-SP4JKAUC.js";
7
+ import {
8
+ Signature
9
+ } from "./chunk-3FVPHQCH.js";
10
+ import {
11
+ MakeCommand
12
+ } from "./chunk-PMV4TMFS.js";
13
+ import {
14
+ Utils
15
+ } from "./chunk-POF4JGTX.js";
16
+ import {
17
+ __name
18
+ } from "./chunk-SHUYVCID.js";
19
+
20
+ // src/Musket.ts
21
+ import chalk from "chalk";
22
+ import { program } from "commander";
23
+ var Musket = class _Musket {
24
+ static {
25
+ __name(this, "Musket");
26
+ }
27
+ app;
28
+ kernel;
29
+ output = Utils.output();
30
+ commands = [];
31
+ constructor(app, kernel) {
32
+ this.app = app;
33
+ this.kernel = kernel;
34
+ }
35
+ async build() {
36
+ this.loadBaseCommands();
37
+ await this.loadDiscoveredCommands();
38
+ return this.initialize();
39
+ }
40
+ loadBaseCommands() {
41
+ const commands = [
42
+ new ServeCommand(this.app, this.kernel),
43
+ new MakeCommand(this.app, this.kernel),
44
+ new MigrateCommand(this.app, this.kernel)
45
+ ];
46
+ commands.forEach((e) => this.addCommand(e));
47
+ }
48
+ async loadDiscoveredCommands() {
49
+ const commands = [];
50
+ commands.forEach((e) => this.addCommand(e));
51
+ }
52
+ addCommand(command) {
53
+ this.commands.push(Signature.parseSignature(command.getSignature(), command));
54
+ }
55
+ initialize() {
56
+ const cliVersion = [
57
+ "H3ravel Version:",
58
+ chalk.green(this.kernel.consolePackage.version)
59
+ ].join(" ");
60
+ const localVersion = [
61
+ "Musket Version:",
62
+ chalk.green(this.kernel.modulePackage.version || "None")
63
+ ].join(" ");
64
+ program.name("musket").version(`${cliVersion}
65
+ ${localVersion}`);
66
+ program.command("init").description("Initialize H3ravel.").action(async () => {
67
+ this.output.success(`Initialized: H3ravel has been initialized!`);
68
+ });
69
+ for (let i = 0; i < this.commands.length; i++) {
70
+ const command = this.commands[i];
71
+ const instance = command.commandClass;
72
+ if (command.isNamespaceCommand && command.subCommands) {
73
+ const cmd = command.isHidden ? program : program.command(command.baseCommand).description(command.description ?? "").action(async () => {
74
+ instance.setInput(cmd.opts(), cmd.args, cmd.registeredArguments, command);
75
+ await instance.handle();
76
+ });
77
+ if ((command.options?.length ?? 0) > 0) {
78
+ command.options?.filter((v, i2, a) => a.findIndex((t) => t.name === v.name) === i2).forEach((opt) => {
79
+ this.makeOption(opt, cmd);
80
+ });
81
+ }
82
+ command.subCommands.filter((v, i2, a) => !v.shared && a.findIndex((t) => t.name === v.name) === i2).forEach((sub) => {
83
+ const cmd2 = program.command(`${command.baseCommand}:${sub.name}`).description(sub.description || "").action(async () => {
84
+ instance.setInput(cmd2.opts(), cmd2.args, cmd2.registeredArguments, sub);
85
+ await instance.handle();
86
+ });
87
+ command.subCommands?.filter((e) => e.shared).forEach((opt) => {
88
+ this.makeOption(opt, cmd2, false, sub);
89
+ });
90
+ command.options?.filter((e) => e.shared).forEach((opt) => {
91
+ this.makeOption(opt, cmd2, false, sub);
92
+ });
93
+ if (sub.nestedOptions) {
94
+ sub.nestedOptions.filter((v, i2, a) => a.findIndex((t) => t.name === v.name) === i2).forEach((opt) => {
95
+ this.makeOption(opt, cmd2);
96
+ });
97
+ }
98
+ });
99
+ } else {
100
+ const cmd = program.command(command.baseCommand).description(command.description ?? "");
101
+ command?.options?.filter((v, i2, a) => a.findIndex((t) => t.name === v.name) === i2).forEach((opt) => {
102
+ this.makeOption(opt, cmd, true);
103
+ });
104
+ cmd.action(async () => {
105
+ instance.setInput(cmd.opts(), cmd.args, cmd.registeredArguments, command);
106
+ await instance.handle();
107
+ });
108
+ }
109
+ }
110
+ return program;
111
+ }
112
+ makeOption(opt, cmd, parse, parent) {
113
+ const description = opt.description?.replace(/\[(\w+)\]/g, (_, k) => parent?.[k] ?? `[${k}]`) ?? "";
114
+ const type = opt.name.replaceAll("-", "");
115
+ if (opt.isFlag) {
116
+ if (parse) {
117
+ const flags = opt.flags?.map((f) => f.length === 1 ? `-${f}` : `--${f}`).join(", ");
118
+ cmd.option(flags || "", description, String(opt.defaultValue) || void 0);
119
+ } else {
120
+ cmd.option(opt.flags?.join(", ") + (opt.required ? ` <${type}>` : ""), description, opt.defaultValue);
121
+ }
122
+ } else {
123
+ cmd.argument(opt.required ? `<${opt.name}>` : `[${opt.name}]`, description, opt.defaultValue);
124
+ }
125
+ }
126
+ static async parse(kernel) {
127
+ return (await new _Musket(kernel.app, kernel).build()).parseAsync();
128
+ }
129
+ };
130
+
131
+ export {
132
+ Musket
133
+ };
File without changes