@sublang/spex 0.2.0 → 0.2.2
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 +2 -2
- package/dist/copy-templates.d.ts +11 -10
- package/dist/copy-templates.js +30 -25
- package/dist/scaffold.js +18 -42
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -55,8 +55,8 @@ When a new release ships updated templates, refresh them with:
|
|
|
55
55
|
spex scaffold --update
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
-
- Spex-authoritative files (`specs/meta.md` and the spec-format decision record) are refreshed unconditionally.
|
|
59
|
-
- Starter files (`map.md`, the sample iteration, boilerplate items) are refreshed
|
|
58
|
+
- Spex-authoritative files (`specs/meta.md` and the spec-format decision record) are refreshed unconditionally, including when they are absent.
|
|
59
|
+
- Starter files (`map.md`, the sample iteration, boilerplate items) are refreshed when you have not customized them, and written from the bundled template when they are absent. Customized starter files are kept as-is. Remove a starter file *after* `--update` if you do not want it.
|
|
60
60
|
- Anything you authored outside the bundled framework and starter files is left alone.
|
|
61
61
|
|
|
62
62
|
Review the changes with `git diff -- specs`.
|
package/dist/copy-templates.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
export type PristineState = "pristine" | "modified" | "missing";
|
|
2
|
+
export type LegacyItemLayoutResult = {
|
|
3
|
+
status: "migrated" | "conflict";
|
|
4
|
+
targetRelPath: string;
|
|
5
|
+
legacyRelPath: string;
|
|
6
|
+
};
|
|
7
|
+
type RefreshPristineSeedsOptions = {
|
|
8
|
+
migratedFrom?: ReadonlyMap<string, string>;
|
|
9
|
+
};
|
|
2
10
|
/**
|
|
3
11
|
* Copy bundled template files from scaffold/specs/ to target specs/.
|
|
4
12
|
*
|
|
@@ -8,17 +16,10 @@ export type PristineState = "pristine" | "modified" | "missing";
|
|
|
8
16
|
export declare function copyTemplates(basePath: string): void;
|
|
9
17
|
export declare function getFrameworkSpecFiles(): readonly string[];
|
|
10
18
|
export declare function getSeedSpecFiles(): readonly string[];
|
|
11
|
-
export declare function migrateLegacyItemLayout(basePath: string):
|
|
12
|
-
migrated: string[];
|
|
13
|
-
conflicts: string[];
|
|
14
|
-
};
|
|
19
|
+
export declare function migrateLegacyItemLayout(basePath: string): LegacyItemLayoutResult[];
|
|
15
20
|
export declare function getFileHistory(relPath: string): string[];
|
|
16
21
|
export declare function canonicalContentHash(data: Buffer): string;
|
|
17
22
|
export declare function isPristine(basePath: string, relPath: string): PristineState;
|
|
18
23
|
export declare function overwriteFrameworkSpecFiles(basePath: string): void;
|
|
19
|
-
export declare function refreshPristineSeeds(basePath: string):
|
|
20
|
-
|
|
21
|
-
unchanged: string[];
|
|
22
|
-
modified: string[];
|
|
23
|
-
missing: string[];
|
|
24
|
-
};
|
|
24
|
+
export declare function refreshPristineSeeds(basePath: string, options?: RefreshPristineSeedsOptions): void;
|
|
25
|
+
export {};
|
package/dist/copy-templates.js
CHANGED
|
@@ -101,8 +101,7 @@ function removeEmptyDirectories(dir) {
|
|
|
101
101
|
}
|
|
102
102
|
// SCAF-26.
|
|
103
103
|
export function migrateLegacyItemLayout(basePath) {
|
|
104
|
-
const
|
|
105
|
-
const conflicts = [];
|
|
104
|
+
const results = [];
|
|
106
105
|
for (const [legacyRootRel, targetRootRel] of LEGACY_ITEM_DIRS) {
|
|
107
106
|
const legacyRoot = join(basePath, legacyRootRel);
|
|
108
107
|
if (!existsSync(legacyRoot))
|
|
@@ -113,18 +112,24 @@ export function migrateLegacyItemLayout(basePath) {
|
|
|
113
112
|
const targetRelPath = posix.join(targetRootRel, suffix);
|
|
114
113
|
const target = join(basePath, targetRelPath);
|
|
115
114
|
if (existsSync(target)) {
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
results.push({
|
|
116
|
+
status: "conflict",
|
|
117
|
+
targetRelPath,
|
|
118
|
+
legacyRelPath,
|
|
119
|
+
});
|
|
118
120
|
continue;
|
|
119
121
|
}
|
|
120
122
|
mkdirSync(dirname(target), { recursive: true });
|
|
121
123
|
renameSync(source, target);
|
|
122
|
-
|
|
123
|
-
|
|
124
|
+
results.push({
|
|
125
|
+
status: "migrated",
|
|
126
|
+
targetRelPath,
|
|
127
|
+
legacyRelPath,
|
|
128
|
+
});
|
|
124
129
|
}
|
|
125
130
|
}
|
|
126
131
|
removeEmptyDirectories(join(basePath, "specs", "items"));
|
|
127
|
-
return
|
|
132
|
+
return results;
|
|
128
133
|
}
|
|
129
134
|
// SCAF-21.
|
|
130
135
|
export function getFileHistory(relPath) {
|
|
@@ -167,40 +172,40 @@ export function overwriteFrameworkSpecFiles(basePath) {
|
|
|
167
172
|
console.log(` ${relPath} (unchanged)`);
|
|
168
173
|
continue;
|
|
169
174
|
}
|
|
175
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
170
176
|
copyFileSync(source, target);
|
|
171
177
|
console.log(` ${relPath} (updated)`);
|
|
172
178
|
}
|
|
173
179
|
}
|
|
174
180
|
// SCAF-23.
|
|
175
|
-
|
|
181
|
+
function formatSeedIndicator(relPath, indicator, migratedFrom) {
|
|
182
|
+
const legacyRelPath = migratedFrom?.get(relPath);
|
|
183
|
+
if (legacyRelPath === undefined)
|
|
184
|
+
return indicator;
|
|
185
|
+
if (indicator === "unchanged")
|
|
186
|
+
return `migrated from ${legacyRelPath}`;
|
|
187
|
+
return `migrated from ${legacyRelPath}; ${indicator}`;
|
|
188
|
+
}
|
|
189
|
+
export function refreshPristineSeeds(basePath, options = {}) {
|
|
176
190
|
const scaffoldDir = getScaffoldDir();
|
|
177
|
-
const refreshed = [];
|
|
178
|
-
const unchanged = [];
|
|
179
|
-
const modified = [];
|
|
180
|
-
const missing = [];
|
|
181
191
|
for (const relPath of SEED_FILES) {
|
|
182
192
|
const state = isPristine(basePath, relPath);
|
|
183
|
-
if (state === "missing") {
|
|
184
|
-
console.log(` ${relPath} (kept — missing)`);
|
|
185
|
-
missing.push(relPath);
|
|
186
|
-
continue;
|
|
187
|
-
}
|
|
188
193
|
if (state === "modified") {
|
|
189
|
-
|
|
190
|
-
|
|
194
|
+
const indicator = formatSeedIndicator(relPath, "kept — user-modified", options.migratedFrom);
|
|
195
|
+
console.log(` ${relPath} (${indicator})`);
|
|
191
196
|
continue;
|
|
192
197
|
}
|
|
193
198
|
const target = join(basePath, relPath);
|
|
194
199
|
const source = join(scaffoldDir, relPath);
|
|
195
|
-
if (hashFile(target) === hashFile(source)) {
|
|
196
|
-
|
|
197
|
-
|
|
200
|
+
if (state === "pristine" && hashFile(target) === hashFile(source)) {
|
|
201
|
+
const indicator = formatSeedIndicator(relPath, "unchanged", options.migratedFrom);
|
|
202
|
+
console.log(` ${relPath} (${indicator})`);
|
|
198
203
|
continue;
|
|
199
204
|
}
|
|
205
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
200
206
|
copyFileSync(source, target);
|
|
201
|
-
|
|
202
|
-
|
|
207
|
+
const indicator = state === "missing" ? "created" : "updated";
|
|
208
|
+
console.log(` ${relPath} (${formatSeedIndicator(relPath, indicator, options.migratedFrom)})`);
|
|
203
209
|
}
|
|
204
|
-
return { refreshed, unchanged, modified, missing };
|
|
205
210
|
}
|
|
206
211
|
//# sourceMappingURL=copy-templates.js.map
|
package/dist/scaffold.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { execFileSync } from "node:child_process";
|
|
4
4
|
import { appendAgentSpecs } from "./append-agent-specs.js";
|
|
5
5
|
import { readBundledMarkdown } from "./bundled-scaffold.js";
|
|
6
|
-
import { copyTemplates,
|
|
6
|
+
import { copyTemplates, getSeedSpecFiles, migrateLegacyItemLayout, overwriteFrameworkSpecFiles, refreshPristineSeeds, } from "./copy-templates.js";
|
|
7
7
|
import { createSpecsStructure } from "./create-specs-structure.js";
|
|
8
8
|
import { resolveBase } from "./resolve-base.js";
|
|
9
9
|
function parseArgs(args) {
|
|
@@ -40,33 +40,30 @@ function assertCleanSpecsTree(basePath) {
|
|
|
40
40
|
throw new Error("--update requires a clean specs/ working tree");
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
function assertFrameworkFilesTracked(basePath) {
|
|
44
|
-
const missing = getFrameworkSpecFiles().filter((relPath) => {
|
|
45
|
-
try {
|
|
46
|
-
execFileSync("git", ["cat-file", "-e", `HEAD:${relPath}`], {
|
|
47
|
-
cwd: basePath,
|
|
48
|
-
stdio: "ignore",
|
|
49
|
-
});
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
catch {
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
if (missing.length > 0) {
|
|
57
|
-
throw new Error(`--update requires framework files tracked in HEAD: ${missing.join(", ")}`);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
43
|
function readUpdateMergePrompt() {
|
|
61
44
|
return readBundledMarkdown("update-merge-prompt.md");
|
|
62
45
|
}
|
|
63
46
|
function updateScaffoldTemplates() {
|
|
64
47
|
const basePath = getGitRoot();
|
|
65
48
|
assertCleanSpecsTree(basePath);
|
|
66
|
-
|
|
67
|
-
const
|
|
49
|
+
const legacyResults = migrateLegacyItemLayout(basePath);
|
|
50
|
+
const seedPaths = new Set(getSeedSpecFiles());
|
|
51
|
+
const migratedSeedSources = new Map();
|
|
52
|
+
for (const result of legacyResults) {
|
|
53
|
+
if (result.status === "migrated" && seedPaths.has(result.targetRelPath)) {
|
|
54
|
+
migratedSeedSources.set(result.targetRelPath, result.legacyRelPath);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
for (const result of legacyResults) {
|
|
58
|
+
if (result.status === "conflict") {
|
|
59
|
+
console.log(` ${result.legacyRelPath} (kept — target exists at ${result.targetRelPath})`);
|
|
60
|
+
}
|
|
61
|
+
else if (!seedPaths.has(result.targetRelPath)) {
|
|
62
|
+
console.log(` ${result.targetRelPath} (migrated from ${result.legacyRelPath})`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
68
65
|
overwriteFrameworkSpecFiles(basePath);
|
|
69
|
-
|
|
66
|
+
refreshPristineSeeds(basePath, { migratedFrom: migratedSeedSources });
|
|
70
67
|
console.log("");
|
|
71
68
|
console.log("spex scaffold --update completed.");
|
|
72
69
|
console.log("Review the file indicators above and inspect changes (e.g., `git diff -- specs`).");
|
|
@@ -75,27 +72,6 @@ function updateScaffoldTemplates() {
|
|
|
75
72
|
console.log("```");
|
|
76
73
|
console.log(readUpdateMergePrompt());
|
|
77
74
|
console.log("```");
|
|
78
|
-
if (legacyReport.migrated.length > 0) {
|
|
79
|
-
console.log("");
|
|
80
|
-
console.log("Legacy specs/items layout migrated:");
|
|
81
|
-
for (const relPath of legacyReport.migrated) {
|
|
82
|
-
console.log(`- ${relPath}`);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (legacyReport.conflicts.length > 0) {
|
|
86
|
-
console.log("");
|
|
87
|
-
console.log("Legacy paths left in place because flat targets already exist:");
|
|
88
|
-
for (const relPath of legacyReport.conflicts) {
|
|
89
|
-
console.log(`- ${relPath}`);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (seedReport.refreshed.length > 0) {
|
|
93
|
-
console.log("");
|
|
94
|
-
console.log("Pristine seeds also refreshed (no prior customization detected):");
|
|
95
|
-
for (const relPath of seedReport.refreshed) {
|
|
96
|
-
console.log(`- ${relPath}`);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
75
|
}
|
|
100
76
|
/**
|
|
101
77
|
* Entry point for the scaffold subcommand.
|