@lunaroute/cli 0.12.0 → 0.13.0
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 +86 -11
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { Command, InvalidArgumentError, Option } from "commander";
|
|
5
5
|
|
|
6
6
|
// package.json
|
|
7
|
-
var version = "0.
|
|
7
|
+
var version = "0.13.0";
|
|
8
8
|
|
|
9
9
|
// src/login.ts
|
|
10
10
|
import { createServer } from "http";
|
|
@@ -604,18 +604,77 @@ function renderEnvBlock(exports, opts) {
|
|
|
604
604
|
}
|
|
605
605
|
|
|
606
606
|
// src/setup/apply.ts
|
|
607
|
-
function readExistingJson(path) {
|
|
608
|
-
if (!existsSync3(path)) return null;
|
|
607
|
+
function readExistingJson(path, jsonc = false) {
|
|
608
|
+
if (!existsSync3(path)) return { value: null, droppedComments: false };
|
|
609
609
|
const raw = readFileSync3(path, "utf8").trim();
|
|
610
|
-
if (raw === "") return null;
|
|
610
|
+
if (raw === "") return { value: null, droppedComments: false };
|
|
611
|
+
const scanned = jsonc ? stripJsonc(raw) : { text: raw, hadComments: false };
|
|
611
612
|
try {
|
|
612
|
-
return JSON.parse(
|
|
613
|
+
return { value: JSON.parse(scanned.text), droppedComments: scanned.hadComments };
|
|
613
614
|
} catch {
|
|
614
615
|
throw new Error(
|
|
615
|
-
`refusing to modify ${path}: it exists but is not valid JSON (malformed). Fix or remove it
|
|
616
|
+
`refusing to modify ${path}: it exists but is not valid JSON (malformed). Fix or remove it and re-run.`
|
|
616
617
|
);
|
|
617
618
|
}
|
|
618
619
|
}
|
|
620
|
+
function stripJsonc(raw) {
|
|
621
|
+
let text = "";
|
|
622
|
+
let hadComments = false;
|
|
623
|
+
let i = 0;
|
|
624
|
+
while (i < raw.length) {
|
|
625
|
+
const c = raw[i];
|
|
626
|
+
if (c === '"') {
|
|
627
|
+
text += c;
|
|
628
|
+
i++;
|
|
629
|
+
while (i < raw.length) {
|
|
630
|
+
const s = raw[i];
|
|
631
|
+
text += s;
|
|
632
|
+
i++;
|
|
633
|
+
if (s === "\\") {
|
|
634
|
+
text += raw[i] ?? "";
|
|
635
|
+
i++;
|
|
636
|
+
} else if (s === '"') break;
|
|
637
|
+
}
|
|
638
|
+
continue;
|
|
639
|
+
}
|
|
640
|
+
if (c === "/" && raw[i + 1] === "/") {
|
|
641
|
+
hadComments = true;
|
|
642
|
+
while (i < raw.length && raw[i] !== "\n") i++;
|
|
643
|
+
continue;
|
|
644
|
+
}
|
|
645
|
+
if (c === "/" && raw[i + 1] === "*") {
|
|
646
|
+
hadComments = true;
|
|
647
|
+
i += 2;
|
|
648
|
+
while (i < raw.length && !(raw[i] === "*" && raw[i + 1] === "/")) i++;
|
|
649
|
+
i += 2;
|
|
650
|
+
continue;
|
|
651
|
+
}
|
|
652
|
+
if (c === ",") {
|
|
653
|
+
let j = i + 1;
|
|
654
|
+
for (; ; ) {
|
|
655
|
+
while (j < raw.length && /\s/.test(raw[j])) j++;
|
|
656
|
+
if (raw[j] === "/" && raw[j + 1] === "/") {
|
|
657
|
+
while (j < raw.length && raw[j] !== "\n") j++;
|
|
658
|
+
continue;
|
|
659
|
+
}
|
|
660
|
+
if (raw[j] === "/" && raw[j + 1] === "*") {
|
|
661
|
+
j += 2;
|
|
662
|
+
while (j < raw.length && !(raw[j] === "*" && raw[j + 1] === "/")) j++;
|
|
663
|
+
j += 2;
|
|
664
|
+
continue;
|
|
665
|
+
}
|
|
666
|
+
break;
|
|
667
|
+
}
|
|
668
|
+
if (raw[j] === "}" || raw[j] === "]") {
|
|
669
|
+
i++;
|
|
670
|
+
continue;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
text += c;
|
|
674
|
+
i++;
|
|
675
|
+
}
|
|
676
|
+
return { text, hadComments };
|
|
677
|
+
}
|
|
619
678
|
function resolveYamlContent(fw) {
|
|
620
679
|
const curStr = existsSync3(fw.path) ? readFileSync3(fw.path, "utf8") : null;
|
|
621
680
|
const doc = parseDocument(curStr ?? "", { logLevel: "silent" });
|
|
@@ -634,20 +693,25 @@ function resolveYamlContent(fw) {
|
|
|
634
693
|
function resolveContent(fw) {
|
|
635
694
|
if (fw.kind === "text") {
|
|
636
695
|
const curStr2 = existsSync3(fw.path) ? readFileSync3(fw.path, "utf8") : null;
|
|
637
|
-
return { nextStr: fw.content, curStr: curStr2 };
|
|
696
|
+
return { nextStr: fw.content, curStr: curStr2, droppedComments: false };
|
|
638
697
|
}
|
|
639
|
-
if (fw.kind === "yaml") return resolveYamlContent(fw);
|
|
640
|
-
const existing = readExistingJson(fw.path);
|
|
698
|
+
if (fw.kind === "yaml") return { ...resolveYamlContent(fw), droppedComments: false };
|
|
699
|
+
const { value: existing, droppedComments } = readExistingJson(fw.path, fw.jsonc);
|
|
641
700
|
const curStr = existing === null ? null : `${JSON.stringify(existing, null, 2)}
|
|
642
701
|
`;
|
|
643
702
|
const nextStr = `${JSON.stringify(fw.merge(existing), null, 2)}
|
|
644
703
|
`;
|
|
645
|
-
return { nextStr, curStr };
|
|
704
|
+
return { nextStr, curStr, droppedComments };
|
|
646
705
|
}
|
|
647
706
|
async function applyPlan(plan, opts) {
|
|
648
707
|
const summary = { written: [], backedUp: [] };
|
|
649
708
|
for (const fw of plan.fileWrites) {
|
|
650
|
-
const { nextStr, curStr } = resolveContent(fw);
|
|
709
|
+
const { nextStr, curStr, droppedComments } = resolveContent(fw);
|
|
710
|
+
if (droppedComments) {
|
|
711
|
+
console.log(
|
|
712
|
+
opts.print ? `# ${fw.path}: the merged settings are plain JSON \u2014 comments are dropped` : `# ${fw.path}: comments are dropped by the rewrite${fw.backup !== false ? `; the original is kept at ${fw.path}.bak` : ""}`
|
|
713
|
+
);
|
|
714
|
+
}
|
|
651
715
|
if (opts.print) {
|
|
652
716
|
console.log(`
|
|
653
717
|
# would write ${fw.path}:
|
|
@@ -933,6 +997,8 @@ function extensionPlan(ctx) {
|
|
|
933
997
|
{
|
|
934
998
|
kind: "json",
|
|
935
999
|
path: opencodeConfigPath(),
|
|
1000
|
+
jsonc: true,
|
|
1001
|
+
// opencode documents JSONC config
|
|
936
1002
|
merge: (existing) => {
|
|
937
1003
|
const obj = existing ?? {};
|
|
938
1004
|
const raw = obj.plugin;
|
|
@@ -988,6 +1054,8 @@ function providerPlan(ctx) {
|
|
|
988
1054
|
{
|
|
989
1055
|
kind: "json",
|
|
990
1056
|
path: opencodeConfigPath(),
|
|
1057
|
+
jsonc: true,
|
|
1058
|
+
// opencode documents JSONC config
|
|
991
1059
|
merge: (existing) => {
|
|
992
1060
|
const obj = existing ?? {};
|
|
993
1061
|
const existingProviders = objectOrEmpty(obj.provider);
|
|
@@ -1445,6 +1513,11 @@ function buildPlan8(ctx) {
|
|
|
1445
1513
|
{
|
|
1446
1514
|
kind: "json",
|
|
1447
1515
|
path: openclawConfigPath(),
|
|
1516
|
+
// OpenClaw's config is JSON5 ("comments + trailing commas allowed"), so
|
|
1517
|
+
// a hand-edited file is read tolerantly.
|
|
1518
|
+
// shortcut: the JSON subset of JSON5 only — unquoted keys and single
|
|
1519
|
+
// quotes still refuse; widen it if a real openclaw.json needs it (kata tnhh).
|
|
1520
|
+
jsonc: true,
|
|
1448
1521
|
merge: (existing) => {
|
|
1449
1522
|
const obj = asRecord(existing);
|
|
1450
1523
|
const modelsCfg = asRecord(obj.models);
|
|
@@ -1697,6 +1770,8 @@ function buildPlan10(ctx) {
|
|
|
1697
1770
|
{
|
|
1698
1771
|
kind: "json",
|
|
1699
1772
|
path: zedSettingsPath(),
|
|
1773
|
+
// Zed ships settings.json as JSONC (its template header is comments).
|
|
1774
|
+
jsonc: true,
|
|
1700
1775
|
merge: (existing) => {
|
|
1701
1776
|
const obj = objectOrEmpty2(existing);
|
|
1702
1777
|
const languageModels = objectOrEmpty2(obj.language_models);
|