@domain-first/project-structure 6.0.0 → 7.0.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 +16 -19
- package/dist/201.js +46 -35
- package/dist/287.js +1685 -1612
- package/dist/config-file.d.ts +2 -2
- package/dist/dependency-rules.d.ts +1 -1
- package/dist/file-system.d.ts +5 -0
- package/dist/in-memory-db.d.ts +5 -0
- package/dist/index.cjs +100 -916
- package/dist/index.js +6 -46
- package/dist/init.cjs +868 -0
- package/dist/init.d.ts +2 -0
- package/dist/init.js +36 -0
- package/dist/integration.cjs +412 -33
- package/dist/integration.js +4 -4
- package/dist/integrations/in-memory-db.d.ts +6 -0
- package/dist/integrations/index.d.ts +2 -0
- package/dist/integrations/missing-domain-first-packages.d.ts +8 -0
- package/dist/integrations/rest-endpoint-generator.d.ts +18 -0
- package/dist/integrations/rest-endpoint-generator.spec.d.ts +1 -0
- package/dist/lint.cjs +8 -8
- package/dist/lint.js +7 -7
- package/dist/print-next-steps.d.ts +2 -2
- package/dist/react.cjs +915 -0
- package/dist/react.d.ts +2 -0
- package/dist/react.js +73 -0
- package/dist/use-cases/rest-endpoint-generator.d.ts +1 -1
- package/package.json +3 -1
- package/skills/df-ps-implement/SKILL.md +10 -55
- package/skills/df-ps-plan-feature/SKILL.md +6 -6
- package/skills/df-ps-project-scripts/SKILL.md +1 -1
- package/skills/df-ps-react/SKILL.md +82 -0
- package/skills/df-ps-react/references/generators.md +80 -0
- package/skills/df-ps-scaffold/SKILL.md +38 -20
- package/skills/df-ps-scaffold/references/choosing-components.md +7 -28
- package/skills/df-ps-scaffold/references/generators.md +6 -179
- package/skills/df-ps-scaffold/references/units/aggregate.md +47 -0
- package/skills/df-ps-scaffold/references/units/bounded-context.md +13 -0
- package/skills/df-ps-scaffold/references/units/command-query.md +32 -0
- package/skills/df-ps-scaffold/references/units/endpoint.md +28 -0
- package/skills/df-ps-scaffold/references/units/entity-value-object.md +27 -0
- package/skills/df-ps-scaffold/references/units/errors.md +26 -0
- package/skills/df-ps-scaffold/references/units/port.md +23 -0
- package/skills/df-ps-scaffold/references/units/services.md +28 -0
- package/skills/df-ps-scaffold/references/units/use-case.md +25 -0
- package/skills/df-ps-scaffold/references/units/wire-dependency.md +15 -0
- package/skills/df-ps-scaffold/scripts/drive.mjs +12 -4
package/dist/react.cjs
ADDED
|
@@ -0,0 +1,915 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __webpack_require__ = {};
|
|
4
|
+
(()=>{
|
|
5
|
+
__webpack_require__.n = (module)=>{
|
|
6
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
7
|
+
__webpack_require__.d(getter, {
|
|
8
|
+
a: getter
|
|
9
|
+
});
|
|
10
|
+
return getter;
|
|
11
|
+
};
|
|
12
|
+
})();
|
|
13
|
+
(()=>{
|
|
14
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
15
|
+
var define = (defs, kind)=>{
|
|
16
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
[kind]: defs[key]
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
define(getters, "get");
|
|
22
|
+
define(values, "value");
|
|
23
|
+
};
|
|
24
|
+
})();
|
|
25
|
+
(()=>{
|
|
26
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
const external_node_util_namespaceObject = require("node:util");
|
|
30
|
+
const prompts_namespaceObject = require("@inquirer/prompts");
|
|
31
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
32
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
33
|
+
const external_zod_namespaceObject = require("zod");
|
|
34
|
+
var external_zod_default = /*#__PURE__*/ __webpack_require__.n(external_zod_namespaceObject);
|
|
35
|
+
const moduleKinds = [
|
|
36
|
+
'repositories',
|
|
37
|
+
'domain-services',
|
|
38
|
+
'application-ports',
|
|
39
|
+
'application-services',
|
|
40
|
+
'use-cases',
|
|
41
|
+
'commands',
|
|
42
|
+
'queries',
|
|
43
|
+
'infrastructure-services',
|
|
44
|
+
'presentation-services'
|
|
45
|
+
];
|
|
46
|
+
const domain = [
|
|
47
|
+
'repositories',
|
|
48
|
+
'domain-services'
|
|
49
|
+
];
|
|
50
|
+
const commandsAndQueries = [
|
|
51
|
+
'commands',
|
|
52
|
+
'queries'
|
|
53
|
+
];
|
|
54
|
+
const infrastructure = [
|
|
55
|
+
...domain,
|
|
56
|
+
'application-ports',
|
|
57
|
+
'infrastructure-services'
|
|
58
|
+
];
|
|
59
|
+
const defaultDependencies = {
|
|
60
|
+
'domain-services': [
|
|
61
|
+
'domain-services'
|
|
62
|
+
],
|
|
63
|
+
repositories: [
|
|
64
|
+
'domain-services',
|
|
65
|
+
'application-ports',
|
|
66
|
+
'infrastructure-services'
|
|
67
|
+
],
|
|
68
|
+
'application-ports': infrastructure,
|
|
69
|
+
'application-services': [
|
|
70
|
+
...domain,
|
|
71
|
+
'application-ports',
|
|
72
|
+
...commandsAndQueries
|
|
73
|
+
],
|
|
74
|
+
'use-cases': [
|
|
75
|
+
...domain,
|
|
76
|
+
'application-ports',
|
|
77
|
+
'application-services',
|
|
78
|
+
...commandsAndQueries
|
|
79
|
+
],
|
|
80
|
+
commands: [
|
|
81
|
+
'infrastructure-services'
|
|
82
|
+
],
|
|
83
|
+
queries: [
|
|
84
|
+
'infrastructure-services'
|
|
85
|
+
],
|
|
86
|
+
'infrastructure-services': infrastructure,
|
|
87
|
+
'presentation-services': [
|
|
88
|
+
'application-ports',
|
|
89
|
+
'application-services',
|
|
90
|
+
'use-cases',
|
|
91
|
+
...commandsAndQueries,
|
|
92
|
+
'presentation-services'
|
|
93
|
+
]
|
|
94
|
+
};
|
|
95
|
+
const kindSchema = external_zod_default()["enum"](moduleKinds);
|
|
96
|
+
const dependencyRulesSchema = external_zod_default().partialRecord(kindSchema, external_zod_default().union([
|
|
97
|
+
external_zod_default().array(kindSchema),
|
|
98
|
+
external_zod_default().object({
|
|
99
|
+
add: external_zod_default().array(kindSchema).optional(),
|
|
100
|
+
remove: external_zod_default().array(kindSchema).optional()
|
|
101
|
+
})
|
|
102
|
+
]));
|
|
103
|
+
const dependency_rules_resolveDependencyRules = (config = {})=>{
|
|
104
|
+
const entries = moduleKinds.map((kind)=>{
|
|
105
|
+
const override = config[kind];
|
|
106
|
+
if (Array.isArray(override)) return [
|
|
107
|
+
kind,
|
|
108
|
+
new Set(override)
|
|
109
|
+
];
|
|
110
|
+
const kinds = new Set([
|
|
111
|
+
...defaultDependencies[kind],
|
|
112
|
+
...override?.add ?? []
|
|
113
|
+
]);
|
|
114
|
+
for (const removed of override?.remove ?? [])kinds.delete(removed);
|
|
115
|
+
return [
|
|
116
|
+
kind,
|
|
117
|
+
kinds
|
|
118
|
+
];
|
|
119
|
+
});
|
|
120
|
+
return Object.fromEntries(entries);
|
|
121
|
+
};
|
|
122
|
+
dependency_rules_resolveDependencyRules();
|
|
123
|
+
const external_node_fs_namespaceObject = require("node:fs");
|
|
124
|
+
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
125
|
+
const pendingFiles = new Map();
|
|
126
|
+
const pendingFolders = new Set();
|
|
127
|
+
const pendingMoves = new Map();
|
|
128
|
+
const pendingDeletions = new Map();
|
|
129
|
+
const filesToOverwrite = ()=>[
|
|
130
|
+
...pendingFiles
|
|
131
|
+
].filter(([filePath, { replacesFile }])=>replacesFile && external_node_fs_default().existsSync(filePath)).map(([filePath])=>filePath);
|
|
132
|
+
const discardPendingChanges = ()=>{
|
|
133
|
+
pendingFolders.clear();
|
|
134
|
+
pendingFiles.clear();
|
|
135
|
+
pendingMoves.clear();
|
|
136
|
+
pendingDeletions.clear();
|
|
137
|
+
};
|
|
138
|
+
const removeEmptyFolders = (folderPath, stopAt)=>{
|
|
139
|
+
let current = folderPath;
|
|
140
|
+
while(current.startsWith(`${stopAt}${external_node_path_default().sep}`) && external_node_fs_default().existsSync(current) && !external_node_fs_default().readdirSync(current).length){
|
|
141
|
+
external_node_fs_default().rmdirSync(current);
|
|
142
|
+
current = external_node_path_default().dirname(current);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
const writePendingChanges = ()=>{
|
|
146
|
+
for (const folderPath of pendingFolders)external_node_fs_default().mkdirSync(folderPath, {
|
|
147
|
+
recursive: true
|
|
148
|
+
});
|
|
149
|
+
for (const [filePath, { content }] of pendingFiles){
|
|
150
|
+
external_node_fs_default().mkdirSync(external_node_path_default().dirname(filePath), {
|
|
151
|
+
recursive: true
|
|
152
|
+
});
|
|
153
|
+
external_node_fs_default().writeFileSync(filePath, content, 'utf8');
|
|
154
|
+
}
|
|
155
|
+
for (const [targetPath, { sourcePath }] of pendingMoves){
|
|
156
|
+
external_node_fs_default().mkdirSync(external_node_path_default().dirname(targetPath), {
|
|
157
|
+
recursive: true
|
|
158
|
+
});
|
|
159
|
+
external_node_fs_default().renameSync(sourcePath, targetPath);
|
|
160
|
+
}
|
|
161
|
+
for (const filePath of pendingDeletions.keys())external_node_fs_default().rmSync(filePath, {
|
|
162
|
+
force: true
|
|
163
|
+
});
|
|
164
|
+
for (const [filePath, stopAt] of pendingDeletions)removeEmptyFolders(external_node_path_default().dirname(filePath), stopAt);
|
|
165
|
+
for (const { sourcePath, stopAt } of pendingMoves.values())removeEmptyFolders(external_node_path_default().dirname(sourcePath), stopAt);
|
|
166
|
+
discardPendingChanges();
|
|
167
|
+
};
|
|
168
|
+
class FileSystemItem {
|
|
169
|
+
path;
|
|
170
|
+
constructor(path){
|
|
171
|
+
this.path = path;
|
|
172
|
+
}
|
|
173
|
+
subitem = (relativePath)=>new this.constructor(external_node_path_default().resolve(this.path, ...relativePath));
|
|
174
|
+
get exists() {
|
|
175
|
+
return external_node_fs_default().existsSync(this.path);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
class file_system_Folder extends FileSystemItem {
|
|
179
|
+
createIfNotExisted = ()=>{
|
|
180
|
+
pendingFolders.add(this.path);
|
|
181
|
+
};
|
|
182
|
+
get content() {
|
|
183
|
+
if (!this.exists) return {
|
|
184
|
+
subfolderNames: [],
|
|
185
|
+
fileNames: []
|
|
186
|
+
};
|
|
187
|
+
const content = external_node_fs_default().readdirSync(this.path, {
|
|
188
|
+
withFileTypes: true
|
|
189
|
+
});
|
|
190
|
+
return {
|
|
191
|
+
subfolderNames: content.filter((x)=>x.isDirectory()).map((x)=>x.name),
|
|
192
|
+
fileNames: content.filter((x)=>!x.isDirectory()).map((x)=>external_node_path_default().parse(x.name).name)
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
get name() {
|
|
196
|
+
return external_node_path_default().basename(this.path);
|
|
197
|
+
}
|
|
198
|
+
createFile = (name, content)=>{
|
|
199
|
+
this.createIfNotExisted();
|
|
200
|
+
const file = new file_system_File(this.path).subitem([
|
|
201
|
+
name
|
|
202
|
+
]);
|
|
203
|
+
file.data = content;
|
|
204
|
+
return file;
|
|
205
|
+
};
|
|
206
|
+
file = (name)=>{
|
|
207
|
+
this.createIfNotExisted();
|
|
208
|
+
const file = new file_system_File(this.path).subitem([
|
|
209
|
+
name
|
|
210
|
+
]);
|
|
211
|
+
return file;
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
class file_system_File extends FileSystemItem {
|
|
215
|
+
get exists() {
|
|
216
|
+
return pendingFiles.has(this.path) || pendingMoves.has(this.path) || external_node_fs_default().existsSync(this.path) && !pendingDeletions.has(this.path);
|
|
217
|
+
}
|
|
218
|
+
delete = (stopAt)=>{
|
|
219
|
+
pendingDeletions.set(this.path, stopAt);
|
|
220
|
+
};
|
|
221
|
+
moveTo = (targetPath, stopAt)=>{
|
|
222
|
+
pendingMoves.set(targetPath, {
|
|
223
|
+
sourcePath: this.path,
|
|
224
|
+
stopAt
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
get data() {
|
|
228
|
+
const pendingFile = pendingFiles.get(this.path);
|
|
229
|
+
if (pendingFile) return pendingFile.content;
|
|
230
|
+
if (!this.exists) throw new Error('File does not exist');
|
|
231
|
+
return external_node_fs_default().readFileSync(this.path, 'utf-8');
|
|
232
|
+
}
|
|
233
|
+
set data(content) {
|
|
234
|
+
pendingFiles.set(this.path, {
|
|
235
|
+
content,
|
|
236
|
+
replacesFile: true
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
update = (content)=>{
|
|
240
|
+
pendingFiles.set(this.path, {
|
|
241
|
+
content,
|
|
242
|
+
replacesFile: pendingFiles.get(this.path)?.replacesFile ?? false
|
|
243
|
+
});
|
|
244
|
+
};
|
|
245
|
+
addLine = (newLine, separator = '\n')=>{
|
|
246
|
+
const content = this.exists ? this.data : '';
|
|
247
|
+
pendingFiles.set(this.path, {
|
|
248
|
+
content: [
|
|
249
|
+
content.trim(),
|
|
250
|
+
newLine.trim()
|
|
251
|
+
].filter((x)=>!!x).join(separator),
|
|
252
|
+
replacesFile: pendingFiles.get(this.path)?.replacesFile ?? false
|
|
253
|
+
});
|
|
254
|
+
};
|
|
255
|
+
addLineIfMissing = (newLine, separator = '\n')=>{
|
|
256
|
+
const alreadyAdded = this.exists && this.data.split('\n').some((line)=>line.trim() === newLine.trim());
|
|
257
|
+
if (!alreadyAdded) this.addLine(newLine, separator);
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
class project_root_ProjectRoot {
|
|
261
|
+
path;
|
|
262
|
+
constructor(){
|
|
263
|
+
let dir = process.cwd();
|
|
264
|
+
while(dir !== external_node_path_default().parse(dir).root){
|
|
265
|
+
if (external_node_fs_default().existsSync(external_node_path_default().join(dir, 'package.json'))) {
|
|
266
|
+
this.path = dir;
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
dir = external_node_path_default().dirname(dir);
|
|
270
|
+
}
|
|
271
|
+
throw new Error('No package.json was found');
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
const lintChecks = [
|
|
275
|
+
'context-isolation',
|
|
276
|
+
'shared-kernel',
|
|
277
|
+
'layers',
|
|
278
|
+
'dependencies',
|
|
279
|
+
'react',
|
|
280
|
+
'clock'
|
|
281
|
+
];
|
|
282
|
+
const configFileName = 'domain-first.project-structure.config.json';
|
|
283
|
+
const configSchema = external_zod_default().object({
|
|
284
|
+
rootFolder: external_zod_default().string(),
|
|
285
|
+
domainFirstPackages: external_zod_default().array(external_zod_default()["enum"]([
|
|
286
|
+
'@domain-first/types',
|
|
287
|
+
'@domain-first/errors',
|
|
288
|
+
'@domain-first/handlers',
|
|
289
|
+
'@domain-first/wire',
|
|
290
|
+
'@domain-first/handlers-rest'
|
|
291
|
+
])),
|
|
292
|
+
defaultPersistenceLayerImplementation: external_zod_default().string(),
|
|
293
|
+
withInMemoryDb: external_zod_default().boolean().optional(),
|
|
294
|
+
useReact: external_zod_default().boolean(),
|
|
295
|
+
storybookFramework: external_zod_default().string().optional(),
|
|
296
|
+
testingLibrary: external_zod_default().string().optional(),
|
|
297
|
+
rules: external_zod_default().object({
|
|
298
|
+
dependencies: dependencyRulesSchema.optional(),
|
|
299
|
+
lint: external_zod_default().partialRecord(external_zod_default()["enum"](lintChecks), external_zod_default().boolean()).optional()
|
|
300
|
+
}).optional()
|
|
301
|
+
});
|
|
302
|
+
class config_file_ConfigFile {
|
|
303
|
+
data;
|
|
304
|
+
constructor(){
|
|
305
|
+
const filePath = config_file_ConfigFile.path;
|
|
306
|
+
const file = new file_system_File(filePath);
|
|
307
|
+
const configObject = JSON.parse(file.data);
|
|
308
|
+
this.data = configSchema.parse(configObject);
|
|
309
|
+
}
|
|
310
|
+
static get Instance() {
|
|
311
|
+
return new config_file_ConfigFile();
|
|
312
|
+
}
|
|
313
|
+
static get path() {
|
|
314
|
+
const { path: root } = new project_root_ProjectRoot();
|
|
315
|
+
return external_node_path_default().resolve(root, configFileName);
|
|
316
|
+
}
|
|
317
|
+
static get exists() {
|
|
318
|
+
return new file_system_File(config_file_ConfigFile.path).exists;
|
|
319
|
+
}
|
|
320
|
+
static write = (config)=>{
|
|
321
|
+
new file_system_File(config_file_ConfigFile.path).data = JSON.stringify(config, null, '\t');
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
const save_pending_changes_savePendingChanges = async ()=>{
|
|
325
|
+
const overwrittenFiles = filesToOverwrite();
|
|
326
|
+
if (overwrittenFiles.length) {
|
|
327
|
+
const root = new project_root_ProjectRoot().path;
|
|
328
|
+
console.log('These files already exist and will be overwritten:');
|
|
329
|
+
for (const filePath of overwrittenFiles)console.log(` ${external_node_path_default().relative(root, filePath)}`);
|
|
330
|
+
const overwrite = await (0, prompts_namespaceObject.confirm)({
|
|
331
|
+
message: 'Overwrite them?',
|
|
332
|
+
default: false
|
|
333
|
+
});
|
|
334
|
+
if (!overwrite) {
|
|
335
|
+
discardPendingChanges();
|
|
336
|
+
console.log('Cancelled: nothing was written.');
|
|
337
|
+
return false;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
writePendingChanges();
|
|
341
|
+
return true;
|
|
342
|
+
};
|
|
343
|
+
require("node:module");
|
|
344
|
+
const stripJsonComments = (source)=>source.replace(/("(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g, (_, text)=>text ? text : '').replace(/,(\s*[}\]])/g, '$1');
|
|
345
|
+
class unknown_format_naming_UnknownFormatNaming {
|
|
346
|
+
rawSource;
|
|
347
|
+
camelCase;
|
|
348
|
+
PascalCase;
|
|
349
|
+
constructor(rawSource){
|
|
350
|
+
this.rawSource = rawSource;
|
|
351
|
+
const source = rawSource.trim();
|
|
352
|
+
if (!source.includes('-')) {
|
|
353
|
+
this.camelCase = source.substring(0, 1).toLowerCase() + source.substring(1);
|
|
354
|
+
this.PascalCase = source.substring(0, 1).toUpperCase() + source.substring(1);
|
|
355
|
+
}
|
|
356
|
+
const words = source.split('-').filter((word)=>!!word);
|
|
357
|
+
this.camelCase = words.map((word, index)=>0 === index ? word.toLowerCase() : word[0].toUpperCase() + word.slice(1).toLowerCase()).join('');
|
|
358
|
+
this.PascalCase = words.map((word)=>word[0].toUpperCase() + word.slice(1).toLowerCase()).join('');
|
|
359
|
+
}
|
|
360
|
+
get fileName() {
|
|
361
|
+
return this.rawSource;
|
|
362
|
+
}
|
|
363
|
+
get variableName() {
|
|
364
|
+
return this.camelCase;
|
|
365
|
+
}
|
|
366
|
+
get ClassName() {
|
|
367
|
+
return this.PascalCase;
|
|
368
|
+
}
|
|
369
|
+
get withSpaces() {
|
|
370
|
+
return this.fileName.replaceAll('-', ' ');
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
const splitSegments = (rawSource)=>rawSource.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment);
|
|
374
|
+
class NestedName {
|
|
375
|
+
folders;
|
|
376
|
+
folderName;
|
|
377
|
+
fileName;
|
|
378
|
+
ClassName;
|
|
379
|
+
classNameSegments;
|
|
380
|
+
constructor(rawSource){
|
|
381
|
+
const segments = splitSegments(rawSource);
|
|
382
|
+
this.folders = segments.slice(0, -1);
|
|
383
|
+
this.folderName = new unknown_format_naming_UnknownFormatNaming(segments.at(-1) ?? '').fileName;
|
|
384
|
+
this.fileName = segments.map((segment)=>new unknown_format_naming_UnknownFormatNaming(segment).fileName).join('-');
|
|
385
|
+
this.classNameSegments = segments.map((segment)=>new unknown_format_naming_UnknownFormatNaming(segment).ClassName);
|
|
386
|
+
this.ClassName = this.classNameSegments.join('');
|
|
387
|
+
}
|
|
388
|
+
static validate = (rawSource)=>{
|
|
389
|
+
const segments = splitSegments(rawSource);
|
|
390
|
+
if (!segments.length) return 'Name is required';
|
|
391
|
+
if (segments.some((segment)=>'.' === segment || '..' === segment)) return 'Use a path relative to the folder, without "." or ".."';
|
|
392
|
+
return true;
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
const scaffold_react_page_reactPageContent = (ClassName, { imports = [], body = '<></>' } = {})=>`
|
|
396
|
+
${[
|
|
397
|
+
...imports,
|
|
398
|
+
"import { type FC } from 'react'"
|
|
399
|
+
].join('\n')}
|
|
400
|
+
|
|
401
|
+
export type ${ClassName}PageProps = {}
|
|
402
|
+
|
|
403
|
+
export const ${ClassName}Page: FC<${ClassName}PageProps> = (props) => {
|
|
404
|
+
return ${body}
|
|
405
|
+
}
|
|
406
|
+
`.trim();
|
|
407
|
+
const scaffoldReactPage = async (presentationReactFolder)=>{
|
|
408
|
+
const name = await (0, prompts_namespaceObject.input)({
|
|
409
|
+
message: 'Provide name (folders split by "/"):',
|
|
410
|
+
validate: NestedName.validate
|
|
411
|
+
});
|
|
412
|
+
const { folders, ClassName, fileName } = new NestedName(name);
|
|
413
|
+
presentationReactFolder.subitem([
|
|
414
|
+
'pages',
|
|
415
|
+
...folders
|
|
416
|
+
]).createFile(`${fileName}-page.tsx`, scaffold_react_page_reactPageContent(ClassName));
|
|
417
|
+
};
|
|
418
|
+
const ignoredFolders = new Set([
|
|
419
|
+
'node_modules',
|
|
420
|
+
'.git',
|
|
421
|
+
'.next',
|
|
422
|
+
'dist',
|
|
423
|
+
'build',
|
|
424
|
+
'out',
|
|
425
|
+
'coverage',
|
|
426
|
+
'storybook-static'
|
|
427
|
+
]);
|
|
428
|
+
const codeExtension = /\.(?:tsx?|mts|cts|jsx?|mjs|cjs|mdx)$/;
|
|
429
|
+
const escapeRegExp = (value)=>value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
430
|
+
const react_module_move_walk = (folder)=>{
|
|
431
|
+
if (!external_node_fs_default().existsSync(folder)) return [];
|
|
432
|
+
return external_node_fs_default().readdirSync(folder, {
|
|
433
|
+
withFileTypes: true
|
|
434
|
+
}).flatMap((entry)=>{
|
|
435
|
+
const entryPath = external_node_path_default().join(folder, entry.name);
|
|
436
|
+
if (entry.isDirectory()) return ignoredFolders.has(entry.name) ? [] : react_module_move_walk(entryPath);
|
|
437
|
+
return entry.isFile() ? [
|
|
438
|
+
entryPath
|
|
439
|
+
] : [];
|
|
440
|
+
});
|
|
441
|
+
};
|
|
442
|
+
const toPosix = (value)=>value.split(external_node_path_default().sep).join('/');
|
|
443
|
+
const nestedName = (folders, fileBase)=>{
|
|
444
|
+
const prefix = `${folders.join('-')}-`;
|
|
445
|
+
const last = folders.length && fileBase.startsWith(prefix) ? fileBase.slice(prefix.length) : fileBase;
|
|
446
|
+
return [
|
|
447
|
+
...folders,
|
|
448
|
+
last
|
|
449
|
+
].join('/');
|
|
450
|
+
};
|
|
451
|
+
const declaredClassName = (filePath, suffix, name)=>{
|
|
452
|
+
const content = external_node_fs_default().readFileSync(filePath, 'utf8');
|
|
453
|
+
const declared = content.match(new RegExp(`export\\s+(?:const|function)\\s+(\\w+)${suffix}\\b`))?.[1];
|
|
454
|
+
return declared ?? new NestedName(name).ClassName;
|
|
455
|
+
};
|
|
456
|
+
const findReactModules = (reactFolder, kind)=>{
|
|
457
|
+
const modules = 'page' === kind ? react_module_move_walk(external_node_path_default().join(reactFolder, 'pages')).filter((file)=>file.endsWith('-page.tsx')).map((file)=>{
|
|
458
|
+
const folders = external_node_path_default().relative(external_node_path_default().join(reactFolder, 'pages'), external_node_path_default().dirname(file)).split(external_node_path_default().sep).filter((segment)=>!!segment);
|
|
459
|
+
const fileBase = external_node_path_default().basename(file, '-page.tsx');
|
|
460
|
+
const name = nestedName(folders, fileBase);
|
|
461
|
+
return {
|
|
462
|
+
kind,
|
|
463
|
+
name,
|
|
464
|
+
path: file,
|
|
465
|
+
fileBase,
|
|
466
|
+
ClassName: declaredClassName(file, 'Page', name)
|
|
467
|
+
};
|
|
468
|
+
}) : react_module_move_walk(external_node_path_default().join(reactFolder, 'widgets')).filter((file)=>file.endsWith('-widget.tsx')).map((file)=>{
|
|
469
|
+
const folder = external_node_path_default().dirname(file);
|
|
470
|
+
const name = toPosix(external_node_path_default().relative(external_node_path_default().join(reactFolder, 'widgets'), folder));
|
|
471
|
+
return {
|
|
472
|
+
kind,
|
|
473
|
+
name,
|
|
474
|
+
path: folder,
|
|
475
|
+
fileBase: external_node_path_default().basename(file, '-widget.tsx'),
|
|
476
|
+
ClassName: declaredClassName(file, 'Widget', name)
|
|
477
|
+
};
|
|
478
|
+
});
|
|
479
|
+
return modules.sort((a, b)=>a.name.localeCompare(b.name));
|
|
480
|
+
};
|
|
481
|
+
const react_module_move_targetPath = (reactFolder, module, rawName)=>{
|
|
482
|
+
const { folders, folderName, fileName } = new NestedName(rawName);
|
|
483
|
+
return 'page' === module.kind ? external_node_path_default().join(reactFolder, 'pages', ...folders, `${fileName}-page.tsx`) : external_node_path_default().join(reactFolder, 'widgets', ...folders, folderName);
|
|
484
|
+
};
|
|
485
|
+
const validateMove = (reactFolder, module, rawName)=>{
|
|
486
|
+
const nameError = NestedName.validate(rawName);
|
|
487
|
+
if (true !== nameError) return nameError;
|
|
488
|
+
const target = react_module_move_targetPath(reactFolder, module, rawName);
|
|
489
|
+
if (target !== module.path && external_node_fs_default().existsSync(target)) return `${external_node_path_default().relative(reactFolder, target)} already exists`;
|
|
490
|
+
if (target.startsWith(`${module.path}${external_node_path_default().sep}`)) return 'A widget cannot be moved into itself';
|
|
491
|
+
return true;
|
|
492
|
+
};
|
|
493
|
+
const readAliases = (projectRoot)=>{
|
|
494
|
+
const tsconfig = external_node_path_default().join(projectRoot, 'tsconfig.json');
|
|
495
|
+
if (!external_node_fs_default().existsSync(tsconfig)) return [];
|
|
496
|
+
try {
|
|
497
|
+
const { compilerOptions = {} } = JSON.parse(stripJsonComments(external_node_fs_default().readFileSync(tsconfig, 'utf8')));
|
|
498
|
+
const base = external_node_path_default().resolve(projectRoot, compilerOptions.baseUrl ?? '.');
|
|
499
|
+
return Object.entries(compilerOptions.paths ?? {}).filter(([pattern, targets])=>pattern.endsWith('*') && targets[0]?.endsWith('*')).map(([pattern, [target]])=>({
|
|
500
|
+
prefix: pattern.slice(0, -1),
|
|
501
|
+
target: external_node_path_default().resolve(base, target.slice(0, -1))
|
|
502
|
+
}));
|
|
503
|
+
} catch {
|
|
504
|
+
return [];
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
const specifierPattern = /(\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\brequire\s*\(\s*|\bmock\s*\(\s*)(['"])([^'"\n]+)\2/g;
|
|
508
|
+
const reExportPattern = /\bexport\s+(?:type\s+)?(?:\*(?:\s+as\s+[\w$]+)?|\{[^}]*\})\s*from\s*(['"])([^'"\n]+)\1/g;
|
|
509
|
+
const importPaths = (file)=>{
|
|
510
|
+
const withoutExtension = file.replace(codeExtension, '');
|
|
511
|
+
return 'index' === external_node_path_default().basename(withoutExtension) ? [
|
|
512
|
+
withoutExtension,
|
|
513
|
+
external_node_path_default().dirname(withoutExtension)
|
|
514
|
+
] : [
|
|
515
|
+
withoutExtension
|
|
516
|
+
];
|
|
517
|
+
};
|
|
518
|
+
const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
519
|
+
const newName = new NestedName(rawName);
|
|
520
|
+
const target = react_module_move_targetPath(reactFolder, module, rawName);
|
|
521
|
+
const newClassName = newName.ClassName;
|
|
522
|
+
const renameFile = (name)=>name.replace(new RegExp(`^(use-)?${escapeRegExp(module.fileBase)}(?=[-.])`), (_, use = '')=>`${use}${newName.fileName}`);
|
|
523
|
+
const oldFolder = 'page' === module.kind ? external_node_path_default().dirname(module.path) : module.path;
|
|
524
|
+
const newFolder = 'page' === module.kind ? external_node_path_default().dirname(target) : target;
|
|
525
|
+
const ownsPath = (candidate)=>'page' === module.kind ? external_node_path_default().dirname(candidate) === oldFolder && new RegExp(`^${escapeRegExp(module.fileBase)}-page(?:\\.|$)`).test(external_node_path_default().basename(candidate)) : candidate === oldFolder || candidate.startsWith(`${oldFolder}${external_node_path_default().sep}`);
|
|
526
|
+
const movedPath = (candidate)=>{
|
|
527
|
+
if (!ownsPath(candidate)) return;
|
|
528
|
+
const segments = external_node_path_default().relative(oldFolder, candidate).split(external_node_path_default().sep);
|
|
529
|
+
const last = segments.length - 1;
|
|
530
|
+
segments[last] = renameFile(segments[last]);
|
|
531
|
+
return external_node_path_default().join(newFolder, ...segments);
|
|
532
|
+
};
|
|
533
|
+
const moduleFiles = 'page' === module.kind ? external_node_fs_default().readdirSync(oldFolder).map((name)=>external_node_path_default().join(oldFolder, name)).filter((file)=>external_node_fs_default().statSync(file).isFile() && ownsPath(file)) : react_module_move_walk(oldFolder);
|
|
534
|
+
const moves = new Map(moduleFiles.map((file)=>[
|
|
535
|
+
file,
|
|
536
|
+
movedPath(file) ?? file
|
|
537
|
+
]));
|
|
538
|
+
const aliases = readAliases(projectRoot);
|
|
539
|
+
const resolve = (specifier, fromFile)=>{
|
|
540
|
+
if (specifier.startsWith('.')) return {
|
|
541
|
+
resolved: external_node_path_default().resolve(external_node_path_default().dirname(fromFile), specifier),
|
|
542
|
+
alias: void 0
|
|
543
|
+
};
|
|
544
|
+
const alias = aliases.find(({ prefix })=>specifier.startsWith(prefix));
|
|
545
|
+
return alias ? {
|
|
546
|
+
resolved: external_node_path_default().resolve(alias.target, specifier.slice(alias.prefix.length)),
|
|
547
|
+
alias
|
|
548
|
+
} : void 0;
|
|
549
|
+
};
|
|
550
|
+
const specifierFor = (fromFile, toPath, alias)=>{
|
|
551
|
+
const aliased = alias && toPosix(external_node_path_default().relative(alias.target, toPath));
|
|
552
|
+
if (aliased && !aliased.startsWith('..')) return `${alias.prefix}${aliased}`;
|
|
553
|
+
const relative = toPosix(external_node_path_default().relative(external_node_path_default().dirname(fromFile), toPath));
|
|
554
|
+
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
555
|
+
};
|
|
556
|
+
const suffixes = 'page' === module.kind ? 'Page' : 'Widget|UIModel';
|
|
557
|
+
const classPattern = new RegExp(`(?<![\\w$])(use)?${escapeRegExp(module.ClassName)}(?=${suffixes})`, 'g');
|
|
558
|
+
const oldTitle = `Widgets/${module.name.split('/').map((segment)=>new NestedName(segment).ClassName).join('/')}`;
|
|
559
|
+
const titlePattern = new RegExp(`(['"\`])${escapeRegExp(oldTitle)}\\1`, 'g');
|
|
560
|
+
const newTitle = [
|
|
561
|
+
'Widgets',
|
|
562
|
+
...newName.classNameSegments
|
|
563
|
+
].join('/');
|
|
564
|
+
const codeFiles = new Map(react_module_move_walk(projectRoot).filter((file)=>codeExtension.test(file)).map((file)=>[
|
|
565
|
+
file,
|
|
566
|
+
external_node_fs_default().readFileSync(file, 'utf8')
|
|
567
|
+
]));
|
|
568
|
+
const barrels = new Set();
|
|
569
|
+
const isBarrel = (resolved)=>barrels.has(resolved.replace(codeExtension, ''));
|
|
570
|
+
for(let found = true; found;){
|
|
571
|
+
found = false;
|
|
572
|
+
for (const [file, content] of codeFiles){
|
|
573
|
+
if (moves.has(file) || isBarrel(file)) continue;
|
|
574
|
+
const reExportsModule = [
|
|
575
|
+
...content.matchAll(reExportPattern)
|
|
576
|
+
].some(([, , specifier])=>{
|
|
577
|
+
const resolution = resolve(specifier, file);
|
|
578
|
+
return !!resolution && (!!movedPath(resolution.resolved) || isBarrel(resolution.resolved));
|
|
579
|
+
});
|
|
580
|
+
if (reExportsModule) {
|
|
581
|
+
for (const importPath of importPaths(file))barrels.add(importPath);
|
|
582
|
+
found = true;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
const rewrite = (content, oldFile, newFile)=>{
|
|
587
|
+
let referencesModule = false;
|
|
588
|
+
const rewritten = content.replace(specifierPattern, (match, keyword, quote, specifier)=>{
|
|
589
|
+
const resolution = resolve(specifier, oldFile);
|
|
590
|
+
if (!resolution) return match;
|
|
591
|
+
const moved = movedPath(resolution.resolved);
|
|
592
|
+
if (moved || isBarrel(resolution.resolved)) referencesModule = true;
|
|
593
|
+
if (!moved && oldFile === newFile) return match;
|
|
594
|
+
const next = specifierFor(newFile, moved ?? resolution.resolved, resolution.alias);
|
|
595
|
+
return `${keyword}${quote}${next}${quote}`;
|
|
596
|
+
});
|
|
597
|
+
if (!referencesModule && !moves.has(oldFile)) return content;
|
|
598
|
+
const renamed = rewritten.replace(classPattern, (_, use = '')=>`${use}${newClassName}`);
|
|
599
|
+
return moves.has(oldFile) && 'widget' === module.kind ? renamed.replace(titlePattern, (_, quote)=>`${quote}${newTitle}${quote}`) : renamed;
|
|
600
|
+
};
|
|
601
|
+
for (const [file, newFile] of moves)if (!codeFiles.has(file) && newFile !== file) new file_system_File(file).moveTo(newFile, reactFolder);
|
|
602
|
+
const updated = [];
|
|
603
|
+
for (const [file, content] of codeFiles){
|
|
604
|
+
const newFile = moves.get(file);
|
|
605
|
+
const next = rewrite(content, file, newFile ?? file);
|
|
606
|
+
if (newFile && newFile !== file) {
|
|
607
|
+
new file_system_File(newFile).data = next;
|
|
608
|
+
new file_system_File(file).delete(reactFolder);
|
|
609
|
+
} else if (next !== content) {
|
|
610
|
+
new file_system_File(file).update(next);
|
|
611
|
+
if (!newFile) updated.push(file);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
return {
|
|
615
|
+
moves: [
|
|
616
|
+
...moves
|
|
617
|
+
].filter(([from, to])=>from !== to),
|
|
618
|
+
updated
|
|
619
|
+
};
|
|
620
|
+
};
|
|
621
|
+
const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
622
|
+
const reactFolder = presentationReactFolder.path;
|
|
623
|
+
const modules = findReactModules(reactFolder, kind);
|
|
624
|
+
if (!modules.length) return void console.log(`No ${kind}s generated by df-react were found.`);
|
|
625
|
+
const module = await (0, prompts_namespaceObject.select)({
|
|
626
|
+
message: 'page' === kind ? 'Page:' : 'Widget:',
|
|
627
|
+
choices: modules.map((value)=>({
|
|
628
|
+
name: value.name,
|
|
629
|
+
value,
|
|
630
|
+
description: external_node_path_default().relative(reactFolder, value.path)
|
|
631
|
+
}))
|
|
632
|
+
});
|
|
633
|
+
const name = await (0, prompts_namespaceObject.input)({
|
|
634
|
+
message: 'New name (folders split by "/"):',
|
|
635
|
+
default: module.name,
|
|
636
|
+
validate: (value)=>validateMove(reactFolder, module, value)
|
|
637
|
+
});
|
|
638
|
+
const root = new project_root_ProjectRoot().path;
|
|
639
|
+
const { moves, updated } = moveReactModule(root, reactFolder, module, name);
|
|
640
|
+
if (!moves.length && !updated.length) return void console.log('Nothing to change.');
|
|
641
|
+
const relative = (file)=>external_node_path_default().relative(root, file);
|
|
642
|
+
console.log([
|
|
643
|
+
'Files to move:',
|
|
644
|
+
...moves.map(([from, to])=>` ${relative(from)} → ${relative(to)}`),
|
|
645
|
+
...updated.length ? [
|
|
646
|
+
'Files with updated imports:',
|
|
647
|
+
...updated.map((file)=>` ${relative(file)}`)
|
|
648
|
+
] : []
|
|
649
|
+
].join('\n'));
|
|
650
|
+
if (!await (0, prompts_namespaceObject.confirm)({
|
|
651
|
+
message: 'Apply?',
|
|
652
|
+
default: true
|
|
653
|
+
})) {
|
|
654
|
+
discardPendingChanges();
|
|
655
|
+
console.log('Cancelled: nothing was written.');
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
const scaffoldReactSharedHook = async (presentationReactFolder)=>{
|
|
659
|
+
const name = await (0, prompts_namespaceObject.input)({
|
|
660
|
+
message: 'Name without "use" (e.g. debounce): '
|
|
661
|
+
});
|
|
662
|
+
const { ClassName, fileName } = new unknown_format_naming_UnknownFormatNaming(name.trim().replace(/^use-/, ''));
|
|
663
|
+
presentationReactFolder.subitem([
|
|
664
|
+
'hooks'
|
|
665
|
+
]).createFile(`use-${fileName}.ts`, `
|
|
666
|
+
export const use${ClassName} = () => {
|
|
667
|
+
return {}
|
|
668
|
+
}
|
|
669
|
+
`.trim());
|
|
670
|
+
};
|
|
671
|
+
const scaffoldReactUIKitComponent = async (presentationReactFolder)=>{
|
|
672
|
+
const name = await (0, prompts_namespaceObject.input)({
|
|
673
|
+
message: 'Name: '
|
|
674
|
+
});
|
|
675
|
+
const { ClassName, fileName } = new unknown_format_naming_UnknownFormatNaming(name);
|
|
676
|
+
const componentFolder = presentationReactFolder.subitem([
|
|
677
|
+
'ui-kit',
|
|
678
|
+
fileName
|
|
679
|
+
]);
|
|
680
|
+
componentFolder.createFile('index.ts', `export * from './${fileName}'`);
|
|
681
|
+
componentFolder.createFile(`${fileName}.tsx`, `
|
|
682
|
+
import { type FC } from 'react'
|
|
683
|
+
|
|
684
|
+
export type ${ClassName}Props = {}
|
|
685
|
+
|
|
686
|
+
export const ${ClassName}: FC<${ClassName}Props> = (props) => {
|
|
687
|
+
return <></>
|
|
688
|
+
}
|
|
689
|
+
`.trim());
|
|
690
|
+
const { storybookFramework } = config_file_ConfigFile.Instance.data;
|
|
691
|
+
if (storybookFramework) componentFolder.createFile(`${fileName}.stories.tsx`, `
|
|
692
|
+
import type { Meta, StoryObj } from '${storybookFramework}'
|
|
693
|
+
import { ${ClassName} } from './${fileName}'
|
|
694
|
+
|
|
695
|
+
const meta = {
|
|
696
|
+
title: 'UI-kit/${ClassName}',
|
|
697
|
+
component: ${ClassName}
|
|
698
|
+
} satisfies Meta<typeof ${ClassName}>
|
|
699
|
+
|
|
700
|
+
export default meta
|
|
701
|
+
|
|
702
|
+
type Story = StoryObj<typeof meta>
|
|
703
|
+
|
|
704
|
+
export const Default: Story = {
|
|
705
|
+
args: {}
|
|
706
|
+
}
|
|
707
|
+
`.trim());
|
|
708
|
+
};
|
|
709
|
+
const scaffoldReactWidget = async (presentationReactFolder)=>{
|
|
710
|
+
const widgetName = await (0, prompts_namespaceObject.input)({
|
|
711
|
+
message: 'Name (folders split by "/"): ',
|
|
712
|
+
validate: NestedName.validate
|
|
713
|
+
});
|
|
714
|
+
const widgetType = await (0, prompts_namespaceObject.select)({
|
|
715
|
+
choices: [
|
|
716
|
+
'monolithic',
|
|
717
|
+
'with separated ui',
|
|
718
|
+
'headless'
|
|
719
|
+
],
|
|
720
|
+
message: 'Type: '
|
|
721
|
+
});
|
|
722
|
+
const { folders, folderName, ClassName, fileName, classNameSegments } = new NestedName(widgetName);
|
|
723
|
+
const folder = presentationReactFolder.subitem([
|
|
724
|
+
'widgets',
|
|
725
|
+
...folders,
|
|
726
|
+
folderName
|
|
727
|
+
]);
|
|
728
|
+
const storyTitle = [
|
|
729
|
+
'Widgets',
|
|
730
|
+
...classNameSegments
|
|
731
|
+
].join('/');
|
|
732
|
+
const widgetFileName = `${fileName}-widget`;
|
|
733
|
+
const uiFileName = `${fileName}-widget-ui`;
|
|
734
|
+
const uiModelFileName = `use-${fileName}-ui-model`;
|
|
735
|
+
folder.createFile('index.ts', `export * from './${widgetFileName}'`);
|
|
736
|
+
switch(widgetType){
|
|
737
|
+
case 'monolithic':
|
|
738
|
+
folder.createFile(`${widgetFileName}.tsx`, `
|
|
739
|
+
import { type FC } from 'react'
|
|
740
|
+
|
|
741
|
+
export type ${ClassName}WidgetProps = {}
|
|
742
|
+
|
|
743
|
+
export const ${ClassName}Widget: FC<${ClassName}WidgetProps> = (props) => {
|
|
744
|
+
return <></>
|
|
745
|
+
}
|
|
746
|
+
`.trim());
|
|
747
|
+
break;
|
|
748
|
+
case 'with separated ui':
|
|
749
|
+
{
|
|
750
|
+
folder.createFile('types.ts', `
|
|
751
|
+
export type ${ClassName}WidgetProps = { }
|
|
752
|
+
|
|
753
|
+
export type ${ClassName}WidgetUIProps = { }
|
|
754
|
+
`.trim());
|
|
755
|
+
folder.createFile(`${widgetFileName}.tsx`, `
|
|
756
|
+
import { type FC } from 'react'
|
|
757
|
+
import type { ${ClassName}WidgetProps } from './types'
|
|
758
|
+
import { ${ClassName}WidgetUI } from './ui/${uiFileName}'
|
|
759
|
+
import { use${ClassName}UIModel } from './hooks/${uiModelFileName}'
|
|
760
|
+
|
|
761
|
+
export const ${ClassName}Widget: FC<${ClassName}WidgetProps> = (props) => {
|
|
762
|
+
const uiModel = use${ClassName}UIModel(props)
|
|
763
|
+
return <${ClassName}WidgetUI {...uiModel} />
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
export type { ${ClassName}WidgetProps }
|
|
767
|
+
`.trim());
|
|
768
|
+
folder.subitem([
|
|
769
|
+
'ui'
|
|
770
|
+
]).createFile(`${uiFileName}.tsx`, `
|
|
771
|
+
import { FC } from 'react'
|
|
772
|
+
import type { ${ClassName}WidgetUIProps } from '../types'
|
|
773
|
+
|
|
774
|
+
export const ${ClassName}WidgetUI: FC<${ClassName}WidgetUIProps> = (props) => {
|
|
775
|
+
return <></>
|
|
776
|
+
}
|
|
777
|
+
`.trim());
|
|
778
|
+
const { storybookFramework } = config_file_ConfigFile.Instance.data;
|
|
779
|
+
if (storybookFramework) folder.subitem([
|
|
780
|
+
'ui'
|
|
781
|
+
]).createFile(`${uiFileName}.stories.tsx`, `
|
|
782
|
+
import type { Meta, StoryObj } from '${storybookFramework}'
|
|
783
|
+
import { ${ClassName}WidgetUI } from './${uiFileName}'
|
|
784
|
+
|
|
785
|
+
const meta = {
|
|
786
|
+
title: '${storyTitle}',
|
|
787
|
+
component: ${ClassName}WidgetUI
|
|
788
|
+
} satisfies Meta<typeof ${ClassName}WidgetUI>
|
|
789
|
+
|
|
790
|
+
export default meta
|
|
791
|
+
|
|
792
|
+
type Story = StoryObj<typeof meta>
|
|
793
|
+
|
|
794
|
+
export const Default: Story = {
|
|
795
|
+
args: {}
|
|
796
|
+
}
|
|
797
|
+
`.trim());
|
|
798
|
+
folder.subitem([
|
|
799
|
+
'hooks'
|
|
800
|
+
]).createFile(`${uiModelFileName}.ts`, `
|
|
801
|
+
import type { ${ClassName}WidgetProps, ${ClassName}WidgetUIProps } from '../types'
|
|
802
|
+
|
|
803
|
+
export const use${ClassName}UIModel = (widgetProps: ${ClassName}WidgetProps): ${ClassName}WidgetUIProps => {
|
|
804
|
+
return {}
|
|
805
|
+
}
|
|
806
|
+
`.trim());
|
|
807
|
+
break;
|
|
808
|
+
}
|
|
809
|
+
case 'headless':
|
|
810
|
+
folder.createFile('types.ts', `
|
|
811
|
+
import { type FC } from 'react'
|
|
812
|
+
|
|
813
|
+
export type ${ClassName}WidgetUIProps = { }
|
|
814
|
+
|
|
815
|
+
export type ${ClassName}WidgetProps = {
|
|
816
|
+
UI: FC<${ClassName}WidgetUIProps>
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
`.trim());
|
|
820
|
+
folder.createFile(`${widgetFileName}.tsx`, `
|
|
821
|
+
import { type FC } from 'react'
|
|
822
|
+
import type { ${ClassName}WidgetProps } from './types'
|
|
823
|
+
import { use${ClassName}UIModel } from './hooks/${uiModelFileName}'
|
|
824
|
+
|
|
825
|
+
export const ${ClassName}Widget: FC<${ClassName}WidgetProps> = (props) => {
|
|
826
|
+
const uiModel = use${ClassName}UIModel(props)
|
|
827
|
+
return <props.UI {...uiModel} />
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
export type { ${ClassName}WidgetProps }
|
|
831
|
+
`.trim());
|
|
832
|
+
folder.subitem([
|
|
833
|
+
'hooks'
|
|
834
|
+
]).createFile(`${uiModelFileName}.ts`, `
|
|
835
|
+
import type { ${ClassName}WidgetProps, ${ClassName}WidgetUIProps } from '../types'
|
|
836
|
+
|
|
837
|
+
export const use${ClassName}UIModel = (widgetProps: Omit<${ClassName}WidgetProps, 'UI'>): ${ClassName}WidgetUIProps => {
|
|
838
|
+
return {}
|
|
839
|
+
}
|
|
840
|
+
`.trim());
|
|
841
|
+
break;
|
|
842
|
+
}
|
|
843
|
+
};
|
|
844
|
+
const help = `Usage: df-react
|
|
845
|
+
|
|
846
|
+
Scaffolds React modules of a Domain-First project: pages, widgets, UI-kit
|
|
847
|
+
components and shared hooks, and moves or renames pages and widgets.
|
|
848
|
+
Needs "useReact": true in domain-first.project-structure.config.json.
|
|
849
|
+
|
|
850
|
+
Options:
|
|
851
|
+
-h, --help show this help`;
|
|
852
|
+
const { values } = (0, external_node_util_namespaceObject.parseArgs)({
|
|
853
|
+
options: {
|
|
854
|
+
help: {
|
|
855
|
+
type: 'boolean',
|
|
856
|
+
short: 'h',
|
|
857
|
+
default: false
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
});
|
|
861
|
+
if (values.help) {
|
|
862
|
+
console.log(help);
|
|
863
|
+
process.exit(0);
|
|
864
|
+
}
|
|
865
|
+
if (!config_file_ConfigFile.exists) {
|
|
866
|
+
console.log('No domain-first.project-structure.config.json found: run df-init first to initialize the project.');
|
|
867
|
+
process.exit(1);
|
|
868
|
+
}
|
|
869
|
+
if (!config_file_ConfigFile.Instance.data.useReact) {
|
|
870
|
+
console.log('React is off: set "useReact": true in domain-first.project-structure.config.json or add Storybook with df-integration.');
|
|
871
|
+
process.exit(1);
|
|
872
|
+
}
|
|
873
|
+
const main = async ()=>{
|
|
874
|
+
const reactFolder = new file_system_Folder(new project_root_ProjectRoot().path).subitem([
|
|
875
|
+
config_file_ConfigFile.Instance.data.rootFolder,
|
|
876
|
+
'presentation',
|
|
877
|
+
'react'
|
|
878
|
+
]);
|
|
879
|
+
const action = await (0, prompts_namespaceObject.select)({
|
|
880
|
+
message: 'Module: ',
|
|
881
|
+
choices: [
|
|
882
|
+
'New widget',
|
|
883
|
+
'New page',
|
|
884
|
+
'New UI-kit component',
|
|
885
|
+
'New shared hook',
|
|
886
|
+
'Move or rename widget',
|
|
887
|
+
'Move or rename page'
|
|
888
|
+
]
|
|
889
|
+
});
|
|
890
|
+
switch(action){
|
|
891
|
+
case 'New widget':
|
|
892
|
+
return void await scaffoldReactWidget(reactFolder);
|
|
893
|
+
case 'New page':
|
|
894
|
+
return void await scaffoldReactPage(reactFolder);
|
|
895
|
+
case 'New UI-kit component':
|
|
896
|
+
return void await scaffoldReactUIKitComponent(reactFolder);
|
|
897
|
+
case 'New shared hook':
|
|
898
|
+
return void await scaffoldReactSharedHook(reactFolder);
|
|
899
|
+
case 'Move or rename widget':
|
|
900
|
+
return void await moveReactModuleUseCase(reactFolder, 'widget');
|
|
901
|
+
case 'Move or rename page':
|
|
902
|
+
return void await moveReactModuleUseCase(reactFolder, 'page');
|
|
903
|
+
default:
|
|
904
|
+
return;
|
|
905
|
+
}
|
|
906
|
+
};
|
|
907
|
+
const run = async ()=>{
|
|
908
|
+
await main();
|
|
909
|
+
await save_pending_changes_savePendingChanges();
|
|
910
|
+
};
|
|
911
|
+
run();
|
|
912
|
+
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
913
|
+
Object.defineProperty(exports, '__esModule', {
|
|
914
|
+
value: true
|
|
915
|
+
});
|