@domain-first/project-structure 2.12.0 → 2.13.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 +76 -0
- package/dist/file-system.d.ts +1 -0
- package/dist/index.cjs +356 -16
- package/dist/index.js +356 -16
- package/dist/integrations/index.d.ts +4 -0
- package/dist/integrations/missing-domain-first-packages.d.ts +1 -0
- package/dist/integrations/missing-domain-first-packages.spec.d.ts +1 -0
- package/dist/integrations/package-scripts.d.ts +2 -0
- package/dist/integrations/package-scripts.spec.d.ts +1 -0
- package/dist/integrations/prisma.d.ts +6 -0
- package/dist/integrations/prisma.spec.d.ts +1 -0
- package/dist/integrations/storybook.d.ts +9 -0
- package/dist/save-pending-changes.d.ts +2 -0
- package/dist/use-cases/add-integration.d.ts +1 -0
- package/dist/use-cases/add-integration.spec.d.ts +1 -0
- package/dist/use-cases/index.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -203,6 +203,82 @@ Enable `useReact` and choose **Scaffold React module** from the main menu. Modul
|
|
|
203
203
|
|
|
204
204
|
Page and widget names can include folders split by `/`. For example, a page named `admin/panel/users` is created at `pages/admin/panel/users-page.tsx` as `AdminPanelUsersPage`, and a widget with the same name at `widgets/admin/panel/users/` as `AdminPanelUsersWidget` with the story title `Widgets/Admin/Panel/Users`. File names use only the last segment; code names use the whole path.
|
|
205
205
|
|
|
206
|
+
### Project integrations
|
|
207
|
+
|
|
208
|
+
Choose **Add integration → Storybook (React + Vite)** to configure Storybook.
|
|
209
|
+
The integration creates `main.ts` and `preview.ts` under
|
|
210
|
+
`<rootFolder>/presentation/react/.storybook`, enables React scaffolding and sets
|
|
211
|
+
`storybookFramework` to `@storybook/react-vite` for future generated stories.
|
|
212
|
+
It uses relative story paths and configures the Vite alias `@` to the absolute
|
|
213
|
+
project root (the directory containing `package.json`), computed at runtime
|
|
214
|
+
from the config location. Add project CSS to `preview.ts` with relative imports
|
|
215
|
+
or `@/` imports. The setup includes `@vitejs/plugin-react`.
|
|
216
|
+
|
|
217
|
+
It adds these package scripts, with paths adjusted to your `rootFolder`:
|
|
218
|
+
|
|
219
|
+
```json
|
|
220
|
+
{
|
|
221
|
+
"storybook": "storybook dev -p 6006 -c \"src/presentation/react/.storybook\"",
|
|
222
|
+
"build-storybook": "storybook build -c \"src/presentation/react/.storybook\" -o \"src/presentation/react/storybook-static\""
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Existing unrelated scripts and package fields are preserved. If a script name
|
|
227
|
+
already has a different command, choose to keep it, replace it, or use another
|
|
228
|
+
name. Identical generated configs and scripts are skipped on subsequent runs;
|
|
229
|
+
changed config files use the usual overwrite confirmation. Cancelling before
|
|
230
|
+
writing leaves all files unchanged.
|
|
231
|
+
|
|
232
|
+
After writing, the CLI prints npm commands for missing dependencies and the
|
|
233
|
+
selected scripts. It does not install packages or execute scripts. Install commands omit version constraints for Storybook, its React + Vite
|
|
234
|
+
framework, Vite and the React plugin; existing dependency versions are preserved
|
|
235
|
+
and must be compatible with those packages. Generate a
|
|
236
|
+
UI-kit component or a widget with separated UI to add your first story. The
|
|
237
|
+
static build goes to `<rootFolder>/presentation/react/storybook-static`.
|
|
238
|
+
|
|
239
|
+
### Missing domain-first packages
|
|
240
|
+
|
|
241
|
+
Choose **Add integration → Missing domain-first packages** to compare
|
|
242
|
+
`domainFirstPackages` in the configuration with `dependencies`, `devDependencies`
|
|
243
|
+
and `optionalDependencies` in the project's `package.json`. The CLI prints one
|
|
244
|
+
`npm i` command for missing packages, without version constraints. If none are
|
|
245
|
+
missing, it reports that all configured packages are already declared. This
|
|
246
|
+
checks declared dependencies, not the contents of `node_modules`, and does not
|
|
247
|
+
modify files or install packages.
|
|
248
|
+
|
|
249
|
+
### Prisma 8 (PostgreSQL)
|
|
250
|
+
|
|
251
|
+
Choose **Add integration → Prisma 8 (PostgreSQL, RC)**. The preset creates
|
|
252
|
+
`<rootFolder>/shared/infrastructure/prisma/prisma.config.ts` and a starter
|
|
253
|
+
`contract.prisma`. Existing contracts are preserved, including your models.
|
|
254
|
+
|
|
255
|
+
You can optionally create `PrismaInfrastructureService` in
|
|
256
|
+
`shared/infrastructure/services`; it exposes `orm`, uses the Temporal polyfill,
|
|
257
|
+
and reuses the client across development hot reloads. When `@domain-first/wire`
|
|
258
|
+
is enabled, the integration also creates its wiring factory. A separate prompt
|
|
259
|
+
lets you make `prisma` the default persistence implementation.
|
|
260
|
+
|
|
261
|
+
The integration adds three scripts, all pointing to the generated config:
|
|
262
|
+
|
|
263
|
+
- `prisma:emit`: emit `contract.json` and `contract.d.ts`.
|
|
264
|
+
- `prisma:migration:plan`: emit the contract, then plan a migration.
|
|
265
|
+
- `prisma:migration:apply`: apply migrations and advance the `db` ref.
|
|
266
|
+
|
|
267
|
+
Script conflicts use the same keep/replace/rename flow as Storybook. File changes
|
|
268
|
+
are staged until overwrite confirmation; no packages are installed and no
|
|
269
|
+
commands connect to the database during scaffolding.
|
|
270
|
+
|
|
271
|
+
The printed install commands omit version constraints for `prisma`,
|
|
272
|
+
`@prisma/cli-engine`, `@prisma/orm-postgres`, `temporal-polyfill`, and `dotenv`. Already declared dependencies are kept. This is a PostgreSQL
|
|
273
|
+
preset for Prisma 8 RC, not a Prisma 7 migration tool.
|
|
274
|
+
|
|
275
|
+
After installing dependencies, configure `DATABASE_URL` (the CLI loads `.env`;
|
|
276
|
+
your application must load its runtime environment), add your models to the
|
|
277
|
+
contract and run the emit script before compiling or importing the service.
|
|
278
|
+
Use Node.js 22.18+, TypeScript 5.9+, ESM and JSON import support. Review planned
|
|
279
|
+
migrations before running the apply script. Generated contract files and
|
|
280
|
+
migration history are managed by Prisma, not by this scaffolder.
|
|
281
|
+
|
|
206
282
|
## Configuration
|
|
207
283
|
|
|
208
284
|
The project configuration is stored in `domain-first.project-structure.config.json`. Commit it to share generation settings with your team. For example:
|
package/dist/file-system.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Existing files a full rewrite would replace, whatever their content.
|
|
3
3
|
*/
|
|
4
4
|
export declare const filesToOverwrite: () => string[];
|
|
5
|
+
export declare const discardPendingChanges: () => void;
|
|
5
6
|
export declare const writePendingChanges: () => void;
|
|
6
7
|
declare class FileSystemItem {
|
|
7
8
|
readonly path: string;
|
package/dist/index.cjs
CHANGED
|
@@ -26,9 +26,9 @@ var __webpack_require__ = {};
|
|
|
26
26
|
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
27
27
|
})();
|
|
28
28
|
var __webpack_exports__ = {};
|
|
29
|
+
const prompts_namespaceObject = require("@inquirer/prompts");
|
|
29
30
|
const external_node_path_namespaceObject = require("node:path");
|
|
30
31
|
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
31
|
-
const prompts_namespaceObject = require("@inquirer/prompts");
|
|
32
32
|
const external_zod_namespaceObject = require("zod");
|
|
33
33
|
var external_zod_default = /*#__PURE__*/ __webpack_require__.n(external_zod_namespaceObject);
|
|
34
34
|
const external_node_fs_namespaceObject = require("node:fs");
|
|
@@ -38,6 +38,10 @@ const pendingFolders = new Set();
|
|
|
38
38
|
const filesToOverwrite = ()=>[
|
|
39
39
|
...pendingFiles
|
|
40
40
|
].filter(([filePath, { replacesFile }])=>replacesFile && external_node_fs_default().existsSync(filePath)).map(([filePath])=>filePath);
|
|
41
|
+
const discardPendingChanges = ()=>{
|
|
42
|
+
pendingFolders.clear();
|
|
43
|
+
pendingFiles.clear();
|
|
44
|
+
};
|
|
41
45
|
const writePendingChanges = ()=>{
|
|
42
46
|
for (const folderPath of pendingFolders)external_node_fs_default().mkdirSync(folderPath, {
|
|
43
47
|
recursive: true
|
|
@@ -48,8 +52,7 @@ const writePendingChanges = ()=>{
|
|
|
48
52
|
});
|
|
49
53
|
external_node_fs_default().writeFileSync(filePath, content, 'utf8');
|
|
50
54
|
}
|
|
51
|
-
|
|
52
|
-
pendingFiles.clear();
|
|
55
|
+
discardPendingChanges();
|
|
53
56
|
};
|
|
54
57
|
class FileSystemItem {
|
|
55
58
|
path;
|
|
@@ -185,6 +188,348 @@ class ConfigFile {
|
|
|
185
188
|
new File(ConfigFile.path).data = JSON.stringify(config, null, '\t');
|
|
186
189
|
};
|
|
187
190
|
}
|
|
191
|
+
const savePendingChanges = async ()=>{
|
|
192
|
+
const overwrittenFiles = filesToOverwrite();
|
|
193
|
+
if (overwrittenFiles.length) {
|
|
194
|
+
const root = new ProjectRoot().path;
|
|
195
|
+
console.log('These files already exist and will be overwritten:');
|
|
196
|
+
for (const filePath of overwrittenFiles)console.log(` ${external_node_path_default().relative(root, filePath)}`);
|
|
197
|
+
const overwrite = await (0, prompts_namespaceObject.confirm)({
|
|
198
|
+
message: 'Overwrite them?',
|
|
199
|
+
default: false
|
|
200
|
+
});
|
|
201
|
+
if (!overwrite) {
|
|
202
|
+
discardPendingChanges();
|
|
203
|
+
console.log('Cancelled: nothing was written.');
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
writePendingChanges();
|
|
208
|
+
return true;
|
|
209
|
+
};
|
|
210
|
+
const external_node_util_namespaceObject = require("node:util");
|
|
211
|
+
const missingDomainFirstPackages = ()=>{
|
|
212
|
+
const packages = ConfigFile.Instance.data.domainFirstPackages;
|
|
213
|
+
const manifest = JSON.parse(new File(external_node_path_default().join(new ProjectRoot().path, 'package.json')).data);
|
|
214
|
+
const dependencies = {
|
|
215
|
+
...manifest.dependencies,
|
|
216
|
+
...manifest.devDependencies,
|
|
217
|
+
...manifest.optionalDependencies
|
|
218
|
+
};
|
|
219
|
+
const missing = [
|
|
220
|
+
...new Set(packages)
|
|
221
|
+
].filter((name)=>!Object.hasOwn(dependencies, name));
|
|
222
|
+
return missing.length ? [
|
|
223
|
+
'Install missing domain-first packages (run from the project package directory):',
|
|
224
|
+
` npm i ${missing.join(' ')}`
|
|
225
|
+
] : [
|
|
226
|
+
'All configured domain-first packages are already declared in package.json.'
|
|
227
|
+
];
|
|
228
|
+
};
|
|
229
|
+
const addPackageScripts = async (file, additions)=>{
|
|
230
|
+
const original = file.data;
|
|
231
|
+
const manifest = JSON.parse(original);
|
|
232
|
+
const scripts = {
|
|
233
|
+
...manifest.scripts
|
|
234
|
+
};
|
|
235
|
+
const selected = {};
|
|
236
|
+
for (const [name, command] of Object.entries(additions)){
|
|
237
|
+
let target = name;
|
|
238
|
+
if (Object.hasOwn(scripts, name) && scripts[name] !== command) {
|
|
239
|
+
const action = await (0, prompts_namespaceObject.select)({
|
|
240
|
+
message: `Script "${name}" already exists: ${scripts[name]}`,
|
|
241
|
+
choices: [
|
|
242
|
+
'Keep existing',
|
|
243
|
+
'Replace',
|
|
244
|
+
'Use another name'
|
|
245
|
+
]
|
|
246
|
+
});
|
|
247
|
+
if ('Keep existing' === action) continue;
|
|
248
|
+
if ('Use another name' === action) target = await (0, prompts_namespaceObject.input)({
|
|
249
|
+
message: "New script name:",
|
|
250
|
+
validate: (value)=>!/^[a-zA-Z0-9:_-]+$/.test(value) || Object.hasOwn(scripts, value) || Object.hasOwn(additions, value) ? "Enter an unused script name (letters, numbers, :, _, -)." : true
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
scripts[target] = command;
|
|
254
|
+
selected[name] = target;
|
|
255
|
+
}
|
|
256
|
+
if (JSON.stringify(manifest.scripts) !== JSON.stringify(scripts)) {
|
|
257
|
+
manifest.scripts = scripts;
|
|
258
|
+
const indent = original.match(/\n([\t ]+)"/)?.[1] ?? ' ';
|
|
259
|
+
file.update(`${JSON.stringify(manifest, null, indent)}\n`);
|
|
260
|
+
}
|
|
261
|
+
return selected;
|
|
262
|
+
};
|
|
263
|
+
const runtimePackages = [
|
|
264
|
+
'@prisma/orm-postgres',
|
|
265
|
+
'temporal-polyfill',
|
|
266
|
+
'dotenv'
|
|
267
|
+
];
|
|
268
|
+
const developmentPackages = [
|
|
269
|
+
'prisma',
|
|
270
|
+
'@prisma/cli-engine'
|
|
271
|
+
];
|
|
272
|
+
const prismaScripts = (rootFolder)=>{
|
|
273
|
+
const config = JSON.stringify(external_node_path_default().posix.join(rootFolder.replaceAll('\\', '/'), 'shared/infrastructure/prisma/prisma.config.ts'));
|
|
274
|
+
const emit = `prisma contract emit --config ${config}`;
|
|
275
|
+
return {
|
|
276
|
+
'prisma:emit': emit,
|
|
277
|
+
'prisma:migration:plan': `${emit} && prisma migration plan --config ${config}`,
|
|
278
|
+
'prisma:migration:apply': `prisma db migrate --advance-ref db --config ${config}`
|
|
279
|
+
};
|
|
280
|
+
};
|
|
281
|
+
const prismaConfig = `import 'dotenv/config';
|
|
282
|
+
import { definePrismaConfig } from '@prisma/cli-engine';
|
|
283
|
+
import { defineConfig as ormConfig } from '@prisma/orm-postgres/config';
|
|
284
|
+
|
|
285
|
+
export default definePrismaConfig({
|
|
286
|
+
orm: ormConfig({
|
|
287
|
+
contract: './contract.prisma',
|
|
288
|
+
migrations: { dir: './migrations' },
|
|
289
|
+
db: {
|
|
290
|
+
connection: process.env.DATABASE_URL
|
|
291
|
+
}
|
|
292
|
+
})
|
|
293
|
+
});
|
|
294
|
+
`;
|
|
295
|
+
const prismaService = `import 'temporal-polyfill/global';
|
|
296
|
+
import postgres from '@prisma/orm-postgres/runtime';
|
|
297
|
+
import type {} from 'temporal-polyfill/types/global';
|
|
298
|
+
import type { Contract } from '../prisma/contract.d';
|
|
299
|
+
import contractJson from '../prisma/contract.json' with { type: 'json' };
|
|
300
|
+
|
|
301
|
+
type PrismaClient = ReturnType<typeof postgres<Contract>>;
|
|
302
|
+
|
|
303
|
+
const globalForPrisma = globalThis as typeof globalThis & {
|
|
304
|
+
prismaClient?: PrismaClient;
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
// Reuse the client across development hot reloads.
|
|
308
|
+
const prismaClient = globalForPrisma.prismaClient ??
|
|
309
|
+
postgres<Contract>({ contractJson, url: process.env.DATABASE_URL });
|
|
310
|
+
|
|
311
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
312
|
+
globalForPrisma.prismaClient = prismaClient;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
export class PrismaInfrastructureService {
|
|
316
|
+
readonly orm = prismaClient.orm.public;
|
|
317
|
+
}
|
|
318
|
+
`;
|
|
319
|
+
const prismaWiring = `import { wireClass } from '@domain-first/wire';
|
|
320
|
+
import { PrismaInfrastructureService } from '../../infrastructure/services/prisma-infrastructure-service';
|
|
321
|
+
|
|
322
|
+
export const wirePrismaInfrastructureService = wireClass(
|
|
323
|
+
PrismaInfrastructureService,
|
|
324
|
+
[]
|
|
325
|
+
);
|
|
326
|
+
`;
|
|
327
|
+
const stageFile = (filePath, content)=>{
|
|
328
|
+
const file = new File(filePath);
|
|
329
|
+
if (!file.exists || file.data !== content) file.data = content;
|
|
330
|
+
};
|
|
331
|
+
const addPrisma = async ()=>{
|
|
332
|
+
const config = ConfigFile.Instance.data;
|
|
333
|
+
const root = new ProjectRoot().path;
|
|
334
|
+
const manifestFile = new File(external_node_path_default().join(root, 'package.json'));
|
|
335
|
+
const manifest = JSON.parse(manifestFile.data);
|
|
336
|
+
const dependencies = {
|
|
337
|
+
...manifest.dependencies,
|
|
338
|
+
...manifest.devDependencies
|
|
339
|
+
};
|
|
340
|
+
const shared = external_node_path_default().resolve(root, config.rootFolder, 'shared');
|
|
341
|
+
const prismaFolder = external_node_path_default().join(shared, 'infrastructure/prisma');
|
|
342
|
+
if (dependencies['@prisma/client'] || dependencies.prisma && !/^[~^]?8\./.test(dependencies.prisma) || dependencies['@prisma/orm-mongo'] || dependencies['@prisma/orm-sqlite'] || [
|
|
343
|
+
external_node_path_default().join(root, 'prisma/schema.prisma'),
|
|
344
|
+
external_node_path_default().join(prismaFolder, 'schema.prisma')
|
|
345
|
+
].some((filePath)=>new File(filePath).exists)) throw new Error('This preset adds Prisma 8 for PostgreSQL. Migrate the existing Prisma setup separately before using it.');
|
|
346
|
+
const withService = await (0, prompts_namespaceObject.confirm)({
|
|
347
|
+
message: 'Create shared Prisma infrastructure service?',
|
|
348
|
+
default: true
|
|
349
|
+
});
|
|
350
|
+
const useByDefault = 'prisma' !== config.defaultPersistenceLayerImplementation && await (0, prompts_namespaceObject.confirm)({
|
|
351
|
+
message: 'Use prisma as the default persistence implementation?',
|
|
352
|
+
default: false
|
|
353
|
+
});
|
|
354
|
+
const selected = await addPackageScripts(manifestFile, prismaScripts(config.rootFolder));
|
|
355
|
+
stageFile(external_node_path_default().join(prismaFolder, 'prisma.config.ts'), prismaConfig);
|
|
356
|
+
const contract = new File(external_node_path_default().join(prismaFolder, 'contract.prisma'));
|
|
357
|
+
if (!contract.exists) contract.data = '// use prisma-8\n\n// Add your application models here before running prisma:emit.\n';
|
|
358
|
+
if (withService) {
|
|
359
|
+
stageFile(external_node_path_default().join(shared, 'infrastructure/services/prisma-infrastructure-service.ts'), prismaService);
|
|
360
|
+
if (config.domainFirstPackages.includes('@domain-first/wire')) stageFile(external_node_path_default().join(shared, 'wiring/infrastructure-services/wire-prisma-infrastructure-service.ts'), prismaWiring);
|
|
361
|
+
}
|
|
362
|
+
if (useByDefault) ConfigFile.write({
|
|
363
|
+
...config,
|
|
364
|
+
defaultPersistenceLayerImplementation: 'prisma'
|
|
365
|
+
});
|
|
366
|
+
const install = (packages, dev)=>{
|
|
367
|
+
const missing = packages.filter((name)=>!dependencies[name]);
|
|
368
|
+
return missing.length ? [
|
|
369
|
+
` npm install${dev ? ' --save-dev' : ''} ${missing.join(' ')}`
|
|
370
|
+
] : [];
|
|
371
|
+
};
|
|
372
|
+
const scriptCommand = (name)=>selected[name] ? `npm run ${selected[name]}` : prismaScripts(config.rootFolder)[name];
|
|
373
|
+
const relativeFolder = external_node_path_default().relative(root, prismaFolder).split(external_node_path_default().sep).join('/');
|
|
374
|
+
return [
|
|
375
|
+
'Prisma 8 configuration saved (PostgreSQL, RC preset).',
|
|
376
|
+
'Next steps (run from the project package directory):',
|
|
377
|
+
...install(runtimePackages, false),
|
|
378
|
+
...install(developmentPackages, true),
|
|
379
|
+
' Existing dependency versions were kept.',
|
|
380
|
+
' Use Node.js 22.18+ and TypeScript 5.9+ with ESM and JSON import support.',
|
|
381
|
+
' Set DATABASE_URL in your project environment (.env for the CLI); load it in the application runtime too.',
|
|
382
|
+
` Add your models to ${relativeFolder}/contract.prisma.`,
|
|
383
|
+
` Emit the contract before compiling or importing the service: ${scriptCommand('prisma:emit')}`,
|
|
384
|
+
` Plan migrations: ${scriptCommand('prisma:migration:plan')}`,
|
|
385
|
+
` Review the generated migrations, then apply: ${scriptCommand('prisma:migration:apply')}`
|
|
386
|
+
];
|
|
387
|
+
};
|
|
388
|
+
const storybookFiles = (relativeProjectRoot)=>({
|
|
389
|
+
'main.ts': `import { resolve } from 'node:path';
|
|
390
|
+
import react from '@vitejs/plugin-react';
|
|
391
|
+
import type { StorybookConfig } from '@storybook/react-vite';
|
|
392
|
+
|
|
393
|
+
const projectRoot = resolve(import.meta.dirname, ${JSON.stringify(relativeProjectRoot)});
|
|
394
|
+
|
|
395
|
+
const config: StorybookConfig = {
|
|
396
|
+
stories: ['../**/*.mdx', '../**/*.stories.@(ts|tsx)'],
|
|
397
|
+
framework: {
|
|
398
|
+
name: '@storybook/react-vite',
|
|
399
|
+
options: {}
|
|
400
|
+
},
|
|
401
|
+
core: {
|
|
402
|
+
disableTelemetry: true
|
|
403
|
+
},
|
|
404
|
+
async viteFinal(viteConfig) {
|
|
405
|
+
const { mergeConfig } = await import('vite');
|
|
406
|
+
|
|
407
|
+
return mergeConfig(viteConfig, {
|
|
408
|
+
plugins: [react()],
|
|
409
|
+
resolve: {
|
|
410
|
+
alias: {
|
|
411
|
+
'@': projectRoot
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
export default config;
|
|
419
|
+
`,
|
|
420
|
+
'preview.ts': `import type { Preview } from '@storybook/react-vite';
|
|
421
|
+
|
|
422
|
+
const preview: Preview = {
|
|
423
|
+
parameters: {
|
|
424
|
+
controls: {
|
|
425
|
+
matchers: {
|
|
426
|
+
color: /(background|color)$/i,
|
|
427
|
+
date: /Date$/i
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
export default preview;
|
|
434
|
+
`
|
|
435
|
+
});
|
|
436
|
+
const storybookScripts = (rootFolder)=>{
|
|
437
|
+
const folder = external_node_path_default().posix.join(rootFolder.replaceAll('\\', '/'), 'presentation/react');
|
|
438
|
+
const quote = (value)=>JSON.stringify(value);
|
|
439
|
+
return {
|
|
440
|
+
storybook: `storybook dev -p 6006 -c ${quote(`${folder}/.storybook`)}`,
|
|
441
|
+
'build-storybook': `storybook build -c ${quote(`${folder}/.storybook`)} -o ${quote(`${folder}/storybook-static`)}`
|
|
442
|
+
};
|
|
443
|
+
};
|
|
444
|
+
const addStorybook = async ()=>{
|
|
445
|
+
const config = ConfigFile.Instance.data;
|
|
446
|
+
if ((!config.useReact || config.storybookFramework && '@storybook/react-vite' !== config.storybookFramework) && !await (0, prompts_namespaceObject.confirm)({
|
|
447
|
+
message: 'Configure React scaffolding with @storybook/react-vite?',
|
|
448
|
+
default: false
|
|
449
|
+
})) return [];
|
|
450
|
+
const root = new ProjectRoot().path;
|
|
451
|
+
const manifestFile = new File(external_node_path_default().join(root, 'package.json'));
|
|
452
|
+
const manifest = JSON.parse(manifestFile.data);
|
|
453
|
+
const selected = await addPackageScripts(manifestFile, storybookScripts(config.rootFolder));
|
|
454
|
+
const folder = new Folder(root).subitem([
|
|
455
|
+
config.rootFolder,
|
|
456
|
+
'presentation',
|
|
457
|
+
'react',
|
|
458
|
+
'.storybook'
|
|
459
|
+
]);
|
|
460
|
+
for (const [name, content] of Object.entries(storybookFiles(external_node_path_default().relative(folder.path, root).split(external_node_path_default().sep).join('/')))){
|
|
461
|
+
const file = new File(external_node_path_default().join(folder.path, name));
|
|
462
|
+
if (!file.exists || file.data !== content) file.data = content;
|
|
463
|
+
}
|
|
464
|
+
if (!config.useReact || '@storybook/react-vite' !== config.storybookFramework) ConfigFile.write({
|
|
465
|
+
...config,
|
|
466
|
+
useReact: true,
|
|
467
|
+
storybookFramework: '@storybook/react-vite'
|
|
468
|
+
});
|
|
469
|
+
const dependencies = {
|
|
470
|
+
...manifest.dependencies,
|
|
471
|
+
...manifest.devDependencies
|
|
472
|
+
};
|
|
473
|
+
const missing = [
|
|
474
|
+
'storybook',
|
|
475
|
+
'@storybook/react-vite',
|
|
476
|
+
'vite',
|
|
477
|
+
'@vitejs/plugin-react'
|
|
478
|
+
].filter((name)=>!dependencies[name]);
|
|
479
|
+
const missingReact = [
|
|
480
|
+
'react',
|
|
481
|
+
'react-dom'
|
|
482
|
+
].filter((name)=>!dependencies[name]);
|
|
483
|
+
return [
|
|
484
|
+
'Storybook configuration saved (React + Vite).',
|
|
485
|
+
'Next steps (run from the project package directory):',
|
|
486
|
+
...missing.length ? [
|
|
487
|
+
` npm install --save-dev ${missing.join(' ')}`
|
|
488
|
+
] : [],
|
|
489
|
+
...missingReact.length ? [
|
|
490
|
+
` npm install ${missingReact.join(' ')}`
|
|
491
|
+
] : [],
|
|
492
|
+
' Existing dependency versions were kept; ensure Storybook packages are compatible.',
|
|
493
|
+
' Add your CSS imports to .storybook/preview.ts using relative paths or the @/ alias (project root).',
|
|
494
|
+
' Generate a UI-kit component or widget UI to create a story.',
|
|
495
|
+
...selected.storybook ? [
|
|
496
|
+
` npm run ${selected.storybook}`
|
|
497
|
+
] : [],
|
|
498
|
+
...selected['build-storybook'] ? [
|
|
499
|
+
` npm run ${selected['build-storybook']}`
|
|
500
|
+
] : []
|
|
501
|
+
];
|
|
502
|
+
};
|
|
503
|
+
const integrations = [
|
|
504
|
+
{
|
|
505
|
+
name: 'Storybook (React + Vite)',
|
|
506
|
+
run: addStorybook
|
|
507
|
+
},
|
|
508
|
+
{
|
|
509
|
+
name: 'Prisma 8 (PostgreSQL, RC)',
|
|
510
|
+
run: addPrisma
|
|
511
|
+
},
|
|
512
|
+
{
|
|
513
|
+
name: 'Missing domain-first packages',
|
|
514
|
+
run: missingDomainFirstPackages
|
|
515
|
+
}
|
|
516
|
+
];
|
|
517
|
+
const addIntegration = async ()=>{
|
|
518
|
+
const index = await (0, prompts_namespaceObject.select)({
|
|
519
|
+
message: 'Integration:',
|
|
520
|
+
choices: integrations.map((integration, value)=>({
|
|
521
|
+
name: integration.name,
|
|
522
|
+
value
|
|
523
|
+
}))
|
|
524
|
+
});
|
|
525
|
+
const nextSteps = await integrations[index].run();
|
|
526
|
+
if (await savePendingChanges()) {
|
|
527
|
+
if (nextSteps.length) console.log(nextSteps.map((line)=>/^\s*npm (?:i|install)\b/.test(line) ? (0, external_node_util_namespaceObject.styleText)([
|
|
528
|
+
'bold',
|
|
529
|
+
'cyan'
|
|
530
|
+
], line) : line).join('\n'));
|
|
531
|
+
}
|
|
532
|
+
};
|
|
188
533
|
const initializeUseCase = async ()=>{
|
|
189
534
|
const rootFolderName = await (0, prompts_namespaceObject.input)({
|
|
190
535
|
message: 'Root folder (use "/" for inner folders):',
|
|
@@ -2068,7 +2413,11 @@ const main = async ()=>{
|
|
|
2068
2413
|
name: 'Shared Layer',
|
|
2069
2414
|
action: 'Scaffold in bounded context'
|
|
2070
2415
|
},
|
|
2071
|
-
scaffoldNewBoundedContext
|
|
2416
|
+
scaffoldNewBoundedContext,
|
|
2417
|
+
{
|
|
2418
|
+
name: 'Add integration',
|
|
2419
|
+
action: 'Add integration'
|
|
2420
|
+
}
|
|
2072
2421
|
].filter((x)=>!!x);
|
|
2073
2422
|
const result = await (0, prompts_namespaceObject.select)({
|
|
2074
2423
|
message: '@domain-first/project-structure',
|
|
@@ -2076,6 +2425,8 @@ const main = async ()=>{
|
|
|
2076
2425
|
});
|
|
2077
2426
|
const { action, name } = options.find((x)=>x.name === result);
|
|
2078
2427
|
switch(action){
|
|
2428
|
+
case 'Add integration':
|
|
2429
|
+
return void await addIntegration();
|
|
2079
2430
|
case 'Scaffold React module':
|
|
2080
2431
|
{
|
|
2081
2432
|
const reactFolder = new Folder(rootPath).subitem([
|
|
@@ -2222,18 +2573,7 @@ const main = async ()=>{
|
|
|
2222
2573
|
};
|
|
2223
2574
|
const run = async ()=>{
|
|
2224
2575
|
await main();
|
|
2225
|
-
|
|
2226
|
-
if (overwrittenFiles.length) {
|
|
2227
|
-
const root = new ProjectRoot().path;
|
|
2228
|
-
console.log('These files already exist and will be overwritten:');
|
|
2229
|
-
for (const filePath of overwrittenFiles)console.log(` ${external_node_path_default().relative(root, filePath)}`);
|
|
2230
|
-
const overwrite = await (0, prompts_namespaceObject.confirm)({
|
|
2231
|
-
message: 'Overwrite them?',
|
|
2232
|
-
default: false
|
|
2233
|
-
});
|
|
2234
|
-
if (!overwrite) return void console.log('Cancelled: nothing was written.');
|
|
2235
|
-
}
|
|
2236
|
-
writePendingChanges();
|
|
2576
|
+
await savePendingChanges();
|
|
2237
2577
|
};
|
|
2238
2578
|
run();
|
|
2239
2579
|
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import node_path from "node:path";
|
|
3
2
|
import { Separator, checkbox as prompts_checkbox, confirm as prompts_confirm, input, select as prompts_select } from "@inquirer/prompts";
|
|
3
|
+
import node_path from "node:path";
|
|
4
4
|
import zod from "zod";
|
|
5
5
|
import node_fs from "node:fs";
|
|
6
|
+
import { styleText } from "node:util";
|
|
6
7
|
const pendingFiles = new Map();
|
|
7
8
|
const pendingFolders = new Set();
|
|
8
9
|
const filesToOverwrite = ()=>[
|
|
9
10
|
...pendingFiles
|
|
10
11
|
].filter(([filePath, { replacesFile }])=>replacesFile && node_fs.existsSync(filePath)).map(([filePath])=>filePath);
|
|
12
|
+
const discardPendingChanges = ()=>{
|
|
13
|
+
pendingFolders.clear();
|
|
14
|
+
pendingFiles.clear();
|
|
15
|
+
};
|
|
11
16
|
const writePendingChanges = ()=>{
|
|
12
17
|
for (const folderPath of pendingFolders)node_fs.mkdirSync(folderPath, {
|
|
13
18
|
recursive: true
|
|
@@ -18,8 +23,7 @@ const writePendingChanges = ()=>{
|
|
|
18
23
|
});
|
|
19
24
|
node_fs.writeFileSync(filePath, content, 'utf8');
|
|
20
25
|
}
|
|
21
|
-
|
|
22
|
-
pendingFiles.clear();
|
|
26
|
+
discardPendingChanges();
|
|
23
27
|
};
|
|
24
28
|
class FileSystemItem {
|
|
25
29
|
path;
|
|
@@ -155,6 +159,347 @@ class ConfigFile {
|
|
|
155
159
|
new File(ConfigFile.path).data = JSON.stringify(config, null, '\t');
|
|
156
160
|
};
|
|
157
161
|
}
|
|
162
|
+
const savePendingChanges = async ()=>{
|
|
163
|
+
const overwrittenFiles = filesToOverwrite();
|
|
164
|
+
if (overwrittenFiles.length) {
|
|
165
|
+
const root = new ProjectRoot().path;
|
|
166
|
+
console.log('These files already exist and will be overwritten:');
|
|
167
|
+
for (const filePath of overwrittenFiles)console.log(` ${node_path.relative(root, filePath)}`);
|
|
168
|
+
const overwrite = await prompts_confirm({
|
|
169
|
+
message: 'Overwrite them?',
|
|
170
|
+
default: false
|
|
171
|
+
});
|
|
172
|
+
if (!overwrite) {
|
|
173
|
+
discardPendingChanges();
|
|
174
|
+
console.log('Cancelled: nothing was written.');
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
writePendingChanges();
|
|
179
|
+
return true;
|
|
180
|
+
};
|
|
181
|
+
const missingDomainFirstPackages = ()=>{
|
|
182
|
+
const packages = ConfigFile.Instance.data.domainFirstPackages;
|
|
183
|
+
const manifest = JSON.parse(new File(node_path.join(new ProjectRoot().path, 'package.json')).data);
|
|
184
|
+
const dependencies = {
|
|
185
|
+
...manifest.dependencies,
|
|
186
|
+
...manifest.devDependencies,
|
|
187
|
+
...manifest.optionalDependencies
|
|
188
|
+
};
|
|
189
|
+
const missing = [
|
|
190
|
+
...new Set(packages)
|
|
191
|
+
].filter((name)=>!Object.hasOwn(dependencies, name));
|
|
192
|
+
return missing.length ? [
|
|
193
|
+
'Install missing domain-first packages (run from the project package directory):',
|
|
194
|
+
` npm i ${missing.join(' ')}`
|
|
195
|
+
] : [
|
|
196
|
+
'All configured domain-first packages are already declared in package.json.'
|
|
197
|
+
];
|
|
198
|
+
};
|
|
199
|
+
const addPackageScripts = async (file, additions)=>{
|
|
200
|
+
const original = file.data;
|
|
201
|
+
const manifest = JSON.parse(original);
|
|
202
|
+
const scripts = {
|
|
203
|
+
...manifest.scripts
|
|
204
|
+
};
|
|
205
|
+
const selected = {};
|
|
206
|
+
for (const [name, command] of Object.entries(additions)){
|
|
207
|
+
let target = name;
|
|
208
|
+
if (Object.hasOwn(scripts, name) && scripts[name] !== command) {
|
|
209
|
+
const action = await prompts_select({
|
|
210
|
+
message: `Script "${name}" already exists: ${scripts[name]}`,
|
|
211
|
+
choices: [
|
|
212
|
+
'Keep existing',
|
|
213
|
+
'Replace',
|
|
214
|
+
'Use another name'
|
|
215
|
+
]
|
|
216
|
+
});
|
|
217
|
+
if ('Keep existing' === action) continue;
|
|
218
|
+
if ('Use another name' === action) target = await input({
|
|
219
|
+
message: "New script name:",
|
|
220
|
+
validate: (value)=>!/^[a-zA-Z0-9:_-]+$/.test(value) || Object.hasOwn(scripts, value) || Object.hasOwn(additions, value) ? "Enter an unused script name (letters, numbers, :, _, -)." : true
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
scripts[target] = command;
|
|
224
|
+
selected[name] = target;
|
|
225
|
+
}
|
|
226
|
+
if (JSON.stringify(manifest.scripts) !== JSON.stringify(scripts)) {
|
|
227
|
+
manifest.scripts = scripts;
|
|
228
|
+
const indent = original.match(/\n([\t ]+)"/)?.[1] ?? ' ';
|
|
229
|
+
file.update(`${JSON.stringify(manifest, null, indent)}\n`);
|
|
230
|
+
}
|
|
231
|
+
return selected;
|
|
232
|
+
};
|
|
233
|
+
const runtimePackages = [
|
|
234
|
+
'@prisma/orm-postgres',
|
|
235
|
+
'temporal-polyfill',
|
|
236
|
+
'dotenv'
|
|
237
|
+
];
|
|
238
|
+
const developmentPackages = [
|
|
239
|
+
'prisma',
|
|
240
|
+
'@prisma/cli-engine'
|
|
241
|
+
];
|
|
242
|
+
const prismaScripts = (rootFolder)=>{
|
|
243
|
+
const config = JSON.stringify(node_path.posix.join(rootFolder.replaceAll('\\', '/'), 'shared/infrastructure/prisma/prisma.config.ts'));
|
|
244
|
+
const emit = `prisma contract emit --config ${config}`;
|
|
245
|
+
return {
|
|
246
|
+
'prisma:emit': emit,
|
|
247
|
+
'prisma:migration:plan': `${emit} && prisma migration plan --config ${config}`,
|
|
248
|
+
'prisma:migration:apply': `prisma db migrate --advance-ref db --config ${config}`
|
|
249
|
+
};
|
|
250
|
+
};
|
|
251
|
+
const prismaConfig = `import 'dotenv/config';
|
|
252
|
+
import { definePrismaConfig } from '@prisma/cli-engine';
|
|
253
|
+
import { defineConfig as ormConfig } from '@prisma/orm-postgres/config';
|
|
254
|
+
|
|
255
|
+
export default definePrismaConfig({
|
|
256
|
+
orm: ormConfig({
|
|
257
|
+
contract: './contract.prisma',
|
|
258
|
+
migrations: { dir: './migrations' },
|
|
259
|
+
db: {
|
|
260
|
+
connection: process.env.DATABASE_URL
|
|
261
|
+
}
|
|
262
|
+
})
|
|
263
|
+
});
|
|
264
|
+
`;
|
|
265
|
+
const prismaService = `import 'temporal-polyfill/global';
|
|
266
|
+
import postgres from '@prisma/orm-postgres/runtime';
|
|
267
|
+
import type {} from 'temporal-polyfill/types/global';
|
|
268
|
+
import type { Contract } from '../prisma/contract.d';
|
|
269
|
+
import contractJson from '../prisma/contract.json' with { type: 'json' };
|
|
270
|
+
|
|
271
|
+
type PrismaClient = ReturnType<typeof postgres<Contract>>;
|
|
272
|
+
|
|
273
|
+
const globalForPrisma = globalThis as typeof globalThis & {
|
|
274
|
+
prismaClient?: PrismaClient;
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
// Reuse the client across development hot reloads.
|
|
278
|
+
const prismaClient = globalForPrisma.prismaClient ??
|
|
279
|
+
postgres<Contract>({ contractJson, url: process.env.DATABASE_URL });
|
|
280
|
+
|
|
281
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
282
|
+
globalForPrisma.prismaClient = prismaClient;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export class PrismaInfrastructureService {
|
|
286
|
+
readonly orm = prismaClient.orm.public;
|
|
287
|
+
}
|
|
288
|
+
`;
|
|
289
|
+
const prismaWiring = `import { wireClass } from '@domain-first/wire';
|
|
290
|
+
import { PrismaInfrastructureService } from '../../infrastructure/services/prisma-infrastructure-service';
|
|
291
|
+
|
|
292
|
+
export const wirePrismaInfrastructureService = wireClass(
|
|
293
|
+
PrismaInfrastructureService,
|
|
294
|
+
[]
|
|
295
|
+
);
|
|
296
|
+
`;
|
|
297
|
+
const stageFile = (filePath, content)=>{
|
|
298
|
+
const file = new File(filePath);
|
|
299
|
+
if (!file.exists || file.data !== content) file.data = content;
|
|
300
|
+
};
|
|
301
|
+
const addPrisma = async ()=>{
|
|
302
|
+
const config = ConfigFile.Instance.data;
|
|
303
|
+
const root = new ProjectRoot().path;
|
|
304
|
+
const manifestFile = new File(node_path.join(root, 'package.json'));
|
|
305
|
+
const manifest = JSON.parse(manifestFile.data);
|
|
306
|
+
const dependencies = {
|
|
307
|
+
...manifest.dependencies,
|
|
308
|
+
...manifest.devDependencies
|
|
309
|
+
};
|
|
310
|
+
const shared = node_path.resolve(root, config.rootFolder, 'shared');
|
|
311
|
+
const prismaFolder = node_path.join(shared, 'infrastructure/prisma');
|
|
312
|
+
if (dependencies['@prisma/client'] || dependencies.prisma && !/^[~^]?8\./.test(dependencies.prisma) || dependencies['@prisma/orm-mongo'] || dependencies['@prisma/orm-sqlite'] || [
|
|
313
|
+
node_path.join(root, 'prisma/schema.prisma'),
|
|
314
|
+
node_path.join(prismaFolder, 'schema.prisma')
|
|
315
|
+
].some((filePath)=>new File(filePath).exists)) throw new Error('This preset adds Prisma 8 for PostgreSQL. Migrate the existing Prisma setup separately before using it.');
|
|
316
|
+
const withService = await prompts_confirm({
|
|
317
|
+
message: 'Create shared Prisma infrastructure service?',
|
|
318
|
+
default: true
|
|
319
|
+
});
|
|
320
|
+
const useByDefault = 'prisma' !== config.defaultPersistenceLayerImplementation && await prompts_confirm({
|
|
321
|
+
message: 'Use prisma as the default persistence implementation?',
|
|
322
|
+
default: false
|
|
323
|
+
});
|
|
324
|
+
const selected = await addPackageScripts(manifestFile, prismaScripts(config.rootFolder));
|
|
325
|
+
stageFile(node_path.join(prismaFolder, 'prisma.config.ts'), prismaConfig);
|
|
326
|
+
const contract = new File(node_path.join(prismaFolder, 'contract.prisma'));
|
|
327
|
+
if (!contract.exists) contract.data = '// use prisma-8\n\n// Add your application models here before running prisma:emit.\n';
|
|
328
|
+
if (withService) {
|
|
329
|
+
stageFile(node_path.join(shared, 'infrastructure/services/prisma-infrastructure-service.ts'), prismaService);
|
|
330
|
+
if (config.domainFirstPackages.includes('@domain-first/wire')) stageFile(node_path.join(shared, 'wiring/infrastructure-services/wire-prisma-infrastructure-service.ts'), prismaWiring);
|
|
331
|
+
}
|
|
332
|
+
if (useByDefault) ConfigFile.write({
|
|
333
|
+
...config,
|
|
334
|
+
defaultPersistenceLayerImplementation: 'prisma'
|
|
335
|
+
});
|
|
336
|
+
const install = (packages, dev)=>{
|
|
337
|
+
const missing = packages.filter((name)=>!dependencies[name]);
|
|
338
|
+
return missing.length ? [
|
|
339
|
+
` npm install${dev ? ' --save-dev' : ''} ${missing.join(' ')}`
|
|
340
|
+
] : [];
|
|
341
|
+
};
|
|
342
|
+
const scriptCommand = (name)=>selected[name] ? `npm run ${selected[name]}` : prismaScripts(config.rootFolder)[name];
|
|
343
|
+
const relativeFolder = node_path.relative(root, prismaFolder).split(node_path.sep).join('/');
|
|
344
|
+
return [
|
|
345
|
+
'Prisma 8 configuration saved (PostgreSQL, RC preset).',
|
|
346
|
+
'Next steps (run from the project package directory):',
|
|
347
|
+
...install(runtimePackages, false),
|
|
348
|
+
...install(developmentPackages, true),
|
|
349
|
+
' Existing dependency versions were kept.',
|
|
350
|
+
' Use Node.js 22.18+ and TypeScript 5.9+ with ESM and JSON import support.',
|
|
351
|
+
' Set DATABASE_URL in your project environment (.env for the CLI); load it in the application runtime too.',
|
|
352
|
+
` Add your models to ${relativeFolder}/contract.prisma.`,
|
|
353
|
+
` Emit the contract before compiling or importing the service: ${scriptCommand('prisma:emit')}`,
|
|
354
|
+
` Plan migrations: ${scriptCommand('prisma:migration:plan')}`,
|
|
355
|
+
` Review the generated migrations, then apply: ${scriptCommand('prisma:migration:apply')}`
|
|
356
|
+
];
|
|
357
|
+
};
|
|
358
|
+
const storybookFiles = (relativeProjectRoot)=>({
|
|
359
|
+
'main.ts': `import { resolve } from 'node:path';
|
|
360
|
+
import react from '@vitejs/plugin-react';
|
|
361
|
+
import type { StorybookConfig } from '@storybook/react-vite';
|
|
362
|
+
|
|
363
|
+
const projectRoot = resolve(import.meta.dirname, ${JSON.stringify(relativeProjectRoot)});
|
|
364
|
+
|
|
365
|
+
const config: StorybookConfig = {
|
|
366
|
+
stories: ['../**/*.mdx', '../**/*.stories.@(ts|tsx)'],
|
|
367
|
+
framework: {
|
|
368
|
+
name: '@storybook/react-vite',
|
|
369
|
+
options: {}
|
|
370
|
+
},
|
|
371
|
+
core: {
|
|
372
|
+
disableTelemetry: true
|
|
373
|
+
},
|
|
374
|
+
async viteFinal(viteConfig) {
|
|
375
|
+
const { mergeConfig } = await import('vite');
|
|
376
|
+
|
|
377
|
+
return mergeConfig(viteConfig, {
|
|
378
|
+
plugins: [react()],
|
|
379
|
+
resolve: {
|
|
380
|
+
alias: {
|
|
381
|
+
'@': projectRoot
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
export default config;
|
|
389
|
+
`,
|
|
390
|
+
'preview.ts': `import type { Preview } from '@storybook/react-vite';
|
|
391
|
+
|
|
392
|
+
const preview: Preview = {
|
|
393
|
+
parameters: {
|
|
394
|
+
controls: {
|
|
395
|
+
matchers: {
|
|
396
|
+
color: /(background|color)$/i,
|
|
397
|
+
date: /Date$/i
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
export default preview;
|
|
404
|
+
`
|
|
405
|
+
});
|
|
406
|
+
const storybookScripts = (rootFolder)=>{
|
|
407
|
+
const folder = node_path.posix.join(rootFolder.replaceAll('\\', '/'), 'presentation/react');
|
|
408
|
+
const quote = (value)=>JSON.stringify(value);
|
|
409
|
+
return {
|
|
410
|
+
storybook: `storybook dev -p 6006 -c ${quote(`${folder}/.storybook`)}`,
|
|
411
|
+
'build-storybook': `storybook build -c ${quote(`${folder}/.storybook`)} -o ${quote(`${folder}/storybook-static`)}`
|
|
412
|
+
};
|
|
413
|
+
};
|
|
414
|
+
const addStorybook = async ()=>{
|
|
415
|
+
const config = ConfigFile.Instance.data;
|
|
416
|
+
if ((!config.useReact || config.storybookFramework && '@storybook/react-vite' !== config.storybookFramework) && !await prompts_confirm({
|
|
417
|
+
message: 'Configure React scaffolding with @storybook/react-vite?',
|
|
418
|
+
default: false
|
|
419
|
+
})) return [];
|
|
420
|
+
const root = new ProjectRoot().path;
|
|
421
|
+
const manifestFile = new File(node_path.join(root, 'package.json'));
|
|
422
|
+
const manifest = JSON.parse(manifestFile.data);
|
|
423
|
+
const selected = await addPackageScripts(manifestFile, storybookScripts(config.rootFolder));
|
|
424
|
+
const folder = new Folder(root).subitem([
|
|
425
|
+
config.rootFolder,
|
|
426
|
+
'presentation',
|
|
427
|
+
'react',
|
|
428
|
+
'.storybook'
|
|
429
|
+
]);
|
|
430
|
+
for (const [name, content] of Object.entries(storybookFiles(node_path.relative(folder.path, root).split(node_path.sep).join('/')))){
|
|
431
|
+
const file = new File(node_path.join(folder.path, name));
|
|
432
|
+
if (!file.exists || file.data !== content) file.data = content;
|
|
433
|
+
}
|
|
434
|
+
if (!config.useReact || '@storybook/react-vite' !== config.storybookFramework) ConfigFile.write({
|
|
435
|
+
...config,
|
|
436
|
+
useReact: true,
|
|
437
|
+
storybookFramework: '@storybook/react-vite'
|
|
438
|
+
});
|
|
439
|
+
const dependencies = {
|
|
440
|
+
...manifest.dependencies,
|
|
441
|
+
...manifest.devDependencies
|
|
442
|
+
};
|
|
443
|
+
const missing = [
|
|
444
|
+
'storybook',
|
|
445
|
+
'@storybook/react-vite',
|
|
446
|
+
'vite',
|
|
447
|
+
'@vitejs/plugin-react'
|
|
448
|
+
].filter((name)=>!dependencies[name]);
|
|
449
|
+
const missingReact = [
|
|
450
|
+
'react',
|
|
451
|
+
'react-dom'
|
|
452
|
+
].filter((name)=>!dependencies[name]);
|
|
453
|
+
return [
|
|
454
|
+
'Storybook configuration saved (React + Vite).',
|
|
455
|
+
'Next steps (run from the project package directory):',
|
|
456
|
+
...missing.length ? [
|
|
457
|
+
` npm install --save-dev ${missing.join(' ')}`
|
|
458
|
+
] : [],
|
|
459
|
+
...missingReact.length ? [
|
|
460
|
+
` npm install ${missingReact.join(' ')}`
|
|
461
|
+
] : [],
|
|
462
|
+
' Existing dependency versions were kept; ensure Storybook packages are compatible.',
|
|
463
|
+
' Add your CSS imports to .storybook/preview.ts using relative paths or the @/ alias (project root).',
|
|
464
|
+
' Generate a UI-kit component or widget UI to create a story.',
|
|
465
|
+
...selected.storybook ? [
|
|
466
|
+
` npm run ${selected.storybook}`
|
|
467
|
+
] : [],
|
|
468
|
+
...selected['build-storybook'] ? [
|
|
469
|
+
` npm run ${selected['build-storybook']}`
|
|
470
|
+
] : []
|
|
471
|
+
];
|
|
472
|
+
};
|
|
473
|
+
const integrations = [
|
|
474
|
+
{
|
|
475
|
+
name: 'Storybook (React + Vite)',
|
|
476
|
+
run: addStorybook
|
|
477
|
+
},
|
|
478
|
+
{
|
|
479
|
+
name: 'Prisma 8 (PostgreSQL, RC)',
|
|
480
|
+
run: addPrisma
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
name: 'Missing domain-first packages',
|
|
484
|
+
run: missingDomainFirstPackages
|
|
485
|
+
}
|
|
486
|
+
];
|
|
487
|
+
const addIntegration = async ()=>{
|
|
488
|
+
const index = await prompts_select({
|
|
489
|
+
message: 'Integration:',
|
|
490
|
+
choices: integrations.map((integration, value)=>({
|
|
491
|
+
name: integration.name,
|
|
492
|
+
value
|
|
493
|
+
}))
|
|
494
|
+
});
|
|
495
|
+
const nextSteps = await integrations[index].run();
|
|
496
|
+
if (await savePendingChanges()) {
|
|
497
|
+
if (nextSteps.length) console.log(nextSteps.map((line)=>/^\s*npm (?:i|install)\b/.test(line) ? styleText([
|
|
498
|
+
'bold',
|
|
499
|
+
'cyan'
|
|
500
|
+
], line) : line).join('\n'));
|
|
501
|
+
}
|
|
502
|
+
};
|
|
158
503
|
const initializeUseCase = async ()=>{
|
|
159
504
|
const rootFolderName = await input({
|
|
160
505
|
message: 'Root folder (use "/" for inner folders):',
|
|
@@ -2038,7 +2383,11 @@ const main = async ()=>{
|
|
|
2038
2383
|
name: 'Shared Layer',
|
|
2039
2384
|
action: 'Scaffold in bounded context'
|
|
2040
2385
|
},
|
|
2041
|
-
scaffoldNewBoundedContext
|
|
2386
|
+
scaffoldNewBoundedContext,
|
|
2387
|
+
{
|
|
2388
|
+
name: 'Add integration',
|
|
2389
|
+
action: 'Add integration'
|
|
2390
|
+
}
|
|
2042
2391
|
].filter((x)=>!!x);
|
|
2043
2392
|
const result = await prompts_select({
|
|
2044
2393
|
message: '@domain-first/project-structure',
|
|
@@ -2046,6 +2395,8 @@ const main = async ()=>{
|
|
|
2046
2395
|
});
|
|
2047
2396
|
const { action, name } = options.find((x)=>x.name === result);
|
|
2048
2397
|
switch(action){
|
|
2398
|
+
case 'Add integration':
|
|
2399
|
+
return void await addIntegration();
|
|
2049
2400
|
case 'Scaffold React module':
|
|
2050
2401
|
{
|
|
2051
2402
|
const reactFolder = new Folder(rootPath).subitem([
|
|
@@ -2192,17 +2543,6 @@ const main = async ()=>{
|
|
|
2192
2543
|
};
|
|
2193
2544
|
const run = async ()=>{
|
|
2194
2545
|
await main();
|
|
2195
|
-
|
|
2196
|
-
if (overwrittenFiles.length) {
|
|
2197
|
-
const root = new ProjectRoot().path;
|
|
2198
|
-
console.log('These files already exist and will be overwritten:');
|
|
2199
|
-
for (const filePath of overwrittenFiles)console.log(` ${node_path.relative(root, filePath)}`);
|
|
2200
|
-
const overwrite = await prompts_confirm({
|
|
2201
|
-
message: 'Overwrite them?',
|
|
2202
|
-
default: false
|
|
2203
|
-
});
|
|
2204
|
-
if (!overwrite) return void console.log('Cancelled: nothing was written.');
|
|
2205
|
-
}
|
|
2206
|
-
writePendingChanges();
|
|
2546
|
+
await savePendingChanges();
|
|
2207
2547
|
};
|
|
2208
2548
|
run();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const missingDomainFirstPackages: () => string[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const storybookFiles: (relativeProjectRoot: string) => {
|
|
2
|
+
'main.ts': string;
|
|
3
|
+
'preview.ts': string;
|
|
4
|
+
};
|
|
5
|
+
export declare const storybookScripts: (rootFolder: string) => {
|
|
6
|
+
storybook: string;
|
|
7
|
+
'build-storybook': string;
|
|
8
|
+
};
|
|
9
|
+
export declare const addStorybook: () => Promise<string[]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const addIntegration: () => Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|