typerighter 0.4.4 → 0.30.4

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