@t8/docsgen 0.2.41 → 0.2.43

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
@@ -1,27 +1,4 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
- // If the importer is in node compatibility mode or this is not an ESM
19
- // file that has been converted to a CommonJS file using a Babel-
20
- // compatible transform (i.e. "__esModule" has not been set), then set
21
- // "default" to the CommonJS "module.exports" for node compatibility.
22
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
- mod
24
- ));
25
2
 
26
3
  // node_modules/args-json/dist/index.js
27
4
  function toCamelCase(x) {
@@ -111,7 +88,7 @@ function parseArgs(input, map) {
111
88
  }
112
89
 
113
90
  // src/bin/fetchContent.ts
114
- var import_promises = require("node:fs/promises");
91
+ import { readFile } from "node:fs/promises";
115
92
  async function fetchContent(location) {
116
93
  if (!location) return "";
117
94
  if (/^https?:\/\//.test(location)) {
@@ -123,7 +100,7 @@ async function fetchContent(location) {
123
100
  }
124
101
  }
125
102
  let locationPath = location.replace(/^\//, "");
126
- return (await (0, import_promises.readFile)(locationPath)).toString();
103
+ return (await readFile(locationPath)).toString();
127
104
  }
128
105
 
129
106
  // src/bin/getLocation.ts
@@ -138,11 +115,11 @@ function getLocation(ctx, path, preferredLocation) {
138
115
  }
139
116
 
140
117
  // src/bin/stripHTML.ts
141
- var import_jsdom = require("jsdom");
118
+ import { JSDOM } from "jsdom";
142
119
  function stripHTML(content, replaceNbsp = false) {
143
120
  try {
144
121
  let t = content.replaceAll("<sup>", " (").replaceAll("</sup>", ")");
145
- let s = new import_jsdom.JSDOM(t).window.document.body.textContent;
122
+ let s = new JSDOM(t).window.document.body.textContent;
146
123
  if (replaceNbsp) s = s.replaceAll("\xA0", " ");
147
124
  s = s.replace(/ +/g, " ");
148
125
  return s;
@@ -243,40 +220,41 @@ async function getConfig() {
243
220
  }
244
221
 
245
222
  // src/bin/runEntry.ts
246
- var import_node_child_process2 = require("node:child_process");
247
- var import_promises7 = require("node:fs/promises");
248
- var import_node_util2 = require("node:util");
223
+ import { exec as defaultExec2 } from "node:child_process";
224
+ import { access as access3 } from "node:fs/promises";
225
+ import { promisify as promisify2 } from "node:util";
249
226
 
250
227
  // src/bin/cleanup.ts
251
- var import_promises2 = require("node:fs/promises");
252
- var import_node_path = require("node:path");
228
+ import { rm } from "node:fs/promises";
229
+ import { join } from "node:path";
253
230
  async function cleanup({ dir = "" }) {
254
231
  await Promise.all(
255
232
  ["x", "index.html", "start.html"].map((path) => {
256
- return (0, import_promises2.rm)((0, import_node_path.join)(dir, path), { force: true, recursive: true });
233
+ return rm(join(dir, path), { force: true, recursive: true });
257
234
  })
258
235
  );
259
236
  }
260
237
 
261
238
  // src/bin/createFiles.ts
262
- var import_promises6 = require("node:fs/promises");
239
+ import { access as access2, mkdir as mkdir2 } from "node:fs/promises";
263
240
 
264
241
  // src/bin/setCName.ts
265
- var import_promises3 = require("node:fs/promises");
266
- var import_node_path2 = require("node:path");
242
+ import { writeFile } from "node:fs/promises";
243
+ import { join as join2 } from "node:path";
267
244
  async function setCName({ dir = "", name, cname, jsorg }) {
268
245
  let domain = "";
269
246
  if (cname) domain = cname;
270
247
  else if (typeof jsorg === "string") domain = jsorg ? `${jsorg}.js.org` : "";
271
248
  else if (jsorg === true) domain = name ? `${name}.js.org` : "";
272
- if (domain !== "") await (0, import_promises3.writeFile)((0, import_node_path2.join)(dir, "CNAME"), domain);
249
+ if (domain !== "") await writeFile(join2(dir, "CNAME"), domain);
273
250
  }
274
251
 
275
252
  // src/bin/setContent.ts
276
- var import_node_child_process = require("node:child_process");
277
- var import_promises4 = require("node:fs/promises");
278
- var import_node_path3 = require("node:path");
279
- var import_node_util = require("node:util");
253
+ import { exec as defaultExec } from "node:child_process";
254
+ import { access, cp, mkdir, writeFile as writeFile2 } from "node:fs/promises";
255
+ import { dirname, join as join3 } from "node:path";
256
+ import { fileURLToPath } from "node:url";
257
+ import { promisify } from "node:util";
280
258
 
281
259
  // src/const/packageName.ts
282
260
  var packageName = "@t8/docsgen";
@@ -352,7 +330,7 @@ function getInjectedContent(ctx, page, target, mode = "append") {
352
330
  }
353
331
 
354
332
  // src/bin/getNav.ts
355
- var import_jsdom2 = require("jsdom");
333
+ import { JSDOM as JSDOM2 } from "jsdom";
356
334
 
357
335
  // src/bin/getRepoLink.ts
358
336
  function getRepoLink({ repo }, className) {
@@ -367,7 +345,7 @@ async function getNav(ctx, navItems) {
367
345
  let navContent = await fetchContent(nav);
368
346
  let s = "";
369
347
  if (navContent) {
370
- let navDom = new import_jsdom2.JSDOM(navContent).window.document.body;
348
+ let navDom = new JSDOM2(navContent).window.document.body;
371
349
  for (let link of navDom.querySelectorAll("a")) {
372
350
  if (link.dataset.name === name) {
373
351
  let parent = link.parentElement;
@@ -454,8 +432,8 @@ function getTitle(ctx, { cover, originalContent, withPackageURL } = {}) {
454
432
  }
455
433
 
456
434
  // src/bin/parsing/getParsedContent.ts
457
- var import_jsdom3 = require("jsdom");
458
- var import_markdown_it = __toESM(require("markdown-it"), 1);
435
+ import { JSDOM as JSDOM3 } from "jsdom";
436
+ import Markdown from "markdown-it";
459
437
 
460
438
  // src/bin/getSlug.ts
461
439
  function getSlug(title) {
@@ -579,7 +557,7 @@ function preprocessContent(s) {
579
557
  }
580
558
 
581
559
  // src/bin/parsing/getParsedContent.ts
582
- var md = new import_markdown_it.default({
560
+ var md = new Markdown({
583
561
  html: true
584
562
  });
585
563
  async function getParsedContent(ctx) {
@@ -588,7 +566,7 @@ async function getParsedContent(ctx) {
588
566
  getLocation(ctx, "README.md", ctx.source)
589
567
  );
590
568
  let content = md.render(preprocessContent(rawContent));
591
- let dom = new import_jsdom3.JSDOM(content);
569
+ let dom = new JSDOM3(content);
592
570
  let { nav, linkMap: navLinkMap } = buildNav(ctx, dom);
593
571
  let badges = "";
594
572
  let title = "";
@@ -688,7 +666,9 @@ function toFileContent(x) {
688
666
  }
689
667
 
690
668
  // src/bin/setContent.ts
691
- var exec = (0, import_node_util.promisify)(import_node_child_process.exec);
669
+ var exec = promisify(defaultExec);
670
+ var __filename = fileURLToPath(import.meta.url);
671
+ var __dirname = dirname(__filename);
692
672
  function getDefaultCodeStyleContent(cssRoot) {
693
673
  return `
694
674
  <link rel="stylesheet" href="https://unpkg.com/@highlightjs/cdn-assets@11.11.1/styles/stackoverflow-light.min.css" media="(prefers-color-scheme: light)">
@@ -728,7 +708,7 @@ async function setContent(ctx) {
728
708
  if (assetsDir) {
729
709
  cssRoot.index = assetsDir;
730
710
  cssRoot.content = `../${assetsDir}`;
731
- await (0, import_promises4.cp)((0, import_node_path3.join)(__dirname, "css"), (0, import_node_path3.join)(dir, cssRoot.index), {
711
+ await cp(join3(__dirname, "css"), join3(dir, cssRoot.index), {
732
712
  force: true,
733
713
  recursive: true
734
714
  });
@@ -749,8 +729,8 @@ async function setContent(ctx) {
749
729
  let iconTag = icon.url ? `<link rel="icon"${icon.type ? ` type="${icon.type}"` : ""} href="${icon.url}">` : "";
750
730
  if (redirect) {
751
731
  let escapedRedirect = escapeHTML(redirect);
752
- await (0, import_promises4.writeFile)(
753
- (0, import_node_path3.join)(dir, "index.html"),
732
+ await writeFile2(
733
+ join3(dir, "index.html"),
754
734
  toFileContent(`
755
735
  <!DOCTYPE html>
756
736
  <html lang="en" class="blank"${rootAttrs}>
@@ -777,18 +757,18 @@ ${getInjectedContent(ctx, "redirect", "body")}
777
757
  let dirs = [contentDir];
778
758
  await Promise.all(
779
759
  dirs.map(async (path) => {
780
- let dirPath = (0, import_node_path3.join)(dir, path);
760
+ let dirPath = join3(dir, path);
781
761
  try {
782
- await (0, import_promises4.access)(dirPath);
762
+ await access(dirPath);
783
763
  } catch {
784
- await (0, import_promises4.mkdir)(dirPath);
764
+ await mkdir(dirPath);
785
765
  }
786
766
  })
787
767
  );
788
768
  await Promise.all([
789
769
  ...sections.map(
790
- async (content, i) => (0, import_promises4.writeFile)(
791
- (0, import_node_path3.join)(dir, contentDir, `${nav[i]?.id ?? `_untitled_${i}`}.html`),
770
+ async (content, i) => writeFile2(
771
+ join3(dir, contentDir, `${nav[i]?.id ?? `_untitled_${i}`}.html`),
792
772
  toFileContent(`
793
773
  <!DOCTYPE html>
794
774
  <html lang="en"${rootAttrs}>
@@ -838,8 +818,8 @@ ${getInjectedContent(ctx, "section", "body")}
838
818
  `)
839
819
  )
840
820
  ),
841
- (0, import_promises4.writeFile)(
842
- (0, import_node_path3.join)(dir, "index.html"),
821
+ writeFile2(
822
+ join3(dir, "index.html"),
843
823
  toFileContent(`
844
824
  <!DOCTYPE html>
845
825
  <html lang="en"${rootAttrs}>
@@ -895,8 +875,8 @@ ${getInjectedContent(ctx, "index", "body")}
895
875
  </html>
896
876
  `)
897
877
  ),
898
- (0, import_promises4.writeFile)(
899
- (0, import_node_path3.join)(dir, "start.html"),
878
+ writeFile2(
879
+ join3(dir, "start.html"),
900
880
  toFileContent(`
901
881
  <!DOCTYPE html>
902
882
  <html lang="en" class="blank"${rootAttrs}>
@@ -925,8 +905,8 @@ ${getInjectedContent(ctx, "start", "body")}
925
905
  }
926
906
 
927
907
  // src/bin/setImages.ts
928
- var import_promises5 = require("node:fs/promises");
929
- var import_node_path4 = require("node:path");
908
+ import { writeFile as writeFile3 } from "node:fs/promises";
909
+ import { join as join4 } from "node:path";
930
910
 
931
911
  // src/utils/getIconContent.ts
932
912
  function getIconContent(baseColor = "gray") {
@@ -946,7 +926,7 @@ function getIconContent(baseColor = "gray") {
946
926
  // src/bin/setImages.ts
947
927
  async function setImages({ dir = "", baseColor, favicon }) {
948
928
  if (favicon) return;
949
- await (0, import_promises5.writeFile)((0, import_node_path4.join)(dir, "./favicon.svg"), `${getIconContent(baseColor)}
929
+ await writeFile3(join4(dir, "./favicon.svg"), `${getIconContent(baseColor)}
950
930
  `);
951
931
  }
952
932
 
@@ -955,20 +935,20 @@ async function createFiles(ctx) {
955
935
  let { dir } = ctx;
956
936
  if (dir) {
957
937
  try {
958
- await (0, import_promises6.access)(dir);
938
+ await access2(dir);
959
939
  } catch {
960
- await (0, import_promises6.mkdir)(dir);
940
+ await mkdir2(dir);
961
941
  }
962
942
  }
963
943
  await Promise.all([setCName(ctx), setContent(ctx), setImages(ctx)]);
964
944
  }
965
945
 
966
946
  // src/bin/runEntry.ts
967
- var exec2 = (0, import_node_util2.promisify)(import_node_child_process2.exec);
947
+ var exec2 = promisify2(defaultExec2);
968
948
  var stdout = async (cmd) => (await exec2(cmd)).stdout.trim();
969
949
  async function isGitDir() {
970
950
  try {
971
- await (0, import_promises7.access)("./.git");
951
+ await access3("./.git");
972
952
  return true;
973
953
  } catch {
974
954
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t8/docsgen",
3
- "version": "0.2.41",
3
+ "version": "0.2.43",
4
4
  "description": "",
5
5
  "main": "dist/bin.js",
6
6
  "type": "module",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "scripts": {
11
11
  "build": "npx npm-run-all clean build-bin build-css",
12
- "build-bin": "npx esbuild ./src/bin/run.ts --bundle --outfile=dist/bin.js --platform=node --external:jsdom --external:markdown-it",
12
+ "build-bin": "npx esbuild ./src/bin/run.ts --bundle --outfile=dist/bin.js --platform=node --external:jsdom --external:markdown-it --format=esm",
13
13
  "build-css": "node -e \"require('node:fs').cpSync('src/css', 'dist/css', { force: true, recursive: true });\"",
14
14
  "build-schema": "npx ts-json-schema-generator -p src/types/Config.ts -t Config -o schema.json --minify",
15
15
  "clean": "node -e \"require('node:fs').rmSync('dist', { force: true, recursive: true });\"",
@@ -1,6 +1,7 @@
1
1
  import { exec as defaultExec } from "node:child_process";
2
2
  import { access, cp, mkdir, writeFile } from "node:fs/promises";
3
- import { join } from "node:path";
3
+ import { dirname, join } from "node:path";
4
+ import { fileURLToPath } from "node:url";
4
5
  import { promisify } from "node:util";
5
6
  import { packageName } from "../const/packageName.ts";
6
7
  import type { Context } from "../types/Context.ts";
@@ -18,6 +19,9 @@ import { toFileContent } from "./toFileContent.ts";
18
19
 
19
20
  const exec = promisify(defaultExec);
20
21
 
22
+ const __filename = fileURLToPath(import.meta.url);
23
+ const __dirname = dirname(__filename);
24
+
21
25
  function getDefaultCodeStyleContent(cssRoot: string) {
22
26
  return `
23
27
  <link rel="stylesheet" href="https://unpkg.com/@highlightjs/cdn-assets@11.11.1/styles/stackoverflow-light.min.css" media="(prefers-color-scheme: light)">