@tobi-or-not/docpress 0.1.6 → 0.2.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 +222 -27
- package/dist/cli.js +303 -248
- package/dist/cli.js.map +1 -1
- package/package.json +5 -3
- package/types/utils/commands.d.ts +2 -1
- package/types/utils/logger.d.ts +4 -0
package/dist/cli.js
CHANGED
|
@@ -1,28 +1,30 @@
|
|
|
1
|
-
import { createOption as
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
|
|
1
|
+
import { createOption as f, createCommand as D, Command as le } from "commander";
|
|
2
|
+
import T from "chalk";
|
|
3
|
+
import { fromError as pe } from "zod-validation-error";
|
|
4
|
+
import { readFileSync as w, existsSync as G, mkdirSync as ue, readdirSync as Y, statSync as L, appendFileSync as K, cpSync as j, rmSync as A, writeFileSync as y, renameSync as fe } from "node:fs";
|
|
5
|
+
import { resolve as c, join as me, basename as g, dirname as Q, parse as $ } from "node:path";
|
|
6
|
+
import { z as l } from "zod";
|
|
7
|
+
import ge from "axios";
|
|
8
|
+
import { rimrafSync as he } from "rimraf";
|
|
9
|
+
import { Octokit as be } from "octokit";
|
|
10
|
+
import { simpleGit as ve } from "simple-git";
|
|
11
|
+
import { build as ye } from "vitepress";
|
|
12
|
+
import we from "yaml";
|
|
13
|
+
const Se = "@tobi-or-not/docpress", $e = "module", xe = "0.2.0", Ce = "pnpm@9.12.3", ke = "dist/docpress.js", _e = "types/index.d.ts", Oe = {
|
|
12
14
|
docpress: "bin/docpress.js"
|
|
13
|
-
},
|
|
15
|
+
}, Pe = [
|
|
14
16
|
"bin",
|
|
15
17
|
"dist",
|
|
16
18
|
"types"
|
|
17
|
-
],
|
|
19
|
+
], Ee = {
|
|
18
20
|
node: ">=20"
|
|
19
|
-
},
|
|
21
|
+
}, Re = {
|
|
20
22
|
build: "pnpm run build:types && pnpm run build:vite",
|
|
21
23
|
"build:clean": "rimraf ./dist ./types ./tsconfig.tsbuildinfo",
|
|
22
24
|
"build:docker": "docker build --tag tobi-or-not/docpress --target prod .",
|
|
23
25
|
"build:types": "tsc",
|
|
24
26
|
"build:vite": "vite build",
|
|
25
|
-
dev: "vite-node ./dev/docpress.ts",
|
|
27
|
+
dev: "rimraf ./docpress && vite-node ./dev/docpress.ts",
|
|
26
28
|
format: "eslint . --fix",
|
|
27
29
|
lint: "eslint .",
|
|
28
30
|
prepare: "husky",
|
|
@@ -36,16 +38,18 @@ const he = "@tobi-or-not/docpress", be = "module", ve = "0.1.6", ye = "pnpm@9.12
|
|
|
36
38
|
"vp:dev": "vitepress dev ./docpress --port 8080",
|
|
37
39
|
"vp:dev:docker": "docker run --publish 8080:8080 --name docpress-vp --rm tobi-or-not/docs",
|
|
38
40
|
"vp:preview": "vitepress preview ./docpress --port 8080"
|
|
39
|
-
},
|
|
41
|
+
}, De = {
|
|
40
42
|
axios: "^1.7.7",
|
|
43
|
+
chalk: "^5.3.0",
|
|
41
44
|
commander: "^12.1.0",
|
|
42
45
|
octokit: "^4.0.2",
|
|
43
46
|
rimraf: "^6.0.1",
|
|
44
47
|
"simple-git": "^3.27.0",
|
|
45
48
|
vitepress: "^1.4.1",
|
|
46
49
|
yaml: "^2.6.0",
|
|
47
|
-
zod: "^3.23.8"
|
|
48
|
-
|
|
50
|
+
zod: "^3.23.8",
|
|
51
|
+
"zod-validation-error": "^3.4.0"
|
|
52
|
+
}, Le = {
|
|
49
53
|
"@antfu/eslint-config": "^3.8.0",
|
|
50
54
|
"@commitlint/cli": "^19.5.0",
|
|
51
55
|
"@commitlint/config-conventional": "^19.5.0",
|
|
@@ -58,198 +62,249 @@ const he = "@tobi-or-not/docpress", be = "module", ve = "0.1.6", ye = "pnpm@9.12
|
|
|
58
62
|
vite: "^5.4.9",
|
|
59
63
|
"vite-node": "^2.1.3",
|
|
60
64
|
vitest: "^2.1.3"
|
|
61
|
-
},
|
|
65
|
+
}, je = {
|
|
62
66
|
registry: "https://registry.npmjs.org/",
|
|
63
67
|
access: "public",
|
|
64
68
|
tag: "latest"
|
|
65
|
-
},
|
|
66
|
-
name:
|
|
67
|
-
type:
|
|
68
|
-
version:
|
|
69
|
-
packageManager:
|
|
70
|
-
module:
|
|
71
|
-
types:
|
|
72
|
-
bin:
|
|
73
|
-
files:
|
|
74
|
-
engines:
|
|
75
|
-
scripts:
|
|
76
|
-
dependencies:
|
|
77
|
-
devDependencies:
|
|
78
|
-
publishConfig:
|
|
79
|
-
}
|
|
69
|
+
}, Fe = {
|
|
70
|
+
name: Se,
|
|
71
|
+
type: $e,
|
|
72
|
+
version: xe,
|
|
73
|
+
packageManager: Ce,
|
|
74
|
+
module: ke,
|
|
75
|
+
types: _e,
|
|
76
|
+
bin: Oe,
|
|
77
|
+
files: Pe,
|
|
78
|
+
engines: Ee,
|
|
79
|
+
scripts: Re,
|
|
80
|
+
dependencies: De,
|
|
81
|
+
devDependencies: Le,
|
|
82
|
+
publishConfig: je
|
|
83
|
+
};
|
|
84
|
+
function Ie() {
|
|
85
|
+
return typeof Number(process.env.LOG_LEVEL) == "number" && !Number.isNaN(Number(process.env.LOG_LEVEL)) ? Number(process.env.LOG_LEVEL) : 30;
|
|
86
|
+
}
|
|
87
|
+
const M = {
|
|
88
|
+
info: { color: "white", level: 30 },
|
|
89
|
+
warn: { color: "yellow", level: 20 },
|
|
90
|
+
error: { color: "red", level: 10 },
|
|
91
|
+
debug: { color: "blue", level: 50 },
|
|
92
|
+
trace: { color: "white", level: 40 },
|
|
93
|
+
success: { color: "green", level: 30 }
|
|
94
|
+
};
|
|
95
|
+
function d(e, t = "info", r) {
|
|
96
|
+
const n = r ? T[r](e) : T[M[t].color](e), o = t === "success" ? "info" : t;
|
|
97
|
+
Ie() >= M[t].level && console[o](n);
|
|
98
|
+
}
|
|
99
|
+
const Z = l.object({}), k = c(process.cwd(), "docpress"), ee = c(process.cwd(), "docpress/repositories.json"), te = c(process.cwd(), "docpress/owner.json"), re = c(process.cwd(), "docpress/docs"), Ve = c(process.cwd(), "docpress/docs/index.md"), U = c(process.cwd(), "docpress/.vitepress/config.ts");
|
|
80
100
|
async function P(e) {
|
|
81
101
|
try {
|
|
82
|
-
return (await
|
|
102
|
+
return (await ge.head(e)).status;
|
|
83
103
|
} catch (t) {
|
|
84
104
|
return t.response?.status || t.status || 500;
|
|
85
105
|
}
|
|
86
106
|
}
|
|
87
|
-
function
|
|
88
|
-
let
|
|
89
|
-
return t?.removeIdx && (
|
|
107
|
+
function b(e, t) {
|
|
108
|
+
let r = "";
|
|
109
|
+
return t?.removeIdx && (r = e.replace(/^\d{2}-/, "")), 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;
|
|
90
110
|
}
|
|
91
111
|
function F(e, { clean: t } = { clean: !1 }) {
|
|
92
112
|
try {
|
|
93
|
-
t &&
|
|
94
|
-
} catch (
|
|
95
|
-
console.error(
|
|
113
|
+
t && G(e) && he(`${e}/*`, { glob: !0 }), G(e) || ue(e, { recursive: !0 });
|
|
114
|
+
} catch (r) {
|
|
115
|
+
console.error(r);
|
|
96
116
|
}
|
|
97
117
|
}
|
|
98
|
-
function
|
|
99
|
-
|
|
118
|
+
function Ne(e) {
|
|
119
|
+
try {
|
|
120
|
+
return L(e).isDirectory();
|
|
121
|
+
} catch {
|
|
122
|
+
return !1;
|
|
123
|
+
}
|
|
100
124
|
}
|
|
101
|
-
function
|
|
102
|
-
|
|
125
|
+
function Te(e) {
|
|
126
|
+
try {
|
|
127
|
+
return L(e).isFile();
|
|
128
|
+
} catch {
|
|
129
|
+
return !1;
|
|
130
|
+
}
|
|
103
131
|
}
|
|
104
|
-
function
|
|
105
|
-
return (Array.isArray(e) ? e : [e]).flatMap((t) =>
|
|
132
|
+
function I(e) {
|
|
133
|
+
return (Array.isArray(e) ? e : [e]).flatMap((t) => Te(t) ? [t] : Ne(t) ? Y(t).flatMap((r) => I(me(t, r))) : []);
|
|
106
134
|
}
|
|
107
|
-
function
|
|
108
|
-
return
|
|
135
|
+
function se(e) {
|
|
136
|
+
return I(e).filter((t) => g(t).endsWith(".md"));
|
|
109
137
|
}
|
|
110
|
-
function
|
|
111
|
-
return e.reduce((t,
|
|
138
|
+
function Ge(e) {
|
|
139
|
+
return e.reduce((t, r, n, o) => n ? n === o.length - 1 ? `${t} or "${r}"` : `${t}, "${r}"` : `"${r}"`, "");
|
|
112
140
|
}
|
|
113
|
-
function
|
|
114
|
-
return JSON.parse(
|
|
141
|
+
function Ae() {
|
|
142
|
+
return JSON.parse(w(te).toString());
|
|
115
143
|
}
|
|
116
|
-
function
|
|
117
|
-
return JSON.parse(
|
|
144
|
+
function Me() {
|
|
145
|
+
return JSON.parse(w(ee).toString());
|
|
118
146
|
}
|
|
119
|
-
function
|
|
120
|
-
return e.reduce((t,
|
|
121
|
-
const
|
|
122
|
-
|
|
147
|
+
function R(...e) {
|
|
148
|
+
return e.reduce((t, r) => (r === null || Object.keys(r).forEach((n) => {
|
|
149
|
+
const o = t ? t[n] : null, s = r[n];
|
|
150
|
+
z(o) && z(s) ? t[n] = R(o, s) : t[n] = s;
|
|
123
151
|
}), t), {});
|
|
124
152
|
}
|
|
125
|
-
function
|
|
153
|
+
function z(e) {
|
|
126
154
|
return e && typeof e == "object" && !Array.isArray(e);
|
|
127
155
|
}
|
|
128
|
-
const
|
|
129
|
-
branch:
|
|
130
|
-
gitProvider:
|
|
131
|
-
reposFilter:
|
|
132
|
-
token:
|
|
133
|
-
username:
|
|
134
|
-
}),
|
|
135
|
-
extraHeaderPages:
|
|
136
|
-
extraPublicContent:
|
|
137
|
-
extraTheme:
|
|
138
|
-
vitepressConfig:
|
|
139
|
-
}),
|
|
140
|
-
config:
|
|
156
|
+
const J = ["github"], m = l.object({
|
|
157
|
+
branch: l.string().describe("Branch used to collect Git provider data.").optional().default("main"),
|
|
158
|
+
gitProvider: l.enum(J).describe(`Git provider used to retrieve data. Values should be ${Ge(J)}.`).optional().default("github"),
|
|
159
|
+
reposFilter: l.string().transform((e) => e.split(",")).or(l.string().array()).describe("List of comma separated repositories to retrieve from Git provider. Default to all user's public repositories.").optional(),
|
|
160
|
+
token: l.string().describe("Git provider token used to collect data.").optional(),
|
|
161
|
+
username: l.string().describe("Git provider username used to collect data.")
|
|
162
|
+
}), v = l.object({
|
|
163
|
+
extraHeaderPages: l.string().describe("List of comma separated additional files or directories to process Vitepress header pages.").transform((e) => e.split(",")).optional(),
|
|
164
|
+
extraPublicContent: l.string().describe("List of comma separated additional files or directories to process Vitepress public folder.").transform((e) => e.split(",")).optional(),
|
|
165
|
+
extraTheme: l.string().describe("List of comma separated additional files or directories to use as Vitepress theme.").transform((e) => e.split(",")).optional(),
|
|
166
|
+
vitepressConfig: l.string().describe("Path to the vitepress configuration file.").transform((e) => JSON.parse(w(c(process.cwd(), e)).toString())).optional()
|
|
167
|
+
}), V = l.object({
|
|
168
|
+
config: l.string().describe("Path to the docpress configuration file.").transform((e) => JSON.parse(w(c(process.cwd(), e)).toString())).optional()
|
|
141
169
|
});
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
build:
|
|
145
|
-
fetch:
|
|
146
|
-
prepare:
|
|
147
|
-
global:
|
|
170
|
+
m.merge(v).merge(Z);
|
|
171
|
+
const Ue = {
|
|
172
|
+
build: Z,
|
|
173
|
+
fetch: m,
|
|
174
|
+
prepare: v,
|
|
175
|
+
global: V
|
|
148
176
|
};
|
|
149
|
-
function
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
177
|
+
function N(e, t) {
|
|
178
|
+
d("Initializing Docpress...", "info", "blue"), d(`
|
|
179
|
+
|
|
180
|
+
-> Checking for required environment settings and configurations.`, "info");
|
|
181
|
+
function r(o, s) {
|
|
182
|
+
const i = Ue[o].safeParse({
|
|
183
|
+
...V.parse(s).config,
|
|
184
|
+
...s
|
|
185
|
+
});
|
|
186
|
+
if (i.success)
|
|
187
|
+
return i.data;
|
|
188
|
+
d(` An error occurred while checking configuration: ${pe(i.error).toString()}`, "error"), process.exit(0);
|
|
189
|
+
}
|
|
190
|
+
const n = e.reduce((o, s) => {
|
|
191
|
+
const i = r(s, t);
|
|
192
|
+
return Object.assign(o, i);
|
|
193
|
+
}, {});
|
|
194
|
+
return d(" Setup complete! Ready to process your documentation.", "info"), n;
|
|
195
|
+
}
|
|
196
|
+
function _(e, t) {
|
|
197
|
+
return t.forEach((r) => e.addOption(r)), e;
|
|
198
|
+
}
|
|
199
|
+
async function ze({ username: e, token: t, branch: r }) {
|
|
200
|
+
d(` Get infos for username '${e}'.`, "info");
|
|
201
|
+
const n = new be({ auth: t }), { data: o } = await n.request("GET /users/{username}", { username: e }), { data: s } = await n.request("GET /users/{username}/repos", { username: e, sort: "full_name" });
|
|
202
|
+
return { user: o, repos: s, branch: r };
|
|
203
|
+
}
|
|
204
|
+
async function Je(e, t, r, n) {
|
|
166
205
|
F(t, { clean: !0 });
|
|
167
206
|
try {
|
|
168
|
-
const
|
|
169
|
-
await
|
|
170
|
-
for (const
|
|
171
|
-
|
|
207
|
+
const o = ve({ baseDir: t });
|
|
208
|
+
await o.init().addConfig("core.sparseCheckout", "true", !0, "local").addRemote("origin", e);
|
|
209
|
+
for (const s of n)
|
|
210
|
+
K(c(t, ".git/info/sparse-checkout"), `${s}
|
|
172
211
|
`, "utf8");
|
|
173
|
-
await
|
|
174
|
-
} catch (
|
|
175
|
-
|
|
212
|
+
await o.pull("origin", r), n.some((s) => s.includes("docs")) && (j(c(t, "docs"), t, { recursive: !0 }), A(c(t, "docs"), { recursive: !0 })), A(c(t, ".git"), { recursive: !0 });
|
|
213
|
+
} catch (o) {
|
|
214
|
+
d(` Error when cloning repository: ${o}.`, "error");
|
|
176
215
|
}
|
|
177
216
|
}
|
|
178
|
-
async function
|
|
179
|
-
const
|
|
217
|
+
async function Be(e, t, r) {
|
|
218
|
+
const n = `https://github.com/${e}/${t}/tree/${r}/README.md`, o = `https://github.com/${e}/${t}/tree/${r}/docs`, s = `https://github.com/${e}/${t}/tree/${r}/docs/01-readme.md`, i = await P(n), a = await P(o), u = await P(s);
|
|
180
219
|
return {
|
|
181
|
-
rootReadmeStatus:
|
|
182
|
-
docsFolderStatus:
|
|
220
|
+
rootReadmeStatus: i,
|
|
221
|
+
docsFolderStatus: a,
|
|
183
222
|
docsReadmeStatus: u
|
|
184
223
|
};
|
|
185
224
|
}
|
|
186
|
-
async function
|
|
187
|
-
F(
|
|
225
|
+
async function He({ username: e, branch: t, reposFilter: r, token: n }) {
|
|
226
|
+
F(k, { clean: !0 }), await ze({ username: e, token: n, branch: t }).then(async ({ user: o, repos: s, branch: i }) => Xe(o, s, i, r)).then(async ({ repos: o }) => Ye(o, r));
|
|
188
227
|
}
|
|
189
|
-
async function
|
|
190
|
-
const
|
|
228
|
+
async function We(e, t, r) {
|
|
229
|
+
const n = [];
|
|
191
230
|
return await Promise.all(
|
|
192
|
-
e.map(async (
|
|
193
|
-
const
|
|
231
|
+
e.map(async (o) => {
|
|
232
|
+
const s = t ?? o.default_branch ?? "main", i = c(re, o.name), a = oe(o, r);
|
|
194
233
|
let u = [];
|
|
195
|
-
!
|
|
196
|
-
...
|
|
234
|
+
!o.fork && !o.private && !a && (u = await qe(o, s)), n.push({
|
|
235
|
+
...o,
|
|
197
236
|
docpress: {
|
|
198
|
-
filtered:
|
|
199
|
-
branch:
|
|
237
|
+
filtered: a,
|
|
238
|
+
branch: s,
|
|
200
239
|
includes: u,
|
|
201
|
-
projectPath:
|
|
202
|
-
raw_url: `https://raw.githubusercontent.com/${
|
|
203
|
-
replace_url: `https://github.com/${
|
|
240
|
+
projectPath: i,
|
|
241
|
+
raw_url: `https://raw.githubusercontent.com/${o.owner.login}/${o.name}/${s}`,
|
|
242
|
+
replace_url: `https://github.com/${o.owner.login}/${o.name}/tree/${s}`
|
|
204
243
|
}
|
|
205
244
|
});
|
|
206
245
|
})
|
|
207
|
-
),
|
|
246
|
+
), n;
|
|
208
247
|
}
|
|
209
|
-
async function
|
|
210
|
-
const
|
|
211
|
-
return Object.values(
|
|
248
|
+
async function qe(e, t) {
|
|
249
|
+
const r = await Be(e.owner.login, e.name, t), n = [];
|
|
250
|
+
return Object.values(r).every((o) => o === 404) || !e.size ? [] : (r.docsFolderStatus !== 404 && n.push("docs/*"), (r.docsFolderStatus === 404 || r.docsReadmeStatus === 404) && n.push("README.md", "!*/**/README.md"), n);
|
|
212
251
|
}
|
|
213
|
-
async function
|
|
214
|
-
|
|
215
|
-
const
|
|
216
|
-
return
|
|
252
|
+
async function Xe(e, t, r, n) {
|
|
253
|
+
y(te, JSON.stringify(e, null, 2));
|
|
254
|
+
const o = await We(t, r, n);
|
|
255
|
+
return y(ee, JSON.stringify(o, null, 2)), { user: e, repos: o };
|
|
217
256
|
}
|
|
218
|
-
async function
|
|
257
|
+
async function Ye(e, t) {
|
|
219
258
|
if (!e) {
|
|
220
|
-
|
|
259
|
+
d(" No repository respect docpress rules.", "warn");
|
|
221
260
|
return;
|
|
222
261
|
}
|
|
223
262
|
await Promise.all(
|
|
224
|
-
e.filter((
|
|
263
|
+
e.filter((r) => !oe(r, t)).map(async (r) => {
|
|
264
|
+
d(` Clone repository '${r.name}'.`, "info"), await Je(r.clone_url, r.docpress.projectPath, r.docpress.branch, r.docpress.includes);
|
|
265
|
+
})
|
|
225
266
|
);
|
|
226
267
|
}
|
|
227
|
-
function
|
|
228
|
-
const
|
|
229
|
-
return "docpress" in e && !e.docpress.includes.length ? !0 : !(e.clone_url && !e.fork && !e.private && !
|
|
230
|
-
}
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
],
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
],
|
|
240
|
-
|
|
268
|
+
function oe(e, t) {
|
|
269
|
+
const r = t?.filter((s) => s.startsWith("!")).some((s) => e.name === s.substring(1)), n = !t || t?.filter((s) => !s.startsWith("!")).includes(e.name), o = r || !n;
|
|
270
|
+
return "docpress" in e && !e.docpress.includes.length ? !0 : !(e.clone_url && !e.fork && !e.private && !o);
|
|
271
|
+
}
|
|
272
|
+
const O = [
|
|
273
|
+
f("-C, --config <string>", V.shape.config._def.description)
|
|
274
|
+
], B = "fetch", ne = [
|
|
275
|
+
f("-b, --branch <string>", m.shape.branch._def.description).default(m.shape.branch._def.defaultValue()),
|
|
276
|
+
f("-g, --git-provider <string>", m.shape.gitProvider._def.description).default(m.shape.gitProvider._def.defaultValue()),
|
|
277
|
+
f("-r, --repos-filter <string>", m.shape.reposFilter._def.description),
|
|
278
|
+
f("-T, --token <string>", m.shape.token._def.description),
|
|
279
|
+
f("-u, --username <string>", m.shape.username._def.description)
|
|
280
|
+
], Ke = _(D(B), [...ne, ...O]).description("Fetch docs with the given username and git provider.").action(async (e) => {
|
|
281
|
+
const t = N([B], e);
|
|
282
|
+
await ie(t);
|
|
241
283
|
});
|
|
242
|
-
async function
|
|
243
|
-
const { username: t, reposFilter:
|
|
244
|
-
|
|
284
|
+
async function ie(e) {
|
|
285
|
+
const { username: t, reposFilter: r, token: n, branch: o, gitProvider: s } = e;
|
|
286
|
+
d(`
|
|
287
|
+
-> Start fetching documentation files. This may take a moment, especially for larger repositories.`, "info"), await He({ username: t, branch: o, reposFilter: r, gitProvider: s, token: n });
|
|
245
288
|
}
|
|
246
|
-
const
|
|
247
|
-
await
|
|
289
|
+
const Qe = "build", Ze = _(D(Qe), O).description("Build vitepress website.").action(async (e) => {
|
|
290
|
+
await ce();
|
|
248
291
|
});
|
|
249
|
-
async function
|
|
250
|
-
|
|
292
|
+
async function ce() {
|
|
293
|
+
d(`
|
|
294
|
+
-> Start building Vitepress website.
|
|
295
|
+
|
|
296
|
+
`, "info");
|
|
297
|
+
try {
|
|
298
|
+
await ye(k), d(`
|
|
299
|
+
|
|
300
|
+
Docpress build succedeed.`, "success");
|
|
301
|
+
} catch (e) {
|
|
302
|
+
d(`
|
|
303
|
+
|
|
304
|
+
Docpress build failed : ${e}`, "error");
|
|
305
|
+
}
|
|
251
306
|
}
|
|
252
|
-
const
|
|
307
|
+
const H = {
|
|
253
308
|
base: "/",
|
|
254
309
|
lang: "en-US",
|
|
255
310
|
vite: {
|
|
@@ -258,7 +313,7 @@ const qe = {
|
|
|
258
313
|
title: "Home",
|
|
259
314
|
description: "Docpress",
|
|
260
315
|
srcDir: "./docs",
|
|
261
|
-
cleanUrls: !
|
|
316
|
+
cleanUrls: !1,
|
|
262
317
|
ignoreDeadLinks: "localhostLinks",
|
|
263
318
|
themeConfig: {
|
|
264
319
|
outline: [2, 3],
|
|
@@ -286,147 +341,147 @@ const qe = {
|
|
|
286
341
|
}
|
|
287
342
|
}
|
|
288
343
|
};
|
|
289
|
-
function
|
|
290
|
-
|
|
291
|
-
return {
|
|
292
|
-
...o,
|
|
293
|
-
themeConfig: {
|
|
294
|
-
...o.themeConfig,
|
|
295
|
-
sidebar: e,
|
|
296
|
-
nav: t
|
|
297
|
-
}
|
|
298
|
-
};
|
|
344
|
+
function et(e, t, r) {
|
|
345
|
+
return r ? R(H, r, { themeConfig: { sidebar: e, nav: t } }) : R(H, { themeConfig: { sidebar: e, nav: t } });
|
|
299
346
|
}
|
|
300
|
-
function
|
|
301
|
-
const
|
|
302
|
-
|
|
347
|
+
function tt(e, t) {
|
|
348
|
+
const n = w(e, "utf8").replace(/\[([^\]]+)\]\(\.\.\/([^)]+)\)/g, (o, s, i) => `[${s}](${t}/${i})`);
|
|
349
|
+
y(e, n, "utf8");
|
|
303
350
|
}
|
|
304
|
-
function
|
|
305
|
-
const
|
|
306
|
-
|
|
351
|
+
function rt(e, t) {
|
|
352
|
+
const n = w(e, "utf8").replace(/\[([^\]]+)\]\((?!\.?\/docs\/|docs\/|http)(\.?\/)?([^/][^)]+)\)/g, (o, s, i, a) => `[${s}](${t}/${a})`).replace(/\[([^\]]+)\]\((\.?\/docs\/|docs\/)([^)]*)\)/g, (o, s, i, a) => `[${s}](${a})`);
|
|
353
|
+
y(e, n, "utf8");
|
|
307
354
|
}
|
|
308
|
-
function
|
|
309
|
-
const
|
|
355
|
+
function W(e, t) {
|
|
356
|
+
const o = `${g(t) === "introduction.md" ? `
|
|
310
357
|
## Sources` : "# Sources"}
|
|
311
358
|
|
|
312
359
|
Take a look at the [project sources](${e}).
|
|
313
360
|
`;
|
|
314
|
-
|
|
361
|
+
K(t, o, "utf8");
|
|
315
362
|
}
|
|
316
|
-
function
|
|
317
|
-
const { name:
|
|
363
|
+
function st(e, t) {
|
|
364
|
+
const { name: r, login: n, bio: o } = t;
|
|
318
365
|
return {
|
|
319
366
|
layout: "home",
|
|
320
367
|
hero: {
|
|
321
|
-
name:
|
|
322
|
-
tagline:
|
|
368
|
+
name: r ? `${r}'s projects` : `${n}'s projects`,
|
|
369
|
+
tagline: o ?? "Robots are everywhere 🤖"
|
|
323
370
|
// \U0001F916
|
|
324
371
|
},
|
|
325
372
|
features: e
|
|
326
373
|
};
|
|
327
374
|
}
|
|
328
|
-
function
|
|
329
|
-
const
|
|
330
|
-
title:
|
|
375
|
+
function ot(e, t, r) {
|
|
376
|
+
const n = {
|
|
377
|
+
title: b(e, { mode: "capitalize", replaceDash: !0 }),
|
|
331
378
|
details: t,
|
|
332
|
-
link: `/${e}/
|
|
379
|
+
link: `/${e}/introduction`
|
|
333
380
|
};
|
|
334
|
-
return
|
|
381
|
+
return r ? [...r, n] : [n];
|
|
335
382
|
}
|
|
336
|
-
function
|
|
383
|
+
function nt(e, t) {
|
|
337
384
|
return {
|
|
338
|
-
text:
|
|
385
|
+
text: b(e, { mode: "capitalize", replaceDash: !0 }),
|
|
339
386
|
collapsed: !0,
|
|
340
387
|
items: t
|
|
341
388
|
};
|
|
342
389
|
}
|
|
343
|
-
function
|
|
344
|
-
const
|
|
345
|
-
text: t === "
|
|
390
|
+
function E(e, t, r) {
|
|
391
|
+
const n = {
|
|
392
|
+
text: t === "introduction" ? "Introduction" : b(t, { mode: "capitalize", replaceDash: !0 }),
|
|
346
393
|
link: `/${e}/${t}`
|
|
347
394
|
};
|
|
348
|
-
return
|
|
349
|
-
}
|
|
350
|
-
function
|
|
351
|
-
const
|
|
352
|
-
for (const
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
});
|
|
356
|
-
const
|
|
357
|
-
const
|
|
358
|
-
|
|
359
|
-
|
|
395
|
+
return r ? [...r, n] : [n];
|
|
396
|
+
}
|
|
397
|
+
function it(e, t) {
|
|
398
|
+
const r = [], n = [];
|
|
399
|
+
for (const s of e) {
|
|
400
|
+
d(` Replace urls for repository '${s.name}'.`, "info"), se([s.docpress.projectPath]).forEach((a) => {
|
|
401
|
+
tt(a, `https://github.com/${s.owner.login}/${s.name}/tree/${s.docpress.branch}`), g(a).toLowerCase() === "readme.md" && rt(a, `https://github.com/${s.owner.login}/${s.name}/tree/${s.docpress.branch}`);
|
|
402
|
+
}), d(` Generate sidebar for repository '${s.name}'.`, "info");
|
|
403
|
+
const i = Y(s.docpress.projectPath).filter((a) => L(c(s.docpress.projectPath, a)).isFile() && g(c(s.docpress.projectPath, a)).endsWith(".md")).sort((a, u) => a.localeCompare(u)).reduce((a, u, x, C) => {
|
|
404
|
+
const h = c(s.docpress.projectPath, u);
|
|
405
|
+
let p = b(g(h), { mode: "lowercase", removeIdx: !0 });
|
|
406
|
+
if (p === "readme.md" && (p = "introduction.md"), p !== g(h) && fe(h, c(Q(h), p)), x === C.length - 1) {
|
|
407
|
+
let S;
|
|
360
408
|
if (C.length > 1)
|
|
361
|
-
return
|
|
362
|
-
|
|
363
|
-
S
|
|
364
|
-
|
|
409
|
+
return S = c(s.docpress.projectPath, "sources.md"), W(s.html_url, S), E(
|
|
410
|
+
s.name,
|
|
411
|
+
$(S).name,
|
|
412
|
+
E(s.name, $(p).name, a)
|
|
365
413
|
);
|
|
366
|
-
|
|
414
|
+
S = c(s.docpress.projectPath, p), W(s.html_url, S);
|
|
367
415
|
}
|
|
368
|
-
return
|
|
416
|
+
return E(s.name, $(p).name, a);
|
|
369
417
|
}, []);
|
|
370
|
-
|
|
418
|
+
n.push(nt(s.name, i)), r.push(...ot(s.name, s.description || ""));
|
|
371
419
|
}
|
|
372
|
-
|
|
420
|
+
d(" Generate index content.", "info");
|
|
421
|
+
const o = st(r.sort((s, i) => s.title.localeCompare(i.title)), t);
|
|
373
422
|
return {
|
|
374
|
-
sidebar:
|
|
375
|
-
index:
|
|
423
|
+
sidebar: n.sort((s, i) => s.text.localeCompare(i.text)),
|
|
424
|
+
index: o
|
|
376
425
|
};
|
|
377
426
|
}
|
|
378
|
-
function
|
|
379
|
-
const t =
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
427
|
+
function ct(e) {
|
|
428
|
+
const t = se(e), r = [];
|
|
429
|
+
d(" Add extras Vitepress headers pages.", "info");
|
|
430
|
+
for (const n of t) {
|
|
431
|
+
const o = c(process.cwd(), n), s = c(re, b(g(n), { mode: "lowercase", removeIdx: !0 }));
|
|
432
|
+
j(o, s), r.push({
|
|
433
|
+
text: b($(o).name, { replaceDash: !0, removeIdx: !0 }),
|
|
434
|
+
link: `/${b($(o).name, { removeIdx: !0, mode: "lowercase" })}`
|
|
385
435
|
});
|
|
386
436
|
}
|
|
387
|
-
return
|
|
437
|
+
return r;
|
|
388
438
|
}
|
|
389
|
-
function
|
|
390
|
-
const
|
|
391
|
-
for (const
|
|
392
|
-
const
|
|
393
|
-
|
|
439
|
+
function q(e, t, r) {
|
|
440
|
+
const n = I(e);
|
|
441
|
+
for (const o of n) {
|
|
442
|
+
const s = c(process.cwd(), o), i = c(t, g(o));
|
|
443
|
+
j(s, i);
|
|
394
444
|
}
|
|
395
445
|
}
|
|
396
|
-
function
|
|
397
|
-
F(
|
|
398
|
-
`),
|
|
399
|
-
`.concat(
|
|
400
|
-
}
|
|
401
|
-
const
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
],
|
|
407
|
-
|
|
446
|
+
function at(e, t) {
|
|
447
|
+
F(Q(U)), d(" Generate Vitepress config.", "info"), y(U, `export default ${JSON.stringify(e, null, 2)}
|
|
448
|
+
`), d(" Generate index file.", "info"), y(Ve, `---
|
|
449
|
+
`.concat(we.stringify(t)));
|
|
450
|
+
}
|
|
451
|
+
const X = "prepare", ae = [
|
|
452
|
+
f("-c, --extra-public-content <string>", v.shape.extraPublicContent._def.description),
|
|
453
|
+
f("-p, --extra-header-pages <string>", v.shape.extraHeaderPages._def.description),
|
|
454
|
+
f("-t, --extra-theme <string>", v.shape.extraTheme._def.description),
|
|
455
|
+
f("-v, --vitepress-config <string>", v.shape.vitepressConfig._def.description)
|
|
456
|
+
], dt = _(D(X), [...ae, ...O]).description("Transform doc to the target vitepress format.").action(async (e) => {
|
|
457
|
+
const t = N([X], e);
|
|
458
|
+
await de(t);
|
|
408
459
|
});
|
|
409
|
-
async function
|
|
410
|
-
const { extraHeaderPages: t, extraPublicContent:
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
460
|
+
async function de(e) {
|
|
461
|
+
const { extraHeaderPages: t, extraPublicContent: r, extraTheme: n, vitepressConfig: o } = e;
|
|
462
|
+
d(`
|
|
463
|
+
-> Start transform files to prepare Vitepress build.`, "info");
|
|
464
|
+
const s = Ae(), i = Me().reduce((h, p) => p.clone_url && !p.fork && !p.private && p.docpress.includes.length && !p.docpress.filtered ? [...h, p] : h, []), { sidebar: a, index: u } = it(i, s), x = [];
|
|
465
|
+
t && x.push(...ct(t)), r && (d(" Add extras Vitepress public folder content.", "info"), q(r, c(k, "public"))), n && (d(" Add extras Vitepress theme files.", "info"), q(n, c(k, ".vitepress/theme")));
|
|
466
|
+
const C = et(a, x, o);
|
|
467
|
+
at(C, u);
|
|
468
|
+
}
|
|
469
|
+
function lt() {
|
|
470
|
+
const e = new le().name("docpress").description("Build your doc website faster than light ⚡️⚡️⚡️").version(`${Fe.version}`).addCommand(Ke).addCommand(dt).addCommand(Ze).action(async (t, r) => {
|
|
471
|
+
const n = N(["fetch", "prepare"], t);
|
|
472
|
+
await ie(n), await de(n), await ce();
|
|
418
473
|
}).configureHelp({
|
|
419
474
|
sortSubcommands: !0,
|
|
420
475
|
sortOptions: !0,
|
|
421
476
|
showGlobalOptions: !0
|
|
422
477
|
}).enablePositionalOptions().passThroughOptions();
|
|
423
|
-
return
|
|
478
|
+
return _(e, [...ne, ...ae, ...O]), e;
|
|
424
479
|
}
|
|
425
|
-
function
|
|
426
|
-
|
|
480
|
+
function xt() {
|
|
481
|
+
lt().parseAsync();
|
|
427
482
|
}
|
|
428
483
|
export {
|
|
429
|
-
|
|
430
|
-
|
|
484
|
+
lt as getProgram,
|
|
485
|
+
xt as main
|
|
431
486
|
};
|
|
432
487
|
//# sourceMappingURL=cli.js.map
|