@riboseinc/anafero-cli 0.0.67 → 0.0.68
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/bootstrap.css.map +2 -2
- package/bootstrap.js +87 -1
- package/bootstrap.js.map +3 -3
- package/build-site.mjs +159 -26
- package/generate-to-filesystem.tsx +73 -19
- package/package.json +1 -1
package/build-site.mjs
CHANGED
|
@@ -294425,7 +294425,88 @@ function makeDummyInMemoryCache() {
|
|
|
294425
294425
|
throw new Error("Requested key does not exist");
|
|
294426
294426
|
}
|
|
294427
294427
|
},
|
|
294428
|
-
dump: () =>
|
|
294428
|
+
dump: async (stream4, signal) => {
|
|
294429
|
+
async function* buildKeypaths(obj, currentPath, seen, paths2, signal2) {
|
|
294430
|
+
if (signal2.aborted) {
|
|
294431
|
+
throw new Error("Aborted");
|
|
294432
|
+
}
|
|
294433
|
+
for (const key of Object.keys(Object(obj))) {
|
|
294434
|
+
const val = obj[key];
|
|
294435
|
+
if (typeof val === "string" || Object.keys(Object(val)).length === 0) {
|
|
294436
|
+
yield [...currentPath, key];
|
|
294437
|
+
} else {
|
|
294438
|
+
const complexVal = val;
|
|
294439
|
+
if (!seen.has(complexVal)) {
|
|
294440
|
+
seen.add(complexVal);
|
|
294441
|
+
yield* buildKeypaths(
|
|
294442
|
+
complexVal,
|
|
294443
|
+
[...currentPath, key],
|
|
294444
|
+
seen,
|
|
294445
|
+
paths2,
|
|
294446
|
+
signal2
|
|
294447
|
+
);
|
|
294448
|
+
}
|
|
294449
|
+
}
|
|
294450
|
+
}
|
|
294451
|
+
}
|
|
294452
|
+
async function write4(data, end6) {
|
|
294453
|
+
return new Promise((resolve4) => {
|
|
294454
|
+
if (end6) {
|
|
294455
|
+
stream4.end(data, function() {
|
|
294456
|
+
resolve4();
|
|
294457
|
+
});
|
|
294458
|
+
} else {
|
|
294459
|
+
stream4.write(data, function() {
|
|
294460
|
+
resolve4();
|
|
294461
|
+
});
|
|
294462
|
+
}
|
|
294463
|
+
});
|
|
294464
|
+
}
|
|
294465
|
+
function serializeKeypath(idx2, keyPaths) {
|
|
294466
|
+
const keyPath = keyPaths[idx2];
|
|
294467
|
+
if (keyPath) {
|
|
294468
|
+
const keyString = keyPath.join(".");
|
|
294469
|
+
keyPath.reverse();
|
|
294470
|
+
let valueCursor = cache3;
|
|
294471
|
+
while (true) {
|
|
294472
|
+
let part = keyPath.pop();
|
|
294473
|
+
if (part) {
|
|
294474
|
+
valueCursor = valueCursor[part];
|
|
294475
|
+
} else {
|
|
294476
|
+
break;
|
|
294477
|
+
}
|
|
294478
|
+
}
|
|
294479
|
+
return `
|
|
294480
|
+
${JSON.stringify(keyString)}: ${valueCursor}`;
|
|
294481
|
+
} else {
|
|
294482
|
+
return null;
|
|
294483
|
+
}
|
|
294484
|
+
}
|
|
294485
|
+
const pathGen = buildKeypaths(cache3, [], /* @__PURE__ */ new Set(), [], signal);
|
|
294486
|
+
const paths = [];
|
|
294487
|
+
for await (const p3 of pathGen) {
|
|
294488
|
+
paths.push(p3);
|
|
294489
|
+
}
|
|
294490
|
+
await write4(`
|
|
294491
|
+
-- starting dumping ${paths.length} paths --`);
|
|
294492
|
+
let idx = 0;
|
|
294493
|
+
const chunkSize = 1e3;
|
|
294494
|
+
let chunk4 = "";
|
|
294495
|
+
while (true) {
|
|
294496
|
+
if (idx > 0 && idx % chunkSize === 0) {
|
|
294497
|
+
await write4(chunk4);
|
|
294498
|
+
chunk4 = "";
|
|
294499
|
+
}
|
|
294500
|
+
const nextItem = serializeKeypath(idx, paths);
|
|
294501
|
+
if (nextItem) {
|
|
294502
|
+
chunk4 = chunk4 + nextItem;
|
|
294503
|
+
} else {
|
|
294504
|
+
break;
|
|
294505
|
+
}
|
|
294506
|
+
idx += 1;
|
|
294507
|
+
}
|
|
294508
|
+
return;
|
|
294509
|
+
}
|
|
294429
294510
|
};
|
|
294430
294511
|
}
|
|
294431
294512
|
|
|
@@ -313425,6 +313506,11 @@ var BuildConfigSchema = Struct({
|
|
|
313425
313506
|
version: Literal4("0.1"),
|
|
313426
313507
|
/** The entry point, path to XML of a Metanorma document or collection. */
|
|
313427
313508
|
entryPoint: String$2.pipe(nonEmptyString4()),
|
|
313509
|
+
/**
|
|
313510
|
+
* Workspace title.
|
|
313511
|
+
* If not provided, “document ID • document title” is used.
|
|
313512
|
+
*/
|
|
313513
|
+
workspaceTitle: String$2.pipe(nonEmptyString4()).pipe(optional),
|
|
313428
313514
|
/**
|
|
313429
313515
|
* Which reader modules to use.
|
|
313430
313516
|
*
|
|
@@ -317625,7 +317711,7 @@ ${inject.head ?? ""}`;
|
|
|
317625
317711
|
const assetsToWrite = {};
|
|
317626
317712
|
const rootMeta = reader.describeRoot();
|
|
317627
317713
|
const maybePrimaryLanguageID = rootMeta.primaryLanguageID ?? "en";
|
|
317628
|
-
const maybeMainTitle = rootMeta.labelInPlainText ?? "Document";
|
|
317714
|
+
const maybeMainTitle = cfg.workspaceTitle ?? rootMeta.labelInPlainText ?? "Document";
|
|
317629
317715
|
const allLanguages = /* @__PURE__ */ new Set(["en"]);
|
|
317630
317716
|
function getReverseResourceMap() {
|
|
317631
317717
|
return Object.fromEntries(Object.entries(resourceMap).map(([k, v]) => [v, k]));
|
|
@@ -317706,7 +317792,11 @@ ${inject.head ?? ""}`;
|
|
|
317706
317792
|
content.content.contentDoc
|
|
317707
317793
|
);
|
|
317708
317794
|
resourceMap[path3] = resourceURI;
|
|
317709
|
-
resourceGraph.push([
|
|
317795
|
+
resourceGraph.push([
|
|
317796
|
+
resourceURI,
|
|
317797
|
+
"isDefinedBy",
|
|
317798
|
+
`${path3}/resource.json`
|
|
317799
|
+
]);
|
|
317710
317800
|
resourceDescriptions[resourceURI] = resourceMeta;
|
|
317711
317801
|
searchableResources.pages[resourceURI] = {
|
|
317712
317802
|
name: resourceURI,
|
|
@@ -317728,7 +317818,11 @@ ${inject.head ?? ""}`;
|
|
|
317728
317818
|
const meta2 = reader.describe(inPageResourceID);
|
|
317729
317819
|
const graph2 = reader.resolve(inPageResourceID);
|
|
317730
317820
|
resourceMap[pathWithFragment] = inPageResourceID;
|
|
317731
|
-
resourceGraph.push([
|
|
317821
|
+
resourceGraph.push([
|
|
317822
|
+
inPageResourceID,
|
|
317823
|
+
"isDefinedBy",
|
|
317824
|
+
`${path3}/resource.json`
|
|
317825
|
+
]);
|
|
317732
317826
|
resourceDescriptions[inPageResourceID] = meta2;
|
|
317733
317827
|
if (inPageResourceID !== resourceURI) {
|
|
317734
317828
|
const body = preprocessStringForIndexing(
|
|
@@ -317838,7 +317932,7 @@ ${inject.head ?? ""}`;
|
|
|
317838
317932
|
supportedLanguages.join(", ")
|
|
317839
317933
|
);
|
|
317840
317934
|
const lunrTokenizer = import_lunr.default.tokenizer;
|
|
317841
|
-
this.tokenizer = function(x2) {
|
|
317935
|
+
this.tokenizer = function anaferoTokenizer(x2) {
|
|
317842
317936
|
const baseLunrTokens = lunrTokenizer(x2);
|
|
317843
317937
|
const tokens = [...baseLunrTokens];
|
|
317844
317938
|
for (const lang of nonDefaultLanguages) {
|
|
@@ -317854,7 +317948,7 @@ ${inject.head ?? ""}`;
|
|
|
317854
317948
|
return tokens;
|
|
317855
317949
|
};
|
|
317856
317950
|
const lunrStopWordFilter = import_lunr.default.stopWordFilter;
|
|
317857
|
-
this.stopWordFilter = function(token) {
|
|
317951
|
+
this.stopWordFilter = function anaferoStopWordFilter(token) {
|
|
317858
317952
|
return lunrStopWordFilter(token) && !nonDefaultLanguages.map(
|
|
317859
317953
|
(lang) => !!this[lang].stopWordFilter(token)
|
|
317860
317954
|
).includes(false) ? token : void 0;
|
|
@@ -317878,7 +317972,9 @@ ${inject.head ?? ""}`;
|
|
|
317878
317972
|
}
|
|
317879
317973
|
});
|
|
317880
317974
|
indexProgress(null);
|
|
317881
|
-
yield {
|
|
317975
|
+
yield {
|
|
317976
|
+
"/search-index.json": encoder.encode(JSON.stringify(lunrIndex, null, 4))
|
|
317977
|
+
};
|
|
317882
317978
|
}
|
|
317883
317979
|
async function* generateStaticSiteAssets(versions, currentVersionID, opts) {
|
|
317884
317980
|
const versionIDsSorted = Array.from(Object.entries(versions)).toSorted(
|
|
@@ -322468,22 +322564,8 @@ var buildSite = Command_exports2.make(
|
|
|
322468
322564
|
if (prefix && (!prefix.startsWith("/") || prefix.endsWith("/"))) {
|
|
322469
322565
|
throw new Error("Path prefix must have a leading slash and no trailing slash");
|
|
322470
322566
|
}
|
|
322471
|
-
|
|
322472
|
-
|
|
322473
|
-
try {
|
|
322474
|
-
console.warn("Dumping cache to cacheDump.json");
|
|
322475
|
-
fs4.writeFileSync(
|
|
322476
|
-
"cacheDump.json",
|
|
322477
|
-
JSON.stringify(cache3.dump(), null, 2),
|
|
322478
|
-
{ encoding: "utf-8" }
|
|
322479
|
-
);
|
|
322480
|
-
} catch (e3) {
|
|
322481
|
-
console.error("Cache dump could not be written!", e3);
|
|
322482
|
-
}
|
|
322483
|
-
}
|
|
322484
|
-
}
|
|
322485
|
-
process.on("SIGINT", maybeDumpCache);
|
|
322486
|
-
render_default(/* @__PURE__ */ import_react129.default.createElement(Processor, { rootTaskName: "build site", onStart: async function({ onProgress }) {
|
|
322567
|
+
let dumping = false;
|
|
322568
|
+
async function generate({ onProgress }) {
|
|
322487
322569
|
try {
|
|
322488
322570
|
const generator = generateSite(
|
|
322489
322571
|
{
|
|
@@ -322510,14 +322592,65 @@ var buildSite = Command_exports2.make(
|
|
|
322510
322592
|
}
|
|
322511
322593
|
writeProgress(null);
|
|
322512
322594
|
onProgress("build site", null);
|
|
322595
|
+
await maybeDumpCache();
|
|
322513
322596
|
resolve4(void 0);
|
|
322514
322597
|
} catch (e3) {
|
|
322598
|
+
await maybeDumpCache();
|
|
322515
322599
|
reject(e3);
|
|
322516
322600
|
} finally {
|
|
322517
|
-
maybeDumpCache();
|
|
322518
|
-
process.removeListener("SIGINT", maybeDumpCache);
|
|
322519
322601
|
}
|
|
322520
|
-
}
|
|
322602
|
+
}
|
|
322603
|
+
async function maybeDumpCache() {
|
|
322604
|
+
if (dumping || !debug3) {
|
|
322605
|
+
return;
|
|
322606
|
+
}
|
|
322607
|
+
const ac = new AbortController();
|
|
322608
|
+
const filename = "cacheDump.txt";
|
|
322609
|
+
function abortDumpCache() {
|
|
322610
|
+
console.warn("Aborting cache dump");
|
|
322611
|
+
process.removeListener("SIGTERM", abortDumpCache);
|
|
322612
|
+
process.removeListener("SIGINT", abortDumpCache);
|
|
322613
|
+
ac.abort();
|
|
322614
|
+
reject("Aborted");
|
|
322615
|
+
}
|
|
322616
|
+
process.on("SIGTERM", abortDumpCache);
|
|
322617
|
+
process.on("SIGINT", abortDumpCache);
|
|
322618
|
+
return new Promise((resolve5, reject2) => {
|
|
322619
|
+
process.removeListener("SIGINT", maybeDumpCache);
|
|
322620
|
+
dumping = true;
|
|
322621
|
+
try {
|
|
322622
|
+
const stream4 = fs4.createWriteStream(filename, {
|
|
322623
|
+
flags: "w",
|
|
322624
|
+
autoClose: true,
|
|
322625
|
+
emitClose: true,
|
|
322626
|
+
flush: true,
|
|
322627
|
+
encoding: "utf-8",
|
|
322628
|
+
signal: ac.signal
|
|
322629
|
+
});
|
|
322630
|
+
stream4.on("error", function handleCacheDumpStreamError(e3) {
|
|
322631
|
+
console.error("Error writing cache dump", e3);
|
|
322632
|
+
reject2(e3);
|
|
322633
|
+
});
|
|
322634
|
+
stream4.on("close", function handleCloseCacheDumpStream() {
|
|
322635
|
+
console.warn("Cache dump stream close event");
|
|
322636
|
+
resolve5(void 0);
|
|
322637
|
+
stream4.close(function() {
|
|
322638
|
+
console.warn("Exiting");
|
|
322639
|
+
});
|
|
322640
|
+
});
|
|
322641
|
+
stream4.on("ready", function handleOpenCacheDumpStream() {
|
|
322642
|
+
console.warn("Dumping cache due to debug flag");
|
|
322643
|
+
cache3.dump(stream4, ac.signal).then(resolve5, reject2);
|
|
322644
|
+
});
|
|
322645
|
+
} catch (e3) {
|
|
322646
|
+
console.error("Could not start cache dump stream", e3);
|
|
322647
|
+
reject2(e3);
|
|
322648
|
+
} finally {
|
|
322649
|
+
}
|
|
322650
|
+
});
|
|
322651
|
+
}
|
|
322652
|
+
process.on("SIGINT", maybeDumpCache);
|
|
322653
|
+
render_default(/* @__PURE__ */ import_react129.default.createElement(Processor, { rootTaskName: "build site", onStart: generate }));
|
|
322521
322654
|
}),
|
|
322522
322655
|
catch: (e3) => {
|
|
322523
322656
|
console.error(e3);
|
|
@@ -156,22 +156,10 @@ const buildSite = Command.
|
|
|
156
156
|
if (prefix && (!prefix.startsWith('/') || prefix.endsWith('/'))) {
|
|
157
157
|
throw new Error("Path prefix must have a leading slash and no trailing slash");
|
|
158
158
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
fs.writeFileSync(
|
|
164
|
-
'cacheDump.json',
|
|
165
|
-
JSON.stringify(cache.dump(), null, 2),
|
|
166
|
-
{ encoding: 'utf-8' },
|
|
167
|
-
);
|
|
168
|
-
} catch (e) {
|
|
169
|
-
console.error("Cache dump could not be written!", e);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
process.on('SIGINT', maybeDumpCache);
|
|
174
|
-
render(<Processor rootTaskName="build site" onStart={async function ({ onProgress }) {
|
|
159
|
+
|
|
160
|
+
let dumping = false;
|
|
161
|
+
|
|
162
|
+
async function generate({ onProgress }: { onProgress: TaskProgressCallback }) {
|
|
175
163
|
try {
|
|
176
164
|
const generator = generateSite(
|
|
177
165
|
{
|
|
@@ -198,14 +186,80 @@ const buildSite = Command.
|
|
|
198
186
|
}
|
|
199
187
|
writeProgress(null);
|
|
200
188
|
onProgress('build site', null);
|
|
189
|
+
await maybeDumpCache();
|
|
201
190
|
resolve(void 0);
|
|
202
191
|
} catch (e) {
|
|
192
|
+
await maybeDumpCache();
|
|
203
193
|
reject(e);
|
|
204
194
|
} finally {
|
|
205
|
-
maybeDumpCache()
|
|
206
|
-
|
|
195
|
+
// Can’t have maybeDumpCache() here, because we want
|
|
196
|
+
// to call it before resolving/rejecting the promise.
|
|
207
197
|
}
|
|
208
|
-
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
async function maybeDumpCache() {
|
|
201
|
+
if (dumping || !debug) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const ac = new AbortController();
|
|
206
|
+
const filename = 'cacheDump.txt';
|
|
207
|
+
|
|
208
|
+
function abortDumpCache() {
|
|
209
|
+
console.warn("Aborting cache dump");
|
|
210
|
+
process.removeListener('SIGTERM', abortDumpCache);
|
|
211
|
+
process.removeListener('SIGINT', abortDumpCache);
|
|
212
|
+
ac.abort();
|
|
213
|
+
reject("Aborted");
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
process.on('SIGTERM', abortDumpCache);
|
|
217
|
+
process.on('SIGINT', abortDumpCache);
|
|
218
|
+
|
|
219
|
+
return new Promise((resolve, reject) => {
|
|
220
|
+
process.removeListener('SIGINT', maybeDumpCache);
|
|
221
|
+
dumping = true;
|
|
222
|
+
|
|
223
|
+
try {
|
|
224
|
+
const stream = fs.createWriteStream(filename, {
|
|
225
|
+
flags: 'w',
|
|
226
|
+
autoClose: true,
|
|
227
|
+
emitClose: true,
|
|
228
|
+
flush: true,
|
|
229
|
+
encoding: 'utf-8',
|
|
230
|
+
signal: ac.signal,
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
stream.on('error', function handleCacheDumpStreamError(e) {
|
|
234
|
+
console.error("Error writing cache dump", e);
|
|
235
|
+
reject(e);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
stream.on('close', function handleCloseCacheDumpStream() {
|
|
239
|
+
console.warn("Cache dump stream close event");
|
|
240
|
+
resolve(void 0);
|
|
241
|
+
|
|
242
|
+
stream.close(function () {
|
|
243
|
+
console.warn("Exiting");
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
stream.on('ready', function handleOpenCacheDumpStream() {
|
|
248
|
+
console.warn("Dumping cache due to debug flag");
|
|
249
|
+
cache.dump(stream, ac.signal).then(resolve, reject);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
} catch (e) {
|
|
253
|
+
console.error("Could not start cache dump stream", e);
|
|
254
|
+
reject(e);
|
|
255
|
+
} finally {
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
process.on('SIGINT', maybeDumpCache);
|
|
261
|
+
|
|
262
|
+
render(<Processor rootTaskName="build site" onStart={generate} />);
|
|
209
263
|
}),
|
|
210
264
|
catch: (e) => {
|
|
211
265
|
console.error(e);
|