@domain-first/project-structure 8.6.1 → 8.7.0
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 +1 -1
- package/bin/df-skills.mjs +55 -9
- package/dist/287.js +54 -2
- package/dist/38.js +36 -0
- package/dist/561.js +9 -1
- package/dist/947.js +11 -1
- package/dist/agent-cli.d.ts +9 -2
- package/dist/agent-principles.cjs +116 -0
- package/dist/agent-principles.d.ts +9 -0
- package/dist/agent-principles.js +64 -0
- package/dist/agent-principles.spec.d.ts +1 -0
- package/dist/agent-requests.d.ts +16 -2
- package/dist/graph.cjs +10 -0
- package/dist/index.cjs +74 -1
- package/dist/index.js +4 -1
- package/dist/init.cjs +12 -2
- package/dist/integration.cjs +71 -1
- package/dist/lint.cjs +46 -0
- package/dist/react.cjs +71 -1
- package/dist/use-cases/add-integration.d.ts +1 -1
- package/dist/use-cases/index.d.ts +1 -0
- package/dist/use-cases/scaffold-new-infrastructure-helper.d.ts +7 -0
- package/dist/wiring.d.ts +2 -2
- package/package.json +3 -2
- package/principles/df-principles.md +33 -0
- package/skills/df-ps-implement/SKILL.md +26 -1
- package/skills/df-ps-plan-feature/SKILL.md +22 -18
- package/skills/df-ps-react/SKILL.md +2 -9
- package/skills/df-ps-react/references/generators.md +9 -9
- package/skills/df-ps-scaffold/SKILL.md +19 -125
- package/skills/df-ps-scaffold/references/agent-mode.md +2 -2
- package/skills/df-ps-scaffold/references/agent-operations.md +1 -0
- package/skills/df-ps-scaffold/references/choosing-components.md +65 -49
- package/skills/df-ps-scaffold/references/generators.md +28 -5
- package/skills/df-ps-scaffold/references/units/aggregate.md +1 -3
- package/skills/df-ps-scaffold/references/units/bounded-context.md +1 -1
- package/skills/df-ps-scaffold/references/units/command-query.md +4 -6
- package/skills/df-ps-scaffold/references/units/delete.md +0 -2
- package/skills/df-ps-scaffold/references/units/endpoint.md +1 -4
- package/skills/df-ps-scaffold/references/units/entity-value-object.md +0 -4
- package/skills/df-ps-scaffold/references/units/errors.md +0 -4
- package/skills/df-ps-scaffold/references/units/helper.md +30 -0
- package/skills/df-ps-scaffold/references/units/implementation.md +0 -4
- package/skills/df-ps-scaffold/references/units/move-or-rename.md +0 -4
- package/skills/df-ps-scaffold/references/units/port.md +2 -5
- package/skills/df-ps-scaffold/references/units/services.md +2 -4
- package/skills/df-ps-scaffold/references/units/use-case.md +1 -2
- package/skills/df-ps-scaffold/references/units/wire-dependency.md +0 -2
- package/skills/df-ps-scaffold/references/work-plan.md +73 -0
- package/skills/df-ps-scaffold/scripts/drive.mjs +0 -252
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Drives an interactive CLI of the package (`df-scaffold` by default, or
|
|
4
|
-
* `df-react` / `df-init` with `--bin`) with a scripted list of answers and
|
|
5
|
-
* prints the files it created or changed.
|
|
6
|
-
*
|
|
7
|
-
* Usage:
|
|
8
|
-
* node drive.mjs [--bin <name>] [--cwd <dir>] [--delay <ms>] <step> [<step> ...]
|
|
9
|
-
* node drive.mjs "pick:Bounded Context: sales" pick:Application "pick:New Port" text:billing-gateway "pick:System: cross-context" no toggle:1
|
|
10
|
-
* (when the dependency list has the desired neighboring handler at item 1)
|
|
11
|
-
*
|
|
12
|
-
* Steps (one per prompt, in the order the CLI asks them):
|
|
13
|
-
* pick:<label> select prompt: type the choice label (or a unique prefix) and press Enter
|
|
14
|
-
* text:<value> input prompt: type the value and press Enter
|
|
15
|
-
* default input/select prompt: accept the suggested default (press Enter)
|
|
16
|
-
* yes | no confirm prompt
|
|
17
|
-
* toggle:<n,..> checkbox prompt: toggle 1-based items (headers not counted),
|
|
18
|
-
* moving with the arrow keys, then press Enter
|
|
19
|
-
* none checkbox prompt: submit as is (pre-checked items stay checked)
|
|
20
|
-
*
|
|
21
|
-
* Implementation menus use the same pick:<label> steps as any select:
|
|
22
|
-
* a saved implementation label or an available System: implementation,
|
|
23
|
-
* or either manual-entry action followed by a separate text:<type> step:
|
|
24
|
-
* "pick:Enter implementation type and save for future use" text:redis
|
|
25
|
-
* "pick:Enter implementation type for this run only" text:redis
|
|
26
|
-
*/
|
|
27
|
-
import { spawn } from 'node:child_process';
|
|
28
|
-
import fs from 'node:fs';
|
|
29
|
-
import path from 'node:path';
|
|
30
|
-
|
|
31
|
-
const args = process.argv.slice(2);
|
|
32
|
-
let cwd = process.cwd();
|
|
33
|
-
let delay = 600;
|
|
34
|
-
let bin = 'df-scaffold';
|
|
35
|
-
const steps = [];
|
|
36
|
-
|
|
37
|
-
for (let i = 0; i < args.length; i++) {
|
|
38
|
-
if (args[i] === '--cwd') cwd = path.resolve(args[++i]);
|
|
39
|
-
else if (args[i] === '--bin') bin = args[++i];
|
|
40
|
-
else if (args[i] === '--delay') delay = Number(args[++i]);
|
|
41
|
-
else steps.push(args[i]);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const findProjectRoot = (dir) => {
|
|
45
|
-
while (dir !== path.parse(dir).root) {
|
|
46
|
-
if (fs.existsSync(path.join(dir, 'package.json'))) return dir;
|
|
47
|
-
dir = path.dirname(dir);
|
|
48
|
-
}
|
|
49
|
-
throw new Error(`No package.json found above ${cwd}`);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const projectRoot = findProjectRoot(cwd);
|
|
53
|
-
|
|
54
|
-
const toKeys = (step) => {
|
|
55
|
-
if (step === 'yes') return ['y\r'];
|
|
56
|
-
if (step === 'no') return ['n\r'];
|
|
57
|
-
if (step === 'default' || step === 'none') return ['\r'];
|
|
58
|
-
if (step.startsWith('text:')) return [`${step.slice(5)}\r`];
|
|
59
|
-
// Select prompts jump to the first choice starting with the typed text.
|
|
60
|
-
if (step.startsWith('pick:')) return [step.slice(5), '\r'];
|
|
61
|
-
if (step.startsWith('toggle:')) {
|
|
62
|
-
const items = step
|
|
63
|
-
.slice(7)
|
|
64
|
-
.split(',')
|
|
65
|
-
.map((n) => n.trim());
|
|
66
|
-
if (!items.every((n) => /^[1-9]\d*$/.test(n))) {
|
|
67
|
-
throw new Error(`Toggle items must be positive numbers: ${step}`);
|
|
68
|
-
}
|
|
69
|
-
// Sent by the main loop, which moves with the arrow keys.
|
|
70
|
-
return [];
|
|
71
|
-
}
|
|
72
|
-
throw new Error(`Unknown step: ${step}`);
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
// biome-ignore lint/suspicious/noControlCharactersInRegex: strip ANSI escapes
|
|
76
|
-
const stripAnsi = (text) => text.replace(/\x1b\[[0-9;?]*[A-Za-z]/g, '');
|
|
77
|
-
|
|
78
|
-
// Fail on malformed steps before the CLI starts writing files.
|
|
79
|
-
try {
|
|
80
|
-
steps.forEach(toKeys);
|
|
81
|
-
} catch (error) {
|
|
82
|
-
console.error(error.message);
|
|
83
|
-
process.exit(2);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const ignored = new Set(['node_modules', '.git', 'dist', 'build', '.next']);
|
|
87
|
-
const snapshot = () => {
|
|
88
|
-
const result = new Map();
|
|
89
|
-
const walk = (dir) => {
|
|
90
|
-
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
91
|
-
if (ignored.has(entry.name)) continue;
|
|
92
|
-
const full = path.join(dir, entry.name);
|
|
93
|
-
if (entry.isDirectory()) walk(full);
|
|
94
|
-
else result.set(full, fs.readFileSync(full, 'utf8'));
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
walk(projectRoot);
|
|
98
|
-
return result;
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
if (!['df-scaffold', 'df-react', 'df-init'].includes(bin)) {
|
|
102
|
-
console.error(`Unknown --bin: ${bin}`);
|
|
103
|
-
process.exit(2);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const localBin = path.join(projectRoot, 'node_modules', '.bin', bin);
|
|
107
|
-
const [command, commandArgs] = fs.existsSync(localBin)
|
|
108
|
-
? [localBin, []]
|
|
109
|
-
: [
|
|
110
|
-
'npm',
|
|
111
|
-
['exec', '--yes', '--package=@domain-first/project-structure', '--', bin]
|
|
112
|
-
];
|
|
113
|
-
|
|
114
|
-
const before = snapshot();
|
|
115
|
-
const child = spawn(command, commandArgs, {
|
|
116
|
-
cwd,
|
|
117
|
-
stdio: ['pipe', 'pipe', 'pipe']
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
let output = '';
|
|
121
|
-
child.stdout.on('data', (chunk) => (output += chunk));
|
|
122
|
-
child.stderr.on('data', (chunk) => (output += chunk));
|
|
123
|
-
|
|
124
|
-
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
125
|
-
|
|
126
|
-
let exited = false;
|
|
127
|
-
const exitCode = new Promise((resolve) =>
|
|
128
|
-
child.on('exit', (code) => {
|
|
129
|
-
exited = true;
|
|
130
|
-
resolve(code);
|
|
131
|
-
})
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
// npm exec may need extra time to download the package on first use.
|
|
135
|
-
await sleep(fs.existsSync(localBin) ? 1200 : 8000);
|
|
136
|
-
let aborted;
|
|
137
|
-
const arrowDown = '\x1b[B';
|
|
138
|
-
|
|
139
|
-
// The latest highlighted choice, without checkbox marks.
|
|
140
|
-
const highlightedChoice = () =>
|
|
141
|
-
[...stripAnsi(output).matchAll(/❯\s*([^\n]*)/g)]
|
|
142
|
-
.at(-1)?.[1]
|
|
143
|
-
?.replace(/^[◯◉]\s*/, '')
|
|
144
|
-
.trim();
|
|
145
|
-
|
|
146
|
-
for (const step of steps) {
|
|
147
|
-
if (exited) break;
|
|
148
|
-
const keys = toKeys(step);
|
|
149
|
-
if (step.startsWith('toggle:')) {
|
|
150
|
-
// Number keys reach only items 1-9, so walk down from the first
|
|
151
|
-
// item instead. Headers are skipped by the prompt itself.
|
|
152
|
-
const targets = [
|
|
153
|
-
...new Set(
|
|
154
|
-
step
|
|
155
|
-
.slice(7)
|
|
156
|
-
.split(',')
|
|
157
|
-
.map((n) => Number(n.trim()))
|
|
158
|
-
)
|
|
159
|
-
].sort((a, b) => a - b);
|
|
160
|
-
let position = 1;
|
|
161
|
-
for (const target of targets) {
|
|
162
|
-
for (; position < target - 1; position++) {
|
|
163
|
-
child.stdin.write(arrowDown);
|
|
164
|
-
await sleep(Math.min(delay, 100));
|
|
165
|
-
}
|
|
166
|
-
if (position < target) {
|
|
167
|
-
// The cursor stays put past the last item, so check the
|
|
168
|
-
// last step down.
|
|
169
|
-
await sleep(delay);
|
|
170
|
-
const before = highlightedChoice();
|
|
171
|
-
child.stdin.write(arrowDown);
|
|
172
|
-
position++;
|
|
173
|
-
await sleep(delay);
|
|
174
|
-
if (highlightedChoice() === before) {
|
|
175
|
-
aborted = `${step}: item ${target} does not exist; the list ends at "${before ?? '?'}".`;
|
|
176
|
-
break;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
child.stdin.write(' ');
|
|
180
|
-
await sleep(delay);
|
|
181
|
-
}
|
|
182
|
-
if (aborted) break;
|
|
183
|
-
child.stdin.write('\r');
|
|
184
|
-
await sleep(delay);
|
|
185
|
-
continue;
|
|
186
|
-
}
|
|
187
|
-
if (step.startsWith('pick:')) {
|
|
188
|
-
// Type the label, then make sure the highlighted choice really
|
|
189
|
-
// matches before pressing Enter: a miss would silently keep the
|
|
190
|
-
// previously highlighted choice.
|
|
191
|
-
child.stdin.write(keys[0]);
|
|
192
|
-
await sleep(delay);
|
|
193
|
-
// No re-render happens when the match is already highlighted, so
|
|
194
|
-
// read the latest highlighted line from the whole output.
|
|
195
|
-
const render = stripAnsi(output);
|
|
196
|
-
const highlighted = [...render.matchAll(/❯\s*([^\n]*)/g)]
|
|
197
|
-
.at(-1)?.[1]
|
|
198
|
-
?.trim();
|
|
199
|
-
const wanted = step.slice(5).toLowerCase();
|
|
200
|
-
if (!highlighted?.toLowerCase().startsWith(wanted)) {
|
|
201
|
-
aborted = `"${step.slice(5)}" does not match the highlighted choice "${highlighted ?? '?'}". A pick label must be a prefix of a choice shown in the menu.`;
|
|
202
|
-
break;
|
|
203
|
-
}
|
|
204
|
-
child.stdin.write(keys[1]);
|
|
205
|
-
await sleep(delay);
|
|
206
|
-
continue;
|
|
207
|
-
}
|
|
208
|
-
for (const key of keys) {
|
|
209
|
-
child.stdin.write(key);
|
|
210
|
-
await sleep(delay);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
await sleep(delay);
|
|
214
|
-
const unansweredPrompt = !exited && !aborted;
|
|
215
|
-
if (aborted) child.kill();
|
|
216
|
-
child.stdin.end();
|
|
217
|
-
const code = await exitCode;
|
|
218
|
-
|
|
219
|
-
const after = snapshot();
|
|
220
|
-
const rel = (p) => path.relative(projectRoot, p);
|
|
221
|
-
const created = [...after.keys()].filter((p) => !before.has(p)).map(rel);
|
|
222
|
-
const changed = [...after.keys()]
|
|
223
|
-
.filter((p) => before.has(p) && before.get(p) !== after.get(p))
|
|
224
|
-
.map(rel);
|
|
225
|
-
const deleted = [...before.keys()].filter((p) => !after.has(p)).map(rel);
|
|
226
|
-
|
|
227
|
-
const plain = stripAnsi(output);
|
|
228
|
-
const answered = [...plain.matchAll(/✔\s*([^\n]*)/g)].map((m) => m[1].trim());
|
|
229
|
-
|
|
230
|
-
console.log(`project root: ${projectRoot}`);
|
|
231
|
-
console.log(`exit code: ${code}`);
|
|
232
|
-
if (aborted) {
|
|
233
|
-
console.log(`ABORTED before submitting the answer: ${aborted}`);
|
|
234
|
-
}
|
|
235
|
-
if (unansweredPrompt) {
|
|
236
|
-
console.log('WARNING: the CLI was still waiting for input after the last step.');
|
|
237
|
-
}
|
|
238
|
-
console.log('\nanswered prompts:');
|
|
239
|
-
for (const line of answered) console.log(` ${line}`);
|
|
240
|
-
console.log('\ncreated:');
|
|
241
|
-
for (const file of created) console.log(` + ${file}`);
|
|
242
|
-
console.log('\nchanged:');
|
|
243
|
-
for (const file of changed) console.log(` ~ ${file}`);
|
|
244
|
-
if (deleted.length) {
|
|
245
|
-
console.log('\ndeleted:');
|
|
246
|
-
for (const file of deleted) console.log(` - ${file}`);
|
|
247
|
-
}
|
|
248
|
-
if (code !== 0 || unansweredPrompt || aborted) {
|
|
249
|
-
console.log('\nraw output (tail):');
|
|
250
|
-
console.log(plain.split('\n').slice(-15).join('\n'));
|
|
251
|
-
process.exitCode = 1;
|
|
252
|
-
}
|