@t8/docsgen 0.1.57 → 0.1.59

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/README.md CHANGED
@@ -0,0 +1,42 @@
1
+ ```sh
2
+ # with specified entries (e.g. in docsgen.config.json)
3
+ npx @t8/docsgen [...<entry id or dir>]
4
+
5
+ # without entries
6
+ npx @t8/docsgen <dir path> <repo URL>
7
+ ```
8
+
9
+ <details>
10
+ <summary>Example of <i>docsgen.config.json</i></summary>
11
+
12
+ ```
13
+ {
14
+ "$schema": "https://unpkg.com/@t8/docsgen/schema.json",
15
+ "baseColor": "purple",
16
+ "favicon": "/assets/favicon.png",
17
+ "append": {
18
+ "body": "<script src=\"/assets/stats.js\"></script>"
19
+ },
20
+ "linkMap": {
21
+ "https://github.com/org/package1": "/package1"
22
+ "https://github.com/org/package2": "/package2"
23
+ },
24
+ "entries": [
25
+ {
26
+ "dir": "package1",
27
+ "htmlTitle": "<a href=\"/\">Org</a> / Package 1",
28
+ "repo": "https://github.com/org/package1",
29
+ "nav": "/assets/nav_links.html"
30
+ },
31
+ {
32
+ "dir": "package2",
33
+ "htmlTitle": "<a href=\"/\">Org</a> / Package 2",
34
+ "repo": "https://github.com/org/package2",
35
+ "nav": "/assets/nav_links.html",
36
+ "singlePage": true
37
+ }
38
+ ]
39
+ }
40
+ ```
41
+
42
+ </details>
package/dist/bin.js CHANGED
@@ -212,20 +212,26 @@ async function getConfig() {
212
212
  delete localConfig.$schema;
213
213
  } catch {
214
214
  }
215
- let targetId;
216
215
  let args = process.argv.slice(2);
217
- if (args.length !== 0 && !args[0].startsWith("--")) targetId = args.shift();
216
+ let targetArgs = [];
217
+ while (args[0] && !args[0].startsWith("--")) targetArgs.push(args.shift());
218
218
  config = {
219
- targetId,
220
219
  mainBranch: "main",
221
220
  root: "/",
222
221
  contentDir: "x",
223
222
  ...localConfig,
224
223
  ...parseArgs(args)
225
224
  };
226
- if (config.entries)
225
+ if (config.entries) {
226
+ config.targetIds = targetArgs;
227
227
  config.entries = await Promise.all(config.entries.map(reviseConfig));
228
- else config = await reviseConfig(config);
228
+ } else {
229
+ if (!config.dir)
230
+ config.dir = targetArgs.find((arg) => !/^https?:\/\//.test(arg));
231
+ if (!config.repo)
232
+ config.repo = targetArgs.find((arg) => /^https?:\/\//.test(arg));
233
+ config = await reviseConfig(config);
234
+ }
229
235
  return config;
230
236
  }
231
237
 
@@ -895,25 +901,14 @@ async function runEntry(ctx) {
895
901
 
896
902
  // src/bin/run.ts
897
903
  async function run() {
898
- let { targetId, entries, ...rootCtx } = await getConfig();
899
- if (!entries) {
900
- if (!targetId || targetId === rootCtx.id) return await runEntry(rootCtx);
901
- console.warn(`Specified config entry not found: '${targetId}'`);
902
- return;
903
- }
904
- if (targetId) {
905
- let entryCtx = entries.find(
906
- ({ id, dir }) => id === targetId || dir === targetId
907
- );
908
- if (entryCtx) runEntry({ ...rootCtx, ...entryCtx });
909
- else console.warn(`Specified config entry not found: '${targetId}'`);
910
- } else {
911
- await Promise.all(
912
- entries.map((entryCtx) => {
913
- return runEntry({ ...rootCtx, ...entryCtx });
914
- })
915
- );
916
- }
904
+ let { targetIds, entries, ...rootCtx } = await getConfig();
905
+ if (!entries) return await runEntry(rootCtx);
906
+ let targetEntries = targetIds && targetIds.length !== 0 ? entries.filter(({ id, dir }) => {
907
+ return id && targetIds.includes(id) || dir && targetIds.includes(dir);
908
+ }) : entries;
909
+ await Promise.all(
910
+ targetEntries.map((entryCtx) => runEntry({ ...rootCtx, ...entryCtx }))
911
+ );
917
912
  }
918
913
  (async () => {
919
914
  await run();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t8/docsgen",
3
- "version": "0.1.57",
3
+ "version": "0.1.59",
4
4
  "description": "",
5
5
  "main": "dist/bin.js",
6
6
  "bin": {
package/schema.json CHANGED
@@ -1 +1 @@
1
- {"$ref":"#/definitions/Config","$schema":"http://json-schema.org/draft-07/schema#","definitions":{"Config":{"additionalProperties":false,"properties":{"$schema":{"type":"string"},"append":{"$ref":"#/definitions/ContentInjectionMap%3C(%22head%22%7C%22body%22%7C%22%3Ahas-code%22)%3E"},"backstory":{"description":"Backstory link URL to be added to the front page.","type":"string"},"baseColor":{"type":"string"},"cname":{"description":"Content of the './CNAME' file.","type":"string"},"contentDir":{"description":"Generated section content directory.","type":"string"},"description":{"type":"string"},"dir":{"type":"string"},"entries":{"items":{"$ref":"#/definitions/EntryConfig"},"type":"array"},"favicon":{"description":"Favicon URL.","type":"string"},"faviconType":{"type":"string"},"htmlTitle":{"type":"string"},"id":{"type":"string"},"jsorg":{"description":"As a boolean, it means whether to add the '<package_name>.js.org' domain to the './CNAME' file.\n\nAs a string, it sets the '<jsorg_value>.js.org' domain to the './CNAME' file.","type":["boolean","string"]},"linkMap":{"additionalProperties":{"anyOf":[{"type":"string"},{"not":{}}]},"description":"Link substitution map.","type":"object"},"mainBranch":{"type":"string"},"name":{"type":"string"},"nav":{"description":"URL of an HTML file inserted into the navigation bar.","type":"string"},"npm":{"type":"string"},"redirect":{"description":"Redirection URL.","type":"string"},"remove":{"description":"Whether to remove the GitHub Pages branch and quit.","type":"boolean"},"repo":{"type":"string"},"root":{"description":"Main page root path.","type":"string"},"scope":{"description":"Scope URL.","type":"string"},"singlePage":{"description":"Whether to show all sections on a single page.","type":"boolean"},"source":{"type":"string"},"targetBranch":{"description":"Target branch.","examples":["gh-pages"],"type":"string"},"targetId":{"type":"string"},"theme":{"type":"string"},"title":{"type":"string"},"version":{"type":"string"},"ymid":{"type":["number","string"]}},"type":"object"},"ContentInjectionMap<(\"head\"|\"body\"|\":has-code\")>":{"additionalProperties":false,"properties":{":has-code":{"anyOf":[{"type":"string"},{"additionalProperties":false,"properties":{"content":{"type":"string"},"pages":{"items":{"$ref":"#/definitions/Page"},"type":"array"}},"type":"object"},{"items":{"anyOf":[{"type":"string"},{"not":{}},{"additionalProperties":false,"properties":{"content":{"type":"string"},"pages":{"items":{"$ref":"#/definitions/Page"},"type":"array"}},"type":"object"}]},"type":"array"}]},"body":{"anyOf":[{"type":"string"},{"additionalProperties":false,"properties":{"content":{"type":"string"},"pages":{"items":{"$ref":"#/definitions/Page"},"type":"array"}},"type":"object"},{"items":{"anyOf":[{"type":"string"},{"not":{}},{"additionalProperties":false,"properties":{"content":{"type":"string"},"pages":{"items":{"$ref":"#/definitions/Page"},"type":"array"}},"type":"object"}]},"type":"array"}]},"head":{"anyOf":[{"type":"string"},{"additionalProperties":false,"properties":{"content":{"type":"string"},"pages":{"items":{"$ref":"#/definitions/Page"},"type":"array"}},"type":"object"},{"items":{"anyOf":[{"type":"string"},{"not":{}},{"additionalProperties":false,"properties":{"content":{"type":"string"},"pages":{"items":{"$ref":"#/definitions/Page"},"type":"array"}},"type":"object"}]},"type":"array"}]}},"type":"object"},"EntryConfig":{"additionalProperties":false,"properties":{"append":{"$ref":"#/definitions/ContentInjectionMap%3C(%22head%22%7C%22body%22%7C%22%3Ahas-code%22)%3E"},"backstory":{"description":"Backstory link URL to be added to the front page.","type":"string"},"baseColor":{"type":"string"},"cname":{"description":"Content of the './CNAME' file.","type":"string"},"contentDir":{"description":"Generated section content directory.","type":"string"},"description":{"type":"string"},"dir":{"type":"string"},"favicon":{"description":"Favicon URL.","type":"string"},"faviconType":{"type":"string"},"htmlTitle":{"type":"string"},"id":{"type":"string"},"jsorg":{"description":"As a boolean, it means whether to add the '<package_name>.js.org' domain to the './CNAME' file.\n\nAs a string, it sets the '<jsorg_value>.js.org' domain to the './CNAME' file.","type":["boolean","string"]},"linkMap":{"additionalProperties":{"anyOf":[{"type":"string"},{"not":{}}]},"description":"Link substitution map.","type":"object"},"mainBranch":{"type":"string"},"name":{"type":"string"},"nav":{"description":"URL of an HTML file inserted into the navigation bar.","type":"string"},"npm":{"type":"string"},"redirect":{"description":"Redirection URL.","type":"string"},"remove":{"description":"Whether to remove the GitHub Pages branch and quit.","type":"boolean"},"repo":{"type":"string"},"root":{"description":"Main page root path.","type":"string"},"scope":{"description":"Scope URL.","type":"string"},"singlePage":{"description":"Whether to show all sections on a single page.","type":"boolean"},"source":{"type":"string"},"targetBranch":{"description":"Target branch.","examples":["gh-pages"],"type":"string"},"theme":{"type":"string"},"title":{"type":"string"},"version":{"type":"string"},"ymid":{"type":["number","string"]}},"type":"object"},"Page":{"enum":["index","start","section","redirect"],"type":"string"}}}
1
+ {"$ref":"#/definitions/Config","$schema":"http://json-schema.org/draft-07/schema#","definitions":{"Config":{"additionalProperties":false,"properties":{"$schema":{"type":"string"},"append":{"$ref":"#/definitions/ContentInjectionMap%3C(%22head%22%7C%22body%22%7C%22%3Ahas-code%22)%3E"},"backstory":{"description":"Backstory link URL to be added to the front page.","type":"string"},"baseColor":{"type":"string"},"cname":{"description":"Content of the './CNAME' file.","type":"string"},"contentDir":{"description":"Generated section content directory.","type":"string"},"description":{"type":"string"},"dir":{"type":"string"},"entries":{"items":{"$ref":"#/definitions/EntryConfig"},"type":"array"},"favicon":{"description":"Favicon URL.","type":"string"},"faviconType":{"type":"string"},"htmlTitle":{"type":"string"},"id":{"type":"string"},"jsorg":{"description":"As a boolean, it means whether to add the '<package_name>.js.org' domain to the './CNAME' file.\n\nAs a string, it sets the '<jsorg_value>.js.org' domain to the './CNAME' file.","type":["boolean","string"]},"linkMap":{"additionalProperties":{"anyOf":[{"type":"string"},{"not":{}}]},"description":"Link substitution map.","type":"object"},"mainBranch":{"type":"string"},"name":{"type":"string"},"nav":{"description":"URL of an HTML file inserted into the navigation bar.","type":"string"},"npm":{"type":"string"},"redirect":{"description":"Redirection URL.","type":"string"},"remove":{"description":"Whether to remove the GitHub Pages branch and quit.","type":"boolean"},"repo":{"type":"string"},"root":{"description":"Main page root path.","type":"string"},"scope":{"description":"Scope URL.","type":"string"},"singlePage":{"description":"Whether to show all sections on a single page.","type":"boolean"},"source":{"type":"string"},"targetBranch":{"description":"Target branch.","examples":["gh-pages"],"type":"string"},"targetIds":{"items":{"type":"string"},"type":"array"},"theme":{"type":"string"},"title":{"type":"string"},"version":{"type":"string"},"ymid":{"type":["number","string"]}},"type":"object"},"ContentInjectionMap<(\"head\"|\"body\"|\":has-code\")>":{"additionalProperties":false,"properties":{":has-code":{"anyOf":[{"type":"string"},{"additionalProperties":false,"properties":{"content":{"type":"string"},"pages":{"items":{"$ref":"#/definitions/Page"},"type":"array"}},"type":"object"},{"items":{"anyOf":[{"type":"string"},{"not":{}},{"additionalProperties":false,"properties":{"content":{"type":"string"},"pages":{"items":{"$ref":"#/definitions/Page"},"type":"array"}},"type":"object"}]},"type":"array"}]},"body":{"anyOf":[{"type":"string"},{"additionalProperties":false,"properties":{"content":{"type":"string"},"pages":{"items":{"$ref":"#/definitions/Page"},"type":"array"}},"type":"object"},{"items":{"anyOf":[{"type":"string"},{"not":{}},{"additionalProperties":false,"properties":{"content":{"type":"string"},"pages":{"items":{"$ref":"#/definitions/Page"},"type":"array"}},"type":"object"}]},"type":"array"}]},"head":{"anyOf":[{"type":"string"},{"additionalProperties":false,"properties":{"content":{"type":"string"},"pages":{"items":{"$ref":"#/definitions/Page"},"type":"array"}},"type":"object"},{"items":{"anyOf":[{"type":"string"},{"not":{}},{"additionalProperties":false,"properties":{"content":{"type":"string"},"pages":{"items":{"$ref":"#/definitions/Page"},"type":"array"}},"type":"object"}]},"type":"array"}]}},"type":"object"},"EntryConfig":{"additionalProperties":false,"properties":{"append":{"$ref":"#/definitions/ContentInjectionMap%3C(%22head%22%7C%22body%22%7C%22%3Ahas-code%22)%3E"},"backstory":{"description":"Backstory link URL to be added to the front page.","type":"string"},"baseColor":{"type":"string"},"cname":{"description":"Content of the './CNAME' file.","type":"string"},"contentDir":{"description":"Generated section content directory.","type":"string"},"description":{"type":"string"},"dir":{"type":"string"},"favicon":{"description":"Favicon URL.","type":"string"},"faviconType":{"type":"string"},"htmlTitle":{"type":"string"},"id":{"type":"string"},"jsorg":{"description":"As a boolean, it means whether to add the '<package_name>.js.org' domain to the './CNAME' file.\n\nAs a string, it sets the '<jsorg_value>.js.org' domain to the './CNAME' file.","type":["boolean","string"]},"linkMap":{"additionalProperties":{"anyOf":[{"type":"string"},{"not":{}}]},"description":"Link substitution map.","type":"object"},"mainBranch":{"type":"string"},"name":{"type":"string"},"nav":{"description":"URL of an HTML file inserted into the navigation bar.","type":"string"},"npm":{"type":"string"},"redirect":{"description":"Redirection URL.","type":"string"},"remove":{"description":"Whether to remove the GitHub Pages branch and quit.","type":"boolean"},"repo":{"type":"string"},"root":{"description":"Main page root path.","type":"string"},"scope":{"description":"Scope URL.","type":"string"},"singlePage":{"description":"Whether to show all sections on a single page.","type":"boolean"},"source":{"type":"string"},"targetBranch":{"description":"Target branch.","examples":["gh-pages"],"type":"string"},"theme":{"type":"string"},"title":{"type":"string"},"version":{"type":"string"},"ymid":{"type":["number","string"]}},"type":"object"},"Page":{"enum":["index","start","section","redirect"],"type":"string"}}}
@@ -56,13 +56,12 @@ export async function getConfig(): Promise<Config> {
56
56
  delete localConfig.$schema;
57
57
  } catch {}
58
58
 
59
- let targetId: string | undefined;
60
59
  let args = process.argv.slice(2);
60
+ let targetArgs: string[] = [];
61
61
 
62
- if (args.length !== 0 && !args[0].startsWith("--")) targetId = args.shift();
62
+ while (args[0] && !args[0].startsWith("--")) targetArgs.push(args.shift()!);
63
63
 
64
64
  config = {
65
- targetId,
66
65
  mainBranch: "main",
67
66
  root: "/",
68
67
  contentDir: "x",
@@ -70,9 +69,18 @@ export async function getConfig(): Promise<Config> {
70
69
  ...parseArgs<Config>(args),
71
70
  };
72
71
 
73
- if (config.entries)
72
+ if (config.entries) {
73
+ config.targetIds = targetArgs;
74
74
  config.entries = await Promise.all(config.entries.map(reviseConfig));
75
- else config = await reviseConfig(config);
75
+ } else {
76
+ if (!config.dir)
77
+ config.dir = targetArgs.find((arg) => !/^https?:\/\//.test(arg));
78
+
79
+ if (!config.repo)
80
+ config.repo = targetArgs.find((arg) => /^https?:\/\//.test(arg));
81
+
82
+ config = await reviseConfig(config);
83
+ }
76
84
 
77
85
  return config;
78
86
  }
package/src/bin/run.ts CHANGED
@@ -3,29 +3,22 @@ import { getConfig } from "./getConfig";
3
3
  import { runEntry } from "./runEntry";
4
4
 
5
5
  async function run() {
6
- let { targetId, entries, ...rootCtx } = await getConfig();
6
+ let { targetIds, entries, ...rootCtx } = await getConfig();
7
7
 
8
- if (!entries) {
9
- if (!targetId || targetId === rootCtx.id) return await runEntry(rootCtx);
8
+ if (!entries) return await runEntry(rootCtx);
10
9
 
11
- console.warn(`Specified config entry not found: '${targetId}'`);
12
- return;
13
- }
10
+ let targetEntries =
11
+ targetIds && targetIds.length !== 0
12
+ ? entries.filter(({ id, dir }) => {
13
+ return (
14
+ (id && targetIds.includes(id)) || (dir && targetIds.includes(dir))
15
+ );
16
+ })
17
+ : entries;
14
18
 
15
- if (targetId) {
16
- let entryCtx = entries.find(
17
- ({ id, dir }) => id === targetId || dir === targetId,
18
- );
19
-
20
- if (entryCtx) runEntry({ ...rootCtx, ...entryCtx });
21
- else console.warn(`Specified config entry not found: '${targetId}'`);
22
- } else {
23
- await Promise.all(
24
- entries.map((entryCtx) => {
25
- return runEntry({ ...rootCtx, ...entryCtx });
26
- }),
27
- );
28
- }
19
+ await Promise.all(
20
+ targetEntries.map((entryCtx) => runEntry({ ...rootCtx, ...entryCtx })),
21
+ );
29
22
  }
30
23
 
31
24
  (async () => {
@@ -2,6 +2,6 @@ import type { EntryConfig } from "./EntryConfig";
2
2
 
3
3
  export type Config = EntryConfig & {
4
4
  $schema?: string;
5
- targetId?: string;
5
+ targetIds?: string[];
6
6
  entries?: EntryConfig[];
7
7
  };