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