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