@decantr/cli 1.7.13 → 1.7.15
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.js +3 -3
- package/dist/{chunk-YSBFK43A.js → chunk-M2DFCY3N.js} +4017 -3484
- package/dist/chunk-QRQCPD3C.js +135 -0
- package/dist/{chunk-NZ4SGTDS.js → chunk-WINKQSUX.js} +2245 -651
- package/dist/{heal-MURR3RVQ.js → heal-EMT5LYVZ.js} +24 -8
- package/dist/index.js +3 -3
- package/dist/{upgrade-A3LEZKSD.js → upgrade-Q7PHW34P.js} +11 -5
- package/package.json +5 -4
- package/dist/chunk-KUDAVJOR.js +0 -46
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// src/lib/scan-interactions.ts
|
|
2
|
+
import { existsSync, readdirSync, readFileSync, statSync } from "fs";
|
|
3
|
+
import { extname, join } from "path";
|
|
4
|
+
import { verifyInteractionsInSource } from "@decantr/verifier";
|
|
5
|
+
var SCAN_EXTENSIONS = /* @__PURE__ */ new Set([".tsx", ".jsx", ".ts", ".js", ".html", ".mdx"]);
|
|
6
|
+
var SKIP_DIRECTORIES = /* @__PURE__ */ new Set([
|
|
7
|
+
"node_modules",
|
|
8
|
+
".decantr",
|
|
9
|
+
".git",
|
|
10
|
+
"dist",
|
|
11
|
+
"build",
|
|
12
|
+
".next",
|
|
13
|
+
".turbo",
|
|
14
|
+
"coverage",
|
|
15
|
+
".cache"
|
|
16
|
+
]);
|
|
17
|
+
var MAX_FILE_SIZE = 1024 * 1024;
|
|
18
|
+
function walkSourceTree(rootDir) {
|
|
19
|
+
const sources = /* @__PURE__ */ new Map();
|
|
20
|
+
function walk(dir) {
|
|
21
|
+
let entries;
|
|
22
|
+
try {
|
|
23
|
+
entries = readdirSync(dir);
|
|
24
|
+
} catch {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
for (const entry of entries) {
|
|
28
|
+
if (SKIP_DIRECTORIES.has(entry)) continue;
|
|
29
|
+
const fullPath = join(dir, entry);
|
|
30
|
+
let s;
|
|
31
|
+
try {
|
|
32
|
+
s = statSync(fullPath);
|
|
33
|
+
} catch {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (s.isDirectory()) {
|
|
37
|
+
walk(fullPath);
|
|
38
|
+
} else if (s.isFile() && SCAN_EXTENSIONS.has(extname(entry))) {
|
|
39
|
+
if (s.size > MAX_FILE_SIZE) continue;
|
|
40
|
+
try {
|
|
41
|
+
sources.set(fullPath, readFileSync(fullPath, "utf8"));
|
|
42
|
+
} catch {
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
walk(rootDir);
|
|
48
|
+
return sources;
|
|
49
|
+
}
|
|
50
|
+
function collectDeclaredInteractions(projectRoot) {
|
|
51
|
+
const manifestPath = join(projectRoot, ".decantr", "context", "pack-manifest.json");
|
|
52
|
+
if (!existsSync(manifestPath)) return [];
|
|
53
|
+
let manifest;
|
|
54
|
+
try {
|
|
55
|
+
manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
|
|
56
|
+
} catch {
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
const all = [];
|
|
60
|
+
const pages = manifest.pages ?? [];
|
|
61
|
+
const contextDir = join(projectRoot, ".decantr", "context");
|
|
62
|
+
for (const page of pages) {
|
|
63
|
+
const packPath = join(contextDir, page.json);
|
|
64
|
+
if (!existsSync(packPath)) continue;
|
|
65
|
+
let pack;
|
|
66
|
+
try {
|
|
67
|
+
pack = JSON.parse(readFileSync(packPath, "utf8"));
|
|
68
|
+
} catch {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const patterns = pack.data?.patterns ?? [];
|
|
72
|
+
for (const pat of patterns) {
|
|
73
|
+
if (Array.isArray(pat.interactions)) {
|
|
74
|
+
all.push(...pat.interactions);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return all;
|
|
79
|
+
}
|
|
80
|
+
function scanProjectInteractions(projectRoot) {
|
|
81
|
+
const declared = collectDeclaredInteractions(projectRoot);
|
|
82
|
+
if (declared.length === 0) return [];
|
|
83
|
+
const sources = walkSourceTree(projectRoot);
|
|
84
|
+
if (sources.size === 0) return [];
|
|
85
|
+
const missing = verifyInteractionsInSource(declared, sources);
|
|
86
|
+
return missing.map(({ interaction, suggestion }) => `${interaction} \u2192 ${suggestion}`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/guard-context.ts
|
|
90
|
+
import { existsSync as existsSync2, readdirSync as readdirSync2, readFileSync as readFileSync2 } from "fs";
|
|
91
|
+
import { join as join2 } from "path";
|
|
92
|
+
function loadJsonEntries(dir) {
|
|
93
|
+
if (!existsSync2(dir)) return [];
|
|
94
|
+
try {
|
|
95
|
+
return readdirSync2(dir).filter((file) => file.endsWith(".json") && file !== "index.json").map((file) => JSON.parse(readFileSync2(join2(dir, file), "utf-8")));
|
|
96
|
+
} catch {
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function buildGuardRegistryContext(projectRoot = process.cwd()) {
|
|
101
|
+
const themeRegistry = /* @__PURE__ */ new Map();
|
|
102
|
+
const patternRegistry = /* @__PURE__ */ new Map();
|
|
103
|
+
const cacheDir = join2(projectRoot, ".decantr", "cache");
|
|
104
|
+
const customDir = join2(projectRoot, ".decantr", "custom");
|
|
105
|
+
for (const data of loadJsonEntries(join2(cacheDir, "@official", "themes"))) {
|
|
106
|
+
if (typeof data.id === "string" && !themeRegistry.has(data.id)) {
|
|
107
|
+
themeRegistry.set(data.id, {
|
|
108
|
+
modes: Array.isArray(data.modes) ? data.modes.filter((mode) => typeof mode === "string") : ["light", "dark"]
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
for (const data of loadJsonEntries(join2(customDir, "themes"))) {
|
|
113
|
+
if (typeof data.id === "string") {
|
|
114
|
+
themeRegistry.set(`custom:${data.id}`, {
|
|
115
|
+
modes: Array.isArray(data.modes) ? data.modes.filter((mode) => typeof mode === "string") : ["light", "dark"]
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
for (const data of loadJsonEntries(join2(cacheDir, "@official", "patterns"))) {
|
|
120
|
+
if (typeof data.id === "string" && !patternRegistry.has(data.id)) {
|
|
121
|
+
patternRegistry.set(data.id, data);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
for (const data of loadJsonEntries(join2(customDir, "patterns"))) {
|
|
125
|
+
if (typeof data.id === "string") {
|
|
126
|
+
patternRegistry.set(data.id, data);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return { themeRegistry, patternRegistry };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export {
|
|
133
|
+
scanProjectInteractions,
|
|
134
|
+
buildGuardRegistryContext
|
|
135
|
+
};
|