@batijs/cli 0.0.2 → 0.0.5

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 (33) hide show
  1. package/dist/boilerplates/@batijs/express/$$express-entry.ts.ts +124 -0
  2. package/dist/boilerplates/@batijs/express/$package.json.js +21 -0
  3. package/dist/boilerplates/@batijs/express/chunk-package-APCXQNZT.js +81 -0
  4. package/dist/boilerplates/@batijs/hattip/$$hattip-entry.ts.ts +84 -0
  5. package/dist/boilerplates/@batijs/hattip/$package.json.js +23 -0
  6. package/dist/boilerplates/@batijs/hattip/chunk-package-7TF47AAW.js +81 -0
  7. package/dist/boilerplates/@batijs/shared/package.json +17 -0
  8. package/dist/boilerplates/@batijs/shared/tsconfig.json +18 -0
  9. package/dist/boilerplates/@batijs/shared/vite.config.ts +5 -0
  10. package/dist/boilerplates/@batijs/solid/$package.json.js +11 -0
  11. package/dist/boilerplates/@batijs/solid/$tsconfig.json.js +12 -0
  12. package/dist/boilerplates/@batijs/solid/$vite.config.ts.js +13 -0
  13. package/dist/boilerplates/@batijs/solid/assets/logo.svg +36 -0
  14. package/dist/boilerplates/@batijs/solid/chunk-package-6DR2MCJ3.js +79 -0
  15. package/dist/boilerplates/@batijs/solid/components/Link.tsx +16 -0
  16. package/dist/boilerplates/@batijs/solid/layouts/LayoutDefault.tsx +74 -0
  17. package/dist/boilerplates/@batijs/solid/layouts/style.css +29 -0
  18. package/dist/boilerplates/@batijs/solid/pages/+config.ts +11 -0
  19. package/dist/boilerplates/@batijs/solid/pages/_error/+Page.tsx +20 -0
  20. package/dist/boilerplates/@batijs/solid/pages/index/+Page.tsx +17 -0
  21. package/dist/boilerplates/@batijs/solid/pages/index/Counter.tsx +13 -0
  22. package/dist/boilerplates/@batijs/solid/pages/star-wars/@id/+Page.tsx +15 -0
  23. package/dist/boilerplates/@batijs/solid/pages/star-wars/@id/+onBeforeRender.ts +29 -0
  24. package/dist/boilerplates/@batijs/solid/pages/star-wars/filterMovieData.ts +11 -0
  25. package/dist/boilerplates/@batijs/solid/pages/star-wars/index/+Page.tsx +23 -0
  26. package/dist/boilerplates/@batijs/solid/pages/star-wars/index/+onBeforeRender.ts +80 -0
  27. package/dist/boilerplates/@batijs/solid/pages/star-wars/types.ts +13 -0
  28. package/dist/boilerplates/@batijs/telefunc/$package.json.js +11 -0
  29. package/dist/boilerplates/@batijs/telefunc/$vite.config.ts.js +14 -0
  30. package/dist/boilerplates/@batijs/telefunc/chunk-package-2DIT65W7.js +75 -0
  31. package/dist/boilerplates/boilerplates.json +1 -0
  32. package/dist/index.js +643 -29
  33. package/package.json +18 -9
package/dist/index.js CHANGED
@@ -1,24 +1,584 @@
1
+ // ../../node_modules/.pnpm/citty@0.1.1/node_modules/citty/dist/index.mjs
2
+ import * as tty from "tty";
3
+ function toArray(val) {
4
+ if (Array.isArray(val)) {
5
+ return val;
6
+ }
7
+ return val !== void 0 ? [val] : [];
8
+ }
9
+ function formatLineColumns(lines, linePrefix = "") {
10
+ const maxLengh = [];
11
+ for (const line of lines) {
12
+ for (const [i, element] of line.entries()) {
13
+ maxLengh[i] = Math.max(maxLengh[i] || 0, element.length);
14
+ }
15
+ }
16
+ return lines.map(
17
+ (l) => l.map(
18
+ (c, i) => linePrefix + c[i === 0 ? "padStart" : "padEnd"](maxLengh[i])
19
+ ).join(" ")
20
+ ).join("\n");
21
+ }
22
+ function resolveValue(input) {
23
+ return typeof input === "function" ? input() : input;
24
+ }
25
+ var CLIError = class extends Error {
26
+ constructor(message, code) {
27
+ super(message);
28
+ this.code = code;
29
+ this.name = "CLIError";
30
+ }
31
+ };
32
+ var NUMBER_CHAR_RE = /\d/;
33
+ var STR_SPLITTERS = ["-", "_", "/", "."];
34
+ function isUppercase(char = "") {
35
+ if (NUMBER_CHAR_RE.test(char)) {
36
+ return void 0;
37
+ }
38
+ return char.toUpperCase() === char;
39
+ }
40
+ function splitByCase(string_, separators) {
41
+ const splitters = separators ?? STR_SPLITTERS;
42
+ const parts = [];
43
+ if (!string_ || typeof string_ !== "string") {
44
+ return parts;
45
+ }
46
+ let buff = "";
47
+ let previousUpper;
48
+ let previousSplitter;
49
+ for (const char of string_) {
50
+ const isSplitter = splitters.includes(char);
51
+ if (isSplitter === true) {
52
+ parts.push(buff);
53
+ buff = "";
54
+ previousUpper = void 0;
55
+ continue;
56
+ }
57
+ const isUpper = isUppercase(char);
58
+ if (previousSplitter === false) {
59
+ if (previousUpper === false && isUpper === true) {
60
+ parts.push(buff);
61
+ buff = char;
62
+ previousUpper = isUpper;
63
+ continue;
64
+ }
65
+ if (previousUpper === true && isUpper === false && buff.length > 1) {
66
+ const lastChar = buff[buff.length - 1];
67
+ parts.push(buff.slice(0, Math.max(0, buff.length - 1)));
68
+ buff = lastChar + char;
69
+ previousUpper = isUpper;
70
+ continue;
71
+ }
72
+ }
73
+ buff += char;
74
+ previousUpper = isUpper;
75
+ previousSplitter = isSplitter;
76
+ }
77
+ parts.push(buff);
78
+ return parts;
79
+ }
80
+ function upperFirst(string_) {
81
+ return !string_ ? "" : string_[0].toUpperCase() + string_.slice(1);
82
+ }
83
+ function lowerFirst(string_) {
84
+ return !string_ ? "" : string_[0].toLowerCase() + string_.slice(1);
85
+ }
86
+ function pascalCase(string_) {
87
+ return !string_ ? "" : (Array.isArray(string_) ? string_ : splitByCase(string_)).map((p) => upperFirst(p)).join("");
88
+ }
89
+ function camelCase(string_) {
90
+ return lowerFirst(pascalCase(string_));
91
+ }
92
+ function kebabCase(string_, joiner) {
93
+ return !string_ ? "" : (Array.isArray(string_) ? string_ : splitByCase(string_)).map((p) => p.toLowerCase()).join(joiner ?? "-");
94
+ }
95
+ function toArr(any) {
96
+ return any == void 0 ? [] : Array.isArray(any) ? any : [any];
97
+ }
98
+ function toVal(out, key, val, opts) {
99
+ let x;
100
+ const old = out[key];
101
+ 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;
102
+ out[key] = old == void 0 ? nxt : Array.isArray(old) ? old.concat(nxt) : [old, nxt];
103
+ }
104
+ function parseRawArgs(args = [], opts = {}) {
105
+ let k;
106
+ let arr;
107
+ let arg;
108
+ let name;
109
+ let val;
110
+ const out = { _: [] };
111
+ let i = 0;
112
+ let j = 0;
113
+ let idx = 0;
114
+ const len = args.length;
115
+ const alibi = opts.alias !== void 0;
116
+ const strict = opts.unknown !== void 0;
117
+ const defaults = opts.default !== void 0;
118
+ opts.alias = opts.alias || {};
119
+ opts.string = toArr(opts.string);
120
+ opts.boolean = toArr(opts.boolean);
121
+ if (alibi) {
122
+ for (k in opts.alias) {
123
+ arr = opts.alias[k] = toArr(opts.alias[k]);
124
+ for (i = 0; i < arr.length; i++) {
125
+ (opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
126
+ }
127
+ }
128
+ }
129
+ for (i = opts.boolean.length; i-- > 0; ) {
130
+ arr = opts.alias[opts.boolean[i]] || [];
131
+ for (j = arr.length; j-- > 0; ) {
132
+ opts.boolean.push(arr[j]);
133
+ }
134
+ }
135
+ for (i = opts.string.length; i-- > 0; ) {
136
+ arr = opts.alias[opts.string[i]] || [];
137
+ for (j = arr.length; j-- > 0; ) {
138
+ opts.string.push(arr[j]);
139
+ }
140
+ }
141
+ if (defaults) {
142
+ for (k in opts.default) {
143
+ name = typeof opts.default[k];
144
+ arr = opts.alias[k] = opts.alias[k] || [];
145
+ if (opts[name] !== void 0) {
146
+ opts[name].push(k);
147
+ for (i = 0; i < arr.length; i++) {
148
+ opts[name].push(arr[i]);
149
+ }
150
+ }
151
+ }
152
+ }
153
+ const keys = strict ? Object.keys(opts.alias) : [];
154
+ for (i = 0; i < len; i++) {
155
+ arg = args[i];
156
+ if (arg === "--") {
157
+ out._ = out._.concat(args.slice(++i));
158
+ break;
159
+ }
160
+ for (j = 0; j < arg.length; j++) {
161
+ if (arg.charCodeAt(j) !== 45) {
162
+ break;
163
+ }
164
+ }
165
+ if (j === 0) {
166
+ out._.push(arg);
167
+ } else if (arg.substring(j, j + 3) === "no-") {
168
+ name = arg.slice(Math.max(0, j + 3));
169
+ if (strict && !~keys.indexOf(name)) {
170
+ return opts.unknown(arg);
171
+ }
172
+ out[name] = false;
173
+ } else {
174
+ for (idx = j + 1; idx < arg.length; idx++) {
175
+ if (arg.charCodeAt(idx) === 61) {
176
+ break;
177
+ }
178
+ }
179
+ name = arg.substring(j, idx);
180
+ val = arg.slice(Math.max(0, ++idx)) || i + 1 === len || ("" + args[i + 1]).charCodeAt(0) === 45 || args[++i];
181
+ arr = j === 2 ? [name] : name;
182
+ for (idx = 0; idx < arr.length; idx++) {
183
+ name = arr[idx];
184
+ if (strict && !~keys.indexOf(name)) {
185
+ return opts.unknown("-".repeat(j) + name);
186
+ }
187
+ toVal(out, name, idx + 1 < arr.length || val, opts);
188
+ }
189
+ }
190
+ }
191
+ if (defaults) {
192
+ for (k in opts.default) {
193
+ if (out[k] === void 0) {
194
+ out[k] = opts.default[k];
195
+ }
196
+ }
197
+ }
198
+ if (alibi) {
199
+ for (k in out) {
200
+ arr = opts.alias[k] || [];
201
+ while (arr.length > 0) {
202
+ out[arr.shift()] = out[k];
203
+ }
204
+ }
205
+ }
206
+ return out;
207
+ }
208
+ function parseArgs(rawArgs, argsDef) {
209
+ const parseOptions = {
210
+ boolean: [],
211
+ string: [],
212
+ mixed: [],
213
+ alias: {},
214
+ default: {}
215
+ };
216
+ const args = resolveArgs(argsDef);
217
+ for (const arg of args) {
218
+ if (arg.type === "positional") {
219
+ continue;
220
+ }
221
+ if (arg.type === "string") {
222
+ parseOptions.string.push(arg.name);
223
+ } else if (arg.type === "boolean") {
224
+ parseOptions.boolean.push(arg.name);
225
+ }
226
+ if (arg.default !== void 0) {
227
+ parseOptions.default[arg.name] = arg.default;
228
+ }
229
+ if (arg.alias) {
230
+ parseOptions.alias[arg.name] = arg.alias;
231
+ }
232
+ }
233
+ const parsed = parseRawArgs(rawArgs, parseOptions);
234
+ const [...positionalArguments] = parsed._;
235
+ const parsedArgsProxy = new Proxy(parsed, {
236
+ get(target, prop) {
237
+ return target[prop] ?? target[camelCase(prop)] ?? target[kebabCase(prop)];
238
+ }
239
+ });
240
+ for (const [, arg] of args.entries()) {
241
+ if (arg.type === "positional") {
242
+ const nextPositionalArgument = positionalArguments.shift();
243
+ if (nextPositionalArgument !== void 0) {
244
+ parsedArgsProxy[arg.name] = nextPositionalArgument;
245
+ } else if (arg.default !== void 0) {
246
+ parsedArgsProxy[arg.name] = arg.default;
247
+ } else {
248
+ throw new CLIError(
249
+ `Missing required positional argument: ${arg.name.toUpperCase()}`,
250
+ "EARG"
251
+ );
252
+ }
253
+ } else if (arg.required && parsedArgsProxy[arg.name] === void 0) {
254
+ throw new CLIError(`Missing required argument: --${arg.name}`, "EARG");
255
+ }
256
+ }
257
+ return parsedArgsProxy;
258
+ }
259
+ function resolveArgs(argsDef) {
260
+ const args = [];
261
+ for (const [name, argDef] of Object.entries(argsDef || {})) {
262
+ args.push({
263
+ ...argDef,
264
+ name,
265
+ alias: toArray(argDef.alias)
266
+ });
267
+ }
268
+ return args;
269
+ }
270
+ function defineCommand(def) {
271
+ return def;
272
+ }
273
+ async function runCommand(cmd, opts) {
274
+ const cmdArgs = await resolveValue(cmd.args || {});
275
+ const parsedArgs = parseArgs(opts.rawArgs, cmdArgs);
276
+ const context = {
277
+ rawArgs: opts.rawArgs,
278
+ args: parsedArgs,
279
+ cmd
280
+ };
281
+ if (typeof cmd.setup === "function") {
282
+ await cmd.setup(context);
283
+ }
284
+ const subCommands = await resolveValue(cmd.subCommands);
285
+ if (subCommands && Object.keys(subCommands).length > 0) {
286
+ const subCommandArgIndex = opts.rawArgs.findIndex(
287
+ (arg) => !arg.startsWith("-")
288
+ );
289
+ const subCommandName = opts.rawArgs[subCommandArgIndex];
290
+ if (!subCommandName && !cmd.run) {
291
+ throw new CLIError(
292
+ `Missing sub command. Use --help to see available sub commands.`,
293
+ "ESUBCOMMAND"
294
+ );
295
+ }
296
+ if (!subCommands[subCommandName]) {
297
+ throw new CLIError(
298
+ `Unknown sub command: ${subCommandName}`,
299
+ "ESUBCOMMAND"
300
+ );
301
+ }
302
+ const subCommand = await resolveValue(subCommands[subCommandName]);
303
+ if (subCommand) {
304
+ await runCommand(subCommand, {
305
+ rawArgs: opts.rawArgs.slice(subCommandArgIndex + 1)
306
+ });
307
+ }
308
+ }
309
+ if (typeof cmd.run === "function") {
310
+ await cmd.run(context);
311
+ }
312
+ }
313
+ async function resolveSubCommand(cmd, rawArgs, parent) {
314
+ const subCommands = await resolveValue(cmd.subCommands);
315
+ if (subCommands && Object.keys(subCommands).length > 0) {
316
+ const subCommandArgIndex = rawArgs.findIndex((arg) => !arg.startsWith("-"));
317
+ const subCommandName = rawArgs[subCommandArgIndex];
318
+ const subCommand = await resolveValue(subCommands[subCommandName]);
319
+ if (subCommand) {
320
+ return resolveSubCommand(
321
+ subCommand,
322
+ rawArgs.slice(subCommandArgIndex + 1),
323
+ cmd
324
+ );
325
+ }
326
+ }
327
+ return [cmd, parent];
328
+ }
329
+ async function showUsage(cmd, parent) {
330
+ try {
331
+ console.log(await renderUsage(cmd, parent) + "\n");
332
+ } catch (error) {
333
+ console.error(error);
334
+ }
335
+ }
336
+ async function renderUsage(cmd, parent) {
337
+ const cmdMeta = await resolveValue(cmd.meta || {});
338
+ const cmdArgs = resolveArgs(await resolveValue(cmd.args || {}));
339
+ const parentMeta = await resolveValue(parent?.meta || {});
340
+ const commandName = `${parentMeta.name ? `${parentMeta.name} ` : ""}` + (cmdMeta.name || process.argv[1]);
341
+ const argLines = [];
342
+ const posLines = [];
343
+ const commandsLines = [];
344
+ const usageLine = [];
345
+ for (const arg of cmdArgs) {
346
+ if (arg.type === "positional") {
347
+ const name = arg.name.toUpperCase();
348
+ const isRequired = arg.required !== false && arg.default === void 0;
349
+ const usageHint = arg.default ? `="${arg.default}"` : "";
350
+ posLines.push([name + usageHint, arg.description || ""]);
351
+ usageLine.push(isRequired ? `<${name}>` : `[${name}]`);
352
+ } else {
353
+ const isRequired = arg.required === true && arg.default === void 0;
354
+ const argStr = (arg.type === "boolean" && arg.default === true ? [
355
+ ...(arg.alias || []).map((a) => `--no-${a}`),
356
+ `--no-${arg.name}`
357
+ ].join(", ") : [...(arg.alias || []).map((a) => `-${a}`), `--${arg.name}`].join(
358
+ ", "
359
+ )) + (arg.type === "string" && (arg.valueHint || arg.default) ? `=${arg.valueHint ? `<${arg.valueHint}>` : `"${arg.default || ""}"`}` : "");
360
+ argLines.push([
361
+ argStr + (isRequired ? " (required)" : ""),
362
+ arg.description || ""
363
+ ]);
364
+ if (isRequired) {
365
+ usageLine.push(argStr);
366
+ }
367
+ }
368
+ }
369
+ if (cmd.subCommands) {
370
+ const commandNames = [];
371
+ for (const [name, sub] of Object.entries(cmd.subCommands)) {
372
+ commandsLines.push([name, sub.meta?.description || ""]);
373
+ commandNames.push(name);
374
+ }
375
+ usageLine.push(commandNames.join("|"));
376
+ }
377
+ const usageLines = [];
378
+ const version = cmdMeta.version || parentMeta.version;
379
+ usageLines.push(
380
+ commandName + (version ? ` v${version}` : ""),
381
+ cmdMeta.description,
382
+ ""
383
+ );
384
+ const hasOptions = argLines.length > 0 || posLines.length > 0;
385
+ usageLines.push(
386
+ `USAGE: ${commandName}${hasOptions ? " [OPTIONS]" : ""} ${usageLine.join(
387
+ " "
388
+ )}`,
389
+ ""
390
+ );
391
+ if (posLines.length > 0) {
392
+ usageLines.push("ARGUMENTS:", "");
393
+ usageLines.push(formatLineColumns(posLines, " "));
394
+ usageLines.push("");
395
+ }
396
+ if (argLines.length > 0) {
397
+ usageLines.push("OPTIONS:", "");
398
+ usageLines.push(formatLineColumns(argLines, " "));
399
+ usageLines.push("");
400
+ }
401
+ if (commandsLines.length > 0) {
402
+ usageLines.push("COMMANDS:", "");
403
+ usageLines.push(formatLineColumns(commandsLines, " "));
404
+ usageLines.push(
405
+ "",
406
+ `Use \`${commandName} <command> --help\` for more information about a command.`
407
+ );
408
+ }
409
+ return usageLines.filter((l) => typeof l === "string").join("\n");
410
+ }
411
+ var {
412
+ env = {},
413
+ argv = [],
414
+ platform = ""
415
+ } = typeof process === "undefined" ? {} : process;
416
+ var isDisabled = "NO_COLOR" in env || argv.includes("--no-color");
417
+ var isForced = "FORCE_COLOR" in env || argv.includes("--color");
418
+ var isWindows = platform === "win32";
419
+ var isDumbTerminal = env.TERM === "dumb";
420
+ var isCompatibleTerminal = tty && tty.isatty && tty.isatty(1) && env.TERM && !isDumbTerminal;
421
+ var isCI = "CI" in env && ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env);
422
+ var isColorSupported = !isDisabled && (isForced || isWindows && !isDumbTerminal || isCompatibleTerminal || isCI);
423
+ var replaceClose = (index, string, close, replace, head = string.substring(0, index) + replace, tail = string.substring(index + close.length), next = tail.indexOf(close)) => head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
424
+ var clearBleed = (index, string, open, close, replace) => index < 0 ? open + string + close : open + replaceClose(index, string, close, replace) + close;
425
+ var filterEmpty = (open, close, replace = open, at = open.length + 1) => (string) => string || !(string === "" || string === void 0) ? clearBleed(
426
+ ("" + string).indexOf(close, at),
427
+ string,
428
+ open,
429
+ close,
430
+ replace
431
+ ) : "";
432
+ var init = (open, close, replace) => filterEmpty(`\x1B[${open}m`, `\x1B[${close}m`, replace);
433
+ var colors = {
434
+ reset: init(0, 0),
435
+ bold: init(1, 22, "\x1B[22m\x1B[1m"),
436
+ dim: init(2, 22, "\x1B[22m\x1B[2m"),
437
+ italic: init(3, 23),
438
+ underline: init(4, 24),
439
+ inverse: init(7, 27),
440
+ hidden: init(8, 28),
441
+ strikethrough: init(9, 29),
442
+ black: init(30, 39),
443
+ red: init(31, 39),
444
+ green: init(32, 39),
445
+ yellow: init(33, 39),
446
+ blue: init(34, 39),
447
+ magenta: init(35, 39),
448
+ cyan: init(36, 39),
449
+ white: init(37, 39),
450
+ gray: init(90, 39),
451
+ bgBlack: init(40, 49),
452
+ bgRed: init(41, 49),
453
+ bgGreen: init(42, 49),
454
+ bgYellow: init(43, 49),
455
+ bgBlue: init(44, 49),
456
+ bgMagenta: init(45, 49),
457
+ bgCyan: init(46, 49),
458
+ bgWhite: init(47, 49),
459
+ blackBright: init(90, 39),
460
+ redBright: init(91, 39),
461
+ greenBright: init(92, 39),
462
+ yellowBright: init(93, 39),
463
+ blueBright: init(94, 39),
464
+ magentaBright: init(95, 39),
465
+ cyanBright: init(96, 39),
466
+ whiteBright: init(97, 39),
467
+ bgBlackBright: init(100, 49),
468
+ bgRedBright: init(101, 49),
469
+ bgGreenBright: init(102, 49),
470
+ bgYellowBright: init(103, 49),
471
+ bgBlueBright: init(104, 49),
472
+ bgMagentaBright: init(105, 49),
473
+ bgCyanBright: init(106, 49),
474
+ bgWhiteBright: init(107, 49)
475
+ };
476
+ var createColors = ({ useColor = isColorSupported } = {}) => useColor ? colors : Object.keys(colors).reduce(
477
+ (colors2, key) => ({ ...colors2, [key]: String }),
478
+ {}
479
+ );
480
+ var {
481
+ reset,
482
+ bold,
483
+ dim,
484
+ italic,
485
+ underline,
486
+ inverse,
487
+ hidden,
488
+ strikethrough,
489
+ black,
490
+ red,
491
+ green,
492
+ yellow,
493
+ blue,
494
+ magenta,
495
+ cyan,
496
+ white,
497
+ gray,
498
+ bgBlack,
499
+ bgRed,
500
+ bgGreen,
501
+ bgYellow,
502
+ bgBlue,
503
+ bgMagenta,
504
+ bgCyan,
505
+ bgWhite,
506
+ blackBright,
507
+ redBright,
508
+ greenBright,
509
+ yellowBright,
510
+ blueBright,
511
+ magentaBright,
512
+ cyanBright,
513
+ whiteBright,
514
+ bgBlackBright,
515
+ bgRedBright,
516
+ bgGreenBright,
517
+ bgYellowBright,
518
+ bgBlueBright,
519
+ bgMagentaBright,
520
+ bgCyanBright,
521
+ bgWhiteBright
522
+ } = createColors();
523
+ async function runMain(cmd, opts = {}) {
524
+ const rawArgs = opts.rawArgs || process.argv.slice(2);
525
+ try {
526
+ if (rawArgs.includes("--help") || rawArgs.includes("-h")) {
527
+ await showUsage(...await resolveSubCommand(cmd, rawArgs));
528
+ process.exit(0);
529
+ } else {
530
+ await runCommand(cmd, { rawArgs });
531
+ }
532
+ } catch (error) {
533
+ const isCLIError = error instanceof CLIError;
534
+ if (!isCLIError) {
535
+ console.error(error, "\n");
536
+ }
537
+ console.error(
538
+ `
539
+ ${bgRed(` ${error.code || error.name} `)} ${error.message}
540
+ `
541
+ );
542
+ if (isCLIError) {
543
+ await showUsage(...await resolveSubCommand(cmd, rawArgs));
544
+ }
545
+ process.exit(1);
546
+ }
547
+ }
548
+
1
549
  // index.ts
2
- import { defineCommand, runMain } from "citty";
3
550
  import exec from "@batijs/build";
4
551
 
5
552
  // package.json
6
553
  var package_default = {
7
554
  name: "@batijs/cli",
8
- version: "0.0.2",
555
+ version: "0.0.5",
9
556
  description: "",
10
557
  type: "module",
11
558
  scripts: {
559
+ prerelease: "rm -rf ./dist",
12
560
  prepublishOnly: "pnpm run build",
13
- build: "tsup"
561
+ build: "rm -rf dist && tsup"
14
562
  },
15
563
  keywords: [],
16
564
  author: "",
17
565
  license: "MIT",
18
566
  devDependencies: {
19
- "@types/node": "^16.0.0",
20
- tsup: "^6.7.0",
21
- typescript: "^5.0.3"
567
+ "@batijs/tsup": "workspace:*",
568
+ "@types/node": "^16.18.24",
569
+ citty: "^0.1.1",
570
+ colorette: "^2.0.20",
571
+ esbuild: "^0.17.18",
572
+ execa: "^7.1.1",
573
+ typescript: "^5.0.4"
574
+ },
575
+ dependencies: {
576
+ "@batijs/build": "workspace:*",
577
+ "@batijs/core": "workspace:*",
578
+ "@typescript-eslint/eslint-plugin": "^5.59.2",
579
+ "@typescript-eslint/parser": "^5.59.2",
580
+ eslint: "^8.39.0",
581
+ "eslint-plugin-unused-imports": "^2.0.0"
22
582
  },
23
583
  bin: "./dist/index.js",
24
584
  exports: {
@@ -31,36 +591,90 @@ var package_default = {
31
591
  ]
32
592
  }
33
593
  },
34
- dependencies: {
35
- "@batijs/build": "workspace:*",
36
- citty: "^0.1.1"
37
- },
38
594
  files: [
39
595
  "dist/"
40
596
  ]
41
597
  };
42
598
 
43
599
  // index.ts
44
- var main = defineCommand({
45
- meta: {
46
- name: package_default.name,
47
- version: package_default.version,
48
- description: package_default.description
49
- },
50
- args: {
51
- dist: {
52
- type: "positional",
53
- description: "Dist folder",
54
- required: true
600
+ import { flags as coreFlags } from "@batijs/core";
601
+ import { existsSync } from "fs";
602
+ import { fileURLToPath } from "url";
603
+ import { dirname, join } from "path";
604
+ import { readFile } from "fs/promises";
605
+ var __filename = fileURLToPath(import.meta.url);
606
+ var __dirname = dirname(__filename);
607
+ function boilerplatesDir() {
608
+ if (existsSync(join(__dirname, "boilerplates", "boilerplates.json"))) {
609
+ return join(__dirname, "boilerplates");
610
+ } else if (existsSync(join(__dirname, "dist", "boilerplates", "boilerplates.json"))) {
611
+ return join(__dirname, "dist", "boilerplates");
612
+ }
613
+ throw new Error("Missing boilerplates.json file. Run `pnpm run build`");
614
+ }
615
+ async function parseBoilerplates(dir) {
616
+ return JSON.parse(await readFile(join(dir, "boilerplates.json"), "utf-8"));
617
+ }
618
+ function toArg(flag) {
619
+ if (!flag)
620
+ return {};
621
+ return {
622
+ [flag]: {
623
+ type: "boolean",
624
+ required: false
55
625
  }
56
- },
57
- run({ args }) {
58
- exec(
626
+ };
627
+ }
628
+ async function run() {
629
+ const dir = boilerplatesDir();
630
+ const boilerplates = await parseBoilerplates(dir);
631
+ const main = defineCommand({
632
+ meta: {
633
+ name: package_default.name,
634
+ version: package_default.version,
635
+ description: package_default.description
636
+ },
637
+ args: Object.assign(
59
638
  {
60
- dist: args.dist
639
+ dist: {
640
+ type: "positional",
641
+ description: "Dist folder",
642
+ required: true
643
+ }
61
644
  },
62
- {}
63
- );
64
- }
645
+ ...Array.from(coreFlags.keys()).map(toArg)
646
+ ),
647
+ async run({ args }) {
648
+ const sources = [];
649
+ const features = [];
650
+ const flags = Object.entries(args).filter(([, val]) => val === true).map(([key]) => key);
651
+ for (const bl of boilerplates.filter((b) => !b.config.flag)) {
652
+ sources.push(join(dir, bl.folder));
653
+ }
654
+ for (const bl of boilerplates.filter((b) => Boolean(b.config.flag))) {
655
+ if (flags.includes(bl.config.flag)) {
656
+ sources.push(join(dir, bl.folder));
657
+ }
658
+ }
659
+ for (const flag of flags) {
660
+ features.push(coreFlags.get(flag));
661
+ }
662
+ await exec(
663
+ {
664
+ source: sources,
665
+ dist: args.dist
666
+ },
667
+ {
668
+ VIKE_MODULES: features
669
+ }
670
+ );
671
+ }
672
+ });
673
+ await runMain(main);
674
+ }
675
+ run().then(() => {
676
+ process.exit(0);
677
+ }).catch((e) => {
678
+ console.error(e);
679
+ process.exit(1);
65
680
  });
66
- runMain(main);