@tobi-or-not/docpress 0.3.0 → 0.3.2

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