dotdog 0.1.4 → 0.1.5
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/cli.js +46 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2536,6 +2536,7 @@ var source_default = chalk;
|
|
|
2536
2536
|
// src/cli.ts
|
|
2537
2537
|
import { existsSync, readdirSync, readFileSync, mkdirSync, writeFileSync } from "fs";
|
|
2538
2538
|
import { join } from "path";
|
|
2539
|
+
import { homedir } from "os";
|
|
2539
2540
|
|
|
2540
2541
|
// src/parser.ts
|
|
2541
2542
|
function parse(source) {
|
|
@@ -2893,7 +2894,13 @@ function parseInlineObject(value) {
|
|
|
2893
2894
|
}
|
|
2894
2895
|
return obj;
|
|
2895
2896
|
}
|
|
2897
|
+
|
|
2896
2898
|
// src/cli.ts
|
|
2899
|
+
function resolvePath(p) {
|
|
2900
|
+
if (p.startsWith("~"))
|
|
2901
|
+
p = join(homedir(), p.slice(1));
|
|
2902
|
+
return p.startsWith("/") ? p : join(process.cwd(), p);
|
|
2903
|
+
}
|
|
2897
2904
|
function parseSections2(markdown) {
|
|
2898
2905
|
const lines = markdown.split(`
|
|
2899
2906
|
`), sections = [];
|
|
@@ -3021,6 +3028,45 @@ ${s.length} sections`));
|
|
|
3021
3028
|
for (const sec of s)
|
|
3022
3029
|
console.log(` ${sec.heading.padEnd(30)} ${sec.content.length} chars`);
|
|
3023
3030
|
});
|
|
3031
|
+
program2.command("compile [dir]").option("-o, --output <file>").action((d = ".", opts) => {
|
|
3032
|
+
const dir = resolvePath(d);
|
|
3033
|
+
const dirs = [join(dir, "projects"), join(dir, "specs"), dir];
|
|
3034
|
+
let found = false;
|
|
3035
|
+
for (const dd of dirs) {
|
|
3036
|
+
if (!existsSync(dd))
|
|
3037
|
+
continue;
|
|
3038
|
+
const projects = readdirSync(dd, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name);
|
|
3039
|
+
for (const p of projects) {
|
|
3040
|
+
const pd = join(dd, p, "specs");
|
|
3041
|
+
if (!existsSync(pd))
|
|
3042
|
+
continue;
|
|
3043
|
+
const files = readdirSync(pd).filter((f) => f.endsWith(".dog"));
|
|
3044
|
+
const dag = { version: "1.0", project: p, compiled_at: new Date().toISOString(), nodes: [], edges: [], count: files.length };
|
|
3045
|
+
for (const f of files) {
|
|
3046
|
+
const c = readFileSync(join(pd, f), "utf-8");
|
|
3047
|
+
const secs = parseSections2(c);
|
|
3048
|
+
for (const s of secs) {
|
|
3049
|
+
if (s.heading.includes("Entity:") || s.heading.includes("Relationship:")) {
|
|
3050
|
+
const isRel = s.heading.includes("Relationship:");
|
|
3051
|
+
if (isRel) {
|
|
3052
|
+
const parts = s.heading.replace("Relationship:", "").split("→").map((x) => x.trim());
|
|
3053
|
+
dag.edges.push({ source: parts[0] || "?", target: parts[1] || "?", file: f, section: s.heading });
|
|
3054
|
+
} else {
|
|
3055
|
+
dag.nodes.push({ id: s.heading.replace("Entity:", "").trim(), file: f, chars: s.content.length });
|
|
3056
|
+
}
|
|
3057
|
+
}
|
|
3058
|
+
}
|
|
3059
|
+
}
|
|
3060
|
+
found = true;
|
|
3061
|
+
const out = opts.output || join(pd, "..", `${p}.dag`);
|
|
3062
|
+
writeFileSync(out, JSON.stringify(dag, null, 2));
|
|
3063
|
+
console.log(source_default.green(` ✓ ${out}`));
|
|
3064
|
+
console.log(source_default.gray(` ${dag.nodes.length} nodes, ${dag.edges.length} edges, ${dag.count} files`));
|
|
3065
|
+
}
|
|
3066
|
+
}
|
|
3067
|
+
if (!found)
|
|
3068
|
+
console.log(source_default.yellow("No projects found."));
|
|
3069
|
+
});
|
|
3024
3070
|
program2.parse();
|
|
3025
3071
|
export {
|
|
3026
3072
|
parseToJSON,
|