nrdocs 0.2.2 → 0.2.3
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/bin.mjs +149 -127
- package/package.json +1 -1
package/dist/bin.mjs
CHANGED
|
@@ -268,57 +268,24 @@ var require_punycode = __commonJS({
|
|
|
268
268
|
}
|
|
269
269
|
});
|
|
270
270
|
|
|
271
|
-
//
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
]);
|
|
287
|
-
var REJECTED_EXTENSIONS = /* @__PURE__ */ new Set([".js", ".mjs", ".cjs"]);
|
|
288
|
-
|
|
289
|
-
// ../shared/dist/naming.js
|
|
290
|
-
var INSTANCE_NAME_REGEX = /^[a-z0-9]([a-z0-9-]{0,18}[a-z0-9])?$/;
|
|
291
|
-
var MAX_INSTANCE_LENGTH = 20;
|
|
292
|
-
function validateInstanceName(name) {
|
|
293
|
-
if (!name) {
|
|
294
|
-
return { valid: false, error: "Instance name cannot be empty" };
|
|
295
|
-
}
|
|
296
|
-
if (name.length > MAX_INSTANCE_LENGTH) {
|
|
297
|
-
return { valid: false, error: `Instance name must be ${MAX_INSTANCE_LENGTH} characters or fewer` };
|
|
298
|
-
}
|
|
299
|
-
if (!INSTANCE_NAME_REGEX.test(name)) {
|
|
300
|
-
return {
|
|
301
|
-
valid: false,
|
|
302
|
-
error: "Instance name must be lowercase alphanumeric with hyphens, cannot start or end with a hyphen"
|
|
303
|
-
};
|
|
271
|
+
// src/version.ts
|
|
272
|
+
import { readFileSync } from "node:fs";
|
|
273
|
+
import * as path from "node:path";
|
|
274
|
+
import { fileURLToPath } from "node:url";
|
|
275
|
+
var cached;
|
|
276
|
+
function getCliVersion() {
|
|
277
|
+
if (cached) return cached;
|
|
278
|
+
try {
|
|
279
|
+
const pkgPath = path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "package.json");
|
|
280
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
281
|
+
if (typeof pkg.version === "string" && pkg.version.length > 0) {
|
|
282
|
+
cached = pkg.version;
|
|
283
|
+
return cached;
|
|
284
|
+
}
|
|
285
|
+
} catch {
|
|
304
286
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
function getWorkerName(instance) {
|
|
308
|
-
return `nrdocs-${instance}`;
|
|
309
|
-
}
|
|
310
|
-
function getD1Name(instance) {
|
|
311
|
-
return `nrdocs-${instance}-db`;
|
|
312
|
-
}
|
|
313
|
-
function getR2BucketName(instance) {
|
|
314
|
-
return `nrdocs-${instance}-artifacts`;
|
|
315
|
-
}
|
|
316
|
-
function getResourceNames(instance) {
|
|
317
|
-
return {
|
|
318
|
-
worker: getWorkerName(instance),
|
|
319
|
-
d1: getD1Name(instance),
|
|
320
|
-
r2: getR2BucketName(instance)
|
|
321
|
-
};
|
|
287
|
+
cached = "0.0.0";
|
|
288
|
+
return cached;
|
|
322
289
|
}
|
|
323
290
|
|
|
324
291
|
// src/commands/auth/login.ts
|
|
@@ -326,17 +293,17 @@ import * as readline from "node:readline";
|
|
|
326
293
|
|
|
327
294
|
// src/config/paths.ts
|
|
328
295
|
import * as os from "node:os";
|
|
329
|
-
import * as
|
|
296
|
+
import * as path2 from "node:path";
|
|
330
297
|
var APP_NAME = "nrdocs";
|
|
331
298
|
var CONFIG_FILE = "config.json";
|
|
332
299
|
function getConfigDir(overrideDir) {
|
|
333
300
|
if (overrideDir) return overrideDir;
|
|
334
301
|
const xdg = process.env["XDG_CONFIG_HOME"];
|
|
335
|
-
const base = xdg ||
|
|
336
|
-
return
|
|
302
|
+
const base = xdg || path2.join(os.homedir(), ".config");
|
|
303
|
+
return path2.join(base, APP_NAME);
|
|
337
304
|
}
|
|
338
305
|
function getConfigPath(overrideDir) {
|
|
339
|
-
return
|
|
306
|
+
return path2.join(getConfigDir(overrideDir), CONFIG_FILE);
|
|
340
307
|
}
|
|
341
308
|
|
|
342
309
|
// src/config/schema.ts
|
|
@@ -366,7 +333,7 @@ function validateConfig(data) {
|
|
|
366
333
|
|
|
367
334
|
// src/config/store.ts
|
|
368
335
|
import * as fs from "node:fs";
|
|
369
|
-
import * as
|
|
336
|
+
import * as path3 from "node:path";
|
|
370
337
|
var DIR_MODE = 448;
|
|
371
338
|
var FILE_MODE = 384;
|
|
372
339
|
function ensureConfigDir(configDir) {
|
|
@@ -403,7 +370,7 @@ function loadConfig(overrideDir) {
|
|
|
403
370
|
}
|
|
404
371
|
function saveConfig(config2, overrideDir) {
|
|
405
372
|
const configDir = getConfigDir(overrideDir);
|
|
406
|
-
const configPath =
|
|
373
|
+
const configPath = path3.join(configDir, "config.json");
|
|
407
374
|
ensureConfigDir(configDir);
|
|
408
375
|
const json = JSON.stringify(config2, null, 2) + "\n";
|
|
409
376
|
fs.writeFileSync(configPath, json, { mode: FILE_MODE });
|
|
@@ -600,23 +567,23 @@ function authLogout(opts = {}) {
|
|
|
600
567
|
|
|
601
568
|
// src/commands/init.ts
|
|
602
569
|
import * as fs4 from "node:fs";
|
|
603
|
-
import * as
|
|
570
|
+
import * as path6 from "node:path";
|
|
604
571
|
import * as readline2 from "node:readline";
|
|
605
572
|
|
|
606
573
|
// src/config/docs-config.ts
|
|
607
574
|
import * as fs3 from "node:fs";
|
|
608
|
-
import * as
|
|
575
|
+
import * as path5 from "node:path";
|
|
609
576
|
import YAML from "yaml";
|
|
610
577
|
|
|
611
578
|
// src/renderer/navigation.ts
|
|
612
579
|
import * as fs2 from "node:fs";
|
|
613
|
-
import * as
|
|
580
|
+
import * as path4 from "node:path";
|
|
614
581
|
function extractTitle(markdownContent, filePath) {
|
|
615
582
|
const match2 = markdownContent.match(/^#\s+(.+)$/m);
|
|
616
583
|
if (match2) {
|
|
617
584
|
return match2[1].trim();
|
|
618
585
|
}
|
|
619
|
-
const basename3 =
|
|
586
|
+
const basename3 = path4.basename(filePath, ".md");
|
|
620
587
|
if (basename3 === "index") {
|
|
621
588
|
return "Home";
|
|
622
589
|
}
|
|
@@ -627,11 +594,11 @@ function findMarkdownFiles(dir, relativeTo) {
|
|
|
627
594
|
if (!fs2.existsSync(dir)) return results;
|
|
628
595
|
const entries = fs2.readdirSync(dir, { withFileTypes: true });
|
|
629
596
|
for (const entry of entries) {
|
|
630
|
-
const fullPath =
|
|
597
|
+
const fullPath = path4.join(dir, entry.name);
|
|
631
598
|
if (entry.isDirectory()) {
|
|
632
599
|
results.push(...findMarkdownFiles(fullPath, relativeTo));
|
|
633
600
|
} else if (entry.isFile() && entry.name.endsWith(".md")) {
|
|
634
|
-
results.push(
|
|
601
|
+
results.push(path4.relative(relativeTo, fullPath).replace(/\\/g, "/"));
|
|
635
602
|
}
|
|
636
603
|
}
|
|
637
604
|
return results;
|
|
@@ -654,7 +621,7 @@ function mdPathToHref(filePath) {
|
|
|
654
621
|
return `${withoutExt}/`;
|
|
655
622
|
}
|
|
656
623
|
function navEntryFromFile(contentDir, file) {
|
|
657
|
-
const fullPath =
|
|
624
|
+
const fullPath = path4.join(contentDir, file);
|
|
658
625
|
const content = fs2.readFileSync(fullPath, "utf-8");
|
|
659
626
|
return {
|
|
660
627
|
title: extractTitle(content, file),
|
|
@@ -670,7 +637,7 @@ function groupNavEntriesByFolders(files, contentDir, indexPath = "index.md") {
|
|
|
670
637
|
const rootLinks = [];
|
|
671
638
|
const byFolder = /* @__PURE__ */ new Map();
|
|
672
639
|
for (const file of sorted) {
|
|
673
|
-
const dir =
|
|
640
|
+
const dir = path4.dirname(file).replace(/\\/g, "/");
|
|
674
641
|
if (dir === ".") {
|
|
675
642
|
rootLinks.push(navEntryFromFile(contentDir, file));
|
|
676
643
|
continue;
|
|
@@ -719,7 +686,7 @@ function navConfigToNavItems(entries, contentDir) {
|
|
|
719
686
|
throw new Error("Nav has no pages (entries need path or nested children with paths)");
|
|
720
687
|
}
|
|
721
688
|
for (const item of items) {
|
|
722
|
-
const full =
|
|
689
|
+
const full = path4.join(contentDir, item.path);
|
|
723
690
|
if (!fs2.existsSync(full)) {
|
|
724
691
|
throw new Error(`Nav path not found: ${item.path}`);
|
|
725
692
|
}
|
|
@@ -764,7 +731,7 @@ function flattenNavPaths(entries) {
|
|
|
764
731
|
|
|
765
732
|
// src/config/docs-config.ts
|
|
766
733
|
function loadDocsConfig(docsDir) {
|
|
767
|
-
const configPath =
|
|
734
|
+
const configPath = path5.resolve(docsDir, "nrdocs.yml");
|
|
768
735
|
if (!fs3.existsSync(configPath)) {
|
|
769
736
|
throw new Error(`Config file not found: ${configPath}`);
|
|
770
737
|
}
|
|
@@ -774,7 +741,7 @@ function loadDocsConfig(docsDir) {
|
|
|
774
741
|
throw new Error(`Invalid config: ${configPath}`);
|
|
775
742
|
}
|
|
776
743
|
const sourceDir = config2.content?.source_dir ?? ".";
|
|
777
|
-
const contentDir =
|
|
744
|
+
const contentDir = path5.resolve(docsDir, sourceDir);
|
|
778
745
|
return { config: config2, configPath, contentDir };
|
|
779
746
|
}
|
|
780
747
|
function hasExplicitNav(config2) {
|
|
@@ -830,7 +797,7 @@ function validateNavPaths(entries, contentDir) {
|
|
|
830
797
|
errors.push(`Duplicate nav path: ${p}`);
|
|
831
798
|
}
|
|
832
799
|
seen.add(p);
|
|
833
|
-
const full =
|
|
800
|
+
const full = path5.join(contentDir, p);
|
|
834
801
|
if (!fs3.existsSync(full)) {
|
|
835
802
|
errors.push(`Nav path not found: ${p}`);
|
|
836
803
|
}
|
|
@@ -1011,11 +978,11 @@ async function handleInit(args2) {
|
|
|
1011
978
|
process.exit(2);
|
|
1012
979
|
}
|
|
1013
980
|
const docsDir = opts.docsDir || "docs";
|
|
1014
|
-
const docsPath =
|
|
1015
|
-
const configFile =
|
|
981
|
+
const docsPath = path6.resolve(docsDir);
|
|
982
|
+
const configFile = path6.join(docsPath, "nrdocs.yml");
|
|
1016
983
|
const existing = readExistingConfig(configFile);
|
|
1017
984
|
const configExists = fs4.existsSync(configFile);
|
|
1018
|
-
const dirName =
|
|
985
|
+
const dirName = path6.basename(process.cwd());
|
|
1019
986
|
let title = opts.title || existing.title;
|
|
1020
987
|
if (!title) {
|
|
1021
988
|
title = await prompt2("Site title", `${dirName} Docs`);
|
|
@@ -1048,8 +1015,8 @@ async function handleInit(args2) {
|
|
|
1048
1015
|
process.exit(2);
|
|
1049
1016
|
}
|
|
1050
1017
|
apiUrl = normalizeUrl(apiUrl);
|
|
1051
|
-
const workflowDir =
|
|
1052
|
-
const workflowFile =
|
|
1018
|
+
const workflowDir = path6.resolve(".github", "workflows");
|
|
1019
|
+
const workflowFile = path6.join(workflowDir, "nrdocs.yml");
|
|
1053
1020
|
if (!opts.force && fs4.existsSync(workflowFile)) {
|
|
1054
1021
|
console.error("Error: Workflow already exists:");
|
|
1055
1022
|
console.error(` ${workflowFile}`);
|
|
@@ -1071,12 +1038,12 @@ async function handleInit(args2) {
|
|
|
1071
1038
|
console.log("");
|
|
1072
1039
|
console.log("Created/updated:");
|
|
1073
1040
|
if (createdConfig) {
|
|
1074
|
-
console.log(` ${
|
|
1041
|
+
console.log(` ${path6.relative(process.cwd(), configFile)}`);
|
|
1075
1042
|
}
|
|
1076
|
-
console.log(` ${
|
|
1043
|
+
console.log(` ${path6.relative(process.cwd(), workflowFile)}`);
|
|
1077
1044
|
if (!createdConfig) {
|
|
1078
1045
|
console.log("");
|
|
1079
|
-
console.log(`Using existing: ${
|
|
1046
|
+
console.log(`Using existing: ${path6.relative(process.cwd(), configFile)}`);
|
|
1080
1047
|
}
|
|
1081
1048
|
if (navPageCount > 0) {
|
|
1082
1049
|
console.log(` content.nav: ${navPageCount} page(s) from markdown under ${docsDir}/`);
|
|
@@ -1086,7 +1053,7 @@ async function handleInit(args2) {
|
|
|
1086
1053
|
if (navPageCount === 0) {
|
|
1087
1054
|
console.log(` 1. Add markdown files under ${docsDir}/, then run: nrdocs nav generate`);
|
|
1088
1055
|
} else {
|
|
1089
|
-
console.log(` 1. Edit content.nav in ${
|
|
1056
|
+
console.log(` 1. Edit content.nav in ${path6.relative(process.cwd(), configFile)} to reorder pages`);
|
|
1090
1057
|
}
|
|
1091
1058
|
console.log(" 2. Commit and push to trigger the workflow");
|
|
1092
1059
|
console.log(" 3. Ask your operator to approve the repo");
|
|
@@ -1097,7 +1064,7 @@ import * as fs8 from "node:fs";
|
|
|
1097
1064
|
|
|
1098
1065
|
// src/renderer/index.ts
|
|
1099
1066
|
import * as fs7 from "node:fs";
|
|
1100
|
-
import * as
|
|
1067
|
+
import * as path9 from "node:path";
|
|
1101
1068
|
|
|
1102
1069
|
// ../../node_modules/.pnpm/markdown-it@14.1.1/node_modules/markdown-it/lib/common/utils.mjs
|
|
1103
1070
|
var utils_exports = {};
|
|
@@ -6588,9 +6555,63 @@ function escapeHtml2(str) {
|
|
|
6588
6555
|
|
|
6589
6556
|
// src/renderer/assets.ts
|
|
6590
6557
|
import * as fs5 from "node:fs";
|
|
6591
|
-
import * as
|
|
6558
|
+
import * as path7 from "node:path";
|
|
6559
|
+
|
|
6560
|
+
// ../shared/dist/constants.js
|
|
6561
|
+
var ALLOWED_ASSET_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
6562
|
+
".html",
|
|
6563
|
+
".css",
|
|
6564
|
+
".json",
|
|
6565
|
+
".svg",
|
|
6566
|
+
".png",
|
|
6567
|
+
".jpg",
|
|
6568
|
+
".jpeg",
|
|
6569
|
+
".gif",
|
|
6570
|
+
".webp",
|
|
6571
|
+
".ico",
|
|
6572
|
+
".txt",
|
|
6573
|
+
".pdf"
|
|
6574
|
+
]);
|
|
6575
|
+
var REJECTED_EXTENSIONS = /* @__PURE__ */ new Set([".js", ".mjs", ".cjs"]);
|
|
6576
|
+
|
|
6577
|
+
// ../shared/dist/naming.js
|
|
6578
|
+
var INSTANCE_NAME_REGEX = /^[a-z0-9]([a-z0-9-]{0,18}[a-z0-9])?$/;
|
|
6579
|
+
var MAX_INSTANCE_LENGTH = 20;
|
|
6580
|
+
function validateInstanceName(name) {
|
|
6581
|
+
if (!name) {
|
|
6582
|
+
return { valid: false, error: "Instance name cannot be empty" };
|
|
6583
|
+
}
|
|
6584
|
+
if (name.length > MAX_INSTANCE_LENGTH) {
|
|
6585
|
+
return { valid: false, error: `Instance name must be ${MAX_INSTANCE_LENGTH} characters or fewer` };
|
|
6586
|
+
}
|
|
6587
|
+
if (!INSTANCE_NAME_REGEX.test(name)) {
|
|
6588
|
+
return {
|
|
6589
|
+
valid: false,
|
|
6590
|
+
error: "Instance name must be lowercase alphanumeric with hyphens, cannot start or end with a hyphen"
|
|
6591
|
+
};
|
|
6592
|
+
}
|
|
6593
|
+
return { valid: true };
|
|
6594
|
+
}
|
|
6595
|
+
function getWorkerName(instance) {
|
|
6596
|
+
return `nrdocs-${instance}`;
|
|
6597
|
+
}
|
|
6598
|
+
function getD1Name(instance) {
|
|
6599
|
+
return `nrdocs-${instance}-db`;
|
|
6600
|
+
}
|
|
6601
|
+
function getR2BucketName(instance) {
|
|
6602
|
+
return `nrdocs-${instance}-artifacts`;
|
|
6603
|
+
}
|
|
6604
|
+
function getResourceNames(instance) {
|
|
6605
|
+
return {
|
|
6606
|
+
worker: getWorkerName(instance),
|
|
6607
|
+
d1: getD1Name(instance),
|
|
6608
|
+
r2: getR2BucketName(instance)
|
|
6609
|
+
};
|
|
6610
|
+
}
|
|
6611
|
+
|
|
6612
|
+
// src/renderer/assets.ts
|
|
6592
6613
|
function collectAssets(docsDir) {
|
|
6593
|
-
const resolvedDocsDir =
|
|
6614
|
+
const resolvedDocsDir = path7.resolve(docsDir);
|
|
6594
6615
|
const files = [];
|
|
6595
6616
|
collectFromDir(resolvedDocsDir, resolvedDocsDir, files);
|
|
6596
6617
|
return files;
|
|
@@ -6603,8 +6624,8 @@ function collectFromDir(dir, rootDir, results) {
|
|
|
6603
6624
|
return;
|
|
6604
6625
|
}
|
|
6605
6626
|
for (const entry of entries) {
|
|
6606
|
-
const fullPath =
|
|
6607
|
-
const resolved =
|
|
6627
|
+
const fullPath = path7.join(dir, entry.name);
|
|
6628
|
+
const resolved = path7.resolve(fullPath);
|
|
6608
6629
|
if (!resolved.startsWith(rootDir)) {
|
|
6609
6630
|
continue;
|
|
6610
6631
|
}
|
|
@@ -6612,11 +6633,11 @@ function collectFromDir(dir, rootDir, results) {
|
|
|
6612
6633
|
if (entry.name.startsWith(".")) continue;
|
|
6613
6634
|
collectFromDir(fullPath, rootDir, results);
|
|
6614
6635
|
} else if (entry.isFile()) {
|
|
6615
|
-
const ext =
|
|
6636
|
+
const ext = path7.extname(entry.name).toLowerCase();
|
|
6616
6637
|
if (ext === ".md") continue;
|
|
6617
6638
|
if (REJECTED_EXTENSIONS.has(ext)) continue;
|
|
6618
6639
|
if (!ALLOWED_ASSET_EXTENSIONS.has(ext)) continue;
|
|
6619
|
-
const relativePath =
|
|
6640
|
+
const relativePath = path7.relative(rootDir, fullPath);
|
|
6620
6641
|
if (relativePath.includes("..")) continue;
|
|
6621
6642
|
results.push({
|
|
6622
6643
|
path: relativePath.replace(/\\/g, "/"),
|
|
@@ -6628,15 +6649,15 @@ function collectFromDir(dir, rootDir, results) {
|
|
|
6628
6649
|
|
|
6629
6650
|
// src/renderer/mermaid-runtime.ts
|
|
6630
6651
|
import * as fs6 from "node:fs";
|
|
6631
|
-
import * as
|
|
6632
|
-
import { fileURLToPath } from "node:url";
|
|
6633
|
-
var __dirname =
|
|
6652
|
+
import * as path8 from "node:path";
|
|
6653
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
6654
|
+
var __dirname = path8.dirname(fileURLToPath2(import.meta.url));
|
|
6634
6655
|
var MERMAID_RUNTIME_REL = "runtime/mermaid.min.js";
|
|
6635
6656
|
var MERMAID_ARTIFACT_PATH = "_nrdocs/mermaid.min.js";
|
|
6636
6657
|
function mermaidRuntimeCandidates() {
|
|
6637
6658
|
return [
|
|
6638
|
-
|
|
6639
|
-
|
|
6659
|
+
path8.join(__dirname, MERMAID_RUNTIME_REL),
|
|
6660
|
+
path8.join(__dirname, "../../dist/runtime/mermaid.min.js")
|
|
6640
6661
|
];
|
|
6641
6662
|
}
|
|
6642
6663
|
function loadMermaidRuntime() {
|
|
@@ -6671,18 +6692,18 @@ function resolveNav(resolvedDocsDir, nav, indexPath) {
|
|
|
6671
6692
|
}
|
|
6672
6693
|
async function renderSite(options) {
|
|
6673
6694
|
const { docsDir, siteTitle, baseUrl, owner, repo, nav, indexPath = "index.md" } = options;
|
|
6674
|
-
const resolvedDocsDir =
|
|
6695
|
+
const resolvedDocsDir = path9.resolve(docsDir);
|
|
6675
6696
|
const { items: navItems, sidebarConfig } = resolveNav(resolvedDocsDir, nav, indexPath);
|
|
6676
6697
|
const siteBase = `/${owner}/${repo}/`;
|
|
6677
6698
|
const renderedFiles = [];
|
|
6678
6699
|
let siteHasMermaid = false;
|
|
6679
6700
|
for (const navItem of navItems) {
|
|
6680
|
-
const filePath =
|
|
6701
|
+
const filePath = path9.join(resolvedDocsDir, navItem.path);
|
|
6681
6702
|
const markdownContent = fs7.readFileSync(filePath, "utf-8");
|
|
6682
6703
|
const pageHasMermaid = contentHasMermaid(markdownContent);
|
|
6683
6704
|
if (pageHasMermaid) siteHasMermaid = true;
|
|
6684
6705
|
let html = renderMarkdown(markdownContent);
|
|
6685
|
-
const fileDir =
|
|
6706
|
+
const fileDir = path9.dirname(navItem.path);
|
|
6686
6707
|
const baseLinkPath = fileDir === "." ? "" : fileDir;
|
|
6687
6708
|
html = rewriteLinks(html, baseLinkPath, owner, repo);
|
|
6688
6709
|
const pageTitle = extractTitle(markdownContent, navItem.path);
|
|
@@ -6806,8 +6827,8 @@ function normalizeApiBaseUrl(url) {
|
|
|
6806
6827
|
}
|
|
6807
6828
|
function buildApiUrl(baseUrl, apiPath) {
|
|
6808
6829
|
const { url } = normalizeApiBaseUrl(baseUrl);
|
|
6809
|
-
const
|
|
6810
|
-
return `${url}${
|
|
6830
|
+
const path13 = apiPath.startsWith("/") ? apiPath : `/${apiPath}`;
|
|
6831
|
+
return `${url}${path13}`;
|
|
6811
6832
|
}
|
|
6812
6833
|
function extractFetchError(err) {
|
|
6813
6834
|
if (!(err instanceof Error)) {
|
|
@@ -6950,12 +6971,12 @@ async function probeApiStatus(baseUrl, timeoutMs = 15e3) {
|
|
|
6950
6971
|
};
|
|
6951
6972
|
}
|
|
6952
6973
|
const json = await res.json();
|
|
6953
|
-
const
|
|
6974
|
+
const version2 = json.data?.version;
|
|
6954
6975
|
return {
|
|
6955
6976
|
ok: true,
|
|
6956
6977
|
status: res.status,
|
|
6957
|
-
message:
|
|
6958
|
-
version
|
|
6978
|
+
message: version2 ? `OK (nrdocs ${version2})` : "OK",
|
|
6979
|
+
version: version2
|
|
6959
6980
|
};
|
|
6960
6981
|
} catch (e) {
|
|
6961
6982
|
clearTimeout(timer);
|
|
@@ -7055,8 +7076,8 @@ var ApiClient = class {
|
|
|
7055
7076
|
}
|
|
7056
7077
|
};
|
|
7057
7078
|
}
|
|
7058
|
-
async request(method,
|
|
7059
|
-
const url = buildApiUrl(this.baseUrl,
|
|
7079
|
+
async request(method, path13, body, timeoutMs = DEFAULT_TIMEOUT_MS) {
|
|
7080
|
+
const url = buildApiUrl(this.baseUrl, path13);
|
|
7060
7081
|
const controller = new AbortController();
|
|
7061
7082
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
7062
7083
|
const init = {
|
|
@@ -7125,8 +7146,8 @@ var ApiClient = class {
|
|
|
7125
7146
|
});
|
|
7126
7147
|
}
|
|
7127
7148
|
async setSelfPasswordAllow(owner, repo, allow) {
|
|
7128
|
-
const
|
|
7129
|
-
return this.request("POST",
|
|
7149
|
+
const path13 = allow ? `/api/repos/${owner}/${repo}/allow-self-password` : `/api/repos/${owner}/${repo}/disallow-self-password`;
|
|
7150
|
+
return this.request("POST", path13);
|
|
7130
7151
|
}
|
|
7131
7152
|
async listRules() {
|
|
7132
7153
|
return this.request("GET", "/api/auto-approval-rules");
|
|
@@ -7396,7 +7417,7 @@ async function handlePublish(args2) {
|
|
|
7396
7417
|
|
|
7397
7418
|
// src/commands/doctor.ts
|
|
7398
7419
|
import * as fs9 from "node:fs";
|
|
7399
|
-
import * as
|
|
7420
|
+
import * as path10 from "node:path";
|
|
7400
7421
|
function parseDoctorArgs(args2) {
|
|
7401
7422
|
const opts = {};
|
|
7402
7423
|
for (const arg of args2) {
|
|
@@ -7410,7 +7431,7 @@ function countMarkdownFiles(docsDir) {
|
|
|
7410
7431
|
let count = 0;
|
|
7411
7432
|
const walk = (dir) => {
|
|
7412
7433
|
for (const entry of fs9.readdirSync(dir, { withFileTypes: true })) {
|
|
7413
|
-
const full =
|
|
7434
|
+
const full = path10.join(dir, entry.name);
|
|
7414
7435
|
if (entry.isDirectory()) walk(full);
|
|
7415
7436
|
else if (entry.name.endsWith(".md")) count++;
|
|
7416
7437
|
}
|
|
@@ -7422,14 +7443,14 @@ async function handleDoctor(args2) {
|
|
|
7422
7443
|
const opts = parseDoctorArgs(args2);
|
|
7423
7444
|
const inCI = opts.ci || process.env["GITHUB_ACTIONS"] === "true";
|
|
7424
7445
|
const checks = [];
|
|
7425
|
-
const isGitRepo = fs9.existsSync(
|
|
7446
|
+
const isGitRepo = fs9.existsSync(path10.resolve(".git"));
|
|
7426
7447
|
checks.push({
|
|
7427
7448
|
section: "Repo setup",
|
|
7428
7449
|
name: "Git repository",
|
|
7429
7450
|
status: isGitRepo ? "ok" : "fail",
|
|
7430
7451
|
message: isGitRepo ? "Found .git directory" : "Not a git repository"
|
|
7431
7452
|
});
|
|
7432
|
-
const configPath =
|
|
7453
|
+
const configPath = path10.resolve("docs", "nrdocs.yml");
|
|
7433
7454
|
const hasConfig = fs9.existsSync(configPath);
|
|
7434
7455
|
checks.push({
|
|
7435
7456
|
section: "Repo setup",
|
|
@@ -7437,7 +7458,7 @@ async function handleDoctor(args2) {
|
|
|
7437
7458
|
status: hasConfig ? "ok" : "fail",
|
|
7438
7459
|
message: hasConfig ? "Found docs/nrdocs.yml" : "Missing docs/nrdocs.yml \u2014 run: nrdocs init"
|
|
7439
7460
|
});
|
|
7440
|
-
const docsDir =
|
|
7461
|
+
const docsDir = path10.resolve("docs");
|
|
7441
7462
|
const mdCount = countMarkdownFiles(docsDir);
|
|
7442
7463
|
checks.push({
|
|
7443
7464
|
section: "Repo setup",
|
|
@@ -7445,7 +7466,7 @@ async function handleDoctor(args2) {
|
|
|
7445
7466
|
status: mdCount > 0 ? "ok" : "warn",
|
|
7446
7467
|
message: mdCount > 0 ? `${mdCount} markdown file(s) in docs/` : "No .md files in docs/ \u2014 publish will produce an empty site"
|
|
7447
7468
|
});
|
|
7448
|
-
const workflowPath =
|
|
7469
|
+
const workflowPath = path10.resolve(".github", "workflows", "nrdocs.yml");
|
|
7449
7470
|
const hasWorkflow = fs9.existsSync(workflowPath);
|
|
7450
7471
|
checks.push({
|
|
7451
7472
|
section: "Repo setup",
|
|
@@ -7626,7 +7647,7 @@ async function handleDoctor(args2) {
|
|
|
7626
7647
|
|
|
7627
7648
|
// src/commands/nav.ts
|
|
7628
7649
|
import * as fs10 from "node:fs";
|
|
7629
|
-
import * as
|
|
7650
|
+
import * as path11 from "node:path";
|
|
7630
7651
|
function parseNavGenerateArgs(args2) {
|
|
7631
7652
|
const opts = {};
|
|
7632
7653
|
for (let i = 0; i < args2.length; i++) {
|
|
@@ -7645,8 +7666,8 @@ function parseNavGenerateArgs(args2) {
|
|
|
7645
7666
|
}
|
|
7646
7667
|
async function handleNavGenerate(args2) {
|
|
7647
7668
|
const opts = parseNavGenerateArgs(args2);
|
|
7648
|
-
const docsDir =
|
|
7649
|
-
const configPath =
|
|
7669
|
+
const docsDir = path11.resolve(opts.docsDir ?? "docs");
|
|
7670
|
+
const configPath = path11.join(docsDir, "nrdocs.yml");
|
|
7650
7671
|
if (!fs10.existsSync(configPath)) {
|
|
7651
7672
|
console.error(`Error: Config file not found: ${configPath}`);
|
|
7652
7673
|
console.error("Run: nrdocs init");
|
|
@@ -7680,7 +7701,7 @@ async function handleNavGenerate(args2) {
|
|
|
7680
7701
|
}
|
|
7681
7702
|
generateNavInConfig(docsDir, { generatedBy: "nrdocs nav generate", indexPath });
|
|
7682
7703
|
if (!opts.json) {
|
|
7683
|
-
console.log(`Generated navigation for ${entries.length} page(s) in ${
|
|
7704
|
+
console.log(`Generated navigation for ${entries.length} page(s) in ${path11.relative(process.cwd(), configPath)}`);
|
|
7684
7705
|
console.log("Edit the file to reorder or rename entries, then run publish.");
|
|
7685
7706
|
}
|
|
7686
7707
|
}
|
|
@@ -7689,7 +7710,7 @@ async function handleNavGenerate(args2) {
|
|
|
7689
7710
|
import * as readline3 from "node:readline";
|
|
7690
7711
|
import * as crypto from "node:crypto";
|
|
7691
7712
|
import * as fs11 from "node:fs";
|
|
7692
|
-
import * as
|
|
7713
|
+
import * as path12 from "node:path";
|
|
7693
7714
|
import { execSync } from "node:child_process";
|
|
7694
7715
|
function parseDeployArgs(args2) {
|
|
7695
7716
|
const opts = {};
|
|
@@ -7759,35 +7780,35 @@ function normalizeUrl2(url) {
|
|
|
7759
7780
|
function packagedWorkerDir() {
|
|
7760
7781
|
const cliEntry = process.argv[1];
|
|
7761
7782
|
if (!cliEntry) return null;
|
|
7762
|
-
const distDir =
|
|
7763
|
-
const dir =
|
|
7764
|
-
if (fs11.existsSync(
|
|
7783
|
+
const distDir = path12.dirname(path12.resolve(cliEntry));
|
|
7784
|
+
const dir = path12.join(distDir, "deploy-worker");
|
|
7785
|
+
if (fs11.existsSync(path12.join(dir, "index.js"))) return dir;
|
|
7765
7786
|
return null;
|
|
7766
7787
|
}
|
|
7767
7788
|
function findWorkerDir() {
|
|
7768
7789
|
const packaged = packagedWorkerDir();
|
|
7769
7790
|
if (packaged) return packaged;
|
|
7770
7791
|
const monorepoCandidates = [
|
|
7771
|
-
|
|
7772
|
-
|
|
7792
|
+
path12.resolve("packages/worker"),
|
|
7793
|
+
path12.resolve("../worker")
|
|
7773
7794
|
];
|
|
7774
7795
|
if (process.argv[1]) {
|
|
7775
|
-
const cliDir =
|
|
7776
|
-
monorepoCandidates.push(
|
|
7777
|
-
monorepoCandidates.push(
|
|
7796
|
+
const cliDir = path12.dirname(path12.resolve(process.argv[1]));
|
|
7797
|
+
monorepoCandidates.push(path12.resolve(cliDir, "../../../worker"));
|
|
7798
|
+
monorepoCandidates.push(path12.resolve(cliDir, "../../../../packages/worker"));
|
|
7778
7799
|
}
|
|
7779
7800
|
for (const candidate of monorepoCandidates) {
|
|
7780
|
-
if (fs11.existsSync(
|
|
7801
|
+
if (fs11.existsSync(path12.join(candidate, "src", "index.ts"))) {
|
|
7781
7802
|
return candidate;
|
|
7782
7803
|
}
|
|
7783
7804
|
}
|
|
7784
7805
|
return null;
|
|
7785
7806
|
}
|
|
7786
7807
|
function isDocsContentRepo(cwd) {
|
|
7787
|
-
return fs11.existsSync(
|
|
7808
|
+
return fs11.existsSync(path12.join(cwd, "docs", "nrdocs.yml")) && !fs11.existsSync(path12.join(cwd, "packages", "worker", "src", "index.ts"));
|
|
7788
7809
|
}
|
|
7789
7810
|
function workerUsesBundledEntry(workerDir) {
|
|
7790
|
-
return fs11.existsSync(
|
|
7811
|
+
return fs11.existsSync(path12.join(workerDir, "index.js"));
|
|
7791
7812
|
}
|
|
7792
7813
|
async function handleDeploy(args2) {
|
|
7793
7814
|
const opts = parseDeployArgs(args2);
|
|
@@ -7941,11 +7962,11 @@ bucket_name = "${names.r2}"
|
|
|
7941
7962
|
[vars]
|
|
7942
7963
|
BASE_URL = "${baseUrl}"
|
|
7943
7964
|
`;
|
|
7944
|
-
const wranglerPath =
|
|
7965
|
+
const wranglerPath = path12.join(workerDir, "wrangler.toml");
|
|
7945
7966
|
fs11.writeFileSync(wranglerPath, wranglerToml);
|
|
7946
7967
|
console.log("\u2705 wrangler.toml generated");
|
|
7947
7968
|
console.log("Applying D1 migrations...");
|
|
7948
|
-
const migrationsDir =
|
|
7969
|
+
const migrationsDir = path12.join(workerDir, "migrations");
|
|
7949
7970
|
if (fs11.existsSync(migrationsDir)) {
|
|
7950
7971
|
const migResult = runSilent(`npx wrangler d1 migrations apply ${names.d1} --remote --config "${wranglerPath}"`);
|
|
7951
7972
|
if (migResult.ok) {
|
|
@@ -8914,12 +8935,13 @@ function parseAuthLogoutFlags(args2) {
|
|
|
8914
8935
|
|
|
8915
8936
|
// src/bin.ts
|
|
8916
8937
|
var args = process.argv.slice(2);
|
|
8938
|
+
var version = getCliVersion();
|
|
8917
8939
|
if (args.includes("--version") || args.includes("-v")) {
|
|
8918
|
-
console.log(`nrdocs ${
|
|
8940
|
+
console.log(`nrdocs ${version}`);
|
|
8919
8941
|
process.exit(0);
|
|
8920
8942
|
}
|
|
8921
8943
|
if (args.includes("--help") || args.includes("-h") || args.length === 0) {
|
|
8922
|
-
console.log(`nrdocs ${
|
|
8944
|
+
console.log(`nrdocs ${version}
|
|
8923
8945
|
|
|
8924
8946
|
Usage:
|
|
8925
8947
|
nrdocs <command> [options]
|