@tobi-or-not/docpress 0.3.0 → 0.3.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/README.md +23 -0
- package/dist/cli.js +228 -199
- package/dist/cli.js.map +1 -1
- package/dist/templates/theme/index.ts +22 -0
- package/dist/templates/theme/layouts/ForkPage.vue +130 -0
- package/package.json +1 -1
- package/types/{lib → src/lib}/git.d.ts +2 -24
- package/types/src/utils/templates.d.ts +1 -0
- /package/types/{templates → public/templates}/theme/index.d.ts +0 -0
- /package/types/{cli.d.ts → src/cli.d.ts} +0 -0
- /package/types/{commands → src/commands}/build.d.ts +0 -0
- /package/types/{commands → src/commands}/fetch.d.ts +0 -0
- /package/types/{commands → src/commands}/global.d.ts +0 -0
- /package/types/{commands → src/commands}/prepare.d.ts +0 -0
- /package/types/{lib → src/lib}/fetch.d.ts +0 -0
- /package/types/{lib → src/lib}/prepare.d.ts +0 -0
- /package/types/{lib → src/lib}/vitepress.d.ts +0 -0
- /package/types/{schemas → src/schemas}/build.d.ts +0 -0
- /package/types/{schemas → src/schemas}/fetch.d.ts +0 -0
- /package/types/{schemas → src/schemas}/global.d.ts +0 -0
- /package/types/{schemas → src/schemas}/prepare.d.ts +0 -0
- /package/types/{utils → src/utils}/commands.d.ts +0 -0
- /package/types/{utils → src/utils}/const.d.ts +0 -0
- /package/types/{utils → src/utils}/functions.d.ts +0 -0
- /package/types/{utils → src/utils}/logger.d.ts +0 -0
- /package/types/{utils → src/utils}/regex.d.ts +0 -0
package/dist/cli.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { createOption as m, createCommand as
|
|
2
|
-
import
|
|
3
|
-
import { fromZodError as
|
|
4
|
-
import { z as
|
|
5
|
-
import { readFileSync as
|
|
6
|
-
import { resolve as d, join as
|
|
7
|
-
import
|
|
1
|
+
import { createOption as m, createCommand as j, Command as Ce } from "commander";
|
|
2
|
+
import J from "chalk";
|
|
3
|
+
import { fromZodError as ie } from "zod-validation-error";
|
|
4
|
+
import { z as p } from "zod";
|
|
5
|
+
import { readFileSync as C, existsSync as W, mkdirSync as Se, readdirSync as ce, statSync as A, appendFileSync as ae, cpSync as G, rmSync as q, writeFileSync as v, renameSync as xe } from "node:fs";
|
|
6
|
+
import { resolve as d, join as Pe, basename as b, dirname as N, parse as x } from "node:path";
|
|
7
|
+
import _e from "axios";
|
|
8
8
|
import { rimrafSync as Ee } from "rimraf";
|
|
9
|
-
import { Octokit as
|
|
10
|
-
import { simpleGit as
|
|
11
|
-
import { build as
|
|
12
|
-
import
|
|
13
|
-
const
|
|
9
|
+
import { Octokit as de } from "@octokit/rest";
|
|
10
|
+
import { simpleGit as Oe } from "simple-git";
|
|
11
|
+
import { build as Fe } from "vitepress";
|
|
12
|
+
import pe from "yaml";
|
|
13
|
+
const Re = "@tobi-or-not/docpress", Te = "module", De = "0.3.2", Le = "pnpm@9.12.3", Ve = "dist/docpress.js", Ie = "types/index.d.ts", je = {
|
|
14
14
|
docpress: "bin/docpress.js"
|
|
15
|
-
},
|
|
15
|
+
}, Ae = [
|
|
16
16
|
"bin",
|
|
17
17
|
"dist",
|
|
18
18
|
"types"
|
|
19
|
-
],
|
|
19
|
+
], Ge = {
|
|
20
20
|
node: ">=20"
|
|
21
|
-
},
|
|
21
|
+
}, Ne = {
|
|
22
22
|
build: "pnpm run build:types && pnpm run build:vite",
|
|
23
23
|
"build:clean": "rimraf ./dist ./types ./tsconfig.tsbuildinfo",
|
|
24
24
|
"build:docker": "docker build --tag tobi-or-not/docpress --target prod .",
|
|
@@ -39,7 +39,7 @@ const Te = "@tobi-or-not/docpress", Fe = "module", Re = "0.3.0", De = "pnpm@9.12
|
|
|
39
39
|
"vp:dev": "vitepress dev ./docpress --port 8080",
|
|
40
40
|
"vp:dev:docker": "docker run --publish 8080:8080 --name docpress-vp --rm tobi-or-not/docs",
|
|
41
41
|
"vp:preview": "vitepress preview ./docpress --port 8080"
|
|
42
|
-
},
|
|
42
|
+
}, Me = {
|
|
43
43
|
"@octokit/rest": "^21.0.2",
|
|
44
44
|
axios: "^1.7.7",
|
|
45
45
|
chalk: "^5.3.0",
|
|
@@ -51,7 +51,7 @@ const Te = "@tobi-or-not/docpress", Fe = "module", Re = "0.3.0", De = "pnpm@9.12
|
|
|
51
51
|
yaml: "^2.6.1",
|
|
52
52
|
zod: "^3.23.8",
|
|
53
53
|
"zod-validation-error": "^3.4.0"
|
|
54
|
-
},
|
|
54
|
+
}, Ue = {
|
|
55
55
|
"@antfu/eslint-config": "^3.9.2",
|
|
56
56
|
"@commitlint/cli": "^19.6.0",
|
|
57
57
|
"@commitlint/config-conventional": "^19.6.0",
|
|
@@ -69,22 +69,22 @@ const Te = "@tobi-or-not/docpress", Fe = "module", Re = "0.3.0", De = "pnpm@9.12
|
|
|
69
69
|
registry: "https://registry.npmjs.org/",
|
|
70
70
|
access: "public",
|
|
71
71
|
tag: "latest"
|
|
72
|
-
},
|
|
73
|
-
name:
|
|
74
|
-
type:
|
|
75
|
-
version:
|
|
76
|
-
packageManager:
|
|
77
|
-
module:
|
|
78
|
-
types:
|
|
79
|
-
bin:
|
|
80
|
-
files:
|
|
81
|
-
engines:
|
|
82
|
-
scripts:
|
|
83
|
-
dependencies:
|
|
84
|
-
devDependencies:
|
|
72
|
+
}, ze = {
|
|
73
|
+
name: Re,
|
|
74
|
+
type: Te,
|
|
75
|
+
version: De,
|
|
76
|
+
packageManager: Le,
|
|
77
|
+
module: Ve,
|
|
78
|
+
types: Ie,
|
|
79
|
+
bin: je,
|
|
80
|
+
files: Ae,
|
|
81
|
+
engines: Ge,
|
|
82
|
+
scripts: Ne,
|
|
83
|
+
dependencies: Me,
|
|
84
|
+
devDependencies: Ue,
|
|
85
85
|
publishConfig: He
|
|
86
86
|
};
|
|
87
|
-
function
|
|
87
|
+
function Be() {
|
|
88
88
|
return typeof Number(process.env.LOG_LEVEL) == "number" && !Number.isNaN(Number(process.env.LOG_LEVEL)) ? Number(process.env.LOG_LEVEL) : 30;
|
|
89
89
|
}
|
|
90
90
|
const K = {
|
|
@@ -96,71 +96,71 @@ const K = {
|
|
|
96
96
|
success: { color: "green", level: 30 }
|
|
97
97
|
};
|
|
98
98
|
function c(e, t = "info", r) {
|
|
99
|
-
const s = r ?
|
|
100
|
-
|
|
99
|
+
const s = r ? J[r](e) : J[K[t].color](e), n = t === "success" ? "info" : t;
|
|
100
|
+
Be() >= K[t].level && console[n](s);
|
|
101
101
|
}
|
|
102
|
-
const
|
|
103
|
-
async function
|
|
102
|
+
const M = d(process.cwd(), "docpress"), ue = d(process.cwd(), "docpress/repositories.json"), le = d(process.cwd(), "docpress/owner.json"), fe = d(process.cwd(), "docpress/docs"), Je = d(process.cwd(), "docpress/docs/index.md"), We = d(process.cwd(), "docpress/docs/forks.md"), X = d(process.cwd(), "docpress/.vitepress/config.ts"), qe = d(process.cwd(), "docpress/.vitepress/theme"), Ke = d(process.cwd(), "docpress/.vitepress/theme/extras"), Y = process.env.NODE_ENV === "development" ? d(import.meta.dirname, "../../public/templates/theme") : d(import.meta.dirname, "./templates/theme");
|
|
103
|
+
async function L(e) {
|
|
104
104
|
try {
|
|
105
|
-
return (await
|
|
105
|
+
return (await _e.head(e)).status;
|
|
106
106
|
} catch (t) {
|
|
107
107
|
return t.response?.status || t.status || 500;
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
function
|
|
110
|
+
function k(e, t) {
|
|
111
111
|
let r = "";
|
|
112
112
|
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;
|
|
113
113
|
}
|
|
114
|
-
function
|
|
114
|
+
function E(e, { clean: t } = { clean: !1 }) {
|
|
115
115
|
try {
|
|
116
|
-
t &&
|
|
116
|
+
t && W(e) && Ee(`${e}/*`, { glob: !0 }), W(e) || Se(e, { recursive: !0 });
|
|
117
117
|
} catch (r) {
|
|
118
118
|
console.error(r);
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
function Xe(e) {
|
|
122
122
|
try {
|
|
123
|
-
return
|
|
123
|
+
return A(e).isDirectory();
|
|
124
124
|
} catch {
|
|
125
125
|
return !1;
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
function Ye(e) {
|
|
129
129
|
try {
|
|
130
|
-
return
|
|
130
|
+
return A(e).isFile();
|
|
131
131
|
} catch {
|
|
132
132
|
return !1;
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
|
-
function
|
|
136
|
-
return (Array.isArray(e) ? e : [e]).flatMap((t) => Ye(t) ? [t] : Xe(t) ?
|
|
135
|
+
function O(e) {
|
|
136
|
+
return (Array.isArray(e) ? e : [e]).flatMap((t) => Ye(t) ? [t] : Xe(t) ? ce(t).flatMap((r) => O(Pe(t, r))) : []);
|
|
137
137
|
}
|
|
138
|
-
function
|
|
139
|
-
return
|
|
138
|
+
function me(e) {
|
|
139
|
+
return O(e).filter((t) => b(t).endsWith(".md"));
|
|
140
140
|
}
|
|
141
141
|
function Ze(e) {
|
|
142
142
|
return e.reduce((t, r, s, n) => s ? s === n.length - 1 ? `${t} or "${r}"` : `${t}, "${r}"` : `"${r}"`, "");
|
|
143
143
|
}
|
|
144
144
|
function Qe() {
|
|
145
|
-
return JSON.parse(
|
|
145
|
+
return JSON.parse(C(le).toString());
|
|
146
146
|
}
|
|
147
147
|
function et() {
|
|
148
|
-
return JSON.parse(
|
|
148
|
+
return JSON.parse(C(ue).toString());
|
|
149
149
|
}
|
|
150
|
-
function
|
|
150
|
+
function I(...e) {
|
|
151
151
|
return e.reduce((t, r) => (r === null || Object.keys(r).forEach((s) => {
|
|
152
152
|
const n = t ? t[s] : null, o = r[s];
|
|
153
|
-
|
|
153
|
+
Z(n) && Z(o) ? t[s] = I(n, o) : t[s] = o;
|
|
154
154
|
}), t), {});
|
|
155
155
|
}
|
|
156
|
-
function
|
|
156
|
+
function Z(e) {
|
|
157
157
|
return e && typeof e == "object" && !Array.isArray(e);
|
|
158
158
|
}
|
|
159
|
-
function
|
|
159
|
+
function Q(e) {
|
|
160
160
|
if (!e)
|
|
161
161
|
return {};
|
|
162
162
|
try {
|
|
163
|
-
const t = d(process.cwd(), e), r =
|
|
163
|
+
const t = d(process.cwd(), e), r = C(t, "utf8");
|
|
164
164
|
return JSON.parse(r);
|
|
165
165
|
} catch {
|
|
166
166
|
return {};
|
|
@@ -169,24 +169,24 @@ function Z(e) {
|
|
|
169
169
|
function P(e) {
|
|
170
170
|
return e.split(",");
|
|
171
171
|
}
|
|
172
|
-
const
|
|
172
|
+
const ee = ["github"], u = p.object({
|
|
173
173
|
// Global
|
|
174
|
-
username:
|
|
174
|
+
username: p.string().describe("Git provider username used to collect data."),
|
|
175
175
|
// Fetch
|
|
176
|
-
branch:
|
|
177
|
-
gitProvider:
|
|
178
|
-
reposFilter:
|
|
176
|
+
branch: p.string().describe("Branch used to collect Git provider data.").default("main"),
|
|
177
|
+
gitProvider: p.enum(ee).describe(`Git provider used to retrieve data. Values should be ${Ze(ee)}.`).default("github"),
|
|
178
|
+
reposFilter: p.array(p.string()).describe("List of comma separated repositories to retrieve from Git provider. Default to all user's public repositories."),
|
|
179
179
|
// Prepare
|
|
180
|
-
extraHeaderPages:
|
|
181
|
-
extraPublicContent:
|
|
182
|
-
extraTheme:
|
|
183
|
-
forks:
|
|
184
|
-
vitepressConfig:
|
|
180
|
+
extraHeaderPages: p.array(p.string()).describe("List of comma separated additional files or directories to process Vitepress header pages."),
|
|
181
|
+
extraPublicContent: p.array(p.string()).describe("List of comma separated additional files or directories to process Vitepress public folder."),
|
|
182
|
+
extraTheme: p.array(p.string()).describe("List of comma separated additional files or directories to use as Vitepress theme."),
|
|
183
|
+
forks: p.boolean().describe("Whether or not to create the dedicated fork page that aggregate external contributions.").default(!1),
|
|
184
|
+
vitepressConfig: p.any().describe("Path to the vitepress configuration file.")
|
|
185
185
|
});
|
|
186
|
-
function
|
|
186
|
+
function U(e) {
|
|
187
187
|
const { config: t, vitepressConfig: r, token: s, ...n } = e;
|
|
188
188
|
try {
|
|
189
|
-
const o =
|
|
189
|
+
const o = u.partial().parse(Q(t)), i = Q(r), a = u.partial().required({ branch: !0, gitProvider: !0 }).parse({}), l = {
|
|
190
190
|
...i,
|
|
191
191
|
...o.vitepressConfig
|
|
192
192
|
}, g = {
|
|
@@ -195,28 +195,28 @@ function H(e) {
|
|
|
195
195
|
...n,
|
|
196
196
|
...Object.keys(l).length && { vitepressConfig: l }
|
|
197
197
|
};
|
|
198
|
-
return { ...
|
|
198
|
+
return { ...u.partial().required({ username: !0 }).parse(g), token: s };
|
|
199
199
|
} catch (o) {
|
|
200
200
|
c(` An error occurred while checking configuration.
|
|
201
|
-
${
|
|
201
|
+
${ie(o).toString()}`, "error"), process.exit(1);
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
|
-
const
|
|
205
|
-
config:
|
|
206
|
-
token:
|
|
207
|
-
reposFilter:
|
|
208
|
-
extraHeaderPages:
|
|
209
|
-
extraPublicContent:
|
|
210
|
-
extraTheme:
|
|
211
|
-
vitepressConfig:
|
|
212
|
-
}),
|
|
204
|
+
const F = u.partial().extend({
|
|
205
|
+
config: p.string().describe("Path to the docpress configuration file.").optional(),
|
|
206
|
+
token: p.string().describe("Git provider token used to collect data.").optional(),
|
|
207
|
+
reposFilter: p.string().describe(u.shape.reposFilter.description || "").transform(P).optional(),
|
|
208
|
+
extraHeaderPages: p.string().describe(u.shape.extraHeaderPages.description || "").transform(P).optional(),
|
|
209
|
+
extraPublicContent: p.string().describe(u.shape.extraPublicContent.description || "").transform(P).optional(),
|
|
210
|
+
extraTheme: p.string().describe(u.shape.extraTheme.description || "").transform(P).optional(),
|
|
211
|
+
vitepressConfig: p.string().describe(u.shape.vitepressConfig.description || "").optional()
|
|
212
|
+
}), _ = F.partial().transform(U), tt = F.pick({}), rt = F.pick({
|
|
213
213
|
branch: !0,
|
|
214
214
|
config: !0,
|
|
215
215
|
gitProvider: !0,
|
|
216
216
|
reposFilter: !0,
|
|
217
217
|
token: !0,
|
|
218
218
|
username: !0
|
|
219
|
-
}).transform(
|
|
219
|
+
}).transform(U), ot = F.pick({
|
|
220
220
|
extraHeaderPages: !0,
|
|
221
221
|
extraPublicContent: !0,
|
|
222
222
|
extraTheme: !0,
|
|
@@ -226,35 +226,38 @@ const _ = p.partial().extend({
|
|
|
226
226
|
token: !0,
|
|
227
227
|
username: !0,
|
|
228
228
|
vitepressConfig: !0
|
|
229
|
-
}).transform(
|
|
229
|
+
}).transform(U), st = {
|
|
230
230
|
build: tt,
|
|
231
231
|
fetch: rt,
|
|
232
232
|
prepare: ot,
|
|
233
|
-
global:
|
|
233
|
+
global: _
|
|
234
234
|
};
|
|
235
|
-
function
|
|
235
|
+
function H(e, t) {
|
|
236
236
|
c("Initializing Docpress...", "info", "blue"), c(`
|
|
237
237
|
|
|
238
238
|
-> Checking for required environment settings and configurations.`, "info");
|
|
239
239
|
const r = st[e].safeParse(t);
|
|
240
240
|
return r.error && (c(` An error occurred while checking configuration.
|
|
241
|
-
${
|
|
241
|
+
${ie(r.error).toString()}`, "error"), process.exit(1)), c(" Setup complete! Ready to process your documentation.", "info"), r.data;
|
|
242
242
|
}
|
|
243
|
-
function
|
|
243
|
+
function R(e, t) {
|
|
244
244
|
return t.forEach((r) => e.addOption(r)), e;
|
|
245
245
|
}
|
|
246
246
|
async function nt({ username: e, token: t, branch: r }) {
|
|
247
247
|
c(` Get infos for username '${e}'.`, "info");
|
|
248
|
-
const s = new
|
|
248
|
+
const s = new de({ auth: t });
|
|
249
249
|
c(" Get user infos.", "debug");
|
|
250
|
-
const { data: n } = await s.
|
|
250
|
+
const { data: n } = await s.rest.users.getByUsername({ username: e });
|
|
251
251
|
c(" Get repositories infos.", "debug");
|
|
252
|
-
const { data: o } = await s.
|
|
252
|
+
const { data: o } = await s.rest.repos.listForUser({ username: e, sort: "full_name" });
|
|
253
253
|
return { user: n, repos: o, branch: r };
|
|
254
254
|
}
|
|
255
|
-
async function it({
|
|
255
|
+
async function it({
|
|
256
|
+
repository: e,
|
|
257
|
+
token: t
|
|
258
|
+
}) {
|
|
256
259
|
c(` Get contributors infos for repository '${e.name}'.`, "info");
|
|
257
|
-
const r = new
|
|
260
|
+
const r = new de({
|
|
258
261
|
auth: t,
|
|
259
262
|
log: {
|
|
260
263
|
debug: () => {
|
|
@@ -268,27 +271,46 @@ async function it({ repository: e, token: t }) {
|
|
|
268
271
|
o.includes("404") || console.error(o);
|
|
269
272
|
}
|
|
270
273
|
}
|
|
271
|
-
}), { data: s } = await r.
|
|
272
|
-
|
|
274
|
+
}), { data: s } = await r.rest.repos.get({
|
|
275
|
+
owner: e.owner.login,
|
|
276
|
+
repo: e.name
|
|
277
|
+
});
|
|
278
|
+
if (!s.source?.owner?.login)
|
|
273
279
|
return { source: s.source, contributors: [] };
|
|
274
|
-
const
|
|
280
|
+
const n = [];
|
|
281
|
+
try {
|
|
282
|
+
for await (const { data: o } of r.paginate.iterator(
|
|
283
|
+
r.rest.repos.listContributors,
|
|
284
|
+
{
|
|
285
|
+
owner: s.source.owner.login,
|
|
286
|
+
repo: s.name,
|
|
287
|
+
per_page: 500
|
|
288
|
+
}
|
|
289
|
+
))
|
|
290
|
+
n.push(...o);
|
|
291
|
+
} catch {
|
|
292
|
+
return c(
|
|
293
|
+
` Failed to get contributors infos for repository '${e.name}'.`,
|
|
294
|
+
"warn"
|
|
295
|
+
), { source: s.source, contributors: [] };
|
|
296
|
+
}
|
|
275
297
|
return { source: s.source, contributors: n };
|
|
276
298
|
}
|
|
277
299
|
async function ct(e, t, r, s, n) {
|
|
278
|
-
|
|
300
|
+
E(r, { clean: !0 });
|
|
279
301
|
try {
|
|
280
|
-
const o =
|
|
302
|
+
const o = Oe({ baseDir: r });
|
|
281
303
|
await o.init().addConfig("core.sparseCheckout", "true", !0, "local").addRemote("origin", t);
|
|
282
304
|
for (const i of n)
|
|
283
|
-
c(` Add '${i}' to '${e}' sparse-checkout file.`, "debug"),
|
|
305
|
+
c(` Add '${i}' to '${e}' sparse-checkout file.`, "debug"), ae(d(r, ".git/info/sparse-checkout"), `${i}
|
|
284
306
|
`, "utf8");
|
|
285
|
-
c(` Clone repository '${e}'.`, "info"), await o.pull("origin", s), n.some((i) => i.includes("docs")) && (
|
|
307
|
+
c(` Clone repository '${e}'.`, "info"), await o.pull("origin", s), n.some((i) => i.includes("docs")) && (G(d(r, "docs"), r, { recursive: !0 }), q(d(r, "docs"), { recursive: !0 })), q(d(r, ".git"), { recursive: !0 });
|
|
286
308
|
} catch (o) {
|
|
287
309
|
c(` Error when cloning repository: ${o}.`, "error");
|
|
288
310
|
}
|
|
289
311
|
}
|
|
290
312
|
async function at(e, t, r) {
|
|
291
|
-
const s = `https://github.com/${e}/${t}/tree/${r}/README.md`, n = `https://github.com/${e}/${t}/tree/${r}/docs`, o = `https://github.com/${e}/${t}/tree/${r}/docs/01-readme.md`, i = await
|
|
313
|
+
const s = `https://github.com/${e}/${t}/tree/${r}/README.md`, n = `https://github.com/${e}/${t}/tree/${r}/docs`, o = `https://github.com/${e}/${t}/tree/${r}/docs/01-readme.md`, i = await L(s), a = await L(n), l = await L(o);
|
|
292
314
|
return {
|
|
293
315
|
rootReadmeStatus: i,
|
|
294
316
|
docsFolderStatus: a,
|
|
@@ -296,15 +318,15 @@ async function at(e, t, r) {
|
|
|
296
318
|
};
|
|
297
319
|
}
|
|
298
320
|
async function dt({ username: e, branch: t, reposFilter: r, token: s }) {
|
|
299
|
-
|
|
321
|
+
E(M, { clean: !0 }), await nt({ username: e, token: s, branch: t }).then(async ({ user: n, repos: o, branch: i }) => lt(n, o, i, r)).then(async ({ repos: n }) => ft(n, r));
|
|
300
322
|
}
|
|
301
|
-
async function
|
|
323
|
+
async function pt(e, t, r) {
|
|
302
324
|
const s = [];
|
|
303
325
|
return await Promise.all(
|
|
304
326
|
e.map(async (n) => {
|
|
305
|
-
const o = t ?? n.default_branch ?? "main", i = d(
|
|
327
|
+
const o = t ?? n.default_branch ?? "main", i = d(fe, n.name), a = ge(n, r);
|
|
306
328
|
let l = [];
|
|
307
|
-
!n.fork && !n.private && !a && (l = await
|
|
329
|
+
!n.fork && !n.private && !a && (l = await ut(n, o)), s.push({
|
|
308
330
|
...n,
|
|
309
331
|
docpress: {
|
|
310
332
|
filtered: a,
|
|
@@ -318,14 +340,14 @@ async function ut(e, t, r) {
|
|
|
318
340
|
})
|
|
319
341
|
), s;
|
|
320
342
|
}
|
|
321
|
-
async function
|
|
343
|
+
async function ut(e, t) {
|
|
322
344
|
const r = await at(e.owner.login, e.name, t), s = [];
|
|
323
345
|
return Object.values(r).every((n) => n === 404) || !e.size ? [] : (r.docsFolderStatus !== 404 && s.push("docs/*"), (r.docsFolderStatus === 404 || r.docsReadmeStatus === 404) && s.push("README.md", "!*/**/README.md"), s);
|
|
324
346
|
}
|
|
325
347
|
async function lt(e, t, r, s) {
|
|
326
|
-
|
|
327
|
-
const n = await
|
|
328
|
-
return
|
|
348
|
+
v(le, JSON.stringify(e, null, 2));
|
|
349
|
+
const n = await pt(t, r, s);
|
|
350
|
+
return v(ue, JSON.stringify(n, null, 2)), { user: e, repos: n };
|
|
329
351
|
}
|
|
330
352
|
async function ft(e, t) {
|
|
331
353
|
if (!e) {
|
|
@@ -333,42 +355,42 @@ async function ft(e, t) {
|
|
|
333
355
|
return;
|
|
334
356
|
}
|
|
335
357
|
await Promise.all(
|
|
336
|
-
e.filter((r) => !
|
|
358
|
+
e.filter((r) => !ge(r, t)).map(async (r) => {
|
|
337
359
|
await ct(r.name, r.clone_url, r.docpress.projectPath, r.docpress.branch, r.docpress.includes);
|
|
338
360
|
})
|
|
339
361
|
);
|
|
340
362
|
}
|
|
341
|
-
function
|
|
363
|
+
function ge(e, t) {
|
|
342
364
|
const r = t?.every((i) => i.startsWith("!")), s = t?.filter((i) => i.startsWith("!")).some((i) => e.name === i.substring(1)), n = !t || t?.filter((i) => !i.startsWith("!")).includes(e.name) || e.fork && !s || r && !s, o = s || !n;
|
|
343
365
|
return "docpress" in e && !e.docpress.includes.length ? !0 : !(e.clone_url && !e.private && !o);
|
|
344
366
|
}
|
|
345
367
|
const T = [
|
|
346
|
-
m("-C, --config <string>",
|
|
347
|
-
m("-T, --token <string>",
|
|
348
|
-
m("-U, --username <string>",
|
|
349
|
-
],
|
|
350
|
-
m("-b, --branch <string>",
|
|
351
|
-
m("-g, --git-provider <string>",
|
|
352
|
-
m("-r, --repos-filter <string>",
|
|
353
|
-
], mt =
|
|
354
|
-
const t =
|
|
355
|
-
await
|
|
368
|
+
m("-C, --config <string>", _.innerType().shape.config._def.description),
|
|
369
|
+
m("-T, --token <string>", _.innerType().shape.token._def.description),
|
|
370
|
+
m("-U, --username <string>", _.innerType().shape.username._def.description)
|
|
371
|
+
], te = "fetch", he = [
|
|
372
|
+
m("-b, --branch <string>", u.shape.branch._def.description).default(u.shape.branch._def.defaultValue()),
|
|
373
|
+
m("-g, --git-provider <string>", u.shape.gitProvider._def.description).default(u.shape.gitProvider._def.defaultValue()),
|
|
374
|
+
m("-r, --repos-filter <string>", u.shape.reposFilter._def.description)
|
|
375
|
+
], mt = R(j(te), [...he, ...T]).description("Fetch docs with the given username and git provider.").action(async (e) => {
|
|
376
|
+
const t = H(te, e);
|
|
377
|
+
await be(t);
|
|
356
378
|
});
|
|
357
|
-
async function
|
|
379
|
+
async function be(e) {
|
|
358
380
|
const { username: t, reposFilter: r, token: s, branch: n, gitProvider: o } = e;
|
|
359
381
|
c(`
|
|
360
382
|
-> Start fetching documentation files. This may take a moment, especially for larger repositories.`, "info"), await dt({ username: t, branch: n, reposFilter: r, gitProvider: o, token: s });
|
|
361
383
|
}
|
|
362
|
-
const gt = "build", ht =
|
|
363
|
-
await
|
|
384
|
+
const gt = "build", ht = R(j(gt), T).description("Build vitepress website.").action(async (e) => {
|
|
385
|
+
await ve();
|
|
364
386
|
});
|
|
365
|
-
async function
|
|
387
|
+
async function ve() {
|
|
366
388
|
c(`
|
|
367
389
|
-> Start building Vitepress website.
|
|
368
390
|
|
|
369
391
|
`, "info");
|
|
370
392
|
try {
|
|
371
|
-
await
|
|
393
|
+
await Fe(M), c(`
|
|
372
394
|
|
|
373
395
|
Docpress build succedeed.`, "success");
|
|
374
396
|
} catch (e) {
|
|
@@ -377,7 +399,7 @@ Docpress build succedeed.`, "success");
|
|
|
377
399
|
Docpress build failed : ${e}`, "error");
|
|
378
400
|
}
|
|
379
401
|
}
|
|
380
|
-
const
|
|
402
|
+
const re = {
|
|
381
403
|
base: "/",
|
|
382
404
|
lang: "en-US",
|
|
383
405
|
vite: {
|
|
@@ -415,25 +437,29 @@ const te = {
|
|
|
415
437
|
}
|
|
416
438
|
};
|
|
417
439
|
function bt(e, t, r) {
|
|
418
|
-
return r ?
|
|
440
|
+
return r ? I(re, r, { themeConfig: { sidebar: e, nav: t } }) : I(re, { themeConfig: { sidebar: e, nav: t } });
|
|
419
441
|
}
|
|
420
442
|
function vt(e, t) {
|
|
421
|
-
const
|
|
422
|
-
|
|
443
|
+
const r = C(e, { encoding: "utf8" });
|
|
444
|
+
E(N(t)), v(t, r);
|
|
423
445
|
}
|
|
424
446
|
function yt(e, t) {
|
|
425
|
-
const s =
|
|
426
|
-
|
|
447
|
+
const s = C(e, "utf8").replace(/\[([^\]]+)\]\(\.\.\/([^)]+)\)/g, (n, o, i) => `[${o}](${t}/${i})`);
|
|
448
|
+
v(e, s, "utf8");
|
|
449
|
+
}
|
|
450
|
+
function wt(e, t) {
|
|
451
|
+
const s = C(e, "utf8").replace(/\[([^\]]+)\]\((?!\.?\/docs\/|docs\/|http|#)(\.?\/)?([^/][^)]+)\)/g, (n, o, i, a) => `[${o}](${t}/${a})`).replace(/\[([^\]]+)\]\((\.?\/docs\/|docs\/)([^)]*)\)/g, (n, o, i, a) => `[${o}](${a})`);
|
|
452
|
+
v(e, s, "utf8");
|
|
427
453
|
}
|
|
428
|
-
function
|
|
454
|
+
function oe(e, t) {
|
|
429
455
|
const n = `${b(t) === "introduction.md" ? `
|
|
430
456
|
## Sources` : "# Sources"}
|
|
431
457
|
|
|
432
458
|
Take a look at the [project sources](${e}).
|
|
433
459
|
`;
|
|
434
|
-
|
|
460
|
+
ae(t, n, "utf8");
|
|
435
461
|
}
|
|
436
|
-
function
|
|
462
|
+
function kt(e, t) {
|
|
437
463
|
const { name: r, login: s, bio: n } = t;
|
|
438
464
|
return {
|
|
439
465
|
layout: "home",
|
|
@@ -445,83 +471,83 @@ function wt(e, t) {
|
|
|
445
471
|
features: e
|
|
446
472
|
};
|
|
447
473
|
}
|
|
448
|
-
function
|
|
474
|
+
function $t(e, t, r) {
|
|
449
475
|
const s = {
|
|
450
|
-
title:
|
|
476
|
+
title: k(e, { mode: "capitalize", replaceDash: !0 }),
|
|
451
477
|
details: t,
|
|
452
478
|
link: `/${e}/introduction`
|
|
453
479
|
};
|
|
454
480
|
return r ? [...r, s] : [s];
|
|
455
481
|
}
|
|
456
|
-
function
|
|
482
|
+
function Ct(e, t) {
|
|
457
483
|
return {
|
|
458
|
-
text:
|
|
484
|
+
text: k(e, { mode: "capitalize", replaceDash: !0 }),
|
|
459
485
|
collapsed: !0,
|
|
460
486
|
items: t
|
|
461
487
|
};
|
|
462
488
|
}
|
|
463
|
-
function
|
|
489
|
+
function V(e, t, r) {
|
|
464
490
|
const s = {
|
|
465
|
-
text: t === "introduction" ? "Introduction" :
|
|
491
|
+
text: t === "introduction" ? "Introduction" : k(t, { mode: "capitalize", replaceDash: !0 }),
|
|
466
492
|
link: `/${e}/${t}`
|
|
467
493
|
};
|
|
468
494
|
return r ? [...r, s] : [s];
|
|
469
495
|
}
|
|
470
|
-
function
|
|
496
|
+
function St(e, t) {
|
|
471
497
|
const r = [], s = [];
|
|
472
498
|
for (const o of e) {
|
|
473
|
-
c(` Replace urls for repository '${o.name}'.`, "info"),
|
|
474
|
-
c(` Processing file '${b(a)}' for repository '${o.name}'.`, "debug"),
|
|
499
|
+
c(` Replace urls for repository '${o.name}'.`, "info"), me([o.docpress.projectPath]).forEach((a) => {
|
|
500
|
+
c(` Processing file '${b(a)}' for repository '${o.name}'.`, "debug"), yt(a, `https://github.com/${o.owner.login}/${o.name}/tree/${o.docpress.branch}`), b(a).toLowerCase() === "readme.md" && wt(a, `https://github.com/${o.owner.login}/${o.name}/tree/${o.docpress.branch}`);
|
|
475
501
|
}), c(` Generate sidebar for repository '${o.name}'.`, "info");
|
|
476
|
-
const i =
|
|
502
|
+
const i = ce(o.docpress.projectPath).filter((a) => A(d(o.docpress.projectPath, a)).isFile() && b(d(o.docpress.projectPath, a)).endsWith(".md")).sort((a, l) => a.localeCompare(l)).reduce((a, l, g, y) => {
|
|
477
503
|
const h = d(o.docpress.projectPath, l);
|
|
478
|
-
let f =
|
|
479
|
-
if (f === "readme.md" && (f = "introduction.md"), f !== b(h) &&
|
|
480
|
-
let
|
|
481
|
-
if (
|
|
482
|
-
return
|
|
504
|
+
let f = k(b(h), { mode: "lowercase", removeIdx: !0 });
|
|
505
|
+
if (f === "readme.md" && (f = "introduction.md"), f !== b(h) && xe(h, d(N(h), f)), g === y.length - 1) {
|
|
506
|
+
let w;
|
|
507
|
+
if (y.length > 1)
|
|
508
|
+
return w = d(o.docpress.projectPath, "sources.md"), c(` Add sources for repository '${o.name}'.`, "info"), oe(o.html_url, w), V(
|
|
483
509
|
o.name,
|
|
484
|
-
|
|
485
|
-
|
|
510
|
+
x(w).name,
|
|
511
|
+
V(o.name, x(f).name, a)
|
|
486
512
|
);
|
|
487
|
-
|
|
513
|
+
w = d(o.docpress.projectPath, f), oe(o.html_url, w);
|
|
488
514
|
}
|
|
489
|
-
return
|
|
515
|
+
return V(o.name, x(f).name, a);
|
|
490
516
|
}, []);
|
|
491
|
-
s.push(
|
|
517
|
+
s.push(Ct(o.name, i)), r.push(...$t(o.name, o.description || ""));
|
|
492
518
|
}
|
|
493
519
|
c(" Generate index content.", "info");
|
|
494
|
-
const n =
|
|
520
|
+
const n = kt(r.sort((o, i) => o.title.localeCompare(i.title)), t);
|
|
495
521
|
return {
|
|
496
522
|
sidebar: s.sort((o, i) => o.text.localeCompare(i.text)),
|
|
497
523
|
index: n
|
|
498
524
|
};
|
|
499
525
|
}
|
|
500
|
-
function
|
|
501
|
-
const t =
|
|
526
|
+
function xt(e) {
|
|
527
|
+
const t = me(e), r = [];
|
|
502
528
|
c(" Add extras Vitepress headers pages.", "info");
|
|
503
529
|
for (const s of t) {
|
|
504
530
|
c(` Processing file '${s}'.`, "debug");
|
|
505
|
-
const n = d(process.cwd(), s), o = d(
|
|
506
|
-
|
|
507
|
-
text:
|
|
508
|
-
link: `/${
|
|
531
|
+
const n = d(process.cwd(), s), o = d(fe, k(b(s), { mode: "lowercase", removeIdx: !0 }));
|
|
532
|
+
G(n, o), r.push({
|
|
533
|
+
text: k(x(n).name, { replaceDash: !0, removeIdx: !0 }),
|
|
534
|
+
link: `/${k(x(n).name, { removeIdx: !0, mode: "lowercase" })}`
|
|
509
535
|
});
|
|
510
536
|
}
|
|
511
537
|
return r;
|
|
512
538
|
}
|
|
513
|
-
function
|
|
539
|
+
function se(e, t, r) {
|
|
514
540
|
for (const s of Array.isArray(e) ? e : [e]) {
|
|
515
|
-
const n = d(process.cwd(), s), o =
|
|
541
|
+
const n = d(process.cwd(), s), o = O(n);
|
|
516
542
|
for (const i of o) {
|
|
517
543
|
const a = i.replace(n, ".");
|
|
518
544
|
c(` Processing file '${a}' for entry '${s}'.`, "debug");
|
|
519
545
|
const l = d(process.cwd(), i), g = d(t, a);
|
|
520
|
-
|
|
546
|
+
G(l, g);
|
|
521
547
|
}
|
|
522
548
|
}
|
|
523
549
|
}
|
|
524
|
-
function
|
|
550
|
+
function Pt(e) {
|
|
525
551
|
const t = `---
|
|
526
552
|
`, r = `layout: fork-page
|
|
527
553
|
repoList:
|
|
@@ -534,12 +560,12 @@ Every tile below represents a unique project where contributions have been made-
|
|
|
534
560
|
|
|
535
561
|
This page serves as both a portfolio of past work and a resource for revisiting projects that have made a meaningful impact.
|
|
536
562
|
`, n = e.map(({ repository: o, contributions: i }) => {
|
|
537
|
-
const { name: a, owner: l, html_url: g, description:
|
|
538
|
-
return { name: a, owner: l.login, html_url: g, description:
|
|
563
|
+
const { name: a, owner: l, html_url: g, description: y, stargazers_count: h } = o;
|
|
564
|
+
return { name: a, owner: l.login, html_url: g, description: y, stargazers_count: h, contributions: i };
|
|
539
565
|
});
|
|
540
|
-
c(" Generate forks page.", "info"),
|
|
566
|
+
c(" Generate forks page.", "info"), v(We, t.concat(r, pe.stringify(n), t, s));
|
|
541
567
|
}
|
|
542
|
-
async function
|
|
568
|
+
async function _t(e, t, r) {
|
|
543
569
|
const s = await Promise.all(
|
|
544
570
|
e.map(async (n) => {
|
|
545
571
|
const { source: o, contributors: i } = await it({ repository: n, token: r });
|
|
@@ -549,62 +575,65 @@ async function Pt(e, t, r) {
|
|
|
549
575
|
};
|
|
550
576
|
})
|
|
551
577
|
).then((n) => n.filter(({ repository: o, contributions: i }) => !!o && i));
|
|
552
|
-
|
|
578
|
+
Pt(s);
|
|
553
579
|
}
|
|
554
580
|
function Et(e, t) {
|
|
555
581
|
const r = `---
|
|
556
582
|
`;
|
|
557
|
-
N(
|
|
558
|
-
`), c(" Generate index file.", "info"),
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
m("-
|
|
565
|
-
m("-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
583
|
+
return E(N(X)), c(" Generate Vitepress config.", "info"), v(X, `export default ${JSON.stringify(e, null, 2)}
|
|
584
|
+
`), c(" Generate index file.", "info"), v(Je, r.concat(pe.stringify(t), r)), c(" Add Docpress theme files.", "info"), O(Y).forEach((s) => {
|
|
585
|
+
const n = s.replace(`${Y}/`, "");
|
|
586
|
+
vt(s, d(qe, n));
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
const ne = "prepare", ye = [
|
|
590
|
+
m("-c, --extra-public-content <string>", u.shape.extraPublicContent._def.description),
|
|
591
|
+
m("-f, --forks", u.shape.forks._def.description),
|
|
592
|
+
m("-p, --extra-header-pages <string>", u.shape.extraHeaderPages._def.description),
|
|
593
|
+
m("-t, --extra-theme <string>", u.shape.extraTheme._def.description),
|
|
594
|
+
m("-v, --vitepress-config <string>", u.shape.vitepressConfig._def.description)
|
|
595
|
+
], Ot = R(j(ne), [...ye, ...T]).description("Transform doc to the target vitepress format.").action(async (e) => {
|
|
596
|
+
const t = H(ne, e);
|
|
597
|
+
await we(t);
|
|
569
598
|
});
|
|
570
|
-
async function
|
|
599
|
+
async function we(e) {
|
|
571
600
|
const { extraHeaderPages: t, extraPublicContent: r, extraTheme: s, vitepressConfig: n, forks: o, token: i, username: a } = e;
|
|
572
601
|
c(`
|
|
573
602
|
-> Start transform files to prepare Vitepress build.`, "info");
|
|
574
|
-
const l = Qe(), g = et().reduce(({ internals: $, forks:
|
|
575
|
-
const { clone_url:
|
|
576
|
-
if (
|
|
577
|
-
if (!z &&
|
|
578
|
-
return { internals: [...$,
|
|
603
|
+
const l = Qe(), g = et().reduce(({ internals: $, forks: S }, D) => {
|
|
604
|
+
const { clone_url: ke, private: $e, fork: z, docpress: B } = D;
|
|
605
|
+
if (ke && !$e && !B.filtered) {
|
|
606
|
+
if (!z && B.includes.length)
|
|
607
|
+
return { internals: [...$, D], forks: S };
|
|
579
608
|
if (z)
|
|
580
|
-
return { internals: $, forks: [...
|
|
609
|
+
return { internals: $, forks: [...S, D] };
|
|
581
610
|
}
|
|
582
|
-
return { internals: $, forks:
|
|
583
|
-
}, { internals: [], forks: [] }), { sidebar:
|
|
611
|
+
return { internals: $, forks: S };
|
|
612
|
+
}, { internals: [], forks: [] }), { sidebar: y, index: h } = St(g.internals, l), f = [];
|
|
584
613
|
if (t) {
|
|
585
|
-
const $ =
|
|
586
|
-
o ? f.push(...$.filter((
|
|
614
|
+
const $ = xt(t);
|
|
615
|
+
o ? f.push(...$.filter((S) => S.link !== "/forks")) : f.push(...$);
|
|
587
616
|
}
|
|
588
|
-
r && (c(" Add extras Vitepress public folder content.", "info"),
|
|
589
|
-
const
|
|
590
|
-
Et(
|
|
591
|
-
}
|
|
592
|
-
function
|
|
593
|
-
const e = new
|
|
594
|
-
const s =
|
|
595
|
-
await
|
|
617
|
+
r && (c(" Add extras Vitepress public folder content.", "info"), se(r, d(M, "public"))), s && (c(" Add extras Vitepress theme files.", "info"), se(s, d(Ke))), o && a && (c(" Add fork page to display external contributions.", "info"), await _t(g.forks, a, i), f.push({ text: "Forks", link: "/forks" }));
|
|
618
|
+
const w = bt(y, f, n);
|
|
619
|
+
Et(w, h);
|
|
620
|
+
}
|
|
621
|
+
function Ft() {
|
|
622
|
+
const e = new Ce().name("docpress").description("Build your doc website faster than light ⚡️⚡️⚡️").version(`${ze.version}`).action(async (t, r) => {
|
|
623
|
+
const s = H("global", t);
|
|
624
|
+
await be(s), await we(s), await ve();
|
|
596
625
|
}).configureHelp({
|
|
597
626
|
sortSubcommands: !0,
|
|
598
627
|
sortOptions: !0,
|
|
599
628
|
showGlobalOptions: !0
|
|
600
|
-
}).enablePositionalOptions().passThroughOptions().addCommand(mt).addCommand(
|
|
601
|
-
return
|
|
629
|
+
}).enablePositionalOptions().passThroughOptions().addCommand(mt).addCommand(Ot).addCommand(ht);
|
|
630
|
+
return R(e, [...he, ...ye, ...T]), e;
|
|
602
631
|
}
|
|
603
632
|
function Ht() {
|
|
604
|
-
|
|
633
|
+
Ft().parseAsync(process.argv);
|
|
605
634
|
}
|
|
606
635
|
export {
|
|
607
|
-
|
|
636
|
+
Ft as getProgram,
|
|
608
637
|
Ht as main
|
|
609
638
|
};
|
|
610
639
|
//# sourceMappingURL=cli.js.map
|