@mp-lb/forum-cli 0.1.7 → 0.1.9
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/index.js +170 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -31440,6 +31440,7 @@ var createStoreClient = ({
|
|
|
31440
31440
|
writeQueryFile: (input) => call("files.writeQuery", () => trpc.files.writeQuery.mutate(input)),
|
|
31441
31441
|
readFile: (input) => call("files.readFile", () => trpc.files.readFile.query(input)),
|
|
31442
31442
|
readFileByRef: (input) => call("files.readFileByRef", () => trpc.files.readFileByRef.query(input)),
|
|
31443
|
+
readFileById: (input) => call("files.readFileById", () => trpc.files.readFileById.query(input)),
|
|
31443
31444
|
createFileDownloadUrl: (input) => call(
|
|
31444
31445
|
"files.createFileDownloadUrl",
|
|
31445
31446
|
() => trpc.files.createFileDownloadUrl.mutate(input)
|
|
@@ -32229,6 +32230,111 @@ var readHiddenLine = async (prompt) => {
|
|
|
32229
32230
|
});
|
|
32230
32231
|
};
|
|
32231
32232
|
|
|
32233
|
+
// src/compileMarkdown.ts
|
|
32234
|
+
var maxCompileDepth = 32;
|
|
32235
|
+
var maxCompileFiles = 100;
|
|
32236
|
+
var maxCompileBytes = 10 * 1024 * 1024;
|
|
32237
|
+
var CompileError = class extends Error {
|
|
32238
|
+
code;
|
|
32239
|
+
constructor(code, message) {
|
|
32240
|
+
super(`${code}: ${message}`);
|
|
32241
|
+
this.name = "CompileError";
|
|
32242
|
+
this.code = code;
|
|
32243
|
+
}
|
|
32244
|
+
};
|
|
32245
|
+
var rawFileId = (href) => {
|
|
32246
|
+
try {
|
|
32247
|
+
const url2 = new URL(href);
|
|
32248
|
+
const parts = url2.pathname.split("/").filter(Boolean);
|
|
32249
|
+
if (url2.search || url2.hash) return null;
|
|
32250
|
+
if ((url2.hostname === "hyperdoc.forumlabs.net" || url2.hostname === "dx.ink") && parts.length === 1) {
|
|
32251
|
+
return decodeURIComponent(parts[0] ?? "");
|
|
32252
|
+
}
|
|
32253
|
+
return url2.hostname === "app.forumlabs.net" && parts.length === 2 && parts[0] === "raw-file" ? decodeURIComponent(parts[1] ?? "") : null;
|
|
32254
|
+
} catch {
|
|
32255
|
+
return null;
|
|
32256
|
+
}
|
|
32257
|
+
};
|
|
32258
|
+
var standaloneIncludeId = (paragraph) => {
|
|
32259
|
+
const match = paragraph.match(/^\s*\[[^\]]*\]\(([^)\s]+)\)\s*$/);
|
|
32260
|
+
return match ? rawFileId(match[1] ?? "") : null;
|
|
32261
|
+
};
|
|
32262
|
+
var textContent = (file2) => file2?.content && "text" in file2.content ? file2.content.text : null;
|
|
32263
|
+
var compileMarkdown = async ({
|
|
32264
|
+
entry,
|
|
32265
|
+
readFile: readFile9,
|
|
32266
|
+
optional: optional2,
|
|
32267
|
+
limits = {}
|
|
32268
|
+
}) => {
|
|
32269
|
+
const warnings = [];
|
|
32270
|
+
const maxBytes = limits.maxBytes ?? maxCompileBytes;
|
|
32271
|
+
const maxDepth = limits.maxDepth ?? maxCompileDepth;
|
|
32272
|
+
const maxFiles = limits.maxFiles ?? maxCompileFiles;
|
|
32273
|
+
let bytesRead = 0;
|
|
32274
|
+
let filesRead = 0;
|
|
32275
|
+
const compile = async (file2, chain, depth) => {
|
|
32276
|
+
const source = textContent(file2);
|
|
32277
|
+
const label = file2.path ?? file2.id ?? "entry file";
|
|
32278
|
+
if (source === null)
|
|
32279
|
+
throw new Error(`Cannot compile ${label}: file is binary or unreadable.`);
|
|
32280
|
+
if (depth > maxDepth)
|
|
32281
|
+
throw new CompileError(
|
|
32282
|
+
"FM_COMPILE_MAX_DEPTH",
|
|
32283
|
+
`maximum include depth (${maxDepth}) exceeded: ${chain.join(" -> ")}`
|
|
32284
|
+
);
|
|
32285
|
+
filesRead += 1;
|
|
32286
|
+
if (filesRead > maxFiles)
|
|
32287
|
+
throw new CompileError(
|
|
32288
|
+
"FM_COMPILE_MAX_FILES",
|
|
32289
|
+
`maximum file count (${maxFiles}) exceeded while reading ${label}.`
|
|
32290
|
+
);
|
|
32291
|
+
bytesRead += Buffer.byteLength(source, "utf8");
|
|
32292
|
+
if (bytesRead > maxBytes)
|
|
32293
|
+
throw new CompileError(
|
|
32294
|
+
"FM_COMPILE_MAX_BYTES",
|
|
32295
|
+
`maximum source size (${maxBytes} bytes) exceeded while reading ${label}.`
|
|
32296
|
+
);
|
|
32297
|
+
const paragraphs = source.split(/(\n(?:[ \t]*\n)+)/);
|
|
32298
|
+
const rendered = [];
|
|
32299
|
+
for (const paragraph of paragraphs) {
|
|
32300
|
+
const id = standaloneIncludeId(paragraph);
|
|
32301
|
+
if (!id) {
|
|
32302
|
+
rendered.push(paragraph);
|
|
32303
|
+
continue;
|
|
32304
|
+
}
|
|
32305
|
+
if (chain.includes(id))
|
|
32306
|
+
throw new Error(`Include cycle: ${[...chain, id].join(" -> ")}`);
|
|
32307
|
+
let target;
|
|
32308
|
+
try {
|
|
32309
|
+
target = await readFile9(id);
|
|
32310
|
+
} catch (error51) {
|
|
32311
|
+
if (optional2) {
|
|
32312
|
+
warnings.push(`Omitted unreadable include ${id} from ${label}.`);
|
|
32313
|
+
continue;
|
|
32314
|
+
}
|
|
32315
|
+
throw new Error(
|
|
32316
|
+
`Cannot include ${id} from ${label}: ${error51 instanceof Error ? error51.message : String(error51)}`
|
|
32317
|
+
);
|
|
32318
|
+
}
|
|
32319
|
+
if (!target || textContent(target) === null) {
|
|
32320
|
+
if (optional2) {
|
|
32321
|
+
warnings.push(`Omitted unreadable include ${id} from ${label}.`);
|
|
32322
|
+
continue;
|
|
32323
|
+
}
|
|
32324
|
+
throw new Error(
|
|
32325
|
+
`Cannot include ${id} from ${label}: target is missing, binary, or unreadable.`
|
|
32326
|
+
);
|
|
32327
|
+
}
|
|
32328
|
+
rendered.push(await compile(target, [...chain, id], depth + 1));
|
|
32329
|
+
}
|
|
32330
|
+
return rendered.join("");
|
|
32331
|
+
};
|
|
32332
|
+
return {
|
|
32333
|
+
text: await compile(entry, entry.id ? [entry.id] : [], 0),
|
|
32334
|
+
warnings
|
|
32335
|
+
};
|
|
32336
|
+
};
|
|
32337
|
+
|
|
32232
32338
|
// src/resolveDecryptAuthMode.ts
|
|
32233
32339
|
var resolveDecryptAuthMode = ({
|
|
32234
32340
|
encryptionPassword,
|
|
@@ -32270,6 +32376,8 @@ Usage:
|
|
|
32270
32376
|
fm store delete <storeId> [--yes|-y] [--token <jwt>]
|
|
32271
32377
|
fm file ls [directoryPath] [--store <storeId>] [--token <jwt>]
|
|
32272
32378
|
fm file read <filePath> [--store <storeId>] [--token <jwt>]
|
|
32379
|
+
fm compile <workspace>/<store> <entry-file> [-o <output-file>] [--optional] [--token <jwt>]
|
|
32380
|
+
fm compile --stdin [-o <output-file>] [--optional] [--token <jwt>]
|
|
32273
32381
|
fm file info <filePath> [--store <storeId>] [--token <jwt>]
|
|
32274
32382
|
fm file move <sourcePath> <destinationPath> [--store <storeId>] [--token <jwt>]
|
|
32275
32383
|
fm file delete <filePath> [--store <storeId>] [--token <jwt>]
|
|
@@ -32414,6 +32522,7 @@ var parseArgs = (argv) => {
|
|
|
32414
32522
|
let searchLimit = null;
|
|
32415
32523
|
let searchType = null;
|
|
32416
32524
|
let inputFilePath = null;
|
|
32525
|
+
let outputFilePath = null;
|
|
32417
32526
|
let ref = null;
|
|
32418
32527
|
let encryptionPassword = null;
|
|
32419
32528
|
let recipientSecret = null;
|
|
@@ -32434,6 +32543,8 @@ var parseArgs = (argv) => {
|
|
|
32434
32543
|
let local = false;
|
|
32435
32544
|
let notify = false;
|
|
32436
32545
|
let openBrowser = true;
|
|
32546
|
+
let optional2 = false;
|
|
32547
|
+
let stdin = false;
|
|
32437
32548
|
let readonly2 = false;
|
|
32438
32549
|
let verbose = false;
|
|
32439
32550
|
let watch3 = false;
|
|
@@ -32478,6 +32589,12 @@ var parseArgs = (argv) => {
|
|
|
32478
32589
|
index += 1;
|
|
32479
32590
|
continue;
|
|
32480
32591
|
}
|
|
32592
|
+
if (current === "--output" || current === "-o") {
|
|
32593
|
+
if (!next) throw new Error(`${current} requires a local output path.`);
|
|
32594
|
+
outputFilePath = path21.resolve(next);
|
|
32595
|
+
index += 1;
|
|
32596
|
+
continue;
|
|
32597
|
+
}
|
|
32481
32598
|
if (current === "--password") {
|
|
32482
32599
|
encryptionPassword = next ?? encryptionPassword;
|
|
32483
32600
|
index += 1;
|
|
@@ -32578,6 +32695,14 @@ var parseArgs = (argv) => {
|
|
|
32578
32695
|
openBrowser = false;
|
|
32579
32696
|
continue;
|
|
32580
32697
|
}
|
|
32698
|
+
if (current === "--optional") {
|
|
32699
|
+
optional2 = true;
|
|
32700
|
+
continue;
|
|
32701
|
+
}
|
|
32702
|
+
if (current === "--stdin") {
|
|
32703
|
+
stdin = true;
|
|
32704
|
+
continue;
|
|
32705
|
+
}
|
|
32581
32706
|
if (isSyncCommand && (current === "-p" || current === "--prioritize" || current.startsWith("--prioritize="))) {
|
|
32582
32707
|
const value = current.startsWith("--prioritize=") ? current.slice("--prioritize=".length) : next;
|
|
32583
32708
|
if (value !== "local" && value !== "remote") {
|
|
@@ -32645,6 +32770,7 @@ var parseArgs = (argv) => {
|
|
|
32645
32770
|
searchLimit,
|
|
32646
32771
|
searchType,
|
|
32647
32772
|
inputFilePath,
|
|
32773
|
+
outputFilePath,
|
|
32648
32774
|
ref,
|
|
32649
32775
|
encryptionPassword,
|
|
32650
32776
|
recipientSecret,
|
|
@@ -32664,6 +32790,8 @@ var parseArgs = (argv) => {
|
|
|
32664
32790
|
local,
|
|
32665
32791
|
notify,
|
|
32666
32792
|
openBrowser,
|
|
32793
|
+
optional: optional2,
|
|
32794
|
+
stdin,
|
|
32667
32795
|
readonly: readonly2,
|
|
32668
32796
|
verbose,
|
|
32669
32797
|
watch: watch3,
|
|
@@ -37846,6 +37974,48 @@ var main = async (argv = process.argv.slice(2)) => {
|
|
|
37846
37974
|
);
|
|
37847
37975
|
return;
|
|
37848
37976
|
}
|
|
37977
|
+
if (command === "compile") {
|
|
37978
|
+
const [storeInput, entryPath, ...extra] = rest;
|
|
37979
|
+
let entry;
|
|
37980
|
+
if (parsed.stdin) {
|
|
37981
|
+
if (rest.length > 0) {
|
|
37982
|
+
throw new Error(
|
|
37983
|
+
`Usage: ${commandNames} compile --stdin [-o <output-file>] [--optional]`
|
|
37984
|
+
);
|
|
37985
|
+
}
|
|
37986
|
+
entry = {
|
|
37987
|
+
id: "stdin",
|
|
37988
|
+
path: "stdin",
|
|
37989
|
+
content: { text: await readStdinText() }
|
|
37990
|
+
};
|
|
37991
|
+
} else {
|
|
37992
|
+
if (!storeInput || !entryPath || extra.length > 0) {
|
|
37993
|
+
throw new Error(
|
|
37994
|
+
`Usage: ${commandNames} compile <workspace>/<store> <entry-file> [-o <output-file>] [--optional]`
|
|
37995
|
+
);
|
|
37996
|
+
}
|
|
37997
|
+
if (!isMarkdownStorePath(entryPath)) {
|
|
37998
|
+
throw new Error(
|
|
37999
|
+
`Compile only supports Forum-hosted Markdown files: ${entryPath}`
|
|
38000
|
+
);
|
|
38001
|
+
}
|
|
38002
|
+
const storeRef = await resolveOwnStoreRef(storeInput, client);
|
|
38003
|
+
entry = await client.readFileByRef({ ...storeRef, path: entryPath });
|
|
38004
|
+
if (!entry) throw new Error(`Entry file not found: ${entryPath}`);
|
|
38005
|
+
}
|
|
38006
|
+
const result = await compileMarkdown({
|
|
38007
|
+
entry,
|
|
38008
|
+
optional: parsed.optional,
|
|
38009
|
+
readFile: (id) => client.readFileById({ id })
|
|
38010
|
+
});
|
|
38011
|
+
result.warnings.forEach((warning) => renderWarning(warning));
|
|
38012
|
+
if (parsed.outputFilePath) {
|
|
38013
|
+
await writeFile6(parsed.outputFilePath, result.text, "utf8");
|
|
38014
|
+
} else {
|
|
38015
|
+
renderOutput(result.text);
|
|
38016
|
+
}
|
|
38017
|
+
return;
|
|
38018
|
+
}
|
|
37849
38019
|
if (command === "read" || command === "cat") {
|
|
37850
38020
|
if (command === "cat") {
|
|
37851
38021
|
const storeRef = await resolveSingleStoreRef(parsed.storeFilters, client);
|