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