dotdog 0.1.1 → 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 +47 -1
- package/package.json +4 -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) {
|
|
@@ -2895,6 +2896,11 @@ function parseInlineObject(value) {
|
|
|
2895
2896
|
}
|
|
2896
2897
|
|
|
2897
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
|
+
}
|
|
2898
2904
|
function parseSections2(markdown) {
|
|
2899
2905
|
const lines = markdown.split(`
|
|
2900
2906
|
`), sections = [];
|
|
@@ -2927,7 +2933,8 @@ function parseSections2(markdown) {
|
|
|
2927
2933
|
return sections;
|
|
2928
2934
|
}
|
|
2929
2935
|
var program2 = new Command;
|
|
2930
|
-
|
|
2936
|
+
var pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf-8"));
|
|
2937
|
+
program2.name("spec").alias("dotdog").description("The spec dog — validate, analyze, generate .dog files").version(pkg.version);
|
|
2931
2938
|
program2.command("validate [dir]").action((d = ".") => {
|
|
2932
2939
|
const dirs = [join(d, "projects"), join(d, "specs")];
|
|
2933
2940
|
let found = false;
|
|
@@ -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,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dotdog",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "The spec dog \u2014 validate, analyze, parse, and generate .dog spec genome files",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/cli.js",
|
|
@@ -29,5 +29,8 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"commander": "^15.0.0",
|
|
31
31
|
"chalk": "^5.6.0"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
32
35
|
}
|
|
33
36
|
}
|