@specdest/devkit 0.4.6 → 0.4.8
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/README.md +34 -4
- package/dist/npm/canonical-project-operations.d.ts +5 -0
- package/dist/npm/canonical-project-operations.js +5 -0
- package/dist/npm/canonical-project.d.ts +10 -0
- package/dist/npm/canonical-project.js +109 -0
- package/dist/npm/canonical-source.d.ts +14 -0
- package/dist/npm/canonical-source.js +216 -0
- package/dist/npm/catalog-snapshot.d.ts +47 -0
- package/dist/npm/catalog-snapshot.js +28 -0
- package/dist/npm/cli.d.ts +2 -0
- package/dist/npm/cli.js +15 -0
- package/dist/npm/commands.d.ts +9 -0
- package/dist/npm/commands.js +157 -0
- package/dist/npm/flow.d.ts +48 -0
- package/dist/npm/flow.js +396 -0
- package/dist/npm/fuzz.d.ts +138 -0
- package/dist/npm/fuzz.js +327 -0
- package/dist/npm/git-catalog.d.ts +39 -0
- package/dist/npm/git-catalog.js +190 -0
- package/dist/npm/index.d.ts +5 -0
- package/dist/npm/index.js +22 -0
- package/dist/npm/installer-primitives.d.ts +3 -0
- package/dist/npm/installer-primitives.js +50 -0
- package/dist/npm/predefined-packages/abac.d.ts +2 -0
- package/dist/npm/predefined-packages/abac.js +22 -0
- package/dist/npm/predefined-packages/auth.d.ts +2 -0
- package/dist/npm/predefined-packages/auth.js +21 -0
- package/dist/npm/predefined-packages/convex.d.ts +2 -0
- package/dist/npm/predefined-packages/convex.js +53 -0
- package/dist/npm/predefined-packages/expo.d.ts +2 -0
- package/dist/npm/predefined-packages/expo.js +84 -0
- package/dist/npm/predefined-packages/firebase-hosting.d.ts +2 -0
- package/dist/npm/predefined-packages/firebase-hosting.js +24 -0
- package/dist/npm/predefined-packages/health.d.ts +10 -0
- package/dist/npm/predefined-packages/health.js +52 -0
- package/dist/npm/predefined-packages/husky.d.ts +2 -0
- package/dist/npm/predefined-packages/husky.js +57 -0
- package/dist/npm/predefined-packages/index.d.ts +11 -0
- package/dist/npm/predefined-packages/index.js +56 -0
- package/dist/npm/predefined-packages/install.d.ts +19 -0
- package/dist/npm/predefined-packages/install.js +85 -0
- package/dist/npm/predefined-packages/local-logging.d.ts +2 -0
- package/dist/npm/predefined-packages/local-logging.js +17 -0
- package/dist/npm/predefined-packages/logging.d.ts +2 -0
- package/dist/npm/predefined-packages/logging.js +21 -0
- package/dist/npm/predefined-packages/multi-tenancy.d.ts +2 -0
- package/dist/npm/predefined-packages/multi-tenancy.js +21 -0
- package/dist/npm/predefined-packages/nps.d.ts +2 -0
- package/dist/npm/predefined-packages/nps.js +32 -0
- package/dist/npm/predefined-packages/oxfmt.d.ts +2 -0
- package/dist/npm/predefined-packages/oxfmt.js +22 -0
- package/dist/npm/predefined-packages/oxlint.d.ts +2 -0
- package/dist/npm/predefined-packages/oxlint.js +35 -0
- package/dist/npm/predefined-packages/package-json.d.ts +3 -0
- package/dist/npm/predefined-packages/package-json.js +61 -0
- package/dist/npm/predefined-packages/payments.d.ts +2 -0
- package/dist/npm/predefined-packages/payments.js +31 -0
- package/dist/npm/predefined-packages/playwright.d.ts +2 -0
- package/dist/npm/predefined-packages/playwright.js +35 -0
- package/dist/npm/predefined-packages/project-signals.d.ts +4 -0
- package/dist/npm/predefined-packages/project-signals.js +39 -0
- package/dist/npm/predefined-packages/registry.d.ts +3 -0
- package/dist/npm/predefined-packages/registry.js +63 -0
- package/dist/npm/predefined-packages/resolver.d.ts +8 -0
- package/dist/npm/predefined-packages/resolver.js +35 -0
- package/dist/npm/predefined-packages/sentry.d.ts +2 -0
- package/dist/npm/predefined-packages/sentry.js +29 -0
- package/dist/npm/predefined-packages/shadcn.d.ts +2 -0
- package/dist/npm/predefined-packages/shadcn.js +23 -0
- package/dist/npm/predefined-packages/storybook.d.ts +2 -0
- package/dist/npm/predefined-packages/storybook.js +25 -0
- package/dist/npm/predefined-packages/stryker.d.ts +2 -0
- package/dist/npm/predefined-packages/stryker.js +48 -0
- package/dist/npm/predefined-packages/supabase.d.ts +2 -0
- package/dist/npm/predefined-packages/supabase.js +84 -0
- package/dist/npm/predefined-packages/tailwind.d.ts +2 -0
- package/dist/npm/predefined-packages/tailwind.js +18 -0
- package/dist/npm/predefined-packages/tanstack-form.d.ts +2 -0
- package/dist/npm/predefined-packages/tanstack-form.js +19 -0
- package/dist/npm/predefined-packages/tanstack-query.d.ts +2 -0
- package/dist/npm/predefined-packages/tanstack-query.js +15 -0
- package/dist/npm/predefined-packages/tanstack-router.d.ts +2 -0
- package/dist/npm/predefined-packages/tanstack-router.js +18 -0
- package/dist/npm/predefined-packages/types.d.ts +31 -0
- package/dist/npm/predefined-packages/types.js +1 -0
- package/dist/npm/predefined-packages/vite.d.ts +2 -0
- package/dist/npm/predefined-packages/vite.js +123 -0
- package/dist/npm/predefined-packages/vitest.d.ts +2 -0
- package/dist/npm/predefined-packages/vitest.js +20 -0
- package/dist/npm/predefined-packages/zod.d.ts +2 -0
- package/dist/npm/predefined-packages/zod.js +18 -0
- package/dist/npm/project-check.d.ts +6 -0
- package/dist/npm/project-check.js +87 -0
- package/dist/npm/project-context.d.ts +42 -0
- package/dist/npm/project-context.js +192 -0
- package/dist/npm/project-rules.d.ts +22 -0
- package/dist/npm/project-rules.js +66 -0
- package/dist/npm/project-runtime.d.ts +18 -0
- package/dist/npm/project-runtime.js +27 -0
- package/dist/npm/project-status.d.ts +32 -0
- package/dist/npm/project-status.js +56 -0
- package/dist/npm/project-sync.d.ts +7 -0
- package/dist/npm/project-sync.js +135 -0
- package/dist/npm/remote-installer.d.ts +4 -0
- package/dist/npm/remote-installer.js +312 -0
- package/dist/npm/state.d.ts +14 -0
- package/dist/npm/state.js +182 -0
- package/package.json +10 -7
- package/src/canonical-project-operations.js +0 -438
- package/src/canonical-project.js +0 -136
- package/src/canonical-source.js +0 -250
- package/src/catalog-snapshot.js +0 -39
- package/src/catalog.js +0 -117
- package/src/cli.js +0 -14
- package/src/fuzz.js +0 -291
- package/src/git-catalog.js +0 -177
- package/src/index.js +0 -36
- package/src/installer-primitives.js +0 -198
- package/src/project-operations.js +0 -189
- package/src/project-targeting.js +0 -48
- package/src/remote-installer.js +0 -479
- package/src/rule-profile.js +0 -61
- package/src/setup-requirements.js +0 -82
- package/src/shared-file.js +0 -131
- package/src/sync-core.js +0 -390
package/src/remote-installer.js
DELETED
|
@@ -1,479 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process';
|
|
2
|
-
import { createHash } from 'node:crypto';
|
|
3
|
-
import { mkdir, readFile, readdir, rename, stat, unlink, writeFile } from 'node:fs/promises';
|
|
4
|
-
import { dirname, isAbsolute, resolve, sep } from 'node:path';
|
|
5
|
-
|
|
6
|
-
import { removeMarkdownSection, resolveProjectPath, upsertMarkdownSection } from './installer-primitives.js';
|
|
7
|
-
import { formatJsonState } from './sync-core.js';
|
|
8
|
-
|
|
9
|
-
const INSTALLED_PATH = '.specdest/installed.json';
|
|
10
|
-
const STATE_PATH = '.specdest/state.json';
|
|
11
|
-
const SCRIPT_PHASES = new Set(['pre_install', 'post_install', 'pre_sync', 'post_sync', 'pre_remove', 'post_remove']);
|
|
12
|
-
const OP_TYPES = new Set(['copy_file', 'scaffold_file', 'copy_directory', 'managed_section', 'json_set', 'json_merge', 'yaml_set', 'yaml_merge', 'env_set', 'env_remove', 'delete_owned_artifact', 'run_custom_script', 'run_script_file']);
|
|
13
|
-
const clone = (value) => value === undefined ? undefined : JSON.parse(JSON.stringify(value));
|
|
14
|
-
const hash = (value) => createHash('sha256').update(typeof value === 'string' ? value : JSON.stringify(value)).digest('hex');
|
|
15
|
-
const hasOwn = (object, key) => Object.prototype.hasOwnProperty.call(object, key);
|
|
16
|
-
|
|
17
|
-
function payloadPath(payloadRoot, relativePath) {
|
|
18
|
-
if (!relativePath || isAbsolute(relativePath)) throw new Error(`Source must be payload-relative: ${relativePath}`);
|
|
19
|
-
const root = resolve(payloadRoot);
|
|
20
|
-
const target = resolve(root, relativePath);
|
|
21
|
-
if (target !== root && !target.startsWith(`${root}${sep}`)) throw new Error(`Source escapes payload: ${relativePath}`);
|
|
22
|
-
return target;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async function exists(path) {
|
|
26
|
-
try { await stat(path); return true; } catch (error) { if (error?.code === 'ENOENT') return false; throw error; }
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async function readJsonState(root, relativePath, fallback, label) {
|
|
30
|
-
try {
|
|
31
|
-
const parsed = JSON.parse(await readFile(resolveProjectPath(root, relativePath), 'utf8'));
|
|
32
|
-
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) throw new Error(`Invalid ${label} state`);
|
|
33
|
-
return parsed;
|
|
34
|
-
} catch (error) {
|
|
35
|
-
if (error?.code === 'ENOENT') return clone(fallback);
|
|
36
|
-
throw error;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async function writeJsonState(root, relativePath, state) {
|
|
41
|
-
const target = resolveProjectPath(root, relativePath);
|
|
42
|
-
await mkdir(dirname(target), { recursive: true });
|
|
43
|
-
const temp = `${target}.${process.pid}.tmp`;
|
|
44
|
-
await writeFile(temp, formatJsonState(state), 'utf8');
|
|
45
|
-
await rename(temp, target);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async function readInstalledState(root) {
|
|
49
|
-
const state = await readJsonState(root, INSTALLED_PATH, { schemaVersion: 2, requested: [], installed: {} }, 'installed');
|
|
50
|
-
if (!state.installed || typeof state.installed !== 'object' || Array.isArray(state.installed)) throw new Error('Invalid installed state');
|
|
51
|
-
if (!Array.isArray(state.requested)) state.requested = [];
|
|
52
|
-
return state;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async function readRuntimeState(root) {
|
|
56
|
-
const state = await readJsonState(root, STATE_PATH, { schemaVersion: 2, results: {}, ownership: {} }, 'runtime');
|
|
57
|
-
if (!state.results || typeof state.results !== 'object' || Array.isArray(state.results)) state.results = {};
|
|
58
|
-
if (!state.ownership || typeof state.ownership !== 'object' || Array.isArray(state.ownership)) state.ownership = {};
|
|
59
|
-
return state;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const checkerSkillIds = new Map([
|
|
63
|
-
['abac-permissions-convex', 'abac-permissions'],
|
|
64
|
-
['abac-permissions-supabase', 'abac-permissions'],
|
|
65
|
-
['unit-test-rules-convex', 'unit-test-rules'],
|
|
66
|
-
['unit-test-rules-supabase', 'unit-test-rules'],
|
|
67
|
-
]);
|
|
68
|
-
|
|
69
|
-
function checkerSkillId(implementation) {
|
|
70
|
-
return checkerSkillIds.get(implementation) ?? implementation;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function normalizeManifest(manifest) {
|
|
74
|
-
const operations = Array.isArray(manifest?.operations) ? [...manifest.operations] : [];
|
|
75
|
-
const checkerImplementation = String(manifest?.checker?.implementation ?? "").trim();
|
|
76
|
-
const check = manifest?.check ?? (checkerImplementation
|
|
77
|
-
? { command: ["node", `.agents/skills/${checkerSkillId(checkerImplementation)}/check.ts`] }
|
|
78
|
-
: undefined);
|
|
79
|
-
for (const copy of manifest?.copies ?? []) {
|
|
80
|
-
operations.push({
|
|
81
|
-
type: copy.type === 'directory' || copy.directory === true ? 'copy_directory' : copy.mode === 'scaffold' || copy.mode === 'create-only' ? 'scaffold_file' : 'copy_file',
|
|
82
|
-
source: copy.source,
|
|
83
|
-
path: copy.target ?? copy.path,
|
|
84
|
-
mode: copy.mode,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
for (const section of manifest?.markdownSections ?? []) {
|
|
88
|
-
operations.push({ type: 'managed_section', path: section.path, heading: section.heading, content: section.body ?? section.content ?? '' });
|
|
89
|
-
}
|
|
90
|
-
return { ...manifest, operations, ...(check ? { check } : {}) };
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export function validateRemoteManifest(input) {
|
|
94
|
-
if (!input || typeof input !== 'object' || !String(input.id ?? '').trim()) throw new Error('Manifest id is required');
|
|
95
|
-
const manifest = normalizeManifest(input);
|
|
96
|
-
if (!Array.isArray(manifest.operations)) throw new Error(`Manifest operations must be an array: ${manifest.id}`);
|
|
97
|
-
for (const op of manifest.operations) {
|
|
98
|
-
if (!OP_TYPES.has(op?.type)) throw new Error(`Unsupported manifest operation: ${op?.type}`);
|
|
99
|
-
if (op.type.startsWith('run_')) {
|
|
100
|
-
if (!SCRIPT_PHASES.has(op.phase)) throw new Error(`Script operation must declare a valid lifecycle phase: ${op.type}`);
|
|
101
|
-
} else if (op.path) resolveProjectPath('/__specdest_project__', op.path);
|
|
102
|
-
}
|
|
103
|
-
return manifest;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function getAt(root, keyPath) {
|
|
107
|
-
let current = root;
|
|
108
|
-
for (const key of keyPath) {
|
|
109
|
-
if (!current || typeof current !== 'object' || Array.isArray(current) || !hasOwn(current, key)) return { exists: false, value: undefined };
|
|
110
|
-
current = current[key];
|
|
111
|
-
}
|
|
112
|
-
return { exists: true, value: current };
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function setAt(root, keyPath, value) {
|
|
116
|
-
let current = root;
|
|
117
|
-
for (const key of keyPath.slice(0, -1)) {
|
|
118
|
-
if (!hasOwn(current, key)) current[key] = {};
|
|
119
|
-
if (!current[key] || typeof current[key] !== 'object' || Array.isArray(current[key])) throw new Error(`Cannot set nested key through non-object: ${keyPath.join('.')}`);
|
|
120
|
-
current = current[key];
|
|
121
|
-
}
|
|
122
|
-
current[keyPath.at(-1)] = clone(value);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function deleteAt(root, keyPath) {
|
|
126
|
-
let current = root;
|
|
127
|
-
for (const key of keyPath.slice(0, -1)) {
|
|
128
|
-
if (!current || typeof current !== 'object' || !hasOwn(current, key)) return;
|
|
129
|
-
current = current[key];
|
|
130
|
-
}
|
|
131
|
-
if (current && typeof current === 'object') delete current[keyPath.at(-1)];
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function leaves(value, prefix = []) {
|
|
135
|
-
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
136
|
-
return Object.entries(value).flatMap(([key, nested]) => leaves(nested, [...prefix, key]));
|
|
137
|
-
}
|
|
138
|
-
return [[prefix, value]];
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function scalarFromYaml(raw) {
|
|
142
|
-
const value = raw.trim();
|
|
143
|
-
if (value === 'true') return true;
|
|
144
|
-
if (value === 'false') return false;
|
|
145
|
-
if (value === 'null' || value === '~') return null;
|
|
146
|
-
if (/^-?\d+(\.\d+)?$/u.test(value)) return Number(value);
|
|
147
|
-
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) return value.slice(1, -1);
|
|
148
|
-
return value;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function parseYaml(text) {
|
|
152
|
-
const root = {};
|
|
153
|
-
const stack = [{ indent: -1, object: root }];
|
|
154
|
-
for (const raw of text.replace(/\r\n/g, '\n').split('\n')) {
|
|
155
|
-
if (!raw.trim() || raw.trimStart().startsWith('#')) continue;
|
|
156
|
-
const indent = raw.match(/^ */u)?.[0].length ?? 0;
|
|
157
|
-
const match = raw.trim().match(/^([^:#][^:]*):(?:\s*(.*))?$/u);
|
|
158
|
-
if (!match) throw new Error(`Unsupported YAML syntax: ${raw.trim()}`);
|
|
159
|
-
while (stack.length > 1 && indent <= stack.at(-1).indent) stack.pop();
|
|
160
|
-
const object = stack.at(-1).object;
|
|
161
|
-
const key = match[1].trim();
|
|
162
|
-
const rest = match[2] ?? '';
|
|
163
|
-
if (!rest) {
|
|
164
|
-
object[key] = {};
|
|
165
|
-
stack.push({ indent, object: object[key] });
|
|
166
|
-
} else object[key] = scalarFromYaml(rest);
|
|
167
|
-
}
|
|
168
|
-
return root;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function yamlScalar(value) {
|
|
172
|
-
if (value === null) return 'null';
|
|
173
|
-
if (typeof value === 'boolean' || typeof value === 'number') return String(value);
|
|
174
|
-
const text = String(value);
|
|
175
|
-
return /^[A-Za-z0-9_./@-]+$/u.test(text) ? text : JSON.stringify(text);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function stringifyYaml(object, indent = 0) {
|
|
179
|
-
const lines = [];
|
|
180
|
-
for (const [key, value] of Object.entries(object)) {
|
|
181
|
-
const prefix = ' '.repeat(indent);
|
|
182
|
-
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
183
|
-
lines.push(`${prefix}${key}:`);
|
|
184
|
-
lines.push(stringifyYaml(value, indent + 2).trimEnd());
|
|
185
|
-
} else if (Array.isArray(value)) {
|
|
186
|
-
lines.push(`${prefix}${key}: ${JSON.stringify(value)}`);
|
|
187
|
-
} else lines.push(`${prefix}${key}: ${yamlScalar(value)}`);
|
|
188
|
-
}
|
|
189
|
-
return `${lines.filter(Boolean).join('\n')}\n`;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
function envMap(text) {
|
|
193
|
-
const map = new Map();
|
|
194
|
-
for (const line of text.replace(/\r\n/g, '\n').split('\n')) {
|
|
195
|
-
const match = line.match(/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/u);
|
|
196
|
-
if (match) map.set(match[1], match[2]);
|
|
197
|
-
}
|
|
198
|
-
return map;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
function setEnv(text, key, value) {
|
|
202
|
-
const lines = text.replace(/\r\n/g, '\n').split('\n').filter((line) => !new RegExp(`^${key}=`).test(line));
|
|
203
|
-
while (lines.length && lines.at(-1) === '') lines.pop();
|
|
204
|
-
lines.push(`${key}=${value}`);
|
|
205
|
-
return `${lines.join('\n')}\n`;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
function removeEnv(text, key) {
|
|
209
|
-
const lines = text.replace(/\r\n/g, '\n').split('\n').filter((line) => !new RegExp(`^${key}=`).test(line));
|
|
210
|
-
while (lines.length && lines.at(-1) === '') lines.pop();
|
|
211
|
-
return lines.length ? `${lines.join('\n')}\n` : '';
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
function markdownSection(text, heading) {
|
|
215
|
-
const lines = text.split(/(?<=\n)/u);
|
|
216
|
-
const level = heading.trim().match(/^(#{1,6})\s/u)?.[1].length ?? 2;
|
|
217
|
-
let start = -1; let end = text.length; let offset = 0;
|
|
218
|
-
for (const line of lines) {
|
|
219
|
-
if (start < 0 && line.trim() === heading.trim()) start = offset;
|
|
220
|
-
else if (start >= 0 && new RegExp(`^#{1,${level}}\\s+`).test(line.trim())) { end = offset; break; }
|
|
221
|
-
offset += line.length;
|
|
222
|
-
}
|
|
223
|
-
return start < 0 ? { exists: false, value: '' } : { exists: true, value: text.slice(start, end).trimEnd() };
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
function ownershipKey(type, path, scope = '') { return `${type}:${path}${scope ? `:${scope}` : ''}`; }
|
|
227
|
-
function fingerprint(found) { return hash({ exists: found.exists, value: found.value }); }
|
|
228
|
-
function assertFingerprint(record, current, label) {
|
|
229
|
-
if (record.appliedHash !== fingerprint(current)) throw new Error(`Conflict: user-modified owned content at ${label}`);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
async function writeText(root, path, content) {
|
|
233
|
-
const target = resolveProjectPath(root, path);
|
|
234
|
-
await mkdir(dirname(target), { recursive: true });
|
|
235
|
-
await writeFile(target, content, 'utf8');
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
async function readText(root, path) {
|
|
239
|
-
const target = resolveProjectPath(root, path);
|
|
240
|
-
return await exists(target) ? await readFile(target, 'utf8') : '';
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
async function executeHook(op, { projectRoot, payloadRoot, executor }) {
|
|
244
|
-
const cwd = op.cwd ? resolveProjectPath(projectRoot, op.cwd) : projectRoot;
|
|
245
|
-
let command; let args;
|
|
246
|
-
if (op.type === 'run_custom_script') {
|
|
247
|
-
command = op.command;
|
|
248
|
-
args = op.args ?? [];
|
|
249
|
-
} else {
|
|
250
|
-
const source = payloadPath(payloadRoot, op.source);
|
|
251
|
-
command = op.command ?? source;
|
|
252
|
-
args = op.command ? [source, ...(op.args ?? [])] : (op.args ?? []);
|
|
253
|
-
}
|
|
254
|
-
if (!String(command ?? '').trim()) throw new Error(`Script command is required: ${op.type}`);
|
|
255
|
-
const run = executor ?? ((cmd, argv, options) => new Promise((resolveRun, reject) => {
|
|
256
|
-
const child = spawn(cmd, argv, { cwd: options.cwd, stdio: 'inherit', shell: false });
|
|
257
|
-
child.on('error', reject);
|
|
258
|
-
child.on('close', (code) => resolveRun(code ?? 1));
|
|
259
|
-
}));
|
|
260
|
-
const code = await run(command, args, { cwd });
|
|
261
|
-
if (code !== 0) throw new Error(`${op.type} exited with code ${code}`);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
async function runPhase(manifest, phase, context) {
|
|
265
|
-
for (const op of manifest.operations) if (op.type.startsWith('run_') && op.phase === phase) await executeHook(op, context);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
async function currentForRecord(root, record) {
|
|
269
|
-
if (record.type === 'file') {
|
|
270
|
-
const target = resolveProjectPath(root, record.path);
|
|
271
|
-
return await exists(target) ? { exists: true, value: await readFile(target, 'utf8') } : { exists: false, value: undefined };
|
|
272
|
-
}
|
|
273
|
-
const text = await readText(root, record.path);
|
|
274
|
-
if (record.type === 'markdown') return markdownSection(text, record.heading);
|
|
275
|
-
if (record.type === 'env') {
|
|
276
|
-
const map = envMap(text);
|
|
277
|
-
return { exists: map.has(record.key), value: map.get(record.key) };
|
|
278
|
-
}
|
|
279
|
-
const object = record.type === 'json' ? (text.trim() ? JSON.parse(text) : {}) : parseYaml(text);
|
|
280
|
-
return getAt(object, record.keyPath);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
async function restoreRecord(root, record, { deleteInstead = false } = {}) {
|
|
284
|
-
const current = await currentForRecord(root, record);
|
|
285
|
-
assertFingerprint(record, current, record.path);
|
|
286
|
-
if (record.type === 'file') {
|
|
287
|
-
const target = resolveProjectPath(root, record.path);
|
|
288
|
-
if (deleteInstead || !record.previousExists) { if (await exists(target)) await unlink(target); }
|
|
289
|
-
else await writeText(root, record.path, record.previousValue);
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
if (record.type === 'markdown') {
|
|
293
|
-
const text = await readText(root, record.path);
|
|
294
|
-
const updated = record.previousExists && !deleteInstead
|
|
295
|
-
? upsertMarkdownSection(text, record.heading, String(record.previousValue).replace(/^#{1,6}\s+.*?\n+/u, ''))
|
|
296
|
-
: removeMarkdownSection(text, record.heading);
|
|
297
|
-
await writeText(root, record.path, updated);
|
|
298
|
-
return;
|
|
299
|
-
}
|
|
300
|
-
if (record.type === 'env') {
|
|
301
|
-
let text = await readText(root, record.path);
|
|
302
|
-
text = record.previousExists && !deleteInstead ? setEnv(text, record.key, record.previousValue) : removeEnv(text, record.key);
|
|
303
|
-
await writeText(root, record.path, text);
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
const text = await readText(root, record.path);
|
|
307
|
-
const object = record.type === 'json' ? (text.trim() ? JSON.parse(text) : {}) : parseYaml(text);
|
|
308
|
-
if (record.previousExists && !deleteInstead) setAt(object, record.keyPath, record.previousValue); else deleteAt(object, record.keyPath);
|
|
309
|
-
await writeText(root, record.path, record.type === 'json' ? `${JSON.stringify(object, null, 2)}\n` : stringifyYaml(object));
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
async function claimFile(context, sourcePath, destination, touched) {
|
|
313
|
-
const content = await readFile(sourcePath, 'utf8');
|
|
314
|
-
const key = ownershipKey('file', destination);
|
|
315
|
-
const prior = context.prior[key];
|
|
316
|
-
const target = resolveProjectPath(context.projectRoot, destination);
|
|
317
|
-
const current = await exists(target) ? { exists: true, value: await readFile(target, 'utf8') } : { exists: false, value: undefined };
|
|
318
|
-
if (prior) assertFingerprint(prior, current, destination);
|
|
319
|
-
const original = prior ?? { previousExists: current.exists, previousValue: current.value };
|
|
320
|
-
await writeText(context.projectRoot, destination, content);
|
|
321
|
-
context.next[key] = { type: 'file', path: destination, previousExists: original.previousExists, previousValue: original.previousValue, appliedHash: fingerprint({ exists: true, value: content }) };
|
|
322
|
-
touched.add(key);
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
async function applyOperation(op, context, touched) {
|
|
326
|
-
const { projectRoot, payloadRoot } = context;
|
|
327
|
-
if (op.type === 'copy_file') return claimFile(context, payloadPath(payloadRoot, op.source), op.path, touched);
|
|
328
|
-
if (op.type === 'scaffold_file') {
|
|
329
|
-
const target = resolveProjectPath(projectRoot, op.path);
|
|
330
|
-
const key = ownershipKey('file', op.path);
|
|
331
|
-
const prior = context.prior[key];
|
|
332
|
-
if (prior) {
|
|
333
|
-
// Reclassifying a formerly managed file as a scaffold intentionally hands
|
|
334
|
-
// ownership to the project. Preserve whatever the project currently has.
|
|
335
|
-
delete context.next[key];
|
|
336
|
-
touched.add(key);
|
|
337
|
-
return;
|
|
338
|
-
}
|
|
339
|
-
if (!(await exists(target))) {
|
|
340
|
-
await writeText(projectRoot, op.path, await readFile(payloadPath(payloadRoot, op.source), 'utf8'));
|
|
341
|
-
}
|
|
342
|
-
return;
|
|
343
|
-
}
|
|
344
|
-
if (op.type === 'copy_directory') {
|
|
345
|
-
const sourceRoot = payloadPath(payloadRoot, op.source);
|
|
346
|
-
const walk = async (dir, prefix = '') => {
|
|
347
|
-
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
348
|
-
const relative = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
349
|
-
if (entry.isDirectory()) await walk(resolve(dir, entry.name), relative);
|
|
350
|
-
else if (entry.isFile()) await claimFile(context, resolve(dir, entry.name), `${op.path.replace(/\/$/u, '')}/${relative}`, touched);
|
|
351
|
-
}
|
|
352
|
-
};
|
|
353
|
-
return walk(sourceRoot);
|
|
354
|
-
}
|
|
355
|
-
if (op.type === 'delete_owned_artifact') {
|
|
356
|
-
const matches = Object.entries(context.next).filter(([, record]) => record.path === op.path && record.type === 'file');
|
|
357
|
-
if (!matches.length) throw new Error(`Artifact is not owned: ${op.path}`);
|
|
358
|
-
for (const [key, record] of matches) { await restoreRecord(projectRoot, record, { deleteInstead: true }); delete context.next[key]; touched.add(key); }
|
|
359
|
-
return;
|
|
360
|
-
}
|
|
361
|
-
if (op.type === 'managed_section') {
|
|
362
|
-
const key = ownershipKey('markdown', op.path, op.heading);
|
|
363
|
-
const prior = context.prior[key];
|
|
364
|
-
const text = await readText(projectRoot, op.path);
|
|
365
|
-
const current = markdownSection(text, op.heading);
|
|
366
|
-
if (prior) assertFingerprint(prior, current, op.path);
|
|
367
|
-
const original = prior ?? { previousExists: current.exists, previousValue: current.value };
|
|
368
|
-
const updated = upsertMarkdownSection(text, op.heading, op.content ?? '');
|
|
369
|
-
await writeText(projectRoot, op.path, updated);
|
|
370
|
-
const applied = markdownSection(updated, op.heading);
|
|
371
|
-
context.next[key] = { type: 'markdown', path: op.path, heading: op.heading, previousExists: original.previousExists, previousValue: original.previousValue, appliedHash: fingerprint(applied) };
|
|
372
|
-
touched.add(key); return;
|
|
373
|
-
}
|
|
374
|
-
if (op.type === 'env_set' || op.type === 'env_remove') {
|
|
375
|
-
const key = ownershipKey('env', op.path, op.key);
|
|
376
|
-
const prior = context.prior[key];
|
|
377
|
-
let text = await readText(projectRoot, op.path);
|
|
378
|
-
const map = envMap(text);
|
|
379
|
-
const current = { exists: map.has(op.key), value: map.get(op.key) };
|
|
380
|
-
if (prior) assertFingerprint(prior, current, op.path);
|
|
381
|
-
const original = prior ?? { previousExists: current.exists, previousValue: current.value };
|
|
382
|
-
text = op.type === 'env_set' ? setEnv(text, op.key, String(op.value ?? '')) : removeEnv(text, op.key);
|
|
383
|
-
await writeText(projectRoot, op.path, text);
|
|
384
|
-
const updatedMap = envMap(text);
|
|
385
|
-
context.next[key] = { type: 'env', path: op.path, key: op.key, previousExists: original.previousExists, previousValue: original.previousValue, appliedHash: fingerprint({ exists: updatedMap.has(op.key), value: updatedMap.get(op.key) }) };
|
|
386
|
-
touched.add(key); return;
|
|
387
|
-
}
|
|
388
|
-
if (['json_set', 'json_merge', 'yaml_set', 'yaml_merge'].includes(op.type)) {
|
|
389
|
-
const type = op.type.startsWith('json') ? 'json' : 'yaml';
|
|
390
|
-
const text = await readText(projectRoot, op.path);
|
|
391
|
-
const object = type === 'json' ? (text.trim() ? JSON.parse(text) : {}) : parseYaml(text);
|
|
392
|
-
const assignments = op.type.endsWith('_set') ? [[op.keyPath, op.value]] : leaves(op.value);
|
|
393
|
-
for (const [keyPath, value] of assignments) {
|
|
394
|
-
if (!Array.isArray(keyPath) || !keyPath.length) throw new Error(`Structured operation requires keyPath/value leaves: ${op.path}`);
|
|
395
|
-
const key = ownershipKey(type, op.path, keyPath.join('.'));
|
|
396
|
-
const prior = context.prior[key];
|
|
397
|
-
const current = getAt(object, keyPath);
|
|
398
|
-
if (prior) assertFingerprint(prior, current, op.path);
|
|
399
|
-
const original = prior ?? { previousExists: current.exists, previousValue: current.value };
|
|
400
|
-
setAt(object, keyPath, value);
|
|
401
|
-
context.next[key] = { type, path: op.path, keyPath, previousExists: original.previousExists, previousValue: original.previousValue, appliedHash: fingerprint({ exists: true, value }) };
|
|
402
|
-
touched.add(key);
|
|
403
|
-
}
|
|
404
|
-
await writeText(projectRoot, op.path, type === 'json' ? `${JSON.stringify(object, null, 2)}\n` : stringifyYaml(object));
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
async function reconcile(kind, { projectRoot, payloadRoot, manifest: inputManifest, executor }) {
|
|
409
|
-
const manifest = validateRemoteManifest(inputManifest);
|
|
410
|
-
const installedState = await readInstalledState(projectRoot);
|
|
411
|
-
const runtimeState = await readRuntimeState(projectRoot);
|
|
412
|
-
const installed = installedState.installed[manifest.id];
|
|
413
|
-
if (kind === 'install' && installed) throw new Error(`${manifest.id} is already installed`);
|
|
414
|
-
if (kind !== 'install' && !installed) throw new Error(`${manifest.id} is not installed`);
|
|
415
|
-
const prior = clone(runtimeState.ownership[manifest.id] ?? {});
|
|
416
|
-
const context = { projectRoot, payloadRoot, executor, prior, next: clone(prior) };
|
|
417
|
-
|
|
418
|
-
await runPhase(manifest, `pre_${kind}`, context);
|
|
419
|
-
const touched = new Set();
|
|
420
|
-
if (kind === 'remove') {
|
|
421
|
-
for (const [key, record] of Object.entries(prior)) { await restoreRecord(projectRoot, record); delete context.next[key]; }
|
|
422
|
-
} else {
|
|
423
|
-
for (const op of manifest.operations) if (!op.type.startsWith('run_')) await applyOperation(op, context, touched);
|
|
424
|
-
for (const [key, record] of Object.entries(prior)) {
|
|
425
|
-
if (!touched.has(key) && context.next[key]) { await restoreRecord(projectRoot, record); delete context.next[key]; }
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
await runPhase(manifest, `post_${kind}`, context);
|
|
429
|
-
|
|
430
|
-
if (kind === 'remove') {
|
|
431
|
-
delete installedState.installed[manifest.id];
|
|
432
|
-
installedState.requested = installedState.requested.filter((id) => id !== manifest.id);
|
|
433
|
-
delete runtimeState.ownership[manifest.id];
|
|
434
|
-
delete runtimeState.results[manifest.id];
|
|
435
|
-
} else {
|
|
436
|
-
const contentHash = String(manifest.contentHash ?? hash({ id: manifest.id, revision: manifest.revision ?? null, operations: manifest.operations, check: manifest.check ?? null }));
|
|
437
|
-
const revision = String(manifest.revision ?? contentHash);
|
|
438
|
-
installedState.installed[manifest.id] = {
|
|
439
|
-
kind: manifest.kind ?? 'rule',
|
|
440
|
-
version: String(manifest.version ?? contentHash),
|
|
441
|
-
revision,
|
|
442
|
-
contentHash,
|
|
443
|
-
...(manifest.check ? { check: clone(manifest.check) } : {}),
|
|
444
|
-
};
|
|
445
|
-
installedState.requested = [...new Set([...installedState.requested, manifest.id])].sort();
|
|
446
|
-
runtimeState.ownership[manifest.id] = context.next;
|
|
447
|
-
}
|
|
448
|
-
installedState.schemaVersion = 2;
|
|
449
|
-
runtimeState.schemaVersion = 2;
|
|
450
|
-
await writeJsonState(projectRoot, INSTALLED_PATH, installedState);
|
|
451
|
-
await writeJsonState(projectRoot, STATE_PATH, runtimeState);
|
|
452
|
-
return installedState.installed[manifest.id] ?? null;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
export async function installRule(options) { return reconcile('install', options); }
|
|
456
|
-
export async function syncRule(options) { return reconcile('sync', options); }
|
|
457
|
-
export async function removeRule(options) { return reconcile('remove', options); }
|
|
458
|
-
|
|
459
|
-
export async function runRemoteChecks(projectRoot, options = {}) {
|
|
460
|
-
const installedState = await readInstalledState(projectRoot);
|
|
461
|
-
const runtimeState = await readRuntimeState(projectRoot);
|
|
462
|
-
const executor = options.executor ?? ((command, args, runOptions) => new Promise((resolveRun, reject) => {
|
|
463
|
-
const child = spawn(command, args, { cwd: runOptions.cwd, stdio: 'inherit', shell: false });
|
|
464
|
-
child.on('error', reject);
|
|
465
|
-
child.on('close', (code) => resolveRun(code ?? 1));
|
|
466
|
-
}));
|
|
467
|
-
let exitCode = 0;
|
|
468
|
-
for (const [id, entry] of Object.entries(installedState.installed).sort(([a], [b]) => a.localeCompare(b))) {
|
|
469
|
-
if (!Array.isArray(entry.check?.command) || entry.check.command.length === 0) continue;
|
|
470
|
-
const [command, ...args] = entry.check.command;
|
|
471
|
-
const code = await executor(command, args, { cwd: projectRoot });
|
|
472
|
-
runtimeState.results[id] = { status: code === 0 ? 'pass' : 'fail', exitCode: code };
|
|
473
|
-
if (code !== 0) exitCode = 1;
|
|
474
|
-
}
|
|
475
|
-
runtimeState.schemaVersion = 2;
|
|
476
|
-
runtimeState.checkedAt = new Date(options.nowMs ?? Date.now()).toISOString();
|
|
477
|
-
await writeJsonState(projectRoot, STATE_PATH, runtimeState);
|
|
478
|
-
return { exitCode, results: runtimeState.results };
|
|
479
|
-
}
|
package/src/rule-profile.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { readFile } from 'node:fs/promises';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
|
|
4
|
-
export const RULE_PROFILE_RELATIVE_PATH = '.specdest/rules.json';
|
|
5
|
-
export const EMPTY_RULE_PROFILE = Object.freeze({
|
|
6
|
-
schemaVersion: 1,
|
|
7
|
-
projectType: null,
|
|
8
|
-
capabilities: [],
|
|
9
|
-
include: [],
|
|
10
|
-
exclude: [],
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
function uniqueStrings(values, label) {
|
|
14
|
-
if (!Array.isArray(values ?? [])) throw new Error(`Invalid ${label}`);
|
|
15
|
-
return [...new Set((values ?? []).map(String).map((value) => value.trim()).filter(Boolean))].sort();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function validateRuleProfile(profile) {
|
|
19
|
-
if (!profile || typeof profile !== 'object' || Array.isArray(profile) || profile.schemaVersion !== 1) {
|
|
20
|
-
throw new Error('Invalid .specdest/rules.json profile');
|
|
21
|
-
}
|
|
22
|
-
const projectType = profile.projectType == null ? null : String(profile.projectType).trim();
|
|
23
|
-
if (profile.projectType != null && !projectType) throw new Error('Invalid rule profile projectType');
|
|
24
|
-
const capabilities = uniqueStrings(profile.capabilities, 'rule profile capabilities');
|
|
25
|
-
const include = uniqueStrings(profile.include, 'rule profile include');
|
|
26
|
-
if (!Array.isArray(profile.exclude ?? [])) throw new Error('Invalid rule profile exclude');
|
|
27
|
-
const exclude = (profile.exclude ?? []).map((item) => {
|
|
28
|
-
if (!item || typeof item !== 'object' || !String(item.id ?? '').trim() || !String(item.reason ?? '').trim()) {
|
|
29
|
-
throw new Error('Rule exclusions require both id and non-empty reason');
|
|
30
|
-
}
|
|
31
|
-
return { id: String(item.id).trim(), reason: String(item.reason).trim() };
|
|
32
|
-
}).sort((a, b) => a.id.localeCompare(b.id));
|
|
33
|
-
return { schemaVersion: 1, projectType, capabilities, include, exclude };
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export async function readRuleProfile(projectRoot) {
|
|
37
|
-
try {
|
|
38
|
-
const raw = JSON.parse(await readFile(join(projectRoot, RULE_PROFILE_RELATIVE_PATH), 'utf8'));
|
|
39
|
-
return validateRuleProfile(raw);
|
|
40
|
-
} catch (error) {
|
|
41
|
-
if (error?.code === 'ENOENT') return { ...EMPTY_RULE_PROFILE, capabilities: [], include: [], exclude: [] };
|
|
42
|
-
throw error;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function ruleApplies(entry, stack, profile = EMPTY_RULE_PROFILE) {
|
|
47
|
-
const included = new Set(profile.include ?? []);
|
|
48
|
-
const excluded = new Set((profile.exclude ?? []).map((item) => item.id));
|
|
49
|
-
if (excluded.has(entry.id)) return false;
|
|
50
|
-
if (included.has(entry.id)) return true;
|
|
51
|
-
if (entry.applicableStacks?.length && (!stack || !entry.applicableStacks.includes(stack))) return false;
|
|
52
|
-
const capabilities = new Set(profile.capabilities ?? []);
|
|
53
|
-
if (entry.requiredCapabilities?.some((capability) => !capabilities.has(capability))) return false;
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function assertKnownRuleOverrides(entries, profile) {
|
|
58
|
-
const ids = new Set(entries.filter((entry) => entry.kind === 'rule').map((entry) => entry.id));
|
|
59
|
-
for (const id of profile.include ?? []) if (!ids.has(id)) throw new Error(`Unknown included rule: ${id}`);
|
|
60
|
-
for (const item of profile.exclude ?? []) if (!ids.has(item.id)) throw new Error(`Unknown excluded rule: ${item.id}`);
|
|
61
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { readFile } from 'node:fs/promises';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
|
|
4
|
-
const DEFAULT_ENV_FILES = [
|
|
5
|
-
'.env',
|
|
6
|
-
'.env.local',
|
|
7
|
-
'.env.development',
|
|
8
|
-
'.env.development.local',
|
|
9
|
-
'.env.production',
|
|
10
|
-
'.env.production.local',
|
|
11
|
-
'.env.test',
|
|
12
|
-
'.env.test.local',
|
|
13
|
-
];
|
|
14
|
-
|
|
15
|
-
function parseEnvText(text) {
|
|
16
|
-
const values = {};
|
|
17
|
-
for (const rawLine of text.split(/\r?\n/)) {
|
|
18
|
-
const line = rawLine.trim();
|
|
19
|
-
if (!line || line.startsWith('#')) continue;
|
|
20
|
-
const normalized = line.startsWith('export ') ? line.slice(7).trim() : line;
|
|
21
|
-
const index = normalized.indexOf('=');
|
|
22
|
-
if (index <= 0) continue;
|
|
23
|
-
const name = normalized.slice(0, index).trim();
|
|
24
|
-
let value = normalized.slice(index + 1).trim();
|
|
25
|
-
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
|
|
26
|
-
value = value.slice(1, -1);
|
|
27
|
-
}
|
|
28
|
-
values[name] = value;
|
|
29
|
-
}
|
|
30
|
-
return values;
|
|
31
|
-
}
|
|
32
|
-
export function validateSetupRequirements(requirements = []) {
|
|
33
|
-
if (!Array.isArray(requirements)) throw new Error('setupRequirements must be an array');
|
|
34
|
-
const seen = new Set();
|
|
35
|
-
for (const item of requirements) {
|
|
36
|
-
if (!item || typeof item !== 'object' || Array.isArray(item)) throw new Error('Setup requirement must be an object');
|
|
37
|
-
if (item.kind !== 'env') throw new Error(`Unsupported setup requirement kind: ${item.kind}`);
|
|
38
|
-
if (!/^[A-Z][A-Z0-9_]*$/.test(String(item.name ?? ''))) throw new Error('Setup env requirement name must be uppercase snake case');
|
|
39
|
-
if (item.required !== true && item.required !== false) throw new Error(`Setup env requirement required must be boolean: ${item.name}`);
|
|
40
|
-
const key = `${item.kind}:${item.name}`;
|
|
41
|
-
if (seen.has(key)) throw new Error(`Duplicate setup requirement: ${item.name}`);
|
|
42
|
-
seen.add(key);
|
|
43
|
-
if (item.exampleFile !== undefined && !String(item.exampleFile).trim()) throw new Error(`Invalid exampleFile for setup requirement: ${item.name}`);
|
|
44
|
-
}
|
|
45
|
-
return requirements;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async function readProjectEnvValues(projectRoot, options = {}) {
|
|
49
|
-
const values = { ...(options.env ?? process.env) };
|
|
50
|
-
const files = options.envFiles ?? DEFAULT_ENV_FILES;
|
|
51
|
-
for (const relativePath of files) {
|
|
52
|
-
let text = '';
|
|
53
|
-
try {
|
|
54
|
-
text = await readFile(join(projectRoot, relativePath), 'utf8');
|
|
55
|
-
} catch (error) {
|
|
56
|
-
if (error?.code === 'ENOENT') continue;
|
|
57
|
-
throw error;
|
|
58
|
-
}
|
|
59
|
-
Object.assign(values, parseEnvText(text));
|
|
60
|
-
}
|
|
61
|
-
return values;
|
|
62
|
-
}
|
|
63
|
-
export async function evaluateSetupRequirements(projectRoot, entries, options = {}) {
|
|
64
|
-
const values = await readProjectEnvValues(projectRoot, options);
|
|
65
|
-
const requirements = [];
|
|
66
|
-
for (const entry of entries) {
|
|
67
|
-
validateSetupRequirements(entry.setupRequirements ?? []);
|
|
68
|
-
for (const item of entry.setupRequirements ?? []) {
|
|
69
|
-
const configured = Boolean(String(values[item.name] ?? '').trim());
|
|
70
|
-
requirements.push({
|
|
71
|
-
ownerId: entry.id,
|
|
72
|
-
...item,
|
|
73
|
-
status: configured ? 'configured' : 'missing',
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
requirements.sort((a, b) => a.name.localeCompare(b.name) || a.ownerId.localeCompare(b.ownerId));
|
|
78
|
-
return {
|
|
79
|
-
requirements,
|
|
80
|
-
missing: requirements.filter((item) => item.required && item.status === 'missing'),
|
|
81
|
-
};
|
|
82
|
-
}
|