@tobi-or-not/docpress 0.1.6 → 0.2.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,28 +1,30 @@
1
- import { createOption as l, createCommand as R, Command as ie } from "commander";
2
- import { readFileSync as y, existsSync as T, mkdirSync as ce, readdirSync as M, statSync as D, appendFileSync as z, cpSync as E, rmSync as N, writeFileSync as v, renameSync as ae } from "node:fs";
3
- import { resolve as i, join as de, basename as m, dirname as J, parse as S } from "node:path";
4
- import { z as d } from "zod";
5
- import pe from "axios";
6
- import { rimrafSync as ue } from "rimraf";
7
- import { Octokit as le } from "octokit";
8
- import { simpleGit as fe } from "simple-git";
9
- import { build as me } from "vitepress";
10
- import ge from "yaml";
11
- const he = "@tobi-or-not/docpress", be = "module", ve = "0.1.6", ye = "pnpm@9.12.3", we = "dist/docpress.js", Se = "types/index.d.ts", $e = {
1
+ import { createOption as f, createCommand as D, Command as le } from "commander";
2
+ import T from "chalk";
3
+ import { fromError as pe } from "zod-validation-error";
4
+ import { readFileSync as w, existsSync as G, mkdirSync as ue, readdirSync as Y, statSync as L, appendFileSync as K, cpSync as j, rmSync as A, writeFileSync as y, renameSync as fe } from "node:fs";
5
+ import { resolve as c, join as me, basename as g, dirname as Q, parse as $ } from "node:path";
6
+ import { z as l } from "zod";
7
+ import ge from "axios";
8
+ import { rimrafSync as he } from "rimraf";
9
+ import { Octokit as be } from "octokit";
10
+ import { simpleGit as ve } from "simple-git";
11
+ import { build as ye } from "vitepress";
12
+ import we from "yaml";
13
+ const Se = "@tobi-or-not/docpress", $e = "module", xe = "0.2.0", Ce = "pnpm@9.12.3", ke = "dist/docpress.js", _e = "types/index.d.ts", Oe = {
12
14
  docpress: "bin/docpress.js"
13
- }, Ce = [
15
+ }, Pe = [
14
16
  "bin",
15
17
  "dist",
16
18
  "types"
17
- ], xe = {
19
+ ], Ee = {
18
20
  node: ">=20"
19
- }, ke = {
21
+ }, Re = {
20
22
  build: "pnpm run build:types && pnpm run build:vite",
21
23
  "build:clean": "rimraf ./dist ./types ./tsconfig.tsbuildinfo",
22
24
  "build:docker": "docker build --tag tobi-or-not/docpress --target prod .",
23
25
  "build:types": "tsc",
24
26
  "build:vite": "vite build",
25
- dev: "vite-node ./dev/docpress.ts",
27
+ dev: "rimraf ./docpress && vite-node ./dev/docpress.ts",
26
28
  format: "eslint . --fix",
27
29
  lint: "eslint .",
28
30
  prepare: "husky",
@@ -36,16 +38,18 @@ const he = "@tobi-or-not/docpress", be = "module", ve = "0.1.6", ye = "pnpm@9.12
36
38
  "vp:dev": "vitepress dev ./docpress --port 8080",
37
39
  "vp:dev:docker": "docker run --publish 8080:8080 --name docpress-vp --rm tobi-or-not/docs",
38
40
  "vp:preview": "vitepress preview ./docpress --port 8080"
39
- }, _e = {
41
+ }, De = {
40
42
  axios: "^1.7.7",
43
+ chalk: "^5.3.0",
41
44
  commander: "^12.1.0",
42
45
  octokit: "^4.0.2",
43
46
  rimraf: "^6.0.1",
44
47
  "simple-git": "^3.27.0",
45
48
  vitepress: "^1.4.1",
46
49
  yaml: "^2.6.0",
47
- zod: "^3.23.8"
48
- }, Pe = {
50
+ zod: "^3.23.8",
51
+ "zod-validation-error": "^3.4.0"
52
+ }, Le = {
49
53
  "@antfu/eslint-config": "^3.8.0",
50
54
  "@commitlint/cli": "^19.5.0",
51
55
  "@commitlint/config-conventional": "^19.5.0",
@@ -58,198 +62,249 @@ const he = "@tobi-or-not/docpress", be = "module", ve = "0.1.6", ye = "pnpm@9.12
58
62
  vite: "^5.4.9",
59
63
  "vite-node": "^2.1.3",
60
64
  vitest: "^2.1.3"
61
- }, Oe = {
65
+ }, je = {
62
66
  registry: "https://registry.npmjs.org/",
63
67
  access: "public",
64
68
  tag: "latest"
65
- }, Re = {
66
- name: he,
67
- type: be,
68
- version: ve,
69
- packageManager: ye,
70
- module: we,
71
- types: Se,
72
- bin: $e,
73
- files: Ce,
74
- engines: xe,
75
- scripts: ke,
76
- dependencies: _e,
77
- devDependencies: Pe,
78
- publishConfig: Oe
79
- }, B = d.object({}), x = i(process.cwd(), "docpress"), H = i(process.cwd(), "docpress/repositories.json"), W = i(process.cwd(), "docpress/owner.json"), q = i(process.cwd(), "docpress/docs"), De = i(process.cwd(), "docpress/docs/index.md"), L = i(process.cwd(), "docpress/.vitepress/config.ts");
69
+ }, Fe = {
70
+ name: Se,
71
+ type: $e,
72
+ version: xe,
73
+ packageManager: Ce,
74
+ module: ke,
75
+ types: _e,
76
+ bin: Oe,
77
+ files: Pe,
78
+ engines: Ee,
79
+ scripts: Re,
80
+ dependencies: De,
81
+ devDependencies: Le,
82
+ publishConfig: je
83
+ };
84
+ function Ie() {
85
+ return typeof Number(process.env.LOG_LEVEL) == "number" && !Number.isNaN(Number(process.env.LOG_LEVEL)) ? Number(process.env.LOG_LEVEL) : 30;
86
+ }
87
+ const M = {
88
+ info: { color: "white", level: 30 },
89
+ warn: { color: "yellow", level: 20 },
90
+ error: { color: "red", level: 10 },
91
+ debug: { color: "blue", level: 50 },
92
+ trace: { color: "white", level: 40 },
93
+ success: { color: "green", level: 30 }
94
+ };
95
+ function d(e, t = "info", r) {
96
+ const n = r ? T[r](e) : T[M[t].color](e), o = t === "success" ? "info" : t;
97
+ Ie() >= M[t].level && console[o](n);
98
+ }
99
+ const Z = l.object({}), k = c(process.cwd(), "docpress"), ee = c(process.cwd(), "docpress/repositories.json"), te = c(process.cwd(), "docpress/owner.json"), re = c(process.cwd(), "docpress/docs"), Ve = c(process.cwd(), "docpress/docs/index.md"), U = c(process.cwd(), "docpress/.vitepress/config.ts");
80
100
  async function P(e) {
81
101
  try {
82
- return (await pe.head(e)).status;
102
+ return (await ge.head(e)).status;
83
103
  } catch (t) {
84
104
  return t.response?.status || t.status || 500;
85
105
  }
86
106
  }
87
- function h(e, t) {
88
- let s = "";
89
- return t?.removeIdx && (s = e.replace(/^\d{2}-/, "")), t?.replaceDash && (s = (s || e).replaceAll("-", " ")), t?.mode === "capitalize" ? s = (s || e).slice(0, 1).toUpperCase() + (s || e).slice(1).toLowerCase() : t?.mode === "lowercase" ? s = (s || e).toLowerCase() : t?.mode === "uppercase" && (s = (s || e).toUpperCase()), s || e;
107
+ function b(e, t) {
108
+ let r = "";
109
+ 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;
90
110
  }
91
111
  function F(e, { clean: t } = { clean: !1 }) {
92
112
  try {
93
- t && T(e) && ue(`${e}/*`, { glob: !0 }), T(e) || ce(e, { recursive: !0 });
94
- } catch (s) {
95
- console.error(s);
113
+ t && G(e) && he(`${e}/*`, { glob: !0 }), G(e) || ue(e, { recursive: !0 });
114
+ } catch (r) {
115
+ console.error(r);
96
116
  }
97
117
  }
98
- function Ee(e) {
99
- return D(e).isDirectory();
118
+ function Ne(e) {
119
+ try {
120
+ return L(e).isDirectory();
121
+ } catch {
122
+ return !1;
123
+ }
100
124
  }
101
- function Fe(e) {
102
- return D(e).isFile();
125
+ function Te(e) {
126
+ try {
127
+ return L(e).isFile();
128
+ } catch {
129
+ return !1;
130
+ }
103
131
  }
104
- function j(e) {
105
- return (Array.isArray(e) ? e : [e]).flatMap((t) => Fe(t) ? [t] : Ee(t) ? M(t).flatMap((s) => j(de(t, s))) : []);
132
+ function I(e) {
133
+ return (Array.isArray(e) ? e : [e]).flatMap((t) => Te(t) ? [t] : Ne(t) ? Y(t).flatMap((r) => I(me(t, r))) : []);
106
134
  }
107
- function X(e) {
108
- return j(e).filter((t) => m(t).endsWith(".md"));
135
+ function se(e) {
136
+ return I(e).filter((t) => g(t).endsWith(".md"));
109
137
  }
110
- function je(e) {
111
- return e.reduce((t, s, o, n) => o ? o === n.length - 1 ? `${t} or "${s}"` : `${t}, "${s}"` : `"${s}"`, "");
138
+ function Ge(e) {
139
+ return e.reduce((t, r, n, o) => n ? n === o.length - 1 ? `${t} or "${r}"` : `${t}, "${r}"` : `"${r}"`, "");
112
140
  }
113
- function Ie() {
114
- return JSON.parse(y(W).toString());
141
+ function Ae() {
142
+ return JSON.parse(w(te).toString());
115
143
  }
116
- function Te() {
117
- return JSON.parse(y(H).toString());
144
+ function Me() {
145
+ return JSON.parse(w(ee).toString());
118
146
  }
119
- function Y(...e) {
120
- return e.reduce((t, s) => (s === null || Object.keys(s).forEach((o) => {
121
- const n = t ? t[o] : null, r = s[o];
122
- V(n) && V(r) ? t[o] = Y(n, r) : t[o] = r;
147
+ function R(...e) {
148
+ return e.reduce((t, r) => (r === null || Object.keys(r).forEach((n) => {
149
+ const o = t ? t[n] : null, s = r[n];
150
+ z(o) && z(s) ? t[n] = R(o, s) : t[n] = s;
123
151
  }), t), {});
124
152
  }
125
- function V(e) {
153
+ function z(e) {
126
154
  return e && typeof e == "object" && !Array.isArray(e);
127
155
  }
128
- const A = ["github"], f = d.object({
129
- branch: d.string().describe("Branch used to collect Git provider data.").optional().default("main"),
130
- gitProvider: d.enum(A).describe(`Git provider used to retrieve data. Values should be one of ${je(A)}.`).optional().default("github"),
131
- reposFilter: d.string().transform((e) => e.split(",")).or(d.string().array()).describe("List of comma separated repositories to retrieve from Git provider. Default to all user's public repositories.").optional(),
132
- token: d.string().describe("Git provider token used to collect data.").optional(),
133
- username: d.string().describe("Git provider username used to collect data.")
134
- }), b = d.object({
135
- extraHeaderPages: d.string().describe("List of comma separated additional files or directories to process Vitepress header pages.").transform((e) => e.split(",")).optional(),
136
- extraPublicContent: d.string().describe("List of comma separated additional files or directories to process Vitepress public folder.").transform((e) => e.split(",")).optional(),
137
- extraTheme: d.string().describe("List of comma separated additional files or directories to use as Vitepress theme.").transform((e) => e.split(",")).optional(),
138
- vitepressConfig: d.string().describe("Path to the vitepress configuration file.").transform((e) => JSON.parse(y(i(process.cwd(), e)).toString())).optional()
139
- }), I = d.object({
140
- config: d.string().describe("Path to the docpress configuration file.").transform((e) => JSON.parse(y(i(process.cwd(), e)).toString())).optional()
156
+ const J = ["github"], m = l.object({
157
+ branch: l.string().describe("Branch used to collect Git provider data.").optional().default("main"),
158
+ gitProvider: l.enum(J).describe(`Git provider used to retrieve data. Values should be ${Ge(J)}.`).optional().default("github"),
159
+ reposFilter: l.string().transform((e) => e.split(",")).or(l.string().array()).describe("List of comma separated repositories to retrieve from Git provider. Default to all user's public repositories.").optional(),
160
+ token: l.string().describe("Git provider token used to collect data.").optional(),
161
+ username: l.string().describe("Git provider username used to collect data.")
162
+ }), v = l.object({
163
+ extraHeaderPages: l.string().describe("List of comma separated additional files or directories to process Vitepress header pages.").transform((e) => e.split(",")).optional(),
164
+ extraPublicContent: l.string().describe("List of comma separated additional files or directories to process Vitepress public folder.").transform((e) => e.split(",")).optional(),
165
+ extraTheme: l.string().describe("List of comma separated additional files or directories to use as Vitepress theme.").transform((e) => e.split(",")).optional(),
166
+ vitepressConfig: l.string().describe("Path to the vitepress configuration file.").transform((e) => JSON.parse(w(c(process.cwd(), e)).toString())).optional()
167
+ }), V = l.object({
168
+ config: l.string().describe("Path to the docpress configuration file.").transform((e) => JSON.parse(w(c(process.cwd(), e)).toString())).optional()
141
169
  });
142
- f.merge(b).merge(B);
143
- const Ne = {
144
- build: B,
145
- fetch: f,
146
- prepare: b,
147
- global: I
170
+ m.merge(v).merge(Z);
171
+ const Ue = {
172
+ build: Z,
173
+ fetch: m,
174
+ prepare: v,
175
+ global: V
148
176
  };
149
- function K(e, t) {
150
- const s = Ne[e].safeParse({
151
- ...I.parse(t).config,
152
- ...t
153
- });
154
- if (s.success)
155
- return s.data;
156
- throw new Error(`Invalid options: ${s.error}`);
157
- }
158
- function k(e, t) {
159
- return t.forEach((s) => e.addOption(s)), e;
160
- }
161
- async function Le({ username: e, token: t, branch: s }) {
162
- const o = new le({ auth: t }), { data: n } = await o.request("GET /users/{username}", { username: e }), { data: r } = await o.request("GET /users/{username}/repos", { username: e, sort: "full_name" });
163
- return { user: n, repos: r, branch: s };
164
- }
165
- async function Ve(e, t, s, o) {
177
+ function N(e, t) {
178
+ d("Initializing Docpress...", "info", "blue"), d(`
179
+
180
+ -> Checking for required environment settings and configurations.`, "info");
181
+ function r(o, s) {
182
+ const i = Ue[o].safeParse({
183
+ ...V.parse(s).config,
184
+ ...s
185
+ });
186
+ if (i.success)
187
+ return i.data;
188
+ d(` An error occurred while checking configuration: ${pe(i.error).toString()}`, "error"), process.exit(0);
189
+ }
190
+ const n = e.reduce((o, s) => {
191
+ const i = r(s, t);
192
+ return Object.assign(o, i);
193
+ }, {});
194
+ return d(" Setup complete! Ready to process your documentation.", "info"), n;
195
+ }
196
+ function _(e, t) {
197
+ return t.forEach((r) => e.addOption(r)), e;
198
+ }
199
+ async function ze({ username: e, token: t, branch: r }) {
200
+ d(` Get infos for username '${e}'.`, "info");
201
+ const n = new be({ auth: t }), { data: o } = await n.request("GET /users/{username}", { username: e }), { data: s } = await n.request("GET /users/{username}/repos", { username: e, sort: "full_name" });
202
+ return { user: o, repos: s, branch: r };
203
+ }
204
+ async function Je(e, t, r, n) {
166
205
  F(t, { clean: !0 });
167
206
  try {
168
- const n = fe({ baseDir: t });
169
- await n.init().addConfig("core.sparseCheckout", "true", !0, "local").addRemote("origin", e);
170
- for (const r of o)
171
- z(i(t, ".git/info/sparse-checkout"), `${r}
207
+ const o = ve({ baseDir: t });
208
+ await o.init().addConfig("core.sparseCheckout", "true", !0, "local").addRemote("origin", e);
209
+ for (const s of n)
210
+ K(c(t, ".git/info/sparse-checkout"), `${s}
172
211
  `, "utf8");
173
- await n.pull("origin", s), o.some((r) => r.includes("docs")) && (E(i(t, "docs"), t, { recursive: !0 }), N(i(t, "docs"), { recursive: !0 })), N(i(t, ".git"), { recursive: !0 });
174
- } catch (n) {
175
- console.error(n);
212
+ await o.pull("origin", r), n.some((s) => s.includes("docs")) && (j(c(t, "docs"), t, { recursive: !0 }), A(c(t, "docs"), { recursive: !0 })), A(c(t, ".git"), { recursive: !0 });
213
+ } catch (o) {
214
+ d(` Error when cloning repository: ${o}.`, "error");
176
215
  }
177
216
  }
178
- async function Ae(e, t, s) {
179
- const o = `https://github.com/${e}/${t}/tree/${s}/README.md`, n = `https://github.com/${e}/${t}/tree/${s}/docs`, r = `https://github.com/${e}/${t}/tree/${s}/docs/01-readme.md`, a = await P(o), c = await P(n), u = await P(r);
217
+ async function Be(e, t, r) {
218
+ const n = `https://github.com/${e}/${t}/tree/${r}/README.md`, o = `https://github.com/${e}/${t}/tree/${r}/docs`, s = `https://github.com/${e}/${t}/tree/${r}/docs/01-readme.md`, i = await P(n), a = await P(o), u = await P(s);
180
219
  return {
181
- rootReadmeStatus: a,
182
- docsFolderStatus: c,
220
+ rootReadmeStatus: i,
221
+ docsFolderStatus: a,
183
222
  docsReadmeStatus: u
184
223
  };
185
224
  }
186
- async function Ue({ username: e, branch: t, reposFilter: s, token: o }) {
187
- F(x, { clean: !0 }), await Le({ username: e, token: o, branch: t }).then(async ({ user: n, repos: r, branch: a }) => ze(n, r, a, s)).then(async ({ repos: n }) => Je(n, s));
225
+ async function He({ username: e, branch: t, reposFilter: r, token: n }) {
226
+ F(k, { clean: !0 }), await ze({ username: e, token: n, branch: t }).then(async ({ user: o, repos: s, branch: i }) => Xe(o, s, i, r)).then(async ({ repos: o }) => Ye(o, r));
188
227
  }
189
- async function Ge(e, t, s) {
190
- const o = [];
228
+ async function We(e, t, r) {
229
+ const n = [];
191
230
  return await Promise.all(
192
- e.map(async (n) => {
193
- const r = t ?? n.default_branch ?? "main", a = i(q, n.name), c = Q(n, s);
231
+ e.map(async (o) => {
232
+ const s = t ?? o.default_branch ?? "main", i = c(re, o.name), a = oe(o, r);
194
233
  let u = [];
195
- !n.fork && !n.private && !c && (u = await Me(n, r)), o.push({
196
- ...n,
234
+ !o.fork && !o.private && !a && (u = await qe(o, s)), n.push({
235
+ ...o,
197
236
  docpress: {
198
- filtered: c,
199
- branch: r,
237
+ filtered: a,
238
+ branch: s,
200
239
  includes: u,
201
- projectPath: a,
202
- raw_url: `https://raw.githubusercontent.com/${n.owner.login}/${n.name}/${r}`,
203
- replace_url: `https://github.com/${n.owner.login}/${n.name}/tree/${r}`
240
+ projectPath: i,
241
+ raw_url: `https://raw.githubusercontent.com/${o.owner.login}/${o.name}/${s}`,
242
+ replace_url: `https://github.com/${o.owner.login}/${o.name}/tree/${s}`
204
243
  }
205
244
  });
206
245
  })
207
- ), o;
246
+ ), n;
208
247
  }
209
- async function Me(e, t) {
210
- const s = await Ae(e.owner.login, e.name, t), o = [];
211
- return Object.values(s).every((n) => n === 404) || !e.size ? [] : (s.docsFolderStatus !== 404 && o.push("docs/*"), (s.docsFolderStatus === 404 || s.docsReadmeStatus === 404) && o.push("README.md", "!*/**/README.md"), o);
248
+ async function qe(e, t) {
249
+ const r = await Be(e.owner.login, e.name, t), n = [];
250
+ return Object.values(r).every((o) => o === 404) || !e.size ? [] : (r.docsFolderStatus !== 404 && n.push("docs/*"), (r.docsFolderStatus === 404 || r.docsReadmeStatus === 404) && n.push("README.md", "!*/**/README.md"), n);
212
251
  }
213
- async function ze(e, t, s, o) {
214
- v(W, JSON.stringify(e, null, 2));
215
- const n = await Ge(t, s, o);
216
- return v(H, JSON.stringify(n, null, 2)), { user: e, repos: n };
252
+ async function Xe(e, t, r, n) {
253
+ y(te, JSON.stringify(e, null, 2));
254
+ const o = await We(t, r, n);
255
+ return y(ee, JSON.stringify(o, null, 2)), { user: e, repos: o };
217
256
  }
218
- async function Je(e, t) {
257
+ async function Ye(e, t) {
219
258
  if (!e) {
220
- console.warn("No repository respect docpress rules.");
259
+ d(" No repository respect docpress rules.", "warn");
221
260
  return;
222
261
  }
223
262
  await Promise.all(
224
- e.filter((s) => !Q(s, t)).map(async (s) => Ve(s.clone_url, s.docpress.projectPath, s.docpress.branch, s.docpress.includes))
263
+ e.filter((r) => !oe(r, t)).map(async (r) => {
264
+ d(` Clone repository '${r.name}'.`, "info"), await Je(r.clone_url, r.docpress.projectPath, r.docpress.branch, r.docpress.includes);
265
+ })
225
266
  );
226
267
  }
227
- function Q(e, t) {
228
- const s = t?.filter((r) => r.startsWith("!")).some((r) => e.name === r.substring(1)), o = !t || t?.filter((r) => !r.startsWith("!")).includes(e.name), n = s || !o;
229
- return "docpress" in e && !e.docpress.includes.length ? !0 : !(e.clone_url && !e.fork && !e.private && !n);
230
- }
231
- const _ = [
232
- l("-C, --config <string>", I.shape.config._def.description)
233
- ], Z = "fetch", ee = [
234
- l("-b, --branch <string>", f.shape.branch._def.description).default(f.shape.branch._def.defaultValue()),
235
- l("-g, --git-provider <string>", f.shape.gitProvider._def.description).default(f.shape.gitProvider._def.defaultValue()),
236
- l("-r, --repos-filter <string>", f.shape.reposFilter._def.description),
237
- l("-T, --token <string>", f.shape.token._def.description),
238
- l("-u, --username <string>", f.shape.username._def.description)
239
- ], Be = k(R(Z), [...ee, ..._]).description("Fetch docs with the given username and git provider.").action(async (e) => {
240
- await te(e);
268
+ function oe(e, t) {
269
+ const r = t?.filter((s) => s.startsWith("!")).some((s) => e.name === s.substring(1)), n = !t || t?.filter((s) => !s.startsWith("!")).includes(e.name), o = r || !n;
270
+ return "docpress" in e && !e.docpress.includes.length ? !0 : !(e.clone_url && !e.fork && !e.private && !o);
271
+ }
272
+ const O = [
273
+ f("-C, --config <string>", V.shape.config._def.description)
274
+ ], B = "fetch", ne = [
275
+ f("-b, --branch <string>", m.shape.branch._def.description).default(m.shape.branch._def.defaultValue()),
276
+ f("-g, --git-provider <string>", m.shape.gitProvider._def.description).default(m.shape.gitProvider._def.defaultValue()),
277
+ f("-r, --repos-filter <string>", m.shape.reposFilter._def.description),
278
+ f("-T, --token <string>", m.shape.token._def.description),
279
+ f("-u, --username <string>", m.shape.username._def.description)
280
+ ], Ke = _(D(B), [...ne, ...O]).description("Fetch docs with the given username and git provider.").action(async (e) => {
281
+ const t = N([B], e);
282
+ await ie(t);
241
283
  });
242
- async function te(e) {
243
- const { username: t, reposFilter: s, token: o, branch: n, gitProvider: r } = K(Z, e);
244
- await Ue({ username: t, branch: n, reposFilter: s, gitProvider: r, token: o });
284
+ async function ie(e) {
285
+ const { username: t, reposFilter: r, token: n, branch: o, gitProvider: s } = e;
286
+ d(`
287
+ -> Start fetching documentation files. This may take a moment, especially for larger repositories.`, "info"), await He({ username: t, branch: o, reposFilter: r, gitProvider: s, token: n });
245
288
  }
246
- const He = "build", We = k(R(He), _).description("Build vitepress website.").action(async (e) => {
247
- await se();
289
+ const Qe = "build", Ze = _(D(Qe), O).description("Build vitepress website.").action(async (e) => {
290
+ await ce();
248
291
  });
249
- async function se() {
250
- await me(x);
292
+ async function ce() {
293
+ d(`
294
+ -> Start building Vitepress website.
295
+
296
+ `, "info");
297
+ try {
298
+ await ye(k), d(`
299
+
300
+ Docpress build succedeed.`, "success");
301
+ } catch (e) {
302
+ d(`
303
+
304
+ Docpress build failed : ${e}`, "error");
305
+ }
251
306
  }
252
- const qe = {
307
+ const H = {
253
308
  base: "/",
254
309
  lang: "en-US",
255
310
  vite: {
@@ -258,7 +313,7 @@ const qe = {
258
313
  title: "Home",
259
314
  description: "Docpress",
260
315
  srcDir: "./docs",
261
- cleanUrls: !0,
316
+ cleanUrls: !1,
262
317
  ignoreDeadLinks: "localhostLinks",
263
318
  themeConfig: {
264
319
  outline: [2, 3],
@@ -286,147 +341,147 @@ const qe = {
286
341
  }
287
342
  }
288
343
  };
289
- function Xe(e, t, s) {
290
- const o = Y(qe, s ?? {});
291
- return {
292
- ...o,
293
- themeConfig: {
294
- ...o.themeConfig,
295
- sidebar: e,
296
- nav: t
297
- }
298
- };
344
+ function et(e, t, r) {
345
+ return r ? R(H, r, { themeConfig: { sidebar: e, nav: t } }) : R(H, { themeConfig: { sidebar: e, nav: t } });
299
346
  }
300
- function Ye(e, t) {
301
- const o = y(e, "utf8").replace(/\[([^\]]+)\]\(\.\.\/([^)]+)\)/g, (n, r, a) => `[${r}](${t}/${a})`);
302
- v(e, o, "utf8");
347
+ function tt(e, t) {
348
+ const n = w(e, "utf8").replace(/\[([^\]]+)\]\(\.\.\/([^)]+)\)/g, (o, s, i) => `[${s}](${t}/${i})`);
349
+ y(e, n, "utf8");
303
350
  }
304
- function Ke(e, t) {
305
- const o = y(e, "utf8").replace(/\[([^\]]+)\]\((?!\.?\/docs\/|docs\/|http)(\.?\/)?([^/][^)]+)\)/g, (n, r, a, c) => `[${r}](${t}/${c})`).replace(/\[([^\]]+)\]\((\.?\/docs\/|docs\/)([^)]*)\)/g, (n, r, a, c) => `[${r}](${c})`);
306
- v(e, o, "utf8");
351
+ function rt(e, t) {
352
+ const n = w(e, "utf8").replace(/\[([^\]]+)\]\((?!\.?\/docs\/|docs\/|http)(\.?\/)?([^/][^)]+)\)/g, (o, s, i, a) => `[${s}](${t}/${a})`).replace(/\[([^\]]+)\]\((\.?\/docs\/|docs\/)([^)]*)\)/g, (o, s, i, a) => `[${s}](${a})`);
353
+ y(e, n, "utf8");
307
354
  }
308
- function U(e, t) {
309
- const n = `${m(t) === "readme.md" ? `
355
+ function W(e, t) {
356
+ const o = `${g(t) === "introduction.md" ? `
310
357
  ## Sources` : "# Sources"}
311
358
 
312
359
  Take a look at the [project sources](${e}).
313
360
  `;
314
- z(t, n, "utf8");
361
+ K(t, o, "utf8");
315
362
  }
316
- function Qe(e, t) {
317
- const { name: s, login: o, bio: n } = t;
363
+ function st(e, t) {
364
+ const { name: r, login: n, bio: o } = t;
318
365
  return {
319
366
  layout: "home",
320
367
  hero: {
321
- name: s ? `${s}'s projects` : `${o}'s projects`,
322
- tagline: n ?? "Robots are everywhere 🤖"
368
+ name: r ? `${r}'s projects` : `${n}'s projects`,
369
+ tagline: o ?? "Robots are everywhere 🤖"
323
370
  // \U0001F916
324
371
  },
325
372
  features: e
326
373
  };
327
374
  }
328
- function Ze(e, t, s) {
329
- const o = {
330
- title: h(e, { mode: "capitalize", replaceDash: !0 }),
375
+ function ot(e, t, r) {
376
+ const n = {
377
+ title: b(e, { mode: "capitalize", replaceDash: !0 }),
331
378
  details: t,
332
- link: `/${e}/readme`
379
+ link: `/${e}/introduction`
333
380
  };
334
- return s ? [...s, o] : [o];
381
+ return r ? [...r, n] : [n];
335
382
  }
336
- function et(e, t) {
383
+ function nt(e, t) {
337
384
  return {
338
- text: h(e, { mode: "capitalize", replaceDash: !0 }),
385
+ text: b(e, { mode: "capitalize", replaceDash: !0 }),
339
386
  collapsed: !0,
340
387
  items: t
341
388
  };
342
389
  }
343
- function O(e, t, s) {
344
- const o = {
345
- text: t === "readme" ? "Introduction" : h(t, { mode: "capitalize", replaceDash: !0 }),
390
+ function E(e, t, r) {
391
+ const n = {
392
+ text: t === "introduction" ? "Introduction" : b(t, { mode: "capitalize", replaceDash: !0 }),
346
393
  link: `/${e}/${t}`
347
394
  };
348
- return s ? [...s, o] : [o];
349
- }
350
- function tt(e, t) {
351
- const s = [], o = [];
352
- for (const r of e) {
353
- X([r.docpress.projectPath]).forEach((c) => {
354
- Ye(c, `https://github.com/${r.owner.login}/${r.name}/tree/${r.docpress.branch}`), m(c).toLowerCase() === "readme.md" && Ke(c, `https://github.com/${r.owner.login}/${r.name}/tree/${r.docpress.branch}`);
355
- });
356
- const a = M(r.docpress.projectPath).filter((c) => D(i(r.docpress.projectPath, c)).isFile() && m(i(r.docpress.projectPath, c)).endsWith(".md")).sort((c, u) => c.localeCompare(u)).reduce((c, u, $, C) => {
357
- const g = i(r.docpress.projectPath, u), p = h(m(g), { mode: "lowercase", removeIdx: !0 });
358
- if (p !== m(g) && ae(g, i(J(g), p)), $ === C.length - 1) {
359
- let w;
395
+ return r ? [...r, n] : [n];
396
+ }
397
+ function it(e, t) {
398
+ const r = [], n = [];
399
+ for (const s of e) {
400
+ d(` Replace urls for repository '${s.name}'.`, "info"), se([s.docpress.projectPath]).forEach((a) => {
401
+ tt(a, `https://github.com/${s.owner.login}/${s.name}/tree/${s.docpress.branch}`), g(a).toLowerCase() === "readme.md" && rt(a, `https://github.com/${s.owner.login}/${s.name}/tree/${s.docpress.branch}`);
402
+ }), d(` Generate sidebar for repository '${s.name}'.`, "info");
403
+ const i = Y(s.docpress.projectPath).filter((a) => L(c(s.docpress.projectPath, a)).isFile() && g(c(s.docpress.projectPath, a)).endsWith(".md")).sort((a, u) => a.localeCompare(u)).reduce((a, u, x, C) => {
404
+ const h = c(s.docpress.projectPath, u);
405
+ let p = b(g(h), { mode: "lowercase", removeIdx: !0 });
406
+ if (p === "readme.md" && (p = "introduction.md"), p !== g(h) && fe(h, c(Q(h), p)), x === C.length - 1) {
407
+ let S;
360
408
  if (C.length > 1)
361
- return w = i(r.docpress.projectPath, "sources.md"), U(r.html_url, w), O(
362
- r.name,
363
- S(w).name,
364
- O(r.name, S(p).name, c)
409
+ return S = c(s.docpress.projectPath, "sources.md"), W(s.html_url, S), E(
410
+ s.name,
411
+ $(S).name,
412
+ E(s.name, $(p).name, a)
365
413
  );
366
- w = i(r.docpress.projectPath, "readme.md"), U(r.html_url, w);
414
+ S = c(s.docpress.projectPath, p), W(s.html_url, S);
367
415
  }
368
- return O(r.name, S(p).name, c);
416
+ return E(s.name, $(p).name, a);
369
417
  }, []);
370
- o.push(et(r.name, a)), s.push(...Ze(r.name, r.description || ""));
418
+ n.push(nt(s.name, i)), r.push(...ot(s.name, s.description || ""));
371
419
  }
372
- const n = Qe(s.sort((r, a) => r.title.localeCompare(a.title)), t);
420
+ d(" Generate index content.", "info");
421
+ const o = st(r.sort((s, i) => s.title.localeCompare(i.title)), t);
373
422
  return {
374
- sidebar: o.sort((r, a) => r.text.localeCompare(a.text)),
375
- index: n
423
+ sidebar: n.sort((s, i) => s.text.localeCompare(i.text)),
424
+ index: o
376
425
  };
377
426
  }
378
- function st(e) {
379
- const t = X(e), s = [];
380
- for (const o of t) {
381
- const n = i(process.cwd(), o), r = i(q, h(m(o), { mode: "lowercase", removeIdx: !0 }));
382
- E(n, r), s.push({
383
- text: h(S(n).name, { replaceDash: !0, removeIdx: !0 }),
384
- link: `/${h(S(n).name, { removeIdx: !0, mode: "lowercase" })}`
427
+ function ct(e) {
428
+ const t = se(e), r = [];
429
+ d(" Add extras Vitepress headers pages.", "info");
430
+ for (const n of t) {
431
+ const o = c(process.cwd(), n), s = c(re, b(g(n), { mode: "lowercase", removeIdx: !0 }));
432
+ j(o, s), r.push({
433
+ text: b($(o).name, { replaceDash: !0, removeIdx: !0 }),
434
+ link: `/${b($(o).name, { removeIdx: !0, mode: "lowercase" })}`
385
435
  });
386
436
  }
387
- return s;
437
+ return r;
388
438
  }
389
- function G(e, t, s) {
390
- const o = j(e);
391
- for (const n of o) {
392
- const r = i(process.cwd(), n), a = i(t, m(n));
393
- E(r, a);
439
+ function q(e, t, r) {
440
+ const n = I(e);
441
+ for (const o of n) {
442
+ const s = c(process.cwd(), o), i = c(t, g(o));
443
+ j(s, i);
394
444
  }
395
445
  }
396
- function rt(e, t) {
397
- F(J(L)), v(L, `export default ${JSON.stringify(e, null, 2)}
398
- `), v(De, `---
399
- `.concat(ge.stringify(t)));
400
- }
401
- const re = "prepare", oe = [
402
- l("-c, --extra-public-content <string>", b.shape.extraPublicContent._def.description),
403
- l("-p, --extra-header-pages <string>", b.shape.extraHeaderPages._def.description),
404
- l("-t, --extra-theme <string>", b.shape.extraTheme._def.description),
405
- l("-v, --vitepress-config <string>", b.shape.vitepressConfig._def.description)
406
- ], ot = k(R(re), [...oe, ..._]).description("Transform doc to the target vitepress format.").action(async (e) => {
407
- await ne(e);
446
+ function at(e, t) {
447
+ F(Q(U)), d(" Generate Vitepress config.", "info"), y(U, `export default ${JSON.stringify(e, null, 2)}
448
+ `), d(" Generate index file.", "info"), y(Ve, `---
449
+ `.concat(we.stringify(t)));
450
+ }
451
+ const X = "prepare", ae = [
452
+ f("-c, --extra-public-content <string>", v.shape.extraPublicContent._def.description),
453
+ f("-p, --extra-header-pages <string>", v.shape.extraHeaderPages._def.description),
454
+ f("-t, --extra-theme <string>", v.shape.extraTheme._def.description),
455
+ f("-v, --vitepress-config <string>", v.shape.vitepressConfig._def.description)
456
+ ], dt = _(D(X), [...ae, ...O]).description("Transform doc to the target vitepress format.").action(async (e) => {
457
+ const t = N([X], e);
458
+ await de(t);
408
459
  });
409
- async function ne(e) {
410
- const { extraHeaderPages: t, extraPublicContent: s, extraTheme: o, vitepressConfig: n } = K(re, e), r = Ie(), a = Te().reduce((g, p) => p.clone_url && !p.fork && !p.private && p.docpress.includes.length && !p.docpress.filtered ? [...g, p] : g, []), { sidebar: c, index: u } = tt(a, r), $ = [];
411
- t && $.push(...st(t)), s && G(s, i(x, "public")), o && G(o, i(x, ".vitepress/theme"));
412
- const C = Xe(c, $, n);
413
- rt(C, u);
414
- }
415
- function nt() {
416
- const e = new ie().name("docpress").description("Build your doc website faster than light ⚡️⚡️⚡️").version(`${Re.version}`).addCommand(Be).addCommand(ot).addCommand(We).action(async (t, s) => {
417
- await te(t), await ne(t), await se();
460
+ async function de(e) {
461
+ const { extraHeaderPages: t, extraPublicContent: r, extraTheme: n, vitepressConfig: o } = e;
462
+ d(`
463
+ -> Start transform files to prepare Vitepress build.`, "info");
464
+ const s = Ae(), i = Me().reduce((h, p) => p.clone_url && !p.fork && !p.private && p.docpress.includes.length && !p.docpress.filtered ? [...h, p] : h, []), { sidebar: a, index: u } = it(i, s), x = [];
465
+ t && x.push(...ct(t)), r && (d(" Add extras Vitepress public folder content.", "info"), q(r, c(k, "public"))), n && (d(" Add extras Vitepress theme files.", "info"), q(n, c(k, ".vitepress/theme")));
466
+ const C = et(a, x, o);
467
+ at(C, u);
468
+ }
469
+ function lt() {
470
+ const e = new le().name("docpress").description("Build your doc website faster than light ⚡️⚡️⚡️").version(`${Fe.version}`).addCommand(Ke).addCommand(dt).addCommand(Ze).action(async (t, r) => {
471
+ const n = N(["fetch", "prepare"], t);
472
+ await ie(n), await de(n), await ce();
418
473
  }).configureHelp({
419
474
  sortSubcommands: !0,
420
475
  sortOptions: !0,
421
476
  showGlobalOptions: !0
422
477
  }).enablePositionalOptions().passThroughOptions();
423
- return k(e, [...ee, ...oe, ..._]), e;
478
+ return _(e, [...ne, ...ae, ...O]), e;
424
479
  }
425
- function ht() {
426
- nt().parseAsync();
480
+ function xt() {
481
+ lt().parseAsync();
427
482
  }
428
483
  export {
429
- nt as getProgram,
430
- ht as main
484
+ lt as getProgram,
485
+ xt as main
431
486
  };
432
487
  //# sourceMappingURL=cli.js.map