@tobi-or-not/docpress 0.8.0 → 0.8.2
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/dist/cli.js +117 -114
- package/dist/cli.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +1 -1
- package/types/cli.d.ts +3 -0
- package/types/commands/build.d.ts +3 -0
- package/types/commands/fetch.d.ts +4 -0
- package/types/commands/global.d.ts +1 -0
- package/types/commands/prepare.d.ts +4 -0
- package/types/lib/fetch.d.ts +120 -0
- package/types/lib/git.d.ts +515 -0
- package/types/lib/prepare.d.ts +62 -0
- package/types/lib/vitepress.d.ts +3 -0
- package/types/schemas/build.d.ts +20 -0
- package/types/schemas/fetch.d.ts +52 -0
- package/types/schemas/global.d.ts +150 -0
- package/types/schemas/prepare.d.ts +61 -0
- package/types/src/templates/index.d.ts +1 -0
- package/types/src/templates/theme/index.d.ts +8 -0
- package/types/src/utils/resolver.d.ts +1 -0
- package/types/templates/index.d.ts +5 -0
- package/types/templates/theme/index.d.ts +8 -0
- package/types/utils/commands.d.ts +207 -0
- package/types/utils/const.d.ts +10 -0
- package/types/utils/functions.d.ts +24 -0
- package/types/utils/logger.d.ts +4 -0
- package/types/utils/regex.d.ts +2 -0
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createOption as m, createCommand as J, Command as Pe } from "commander";
|
|
2
|
-
import { readFileSync as
|
|
2
|
+
import { readFileSync as S, existsSync as O, mkdirSync as ke, writeFileSync as v, readdirSync as ue, statSync as z, appendFileSync as le, cpSync as B, rmSync as Z, renameSync as Ee } from "node:fs";
|
|
3
3
|
import { resolve as u, basename as y, join as Fe, dirname as _, parse as R } from "node:path";
|
|
4
4
|
import Te from "axios";
|
|
5
5
|
import { rimrafSync as Oe } from "rimraf";
|
|
@@ -9,14 +9,15 @@ import { z as l } from "zod";
|
|
|
9
9
|
import { Octokit as de } from "@octokit/rest";
|
|
10
10
|
import { simpleGit as _e } from "simple-git";
|
|
11
11
|
import { build as Ae } from "vitepress";
|
|
12
|
-
import {
|
|
12
|
+
import { withMermaid as Ie } from "vitepress-plugin-mermaid";
|
|
13
|
+
import { readFile as je } from "node:fs/promises";
|
|
13
14
|
import q from "yaml";
|
|
14
|
-
const
|
|
15
|
-
version:
|
|
16
|
-
},
|
|
15
|
+
const Le = "0.8.0", Ve = {
|
|
16
|
+
version: Le
|
|
17
|
+
}, C = u(process.cwd(), "docpress");
|
|
17
18
|
u(process.cwd(), "docpress/repositories.json");
|
|
18
19
|
u(process.cwd(), "docpress/owner.json");
|
|
19
|
-
const pe = u(process.cwd(), "docpress/docs"),
|
|
20
|
+
const pe = u(process.cwd(), "docpress/docs"), M = u(process.cwd(), "docpress/docs/index.md"), Ne = u(process.cwd(), "docpress/docs/forks.md"), E = u(process.cwd(), "docpress/.vitepress/config.ts"), De = u(process.cwd(), "docpress/.vitepress/theme"), Ge = u(process.cwd(), "docpress/.vitepress/theme/extras"), te = process.env.NODE_ENV === "development" ? u(import.meta.dirname, "../../public/templates/theme") : u(import.meta.dirname, "./templates/theme"), He = /\[([^\]]+)\]\(\.\.\/([^)]+)\)/g, Me = /\[([^\]]+)\]\((?!\.?\/docs\/|docs\/|http|#)(\.\/)?([^/][^)]+)\)/g, Ue = /\[([^\]]+)\]\((\.?\/docs\/|docs\/)([^)]*)\)/g, We = /^\d{2}-/;
|
|
20
21
|
async function G(e) {
|
|
21
22
|
try {
|
|
22
23
|
return (await Te.head(e)).status;
|
|
@@ -26,7 +27,7 @@ async function G(e) {
|
|
|
26
27
|
}
|
|
27
28
|
function f(e, t) {
|
|
28
29
|
let r = "";
|
|
29
|
-
return t?.removeDot && (e.startsWith(".") ? r = e.slice(1) : r = e, r = r.replaceAll(".", "-")), t?.removeIdx && (r = (r || e).replace(
|
|
30
|
+
return t?.removeDot && (e.startsWith(".") ? r = e.slice(1) : r = e, r = r.replaceAll(".", "-")), t?.removeIdx && (r = (r || e).replace(We, "")), t?.removeExt && (r = (r || e).split(".")[0]), t?.replaceDash && (r = (r || e).replaceAll("-", " ")), t?.mode === "capitalize" ? r = (r || e).slice(0, 1).toUpperCase() + (r || e).slice(1).toLowerCase() : t?.mode === "lowercase" ? r = (r || e).toLowerCase() : t?.mode === "uppercase" && (r = (r || e).toUpperCase()), r || e;
|
|
30
31
|
}
|
|
31
32
|
function F(e, { clean: t } = { clean: !1 }) {
|
|
32
33
|
try {
|
|
@@ -35,14 +36,14 @@ function F(e, { clean: t } = { clean: !1 }) {
|
|
|
35
36
|
console.error(r);
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
|
-
function
|
|
39
|
+
function Je(e) {
|
|
39
40
|
try {
|
|
40
41
|
return z(e).isDirectory();
|
|
41
42
|
} catch {
|
|
42
43
|
return !1;
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
|
-
function
|
|
46
|
+
function ze(e) {
|
|
46
47
|
try {
|
|
47
48
|
return z(e).isFile();
|
|
48
49
|
} catch {
|
|
@@ -50,19 +51,19 @@ function Je(e) {
|
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
function A(e) {
|
|
53
|
-
return (Array.isArray(e) ? e : [e]).flatMap((t) =>
|
|
54
|
+
return (Array.isArray(e) ? e : [e]).flatMap((t) => ze(t) ? [t] : Je(t) ? ue(t).flatMap((r) => A(Fe(t, r))) : []);
|
|
54
55
|
}
|
|
55
56
|
function fe(e) {
|
|
56
57
|
return A(e).filter((t) => y(t).endsWith(".md"));
|
|
57
58
|
}
|
|
58
|
-
function ze(e) {
|
|
59
|
-
return e.reduce((t, r, o, s) => o ? o === s.length - 1 ? `${t} or "${r}"` : `${t}, "${r}"` : `"${r}"`, "");
|
|
60
|
-
}
|
|
61
59
|
function Be(e) {
|
|
62
|
-
return
|
|
60
|
+
return e.reduce((t, r, o, s) => o ? o === s.length - 1 ? `${t} or "${r}"` : `${t}, "${r}"` : `"${r}"`, "");
|
|
63
61
|
}
|
|
64
62
|
function qe(e) {
|
|
65
|
-
return JSON.parse(
|
|
63
|
+
return JSON.parse(S(`${C}/user-${e}.json`).toString());
|
|
64
|
+
}
|
|
65
|
+
function Ke(e) {
|
|
66
|
+
return JSON.parse(S(`${C}/repos-${e}.json`).toString());
|
|
66
67
|
}
|
|
67
68
|
function U(...e) {
|
|
68
69
|
return e.reduce((t, r) => (r === null || Object.keys(r).forEach((o) => {
|
|
@@ -77,7 +78,7 @@ function W(e) {
|
|
|
77
78
|
if (!e)
|
|
78
79
|
return {};
|
|
79
80
|
try {
|
|
80
|
-
const t = u(process.cwd(), e), r =
|
|
81
|
+
const t = u(process.cwd(), e), r = S(t, "utf8");
|
|
81
82
|
return JSON.parse(r);
|
|
82
83
|
} catch {
|
|
83
84
|
return {};
|
|
@@ -86,15 +87,15 @@ function W(e) {
|
|
|
86
87
|
function k(e) {
|
|
87
88
|
return e.split(",");
|
|
88
89
|
}
|
|
89
|
-
function
|
|
90
|
-
const o =
|
|
90
|
+
function Xe(e, t) {
|
|
91
|
+
const o = S(e, "utf8").replace(He, (s, i, n) => `[${i}](${t}/${n})`);
|
|
91
92
|
v(e, o, "utf8");
|
|
92
93
|
}
|
|
93
|
-
function
|
|
94
|
-
const o =
|
|
94
|
+
function Ye(e, t) {
|
|
95
|
+
const o = S(e, "utf8").replace(Me, (s, i, n, c) => `[${i}](${t}/${c})`).replace(Ue, (s, i, n, c) => `[${i}](${c})`);
|
|
95
96
|
v(e, o, "utf8");
|
|
96
97
|
}
|
|
97
|
-
function
|
|
98
|
+
function Qe() {
|
|
98
99
|
return typeof Number(process.env.LOG_LEVEL) == "number" && !Number.isNaN(Number(process.env.LOG_LEVEL)) ? Number(process.env.LOG_LEVEL) : 30;
|
|
99
100
|
}
|
|
100
101
|
const oe = {
|
|
@@ -107,14 +108,14 @@ const oe = {
|
|
|
107
108
|
};
|
|
108
109
|
function a(e, t = "info", r) {
|
|
109
110
|
const o = r ? ee[r](e) : ee[oe[t].color](e), s = t === "success" ? "info" : t;
|
|
110
|
-
|
|
111
|
+
Qe() >= oe[t].level && console[s](o);
|
|
111
112
|
}
|
|
112
113
|
const se = ["github"], d = l.object({
|
|
113
114
|
// Global
|
|
114
115
|
usernames: l.string().array().describe("List of comma separated Git provider usernames used to collect data."),
|
|
115
116
|
// Fetch
|
|
116
117
|
branch: l.string().describe("Branch used to collect Git provider data.").default("main"),
|
|
117
|
-
gitProvider: l.enum(se).describe(`Git provider used to retrieve data. Values should be ${
|
|
118
|
+
gitProvider: l.enum(se).describe(`Git provider used to retrieve data. Values should be ${Be(se)}.`).default("github"),
|
|
118
119
|
reposFilter: l.string().array().describe("List of comma separated repositories to retrieve from Git provider. Default to all user's public repositories."),
|
|
119
120
|
// Prepare
|
|
120
121
|
extraHeaderPages: l.string().array().describe("List of comma separated additional files or directories to process Vitepress header pages."),
|
|
@@ -124,7 +125,7 @@ const se = ["github"], d = l.object({
|
|
|
124
125
|
vitepressConfig: l.any().describe("Path to the vitepress configuration file."),
|
|
125
126
|
websiteTitle: l.string().describe("Website title."),
|
|
126
127
|
websiteTagline: l.string().describe("Website tagline.")
|
|
127
|
-
}),
|
|
128
|
+
}), H = d.partial().extend({
|
|
128
129
|
config: l.string().describe("Path to the docpress configuration file.").optional(),
|
|
129
130
|
token: l.string().describe("Git provider token used to collect data.").optional(),
|
|
130
131
|
usernames: l.string().describe(d.shape.usernames.description || "").optional(),
|
|
@@ -143,19 +144,19 @@ const se = ["github"], d = l.object({
|
|
|
143
144
|
extraTheme: l.string().describe(d.shape.extraTheme.description || "").transform(k).optional(),
|
|
144
145
|
vitepressConfig: l.string().describe(d.shape.vitepressConfig.description || "").optional()
|
|
145
146
|
});
|
|
146
|
-
function
|
|
147
|
+
function Ze(e) {
|
|
147
148
|
return e ? (e.usernames && typeof e.usernames == "string" && (e.usernames = [e.usernames]), e.reposFilter && typeof e.reposFilter == "string" && (e.reposFilter = [e.reposFilter]), e.extraHeaderPages && typeof e.extraHeaderPages == "string" && (e.extraHeaderPages = [e.extraHeaderPages]), e.extraPublicContent && typeof e.extraPublicContent == "string" && (e.extraPublicContent = [e.extraPublicContent]), e.extraTheme && typeof e.extraTheme == "string" && (e.extraTheme = [e.extraTheme]), e) : {};
|
|
148
149
|
}
|
|
149
|
-
function
|
|
150
|
+
function et(e) {
|
|
150
151
|
if (!e.usernames?.length)
|
|
151
152
|
throw new Error("The usernames field is required");
|
|
152
153
|
return e;
|
|
153
154
|
}
|
|
154
|
-
const
|
|
155
|
+
const tt = I.partial().transform((e) => {
|
|
155
156
|
try {
|
|
156
157
|
const { config: t, vitepressConfig: r, token: o, ...s } = e;
|
|
157
158
|
a(`Debug: Schema transform input: ${JSON.stringify(e)}`, "debug");
|
|
158
|
-
const i = W(t), n =
|
|
159
|
+
const i = W(t), n = Ze(i), c = {
|
|
159
160
|
forks: !1,
|
|
160
161
|
...n,
|
|
161
162
|
...s,
|
|
@@ -166,18 +167,18 @@ const et = I.partial().transform((e) => {
|
|
|
166
167
|
}
|
|
167
168
|
} : {}
|
|
168
169
|
};
|
|
169
|
-
return a(`Debug: Final merged config: ${JSON.stringify(c)}`, "debug"),
|
|
170
|
+
return a(`Debug: Final merged config: ${JSON.stringify(c)}`, "debug"), et({ ...c, token: o });
|
|
170
171
|
} catch (t) {
|
|
171
172
|
a(" An error occurred while checking configuration.", "error"), t instanceof Error ? a(` ${t.message}`, "error") : a(` ${JSON.stringify(t, null, 2)}`, "error"), process.exit(1);
|
|
172
173
|
}
|
|
173
|
-
}),
|
|
174
|
+
}), rt = I.pick({}), ot = I.pick({
|
|
174
175
|
branch: !0,
|
|
175
176
|
config: !0,
|
|
176
177
|
gitProvider: !0,
|
|
177
178
|
reposFilter: !0,
|
|
178
179
|
token: !0,
|
|
179
180
|
usernames: !0
|
|
180
|
-
}),
|
|
181
|
+
}), st = I.pick({
|
|
181
182
|
extraHeaderPages: !0,
|
|
182
183
|
extraPublicContent: !0,
|
|
183
184
|
extraTheme: !0,
|
|
@@ -187,13 +188,13 @@ const et = I.partial().transform((e) => {
|
|
|
187
188
|
token: !0,
|
|
188
189
|
usernames: !0,
|
|
189
190
|
vitepressConfig: !0
|
|
190
|
-
}),
|
|
191
|
-
build:
|
|
192
|
-
fetch:
|
|
193
|
-
prepare:
|
|
194
|
-
global:
|
|
191
|
+
}), nt = {
|
|
192
|
+
build: rt,
|
|
193
|
+
fetch: ot,
|
|
194
|
+
prepare: st,
|
|
195
|
+
global: tt
|
|
195
196
|
};
|
|
196
|
-
function
|
|
197
|
+
function it(e, t) {
|
|
197
198
|
const r = W(e);
|
|
198
199
|
if (!r) return null;
|
|
199
200
|
const o = d.partial().safeParse(r);
|
|
@@ -209,14 +210,14 @@ function K(e, t) {
|
|
|
209
210
|
-> Checking for required environment settings and configurations.`, "info"), a(` Debug info - opts: ${JSON.stringify(t)}`, "debug"), a(` Debug info - options[cmd]: ${e}`, "debug");
|
|
210
211
|
try {
|
|
211
212
|
if (e === "global" && typeof t.config == "string") {
|
|
212
|
-
const o =
|
|
213
|
+
const o = it(
|
|
213
214
|
t.config,
|
|
214
215
|
typeof t.token == "string" ? t.token : void 0
|
|
215
216
|
);
|
|
216
217
|
if (o)
|
|
217
218
|
return o;
|
|
218
219
|
}
|
|
219
|
-
const r =
|
|
220
|
+
const r = nt[e].safeParse(t);
|
|
220
221
|
if (!r.success) {
|
|
221
222
|
try {
|
|
222
223
|
const o = Re(r.error).toString();
|
|
@@ -238,7 +239,7 @@ function j(e, t) {
|
|
|
238
239
|
e.addOption(r);
|
|
239
240
|
return e;
|
|
240
241
|
}
|
|
241
|
-
async function
|
|
242
|
+
async function at({ username: e, token: t, branch: r }) {
|
|
242
243
|
a(` Get infos for username '${e}'.`, "info");
|
|
243
244
|
const o = new de({ auth: t });
|
|
244
245
|
a(" Get user infos.", "debug");
|
|
@@ -247,7 +248,7 @@ async function it({ username: e, token: t, branch: r }) {
|
|
|
247
248
|
const { data: i } = await o.rest.repos.listForUser({ username: e, sort: "full_name", per_page: 500 });
|
|
248
249
|
return { user: s, repos: i, branch: r };
|
|
249
250
|
}
|
|
250
|
-
async function
|
|
251
|
+
async function ct({
|
|
251
252
|
repository: e,
|
|
252
253
|
token: t
|
|
253
254
|
}) {
|
|
@@ -291,7 +292,7 @@ async function at({
|
|
|
291
292
|
}
|
|
292
293
|
return { source: o.source, contributors: s };
|
|
293
294
|
}
|
|
294
|
-
async function
|
|
295
|
+
async function ut(e, t, r, o, s) {
|
|
295
296
|
F(r, { clean: !0 });
|
|
296
297
|
try {
|
|
297
298
|
const i = _e({ baseDir: r });
|
|
@@ -304,7 +305,7 @@ async function ct(e, t, r, o, s) {
|
|
|
304
305
|
a(` Error when cloning repository: ${i}.`, "error");
|
|
305
306
|
}
|
|
306
307
|
}
|
|
307
|
-
async function
|
|
308
|
+
async function lt(e, t, r) {
|
|
308
309
|
const o = `https://github.com/${e}/${t}/tree/${r}/README.md`, s = `https://github.com/${e}/${t}/tree/${r}/docs`, i = `https://github.com/${e}/${t}/tree/${r}/docs/01-readme.md`, n = await G(o), c = await G(s), p = await G(i);
|
|
309
310
|
return {
|
|
310
311
|
rootReadmeStatus: n,
|
|
@@ -312,16 +313,16 @@ async function ut(e, t, r) {
|
|
|
312
313
|
docsReadmeStatus: p
|
|
313
314
|
};
|
|
314
315
|
}
|
|
315
|
-
async function
|
|
316
|
-
await
|
|
316
|
+
async function dt({ username: e, branch: t, reposFilter: r, token: o }) {
|
|
317
|
+
await at({ username: e, token: o, branch: t }).then(async ({ user: s, repos: i, branch: n }) => mt(s, i, n, r)).then(async ({ repos: s }) => gt(s, r));
|
|
317
318
|
}
|
|
318
|
-
async function
|
|
319
|
+
async function pt(e, t, r) {
|
|
319
320
|
const o = [];
|
|
320
321
|
return await Promise.all(
|
|
321
322
|
e.map(async (s) => {
|
|
322
323
|
const i = t ?? s.default_branch ?? "main", n = u(pe, f(s.name, { removeDot: !0 })), c = me(s, r);
|
|
323
324
|
let p = [];
|
|
324
|
-
!s.fork && !s.private && !c && (p = await
|
|
325
|
+
!s.fork && !s.private && !c && (p = await ft(s, i)), o.push({
|
|
325
326
|
...s,
|
|
326
327
|
docpress: {
|
|
327
328
|
filtered: c,
|
|
@@ -335,23 +336,23 @@ async function dt(e, t, r) {
|
|
|
335
336
|
})
|
|
336
337
|
), o;
|
|
337
338
|
}
|
|
338
|
-
async function
|
|
339
|
-
const r = await
|
|
339
|
+
async function ft(e, t) {
|
|
340
|
+
const r = await lt(e.owner.login, e.name, t), o = [];
|
|
340
341
|
return Object.values(r).every((s) => s === 404) || !e.size ? [] : (r.docsFolderStatus !== 404 && o.push("docs/*"), (r.docsFolderStatus === 404 || r.docsReadmeStatus === 404) && o.push("README.md", "!*/**/README.md"), o);
|
|
341
342
|
}
|
|
342
|
-
async function
|
|
343
|
-
v(`${
|
|
344
|
-
const s = await
|
|
345
|
-
return v(`${
|
|
343
|
+
async function mt(e, t, r, o) {
|
|
344
|
+
v(`${C}/user-${e.login}.json`, JSON.stringify(e, null, 2));
|
|
345
|
+
const s = await pt(t, r, o);
|
|
346
|
+
return v(`${C}/repos-${e.login}.json`, JSON.stringify(s, null, 2)), { user: e, repos: s };
|
|
346
347
|
}
|
|
347
|
-
async function
|
|
348
|
+
async function gt(e, t) {
|
|
348
349
|
if (!e) {
|
|
349
350
|
a(" No repository respect docpress rules.", "warn");
|
|
350
351
|
return;
|
|
351
352
|
}
|
|
352
353
|
await Promise.all(
|
|
353
354
|
e.filter((r) => !me(r, t)).map(async (r) => {
|
|
354
|
-
await
|
|
355
|
+
await ut(r.name, r.clone_url, r.docpress.projectPath, r.docpress.branch, r.docpress.includes);
|
|
355
356
|
})
|
|
356
357
|
);
|
|
357
358
|
}
|
|
@@ -360,27 +361,27 @@ function me(e, t) {
|
|
|
360
361
|
return "docpress" in e && !e.docpress.includes.length ? !0 : !(e.clone_url && !e.private && !i);
|
|
361
362
|
}
|
|
362
363
|
const L = [
|
|
363
|
-
m("-C, --config <string>",
|
|
364
|
-
m("-T, --token <string>",
|
|
365
|
-
m("-U, --usernames <string>",
|
|
364
|
+
m("-C, --config <string>", H.shape.config.description),
|
|
365
|
+
m("-T, --token <string>", H.shape.token.description),
|
|
366
|
+
m("-U, --usernames <string>", H.shape.usernames.description)
|
|
366
367
|
], ne = "fetch", ge = [
|
|
367
368
|
m("-b, --branch <string>", d.shape.branch.description).default(d.shape.branch.default),
|
|
368
369
|
m("-g, --git-provider <string>", d.shape.gitProvider.description).default(d.shape.gitProvider.default),
|
|
369
370
|
m("-r, --repos-filter <string>", d.shape.reposFilter.description)
|
|
370
|
-
],
|
|
371
|
+
], ht = j(J(ne), [...ge, ...L]).description("Fetch docs with the given username(s) and git provider.").action(async (e) => {
|
|
371
372
|
const t = K(ne, e);
|
|
372
373
|
await he(t);
|
|
373
374
|
});
|
|
374
375
|
async function he(e) {
|
|
375
376
|
const { usernames: t, reposFilter: r, token: o, branch: s, gitProvider: i } = e;
|
|
376
377
|
a(`
|
|
377
|
-
-> Start fetching documentation files. This may take a moment, especially for larger repositories.`, "info"), F(
|
|
378
|
+
-> Start fetching documentation files. This may take a moment, especially for larger repositories.`, "info"), F(C, { clean: !0 });
|
|
378
379
|
for (const n of t) {
|
|
379
380
|
const c = t.length > 1 ? r?.filter((p) => p.startsWith(`${n}/`)).map((p) => p.replace(`${n}/`, "")) : r;
|
|
380
|
-
await
|
|
381
|
+
await dt({ username: n, branch: s, reposFilter: c, token: o });
|
|
381
382
|
}
|
|
382
383
|
}
|
|
383
|
-
async function
|
|
384
|
+
async function bt(e) {
|
|
384
385
|
const t = console.warn;
|
|
385
386
|
console.warn = function(...r) {
|
|
386
387
|
r.length > 0 && typeof r[0] == "string" && (r[0].includes("[Vue warn]: Invalid watch source:") || r[0].includes("{ open: false }")) || t.apply(console, r);
|
|
@@ -391,7 +392,7 @@ async function ht(e) {
|
|
|
391
392
|
console.warn = t;
|
|
392
393
|
}
|
|
393
394
|
}
|
|
394
|
-
const
|
|
395
|
+
const wt = "build", yt = j(J(wt), L).description("Build vitepress website.").action(async (e) => {
|
|
395
396
|
await be();
|
|
396
397
|
});
|
|
397
398
|
async function be() {
|
|
@@ -400,8 +401,12 @@ async function be() {
|
|
|
400
401
|
|
|
401
402
|
`, "info");
|
|
402
403
|
try {
|
|
403
|
-
await
|
|
404
|
-
await Ae(
|
|
404
|
+
await bt(async () => {
|
|
405
|
+
await Ae(C, {
|
|
406
|
+
onAfterConfigResolve(e) {
|
|
407
|
+
Ie(e);
|
|
408
|
+
}
|
|
409
|
+
});
|
|
405
410
|
}), a(`
|
|
406
411
|
|
|
407
412
|
Docpress build succedeed.`, "success");
|
|
@@ -411,8 +416,8 @@ Docpress build succedeed.`, "success");
|
|
|
411
416
|
Docpress build failed : ${e}`, "error"), process.exit(1);
|
|
412
417
|
}
|
|
413
418
|
}
|
|
414
|
-
function
|
|
415
|
-
const r =
|
|
419
|
+
function vt(e, t) {
|
|
420
|
+
const r = S(e, { encoding: "utf8" });
|
|
416
421
|
F(_(t)), v(t, r);
|
|
417
422
|
}
|
|
418
423
|
const ie = {
|
|
@@ -452,23 +457,23 @@ const ie = {
|
|
|
452
457
|
}
|
|
453
458
|
}
|
|
454
459
|
};
|
|
455
|
-
function
|
|
460
|
+
function $t(e, t, r) {
|
|
456
461
|
return r ? U(ie, r, { themeConfig: { sidebar: e, nav: t } }) : U(ie, { themeConfig: { sidebar: e, nav: t } });
|
|
457
462
|
}
|
|
458
|
-
async function
|
|
459
|
-
const h =
|
|
460
|
-
const { clone_url: P, private:
|
|
461
|
-
if (P && !
|
|
463
|
+
async function xt({ extraHeaderPages: e, extraPublicContent: t, extraTheme: r, vitepressConfig: o, forks: s, token: i, username: n, websiteTitle: c, websiteTagline: p }) {
|
|
464
|
+
const h = qe(n), b = Ke(n).reduce(({ internals: w, forks: $ }, x) => {
|
|
465
|
+
const { clone_url: P, private: Se, fork: Y, docpress: Q } = x;
|
|
466
|
+
if (P && !Se && !Q.filtered) {
|
|
462
467
|
if (!Y && Q.includes.length)
|
|
463
468
|
return { internals: [...w, x], forks: $ };
|
|
464
469
|
if (Y)
|
|
465
470
|
return { internals: w, forks: [...$, x] };
|
|
466
471
|
}
|
|
467
472
|
return { internals: w, forks: $ };
|
|
468
|
-
}, { internals: [], forks: [] }), g = { title: c, tagline: p }, { index: V, sidebar: X } =
|
|
473
|
+
}, { internals: [], forks: [] }), g = { title: c, tagline: p }, { index: V, sidebar: X } = Ft(b.internals, h, g);
|
|
469
474
|
let N, D;
|
|
470
|
-
if (O(
|
|
471
|
-
const w = await
|
|
475
|
+
if (O(M) && O(E)) {
|
|
476
|
+
const w = await _t(E), $ = await At(M);
|
|
472
477
|
N = [
|
|
473
478
|
...w.themeConfig?.sidebar ?? [],
|
|
474
479
|
...X
|
|
@@ -483,14 +488,14 @@ async function $t({ extraHeaderPages: e, extraPublicContent: t, extraTheme: r, v
|
|
|
483
488
|
N = X, D = V;
|
|
484
489
|
const T = [];
|
|
485
490
|
if (e) {
|
|
486
|
-
const w =
|
|
491
|
+
const w = Tt(e);
|
|
487
492
|
s ? T.push(...w.filter(($) => $.link !== "/forks")) : T.push(...w);
|
|
488
493
|
}
|
|
489
|
-
t && (a(" Add extras Vitepress public folder content.", "info"), ae(t, u(
|
|
490
|
-
const
|
|
491
|
-
|
|
494
|
+
t && (a(" Add extras Vitepress public folder content.", "info"), ae(t, u(C, "public"))), r && (a(" Add extras Vitepress theme files.", "info"), ae(r, u(Ge))), s && n.length && (a(" Add fork page to display external contributions.", "info"), await Rt(b.forks, n, i), T.push({ text: "Forks", link: "/forks" }));
|
|
495
|
+
const Ce = $t(N, T, o);
|
|
496
|
+
It(Ce, D);
|
|
492
497
|
}
|
|
493
|
-
function
|
|
498
|
+
function Ct(e, t) {
|
|
494
499
|
const r = y(t), s = `${f(r, { mode: "lowercase", removeIdx: !0 }) === "readme.md" ? `
|
|
495
500
|
## Sources` : "# Sources"}
|
|
496
501
|
|
|
@@ -506,7 +511,7 @@ function St(e, t, r) {
|
|
|
506
511
|
features: e
|
|
507
512
|
};
|
|
508
513
|
}
|
|
509
|
-
function
|
|
514
|
+
function Pt(e, t, r) {
|
|
510
515
|
const o = {
|
|
511
516
|
title: f(e, { mode: "capitalize", replaceDash: !0 }),
|
|
512
517
|
details: t,
|
|
@@ -514,7 +519,7 @@ function Ct(e, t, r) {
|
|
|
514
519
|
};
|
|
515
520
|
return r ? [...r, o] : [o];
|
|
516
521
|
}
|
|
517
|
-
function
|
|
522
|
+
function kt(e, t) {
|
|
518
523
|
return {
|
|
519
524
|
text: f(e, { mode: "capitalize", replaceDash: !0 }),
|
|
520
525
|
collapsed: !0,
|
|
@@ -547,7 +552,7 @@ function ye(e) {
|
|
|
547
552
|
function ve(e, t = "") {
|
|
548
553
|
return Object.entries(e).flatMap(([r, o]) => r === "$" ? Array.isArray(o) ? o.map((s) => t ? `${t}/${s}` : s) : [] : ve(o, t ? `${t}/${r}` : r));
|
|
549
554
|
}
|
|
550
|
-
function
|
|
555
|
+
function Et(e) {
|
|
551
556
|
if (!Array.isArray(e))
|
|
552
557
|
return e;
|
|
553
558
|
const t = e.findIndex((o) => o.text === "Sources");
|
|
@@ -556,18 +561,18 @@ function kt(e) {
|
|
|
556
561
|
const [r] = e.splice(t, 1);
|
|
557
562
|
return e.push(r), e;
|
|
558
563
|
}
|
|
559
|
-
function
|
|
564
|
+
function Ft(e, t, r) {
|
|
560
565
|
const o = [], s = [];
|
|
561
566
|
for (const n of e) {
|
|
562
567
|
a(` Replace urls for repository '${n.name}'.`, "info"), fe([n.docpress.projectPath]).forEach((g) => {
|
|
563
|
-
a(` Processing file '${y(g)}' for repository '${n.name}'.`, "debug"),
|
|
568
|
+
a(` Processing file '${y(g)}' for repository '${n.name}'.`, "debug"), Xe(g, `https://github.com/${n.owner.login}/${n.name}/tree/${n.docpress.branch}`), y(g).toLowerCase() === "readme.md" && Ye(g, `https://github.com/${n.owner.login}/${n.name}/tree/${n.docpress.branch}`);
|
|
564
569
|
}), a(` Generate sidebar for repository '${n.name}'.`, "info");
|
|
565
570
|
const c = ue(n.docpress.projectPath, { recursive: !0 }).filter((g) => z(u(n.docpress.projectPath, g.toString())).isFile() && y(u(n.docpress.projectPath, g.toString())).endsWith(".md"));
|
|
566
571
|
a(` Add sources for repository '${n.name}'.`, "info");
|
|
567
572
|
let p;
|
|
568
|
-
c.length > 1 ? (p = u(n.docpress.projectPath, "sources.md"), c.push("sources.md")) : p = u(n.docpress.projectPath, c[0]),
|
|
569
|
-
const h = ye(c), b =
|
|
570
|
-
s.push(
|
|
573
|
+
c.length > 1 ? (p = u(n.docpress.projectPath, "sources.md"), c.push("sources.md")) : p = u(n.docpress.projectPath, c[0]), Ct(n.html_url, p);
|
|
574
|
+
const h = ye(c), b = Et(we(n, h));
|
|
575
|
+
s.push(kt(f(n.name, { removeDot: !0 }), b)), o.push(...Pt(f(n.name, { removeDot: !0 }), n.description || ""));
|
|
571
576
|
}
|
|
572
577
|
a(" Generate index content.", "info");
|
|
573
578
|
const i = St(o.toSorted((n, c) => n.title.localeCompare(c.title)), t, r);
|
|
@@ -576,7 +581,7 @@ function Et(e, t, r) {
|
|
|
576
581
|
index: i
|
|
577
582
|
};
|
|
578
583
|
}
|
|
579
|
-
function
|
|
584
|
+
function Tt(e) {
|
|
580
585
|
const t = fe(e), r = [];
|
|
581
586
|
a(" Add extras Vitepress headers pages.", "info");
|
|
582
587
|
for (const o of t) {
|
|
@@ -600,7 +605,7 @@ function ae(e, t, r) {
|
|
|
600
605
|
}
|
|
601
606
|
}
|
|
602
607
|
}
|
|
603
|
-
function
|
|
608
|
+
function Ot(e) {
|
|
604
609
|
const t = `---
|
|
605
610
|
`, r = `layout: fork-page
|
|
606
611
|
repoList:
|
|
@@ -616,39 +621,37 @@ This page serves as both a portfolio of past work and a resource for revisiting
|
|
|
616
621
|
const { name: c, owner: p, html_url: h, description: b, stargazers_count: g } = i;
|
|
617
622
|
return { name: c, owner: p.login, html_url: h, description: b, stargazers_count: g, contributions: n };
|
|
618
623
|
});
|
|
619
|
-
a(" Generate forks page.", "info"), v(
|
|
624
|
+
a(" Generate forks page.", "info"), v(Ne, t + r + q.stringify(s) + t + o);
|
|
620
625
|
}
|
|
621
|
-
async function
|
|
626
|
+
async function Rt(e, t, r) {
|
|
622
627
|
const o = await Promise.all(
|
|
623
628
|
e.map(async (s) => {
|
|
624
|
-
const { source: i, contributors: n } = await
|
|
629
|
+
const { source: i, contributors: n } = await ct({ repository: s, token: r });
|
|
625
630
|
return {
|
|
626
631
|
contributions: n?.find((c) => c.login === t)?.contributions ?? 0,
|
|
627
632
|
repository: i
|
|
628
633
|
};
|
|
629
634
|
})
|
|
630
635
|
).then((s) => s.filter(({ repository: i, contributions: n }) => !!i && n));
|
|
631
|
-
|
|
636
|
+
Ot(o);
|
|
632
637
|
}
|
|
633
|
-
async function
|
|
638
|
+
async function _t(e) {
|
|
634
639
|
const { config: t } = await import(u(process.cwd(), e)).catch((r) => r);
|
|
635
640
|
return t;
|
|
636
641
|
}
|
|
637
|
-
async function
|
|
638
|
-
const t = (await
|
|
642
|
+
async function At(e) {
|
|
643
|
+
const t = (await je(u(process.cwd(), e))).toString();
|
|
639
644
|
return q.parse(t);
|
|
640
645
|
}
|
|
641
|
-
function
|
|
646
|
+
function It(e, t) {
|
|
642
647
|
const r = `---
|
|
643
648
|
`;
|
|
644
|
-
return F(_(E)), a(" Generate Vitepress config.", "info"), v(E, `
|
|
645
|
-
|
|
646
|
-
export const config = withMermaid(${JSON.stringify(e, null, 2)})
|
|
649
|
+
return F(_(E)), a(" Generate Vitepress config.", "info"), v(E, `export const config = ${JSON.stringify(e, null, 2)}
|
|
647
650
|
|
|
648
651
|
export default config
|
|
649
|
-
`), a(" Generate index file.", "info"), v(
|
|
652
|
+
`), a(" Generate index file.", "info"), v(M, r + q.stringify(t)), a(" Add Docpress theme files.", "info"), A(te).forEach((o) => {
|
|
650
653
|
const s = o.replace(`${te}/`, "");
|
|
651
|
-
|
|
654
|
+
vt(o, u(De, s));
|
|
652
655
|
});
|
|
653
656
|
}
|
|
654
657
|
const ce = "prepare", $e = [
|
|
@@ -659,7 +662,7 @@ const ce = "prepare", $e = [
|
|
|
659
662
|
m("-v, --vitepress-config <string>", d.shape.vitepressConfig.description),
|
|
660
663
|
m("--website-title <string>", d.shape.websiteTitle.description),
|
|
661
664
|
m("--website-tagline <string>", d.shape.websiteTagline.description)
|
|
662
|
-
],
|
|
665
|
+
], jt = j(J(ce), [...$e, ...L]).description("Transform doc to the target vitepress format.").action(async (e) => {
|
|
663
666
|
const t = K(ce, e);
|
|
664
667
|
await xe(t);
|
|
665
668
|
});
|
|
@@ -668,31 +671,31 @@ async function xe(e) {
|
|
|
668
671
|
a(`
|
|
669
672
|
-> Start transform files to prepare Vitepress build.`, "info"), F(_(E), { clean: !0 });
|
|
670
673
|
for (const b of c)
|
|
671
|
-
await
|
|
674
|
+
await xt({ extraHeaderPages: t, extraPublicContent: r, extraTheme: o, vitepressConfig: s, forks: i, token: n, username: b, websiteTitle: p, websiteTagline: h });
|
|
672
675
|
}
|
|
673
|
-
function
|
|
676
|
+
function Lt(e) {
|
|
674
677
|
return {
|
|
675
678
|
...e,
|
|
676
679
|
branch: "main",
|
|
677
680
|
gitProvider: "github"
|
|
678
681
|
};
|
|
679
682
|
}
|
|
680
|
-
function
|
|
681
|
-
const e = new Pe().name("docpress").description("Build your doc website faster than light ⚡️⚡️⚡️").version(`${
|
|
682
|
-
const o =
|
|
683
|
+
function Vt() {
|
|
684
|
+
const e = new Pe().name("docpress").description("Build your doc website faster than light ⚡️⚡️⚡️").version(`${Ve.version}`).action(async (t, r) => {
|
|
685
|
+
const o = Lt(t), s = K("global", o);
|
|
683
686
|
await he(s), await xe(s), await be();
|
|
684
687
|
}).configureHelp({
|
|
685
688
|
sortSubcommands: !0,
|
|
686
689
|
sortOptions: !0,
|
|
687
690
|
showGlobalOptions: !0
|
|
688
|
-
}).enablePositionalOptions().passThroughOptions().addCommand(
|
|
691
|
+
}).enablePositionalOptions().passThroughOptions().addCommand(ht).addCommand(jt).addCommand(yt);
|
|
689
692
|
return j(e, [...ge, ...$e, ...L]), e;
|
|
690
693
|
}
|
|
691
|
-
function
|
|
692
|
-
|
|
694
|
+
function Qt() {
|
|
695
|
+
Vt().parseAsync(process.argv);
|
|
693
696
|
}
|
|
694
697
|
export {
|
|
695
|
-
|
|
696
|
-
|
|
698
|
+
Vt as getProgram,
|
|
699
|
+
Qt as main
|
|
697
700
|
};
|
|
698
701
|
//# sourceMappingURL=cli.js.map
|