@tobi-or-not/docpress 0.2.3 → 0.3.1

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 h, 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.3", Ce = "pnpm@9.12.3", ke = "dist/docpress.js", _e = "types/index.d.ts", Oe = {
1
+ import { createOption as m, createCommand as A, Command as Se } from "commander";
2
+ import W from "chalk";
3
+ import { fromZodError as ce } from "zod-validation-error";
4
+ import { z as u } from "zod";
5
+ import { readFileSync as C, existsSync as q, mkdirSync as xe, readdirSync as ae, statSync as G, appendFileSync as de, cpSync as N, rmSync as K, writeFileSync as v, renameSync as Pe } from "node:fs";
6
+ import { resolve as d, join as _e, basename as b, dirname as M, parse as x } from "node:path";
7
+ import Ee from "axios";
8
+ import { rimrafSync as Oe } from "rimraf";
9
+ import { Octokit as ue } from "@octokit/rest";
10
+ import { simpleGit as Fe } from "simple-git";
11
+ import { build as Re } from "vitepress";
12
+ import pe from "yaml";
13
+ const Te = "@tobi-or-not/docpress", De = "module", Le = "0.3.1", Ie = "pnpm@9.12.3", Ve = "dist/docpress.js", je = "types/index.d.ts", Ae = {
14
14
  docpress: "bin/docpress.js"
15
- }, Pe = [
15
+ }, Ge = [
16
16
  "bin",
17
17
  "dist",
18
18
  "types"
19
- ], Ee = {
19
+ ], Ne = {
20
20
  node: ">=20"
21
- }, Re = {
21
+ }, Me = {
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.3", 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
+ }, Ue = {
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
+ }, He = {
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
+ }, ze = {
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
+ }, Be = {
73
+ name: Te,
74
+ type: De,
75
+ version: Le,
76
+ packageManager: Ie,
77
+ module: Ve,
78
+ types: je,
79
+ bin: Ae,
80
+ files: Ge,
81
+ engines: Ne,
82
+ scripts: Me,
83
+ dependencies: Ue,
84
+ devDependencies: He,
85
+ publishConfig: ze
83
86
  };
84
- function Ie() {
87
+ function Je() {
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 X = {
88
91
  info: { color: "white", level: 30 },
89
92
  warn: { color: "yellow", level: 20 },
90
93
  error: { color: "red", level: 10 },
@@ -92,219 +95,311 @@ 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 ? W[r](e) : W[X[t].color](e), n = t === "success" ? "info" : t;
100
+ Je() >= X[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 U = d(process.cwd(), "docpress"), le = d(process.cwd(), "docpress/repositories.json"), fe = d(process.cwd(), "docpress/owner.json"), me = d(process.cwd(), "docpress/docs"), We = d(process.cwd(), "docpress/docs/index.md"), qe = d(process.cwd(), "docpress/docs/forks.md"), Y = d(process.cwd(), "docpress/.vitepress/config.ts"), Z = d(process.cwd(), "docpress/.vitepress/theme"), Ke = d(process.cwd(), "docpress/.vitepress/theme/extras"), L = d(import.meta.dirname, "../templates/theme");
103
+ async function I(e) {
101
104
  try {
102
- return (await ge.head(e)).status;
105
+ return (await Ee.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 k(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 E(e, { clean: t } = { clean: !1 }) {
112
115
  try {
113
- t && G(e) && he(`${e}/*`, { glob: !0 }), G(e) || ue(e, { recursive: !0 });
116
+ t && q(e) && Oe(`${e}/*`, { glob: !0 }), q(e) || xe(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 G(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 G(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 O(e) {
136
+ return (Array.isArray(e) ? e : [e]).flatMap((t) => Ye(t) ? [t] : Xe(t) ? ae(t).flatMap((r) => O(_e(t, r))) : []);
134
137
  }
135
- function se(e) {
136
- return I(e).filter((t) => h(t).endsWith(".md"));
138
+ function ge(e) {
139
+ return O(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(C(fe).toString());
143
146
  }
144
- function Me() {
145
- return JSON.parse(w(ee).toString());
147
+ function et() {
148
+ return JSON.parse(C(le).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 j(...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
+ Q(n) && Q(o) ? t[s] = j(n, o) : t[s] = o;
151
154
  }), t), {});
152
155
  }
153
- function z(e) {
156
+ function Q(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 ee(e) {
160
+ if (!e)
161
+ return {};
162
+ try {
163
+ const t = d(process.cwd(), e), r = C(t, "utf8");
164
+ return JSON.parse(r);
165
+ } catch {
166
+ return {};
167
+ }
168
+ }
169
+ function P(e) {
170
+ return e.split(",");
171
+ }
172
+ const te = ["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(te).describe(`Git provider used to retrieve data. Values should be ${Ze(te)}.`).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(ee(t)), i = ee(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
+ ${ce(o).toString()}`, "error"), process.exit(1);
202
+ }
203
+ }
204
+ const F = 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
+ }), _ = F.partial().transform(H), tt = F.pick({}), rt = F.pick({
213
+ branch: !0,
214
+ config: !0,
215
+ gitProvider: !0,
216
+ reposFilter: !0,
217
+ token: !0,
218
+ username: !0
219
+ }).transform(H), ot = F.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: _
176
234
  };
177
- function N(e, t) {
178
- d("Initializing Docpress...", "info", "blue"), d(`
235
+ function z(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
+ ${ce(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 R(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 };
246
+ async function nt({ username: e, token: t, branch: r }) {
247
+ c(` Get infos for username '${e}'.`, "info");
248
+ const s = new ue({ auth: t });
249
+ c(" Get user infos.", "debug");
250
+ const { data: n } = await s.rest.users.getByUsername({ username: e });
251
+ c(" Get repositories infos.", "debug");
252
+ const { data: o } = await s.rest.repos.listForUser({ username: e, sort: "full_name" });
253
+ return { user: n, repos: o, branch: r };
254
+ }
255
+ async function it({
256
+ repository: e,
257
+ token: t
258
+ }) {
259
+ c(` Get contributors infos for repository '${e.name}'.`, "info");
260
+ const r = new ue({
261
+ auth: t,
262
+ log: {
263
+ debug: () => {
264
+ },
265
+ info: () => {
266
+ },
267
+ warn: (o) => {
268
+ o.includes("404") || console.warn(o);
269
+ },
270
+ error: (o) => {
271
+ o.includes("404") || console.error(o);
272
+ }
273
+ }
274
+ }), { data: s } = await r.rest.repos.get({
275
+ owner: e.owner.login,
276
+ repo: e.name
277
+ });
278
+ if (!s.source?.owner?.login)
279
+ return { source: s.source, contributors: [] };
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
+ }
297
+ return { source: s.source, contributors: n };
203
298
  }
204
- async function Je(e, t, r, o) {
205
- F(t, { clean: !0 });
299
+ async function ct(e, t, r, s, n) {
300
+ E(r, { clean: !0 });
206
301
  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}
302
+ const o = Fe({ baseDir: r });
303
+ await o.init().addConfig("core.sparseCheckout", "true", !0, "local").addRemote("origin", t);
304
+ for (const i of n)
305
+ c(` Add '${i}' to '${e}' sparse-checkout file.`, "debug"), de(d(r, ".git/info/sparse-checkout"), `${i}
211
306
  `, "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");
307
+ c(` Clone repository '${e}'.`, "info"), await o.pull("origin", s), n.some((i) => i.includes("docs")) && (N(d(r, "docs"), r, { recursive: !0 }), K(d(r, "docs"), { recursive: !0 })), K(d(r, ".git"), { recursive: !0 });
308
+ } catch (o) {
309
+ c(` Error when cloning repository: ${o}.`, "error");
215
310
  }
216
311
  }
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);
312
+ async function at(e, t, r) {
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 I(s), a = await I(n), l = await I(o);
219
314
  return {
220
315
  rootReadmeStatus: i,
221
316
  docsFolderStatus: a,
222
- docsReadmeStatus: u
317
+ docsReadmeStatus: l
223
318
  };
224
319
  }
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));
320
+ async function dt({ username: e, branch: t, reposFilter: r, token: s }) {
321
+ E(U, { 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
322
  }
228
- async function We(e, t, r) {
229
- const o = [];
323
+ async function ut(e, t, r) {
324
+ const s = [];
230
325
  return await Promise.all(
231
326
  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({
327
+ const o = t ?? n.default_branch ?? "main", i = d(me, n.name), a = he(n, r);
328
+ let l = [];
329
+ !n.fork && !n.private && !a && (l = await pt(n, o)), s.push({
235
330
  ...n,
236
331
  docpress: {
237
332
  filtered: a,
238
- branch: s,
239
- includes: u,
333
+ branch: o,
334
+ includes: l,
240
335
  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}`
336
+ raw_url: `https://raw.githubusercontent.com/${n.owner.login}/${n.name}/${o}`,
337
+ replace_url: `https://github.com/${n.owner.login}/${n.name}/tree/${o}`
243
338
  }
244
339
  });
245
340
  })
246
- ), o;
341
+ ), s;
247
342
  }
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);
343
+ async function pt(e, t) {
344
+ const r = await at(e.owner.login, e.name, t), s = [];
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);
251
346
  }
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 };
347
+ async function lt(e, t, r, s) {
348
+ v(fe, JSON.stringify(e, null, 2));
349
+ const n = await ut(t, r, s);
350
+ return v(le, JSON.stringify(n, null, 2)), { user: e, repos: n };
256
351
  }
257
- async function Ye(e, t) {
352
+ async function ft(e, t) {
258
353
  if (!e) {
259
- d(" No repository respect docpress rules.", "warn");
354
+ c(" No repository respect docpress rules.", "warn");
260
355
  return;
261
356
  }
262
357
  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);
358
+ e.filter((r) => !he(r, t)).map(async (r) => {
359
+ await ct(r.name, r.clone_url, r.docpress.projectPath, r.docpress.branch, r.docpress.includes);
265
360
  })
266
361
  );
267
362
  }
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);
363
+ function he(e, t) {
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;
365
+ return "docpress" in e && !e.docpress.includes.length ? !0 : !(e.clone_url && !e.private && !o);
366
+ }
367
+ const T = [
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
+ ], re = "fetch", be = [
372
+ m("-b, --branch <string>", p.shape.branch._def.description).default(p.shape.branch._def.defaultValue()),
373
+ m("-g, --git-provider <string>", p.shape.gitProvider._def.description).default(p.shape.gitProvider._def.defaultValue()),
374
+ m("-r, --repos-filter <string>", p.shape.reposFilter._def.description)
375
+ ], mt = R(A(re), [...be, ...T]).description("Fetch docs with the given username and git provider.").action(async (e) => {
376
+ const t = z(re, e);
377
+ await ve(t);
283
378
  });
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 });
379
+ async function ve(e) {
380
+ const { username: t, reposFilter: r, token: s, branch: n, gitProvider: o } = e;
381
+ c(`
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 });
288
383
  }
289
- const Qe = "build", Ze = _(D(Qe), O).description("Build vitepress website.").action(async (e) => {
290
- await ce();
384
+ const gt = "build", ht = R(A(gt), T).description("Build vitepress website.").action(async (e) => {
385
+ await ye();
291
386
  });
292
- async function ce() {
293
- d(`
387
+ async function ye() {
388
+ c(`
294
389
  -> Start building Vitepress website.
295
390
 
296
391
  `, "info");
297
392
  try {
298
- await ye(k), d(`
393
+ await Re(U), c(`
299
394
 
300
395
  Docpress build succedeed.`, "success");
301
396
  } catch (e) {
302
- d(`
397
+ c(`
303
398
 
304
399
  Docpress build failed : ${e}`, "error");
305
400
  }
306
401
  }
307
- const H = {
402
+ const oe = {
308
403
  base: "/",
309
404
  lang: "en-US",
310
405
  vite: {
@@ -341,150 +436,206 @@ const H = {
341
436
  }
342
437
  }
343
438
  };
344
- function et(e, t, r) {
345
- return r ? R(H, r, { themeConfig: { sidebar: e, nav: t } }) : R(H, { themeConfig: { sidebar: e, nav: t } });
439
+ function bt(e, t, r) {
440
+ return r ? j(oe, r, { themeConfig: { sidebar: e, nav: t } }) : j(oe, { themeConfig: { sidebar: e, nav: t } });
346
441
  }
347
- function tt(e, t) {
348
- const o = w(e, "utf8").replace(/\[([^\]]+)\]\(\.\.\/([^)]+)\)/g, (n, s, i) => `[${s}](${t}/${i})`);
349
- y(e, o, "utf8");
442
+ function vt(e, t) {
443
+ const r = C(e, { encoding: "utf8" });
444
+ E(M(t)), v(t, r);
350
445
  }
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");
446
+ function yt(e, t) {
447
+ const s = C(e, "utf8").replace(/\[([^\]]+)\]\(\.\.\/([^)]+)\)/g, (n, o, i) => `[${o}](${t}/${i})`);
448
+ v(e, s, "utf8");
354
449
  }
355
- function W(e, t) {
356
- const n = `${h(t) === "introduction.md" ? `
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");
453
+ }
454
+ function se(e, t) {
455
+ const n = `${b(t) === "introduction.md" ? `
357
456
  ## Sources` : "# Sources"}
358
457
 
359
458
  Take a look at the [project sources](${e}).
360
459
  `;
361
- K(t, n, "utf8");
460
+ de(t, n, "utf8");
362
461
  }
363
- function st(e, t) {
364
- const { name: r, login: o, bio: n } = t;
462
+ function kt(e, t) {
463
+ const { name: r, login: s, bio: n } = t;
365
464
  return {
366
465
  layout: "home",
367
466
  hero: {
368
- name: r ? `${r}'s projects` : `${o}'s projects`,
467
+ name: r ? `${r}'s projects` : `${s}'s projects`,
369
468
  tagline: n ?? "Robots are everywhere 🤖"
370
469
  // \U0001F916
371
470
  },
372
471
  features: e
373
472
  };
374
473
  }
375
- function ot(e, t, r) {
376
- const o = {
377
- title: b(e, { mode: "capitalize", replaceDash: !0 }),
474
+ function $t(e, t, r) {
475
+ const s = {
476
+ title: k(e, { mode: "capitalize", replaceDash: !0 }),
378
477
  details: t,
379
478
  link: `/${e}/introduction`
380
479
  };
381
- return r ? [...r, o] : [o];
480
+ return r ? [...r, s] : [s];
382
481
  }
383
- function nt(e, t) {
482
+ function Ct(e, t) {
384
483
  return {
385
- text: b(e, { mode: "capitalize", replaceDash: !0 }),
484
+ text: k(e, { mode: "capitalize", replaceDash: !0 }),
386
485
  collapsed: !0,
387
486
  items: t
388
487
  };
389
488
  }
390
- function E(e, t, r) {
391
- const o = {
392
- text: t === "introduction" ? "Introduction" : b(t, { mode: "capitalize", replaceDash: !0 }),
489
+ function V(e, t, r) {
490
+ const s = {
491
+ text: t === "introduction" ? "Introduction" : k(t, { mode: "capitalize", replaceDash: !0 }),
393
492
  link: `/${e}/${t}`
394
493
  };
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}`), h(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() && h(c(s.docpress.projectPath, a)).endsWith(".md")).sort((a, u) => a.localeCompare(u)).reduce((a, u, x, C) => {
404
- const g = c(s.docpress.projectPath, u);
405
- let p = b(h(g), { mode: "lowercase", removeIdx: !0 });
406
- if (p === "readme.md" && (p = "introduction.md"), p !== h(g) && fe(g, c(Q(g), 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)
494
+ return r ? [...r, s] : [s];
495
+ }
496
+ function St(e, t) {
497
+ const r = [], s = [];
498
+ for (const o of e) {
499
+ c(` Replace urls for repository '${o.name}'.`, "info"), ge([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}`);
501
+ }), c(` Generate sidebar for repository '${o.name}'.`, "info");
502
+ const i = ae(o.docpress.projectPath).filter((a) => G(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) => {
503
+ const h = d(o.docpress.projectPath, l);
504
+ let f = k(b(h), { mode: "lowercase", removeIdx: !0 });
505
+ if (f === "readme.md" && (f = "introduction.md"), f !== b(h) && Pe(h, d(M(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"), se(o.html_url, w), V(
509
+ o.name,
510
+ x(w).name,
511
+ V(o.name, x(f).name, a)
413
512
  );
414
- S = c(s.docpress.projectPath, p), W(s.html_url, S);
513
+ w = d(o.docpress.projectPath, f), se(o.html_url, w);
415
514
  }
416
- return E(s.name, $(p).name, a);
515
+ return V(o.name, x(f).name, a);
417
516
  }, []);
418
- o.push(nt(s.name, i)), r.push(...ot(s.name, s.description || ""));
517
+ s.push(Ct(o.name, i)), r.push(...$t(o.name, o.description || ""));
419
518
  }
420
- d(" Generate index content.", "info");
421
- const n = st(r.sort((s, i) => s.title.localeCompare(i.title)), t);
519
+ c(" Generate index content.", "info");
520
+ const n = kt(r.sort((o, i) => o.title.localeCompare(i.title)), t);
422
521
  return {
423
- sidebar: o.sort((s, i) => s.text.localeCompare(i.text)),
522
+ sidebar: s.sort((o, i) => o.text.localeCompare(i.text)),
424
523
  index: n
425
524
  };
426
525
  }
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(h(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" })}`
526
+ function xt(e) {
527
+ const t = ge(e), r = [];
528
+ c(" Add extras Vitepress headers pages.", "info");
529
+ for (const s of t) {
530
+ c(` Processing file '${s}'.`, "debug");
531
+ const n = d(process.cwd(), s), o = d(me, k(b(s), { mode: "lowercase", removeIdx: !0 }));
532
+ N(n, o), r.push({
533
+ text: k(x(n).name, { replaceDash: !0, removeIdx: !0 }),
534
+ link: `/${k(x(n).name, { removeIdx: !0, mode: "lowercase" })}`
435
535
  });
436
536
  }
437
537
  return r;
438
538
  }
439
- function q(e, t, r) {
440
- for (const o of Array.isArray(e) ? e : [e]) {
441
- const n = c(process.cwd(), o), s = I(n);
442
- for (const i of s) {
443
- const a = c(process.cwd(), i), u = c(t, i.replace(n, "."));
444
- j(a, u);
539
+ function ne(e, t, r) {
540
+ for (const s of Array.isArray(e) ? e : [e]) {
541
+ const n = d(process.cwd(), s), o = O(n);
542
+ for (const i of o) {
543
+ const a = i.replace(n, ".");
544
+ c(` Processing file '${a}' for entry '${s}'.`, "debug");
545
+ const l = d(process.cwd(), i), g = d(t, a);
546
+ N(l, g);
445
547
  }
446
548
  }
447
549
  }
448
- function at(e, t) {
550
+ function Pt(e) {
551
+ const t = `---
552
+ `, r = `layout: fork-page
553
+ repoList:
554
+ `, s = `
555
+ # External contributions
556
+
557
+ 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.
558
+
559
+ 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.
560
+
561
+ This page serves as both a portfolio of past work and a resource for revisiting projects that have made a meaningful impact.
562
+ `, n = e.map(({ repository: o, contributions: i }) => {
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 };
565
+ });
566
+ c(" Generate forks page.", "info"), v(qe, t.concat(r, pe.stringify(n), t, s));
567
+ }
568
+ async function _t(e, t, r) {
569
+ const s = await Promise.all(
570
+ e.map(async (n) => {
571
+ const { source: o, contributors: i } = await it({ repository: n, token: r });
572
+ return {
573
+ contributions: i?.find((a) => a.login === t)?.contributions ?? 0,
574
+ repository: o
575
+ };
576
+ })
577
+ ).then((n) => n.filter(({ repository: o, contributions: i }) => !!o && i));
578
+ Pt(s);
579
+ }
580
+ function Et(e, t) {
449
581
  const r = `---
450
582
  `;
451
- F(Q(U)), d(" Generate Vitepress config.", "info"), y(U, `export default ${JSON.stringify(e, null, 2)}
452
- `), d(" Generate index file.", "info"), y(Ve, r.concat(we.stringify(t), r));
453
- }
454
- const X = "prepare", ae = [
455
- f("-c, --extra-public-content <string>", v.shape.extraPublicContent._def.description),
456
- f("-p, --extra-header-pages <string>", v.shape.extraHeaderPages._def.description),
457
- f("-t, --extra-theme <string>", v.shape.extraTheme._def.description),
458
- f("-v, --vitepress-config <string>", v.shape.vitepressConfig._def.description)
459
- ], dt = _(D(X), [...ae, ...O]).description("Transform doc to the target vitepress format.").action(async (e) => {
460
- const t = N([X], e);
461
- await de(t);
583
+ E(M(Y)), c(" Generate Vitepress config.", "info"), v(Y, `export default ${JSON.stringify(e, null, 2)}
584
+ `), c(" Generate index file.", "info"), v(We, r.concat(pe.stringify(t), r)), c(" Add Docpress theme files.", "info");
585
+ const s = O(L);
586
+ for (const n of s) {
587
+ const o = n.replace(`${L}/`, "");
588
+ c(` Processing file '${d(Z, o)}'.`, "debug"), vt(d(L, n), d(Z, o));
589
+ }
590
+ }
591
+ const ie = "prepare", we = [
592
+ m("-c, --extra-public-content <string>", p.shape.extraPublicContent._def.description),
593
+ m("-f, --forks", p.shape.forks._def.description),
594
+ m("-p, --extra-header-pages <string>", p.shape.extraHeaderPages._def.description),
595
+ m("-t, --extra-theme <string>", p.shape.extraTheme._def.description),
596
+ m("-v, --vitepress-config <string>", p.shape.vitepressConfig._def.description)
597
+ ], Ot = R(A(ie), [...we, ...T]).description("Transform doc to the target vitepress format.").action(async (e) => {
598
+ const t = z(ie, e);
599
+ await ke(t);
462
600
  });
463
- async function de(e) {
464
- const { extraHeaderPages: t, extraPublicContent: r, extraTheme: o, vitepressConfig: n } = e;
465
- d(`
601
+ async function ke(e) {
602
+ const { extraHeaderPages: t, extraPublicContent: r, extraTheme: s, vitepressConfig: n, forks: o, token: i, username: a } = e;
603
+ c(`
466
604
  -> Start transform files to prepare Vitepress build.`, "info");
467
- const s = Ae(), i = Me().reduce((g, p) => p.clone_url && !p.fork && !p.private && p.docpress.includes.length && !p.docpress.filtered ? [...g, p] : g, []), { sidebar: a, index: u } = it(i, s), x = [];
468
- 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")));
469
- const C = et(a, x, n);
470
- at(C, u);
471
- }
472
- function lt() {
473
- 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) => {
474
- const o = N(["fetch", "prepare"], t);
475
- await ie(o), await de(o), await ce();
605
+ const l = Qe(), g = et().reduce(({ internals: $, forks: S }, D) => {
606
+ const { clone_url: $e, private: Ce, fork: B, docpress: J } = D;
607
+ if ($e && !Ce && !J.filtered) {
608
+ if (!B && J.includes.length)
609
+ return { internals: [...$, D], forks: S };
610
+ if (B)
611
+ return { internals: $, forks: [...S, D] };
612
+ }
613
+ return { internals: $, forks: S };
614
+ }, { internals: [], forks: [] }), { sidebar: y, index: h } = St(g.internals, l), f = [];
615
+ if (t) {
616
+ const $ = xt(t);
617
+ o ? f.push(...$.filter((S) => S.link !== "/forks")) : f.push(...$);
618
+ }
619
+ r && (c(" Add extras Vitepress public folder content.", "info"), ne(r, d(U, "public"))), s && (c(" Add extras Vitepress theme files.", "info"), ne(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" }));
620
+ const w = bt(y, f, n);
621
+ Et(w, h);
622
+ }
623
+ function Ft() {
624
+ const e = new Se().name("docpress").description("Build your doc website faster than light ⚡️⚡️⚡️").version(`${Be.version}`).action(async (t, r) => {
625
+ const s = z("global", t);
626
+ await ve(s), await ke(s), await ye();
476
627
  }).configureHelp({
477
628
  sortSubcommands: !0,
478
629
  sortOptions: !0,
479
630
  showGlobalOptions: !0
480
- }).enablePositionalOptions().passThroughOptions();
481
- return _(e, [...ne, ...ae, ...O]), e;
631
+ }).enablePositionalOptions().passThroughOptions().addCommand(mt).addCommand(Ot).addCommand(ht);
632
+ return R(e, [...be, ...we, ...T]), e;
482
633
  }
483
- function xt() {
484
- lt().parseAsync();
634
+ function Ht() {
635
+ Ft().parseAsync(process.argv);
485
636
  }
486
637
  export {
487
- lt as getProgram,
488
- xt as main
638
+ Ft as getProgram,
639
+ Ht as main
489
640
  };
490
641
  //# sourceMappingURL=cli.js.map