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