@t8/docsgen 0.1.2 → 0.1.4

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/bin.js CHANGED
@@ -152,7 +152,7 @@ async function getConfig() {
152
152
 
153
153
  // src/bin/runEntry.ts
154
154
  var import_node_child_process2 = require("node:child_process");
155
- var import_promises6 = require("node:fs/promises");
155
+ var import_promises7 = require("node:fs/promises");
156
156
  var import_node_util2 = require("node:util");
157
157
 
158
158
  // src/bin/cleanup.ts
@@ -166,6 +166,9 @@ async function cleanup({ dir = "" }) {
166
166
  );
167
167
  }
168
168
 
169
+ // src/bin/createFiles.ts
170
+ var import_promises6 = require("node:fs/promises");
171
+
169
172
  // src/bin/setCName.ts
170
173
  var import_promises3 = require("node:fs/promises");
171
174
  var import_node_path2 = require("node:path");
@@ -266,19 +269,22 @@ async function getNav(ctx, navItems) {
266
269
  }
267
270
  }
268
271
  if (!s && !navContent) return "";
269
- let repoLink = getRepoLink(ctx);
270
272
  s = s.trim() ? `<section><ul>${s}
271
273
  </ul></section>` : "";
272
- s = `${s}
274
+ let repoLink = getRepoLink(ctx);
275
+ let refContent = "";
276
+ if (repoLink || backstory)
277
+ refContent = `
273
278
  <section class="ref">
274
279
  <ul>
275
- <li>${repoLink}</li>
280
+ ${repoLink ? `<li>${repoLink}</li>` : ""}
276
281
  ${backstory ? `<li><a href="${backstory}">Backstory</a></li>` : ""}
277
282
  </ul>
278
283
  </section>
279
- ${navContent}`;
284
+ `;
280
285
  return `<nav>
281
- ${s}
286
+ ${s}${refContent}
287
+ ${navContent}
282
288
  </nav>`;
283
289
  }
284
290
 
@@ -680,13 +686,22 @@ function getIcon(baseColor = "gray") {
680
686
  }
681
687
 
682
688
  // src/bin/setImages.ts
683
- async function setImages({ dir = "", colorScheme }) {
689
+ async function setImages({ dir = "", colorScheme, favicon }) {
690
+ if (favicon) return;
684
691
  await (0, import_promises5.writeFile)((0, import_node_path4.join)(dir, "./favicon.svg"), `${getIcon(colorScheme)}
685
692
  `);
686
693
  }
687
694
 
688
695
  // src/bin/createFiles.ts
689
696
  async function createFiles(ctx) {
697
+ let { dir } = ctx;
698
+ if (dir) {
699
+ try {
700
+ await (0, import_promises6.access)(dir);
701
+ } catch {
702
+ await (0, import_promises6.mkdir)(dir);
703
+ }
704
+ }
690
705
  await Promise.all([setCName(ctx), setContent(ctx), setImages(ctx)]);
691
706
  }
692
707
 
@@ -695,7 +710,7 @@ var exec2 = (0, import_node_util2.promisify)(import_node_child_process2.exec);
695
710
  var stdout = async (cmd) => (await exec2(cmd)).stdout.trim();
696
711
  async function isGitDir() {
697
712
  try {
698
- await (0, import_promises6.access)("./.git");
713
+ await (0, import_promises7.access)("./.git");
699
714
  return true;
700
715
  } catch {
701
716
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t8/docsgen",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "",
5
5
  "main": "dist/bin.js",
6
6
  "bin": {
@@ -1,8 +1,19 @@
1
+ import { access, mkdir } from "node:fs/promises";
1
2
  import type { Context } from "../types/Context";
2
3
  import { setCName } from "./setCName";
3
4
  import { setContent } from "./setContent";
4
5
  import { setImages } from "./setImages";
5
6
 
6
7
  export async function createFiles(ctx: Context) {
8
+ let { dir } = ctx;
9
+
10
+ if (dir) {
11
+ try {
12
+ await access(dir);
13
+ } catch {
14
+ await mkdir(dir);
15
+ }
16
+ }
17
+
7
18
  await Promise.all([setCName(ctx), setContent(ctx), setImages(ctx)]);
8
19
  }
package/src/bin/getNav.ts CHANGED
@@ -48,17 +48,20 @@ export async function getNav(ctx: Context, navItems: NavItem[]) {
48
48
 
49
49
  if (!s && !navContent) return "";
50
50
 
51
+ s = s.trim() ? `<section><ul>${s}\n</ul></section>` : "";
52
+
51
53
  let repoLink = getRepoLink(ctx);
54
+ let refContent = "";
52
55
 
53
- s = s.trim() ? `<section><ul>${s}\n</ul></section>` : "";
54
- s = `${s}
56
+ if (repoLink || backstory)
57
+ refContent = `
55
58
  <section class="ref">
56
59
  <ul>
57
- <li>${repoLink}</li>
60
+ ${repoLink ? `<li>${repoLink}</li>` : ""}
58
61
  ${backstory ? `<li><a href="${backstory}">Backstory</a></li>` : ""}
59
62
  </ul>
60
63
  </section>
61
- ${navContent}`;
64
+ `;
62
65
 
63
- return `<nav>\n${s}\n</nav>`;
66
+ return `<nav>\n${s}${refContent}\n${navContent}\n</nav>`;
64
67
  }
@@ -3,6 +3,8 @@ import { join } from "node:path";
3
3
  import type { Context } from "../types/Context";
4
4
  import { getIcon } from "../utils/getIcon";
5
5
 
6
- export async function setImages({ dir = "", colorScheme }: Context) {
6
+ export async function setImages({ dir = "", colorScheme, favicon }: Context) {
7
+ if (favicon) return;
8
+
7
9
  await writeFile(join(dir, "./favicon.svg"), `${getIcon(colorScheme)}\n`);
8
10
  }
@@ -37,9 +37,11 @@ export type EntryConfig = {
37
37
  backstory?: string;
38
38
  /** URL of an HTML file inserted into the navigation bar. */
39
39
  nav?: string;
40
- /** Scope URL */
40
+ /** Favicon URL. */
41
+ favicon?: string;
42
+ /** Scope URL. */
41
43
  scope?: string;
42
- /** Redirection URL */
44
+ /** Redirection URL. */
43
45
  redirect?: string;
44
46
  /** Whether to remove the GitHub Pages branch and quit. */
45
47
  remove?: boolean;