23 lines
1.0 KiB
JavaScript
23 lines
1.0 KiB
JavaScript
// 打印预设 extensions 子树的结构(键 + 类型/长度),找脚本挂在哪
|
|
// 用法: node dump-ext.mjs <preset.json>
|
|
import { readFileSync } from "node:fs";
|
|
const preset = JSON.parse(readFileSync(process.argv[2], "utf8"));
|
|
function show(node, pathParts, depth) {
|
|
if (node == null || depth > 4) return;
|
|
if (Array.isArray(node)) {
|
|
console.log(pathParts.join(".") + " [数组 " + node.length + "]");
|
|
node.slice(0, 4).forEach((v, i) => show(v, [...pathParts, String(i)], depth + 1));
|
|
return;
|
|
}
|
|
if (typeof node === "object") {
|
|
for (const [k, v] of Object.entries(node)) {
|
|
const p = [...pathParts, k];
|
|
if (v == null) { console.log(p.join(".") + " = null"); continue; }
|
|
if (typeof v === "string") { console.log(p.join(".") + " = 字符串(" + v.length + ") " + JSON.stringify(v.slice(0, 60))); continue; }
|
|
if (typeof v !== "object") { console.log(p.join(".") + " = " + JSON.stringify(v)); continue; }
|
|
show(v, p, depth + 1);
|
|
}
|
|
}
|
|
}
|
|
show(preset.extensions, ["extensions"], 0);
|