@tobi-or-not/docpress 0.10.3 → 0.11.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 +1 -0
- package/dist/cli.js +346 -301
- package/dist/cli.js.map +1 -1
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { Command as e, createCommand as t, createOption as n } from "commander";
|
|
2
2
|
import { appendFileSync as r, cpSync as i, existsSync as a, mkdirSync as o, readFileSync as s, readdirSync as c, renameSync as l, rmSync as u, statSync as d, writeFileSync as f } from "node:fs";
|
|
3
|
-
import { basename as p, dirname as m, join as
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import { z as
|
|
7
|
-
import { Octokit as
|
|
8
|
-
import { simpleGit as
|
|
9
|
-
import { build as
|
|
10
|
-
import { withMermaid as
|
|
11
|
-
import { readFile as
|
|
12
|
-
var
|
|
3
|
+
import { basename as p, dirname as m, join as ee, parse as h, relative as g, resolve as _ } from "node:path";
|
|
4
|
+
import v from "yaml";
|
|
5
|
+
import y from "picocolors";
|
|
6
|
+
import { z as b } from "zod";
|
|
7
|
+
import { Octokit as x } from "@octokit/rest";
|
|
8
|
+
import { simpleGit as te } from "simple-git";
|
|
9
|
+
import { build as ne } from "vitepress";
|
|
10
|
+
import { withMermaid as re } from "vitepress-plugin-mermaid";
|
|
11
|
+
import { readFile as ie } from "node:fs/promises";
|
|
12
|
+
var ae = {
|
|
13
13
|
name: "@tobi-or-not/docpress",
|
|
14
14
|
type: "module",
|
|
15
|
-
version: "0.
|
|
15
|
+
version: "0.11.0",
|
|
16
16
|
packageManager: "bun@1.3.14",
|
|
17
17
|
homepage: "https://this-is-tobi.com/docpress/introduction",
|
|
18
18
|
repository: {
|
|
@@ -31,7 +31,7 @@ var ie = {
|
|
|
31
31
|
"build:docker": "docker build --tag tobi-or-not/docpress --target prod .",
|
|
32
32
|
"build:types": "tsc",
|
|
33
33
|
"build:vite": "vite build",
|
|
34
|
-
dev: "bun ./dev/docpress.ts",
|
|
34
|
+
dev: "NODE_ENV=development bun ./dev/docpress.ts",
|
|
35
35
|
"dev:clean": "node -e \"require('node:fs').rmSync('./docpress',{recursive:true,force:true})\" && bun run dev",
|
|
36
36
|
format: "eslint . --fix",
|
|
37
37
|
lint: "eslint .",
|
|
@@ -78,12 +78,12 @@ var ie = {
|
|
|
78
78
|
access: "public",
|
|
79
79
|
tag: "latest"
|
|
80
80
|
}
|
|
81
|
-
},
|
|
82
|
-
red:
|
|
83
|
-
yellow:
|
|
84
|
-
white:
|
|
85
|
-
green:
|
|
86
|
-
blue:
|
|
81
|
+
}, S = _(process.cwd(), "docpress"), oe = _(process.cwd(), "docpress/docs"), C = _(process.cwd(), "docpress/docs/index.md"), se = _(process.cwd(), "docpress/docs/forks.md"), w = _(process.cwd(), "docpress/.vitepress/config.ts"), ce = _(process.cwd(), "docpress/.vitepress/theme"), le = _(process.cwd(), "docpress/.vitepress/theme/extras"), T = process.env.NODE_ENV === "development" ? _(import.meta.dirname, "../../public/templates/theme") : _(import.meta.dirname, "./templates/theme"), E = {
|
|
82
|
+
red: y.red,
|
|
83
|
+
yellow: y.yellow,
|
|
84
|
+
white: y.white,
|
|
85
|
+
green: y.green,
|
|
86
|
+
blue: y.blue
|
|
87
87
|
};
|
|
88
88
|
function ue() {
|
|
89
89
|
let e = Number(process.env.LOG_LEVEL);
|
|
@@ -114,14 +114,23 @@ var D = {
|
|
|
114
114
|
color: "blue",
|
|
115
115
|
level: 50
|
|
116
116
|
}
|
|
117
|
-
}
|
|
118
|
-
|
|
117
|
+
}, O = [
|
|
118
|
+
"error",
|
|
119
|
+
"warn",
|
|
120
|
+
"info",
|
|
121
|
+
"trace",
|
|
122
|
+
"debug"
|
|
123
|
+
];
|
|
124
|
+
function de(e) {
|
|
125
|
+
return D[e].level;
|
|
126
|
+
}
|
|
127
|
+
function k(e, t = "info", n) {
|
|
119
128
|
let r = n ? E[n](e) : E[D[t].color](e), i = t === "success" ? "info" : t;
|
|
120
129
|
ue() >= D[t].level && console[i](r);
|
|
121
130
|
}
|
|
122
131
|
//#endregion
|
|
123
132
|
//#region src/utils/regex.ts
|
|
124
|
-
var
|
|
133
|
+
var fe = /\[([^\]]+)\]\(\.\.\/([^)]+)\)/g, pe = /\[([^\]]+)\]\((?!\.?\/docs\/|docs\/|http|#)(\.\/)?([^/][^)]+)\)/g, me = /\[([^\]]+)\]\((\.?\/docs\/|docs\/)([^)]*)\)/g, he = /^\d{2}-/, ge = /^---\r?\n([\s\S]*?)\r?\n---\r?\n/, _e = /\[([^\]]+)\]\((?!https?:|\/|#|mailto:)([^)#]*\/)?([^)#/]+\.md)(#[^)]*)?\)/g;
|
|
125
134
|
//#endregion
|
|
126
135
|
//#region src/utils/functions.ts
|
|
127
136
|
async function A(e) {
|
|
@@ -131,25 +140,35 @@ async function A(e) {
|
|
|
131
140
|
redirect: "manual"
|
|
132
141
|
})).status;
|
|
133
142
|
} catch (t) {
|
|
134
|
-
return
|
|
143
|
+
return k(` Network error while checking '${e}': ${M(t)}`, "debug"), 500;
|
|
135
144
|
}
|
|
136
145
|
}
|
|
137
146
|
function j(e) {
|
|
138
147
|
return (e.split(/[/\\]/).pop() ?? "").replace(/[^\w.-]/g, "_").replace(/^\.+/, "") || "_";
|
|
139
148
|
}
|
|
140
|
-
function
|
|
141
|
-
return !
|
|
149
|
+
function ve(e) {
|
|
150
|
+
return !V(e) || !("token" in e) ? e : {
|
|
142
151
|
...e,
|
|
143
152
|
token: e.token ? "***" : e.token
|
|
144
153
|
};
|
|
145
154
|
}
|
|
146
|
-
function
|
|
155
|
+
function M(e) {
|
|
156
|
+
return e instanceof Error ? e.message : String(e);
|
|
157
|
+
}
|
|
158
|
+
function N(e) {
|
|
159
|
+
if (e < 1e3) return `${Math.round(e)}ms`;
|
|
160
|
+
let t = e / 1e3;
|
|
161
|
+
if (t < 60) return `${t.toFixed(1)}s`;
|
|
162
|
+
let n = Math.floor(t / 60), r = Math.round(t % 60);
|
|
163
|
+
return `${n}m ${String(r).padStart(2, "0")}s`;
|
|
164
|
+
}
|
|
165
|
+
function P(e, t) {
|
|
147
166
|
let n = "";
|
|
148
|
-
return t?.removeDot && (n = e.startsWith(".") ? e.slice(1) : e, n = n.replaceAll(".", "-")), t?.removeIdx && (n = (n || e).replace(
|
|
167
|
+
return t?.removeDot && (n = e.startsWith(".") ? e.slice(1) : e, n = n.replaceAll(".", "-")), t?.removeIdx && (n = (n || e).replace(he, "")), t?.removeExt && (n = (n || e).split(".")[0]), t?.replaceDash && (n = (n || e).replaceAll("-", " ")), t?.mode === "capitalize" ? n = (n || e).slice(0, 1).toUpperCase() + (n || e).slice(1).toLowerCase() : t?.mode === "lowercase" ? n = (n || e).toLowerCase() : t?.mode === "uppercase" && (n = (n || e).toUpperCase()), n || e;
|
|
149
168
|
}
|
|
150
|
-
function
|
|
169
|
+
function F(e, { clean: t } = { clean: !1 }) {
|
|
151
170
|
try {
|
|
152
|
-
if (t && a(e)) for (let t of c(e)) u(
|
|
171
|
+
if (t && a(e)) for (let t of c(e)) u(_(e, t), {
|
|
153
172
|
recursive: !0,
|
|
154
173
|
force: !0
|
|
155
174
|
});
|
|
@@ -158,53 +177,53 @@ function P(e, { clean: t } = { clean: !1 }) {
|
|
|
158
177
|
throw Error(`Unable to create directory '${e}': ${t instanceof Error ? t.message : String(t)}`);
|
|
159
178
|
}
|
|
160
179
|
}
|
|
161
|
-
function
|
|
180
|
+
function ye(e) {
|
|
162
181
|
try {
|
|
163
182
|
return d(e).isDirectory();
|
|
164
183
|
} catch {
|
|
165
184
|
return !1;
|
|
166
185
|
}
|
|
167
186
|
}
|
|
168
|
-
function
|
|
187
|
+
function I(e) {
|
|
169
188
|
try {
|
|
170
189
|
return d(e).isFile();
|
|
171
190
|
} catch {
|
|
172
191
|
return !1;
|
|
173
192
|
}
|
|
174
193
|
}
|
|
175
|
-
function I(e) {
|
|
176
|
-
return (Array.isArray(e) ? e : [e]).flatMap((e) => F(e) ? [e] : ge(e) ? c(e).filter((e) => e !== ".git").sort().flatMap((t) => I(h(e, t))) : []);
|
|
177
|
-
}
|
|
178
194
|
function L(e) {
|
|
179
|
-
return
|
|
195
|
+
return (Array.isArray(e) ? e : [e]).flatMap((e) => I(e) ? [e] : ye(e) ? c(e).filter((e) => e !== ".git").sort().flatMap((t) => L(ee(e, t))) : []);
|
|
180
196
|
}
|
|
181
|
-
function
|
|
197
|
+
function R(e) {
|
|
198
|
+
return L(e).filter((e) => p(e).endsWith(".md"));
|
|
199
|
+
}
|
|
200
|
+
function z(e) {
|
|
182
201
|
return e.reduce((e, t, n, r) => n ? n === r.length - 1 ? `${e} or "${t}"` : `${e}, "${t}"` : `"${t}"`, "");
|
|
183
202
|
}
|
|
184
|
-
function
|
|
185
|
-
return JSON.parse(s(`${
|
|
203
|
+
function be(e) {
|
|
204
|
+
return JSON.parse(s(`${S}/user-${j(e)}.json`).toString());
|
|
186
205
|
}
|
|
187
|
-
function
|
|
188
|
-
return JSON.parse(s(`${
|
|
206
|
+
function xe(e) {
|
|
207
|
+
return JSON.parse(s(`${S}/repos-${j(e)}.json`).toString());
|
|
189
208
|
}
|
|
190
|
-
var
|
|
209
|
+
var Se = /* @__PURE__ */ new Set([
|
|
191
210
|
"__proto__",
|
|
192
211
|
"constructor",
|
|
193
212
|
"prototype"
|
|
194
213
|
]);
|
|
195
|
-
function
|
|
214
|
+
function B(...e) {
|
|
196
215
|
return e.reduce((e, t) => (t === null || Object.keys(t).forEach((n) => {
|
|
197
|
-
if (
|
|
216
|
+
if (Se.has(n)) return;
|
|
198
217
|
let r = e ? e[n] : null, i = t[n];
|
|
199
|
-
|
|
218
|
+
V(r) && V(i) ? e[n] = B(r, i) : V(i) ? e[n] = B({}, i) : e[n] = i;
|
|
200
219
|
}), e), {});
|
|
201
220
|
}
|
|
202
|
-
function
|
|
221
|
+
function V(e) {
|
|
203
222
|
return e && typeof e == "object" && !Array.isArray(e);
|
|
204
223
|
}
|
|
205
|
-
function
|
|
224
|
+
function H(e) {
|
|
206
225
|
if (!e) return {};
|
|
207
|
-
let t =
|
|
226
|
+
let t = _(process.cwd(), e), n;
|
|
208
227
|
try {
|
|
209
228
|
n = s(t, "utf8");
|
|
210
229
|
} catch {
|
|
@@ -216,61 +235,63 @@ function B(e) {
|
|
|
216
235
|
throw Error(`Invalid JSON in config file '${e}'.`);
|
|
217
236
|
}
|
|
218
237
|
}
|
|
219
|
-
function
|
|
238
|
+
function U(e) {
|
|
220
239
|
return e.split(",");
|
|
221
240
|
}
|
|
222
|
-
function
|
|
223
|
-
f(e, s(e, "utf8").replace(
|
|
241
|
+
function Ce(e, t) {
|
|
242
|
+
f(e, s(e, "utf8").replace(fe, (e, n, r) => `[${n}](${t}/${r})`), "utf8");
|
|
224
243
|
}
|
|
225
|
-
function
|
|
226
|
-
let n = s(e, "utf8"), r = n.match(
|
|
244
|
+
function we(e, t) {
|
|
245
|
+
let n = s(e, "utf8"), r = n.match(ge);
|
|
227
246
|
if (r) {
|
|
228
|
-
let i =
|
|
229
|
-
i.lastUpdated = t, f(e, n.replace(
|
|
247
|
+
let i = v.parse(r[1]) ?? {};
|
|
248
|
+
i.lastUpdated = t, f(e, n.replace(ge, `---\n${v.stringify(i)}---\n`), "utf8");
|
|
230
249
|
} else f(e, `---\nlastUpdated: ${t}\n---\n\n${n}`, "utf8");
|
|
231
250
|
}
|
|
232
|
-
function
|
|
233
|
-
f(e, s(e, "utf8").replace(
|
|
234
|
-
let a =
|
|
251
|
+
function Te(e) {
|
|
252
|
+
f(e, s(e, "utf8").replace(_e, (e, t, n, r, i) => {
|
|
253
|
+
let a = P(r, {
|
|
235
254
|
mode: "lowercase",
|
|
236
255
|
removeIdx: !0
|
|
237
256
|
});
|
|
238
257
|
return a === "readme.md" && (a = "introduction.md"), `[${t}](${n ?? ""}${a}${i ?? ""})`;
|
|
239
258
|
}), "utf8");
|
|
240
259
|
}
|
|
241
|
-
function
|
|
242
|
-
f(e, s(e, "utf8").replace(
|
|
260
|
+
function Ee(e, t) {
|
|
261
|
+
f(e, s(e, "utf8").replace(pe, (e, n, r, i) => `[${n}](${t}/${i})`).replace(me, (e, t, n, r) => `[${t}](${r})`), "utf8");
|
|
243
262
|
}
|
|
244
263
|
//#endregion
|
|
245
264
|
//#region src/schemas/global.ts
|
|
246
|
-
var
|
|
247
|
-
usernames:
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
265
|
+
var W = ["github", "gitlab"], De = /^\w[\w./-]*$/, Oe = "Branch name must start with a letter, digit or underscore and only contain letters, digits, \".\", \"-\", \"_\" or \"/\".", G = b.object({
|
|
266
|
+
usernames: b.string().array().describe("List of comma separated Git provider usernames used to collect data."),
|
|
267
|
+
logLevel: b.enum(O).optional().describe(`Verbosity of the CLI output. Values should be ${z(O)}. Defaults to "info", or to the LOG_LEVEL environment variable when set.`),
|
|
268
|
+
branch: b.string().regex(De, Oe).optional().describe("Branch used to collect Git provider data. Defaults to each repository's own default branch when not set."),
|
|
269
|
+
gitProvider: b.enum(W).default("github").describe(`Git provider used to retrieve data. Values should be ${z(W)}.`),
|
|
270
|
+
reposFilter: b.string().array().describe("List of comma separated repositories to retrieve from Git provider. Default to all user's public repositories."),
|
|
271
|
+
extraHeaderPages: b.string().array().describe("List of comma separated additional files or directories to process Vitepress header pages."),
|
|
272
|
+
extraPublicContent: b.string().array().describe("List of comma separated additional files or directories to process Vitepress public folder."),
|
|
273
|
+
extraTheme: b.string().array().describe("List of comma separated additional files or directories to use as Vitepress theme."),
|
|
274
|
+
forks: b.boolean().default(!1).describe("Whether or not to create the dedicated fork page that aggregate external contributions."),
|
|
275
|
+
lastUpdated: b.boolean().default(!1).describe("Whether or not to inject each page's last Git commit date as Vitepress \"lastUpdated\" frontmatter."),
|
|
276
|
+
vitepressConfig: b.any().optional().describe("Path to the vitepress configuration file."),
|
|
277
|
+
websiteTitle: b.string().describe("Website title."),
|
|
278
|
+
websiteTagline: b.string().describe("Website tagline.")
|
|
259
279
|
}), K = G.partial().extend({
|
|
260
|
-
branch:
|
|
261
|
-
gitProvider:
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
280
|
+
branch: b.string().regex(De, Oe).optional().describe(G.shape.branch.description || ""),
|
|
281
|
+
gitProvider: b.enum(W).optional().describe(G.shape.gitProvider.description || ""),
|
|
282
|
+
logLevel: b.enum(O).optional().describe(G.shape.logLevel.description || ""),
|
|
283
|
+
forks: b.boolean().optional().describe(G.shape.forks.description || ""),
|
|
284
|
+
lastUpdated: b.boolean().optional().describe(G.shape.lastUpdated.description || ""),
|
|
285
|
+
config: b.string().optional().describe("Path to the docpress configuration file."),
|
|
286
|
+
token: b.string().optional().describe("Git provider token used to collect data."),
|
|
287
|
+
usernames: b.string().transform(U).optional().describe(G.shape.usernames.description || ""),
|
|
288
|
+
reposFilter: b.string().transform(U).optional().describe(G.shape.reposFilter.description || ""),
|
|
289
|
+
extraHeaderPages: b.string().transform(U).optional().describe(G.shape.extraHeaderPages.description || ""),
|
|
290
|
+
extraPublicContent: b.string().transform(U).optional().describe(G.shape.extraPublicContent.description || ""),
|
|
291
|
+
extraTheme: b.string().transform(U).optional().describe(G.shape.extraTheme.description || ""),
|
|
292
|
+
vitepressConfig: b.string().optional().describe(G.shape.vitepressConfig.description || "")
|
|
272
293
|
});
|
|
273
|
-
function
|
|
294
|
+
function ke(e) {
|
|
274
295
|
if (!e) return {};
|
|
275
296
|
let t = { ...e };
|
|
276
297
|
for (let e of [
|
|
@@ -282,25 +303,26 @@ function Te(e) {
|
|
|
282
303
|
]) typeof t[e] == "string" && (t[e] = [t[e]]);
|
|
283
304
|
return t;
|
|
284
305
|
}
|
|
285
|
-
function
|
|
306
|
+
function Ae(e) {
|
|
286
307
|
let t = G.partial().safeParse(e);
|
|
287
|
-
if (!t.success) throw Error(
|
|
308
|
+
if (!t.success) throw Error(b.prettifyError(t.error));
|
|
288
309
|
return t.data;
|
|
289
310
|
}
|
|
290
|
-
function
|
|
311
|
+
function je(e) {
|
|
291
312
|
if (!e.usernames?.length) throw Error("The usernames field is required");
|
|
292
313
|
return e;
|
|
293
314
|
}
|
|
294
|
-
function
|
|
315
|
+
function Me(e, t) {
|
|
295
316
|
if (e) return e;
|
|
296
317
|
let n = t === "gitlab" ? process.env.GITLAB_TOKEN : process.env.GITHUB_TOKEN;
|
|
297
318
|
return process.env.DOCPRESS_TOKEN ?? n;
|
|
298
319
|
}
|
|
299
|
-
|
|
320
|
+
function Ne(e) {
|
|
321
|
+
e && (process.env.LOG_LEVEL = String(de(e)));
|
|
322
|
+
}
|
|
323
|
+
var Pe = K.partial().transform((e, t) => {
|
|
300
324
|
try {
|
|
301
|
-
let { config: t, vitepressConfig: n, token: r, ...i } = e
|
|
302
|
-
O(`Debug: Schema transform input: ${JSON.stringify(M(e))}`, "debug");
|
|
303
|
-
let a = Ee(Te(B(t))), o = {
|
|
325
|
+
let { config: t, vitepressConfig: n, token: r, ...i } = e, a = Ae(ke(H(t))), o = {
|
|
304
326
|
gitProvider: "github",
|
|
305
327
|
forks: !1,
|
|
306
328
|
lastUpdated: !1,
|
|
@@ -308,26 +330,26 @@ var ke = K.partial().transform((e, t) => {
|
|
|
308
330
|
...i,
|
|
309
331
|
...n ? { vitepressConfig: {
|
|
310
332
|
...a.vitepressConfig || {},
|
|
311
|
-
...
|
|
333
|
+
...H(n) || {}
|
|
312
334
|
} } : {}
|
|
313
335
|
};
|
|
314
|
-
return
|
|
336
|
+
return Ne(o.logLevel), je({
|
|
315
337
|
...o,
|
|
316
|
-
token:
|
|
338
|
+
token: Me(r, o.gitProvider)
|
|
317
339
|
});
|
|
318
340
|
} catch (e) {
|
|
319
341
|
return t.addIssue({
|
|
320
342
|
code: "custom",
|
|
321
343
|
message: e instanceof Error ? e.message : JSON.stringify(e, null, 2)
|
|
322
|
-
}),
|
|
344
|
+
}), b.NEVER;
|
|
323
345
|
}
|
|
324
346
|
});
|
|
325
347
|
//#endregion
|
|
326
348
|
//#region src/utils/commands.ts
|
|
327
349
|
function q(e, t) {
|
|
328
|
-
|
|
329
|
-
let n =
|
|
330
|
-
return n.success || (
|
|
350
|
+
k("Initializing Docpress...", "info", "blue"), k("\n\n-> Checking for required environment settings and configurations.", "info"), k(` Debug info - cmd: ${e}`, "debug");
|
|
351
|
+
let n = Pe.safeParse(t);
|
|
352
|
+
return n.success || (k(` An error occurred while checking configuration.\n ${b.prettifyError(n.error)}`, "error"), process.exit(1)), k(` Debug info - resolved options: ${JSON.stringify(ve(n.data))}`, "debug"), k(" Setup complete! Ready to process your documentation.", "info"), n.data;
|
|
331
353
|
}
|
|
332
354
|
function J(e, t) {
|
|
333
355
|
return Object.fromEntries(Object.entries(t).filter(([t]) => e.getOptionValueSource(t) !== "default"));
|
|
@@ -338,27 +360,27 @@ function Y(e, t) {
|
|
|
338
360
|
}
|
|
339
361
|
//#endregion
|
|
340
362
|
//#region src/lib/git.ts
|
|
341
|
-
var
|
|
363
|
+
var Fe = {
|
|
342
364
|
debug: () => {},
|
|
343
365
|
info: () => {},
|
|
344
366
|
warn: (e) => {
|
|
345
|
-
e.includes("404") ||
|
|
367
|
+
e.includes("404") || k(e, "warn");
|
|
346
368
|
},
|
|
347
369
|
error: (e) => {
|
|
348
|
-
e.includes("404") ||
|
|
370
|
+
e.includes("404") || k(e, "error");
|
|
349
371
|
}
|
|
350
372
|
};
|
|
351
|
-
async function
|
|
352
|
-
|
|
353
|
-
let r = new
|
|
373
|
+
async function Ie({ username: e, token: t, branch: n }) {
|
|
374
|
+
k(` Get infos for username '${e}'.`, "info");
|
|
375
|
+
let r = new x({
|
|
354
376
|
auth: t,
|
|
355
|
-
log:
|
|
377
|
+
log: Fe
|
|
356
378
|
});
|
|
357
|
-
|
|
379
|
+
k(" Get user infos.", "debug");
|
|
358
380
|
let { data: i } = await r.rest.users.getByUsername({ username: e }).catch((t) => {
|
|
359
381
|
throw t.status === 404 ? /* @__PURE__ */ Error(`No GitHub user found for '${e}'.`) : t;
|
|
360
382
|
});
|
|
361
|
-
return
|
|
383
|
+
return k(" Get repositories infos.", "debug"), {
|
|
362
384
|
user: i,
|
|
363
385
|
repos: await r.paginate(r.rest.repos.listForUser, {
|
|
364
386
|
username: e,
|
|
@@ -368,11 +390,11 @@ async function Ae({ username: e, token: t, branch: n }) {
|
|
|
368
390
|
branch: n
|
|
369
391
|
};
|
|
370
392
|
}
|
|
371
|
-
async function
|
|
372
|
-
|
|
373
|
-
let n = new
|
|
393
|
+
async function Le({ repository: e, token: t }) {
|
|
394
|
+
k(` Get contributors infos for repository '${e.name}'.`, "info");
|
|
395
|
+
let n = new x({
|
|
374
396
|
auth: t,
|
|
375
|
-
log:
|
|
397
|
+
log: Fe
|
|
376
398
|
}), r;
|
|
377
399
|
try {
|
|
378
400
|
r = (await n.rest.repos.get({
|
|
@@ -380,7 +402,7 @@ async function je({ repository: e, token: t }) {
|
|
|
380
402
|
repo: e.name
|
|
381
403
|
})).data;
|
|
382
404
|
} catch (t) {
|
|
383
|
-
return
|
|
405
|
+
return k(` Failed to get repository infos for '${e.name}'. Error : ${M(t)}`, "warn"), {
|
|
384
406
|
source: void 0,
|
|
385
407
|
contributors: []
|
|
386
408
|
};
|
|
@@ -397,7 +419,7 @@ async function je({ repository: e, token: t }) {
|
|
|
397
419
|
per_page: 100
|
|
398
420
|
})) i.push(...e);
|
|
399
421
|
} catch (t) {
|
|
400
|
-
return
|
|
422
|
+
return k(` Failed to get contributors infos for repository '${e.name}'. Error : ${M(t)}`, "warn"), {
|
|
401
423
|
source: r.source,
|
|
402
424
|
contributors: []
|
|
403
425
|
};
|
|
@@ -407,7 +429,7 @@ async function je({ repository: e, token: t }) {
|
|
|
407
429
|
contributors: i
|
|
408
430
|
};
|
|
409
431
|
}
|
|
410
|
-
function
|
|
432
|
+
function Re(e) {
|
|
411
433
|
let t = /* @__PURE__ */ new Map(), n = null;
|
|
412
434
|
for (let r of e.split("\n")) {
|
|
413
435
|
let e = r.trim();
|
|
@@ -421,12 +443,12 @@ function Me(e) {
|
|
|
421
443
|
}
|
|
422
444
|
return t;
|
|
423
445
|
}
|
|
424
|
-
async function
|
|
425
|
-
let r =
|
|
446
|
+
async function ze(e, t, n) {
|
|
447
|
+
let r = R([t]);
|
|
426
448
|
if (!r.length) return;
|
|
427
449
|
let i;
|
|
428
450
|
try {
|
|
429
|
-
i =
|
|
451
|
+
i = Re(await e.raw([
|
|
430
452
|
"-c",
|
|
431
453
|
"core.quotePath=false",
|
|
432
454
|
"log",
|
|
@@ -434,19 +456,19 @@ async function Ne(e, t, n) {
|
|
|
434
456
|
"--name-only"
|
|
435
457
|
]));
|
|
436
458
|
} catch (e) {
|
|
437
|
-
|
|
459
|
+
k(` Unable to read commit history for repository '${n}'. Error : ${M(e)}`, "warn");
|
|
438
460
|
return;
|
|
439
461
|
}
|
|
440
462
|
for (let e of r) {
|
|
441
|
-
let n = i.get(
|
|
442
|
-
n &&
|
|
463
|
+
let n = i.get(g(t, e));
|
|
464
|
+
n && we(e, n);
|
|
443
465
|
}
|
|
444
466
|
}
|
|
445
|
-
async function
|
|
446
|
-
if (t.startsWith("-") || a.startsWith("-")) return
|
|
447
|
-
|
|
467
|
+
async function Be(e, t, n, a, o, s) {
|
|
468
|
+
if (t.startsWith("-") || a.startsWith("-")) return k(` Refusing to clone '${e}': unsafe repository URL or branch name.`, "error"), !1;
|
|
469
|
+
F(n, { clean: !0 });
|
|
448
470
|
try {
|
|
449
|
-
let c =
|
|
471
|
+
let c = te({
|
|
450
472
|
baseDir: n,
|
|
451
473
|
config: [
|
|
452
474
|
"maintenance.auto=false",
|
|
@@ -455,32 +477,32 @@ async function Pe(e, t, n, a, o, s) {
|
|
|
455
477
|
]
|
|
456
478
|
});
|
|
457
479
|
await c.init().addConfig("core.sparseCheckout", "true", !0, "local").addRemote("origin", t);
|
|
458
|
-
for (let t of o)
|
|
459
|
-
return
|
|
480
|
+
for (let t of o) k(` Add '${t}' to '${e}' sparse-checkout file.`, "debug"), r(_(n, ".git/info/sparse-checkout"), `${t}\n`, "utf8");
|
|
481
|
+
return k(` Clone repository '${e}'.`, "info"), await c.pull("origin", a), s && await ze(c, n, e), o.some((e) => e.includes("docs")) && (i(_(n, "docs"), n, { recursive: !0 }), u(_(n, "docs"), { recursive: !0 })), u(_(n, ".git"), { recursive: !0 }), !0;
|
|
460
482
|
} catch (t) {
|
|
461
|
-
return
|
|
483
|
+
return k(` Error when cloning repository '${e}': ${M(t)}.`, "error"), !1;
|
|
462
484
|
}
|
|
463
485
|
}
|
|
464
486
|
//#endregion
|
|
465
487
|
//#region src/lib/gitlab.ts
|
|
466
|
-
var
|
|
467
|
-
async function
|
|
468
|
-
let n = await fetch(`${
|
|
488
|
+
var Ve = "https://gitlab.com/api/v4";
|
|
489
|
+
async function X(e, t) {
|
|
490
|
+
let n = await fetch(`${Ve}${e}`, { headers: t ? { "PRIVATE-TOKEN": t } : {} });
|
|
469
491
|
if (!n.ok) throw Error(`GitLab API request failed for '${e}' (status: ${n.status}).`);
|
|
470
492
|
return {
|
|
471
493
|
data: await n.json(),
|
|
472
494
|
headers: n.headers
|
|
473
495
|
};
|
|
474
496
|
}
|
|
475
|
-
async function
|
|
497
|
+
async function He(e, t) {
|
|
476
498
|
let n = e.includes("?") ? "&" : "?", r = [], i = "1";
|
|
477
499
|
for (; i;) {
|
|
478
|
-
let a = await
|
|
500
|
+
let a = await X(`${e}${n}per_page=100&page=${i}`, t);
|
|
479
501
|
r.push(...a.data), i = a.headers.get("x-next-page") || null;
|
|
480
502
|
}
|
|
481
503
|
return r;
|
|
482
504
|
}
|
|
483
|
-
function
|
|
505
|
+
function Ue(e) {
|
|
484
506
|
return {
|
|
485
507
|
login: e.username ?? e.path,
|
|
486
508
|
name: e.name,
|
|
@@ -489,7 +511,7 @@ function Ie(e) {
|
|
|
489
511
|
html_url: e.web_url
|
|
490
512
|
};
|
|
491
513
|
}
|
|
492
|
-
function
|
|
514
|
+
function We(e, t) {
|
|
493
515
|
return {
|
|
494
516
|
name: e.path,
|
|
495
517
|
owner: { login: t },
|
|
@@ -503,32 +525,32 @@ function Le(e, t) {
|
|
|
503
525
|
stargazers_count: e.star_count
|
|
504
526
|
};
|
|
505
527
|
}
|
|
506
|
-
async function
|
|
507
|
-
|
|
508
|
-
let { data: r } = await
|
|
528
|
+
async function Ge({ username: e, token: t, branch: n }) {
|
|
529
|
+
k(` Get infos for username '${e}'.`, "info");
|
|
530
|
+
let { data: r } = await X(`/users?username=${encodeURIComponent(e)}`, t);
|
|
509
531
|
if (r.length) {
|
|
510
532
|
let i = r[0];
|
|
511
|
-
t && (i = await
|
|
512
|
-
let a = await
|
|
533
|
+
t && (i = await X(`/users/${r[0].id}`, t).then((e) => e.data).catch(() => r[0])), k(" Get repositories infos.", "debug");
|
|
534
|
+
let a = await He(`/users/${r[0].id}/projects`, t);
|
|
513
535
|
return {
|
|
514
|
-
user:
|
|
515
|
-
repos: a.map((t) =>
|
|
536
|
+
user: Ue(i),
|
|
537
|
+
repos: a.map((t) => We(t, i.username ?? e)),
|
|
516
538
|
branch: n
|
|
517
539
|
};
|
|
518
540
|
}
|
|
519
|
-
|
|
520
|
-
let i = await
|
|
541
|
+
k(` No GitLab user '${e}' found, trying groups.`, "debug");
|
|
542
|
+
let i = await X(`/groups/${encodeURIComponent(e)}?with_projects=false`, t).then((e) => e.data).catch(() => {
|
|
521
543
|
throw Error(`No GitLab user or group found for '${e}'.`);
|
|
522
|
-
}), a = await
|
|
544
|
+
}), a = await He(`/groups/${encodeURIComponent(e)}/projects`, t);
|
|
523
545
|
return {
|
|
524
|
-
user:
|
|
525
|
-
repos: a.map((t) =>
|
|
546
|
+
user: Ue(i),
|
|
547
|
+
repos: a.map((t) => We(t, i.path ?? e)),
|
|
526
548
|
branch: n
|
|
527
549
|
};
|
|
528
550
|
}
|
|
529
551
|
//#endregion
|
|
530
552
|
//#region src/lib/fetch.ts
|
|
531
|
-
function
|
|
553
|
+
function Ke(e, t, n) {
|
|
532
554
|
if (n === "gitlab") {
|
|
533
555
|
let n = e.html_url ?? `https://gitlab.com/${e.owner.login}/${e.name}`;
|
|
534
556
|
return {
|
|
@@ -544,7 +566,7 @@ function ze(e, t, n) {
|
|
|
544
566
|
raw_url: `https://raw.githubusercontent.com/${e.owner.login}/${e.name}/${t}`
|
|
545
567
|
};
|
|
546
568
|
}
|
|
547
|
-
async function
|
|
569
|
+
async function qe(e) {
|
|
548
570
|
let [t, n, r] = await Promise.all([
|
|
549
571
|
A(`${e.blob_url}/README.md`),
|
|
550
572
|
A(`${e.tree_url}/docs`),
|
|
@@ -556,19 +578,19 @@ async function Be(e) {
|
|
|
556
578
|
docsReadmeStatus: r
|
|
557
579
|
};
|
|
558
580
|
}
|
|
559
|
-
async function
|
|
560
|
-
let { user: s, repos: c, branch: l } = await (r === "gitlab" ?
|
|
581
|
+
async function Je({ username: e, branch: t, reposFilter: n, gitProvider: r, token: i, lastUpdated: a, multiUser: o }) {
|
|
582
|
+
let { user: s, repos: c, branch: l } = await (r === "gitlab" ? Ge : Ie)({
|
|
561
583
|
username: e,
|
|
562
584
|
token: i,
|
|
563
585
|
branch: t
|
|
564
|
-
}), { repos: u } = await
|
|
565
|
-
await
|
|
586
|
+
}), { repos: u } = await Ze(s, c, l, n, r, o ? `${j(e)}/` : "");
|
|
587
|
+
await Qe(u, n, a);
|
|
566
588
|
}
|
|
567
|
-
async function
|
|
589
|
+
async function Ye(e, t, n, r, i = "") {
|
|
568
590
|
let a = [];
|
|
569
591
|
return await Promise.all(e.map(async (e) => {
|
|
570
|
-
let o = t ?? e.default_branch ?? "main", s =
|
|
571
|
-
!e.fork && !e.private && !c && (u = await
|
|
592
|
+
let o = t ?? e.default_branch ?? "main", s = _(oe, `${i}${P(j(e.name), { removeDot: !0 })}`), c = $e(e, n), l = Ke(e, o, r), u = [];
|
|
593
|
+
!e.fork && !e.private && !c && (u = await Xe(e, o, r, l)), a.push({
|
|
572
594
|
...e,
|
|
573
595
|
docpress: {
|
|
574
596
|
filtered: c,
|
|
@@ -582,76 +604,85 @@ async function He(e, t, n, r, i = "") {
|
|
|
582
604
|
});
|
|
583
605
|
})), a;
|
|
584
606
|
}
|
|
585
|
-
async function
|
|
586
|
-
let i = await
|
|
607
|
+
async function Xe(e, t, n, r) {
|
|
608
|
+
let i = await qe(r ?? Ke(e, t, n)), a = [];
|
|
587
609
|
return Object.values(i).every((e) => e !== 200) || !e.size ? [] : (i.docsFolderStatus === 200 && a.push("docs/*"), (i.docsFolderStatus !== 200 || i.docsReadmeStatus !== 200) && a.push("README.md", "!*/**/README.md"), a);
|
|
588
610
|
}
|
|
589
|
-
async function
|
|
590
|
-
f(`${
|
|
591
|
-
let o = await
|
|
592
|
-
return f(`${
|
|
611
|
+
async function Ze(e, t, n, r, i, a = "") {
|
|
612
|
+
f(`${S}/user-${j(e.login)}.json`, JSON.stringify(e, null, 2));
|
|
613
|
+
let o = await Ye(t, n, r, i, a);
|
|
614
|
+
return f(`${S}/repos-${j(e.login)}.json`, JSON.stringify(o, null, 2)), {
|
|
593
615
|
user: e,
|
|
594
616
|
repos: o
|
|
595
617
|
};
|
|
596
618
|
}
|
|
597
|
-
async function
|
|
619
|
+
async function Qe(e, t, n) {
|
|
598
620
|
if (!e) {
|
|
599
|
-
|
|
621
|
+
k(" No repositories to process.", "warn");
|
|
600
622
|
return;
|
|
601
623
|
}
|
|
602
|
-
let r =
|
|
603
|
-
let t = await
|
|
624
|
+
let r = await Promise.all(e.filter((e) => !$e(e, t)).map(async (e) => {
|
|
625
|
+
let t = await Be(e.name, e.clone_url, e.docpress.projectPath, e.docpress.branch, e.docpress.includes, n);
|
|
604
626
|
return {
|
|
605
627
|
name: e.name,
|
|
606
628
|
success: t
|
|
607
629
|
};
|
|
608
|
-
}))
|
|
609
|
-
|
|
630
|
+
}));
|
|
631
|
+
if (!r.length) {
|
|
632
|
+
k(" No repository matched the current filters.", "warn");
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
let i = r.filter(({ success: e }) => !e).map(({ name: e }) => e), a = r.length - i.length;
|
|
636
|
+
i.length ? k(` Cloned ${a}/${r.length} repository(ies), ${i.length} failed: ${i.join(", ")}.`, "warn") : k(` Cloned ${a}/${r.length} repository(ies).`, "success");
|
|
610
637
|
}
|
|
611
|
-
function
|
|
638
|
+
function $e(e, t) {
|
|
612
639
|
if ("docpress" in e && !e.docpress.includes.length) return !0;
|
|
613
640
|
let n = t?.filter((e) => !e.startsWith("!")) ?? [], r = t?.every((e) => e.startsWith("!")), i = t?.filter((e) => e.startsWith("!")).some((t) => e.name === t.substring(1)), a = !t || n.includes(e.name) || e.fork && !i || r && !i, o = i || !a;
|
|
614
641
|
return !(e.clone_url && !e.private && !o);
|
|
615
642
|
}
|
|
616
643
|
//#endregion
|
|
617
644
|
//#region src/commands/global.ts
|
|
618
|
-
var
|
|
645
|
+
var Z = [
|
|
619
646
|
n("-C, --config <string>", K.shape.config.description),
|
|
647
|
+
n("--log-level <string>", K.shape.logLevel.description),
|
|
620
648
|
n("-T, --token <string>", K.shape.token.description),
|
|
621
649
|
n("-U, --usernames <string>", K.shape.usernames.description)
|
|
622
|
-
],
|
|
650
|
+
], et = "fetch", tt = [
|
|
623
651
|
n("-b, --branch <string>", G.shape.branch.description),
|
|
624
652
|
n("-g, --git-provider <string>", G.shape.gitProvider.description).default(G.shape.gitProvider.def.defaultValue),
|
|
625
653
|
n("-l, --last-updated", G.shape.lastUpdated.description),
|
|
626
654
|
n("-r, --repos-filter <string>", G.shape.reposFilter.description)
|
|
627
|
-
],
|
|
628
|
-
await
|
|
655
|
+
], nt = Y(t(et), [...tt, ...Z]).description("Fetch docs with the given username(s) and git provider.").action(async (e, t) => {
|
|
656
|
+
await rt(q(et, J(t, e)));
|
|
629
657
|
});
|
|
630
|
-
async function
|
|
658
|
+
async function rt(e) {
|
|
631
659
|
let { usernames: t, reposFilter: n, token: r, branch: i, gitProvider: a, lastUpdated: o } = e;
|
|
632
|
-
|
|
633
|
-
let s =
|
|
660
|
+
k("\n-> Start fetching documentation files. This may take a moment, especially for larger repositories.", "info");
|
|
661
|
+
let s = Date.now();
|
|
662
|
+
F(S, { clean: !0 });
|
|
663
|
+
let c = [];
|
|
634
664
|
for (let e of t) {
|
|
635
|
-
let
|
|
665
|
+
let s = t.length > 1 ? n?.filter((t) => t.replace(/^!/, "").startsWith(`${e}/`)).map((t) => t.replace(`${e}/`, "")) : n;
|
|
636
666
|
try {
|
|
637
|
-
await
|
|
667
|
+
await Je({
|
|
638
668
|
username: e,
|
|
639
669
|
branch: i,
|
|
640
|
-
reposFilter:
|
|
670
|
+
reposFilter: s,
|
|
641
671
|
gitProvider: a,
|
|
642
672
|
token: r,
|
|
643
673
|
lastUpdated: o,
|
|
644
674
|
multiUser: t.length > 1
|
|
645
675
|
});
|
|
646
676
|
} catch (t) {
|
|
647
|
-
|
|
677
|
+
c.push(e), k(` Failed to fetch documentation for '${e}': ${M(t)}`, "error");
|
|
648
678
|
}
|
|
649
679
|
}
|
|
650
|
-
if (
|
|
680
|
+
if (c.length === t.length) throw Error(`Failed to fetch documentation for all requested username(s): ${c.join(", ")}.`);
|
|
681
|
+
k(` Fetched documentation for ${t.length - c.length}/${t.length} username(s) in ${N(Date.now() - s)}.`, c.length ? "warn" : "success");
|
|
651
682
|
}
|
|
652
683
|
//#endregion
|
|
653
684
|
//#region src/commands/build.ts
|
|
654
|
-
async function
|
|
685
|
+
async function it(e) {
|
|
655
686
|
let t = console.warn;
|
|
656
687
|
console.warn = function(...e) {
|
|
657
688
|
e.length > 0 && typeof e[0] == "string" && (e[0].includes("[Vue warn]: Invalid watch source:") || e[0].includes("{ open: false }")) || t.apply(console, e);
|
|
@@ -662,30 +693,32 @@ async function Ze(e) {
|
|
|
662
693
|
console.warn = t;
|
|
663
694
|
}
|
|
664
695
|
}
|
|
665
|
-
var
|
|
666
|
-
await
|
|
696
|
+
var at = Y(t("build"), Z).description("Build vitepress website.").action(async (e) => {
|
|
697
|
+
await ot();
|
|
667
698
|
});
|
|
668
|
-
async function
|
|
669
|
-
|
|
699
|
+
async function ot() {
|
|
700
|
+
k("\n-> Start building Vitepress website.\n\n", "info");
|
|
701
|
+
let e = Date.now();
|
|
670
702
|
try {
|
|
671
|
-
await
|
|
672
|
-
await
|
|
673
|
-
|
|
703
|
+
await it(async () => {
|
|
704
|
+
await ne(S, { onAfterConfigResolve(e) {
|
|
705
|
+
re(e);
|
|
674
706
|
} });
|
|
675
|
-
})
|
|
707
|
+
});
|
|
676
708
|
} catch (e) {
|
|
677
|
-
|
|
709
|
+
throw Error(`Docpress build failed: ${M(e)}`);
|
|
678
710
|
}
|
|
711
|
+
k(`\n\nDocpress build succeeded in ${N(Date.now() - e)}.`, "success");
|
|
679
712
|
}
|
|
680
713
|
//#endregion
|
|
681
714
|
//#region src/utils/templates.ts
|
|
682
|
-
function
|
|
715
|
+
function st(e, t) {
|
|
683
716
|
let n = s(e, { encoding: "utf8" });
|
|
684
|
-
|
|
717
|
+
F(m(t)), f(t, n);
|
|
685
718
|
}
|
|
686
719
|
//#endregion
|
|
687
720
|
//#region src/lib/vitepress.ts
|
|
688
|
-
var
|
|
721
|
+
var ct = {
|
|
689
722
|
base: "/",
|
|
690
723
|
lang: "en-US",
|
|
691
724
|
vite: { publicDir: "../public" },
|
|
@@ -718,21 +751,21 @@ var tt = {
|
|
|
718
751
|
}
|
|
719
752
|
}
|
|
720
753
|
};
|
|
721
|
-
function
|
|
722
|
-
return n ?
|
|
754
|
+
function lt(e, t, n) {
|
|
755
|
+
return n ? B(ct, n, { themeConfig: {
|
|
723
756
|
sidebar: e,
|
|
724
757
|
nav: t
|
|
725
|
-
} }) :
|
|
758
|
+
} }) : B(ct, { themeConfig: {
|
|
726
759
|
sidebar: e,
|
|
727
760
|
nav: t
|
|
728
761
|
} });
|
|
729
762
|
}
|
|
730
763
|
//#endregion
|
|
731
764
|
//#region src/lib/prepare.ts
|
|
732
|
-
async function
|
|
765
|
+
async function ut({ extraHeaderPages: e, extraPublicContent: t, extraTheme: n, vitepressConfig: r, forks: i, gitProvider: o, lastUpdated: s, token: c, username: l, websiteTitle: u, websiteTagline: d }) {
|
|
733
766
|
let f = i && o !== "gitlab";
|
|
734
|
-
i && !f &&
|
|
735
|
-
let p =
|
|
767
|
+
i && !f && k(" The forks page is not supported with the 'gitlab' provider, skipping.", "warn");
|
|
768
|
+
let p = be(l), m = xe(l).reduce(({ internals: e, forks: t }, n) => {
|
|
736
769
|
let { clone_url: r, private: i, fork: a, docpress: o } = n;
|
|
737
770
|
if (r && !i && !o.filtered) {
|
|
738
771
|
if (!a && o.includes.length) return {
|
|
@@ -751,39 +784,39 @@ async function rt({ extraHeaderPages: e, extraPublicContent: t, extraTheme: n, v
|
|
|
751
784
|
}, {
|
|
752
785
|
internals: [],
|
|
753
786
|
forks: []
|
|
754
|
-
}),
|
|
787
|
+
}), ee = {
|
|
755
788
|
title: u,
|
|
756
789
|
tagline: d
|
|
757
|
-
}, { index:
|
|
758
|
-
if (a(
|
|
759
|
-
let e = await
|
|
760
|
-
|
|
761
|
-
...
|
|
762
|
-
features: [...t.features, ...
|
|
790
|
+
}, { index: h, sidebar: g } = yt(m.internals, p, ee), v, y;
|
|
791
|
+
if (a(C) && a(w)) {
|
|
792
|
+
let e = await Ct(w), t = await wt(C);
|
|
793
|
+
v = [...e.themeConfig?.sidebar ?? [], ...g].sort((e, t) => e.text.localeCompare(t.text)), y = {
|
|
794
|
+
...h,
|
|
795
|
+
features: [...t.features, ...h.features].sort((e, t) => e.title.localeCompare(t.title))
|
|
763
796
|
};
|
|
764
|
-
} else
|
|
765
|
-
let
|
|
797
|
+
} else v = g, y = h;
|
|
798
|
+
let b = [];
|
|
766
799
|
if (e) {
|
|
767
|
-
let t =
|
|
768
|
-
f ?
|
|
800
|
+
let t = bt(e);
|
|
801
|
+
f ? b.push(...t.filter((e) => e.link !== "/forks")) : b.push(...t);
|
|
769
802
|
}
|
|
770
|
-
t && (
|
|
803
|
+
t && (k(" Add extras Vitepress public folder content.", "info"), Q(t, _(S, "public"))), n && (k(" Add extras Vitepress theme files.", "info"), Q(n, _(le))), f && l.length && (k(" Add fork page to display external contributions.", "info"), await St(m.forks, l, c), b.push({
|
|
771
804
|
text: "Forks",
|
|
772
805
|
link: "/forks"
|
|
773
806
|
}));
|
|
774
|
-
let
|
|
807
|
+
let x = s ? {
|
|
775
808
|
lastUpdated: !0,
|
|
776
809
|
...r
|
|
777
810
|
} : r;
|
|
778
|
-
|
|
811
|
+
Tt(lt(v, b, x), y);
|
|
779
812
|
}
|
|
780
|
-
function
|
|
781
|
-
r(t, `${
|
|
813
|
+
function dt(e, t) {
|
|
814
|
+
r(t, `${P(p(t), {
|
|
782
815
|
mode: "lowercase",
|
|
783
816
|
removeIdx: !0
|
|
784
817
|
}) === "readme.md" ? "\n## Sources" : "# Sources"}\n\nTake a look at the [project sources](${e}).\n`, "utf8");
|
|
785
818
|
}
|
|
786
|
-
function
|
|
819
|
+
function ft(e, t, n) {
|
|
787
820
|
let { name: r, login: i, bio: a } = t, { title: o, tagline: s } = n;
|
|
788
821
|
return {
|
|
789
822
|
layout: "home",
|
|
@@ -797,20 +830,20 @@ function at(e, t, n) {
|
|
|
797
830
|
features: e
|
|
798
831
|
};
|
|
799
832
|
}
|
|
800
|
-
function
|
|
833
|
+
function pt(e, t, n, r = "") {
|
|
801
834
|
let i = {
|
|
802
|
-
title:
|
|
835
|
+
title: P(e, {
|
|
803
836
|
mode: "capitalize",
|
|
804
837
|
replaceDash: !0
|
|
805
838
|
}),
|
|
806
839
|
details: t,
|
|
807
|
-
link: `/${r}${
|
|
840
|
+
link: `/${r}${P(e, { removeDot: !0 })}/introduction`
|
|
808
841
|
};
|
|
809
842
|
return n ? [...n, i] : [i];
|
|
810
843
|
}
|
|
811
|
-
function
|
|
844
|
+
function mt(e, t) {
|
|
812
845
|
return {
|
|
813
|
-
text:
|
|
846
|
+
text: P(e, {
|
|
814
847
|
mode: "capitalize",
|
|
815
848
|
replaceDash: !0
|
|
816
849
|
}),
|
|
@@ -818,86 +851,86 @@ function st(e, t) {
|
|
|
818
851
|
items: t
|
|
819
852
|
};
|
|
820
853
|
}
|
|
821
|
-
function
|
|
854
|
+
function ht(e, t) {
|
|
822
855
|
return Object.entries(t).flatMap(([t, n]) => t === "$" ? Array.isArray(n) ? n.map((t) => {
|
|
823
|
-
let n =
|
|
856
|
+
let n = _(e.docpress.projectPath, t), r = P(p(n), {
|
|
824
857
|
mode: "lowercase",
|
|
825
858
|
removeIdx: !0
|
|
826
859
|
});
|
|
827
|
-
return r === "readme.md" && (r = "introduction.md"), r !== p(n) && l(n,
|
|
828
|
-
text:
|
|
860
|
+
return r === "readme.md" && (r = "introduction.md"), r !== p(n) && l(n, _(m(n), r)), {
|
|
861
|
+
text: h(r).name === "introduction" ? "Introduction" : P(r, {
|
|
829
862
|
mode: "capitalize",
|
|
830
863
|
replaceDash: !0,
|
|
831
864
|
removeExt: !0
|
|
832
865
|
}),
|
|
833
|
-
link: `/${e.docpress.routePrefix ?? ""}${
|
|
866
|
+
link: `/${e.docpress.routePrefix ?? ""}${P(e.name, { removeDot: !0 })}/${h(r).name}`
|
|
834
867
|
};
|
|
835
868
|
}) : [] : typeof n == "object" ? [{
|
|
836
|
-
text:
|
|
869
|
+
text: P(t, {
|
|
837
870
|
mode: "capitalize",
|
|
838
871
|
replaceDash: !0
|
|
839
872
|
}),
|
|
840
873
|
collapsed: !0,
|
|
841
|
-
items:
|
|
874
|
+
items: ht({
|
|
842
875
|
...e,
|
|
843
876
|
name: `${e.name}/${t}`
|
|
844
877
|
}, n)
|
|
845
878
|
}] : []);
|
|
846
879
|
}
|
|
847
|
-
function
|
|
880
|
+
function gt(e) {
|
|
848
881
|
return e.reduce((e, t) => {
|
|
849
882
|
let [n, ...r] = t.split("/");
|
|
850
|
-
return r.length ? e[n] =
|
|
883
|
+
return r.length ? e[n] = gt([...e[n] ? _t(e[n], "") : [], r.join("/")]) : e.$ = [...e.$ || [], n], e;
|
|
851
884
|
}, {});
|
|
852
885
|
}
|
|
853
|
-
function
|
|
854
|
-
return Object.entries(e).flatMap(([e, n]) => e === "$" ? Array.isArray(n) ? n.map((e) => t ? `${t}/${e}` : e) : [] :
|
|
886
|
+
function _t(e, t = "") {
|
|
887
|
+
return Object.entries(e).flatMap(([e, n]) => e === "$" ? Array.isArray(n) ? n.map((e) => t ? `${t}/${e}` : e) : [] : _t(n, t ? `${t}/${e}` : e));
|
|
855
888
|
}
|
|
856
|
-
function
|
|
889
|
+
function vt(e) {
|
|
857
890
|
if (!Array.isArray(e)) return e;
|
|
858
891
|
let t = e.findIndex((e) => e.text === "Sources");
|
|
859
892
|
if (t === -1) return e;
|
|
860
893
|
let [n] = e.splice(t, 1);
|
|
861
894
|
return e.push(n), e;
|
|
862
895
|
}
|
|
863
|
-
function
|
|
896
|
+
function yt(e, t, n) {
|
|
864
897
|
let r = [], i = [];
|
|
865
898
|
for (let t of e) {
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
}),
|
|
899
|
+
k(` Replace urls for repository '${t.name}'.`, "info"), R([t.docpress.projectPath]).forEach((e) => {
|
|
900
|
+
k(` Processing file '${p(e)}' for repository '${t.name}'.`, "debug"), Ce(e, t.docpress.replace_url), p(e).toLowerCase() === "readme.md" && Ee(e, t.docpress.replace_url), Te(e);
|
|
901
|
+
}), k(` Generate sidebar for repository '${t.name}'.`, "info");
|
|
869
902
|
let e = c(t.docpress.projectPath, { recursive: !0 }).filter((e) => {
|
|
870
|
-
let n =
|
|
871
|
-
return p(n).endsWith(".md") &&
|
|
903
|
+
let n = _(t.docpress.projectPath, e.toString());
|
|
904
|
+
return p(n).endsWith(".md") && I(n);
|
|
872
905
|
}).sort();
|
|
873
|
-
|
|
906
|
+
k(` Add sources for repository '${t.name}'.`, "info");
|
|
874
907
|
let n;
|
|
875
|
-
e.length > 1 ? (n =
|
|
876
|
-
let a =
|
|
877
|
-
i.push(
|
|
908
|
+
e.length > 1 ? (n = _(t.docpress.projectPath, "sources.md"), e.push("sources.md")) : e.length === 1 && (n = _(t.docpress.projectPath, e[0])), n ? dt(t.html_url, n) : k(` No markdown files found for repository '${t.name}', skipping sources.`, "warn");
|
|
909
|
+
let a = vt(ht(t, gt(e)));
|
|
910
|
+
i.push(mt(P(t.name, { removeDot: !0 }), a)), r.push(...pt(P(t.name, { removeDot: !0 }), t.description || "", void 0, t.docpress.routePrefix ?? ""));
|
|
878
911
|
}
|
|
879
|
-
|
|
880
|
-
let a =
|
|
912
|
+
k(" Generate index content.", "info");
|
|
913
|
+
let a = ft(r.toSorted((e, t) => e.title.localeCompare(t.title)), t, n);
|
|
881
914
|
return {
|
|
882
915
|
sidebar: i.toSorted((e, t) => e.text.localeCompare(t.text)),
|
|
883
916
|
index: a
|
|
884
917
|
};
|
|
885
918
|
}
|
|
886
|
-
function
|
|
887
|
-
let t =
|
|
888
|
-
|
|
919
|
+
function bt(e) {
|
|
920
|
+
let t = R(e), n = [];
|
|
921
|
+
k(" Add extras Vitepress headers pages.", "info");
|
|
889
922
|
for (let e of t) {
|
|
890
|
-
|
|
891
|
-
let t =
|
|
892
|
-
i(t,
|
|
923
|
+
k(` Processing file '${e}'.`, "debug");
|
|
924
|
+
let t = _(process.cwd(), e);
|
|
925
|
+
i(t, _(oe, P(p(e), {
|
|
893
926
|
mode: "lowercase",
|
|
894
927
|
removeIdx: !0
|
|
895
928
|
}))), n.push({
|
|
896
|
-
text:
|
|
929
|
+
text: P(h(t).name, {
|
|
897
930
|
replaceDash: !0,
|
|
898
931
|
removeIdx: !0
|
|
899
932
|
}),
|
|
900
|
-
link: `/${
|
|
933
|
+
link: `/${P(h(t).name, {
|
|
901
934
|
removeIdx: !0,
|
|
902
935
|
mode: "lowercase"
|
|
903
936
|
})}`
|
|
@@ -905,18 +938,18 @@ function pt(e) {
|
|
|
905
938
|
}
|
|
906
939
|
return n;
|
|
907
940
|
}
|
|
908
|
-
function
|
|
941
|
+
function Q(e, t, n) {
|
|
909
942
|
for (let r of Array.isArray(e) ? e : [e]) {
|
|
910
|
-
let e =
|
|
943
|
+
let e = _(process.cwd(), r), a = L(e);
|
|
911
944
|
for (let o of a) {
|
|
912
945
|
let a = o.replace(e, ".");
|
|
913
|
-
|
|
914
|
-
let s =
|
|
946
|
+
k(` Processing file '${a}' for entry '${r}'.`, "debug");
|
|
947
|
+
let s = _(process.cwd(), o), c = _(t, a);
|
|
915
948
|
n && n(), i(s, c);
|
|
916
949
|
}
|
|
917
950
|
}
|
|
918
951
|
}
|
|
919
|
-
function
|
|
952
|
+
function xt(e) {
|
|
920
953
|
let t = e.map(({ repository: e, contributions: t }) => {
|
|
921
954
|
let { name: n, owner: r, html_url: i, description: a, stargazers_count: o } = e;
|
|
922
955
|
return {
|
|
@@ -928,11 +961,11 @@ function ht(e) {
|
|
|
928
961
|
contributions: t
|
|
929
962
|
};
|
|
930
963
|
});
|
|
931
|
-
|
|
964
|
+
k(" Generate forks page.", "info"), f(se, "---\nlayout: fork-page\nrepoList:\n" + v.stringify(t) + "---\n\n# External contributions\n\nThis gallery is a visual representation of the collaborative work done across a variety of open-source projects, each driven by a shared passion for innovation and community growth.\n\nEvery tile below represents a unique project where contributions have been made-ranging from code enhancements to documentation improvements. Each project includes a summary of its goals, features, and links to GitHub for direct access.\n\nThis page serves as both a portfolio of past work and a resource for revisiting projects that have made a meaningful impact.\n");
|
|
932
965
|
}
|
|
933
|
-
async function
|
|
934
|
-
|
|
935
|
-
let { source: r, contributors: i } = await
|
|
966
|
+
async function St(e, t, n) {
|
|
967
|
+
xt(await Promise.all(e.map(async (e) => {
|
|
968
|
+
let { source: r, contributors: i } = await Le({
|
|
936
969
|
repository: e,
|
|
937
970
|
token: n
|
|
938
971
|
});
|
|
@@ -942,26 +975,29 @@ async function gt(e, t, n) {
|
|
|
942
975
|
};
|
|
943
976
|
})).then((e) => e.filter(({ repository: e, contributions: t }) => !!e && t)));
|
|
944
977
|
}
|
|
945
|
-
async function
|
|
978
|
+
async function Ct(e) {
|
|
946
979
|
try {
|
|
947
|
-
let { config: t } = await import(
|
|
980
|
+
let { config: t } = await import(_(process.cwd(), e));
|
|
948
981
|
return t ?? {};
|
|
949
982
|
} catch (t) {
|
|
950
|
-
return
|
|
983
|
+
return k(` Unable to load existing Vitepress config '${e}', starting from an empty config. ${M(t)}`, "warn"), {};
|
|
951
984
|
}
|
|
952
985
|
}
|
|
953
|
-
async function
|
|
954
|
-
let t = (await
|
|
955
|
-
return
|
|
986
|
+
async function wt(e) {
|
|
987
|
+
let t = (await ie(_(process.cwd(), e))).toString();
|
|
988
|
+
return v.parse(t);
|
|
956
989
|
}
|
|
957
|
-
function
|
|
958
|
-
|
|
959
|
-
|
|
990
|
+
function Tt(e, t) {
|
|
991
|
+
F(m(w)), k(" Generate Vitepress config.", "info"), f(w, `export const config = ${JSON.stringify(e, null, 2)}\n\nexport default config\n`), k(" Generate index file.", "info"), f(C, "---\n" + v.stringify(t));
|
|
992
|
+
let n = L(T);
|
|
993
|
+
if (!n.length) throw Error(`No template theme files found at '${T}'. The Vitepress build cannot succeed without them.`);
|
|
994
|
+
k(" Add Docpress theme files.", "info"), n.forEach((e) => {
|
|
995
|
+
st(e, _(ce, e.replace(`${T}/`, "")));
|
|
960
996
|
});
|
|
961
997
|
}
|
|
962
998
|
//#endregion
|
|
963
999
|
//#region src/commands/prepare.ts
|
|
964
|
-
var
|
|
1000
|
+
var Et = "prepare", Dt = [
|
|
965
1001
|
n("-c, --extra-public-content <string>", G.shape.extraPublicContent.description),
|
|
966
1002
|
n("-f, --forks", G.shape.forks.description),
|
|
967
1003
|
n("-p, --extra-header-pages <string>", G.shape.extraHeaderPages.description),
|
|
@@ -969,49 +1005,58 @@ var bt = "prepare", xt = [
|
|
|
969
1005
|
n("-v, --vitepress-config <string>", G.shape.vitepressConfig.description),
|
|
970
1006
|
n("--website-title <string>", G.shape.websiteTitle.description),
|
|
971
1007
|
n("--website-tagline <string>", G.shape.websiteTagline.description)
|
|
972
|
-
],
|
|
973
|
-
await
|
|
1008
|
+
], Ot = Y(t(Et), [...Dt, ...Z]).description("Transform doc to the target vitepress format.").action(async (e, t) => {
|
|
1009
|
+
await kt(q(Et, J(t, e)));
|
|
974
1010
|
});
|
|
975
|
-
async function
|
|
1011
|
+
async function kt(e) {
|
|
976
1012
|
let { extraHeaderPages: t, extraPublicContent: n, extraTheme: r, vitepressConfig: i, forks: a, gitProvider: o, lastUpdated: s, token: c, usernames: l, websiteTitle: u, websiteTagline: d } = e;
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
1013
|
+
k("\n-> Start transform files to prepare Vitepress build.", "info");
|
|
1014
|
+
let f = Date.now();
|
|
1015
|
+
F(m(w), { clean: !0 });
|
|
1016
|
+
let p = [];
|
|
1017
|
+
for (let e of l) try {
|
|
1018
|
+
await ut({
|
|
1019
|
+
extraHeaderPages: t,
|
|
1020
|
+
extraPublicContent: n,
|
|
1021
|
+
extraTheme: r,
|
|
1022
|
+
vitepressConfig: i,
|
|
1023
|
+
forks: a,
|
|
1024
|
+
gitProvider: o,
|
|
1025
|
+
lastUpdated: s,
|
|
1026
|
+
token: c,
|
|
1027
|
+
username: e,
|
|
1028
|
+
websiteTitle: u,
|
|
1029
|
+
websiteTagline: d
|
|
1030
|
+
});
|
|
1031
|
+
} catch (t) {
|
|
1032
|
+
p.push(e), k(` Failed to prepare documentation for '${e}': ${M(t)}`, "error");
|
|
1033
|
+
}
|
|
1034
|
+
if (p.length === l.length) throw Error(`Failed to prepare documentation for all requested username(s): ${p.join(", ")}.`);
|
|
1035
|
+
k(` Prepared documentation for ${l.length - p.length}/${l.length} username(s) in ${N(Date.now() - f)}.`, p.length ? "warn" : "success");
|
|
991
1036
|
}
|
|
992
1037
|
//#endregion
|
|
993
1038
|
//#region src/cli.ts
|
|
994
|
-
function
|
|
995
|
-
let t = new e().name("docpress").description("Build your doc website faster than light ⚡️⚡️⚡️").version(`${
|
|
1039
|
+
function $() {
|
|
1040
|
+
let t = new e().name("docpress").description("Build your doc website faster than light ⚡️⚡️⚡️").version(`${ae.version}`).action(async (e, t) => {
|
|
996
1041
|
let n = q("global", J(t, e));
|
|
997
|
-
await
|
|
1042
|
+
await rt(n), await kt(n), await ot();
|
|
998
1043
|
}).configureHelp({
|
|
999
1044
|
sortSubcommands: !0,
|
|
1000
1045
|
sortOptions: !0,
|
|
1001
1046
|
showGlobalOptions: !0
|
|
1002
|
-
}).enablePositionalOptions().passThroughOptions().addCommand(
|
|
1047
|
+
}).enablePositionalOptions().passThroughOptions().addCommand(nt).addCommand(Ot).addCommand(at);
|
|
1003
1048
|
return Y(t, [
|
|
1004
|
-
...
|
|
1005
|
-
...
|
|
1006
|
-
|
|
1049
|
+
...tt,
|
|
1050
|
+
...Dt,
|
|
1051
|
+
...Z
|
|
1007
1052
|
]), t;
|
|
1008
1053
|
}
|
|
1009
|
-
function
|
|
1010
|
-
|
|
1011
|
-
|
|
1054
|
+
function At() {
|
|
1055
|
+
$().parseAsync(process.argv).catch((e) => {
|
|
1056
|
+
k(`\n${M(e)}`, "error"), process.exit(1);
|
|
1012
1057
|
});
|
|
1013
1058
|
}
|
|
1014
1059
|
//#endregion
|
|
1015
|
-
export {
|
|
1060
|
+
export { $ as getProgram, At as main };
|
|
1016
1061
|
|
|
1017
1062
|
//# sourceMappingURL=cli.js.map
|