@moku-labs/web 0.6.0 → 1.0.1
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 +227 -125
- package/dist/browser.d.mts +524 -111
- package/dist/browser.mjs +1707 -868
- package/dist/{convention-X3zLTlJ8.mjs → convention-CepUwWmT.mjs} +18 -1
- package/dist/{convention-Dr8jxG70.cjs → convention-krwh7Y6Q.cjs} +23 -0
- package/dist/index.cjs +3239 -1935
- package/dist/index.d.cts +365 -176
- package/dist/index.d.mts +366 -177
- package/dist/index.mjs +3236 -1934
- package/dist/{writer-DAF0pM25.cjs → writer-DV5hWB2i.cjs} +25 -27
- package/dist/{writer-BcWqa_7I.mjs → writer-Dc_lx22j.mjs} +25 -27
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_convention = require("./convention-
|
|
1
|
+
const require_convention = require("./convention-krwh7Y6Q.cjs");
|
|
2
2
|
let node_fs_promises = require("node:fs/promises");
|
|
3
3
|
let node_path = require("node:path");
|
|
4
4
|
node_path = require_convention.__toESM(node_path, 1);
|
|
@@ -18,28 +18,13 @@ p_limit = require_convention.__toESM(p_limit, 1);
|
|
|
18
18
|
* file per page, at the path {@link dataSuffix} mirrors from the page URL. No
|
|
19
19
|
* content/article knowledge, no expansion (build already expanded the routes).
|
|
20
20
|
*/
|
|
21
|
-
/** Default build output root, matching
|
|
21
|
+
/** Default build output root, matching build's default `outDir` ("./dist", build/api.ts). */
|
|
22
22
|
const DEFAULT_OUT_DIR = "./dist";
|
|
23
|
-
/** Concurrency bound for per-page writes
|
|
23
|
+
/** Concurrency bound for per-page JSON writes. */
|
|
24
24
|
const WRITE_CONCURRENCY = 8;
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* @param outputDir - The configured data output subdir (e.g. `"_data"`).
|
|
30
|
-
* @param pagePath - The page URL path (e.g. `/en/hello/`).
|
|
31
|
-
* @returns The `outDir`-relative file path (e.g. `_data/en/hello/index.json`).
|
|
32
|
-
* @example
|
|
33
|
-
* ```ts
|
|
34
|
-
* relativeFile("_data", "/en/hello/"); // "_data/en/hello/index.json"
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
function relativeFile(outputDir, pagePath) {
|
|
38
|
-
return `${outputDir.endsWith("/") ? outputDir.slice(0, -1) : outputDir}/${require_convention.dataSuffix(pagePath)}`;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Persist one entry's data as JSON under `<outDir>/<relativeFile>` and return the
|
|
42
|
-
* written `{ relative, bytes }`.
|
|
26
|
+
* Persist one entry's data as JSON under `<outDir>/<relativeDataFile>` and return
|
|
27
|
+
* the written `{ relative, bytes }`.
|
|
43
28
|
*
|
|
44
29
|
* @param entry - The page entry to persist.
|
|
45
30
|
* @param outDir - The build output root.
|
|
@@ -51,7 +36,7 @@ function relativeFile(outputDir, pagePath) {
|
|
|
51
36
|
* ```
|
|
52
37
|
*/
|
|
53
38
|
async function writeEntry(entry, outDir, outputDir) {
|
|
54
|
-
const relative =
|
|
39
|
+
const relative = require_convention.relativeDataFile(outputDir, entry.path);
|
|
55
40
|
const filePath = node_path.default.join(outDir, relative);
|
|
56
41
|
await (0, node_fs_promises.mkdir)(node_path.default.dirname(filePath), { recursive: true });
|
|
57
42
|
const body = JSON.stringify(entry.data);
|
|
@@ -62,6 +47,24 @@ async function writeEntry(entry, outDir, outputDir) {
|
|
|
62
47
|
};
|
|
63
48
|
}
|
|
64
49
|
/**
|
|
50
|
+
* Roll up the per-file write records into the public {@link DataWriteSummary}:
|
|
51
|
+
* file count, total byte length, and the `outDir`-relative paths in write order.
|
|
52
|
+
*
|
|
53
|
+
* @param written - The per-file `{ relative, bytes }` records from {@link writeEntry}.
|
|
54
|
+
* @returns The aggregated write summary.
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* compileSummary([{ relative: "_data/en/hello/index.json", bytes: 12 }]);
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
function compileSummary(written) {
|
|
61
|
+
return {
|
|
62
|
+
fileCount: written.length,
|
|
63
|
+
bytes: written.reduce((total, file) => total + file.bytes, 0),
|
|
64
|
+
files: written.map((file) => file.relative)
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
65
68
|
* The Node write side of the provider. Persists one JSON file per entry (bounded
|
|
66
69
|
* by `p-limit`) — domain-agnostic, no route expansion (`build` already did that).
|
|
67
70
|
* Records the summary in `ctx.state.lastWrite`.
|
|
@@ -79,12 +82,7 @@ async function writeEntry(entry, outDir, outputDir) {
|
|
|
79
82
|
async function writeData(ctx, entries, options) {
|
|
80
83
|
const outDir = options?.outDir ?? DEFAULT_OUT_DIR;
|
|
81
84
|
const limit = (0, p_limit.default)(WRITE_CONCURRENCY);
|
|
82
|
-
const
|
|
83
|
-
const summary = {
|
|
84
|
-
fileCount: written.length,
|
|
85
|
-
bytes: written.reduce((total, file) => total + file.bytes, 0),
|
|
86
|
-
files: written.map((file) => file.relative)
|
|
87
|
-
};
|
|
85
|
+
const summary = compileSummary(await Promise.all(entries.map((entry) => limit(() => writeEntry(entry, outDir, ctx.config.outputDir)))));
|
|
88
86
|
ctx.state.lastWrite = summary;
|
|
89
87
|
return summary;
|
|
90
88
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as relativeDataFile } from "./convention-CepUwWmT.mjs";
|
|
2
2
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import pLimit from "p-limit";
|
|
@@ -16,28 +16,13 @@ import pLimit from "p-limit";
|
|
|
16
16
|
* file per page, at the path {@link dataSuffix} mirrors from the page URL. No
|
|
17
17
|
* content/article knowledge, no expansion (build already expanded the routes).
|
|
18
18
|
*/
|
|
19
|
-
/** Default build output root, matching
|
|
19
|
+
/** Default build output root, matching build's default `outDir` ("./dist", build/api.ts). */
|
|
20
20
|
const DEFAULT_OUT_DIR = "./dist";
|
|
21
|
-
/** Concurrency bound for per-page writes
|
|
21
|
+
/** Concurrency bound for per-page JSON writes. */
|
|
22
22
|
const WRITE_CONCURRENCY = 8;
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* @param outputDir - The configured data output subdir (e.g. `"_data"`).
|
|
28
|
-
* @param pagePath - The page URL path (e.g. `/en/hello/`).
|
|
29
|
-
* @returns The `outDir`-relative file path (e.g. `_data/en/hello/index.json`).
|
|
30
|
-
* @example
|
|
31
|
-
* ```ts
|
|
32
|
-
* relativeFile("_data", "/en/hello/"); // "_data/en/hello/index.json"
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
function relativeFile(outputDir, pagePath) {
|
|
36
|
-
return `${outputDir.endsWith("/") ? outputDir.slice(0, -1) : outputDir}/${dataSuffix(pagePath)}`;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Persist one entry's data as JSON under `<outDir>/<relativeFile>` and return the
|
|
40
|
-
* written `{ relative, bytes }`.
|
|
24
|
+
* Persist one entry's data as JSON under `<outDir>/<relativeDataFile>` and return
|
|
25
|
+
* the written `{ relative, bytes }`.
|
|
41
26
|
*
|
|
42
27
|
* @param entry - The page entry to persist.
|
|
43
28
|
* @param outDir - The build output root.
|
|
@@ -49,7 +34,7 @@ function relativeFile(outputDir, pagePath) {
|
|
|
49
34
|
* ```
|
|
50
35
|
*/
|
|
51
36
|
async function writeEntry(entry, outDir, outputDir) {
|
|
52
|
-
const relative =
|
|
37
|
+
const relative = relativeDataFile(outputDir, entry.path);
|
|
53
38
|
const filePath = path.join(outDir, relative);
|
|
54
39
|
await mkdir(path.dirname(filePath), { recursive: true });
|
|
55
40
|
const body = JSON.stringify(entry.data);
|
|
@@ -60,6 +45,24 @@ async function writeEntry(entry, outDir, outputDir) {
|
|
|
60
45
|
};
|
|
61
46
|
}
|
|
62
47
|
/**
|
|
48
|
+
* Roll up the per-file write records into the public {@link DataWriteSummary}:
|
|
49
|
+
* file count, total byte length, and the `outDir`-relative paths in write order.
|
|
50
|
+
*
|
|
51
|
+
* @param written - The per-file `{ relative, bytes }` records from {@link writeEntry}.
|
|
52
|
+
* @returns The aggregated write summary.
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* compileSummary([{ relative: "_data/en/hello/index.json", bytes: 12 }]);
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
function compileSummary(written) {
|
|
59
|
+
return {
|
|
60
|
+
fileCount: written.length,
|
|
61
|
+
bytes: written.reduce((total, file) => total + file.bytes, 0),
|
|
62
|
+
files: written.map((file) => file.relative)
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
63
66
|
* The Node write side of the provider. Persists one JSON file per entry (bounded
|
|
64
67
|
* by `p-limit`) — domain-agnostic, no route expansion (`build` already did that).
|
|
65
68
|
* Records the summary in `ctx.state.lastWrite`.
|
|
@@ -77,12 +80,7 @@ async function writeEntry(entry, outDir, outputDir) {
|
|
|
77
80
|
async function writeData(ctx, entries, options) {
|
|
78
81
|
const outDir = options?.outDir ?? DEFAULT_OUT_DIR;
|
|
79
82
|
const limit = pLimit(WRITE_CONCURRENCY);
|
|
80
|
-
const
|
|
81
|
-
const summary = {
|
|
82
|
-
fileCount: written.length,
|
|
83
|
-
bytes: written.reduce((total, file) => total + file.bytes, 0),
|
|
84
|
-
files: written.map((file) => file.relative)
|
|
85
|
-
};
|
|
83
|
+
const summary = compileSummary(await Promise.all(entries.map((entry) => limit(() => writeEntry(entry, outDir, ctx.config.outputDir)))));
|
|
86
84
|
ctx.state.lastWrite = summary;
|
|
87
85
|
return summary;
|
|
88
86
|
}
|
package/package.json
CHANGED