typerighter 0.2.1 → 0.3.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.
Files changed (45) hide show
  1. package/bin/typerighter.js +1 -1
  2. package/dist/cli-CoyGXgR1.js +579 -0
  3. package/dist/cli.js +1 -1
  4. package/dist/{vite-BbjHwKzf.js → constants-B7b8AsH0.js} +126 -313
  5. package/dist/index.js +4 -4
  6. package/dist/init-CUo89E7j.js +2358 -0
  7. package/dist/node/build/index.d.ts +2 -3
  8. package/dist/node/build/index.d.ts.map +1 -1
  9. package/dist/node/build/{render.d.ts → prerender.d.ts} +6 -3
  10. package/dist/node/build/prerender.d.ts.map +1 -0
  11. package/dist/node/cli/index.d.ts +1 -1
  12. package/dist/node/cli/index.d.ts.map +1 -1
  13. package/dist/node/cli/init.d.ts +1 -1
  14. package/dist/node/cli/init.d.ts.map +1 -1
  15. package/dist/node/context.d.ts +14 -0
  16. package/dist/node/context.d.ts.map +1 -0
  17. package/dist/node/lib/logger.d.ts +10 -2
  18. package/dist/node/lib/logger.d.ts.map +1 -1
  19. package/dist/node/lib/progress.d.ts +10 -0
  20. package/dist/node/lib/progress.d.ts.map +1 -0
  21. package/dist/node/lib/typedown-context.d.ts +1 -3
  22. package/dist/node/lib/typedown-context.d.ts.map +1 -1
  23. package/dist/node/plugin/vite/index.d.ts +5 -1
  24. package/dist/node/plugin/vite/index.d.ts.map +1 -1
  25. package/dist/plugin-D2xuSVM4.js +1 -0
  26. package/dist/rolldown-runtime-Dqa2HsxW.js +20 -0
  27. package/dist/shared/utils/format.d.ts +2 -0
  28. package/dist/shared/utils/format.d.ts.map +1 -0
  29. package/dist/shared/utils/html.d.ts +2 -0
  30. package/dist/shared/utils/html.d.ts.map +1 -0
  31. package/dist/shared/utils/html.test.d.ts.map +1 -0
  32. package/dist/shared/utils/index.d.ts +2 -0
  33. package/dist/shared/utils/index.d.ts.map +1 -1
  34. package/dist/vite-BxXQPieu.js +228 -0
  35. package/dist/vite.js +2 -2
  36. package/package.json +6 -3
  37. package/dist/cli-Dq8LM0iJ.js +0 -160
  38. package/dist/constants-BN1OmC7K.js +0 -46
  39. package/dist/init-0BIO3hYI.js +0 -647
  40. package/dist/node/build/html.d.ts +0 -21
  41. package/dist/node/build/html.d.ts.map +0 -1
  42. package/dist/node/build/html.test.d.ts.map +0 -1
  43. package/dist/node/build/render.d.ts.map +0 -1
  44. package/dist/plugin-6igA2bKK.js +0 -1
  45. /package/dist/{node/build → shared/utils}/html.test.d.ts +0 -0
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env -S node --no-warnings
2
2
 
3
3
  import('../dist/cli.js').then(({
4
4
  cli,
@@ -0,0 +1,579 @@
1
+ import "./shared-DzTfF-_d.js";
2
+ import { a as e, s as t } from "./constants-B7b8AsH0.js";
3
+ import { n, r, t as i } from "./vite-BxXQPieu.js";
4
+ import a from "node:path";
5
+ import { build as o, createServer as s } from "vite";
6
+ import c from "picocolors";
7
+ import l from "node:fs/promises";
8
+ //#region src/shared/utils/format.ts
9
+ function u(e) {
10
+ return e < 1e3 ? `${Math.round(e)}ms` : `${(e / 1e3).toFixed(1)}s`;
11
+ }
12
+ //#endregion
13
+ //#region src/node/build/prerender.ts
14
+ async function d(e) {
15
+ let t = await import(e.ssrEntryPath), { clientEntry: n, cssFiles: r, jsFiles: i } = await p(e.clientOutDir), o = e.pagePaths.length, s = 0;
16
+ await Promise.all(e.pagePaths.map(async (c) => {
17
+ let u = await t.render(c), d = f({
18
+ content: u.html,
19
+ title: u.pageData.title,
20
+ description: u.pageData.frontmatter.description === void 0 ? "" : String(u.pageData.frontmatter.description),
21
+ clientEntry: n,
22
+ cssFiles: r,
23
+ jsFiles: i,
24
+ base: e.base
25
+ }), p = c === "/" ? "index.html" : `${c.replace(/^\//, "")}.html`, m = a.join(e.outDir, p);
26
+ await l.mkdir(a.dirname(m), { recursive: !0 }), await l.writeFile(m, d), s++, e.progress?.update(s, o);
27
+ }));
28
+ }
29
+ function f(e) {
30
+ let n = e.cssFiles.map((t) => ` <link rel="stylesheet" href="${e.base}${t}">`).join("\n"), r = e.jsFiles.map((t) => ` <link rel="modulepreload" href="${e.base}${t}">`).join("\n");
31
+ return `<!DOCTYPE html>
32
+ <html lang="${e.lang ?? "en"}">
33
+ <head>
34
+ <meta charset="UTF-8">
35
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
36
+ <title>${t(e.title)}</title>
37
+ <meta name="description" content="${t(e.description)}">
38
+ ${n}
39
+ ${r}
40
+ </head>
41
+ <body>
42
+ <div id="app">${e.content}</div>
43
+ <script type="module" src="${e.base}${e.clientEntry}"><\/script>
44
+ </body>
45
+ </html>`;
46
+ }
47
+ async function p(e) {
48
+ let t = a.join(e, "assets"), n = [], r = await l.readdir(t).catch(() => n), i = [], o = [], s = "";
49
+ for (let e of r) e.endsWith(".css") ? i.push(`assets/${e}`) : e.endsWith(".js") && (e.startsWith("client-entry") || e.startsWith("index") ? s = `assets/${e}` : o.push(`assets/${e}`));
50
+ return !s && o.length > 0 && (s = o[0], o.splice(0, 1)), {
51
+ clientEntry: s,
52
+ cssFiles: i,
53
+ jsFiles: o
54
+ };
55
+ }
56
+ //#endregion
57
+ //#region src/node/lib/progress.ts
58
+ var m = class {
59
+ logger;
60
+ label;
61
+ start;
62
+ constructor(e, t) {
63
+ this.logger = e, this.label = t, this.start = performance.now(), this.logger.start(t);
64
+ }
65
+ update(e, t) {
66
+ if (!process.stdout.isTTY) return;
67
+ let n = Math.round(e / t * 100);
68
+ process.stdout.write(`\r ${this.label} ${e}/${t} (${n}%)`);
69
+ }
70
+ done(e) {
71
+ process.stdout.isTTY && process.stdout.write("\r\x1B[K");
72
+ let t = Math.round(performance.now() - this.start);
73
+ this.logger.success(`${e} (${u(t)})`);
74
+ }
75
+ }, h = "typerighter/client/theme-default";
76
+ async function g(e, t = {}) {
77
+ let { root: s, logger: c } = e, u = a.resolve(s, t.outDir ?? "dist"), f = t.base ?? "/", p = a.join(u, ".client"), g = a.join(u, ".server"), v = await e.getTdContext(), [y, b, x] = await Promise.all([
78
+ v.getConfig(),
79
+ v.listFiles(),
80
+ v.listFilesGroupedBySchema()
81
+ ]), S = b.some((e) => e === "index.td"), C = JSON.stringify({
82
+ title: y.siteTitle,
83
+ description: y.siteDescription
84
+ }), w = JSON.stringify({ sidebarGroups: x }), T = a.join(s, "node_modules", ".typerighter");
85
+ await l.mkdir(T, { recursive: !0 });
86
+ let E = a.join(T, "client-entry.js"), D = a.join(T, "ssr-entry.js");
87
+ await Promise.all([l.writeFile(E, n({
88
+ contentDir: y.contentDir,
89
+ siteTitle: y.siteTitle,
90
+ siteDescription: y.siteDescription,
91
+ hasIndex: S,
92
+ sidebarGroups: x
93
+ })), l.writeFile(D, r({
94
+ contentDir: y.contentDir,
95
+ layoutImport: h,
96
+ siteConfig: C,
97
+ siteData: w
98
+ }))]);
99
+ try {
100
+ let n = i({ context: e }), r = e.createViteLogger(), h = new m(c, "Building client bundle...");
101
+ await o({
102
+ ...t.viteConfig,
103
+ root: s,
104
+ base: f,
105
+ plugins: n,
106
+ customLogger: r,
107
+ logLevel: "silent",
108
+ build: {
109
+ ...t.viteConfig?.build,
110
+ outDir: p,
111
+ ssrManifest: !0,
112
+ emptyOutDir: !0,
113
+ rollupOptions: {
114
+ ...t.viteConfig?.build?.rollupOptions,
115
+ input: E
116
+ }
117
+ }
118
+ });
119
+ let v = await l.readdir(a.join(p, "assets")).catch(() => []);
120
+ h.done(`Client bundle (${v.length} chunks)`);
121
+ let x = new m(c, "Building SSR bundle...");
122
+ await o({
123
+ ...t.viteConfig,
124
+ root: s,
125
+ base: f,
126
+ plugins: n,
127
+ customLogger: r,
128
+ logLevel: "silent",
129
+ build: {
130
+ ...t.viteConfig?.build,
131
+ outDir: g,
132
+ ssr: D,
133
+ emptyOutDir: !0
134
+ }
135
+ }), x.done("SSR bundle");
136
+ let C = b.map((e) => {
137
+ let t = e.replace(/\.td$/, "");
138
+ return t === "index" ? "/" : `/${t}`;
139
+ });
140
+ S || C.push("/");
141
+ let w = new m(c, "Pre-rendering pages...");
142
+ await d({
143
+ ssrEntryPath: a.join(g, "ssr-entry.js"),
144
+ clientOutDir: p,
145
+ outDir: u,
146
+ base: f,
147
+ pagePaths: C,
148
+ progress: w
149
+ }), w.done(`Pre-rendered ${C.length} pages`);
150
+ let T = a.join(p, "assets"), O = a.join(u, "assets");
151
+ await l.cp(T, O, { recursive: !0 }).catch(() => {}), await _(a.join(s, y.contentDir), u);
152
+ } finally {
153
+ await Promise.all([
154
+ l.rm(T, {
155
+ recursive: !0,
156
+ force: !0
157
+ }),
158
+ l.rm(p, {
159
+ recursive: !0,
160
+ force: !0
161
+ }),
162
+ l.rm(g, {
163
+ recursive: !0,
164
+ force: !0
165
+ })
166
+ ]);
167
+ }
168
+ c.log(`\nBuild complete. Output: ${u}`);
169
+ }
170
+ async function _(e, t) {
171
+ let n = (await l.readdir(e, {
172
+ recursive: !0,
173
+ withFileTypes: !0
174
+ })).filter((e) => e.isFile() && !e.name.endsWith(".td")).map(async (n) => {
175
+ let r = a.join(n.parentPath, n.name), i = a.relative(e, r), o = a.join(t, i);
176
+ return l.mkdir(a.dirname(o), { recursive: !0 }).then(() => l.copyFile(r, o));
177
+ });
178
+ await Promise.all(n);
179
+ }
180
+ //#endregion
181
+ //#region ../../node_modules/.pnpm/cac@7.0.0/node_modules/cac/dist/index.js
182
+ function v(e) {
183
+ return e == null ? [] : Array.isArray(e) ? e : [e];
184
+ }
185
+ function y(e, t, n, r) {
186
+ var i, a = e[t], o = ~r.string.indexOf(t) ? n == null || n === !0 ? "" : String(n) : typeof n == "boolean" ? n : ~r.boolean.indexOf(t) ? n === "false" ? !1 : n === "true" || (e._.push((i = +n, i * 0 == 0 ? i : n)), !!n) : (i = +n, i * 0 == 0 ? i : n);
187
+ e[t] = a == null ? o : Array.isArray(a) ? a.concat(o) : [a, o];
188
+ }
189
+ function b(e, t) {
190
+ e ||= [], t ||= {};
191
+ var n, r, i, a, o, s = { _: [] }, c = 0, l = 0, u = 0, d = e.length;
192
+ let f = t.alias !== void 0, p = t.unknown !== void 0, m = t.default !== void 0;
193
+ if (t.alias = t.alias || {}, t.string = v(t.string), t.boolean = v(t.boolean), f) for (n in t.alias) for (r = t.alias[n] = v(t.alias[n]), c = 0; c < r.length; c++) (t.alias[r[c]] = r.concat(n)).splice(c, 1);
194
+ for (c = t.boolean.length; c-- > 0;) for (r = t.alias[t.boolean[c]] || [], l = r.length; l-- > 0;) t.boolean.push(r[l]);
195
+ for (c = t.string.length; c-- > 0;) for (r = t.alias[t.string[c]] || [], l = r.length; l-- > 0;) t.string.push(r[l]);
196
+ if (m) {
197
+ for (n in t.default) if (a = typeof t.default[n], r = t.alias[n] = t.alias[n] || [], t[a] !== void 0) for (t[a].push(n), c = 0; c < r.length; c++) t[a].push(r[c]);
198
+ }
199
+ let h = p ? Object.keys(t.alias) : [];
200
+ for (c = 0; c < d; c++) {
201
+ if (i = e[c], i === "--") {
202
+ s._ = s._.concat(e.slice(++c));
203
+ break;
204
+ }
205
+ for (l = 0; l < i.length && i.charCodeAt(l) === 45; l++);
206
+ if (l === 0) s._.push(i);
207
+ else if (i.substring(l, l + 3) === "no-") {
208
+ if (a = i.substring(l + 3), p && !~h.indexOf(a)) return t.unknown(i);
209
+ s[a] = !1;
210
+ } else {
211
+ for (u = l + 1; u < i.length && i.charCodeAt(u) !== 61; u++);
212
+ for (a = i.substring(l, u), o = i.substring(++u) || c + 1 === d || ("" + e[c + 1]).charCodeAt(0) === 45 || e[++c], r = l === 2 ? [a] : a, u = 0; u < r.length; u++) {
213
+ if (a = r[u], p && !~h.indexOf(a)) return t.unknown("-".repeat(l) + a);
214
+ y(s, a, u + 1 < r.length || o, t);
215
+ }
216
+ }
217
+ }
218
+ if (m) for (n in t.default) s[n] === void 0 && (s[n] = t.default[n]);
219
+ if (f) for (n in s) for (r = t.alias[n] || []; r.length > 0;) s[r.shift()] = s[n];
220
+ return s;
221
+ }
222
+ function x(e) {
223
+ return e.replace(/[<[].+/, "").trim();
224
+ }
225
+ function S(e) {
226
+ let t = /<([^>]+)>/g, n = /\[([^\]]+)\]/g, r = [], i = (e) => {
227
+ let t = !1, n = e[1];
228
+ return n.startsWith("...") && (n = n.slice(3), t = !0), {
229
+ required: e[0].startsWith("<"),
230
+ value: n,
231
+ variadic: t
232
+ };
233
+ }, a;
234
+ for (; a = t.exec(e);) r.push(i(a));
235
+ let o;
236
+ for (; o = n.exec(e);) r.push(i(o));
237
+ return r;
238
+ }
239
+ function C(e) {
240
+ let t = {
241
+ alias: {},
242
+ boolean: []
243
+ };
244
+ for (let [n, r] of e.entries()) r.names.length > 1 && (t.alias[r.names[0]] = r.names.slice(1)), r.isBoolean && (r.negated && e.some((e, t) => t !== n && e.names.some((e) => r.names.includes(e)) && typeof e.required == "boolean") || t.boolean.push(r.names[0]));
245
+ return t;
246
+ }
247
+ function w(e) {
248
+ return e.sort((e, t) => e.length > t.length ? -1 : 1)[0];
249
+ }
250
+ function T(e, t) {
251
+ return e.length >= t ? e : `${e}${" ".repeat(t - e.length)}`;
252
+ }
253
+ function E(e) {
254
+ return e.replaceAll(/([a-z])-([a-z])/g, (e, t, n) => t + n.toUpperCase());
255
+ }
256
+ function D(e, t, n) {
257
+ let r = e;
258
+ for (let e = 0; e < t.length; e++) {
259
+ let i = t[e];
260
+ if (e === t.length - 1) {
261
+ r[i] = n;
262
+ return;
263
+ }
264
+ if (r[i] == null) {
265
+ let n = +t[e + 1] > -1;
266
+ r[i] = n ? [] : {};
267
+ }
268
+ r = r[i];
269
+ }
270
+ }
271
+ function O(e, t) {
272
+ for (let n of Object.keys(t)) {
273
+ let r = t[n];
274
+ r.shouldTransform && (e[n] = [e[n]].flat(), typeof r.transformFunction == "function" && (e[n] = e[n].map(r.transformFunction)));
275
+ }
276
+ }
277
+ function k(e) {
278
+ let t = /([^\\/]+)$/.exec(e);
279
+ return t ? t[1] : "";
280
+ }
281
+ function A(e) {
282
+ return e.split(".").map((e, t) => t === 0 ? E(e) : e).join(".");
283
+ }
284
+ var j = class extends Error {
285
+ constructor(e) {
286
+ super(e), this.name = "CACError", typeof Error.captureStackTrace != "function" && (this.stack = Error(e).stack);
287
+ }
288
+ }, M = class {
289
+ rawName;
290
+ description;
291
+ name;
292
+ names;
293
+ isBoolean;
294
+ required;
295
+ config;
296
+ negated;
297
+ constructor(e, t, n) {
298
+ this.rawName = e, this.description = t, this.config = Object.assign({}, n), e = e.replaceAll(".*", ""), this.negated = !1, this.names = x(e).split(",").map((e) => {
299
+ let t = e.trim().replace(/^-{1,2}/, "");
300
+ return t.startsWith("no-") && (this.negated = !0, t = t.replace(/^no-/, "")), A(t);
301
+ }).sort((e, t) => e.length > t.length ? 1 : -1), this.name = this.names.at(-1), this.negated && this.config.default == null && (this.config.default = !0), e.includes("<") ? this.required = !0 : e.includes("[") ? this.required = !1 : this.isBoolean = !0;
302
+ }
303
+ }, N, P;
304
+ if (typeof process < "u") {
305
+ let e;
306
+ e = typeof Deno < "u" && typeof Deno.version?.deno == "string" ? "deno" : typeof Bun < "u" && typeof Bun.version == "string" ? "bun" : "node", P = `${process.platform}-${process.arch} ${e}-${process.version}`, N = process.argv;
307
+ } else P = typeof navigator > "u" ? "unknown" : `${navigator.platform} ${navigator.userAgent}`;
308
+ var F = class {
309
+ rawName;
310
+ description;
311
+ config;
312
+ cli;
313
+ options;
314
+ aliasNames;
315
+ name;
316
+ args;
317
+ commandAction;
318
+ usageText;
319
+ versionNumber;
320
+ examples;
321
+ helpCallback;
322
+ globalCommand;
323
+ constructor(e, t, n = {}, r) {
324
+ this.rawName = e, this.description = t, this.config = n, this.cli = r, this.options = [], this.aliasNames = [], this.name = x(e), this.args = S(e), this.examples = [];
325
+ }
326
+ usage(e) {
327
+ return this.usageText = e, this;
328
+ }
329
+ allowUnknownOptions() {
330
+ return this.config.allowUnknownOptions = !0, this;
331
+ }
332
+ ignoreOptionDefaultValue() {
333
+ return this.config.ignoreOptionDefaultValue = !0, this;
334
+ }
335
+ version(e, t = "-v, --version") {
336
+ return this.versionNumber = e, this.option(t, "Display version number"), this;
337
+ }
338
+ example(e) {
339
+ return this.examples.push(e), this;
340
+ }
341
+ option(e, t, n) {
342
+ let r = new M(e, t, n);
343
+ return this.options.push(r), this;
344
+ }
345
+ alias(e) {
346
+ return this.aliasNames.push(e), this;
347
+ }
348
+ action(e) {
349
+ return this.commandAction = e, this;
350
+ }
351
+ isMatched(e) {
352
+ return this.name === e || this.aliasNames.includes(e);
353
+ }
354
+ get isDefaultCommand() {
355
+ return this.name === "" || this.aliasNames.includes("!");
356
+ }
357
+ get isGlobalCommand() {
358
+ return this instanceof I;
359
+ }
360
+ hasOption(e) {
361
+ return e = e.split(".")[0], this.options.find((t) => t.names.includes(e));
362
+ }
363
+ outputHelp() {
364
+ let { name: e, commands: t } = this.cli, { versionNumber: n, options: r, helpCallback: i } = this.cli.globalCommand, a = [{ body: `${e}${n ? `/${n}` : ""}` }];
365
+ if (a.push({
366
+ title: "Usage",
367
+ body: ` $ ${e} ${this.usageText || this.rawName}`
368
+ }), (this.isGlobalCommand || this.isDefaultCommand) && t.length > 0) {
369
+ let n = w(t.map((e) => e.rawName));
370
+ a.push({
371
+ title: "Commands",
372
+ body: t.map((e) => ` ${T(e.rawName, n.length)} ${e.description}`).join("\n")
373
+ }, {
374
+ title: "For more info, run any command with the `--help` flag",
375
+ body: t.map((t) => ` $ ${e}${t.name === "" ? "" : ` ${t.name}`} --help`).join("\n")
376
+ });
377
+ }
378
+ let o = this.isGlobalCommand ? r : [...this.options, ...r || []];
379
+ if (!this.isGlobalCommand && !this.isDefaultCommand && (o = o.filter((e) => e.name !== "version")), o.length > 0) {
380
+ let e = w(o.map((e) => e.rawName));
381
+ a.push({
382
+ title: "Options",
383
+ body: o.map((t) => ` ${T(t.rawName, e.length)} ${t.description} ${t.config.default === void 0 ? "" : `(default: ${t.config.default})`}`).join("\n")
384
+ });
385
+ }
386
+ this.examples.length > 0 && a.push({
387
+ title: "Examples",
388
+ body: this.examples.map((t) => typeof t == "function" ? t(e) : t).join("\n")
389
+ }), i && (a = i(a) || a), console.info(a.map((e) => e.title ? `${e.title}:\n${e.body}` : e.body).join("\n\n"));
390
+ }
391
+ outputVersion() {
392
+ let { name: e } = this.cli, { versionNumber: t } = this.cli.globalCommand;
393
+ t && console.info(`${e}/${t} ${P}`);
394
+ }
395
+ checkRequiredArgs() {
396
+ let e = this.args.filter((e) => e.required).length;
397
+ if (this.cli.args.length < e) throw new j(`missing required args for command \`${this.rawName}\``);
398
+ }
399
+ checkUnknownOptions() {
400
+ let { options: e, globalCommand: t } = this.cli;
401
+ if (!this.config.allowUnknownOptions) {
402
+ for (let n of Object.keys(e)) if (n !== "--" && !this.hasOption(n) && !t.hasOption(n)) throw new j(`Unknown option \`${n.length > 1 ? `--${n}` : `-${n}`}\``);
403
+ }
404
+ }
405
+ checkOptionValue() {
406
+ let { options: e, globalCommand: t } = this.cli, n = [...t.options, ...this.options];
407
+ for (let t of n) {
408
+ let r = e[t.name.split(".")[0]];
409
+ if (t.required) {
410
+ let e = n.some((e) => e.negated && e.names.includes(t.name));
411
+ if (r === !0 || r === !1 && !e) throw new j(`option \`${t.rawName}\` value is missing`);
412
+ }
413
+ }
414
+ }
415
+ checkUnusedArgs() {
416
+ let e = this.args.some((e) => e.variadic) ? Infinity : this.args.length;
417
+ if (e < this.cli.args.length) throw new j(`Unused args: ${this.cli.args.slice(e).map((e) => `\`${e}\``).join(", ")}`);
418
+ }
419
+ }, I = class extends F {
420
+ constructor(e) {
421
+ super("@@global@@", "", {}, e);
422
+ }
423
+ }, L = class extends EventTarget {
424
+ name;
425
+ commands;
426
+ globalCommand;
427
+ matchedCommand;
428
+ matchedCommandName;
429
+ rawArgs;
430
+ args;
431
+ options;
432
+ showHelpOnExit;
433
+ showVersionOnExit;
434
+ constructor(e = "") {
435
+ super(), this.name = e, this.commands = [], this.rawArgs = [], this.args = [], this.options = {}, this.globalCommand = new I(this), this.globalCommand.usage("<command> [options]");
436
+ }
437
+ usage(e) {
438
+ return this.globalCommand.usage(e), this;
439
+ }
440
+ command(e, t, n) {
441
+ let r = new F(e, t || "", n, this);
442
+ return r.globalCommand = this.globalCommand, this.commands.push(r), r;
443
+ }
444
+ option(e, t, n) {
445
+ return this.globalCommand.option(e, t, n), this;
446
+ }
447
+ help(e) {
448
+ return this.globalCommand.option("-h, --help", "Display this message"), this.globalCommand.helpCallback = e, this.showHelpOnExit = !0, this;
449
+ }
450
+ version(e, t = "-v, --version") {
451
+ return this.globalCommand.version(e, t), this.showVersionOnExit = !0, this;
452
+ }
453
+ example(e) {
454
+ return this.globalCommand.example(e), this;
455
+ }
456
+ outputHelp() {
457
+ this.matchedCommand ? this.matchedCommand.outputHelp() : this.globalCommand.outputHelp();
458
+ }
459
+ outputVersion() {
460
+ this.globalCommand.outputVersion();
461
+ }
462
+ setParsedInfo({ args: e, options: t }, n, r) {
463
+ return this.args = e, this.options = t, n && (this.matchedCommand = n), r && (this.matchedCommandName = r), this;
464
+ }
465
+ unsetMatchedCommand() {
466
+ this.matchedCommand = void 0, this.matchedCommandName = void 0;
467
+ }
468
+ parse(e, { run: t = !0 } = {}) {
469
+ if (!e) {
470
+ if (!N) throw Error("No argv provided and runtime process argv is not available.");
471
+ e = N;
472
+ }
473
+ this.rawArgs = e, this.name ||= e[1] ? k(e[1]) : "cli";
474
+ let n = !0;
475
+ for (let t of this.commands) {
476
+ let r = this.mri(e.slice(2), t), i = r.args[0];
477
+ if (t.isMatched(i)) {
478
+ n = !1;
479
+ let e = {
480
+ ...r,
481
+ args: r.args.slice(1)
482
+ };
483
+ this.setParsedInfo(e, t, i), this.dispatchEvent(new CustomEvent(`command:${i}`, { detail: t }));
484
+ }
485
+ }
486
+ if (n) {
487
+ for (let t of this.commands) if (t.isDefaultCommand) {
488
+ n = !1;
489
+ let r = this.mri(e.slice(2), t);
490
+ this.setParsedInfo(r, t), this.dispatchEvent(new CustomEvent("command:!", { detail: t }));
491
+ }
492
+ }
493
+ if (n) {
494
+ let t = this.mri(e.slice(2));
495
+ this.setParsedInfo(t);
496
+ }
497
+ this.options.help && this.showHelpOnExit && (this.outputHelp(), t = !1, this.unsetMatchedCommand()), this.options.version && this.showVersionOnExit && this.matchedCommandName == null && (this.outputVersion(), t = !1, this.unsetMatchedCommand());
498
+ let r = {
499
+ args: this.args,
500
+ options: this.options
501
+ };
502
+ return t && this.runMatchedCommand(), !this.matchedCommand && this.args[0] && this.dispatchEvent(new CustomEvent("command:*", { detail: this.args[0] })), r;
503
+ }
504
+ mri(e, t) {
505
+ let n = [...this.globalCommand.options, ...t ? t.options : []], r = C(n), i = [], a = e.indexOf("--");
506
+ a !== -1 && (i = e.slice(a + 1), e = e.slice(0, a));
507
+ let o = b(e, r);
508
+ o = Object.keys(o).reduce((e, t) => ({
509
+ ...e,
510
+ [A(t)]: o[t]
511
+ }), { _: [] });
512
+ let s = o._, c = { "--": i }, l = t && t.config.ignoreOptionDefaultValue ? t.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue, u = Object.create(null);
513
+ for (let e of n) {
514
+ if (!l && e.config.default !== void 0) for (let t of e.names) c[t] = e.config.default;
515
+ Array.isArray(e.config.type) && u[e.name] === void 0 && (u[e.name] = Object.create(null), u[e.name].shouldTransform = !0, u[e.name].transformFunction = e.config.type[0]);
516
+ }
517
+ for (let e of Object.keys(o)) e !== "_" && (D(c, e.split("."), o[e]), O(c, u));
518
+ return {
519
+ args: s,
520
+ options: c
521
+ };
522
+ }
523
+ runMatchedCommand() {
524
+ let { args: e, options: t, matchedCommand: n } = this;
525
+ if (!n || !n.commandAction) return;
526
+ n.checkUnknownOptions(), n.checkOptionValue(), n.checkRequiredArgs(), n.checkUnusedArgs();
527
+ let r = [];
528
+ return n.args.forEach((t, n) => {
529
+ t.variadic ? r.push(e.slice(n)) : r.push(e[n]);
530
+ }), r.push(t), n.commandAction.apply(this, r);
531
+ }
532
+ }, R = (e = "") => new L(e), z = c.bold(c.cyan("[typerighter]"));
533
+ function B() {
534
+ let t = R("typerighter");
535
+ process.on("uncaughtException", (e) => {
536
+ V("runtime", e);
537
+ }), process.on("unhandledRejection", (e) => {
538
+ V("runtime", e instanceof Error ? e : Error(String(e)));
539
+ }), t.command("[root]", "Start dev server").alias("dev").option("--port <port>", "Port to listen on").option("--host", "Expose to network").action(async (e, t) => {
540
+ let n = await s({
541
+ root: H(e),
542
+ configFile: !1,
543
+ plugins: [i()],
544
+ server: {
545
+ port: t.port,
546
+ host: t.host
547
+ }
548
+ });
549
+ await n.listen(), n.printUrls();
550
+ }), t.command("build [root]", "Build for production").option("--outDir <dir>", "Output directory", { default: "dist" }).option("--base <path>", "Base public path", { default: "/" }).action(async (t, n) => {
551
+ let r = e(H(t));
552
+ try {
553
+ await g(r, {
554
+ outDir: n.outDir,
555
+ base: n.base
556
+ });
557
+ } finally {
558
+ r.dispose();
559
+ }
560
+ }), t.command("init [root]", "Scaffold a new project").action(async (e) => {
561
+ let { initialize: t } = await import("./init-CUo89E7j.js");
562
+ await t(H(e));
563
+ }), t.command("preview [root]", "Preview production build").option("--port <port>", "Port to listen on").action(async (e, t) => {
564
+ let { preview: n } = await import("vite");
565
+ (await n({
566
+ root: H(e),
567
+ preview: { port: t.port }
568
+ })).printUrls();
569
+ }), t.help(), t.version("0.3.0"), t.parse();
570
+ }
571
+ function V(e, t) {
572
+ let n = t instanceof Error ? t.message : String(t);
573
+ console.error(`\n${z} ${c.red(`${e} failed`)}\n`), console.error(c.red(n)), console.error(""), process.exit(1);
574
+ }
575
+ function H(e) {
576
+ return a.resolve(e ?? process.cwd());
577
+ }
578
+ //#endregion
579
+ export { g as n, B as t };
package/dist/cli.js CHANGED
@@ -1,2 +1,2 @@
1
- import { t as e } from "./cli-Dq8LM0iJ.js";
1
+ import { t as e } from "./cli-CoyGXgR1.js";
2
2
  export { e as cli };