@maizzle/framework 6.0.0-rc.1 → 6.0.0-rc.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.
Files changed (207) hide show
  1. package/bin/maizzle.mjs +1 -1
  2. package/dist/build.mjs +2 -1
  3. package/dist/build.mjs.map +1 -1
  4. package/dist/config/index.mjs +7 -0
  5. package/dist/config/index.mjs.map +1 -1
  6. package/dist/render/createRenderer.d.mts +2 -0
  7. package/dist/render/createRenderer.d.mts.map +1 -1
  8. package/dist/render/createRenderer.mjs +7 -2
  9. package/dist/render/createRenderer.mjs.map +1 -1
  10. package/dist/render/index.mjs +2 -1
  11. package/dist/render/index.mjs.map +1 -1
  12. package/dist/serve.mjs +2 -1
  13. package/dist/serve.mjs.map +1 -1
  14. package/dist/types/config.d.mts +3 -0
  15. package/dist/types/config.d.mts.map +1 -1
  16. package/node_modules/@clack/core/CHANGELOG.md +87 -4
  17. package/node_modules/@clack/core/README.md +1 -1
  18. package/node_modules/@clack/core/dist/index.d.mts +186 -48
  19. package/node_modules/@clack/core/dist/index.mjs +10 -14
  20. package/node_modules/@clack/core/dist/index.mjs.map +1 -1
  21. package/node_modules/@clack/core/package.json +7 -9
  22. package/node_modules/@clack/prompts/CHANGELOG.md +171 -7
  23. package/node_modules/@clack/prompts/README.md +66 -3
  24. package/node_modules/@clack/prompts/dist/index.d.mts +302 -76
  25. package/node_modules/@clack/prompts/dist/index.mjs +134 -84
  26. package/node_modules/@clack/prompts/dist/index.mjs.map +1 -1
  27. package/node_modules/@clack/prompts/package.json +14 -10
  28. package/node_modules/citty/LICENSE +0 -15
  29. package/node_modules/citty/README.md +166 -69
  30. package/node_modules/citty/dist/index.d.mts +88 -56
  31. package/node_modules/citty/dist/index.mjs +399 -437
  32. package/node_modules/citty/package.json +28 -35
  33. package/node_modules/giget/README.md +59 -11
  34. package/node_modules/giget/dist/THIRD-PARTY-LICENSES.md +205 -0
  35. package/node_modules/giget/dist/_chunks/giget.mjs +508 -0
  36. package/node_modules/giget/dist/_chunks/libs/citty.mjs +269 -0
  37. package/node_modules/giget/dist/_chunks/libs/nypm.d.mts +1 -0
  38. package/node_modules/giget/dist/_chunks/libs/nypm.mjs +669 -0
  39. package/node_modules/giget/dist/_chunks/libs/tar.mjs +2931 -0
  40. package/node_modules/giget/dist/_chunks/rolldown-runtime.mjs +14 -0
  41. package/node_modules/giget/dist/cli.d.mts +1 -0
  42. package/node_modules/giget/dist/cli.mjs +89 -111
  43. package/node_modules/giget/dist/index.d.mts +46 -35
  44. package/node_modules/giget/dist/index.mjs +2 -22
  45. package/node_modules/giget/package.json +32 -45
  46. package/node_modules/maizzle/README.md +140 -0
  47. package/node_modules/maizzle/bin/maizzle.mjs +5 -0
  48. package/node_modules/maizzle/dist/commands/new.d.mts +7 -0
  49. package/node_modules/maizzle/dist/commands/new.mjs +278 -0
  50. package/node_modules/{@maizzle/cli → maizzle}/dist/index.d.mts +1 -1
  51. package/node_modules/maizzle/dist/index.mjs +44 -0
  52. package/node_modules/{commander → maizzle/node_modules/commander}/Readme.md +94 -67
  53. package/node_modules/{commander → maizzle/node_modules/commander}/lib/argument.js +5 -4
  54. package/node_modules/{commander → maizzle/node_modules/commander}/lib/command.js +154 -39
  55. package/node_modules/{commander → maizzle/node_modules/commander}/lib/help.js +77 -39
  56. package/node_modules/{commander → maizzle/node_modules/commander}/lib/option.js +16 -3
  57. package/node_modules/{commander → maizzle/node_modules/commander}/package-support.json +4 -1
  58. package/node_modules/{commander → maizzle/node_modules/commander}/package.json +8 -8
  59. package/node_modules/{commander → maizzle/node_modules/commander}/typings/index.d.ts +71 -3
  60. package/node_modules/{@maizzle/cli → maizzle}/package.json +13 -11
  61. package/node_modules/tinyexec/README.md +49 -3
  62. package/node_modules/tinyexec/dist/main.d.mts +25 -14
  63. package/node_modules/tinyexec/dist/main.mjs +148 -100
  64. package/node_modules/tinyexec/package.json +9 -8
  65. package/package.json +3 -3
  66. package/node_modules/@clack/core/dist/index.cjs +0 -15
  67. package/node_modules/@clack/core/dist/index.cjs.map +0 -1
  68. package/node_modules/@clack/core/dist/index.d.cts +0 -211
  69. package/node_modules/@clack/core/dist/index.d.ts +0 -211
  70. package/node_modules/@clack/prompts/dist/index.cjs +0 -87
  71. package/node_modules/@clack/prompts/dist/index.cjs.map +0 -1
  72. package/node_modules/@clack/prompts/dist/index.d.cts +0 -165
  73. package/node_modules/@clack/prompts/dist/index.d.ts +0 -165
  74. package/node_modules/@maizzle/cli/README.md +0 -58
  75. package/node_modules/@maizzle/cli/dist/index.mjs +0 -42
  76. package/node_modules/citty/dist/index.cjs +0 -475
  77. package/node_modules/citty/dist/index.d.cts +0 -80
  78. package/node_modules/citty/dist/index.d.ts +0 -80
  79. package/node_modules/consola/LICENSE +0 -47
  80. package/node_modules/consola/README.md +0 -352
  81. package/node_modules/consola/basic.d.ts +0 -1
  82. package/node_modules/consola/browser.d.ts +0 -1
  83. package/node_modules/consola/core.d.ts +0 -1
  84. package/node_modules/consola/dist/basic.cjs +0 -32
  85. package/node_modules/consola/dist/basic.d.cts +0 -23
  86. package/node_modules/consola/dist/basic.d.mts +0 -21
  87. package/node_modules/consola/dist/basic.d.ts +0 -23
  88. package/node_modules/consola/dist/basic.mjs +0 -24
  89. package/node_modules/consola/dist/browser.cjs +0 -84
  90. package/node_modules/consola/dist/browser.d.cts +0 -23
  91. package/node_modules/consola/dist/browser.d.mts +0 -21
  92. package/node_modules/consola/dist/browser.d.ts +0 -23
  93. package/node_modules/consola/dist/browser.mjs +0 -76
  94. package/node_modules/consola/dist/chunks/prompt.cjs +0 -288
  95. package/node_modules/consola/dist/chunks/prompt.mjs +0 -280
  96. package/node_modules/consola/dist/core.cjs +0 -517
  97. package/node_modules/consola/dist/core.d.cts +0 -459
  98. package/node_modules/consola/dist/core.d.mts +0 -459
  99. package/node_modules/consola/dist/core.d.ts +0 -459
  100. package/node_modules/consola/dist/core.mjs +0 -512
  101. package/node_modules/consola/dist/index.cjs +0 -663
  102. package/node_modules/consola/dist/index.d.cts +0 -24
  103. package/node_modules/consola/dist/index.d.mts +0 -22
  104. package/node_modules/consola/dist/index.d.ts +0 -24
  105. package/node_modules/consola/dist/index.mjs +0 -651
  106. package/node_modules/consola/dist/shared/consola.DCGIlDNP.cjs +0 -75
  107. package/node_modules/consola/dist/shared/consola.DRwqZj3T.mjs +0 -72
  108. package/node_modules/consola/dist/shared/consola.DXBYu-KD.mjs +0 -288
  109. package/node_modules/consola/dist/shared/consola.DwRq1yyg.cjs +0 -312
  110. package/node_modules/consola/dist/utils.cjs +0 -64
  111. package/node_modules/consola/dist/utils.d.cts +0 -286
  112. package/node_modules/consola/dist/utils.d.mts +0 -286
  113. package/node_modules/consola/dist/utils.d.ts +0 -286
  114. package/node_modules/consola/dist/utils.mjs +0 -54
  115. package/node_modules/consola/lib/index.cjs +0 -10
  116. package/node_modules/consola/package.json +0 -136
  117. package/node_modules/consola/utils.d.ts +0 -1
  118. package/node_modules/create-maizzle/README.md +0 -86
  119. package/node_modules/create-maizzle/bin/create-maizzle.mjs +0 -4
  120. package/node_modules/create-maizzle/node_modules/@clack/core/CHANGELOG.md +0 -340
  121. package/node_modules/create-maizzle/node_modules/@clack/core/LICENSE +0 -9
  122. package/node_modules/create-maizzle/node_modules/@clack/core/README.md +0 -22
  123. package/node_modules/create-maizzle/node_modules/@clack/core/dist/index.d.mts +0 -349
  124. package/node_modules/create-maizzle/node_modules/@clack/core/dist/index.mjs +0 -11
  125. package/node_modules/create-maizzle/node_modules/@clack/core/dist/index.mjs.map +0 -1
  126. package/node_modules/create-maizzle/node_modules/@clack/core/package.json +0 -60
  127. package/node_modules/create-maizzle/node_modules/@clack/prompts/CHANGELOG.md +0 -576
  128. package/node_modules/create-maizzle/node_modules/@clack/prompts/LICENSE +0 -9
  129. package/node_modules/create-maizzle/node_modules/@clack/prompts/README.md +0 -270
  130. package/node_modules/create-maizzle/node_modules/@clack/prompts/dist/index.d.mts +0 -391
  131. package/node_modules/create-maizzle/node_modules/@clack/prompts/dist/index.mjs +0 -137
  132. package/node_modules/create-maizzle/node_modules/@clack/prompts/dist/index.mjs.map +0 -1
  133. package/node_modules/create-maizzle/node_modules/@clack/prompts/package.json +0 -65
  134. package/node_modules/create-maizzle/package.json +0 -47
  135. package/node_modules/create-maizzle/src/index.js +0 -242
  136. package/node_modules/defu/LICENSE +0 -21
  137. package/node_modules/defu/README.md +0 -171
  138. package/node_modules/defu/dist/defu.cjs +0 -77
  139. package/node_modules/defu/dist/defu.d.cts +0 -31
  140. package/node_modules/defu/dist/defu.d.mts +0 -29
  141. package/node_modules/defu/dist/defu.d.ts +0 -31
  142. package/node_modules/defu/dist/defu.mjs +0 -69
  143. package/node_modules/defu/lib/defu.cjs +0 -10
  144. package/node_modules/defu/lib/defu.d.cts +0 -12
  145. package/node_modules/defu/package.json +0 -48
  146. package/node_modules/giget/dist/shared/giget.OCaTp9b-.mjs +0 -468
  147. package/node_modules/node-fetch-native/LICENSE +0 -114
  148. package/node_modules/node-fetch-native/README.md +0 -225
  149. package/node_modules/node-fetch-native/dist/chunks/multipart-parser.cjs +0 -2
  150. package/node_modules/node-fetch-native/dist/chunks/multipart-parser.mjs +0 -2
  151. package/node_modules/node-fetch-native/dist/index.cjs +0 -1
  152. package/node_modules/node-fetch-native/dist/index.mjs +0 -1
  153. package/node_modules/node-fetch-native/dist/native.cjs +0 -1
  154. package/node_modules/node-fetch-native/dist/native.mjs +0 -1
  155. package/node_modules/node-fetch-native/dist/node.cjs +0 -19
  156. package/node_modules/node-fetch-native/dist/node.mjs +0 -19
  157. package/node_modules/node-fetch-native/dist/polyfill.cjs +0 -1
  158. package/node_modules/node-fetch-native/dist/polyfill.mjs +0 -1
  159. package/node_modules/node-fetch-native/dist/proxy-stub.cjs +0 -1
  160. package/node_modules/node-fetch-native/dist/proxy-stub.mjs +0 -1
  161. package/node_modules/node-fetch-native/dist/proxy.cjs +0 -58
  162. package/node_modules/node-fetch-native/dist/shared/node-fetch-native.DfbY2q-x.mjs +0 -1
  163. package/node_modules/node-fetch-native/dist/shared/node-fetch-native.DhEqb06g.cjs +0 -1
  164. package/node_modules/node-fetch-native/index.d.ts +0 -1
  165. package/node_modules/node-fetch-native/lib/empty.cjs +0 -0
  166. package/node_modules/node-fetch-native/lib/empty.mjs +0 -0
  167. package/node_modules/node-fetch-native/lib/index.cjs +0 -11
  168. package/node_modules/node-fetch-native/lib/index.d.cts +0 -10
  169. package/node_modules/node-fetch-native/lib/index.d.mts +0 -10
  170. package/node_modules/node-fetch-native/lib/index.d.ts +0 -10
  171. package/node_modules/node-fetch-native/lib/native.cjs +0 -11
  172. package/node_modules/node-fetch-native/lib/polyfill.d.cts +0 -1
  173. package/node_modules/node-fetch-native/lib/polyfill.d.mts +0 -1
  174. package/node_modules/node-fetch-native/lib/polyfill.d.ts +0 -1
  175. package/node_modules/node-fetch-native/lib/proxy.d.ts +0 -32
  176. package/node_modules/node-fetch-native/node.d.ts +0 -1
  177. package/node_modules/node-fetch-native/package.json +0 -138
  178. package/node_modules/node-fetch-native/polyfill.d.ts +0 -1
  179. package/node_modules/node-fetch-native/proxy.d.ts +0 -1
  180. package/node_modules/nypm/node_modules/citty/LICENSE +0 -21
  181. package/node_modules/nypm/node_modules/citty/README.md +0 -231
  182. package/node_modules/nypm/node_modules/citty/dist/index.d.mts +0 -112
  183. package/node_modules/nypm/node_modules/citty/dist/index.mjs +0 -425
  184. package/node_modules/nypm/node_modules/citty/package.json +0 -42
  185. /package/node_modules/{nypm/node_modules/citty → citty}/dist/THIRD-PARTY-LICENSES.md +0 -0
  186. /package/node_modules/{nypm/node_modules/citty → citty}/dist/_chunks/libs/scule.mjs +0 -0
  187. /package/node_modules/{@maizzle/cli → maizzle}/LICENSE +0 -0
  188. /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/component.d.mts +0 -0
  189. /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/component.mjs +0 -0
  190. /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/config.d.mts +0 -0
  191. /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/config.mjs +0 -0
  192. /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/layout.d.mts +0 -0
  193. /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/layout.mjs +0 -0
  194. /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/scaffold.d.mts +0 -0
  195. /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/scaffold.mjs +0 -0
  196. /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/stubs/component.vue +0 -0
  197. /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/stubs/config.ts +0 -0
  198. /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/stubs/layout.vue +0 -0
  199. /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/stubs/template.vue +0 -0
  200. /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/template.d.mts +0 -0
  201. /package/node_modules/{@maizzle/cli → maizzle}/dist/commands/make/template.mjs +0 -0
  202. /package/node_modules/{commander → maizzle/node_modules/commander}/LICENSE +0 -0
  203. /package/node_modules/{commander → maizzle/node_modules/commander}/esm.mjs +0 -0
  204. /package/node_modules/{commander → maizzle/node_modules/commander}/index.js +0 -0
  205. /package/node_modules/{commander → maizzle/node_modules/commander}/lib/error.js +0 -0
  206. /package/node_modules/{commander → maizzle/node_modules/commander}/lib/suggestSimilar.js +0 -0
  207. /package/node_modules/{commander → maizzle/node_modules/commander}/typings/esm.d.mts +0 -0
@@ -1,42 +0,0 @@
1
- import makeConfig from "./commands/make/config.mjs";
2
- import makeLayout from "./commands/make/layout.mjs";
3
- import makeTemplate from "./commands/make/template.mjs";
4
- import makeComponent from "./commands/make/component.mjs";
5
- import { Command } from "commander";
6
- import { main } from "create-maizzle";
7
- //#region src/index.ts
8
- async function bootstrap(framework) {
9
- const program = new Command();
10
- program.name("maizzle").description("Maizzle CLI").version("3.0.0");
11
- program.command("serve").description("Start the Maizzle dev server with HMR").option("-c, --config <path>", "Path to maizzle config file").option("-p, --port <number>", "Dev server port").option("--host [address]", "Expose on network").action(async (options) => {
12
- await framework.serve({
13
- config: options.config,
14
- port: options.port ? parseInt(options.port, 10) : void 0,
15
- host: options.host
16
- });
17
- });
18
- program.command("build").description("Build email templates to HTML").option("-c, --config <path>", "Path to maizzle config file").option("-o, --output <path>", "Output directory").action(async (options) => {
19
- await framework.build({
20
- config: options.config,
21
- output: options.output
22
- });
23
- });
24
- program.command("new").description("Create a new Maizzle project").action(async () => {
25
- await main();
26
- });
27
- program.command("make:config [name]").description("Create a new config file").action(async (name) => {
28
- await makeConfig(name);
29
- });
30
- program.command("make:layout [filepath]").description("Create a new layout").action(async (filepath) => {
31
- await makeLayout(filepath);
32
- });
33
- program.command("make:template [filepath]").description("Create a new template").action(async (filepath) => {
34
- await makeTemplate(filepath);
35
- });
36
- program.command("make:component [filepath]").description("Create a new component").action(async (filepath) => {
37
- await makeComponent(filepath);
38
- });
39
- await program.parseAsync(process.argv);
40
- }
41
- //#endregion
42
- export { bootstrap as default };
@@ -1,475 +0,0 @@
1
- 'use strict';
2
-
3
- const consola = require('consola');
4
- const utils = require('consola/utils');
5
-
6
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
7
-
8
- const consola__default = /*#__PURE__*/_interopDefaultCompat(consola);
9
-
10
- function toArray(val) {
11
- if (Array.isArray(val)) {
12
- return val;
13
- }
14
- return val === void 0 ? [] : [val];
15
- }
16
- function formatLineColumns(lines, linePrefix = "") {
17
- const maxLengh = [];
18
- for (const line of lines) {
19
- for (const [i, element] of line.entries()) {
20
- maxLengh[i] = Math.max(maxLengh[i] || 0, element.length);
21
- }
22
- }
23
- return lines.map(
24
- (l) => l.map(
25
- (c, i) => linePrefix + c[i === 0 ? "padStart" : "padEnd"](maxLengh[i])
26
- ).join(" ")
27
- ).join("\n");
28
- }
29
- function resolveValue(input) {
30
- return typeof input === "function" ? input() : input;
31
- }
32
- class CLIError extends Error {
33
- constructor(message, code) {
34
- super(message);
35
- this.code = code;
36
- this.name = "CLIError";
37
- }
38
- }
39
-
40
- const NUMBER_CHAR_RE = /\d/;
41
- const STR_SPLITTERS = ["-", "_", "/", "."];
42
- function isUppercase(char = "") {
43
- if (NUMBER_CHAR_RE.test(char)) {
44
- return void 0;
45
- }
46
- return char !== char.toLowerCase();
47
- }
48
- function splitByCase(str, separators) {
49
- const splitters = separators ?? STR_SPLITTERS;
50
- const parts = [];
51
- if (!str || typeof str !== "string") {
52
- return parts;
53
- }
54
- let buff = "";
55
- let previousUpper;
56
- let previousSplitter;
57
- for (const char of str) {
58
- const isSplitter = splitters.includes(char);
59
- if (isSplitter === true) {
60
- parts.push(buff);
61
- buff = "";
62
- previousUpper = void 0;
63
- continue;
64
- }
65
- const isUpper = isUppercase(char);
66
- if (previousSplitter === false) {
67
- if (previousUpper === false && isUpper === true) {
68
- parts.push(buff);
69
- buff = char;
70
- previousUpper = isUpper;
71
- continue;
72
- }
73
- if (previousUpper === true && isUpper === false && buff.length > 1) {
74
- const lastChar = buff.at(-1);
75
- parts.push(buff.slice(0, Math.max(0, buff.length - 1)));
76
- buff = lastChar + char;
77
- previousUpper = isUpper;
78
- continue;
79
- }
80
- }
81
- buff += char;
82
- previousUpper = isUpper;
83
- previousSplitter = isSplitter;
84
- }
85
- parts.push(buff);
86
- return parts;
87
- }
88
- function upperFirst(str) {
89
- return str ? str[0].toUpperCase() + str.slice(1) : "";
90
- }
91
- function lowerFirst(str) {
92
- return str ? str[0].toLowerCase() + str.slice(1) : "";
93
- }
94
- function pascalCase(str, opts) {
95
- return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => upperFirst(opts?.normalize ? p.toLowerCase() : p)).join("") : "";
96
- }
97
- function camelCase(str, opts) {
98
- return lowerFirst(pascalCase(str || "", opts));
99
- }
100
- function kebabCase(str, joiner) {
101
- return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => p.toLowerCase()).join(joiner ?? "-") : "";
102
- }
103
-
104
- function toArr(any) {
105
- return any == void 0 ? [] : Array.isArray(any) ? any : [any];
106
- }
107
- function toVal(out, key, val, opts) {
108
- let x;
109
- const old = out[key];
110
- const nxt = ~opts.string.indexOf(key) ? val == void 0 || 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;
111
- out[key] = old == void 0 ? nxt : Array.isArray(old) ? old.concat(nxt) : [old, nxt];
112
- }
113
- function parseRawArgs(args = [], opts = {}) {
114
- let k;
115
- let arr;
116
- let arg;
117
- let name;
118
- let val;
119
- const out = { _: [] };
120
- let i = 0;
121
- let j = 0;
122
- let idx = 0;
123
- const len = args.length;
124
- const alibi = opts.alias !== void 0;
125
- const strict = opts.unknown !== void 0;
126
- const defaults = opts.default !== void 0;
127
- opts.alias = opts.alias || {};
128
- opts.string = toArr(opts.string);
129
- opts.boolean = toArr(opts.boolean);
130
- if (alibi) {
131
- for (k in opts.alias) {
132
- arr = opts.alias[k] = toArr(opts.alias[k]);
133
- for (i = 0; i < arr.length; i++) {
134
- (opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
135
- }
136
- }
137
- }
138
- for (i = opts.boolean.length; i-- > 0; ) {
139
- arr = opts.alias[opts.boolean[i]] || [];
140
- for (j = arr.length; j-- > 0; ) {
141
- opts.boolean.push(arr[j]);
142
- }
143
- }
144
- for (i = opts.string.length; i-- > 0; ) {
145
- arr = opts.alias[opts.string[i]] || [];
146
- for (j = arr.length; j-- > 0; ) {
147
- opts.string.push(arr[j]);
148
- }
149
- }
150
- if (defaults) {
151
- for (k in opts.default) {
152
- name = typeof opts.default[k];
153
- arr = opts.alias[k] = opts.alias[k] || [];
154
- if (opts[name] !== void 0) {
155
- opts[name].push(k);
156
- for (i = 0; i < arr.length; i++) {
157
- opts[name].push(arr[i]);
158
- }
159
- }
160
- }
161
- }
162
- const keys = strict ? Object.keys(opts.alias) : [];
163
- for (i = 0; i < len; i++) {
164
- arg = args[i];
165
- if (arg === "--") {
166
- out._ = out._.concat(args.slice(++i));
167
- break;
168
- }
169
- for (j = 0; j < arg.length; j++) {
170
- if (arg.charCodeAt(j) !== 45) {
171
- break;
172
- }
173
- }
174
- if (j === 0) {
175
- out._.push(arg);
176
- } else if (arg.substring(j, j + 3) === "no-") {
177
- name = arg.slice(Math.max(0, j + 3));
178
- if (strict && !~keys.indexOf(name)) {
179
- return opts.unknown(arg);
180
- }
181
- out[name] = false;
182
- } else {
183
- for (idx = j + 1; idx < arg.length; idx++) {
184
- if (arg.charCodeAt(idx) === 61) {
185
- break;
186
- }
187
- }
188
- name = arg.substring(j, idx);
189
- val = arg.slice(Math.max(0, ++idx)) || i + 1 === len || ("" + args[i + 1]).charCodeAt(0) === 45 || args[++i];
190
- arr = j === 2 ? [name] : name;
191
- for (idx = 0; idx < arr.length; idx++) {
192
- name = arr[idx];
193
- if (strict && !~keys.indexOf(name)) {
194
- return opts.unknown("-".repeat(j) + name);
195
- }
196
- toVal(out, name, idx + 1 < arr.length || val, opts);
197
- }
198
- }
199
- }
200
- if (defaults) {
201
- for (k in opts.default) {
202
- if (out[k] === void 0) {
203
- out[k] = opts.default[k];
204
- }
205
- }
206
- }
207
- if (alibi) {
208
- for (k in out) {
209
- arr = opts.alias[k] || [];
210
- while (arr.length > 0) {
211
- out[arr.shift()] = out[k];
212
- }
213
- }
214
- }
215
- return out;
216
- }
217
-
218
- function parseArgs(rawArgs, argsDef) {
219
- const parseOptions = {
220
- boolean: [],
221
- string: [],
222
- mixed: [],
223
- alias: {},
224
- default: {}
225
- };
226
- const args = resolveArgs(argsDef);
227
- for (const arg of args) {
228
- if (arg.type === "positional") {
229
- continue;
230
- }
231
- if (arg.type === "string") {
232
- parseOptions.string.push(arg.name);
233
- } else if (arg.type === "boolean") {
234
- parseOptions.boolean.push(arg.name);
235
- }
236
- if (arg.default !== void 0) {
237
- parseOptions.default[arg.name] = arg.default;
238
- }
239
- if (arg.alias) {
240
- parseOptions.alias[arg.name] = arg.alias;
241
- }
242
- }
243
- const parsed = parseRawArgs(rawArgs, parseOptions);
244
- const [...positionalArguments] = parsed._;
245
- const parsedArgsProxy = new Proxy(parsed, {
246
- get(target, prop) {
247
- return target[prop] ?? target[camelCase(prop)] ?? target[kebabCase(prop)];
248
- }
249
- });
250
- for (const [, arg] of args.entries()) {
251
- if (arg.type === "positional") {
252
- const nextPositionalArgument = positionalArguments.shift();
253
- if (nextPositionalArgument !== void 0) {
254
- parsedArgsProxy[arg.name] = nextPositionalArgument;
255
- } else if (arg.default === void 0 && arg.required !== false) {
256
- throw new CLIError(
257
- `Missing required positional argument: ${arg.name.toUpperCase()}`,
258
- "EARG"
259
- );
260
- } else {
261
- parsedArgsProxy[arg.name] = arg.default;
262
- }
263
- } else if (arg.required && parsedArgsProxy[arg.name] === void 0) {
264
- throw new CLIError(`Missing required argument: --${arg.name}`, "EARG");
265
- }
266
- }
267
- return parsedArgsProxy;
268
- }
269
- function resolveArgs(argsDef) {
270
- const args = [];
271
- for (const [name, argDef] of Object.entries(argsDef || {})) {
272
- args.push({
273
- ...argDef,
274
- name,
275
- alias: toArray(argDef.alias)
276
- });
277
- }
278
- return args;
279
- }
280
-
281
- function defineCommand(def) {
282
- return def;
283
- }
284
- async function runCommand(cmd, opts) {
285
- const cmdArgs = await resolveValue(cmd.args || {});
286
- const parsedArgs = parseArgs(opts.rawArgs, cmdArgs);
287
- const context = {
288
- rawArgs: opts.rawArgs,
289
- args: parsedArgs,
290
- data: opts.data,
291
- cmd
292
- };
293
- if (typeof cmd.setup === "function") {
294
- await cmd.setup(context);
295
- }
296
- let result;
297
- try {
298
- const subCommands = await resolveValue(cmd.subCommands);
299
- if (subCommands && Object.keys(subCommands).length > 0) {
300
- const subCommandArgIndex = opts.rawArgs.findIndex(
301
- (arg) => !arg.startsWith("-")
302
- );
303
- const subCommandName = opts.rawArgs[subCommandArgIndex];
304
- if (subCommandName) {
305
- if (!subCommands[subCommandName]) {
306
- throw new CLIError(
307
- `Unknown command \`${subCommandName}\``,
308
- "E_UNKNOWN_COMMAND"
309
- );
310
- }
311
- const subCommand = await resolveValue(subCommands[subCommandName]);
312
- if (subCommand) {
313
- await runCommand(subCommand, {
314
- rawArgs: opts.rawArgs.slice(subCommandArgIndex + 1)
315
- });
316
- }
317
- } else if (!cmd.run) {
318
- throw new CLIError(`No command specified.`, "E_NO_COMMAND");
319
- }
320
- }
321
- if (typeof cmd.run === "function") {
322
- result = await cmd.run(context);
323
- }
324
- } finally {
325
- if (typeof cmd.cleanup === "function") {
326
- await cmd.cleanup(context);
327
- }
328
- }
329
- return { result };
330
- }
331
- async function resolveSubCommand(cmd, rawArgs, parent) {
332
- const subCommands = await resolveValue(cmd.subCommands);
333
- if (subCommands && Object.keys(subCommands).length > 0) {
334
- const subCommandArgIndex = rawArgs.findIndex((arg) => !arg.startsWith("-"));
335
- const subCommandName = rawArgs[subCommandArgIndex];
336
- const subCommand = await resolveValue(subCommands[subCommandName]);
337
- if (subCommand) {
338
- return resolveSubCommand(
339
- subCommand,
340
- rawArgs.slice(subCommandArgIndex + 1),
341
- cmd
342
- );
343
- }
344
- }
345
- return [cmd, parent];
346
- }
347
-
348
- async function showUsage(cmd, parent) {
349
- try {
350
- consola__default.log(await renderUsage(cmd, parent) + "\n");
351
- } catch (error) {
352
- consola__default.error(error);
353
- }
354
- }
355
- async function renderUsage(cmd, parent) {
356
- const cmdMeta = await resolveValue(cmd.meta || {});
357
- const cmdArgs = resolveArgs(await resolveValue(cmd.args || {}));
358
- const parentMeta = await resolveValue(parent?.meta || {});
359
- const commandName = `${parentMeta.name ? `${parentMeta.name} ` : ""}` + (cmdMeta.name || process.argv[1]);
360
- const argLines = [];
361
- const posLines = [];
362
- const commandsLines = [];
363
- const usageLine = [];
364
- for (const arg of cmdArgs) {
365
- if (arg.type === "positional") {
366
- const name = arg.name.toUpperCase();
367
- const isRequired = arg.required !== false && arg.default === void 0;
368
- const defaultHint = arg.default ? `="${arg.default}"` : "";
369
- posLines.push([
370
- "`" + name + defaultHint + "`",
371
- arg.description || "",
372
- arg.valueHint ? `<${arg.valueHint}>` : ""
373
- ]);
374
- usageLine.push(isRequired ? `<${name}>` : `[${name}]`);
375
- } else {
376
- const isRequired = arg.required === true && arg.default === void 0;
377
- const argStr = (arg.type === "boolean" && arg.default === true ? [
378
- ...(arg.alias || []).map((a) => `--no-${a}`),
379
- `--no-${arg.name}`
380
- ].join(", ") : [...(arg.alias || []).map((a) => `-${a}`), `--${arg.name}`].join(
381
- ", "
382
- )) + (arg.type === "string" && (arg.valueHint || arg.default) ? `=${arg.valueHint ? `<${arg.valueHint}>` : `"${arg.default || ""}"`}` : "");
383
- argLines.push([
384
- "`" + argStr + (isRequired ? " (required)" : "") + "`",
385
- arg.description || ""
386
- ]);
387
- if (isRequired) {
388
- usageLine.push(argStr);
389
- }
390
- }
391
- }
392
- if (cmd.subCommands) {
393
- const commandNames = [];
394
- const subCommands = await resolveValue(cmd.subCommands);
395
- for (const [name, sub] of Object.entries(subCommands)) {
396
- const subCmd = await resolveValue(sub);
397
- const meta = await resolveValue(subCmd?.meta);
398
- commandsLines.push([`\`${name}\``, meta?.description || ""]);
399
- commandNames.push(name);
400
- }
401
- usageLine.push(commandNames.join("|"));
402
- }
403
- const usageLines = [];
404
- const version = cmdMeta.version || parentMeta.version;
405
- usageLines.push(
406
- utils.colors.gray(
407
- `${cmdMeta.description} (${commandName + (version ? ` v${version}` : "")})`
408
- ),
409
- ""
410
- );
411
- const hasOptions = argLines.length > 0 || posLines.length > 0;
412
- usageLines.push(
413
- `${utils.colors.underline(utils.colors.bold("USAGE"))} \`${commandName}${hasOptions ? " [OPTIONS]" : ""} ${usageLine.join(" ")}\``,
414
- ""
415
- );
416
- if (posLines.length > 0) {
417
- usageLines.push(utils.colors.underline(utils.colors.bold("ARGUMENTS")), "");
418
- usageLines.push(formatLineColumns(posLines, " "));
419
- usageLines.push("");
420
- }
421
- if (argLines.length > 0) {
422
- usageLines.push(utils.colors.underline(utils.colors.bold("OPTIONS")), "");
423
- usageLines.push(formatLineColumns(argLines, " "));
424
- usageLines.push("");
425
- }
426
- if (commandsLines.length > 0) {
427
- usageLines.push(utils.colors.underline(utils.colors.bold("COMMANDS")), "");
428
- usageLines.push(formatLineColumns(commandsLines, " "));
429
- usageLines.push(
430
- "",
431
- `Use \`${commandName} <command> --help\` for more information about a command.`
432
- );
433
- }
434
- return usageLines.filter((l) => typeof l === "string").join("\n");
435
- }
436
-
437
- async function runMain(cmd, opts = {}) {
438
- const rawArgs = opts.rawArgs || process.argv.slice(2);
439
- const showUsage$1 = opts.showUsage || showUsage;
440
- try {
441
- if (rawArgs.includes("--help") || rawArgs.includes("-h")) {
442
- await showUsage$1(...await resolveSubCommand(cmd, rawArgs));
443
- process.exit(0);
444
- } else if (rawArgs.length === 1 && rawArgs[0] === "--version") {
445
- const meta = typeof cmd.meta === "function" ? await cmd.meta() : await cmd.meta;
446
- if (!meta?.version) {
447
- throw new CLIError("No version specified", "E_NO_VERSION");
448
- }
449
- consola__default.log(meta.version);
450
- } else {
451
- await runCommand(cmd, { rawArgs });
452
- }
453
- } catch (error) {
454
- const isCLIError = error instanceof CLIError;
455
- if (!isCLIError) {
456
- consola__default.error(error, "\n");
457
- }
458
- if (isCLIError) {
459
- await showUsage$1(...await resolveSubCommand(cmd, rawArgs));
460
- }
461
- consola__default.error(error.message);
462
- process.exit(1);
463
- }
464
- }
465
- function createMain(cmd) {
466
- return (opts = {}) => runMain(cmd, opts);
467
- }
468
-
469
- exports.createMain = createMain;
470
- exports.defineCommand = defineCommand;
471
- exports.parseArgs = parseArgs;
472
- exports.renderUsage = renderUsage;
473
- exports.runCommand = runCommand;
474
- exports.runMain = runMain;
475
- exports.showUsage = showUsage;
@@ -1,80 +0,0 @@
1
- type ArgType = "boolean" | "string" | "positional" | undefined;
2
- type _ArgDef<T extends ArgType, VT extends boolean | string> = {
3
- type?: T;
4
- description?: string;
5
- valueHint?: string;
6
- alias?: string | string[];
7
- default?: VT;
8
- required?: boolean;
9
- };
10
- type BooleanArgDef = _ArgDef<"boolean", boolean>;
11
- type StringArgDef = _ArgDef<"string", string>;
12
- type PositionalArgDef = Omit<_ArgDef<"positional", string>, "alias">;
13
- type ArgDef = BooleanArgDef | StringArgDef | PositionalArgDef;
14
- type ArgsDef = Record<string, ArgDef>;
15
- type Arg = ArgDef & {
16
- name: string;
17
- alias: string[];
18
- };
19
- type ParsedArgs<T extends ArgsDef = ArgsDef> = {
20
- _: string[];
21
- } & Record<{
22
- [K in keyof T]: T[K] extends {
23
- type: "positional";
24
- } ? K : never;
25
- }[keyof T], string> & Record<{
26
- [K in keyof T]: T[K] extends {
27
- type: "string";
28
- } ? K : never;
29
- }[keyof T], string> & Record<{
30
- [K in keyof T]: T[K] extends {
31
- type: "boolean";
32
- } ? K : never;
33
- }[keyof T], boolean> & Record<string, string | boolean | string[]>;
34
- interface CommandMeta {
35
- name?: string;
36
- version?: string;
37
- description?: string;
38
- }
39
- type SubCommandsDef = Record<string, Resolvable<CommandDef<any>>>;
40
- type CommandDef<T extends ArgsDef = ArgsDef> = {
41
- meta?: Resolvable<CommandMeta>;
42
- args?: Resolvable<T>;
43
- subCommands?: Resolvable<SubCommandsDef>;
44
- setup?: (context: CommandContext<T>) => any | Promise<any>;
45
- cleanup?: (context: CommandContext<T>) => any | Promise<any>;
46
- run?: (context: CommandContext<T>) => any | Promise<any>;
47
- };
48
- type CommandContext<T extends ArgsDef = ArgsDef> = {
49
- rawArgs: string[];
50
- args: ParsedArgs<T>;
51
- cmd: CommandDef<T>;
52
- subCommand?: CommandDef<T>;
53
- data?: any;
54
- };
55
- type Awaitable<T> = () => T | Promise<T>;
56
- type Resolvable<T> = T | Promise<T> | (() => T) | (() => Promise<T>);
57
-
58
- declare function defineCommand<T extends ArgsDef = ArgsDef>(def: CommandDef<T>): CommandDef<T>;
59
- interface RunCommandOptions {
60
- rawArgs: string[];
61
- data?: any;
62
- showUsage?: boolean;
63
- }
64
- declare function runCommand<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, opts: RunCommandOptions): Promise<{
65
- result: unknown;
66
- }>;
67
-
68
- declare function showUsage<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, parent?: CommandDef<T>): Promise<void>;
69
- declare function renderUsage<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, parent?: CommandDef<T>): Promise<string>;
70
-
71
- interface RunMainOptions {
72
- rawArgs?: string[];
73
- showUsage?: typeof showUsage;
74
- }
75
- declare function runMain<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, opts?: RunMainOptions): Promise<void>;
76
- declare function createMain<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>): (opts?: RunMainOptions) => Promise<void>;
77
-
78
- declare function parseArgs<T extends ArgsDef = ArgsDef>(rawArgs: string[], argsDef: ArgsDef): ParsedArgs<T>;
79
-
80
- export { type Arg, type ArgDef, type ArgType, type ArgsDef, type Awaitable, type BooleanArgDef, type CommandContext, type CommandDef, type CommandMeta, type ParsedArgs, type PositionalArgDef, type Resolvable, type RunCommandOptions, type RunMainOptions, type StringArgDef, type SubCommandsDef, type _ArgDef, createMain, defineCommand, parseArgs, renderUsage, runCommand, runMain, showUsage };
@@ -1,80 +0,0 @@
1
- type ArgType = "boolean" | "string" | "positional" | undefined;
2
- type _ArgDef<T extends ArgType, VT extends boolean | string> = {
3
- type?: T;
4
- description?: string;
5
- valueHint?: string;
6
- alias?: string | string[];
7
- default?: VT;
8
- required?: boolean;
9
- };
10
- type BooleanArgDef = _ArgDef<"boolean", boolean>;
11
- type StringArgDef = _ArgDef<"string", string>;
12
- type PositionalArgDef = Omit<_ArgDef<"positional", string>, "alias">;
13
- type ArgDef = BooleanArgDef | StringArgDef | PositionalArgDef;
14
- type ArgsDef = Record<string, ArgDef>;
15
- type Arg = ArgDef & {
16
- name: string;
17
- alias: string[];
18
- };
19
- type ParsedArgs<T extends ArgsDef = ArgsDef> = {
20
- _: string[];
21
- } & Record<{
22
- [K in keyof T]: T[K] extends {
23
- type: "positional";
24
- } ? K : never;
25
- }[keyof T], string> & Record<{
26
- [K in keyof T]: T[K] extends {
27
- type: "string";
28
- } ? K : never;
29
- }[keyof T], string> & Record<{
30
- [K in keyof T]: T[K] extends {
31
- type: "boolean";
32
- } ? K : never;
33
- }[keyof T], boolean> & Record<string, string | boolean | string[]>;
34
- interface CommandMeta {
35
- name?: string;
36
- version?: string;
37
- description?: string;
38
- }
39
- type SubCommandsDef = Record<string, Resolvable<CommandDef<any>>>;
40
- type CommandDef<T extends ArgsDef = ArgsDef> = {
41
- meta?: Resolvable<CommandMeta>;
42
- args?: Resolvable<T>;
43
- subCommands?: Resolvable<SubCommandsDef>;
44
- setup?: (context: CommandContext<T>) => any | Promise<any>;
45
- cleanup?: (context: CommandContext<T>) => any | Promise<any>;
46
- run?: (context: CommandContext<T>) => any | Promise<any>;
47
- };
48
- type CommandContext<T extends ArgsDef = ArgsDef> = {
49
- rawArgs: string[];
50
- args: ParsedArgs<T>;
51
- cmd: CommandDef<T>;
52
- subCommand?: CommandDef<T>;
53
- data?: any;
54
- };
55
- type Awaitable<T> = () => T | Promise<T>;
56
- type Resolvable<T> = T | Promise<T> | (() => T) | (() => Promise<T>);
57
-
58
- declare function defineCommand<T extends ArgsDef = ArgsDef>(def: CommandDef<T>): CommandDef<T>;
59
- interface RunCommandOptions {
60
- rawArgs: string[];
61
- data?: any;
62
- showUsage?: boolean;
63
- }
64
- declare function runCommand<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, opts: RunCommandOptions): Promise<{
65
- result: unknown;
66
- }>;
67
-
68
- declare function showUsage<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, parent?: CommandDef<T>): Promise<void>;
69
- declare function renderUsage<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, parent?: CommandDef<T>): Promise<string>;
70
-
71
- interface RunMainOptions {
72
- rawArgs?: string[];
73
- showUsage?: typeof showUsage;
74
- }
75
- declare function runMain<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, opts?: RunMainOptions): Promise<void>;
76
- declare function createMain<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>): (opts?: RunMainOptions) => Promise<void>;
77
-
78
- declare function parseArgs<T extends ArgsDef = ArgsDef>(rawArgs: string[], argsDef: ArgsDef): ParsedArgs<T>;
79
-
80
- export { type Arg, type ArgDef, type ArgType, type ArgsDef, type Awaitable, type BooleanArgDef, type CommandContext, type CommandDef, type CommandMeta, type ParsedArgs, type PositionalArgDef, type Resolvable, type RunCommandOptions, type RunMainOptions, type StringArgDef, type SubCommandsDef, type _ArgDef, createMain, defineCommand, parseArgs, renderUsage, runCommand, runMain, showUsage };