@mp-lb/forum-cli 0.1.6 → 0.1.8
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 +151 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -3
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,107 @@ 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
|
+
return parts.length === 2 && parts[0] === "raw-file" ? decodeURIComponent(parts[1] ?? "") : null;
|
|
32250
|
+
} catch {
|
|
32251
|
+
return null;
|
|
32252
|
+
}
|
|
32253
|
+
};
|
|
32254
|
+
var standaloneIncludeId = (paragraph) => {
|
|
32255
|
+
const match = paragraph.match(/^\s*\[[^\]]*\]\(([^)\s]+)\)\s*$/);
|
|
32256
|
+
return match ? rawFileId(match[1] ?? "") : null;
|
|
32257
|
+
};
|
|
32258
|
+
var textContent = (file2) => file2?.content && "text" in file2.content ? file2.content.text : null;
|
|
32259
|
+
var compileMarkdown = async ({
|
|
32260
|
+
entry,
|
|
32261
|
+
readFile: readFile9,
|
|
32262
|
+
optional: optional2,
|
|
32263
|
+
limits = {}
|
|
32264
|
+
}) => {
|
|
32265
|
+
const warnings = [];
|
|
32266
|
+
const maxBytes = limits.maxBytes ?? maxCompileBytes;
|
|
32267
|
+
const maxDepth = limits.maxDepth ?? maxCompileDepth;
|
|
32268
|
+
const maxFiles = limits.maxFiles ?? maxCompileFiles;
|
|
32269
|
+
let bytesRead = 0;
|
|
32270
|
+
let filesRead = 0;
|
|
32271
|
+
const compile = async (file2, chain, depth) => {
|
|
32272
|
+
const source = textContent(file2);
|
|
32273
|
+
const label = file2.path ?? file2.id ?? "entry file";
|
|
32274
|
+
if (source === null)
|
|
32275
|
+
throw new Error(`Cannot compile ${label}: file is binary or unreadable.`);
|
|
32276
|
+
if (depth > maxDepth)
|
|
32277
|
+
throw new CompileError(
|
|
32278
|
+
"FM_COMPILE_MAX_DEPTH",
|
|
32279
|
+
`maximum include depth (${maxDepth}) exceeded: ${chain.join(" -> ")}`
|
|
32280
|
+
);
|
|
32281
|
+
filesRead += 1;
|
|
32282
|
+
if (filesRead > maxFiles)
|
|
32283
|
+
throw new CompileError(
|
|
32284
|
+
"FM_COMPILE_MAX_FILES",
|
|
32285
|
+
`maximum file count (${maxFiles}) exceeded while reading ${label}.`
|
|
32286
|
+
);
|
|
32287
|
+
bytesRead += Buffer.byteLength(source, "utf8");
|
|
32288
|
+
if (bytesRead > maxBytes)
|
|
32289
|
+
throw new CompileError(
|
|
32290
|
+
"FM_COMPILE_MAX_BYTES",
|
|
32291
|
+
`maximum source size (${maxBytes} bytes) exceeded while reading ${label}.`
|
|
32292
|
+
);
|
|
32293
|
+
const paragraphs = source.split(/(\n(?:[ \t]*\n)+)/);
|
|
32294
|
+
const rendered = [];
|
|
32295
|
+
for (const paragraph of paragraphs) {
|
|
32296
|
+
const id = standaloneIncludeId(paragraph);
|
|
32297
|
+
if (!id) {
|
|
32298
|
+
rendered.push(paragraph);
|
|
32299
|
+
continue;
|
|
32300
|
+
}
|
|
32301
|
+
if (chain.includes(id))
|
|
32302
|
+
throw new Error(`Include cycle: ${[...chain, id].join(" -> ")}`);
|
|
32303
|
+
let target;
|
|
32304
|
+
try {
|
|
32305
|
+
target = await readFile9(id);
|
|
32306
|
+
} catch (error51) {
|
|
32307
|
+
if (optional2) {
|
|
32308
|
+
warnings.push(`Omitted unreadable include ${id} from ${label}.`);
|
|
32309
|
+
continue;
|
|
32310
|
+
}
|
|
32311
|
+
throw new Error(
|
|
32312
|
+
`Cannot include ${id} from ${label}: ${error51 instanceof Error ? error51.message : String(error51)}`
|
|
32313
|
+
);
|
|
32314
|
+
}
|
|
32315
|
+
if (!target || textContent(target) === null) {
|
|
32316
|
+
if (optional2) {
|
|
32317
|
+
warnings.push(`Omitted unreadable include ${id} from ${label}.`);
|
|
32318
|
+
continue;
|
|
32319
|
+
}
|
|
32320
|
+
throw new Error(
|
|
32321
|
+
`Cannot include ${id} from ${label}: target is missing, binary, or unreadable.`
|
|
32322
|
+
);
|
|
32323
|
+
}
|
|
32324
|
+
rendered.push(await compile(target, [...chain, id], depth + 1));
|
|
32325
|
+
}
|
|
32326
|
+
return rendered.join("");
|
|
32327
|
+
};
|
|
32328
|
+
return {
|
|
32329
|
+
text: await compile(entry, entry.id ? [entry.id] : [], 0),
|
|
32330
|
+
warnings
|
|
32331
|
+
};
|
|
32332
|
+
};
|
|
32333
|
+
|
|
32232
32334
|
// src/resolveDecryptAuthMode.ts
|
|
32233
32335
|
var resolveDecryptAuthMode = ({
|
|
32234
32336
|
encryptionPassword,
|
|
@@ -32270,6 +32372,7 @@ Usage:
|
|
|
32270
32372
|
fm store delete <storeId> [--yes|-y] [--token <jwt>]
|
|
32271
32373
|
fm file ls [directoryPath] [--store <storeId>] [--token <jwt>]
|
|
32272
32374
|
fm file read <filePath> [--store <storeId>] [--token <jwt>]
|
|
32375
|
+
fm compile <workspace>/<store> <entry-file> [-o <output-file>] [--optional] [--token <jwt>]
|
|
32273
32376
|
fm file info <filePath> [--store <storeId>] [--token <jwt>]
|
|
32274
32377
|
fm file move <sourcePath> <destinationPath> [--store <storeId>] [--token <jwt>]
|
|
32275
32378
|
fm file delete <filePath> [--store <storeId>] [--token <jwt>]
|
|
@@ -32316,7 +32419,7 @@ Usage:
|
|
|
32316
32419
|
fm push [filePath] [--token <jwt>] [--force] [--yes|-y] [--dry-run|-d] [--verbose|--debug]
|
|
32317
32420
|
fm status [--token <jwt>] [--json]
|
|
32318
32421
|
fm s [--token <jwt>] [--json]
|
|
32319
|
-
fm sync [--token <jwt>] [--
|
|
32422
|
+
fm sync [--token <jwt>] [--prioritize|-p local|remote] [--force] [--yes|-y] [--verbose] [--watch] [--readonly]
|
|
32320
32423
|
fm sync --watch [<path>] [--notify] [--json] [--readonly]
|
|
32321
32424
|
fm sync --watch <path...> [--paths-file <file>] [--notify] [--json]
|
|
32322
32425
|
fm sync --dry-run|-d [--token <jwt>] [--json]
|
|
@@ -32414,6 +32517,7 @@ var parseArgs = (argv) => {
|
|
|
32414
32517
|
let searchLimit = null;
|
|
32415
32518
|
let searchType = null;
|
|
32416
32519
|
let inputFilePath = null;
|
|
32520
|
+
let outputFilePath = null;
|
|
32417
32521
|
let ref = null;
|
|
32418
32522
|
let encryptionPassword = null;
|
|
32419
32523
|
let recipientSecret = null;
|
|
@@ -32434,6 +32538,7 @@ var parseArgs = (argv) => {
|
|
|
32434
32538
|
let local = false;
|
|
32435
32539
|
let notify = false;
|
|
32436
32540
|
let openBrowser = true;
|
|
32541
|
+
let optional2 = false;
|
|
32437
32542
|
let readonly2 = false;
|
|
32438
32543
|
let verbose = false;
|
|
32439
32544
|
let watch3 = false;
|
|
@@ -32478,6 +32583,12 @@ var parseArgs = (argv) => {
|
|
|
32478
32583
|
index += 1;
|
|
32479
32584
|
continue;
|
|
32480
32585
|
}
|
|
32586
|
+
if (current === "--output" || current === "-o") {
|
|
32587
|
+
if (!next) throw new Error(`${current} requires a local output path.`);
|
|
32588
|
+
outputFilePath = path21.resolve(next);
|
|
32589
|
+
index += 1;
|
|
32590
|
+
continue;
|
|
32591
|
+
}
|
|
32481
32592
|
if (current === "--password") {
|
|
32482
32593
|
encryptionPassword = next ?? encryptionPassword;
|
|
32483
32594
|
index += 1;
|
|
@@ -32578,13 +32689,17 @@ var parseArgs = (argv) => {
|
|
|
32578
32689
|
openBrowser = false;
|
|
32579
32690
|
continue;
|
|
32580
32691
|
}
|
|
32581
|
-
if (
|
|
32582
|
-
|
|
32692
|
+
if (current === "--optional") {
|
|
32693
|
+
optional2 = true;
|
|
32694
|
+
continue;
|
|
32695
|
+
}
|
|
32696
|
+
if (isSyncCommand && (current === "-p" || current === "--prioritize" || current.startsWith("--prioritize="))) {
|
|
32697
|
+
const value = current.startsWith("--prioritize=") ? current.slice("--prioritize=".length) : next;
|
|
32583
32698
|
if (value !== "local" && value !== "remote") {
|
|
32584
|
-
throw new Error("--
|
|
32699
|
+
throw new Error("--prioritize requires local or remote.");
|
|
32585
32700
|
}
|
|
32586
32701
|
conflictPolicy = value;
|
|
32587
|
-
if (!current.startsWith("--
|
|
32702
|
+
if (!current.startsWith("--prioritize=")) index += 1;
|
|
32588
32703
|
continue;
|
|
32589
32704
|
}
|
|
32590
32705
|
if (current === "--force") {
|
|
@@ -32645,6 +32760,7 @@ var parseArgs = (argv) => {
|
|
|
32645
32760
|
searchLimit,
|
|
32646
32761
|
searchType,
|
|
32647
32762
|
inputFilePath,
|
|
32763
|
+
outputFilePath,
|
|
32648
32764
|
ref,
|
|
32649
32765
|
encryptionPassword,
|
|
32650
32766
|
recipientSecret,
|
|
@@ -32664,6 +32780,7 @@ var parseArgs = (argv) => {
|
|
|
32664
32780
|
local,
|
|
32665
32781
|
notify,
|
|
32666
32782
|
openBrowser,
|
|
32783
|
+
optional: optional2,
|
|
32667
32784
|
readonly: readonly2,
|
|
32668
32785
|
verbose,
|
|
32669
32786
|
watch: watch3,
|
|
@@ -37687,7 +37804,7 @@ var main = async (argv = process.argv.slice(2)) => {
|
|
|
37687
37804
|
if (command === "sync") {
|
|
37688
37805
|
if (parsed.conflictPolicy && (parsed.force || parsed.readonly)) {
|
|
37689
37806
|
throw new Error(
|
|
37690
|
-
"--
|
|
37807
|
+
"--prioritize cannot be combined with --force or --readonly."
|
|
37691
37808
|
);
|
|
37692
37809
|
}
|
|
37693
37810
|
if (rest[0] === "reset") {
|
|
@@ -37846,6 +37963,34 @@ var main = async (argv = process.argv.slice(2)) => {
|
|
|
37846
37963
|
);
|
|
37847
37964
|
return;
|
|
37848
37965
|
}
|
|
37966
|
+
if (command === "compile") {
|
|
37967
|
+
const [storeInput, entryPath, ...extra] = rest;
|
|
37968
|
+
if (!storeInput || !entryPath || extra.length > 0) {
|
|
37969
|
+
throw new Error(
|
|
37970
|
+
`Usage: ${commandNames} compile <workspace>/<store> <entry-file> [-o <output-file>] [--optional]`
|
|
37971
|
+
);
|
|
37972
|
+
}
|
|
37973
|
+
if (!isMarkdownStorePath(entryPath)) {
|
|
37974
|
+
throw new Error(
|
|
37975
|
+
`Compile only supports Forum-hosted Markdown files: ${entryPath}`
|
|
37976
|
+
);
|
|
37977
|
+
}
|
|
37978
|
+
const storeRef = await resolveOwnStoreRef(storeInput, client);
|
|
37979
|
+
const entry = await client.readFileByRef({ ...storeRef, path: entryPath });
|
|
37980
|
+
if (!entry) throw new Error(`Entry file not found: ${entryPath}`);
|
|
37981
|
+
const result = await compileMarkdown({
|
|
37982
|
+
entry,
|
|
37983
|
+
optional: parsed.optional,
|
|
37984
|
+
readFile: (id) => client.readFileById({ id })
|
|
37985
|
+
});
|
|
37986
|
+
result.warnings.forEach((warning) => renderWarning(warning));
|
|
37987
|
+
if (parsed.outputFilePath) {
|
|
37988
|
+
await writeFile6(parsed.outputFilePath, result.text, "utf8");
|
|
37989
|
+
} else {
|
|
37990
|
+
renderOutput(result.text);
|
|
37991
|
+
}
|
|
37992
|
+
return;
|
|
37993
|
+
}
|
|
37849
37994
|
if (command === "read" || command === "cat") {
|
|
37850
37995
|
if (command === "cat") {
|
|
37851
37996
|
const storeRef = await resolveSingleStoreRef(parsed.storeFilters, client);
|