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