@domain-first/project-structure 2.13.1 → 2.14.1
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 +52 -4
- package/dist/index.cjs +237 -41
- package/dist/index.js +237 -41
- package/dist/integrations/gitignore.d.ts +1 -0
- package/dist/integrations/index.d.ts +2 -0
- package/dist/integrations/package-scripts.d.ts +1 -0
- package/dist/integrations/playwright.d.ts +5 -0
- package/dist/integrations/playwright.spec.d.ts +1 -0
- package/dist/integrations/vitest.d.ts +6 -0
- package/dist/integrations/vitest.spec.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -229,8 +229,8 @@ name. Identical generated configs and scripts are skipped on subsequent runs;
|
|
|
229
229
|
changed config files use the usual overwrite confirmation. Cancelling before
|
|
230
230
|
writing leaves all files unchanged.
|
|
231
231
|
|
|
232
|
-
After writing, the CLI prints npm commands for missing dependencies
|
|
233
|
-
|
|
232
|
+
After writing, the CLI prints only npm commands for missing dependencies. It
|
|
233
|
+
does not install packages or execute scripts. Install commands omit version constraints for Storybook, its React + Vite
|
|
234
234
|
framework, Vite and the React plugin; existing dependency versions are preserved
|
|
235
235
|
and must be compatible with those packages. Generate a
|
|
236
236
|
UI-kit component or a widget with separated UI to add your first story. The
|
|
@@ -244,7 +244,7 @@ Choose **Add integration → Missing domain-first packages** to compare
|
|
|
244
244
|
`domainFirstPackages` in the configuration with `dependencies`, `devDependencies`
|
|
245
245
|
and `optionalDependencies` in the project's `package.json`. The CLI prints one
|
|
246
246
|
`npm i` command for missing packages, without version constraints. If none are
|
|
247
|
-
missing, it
|
|
247
|
+
missing, it prints nothing. This
|
|
248
248
|
checks declared dependencies, not the contents of `node_modules`, and does not
|
|
249
249
|
modify files or install packages.
|
|
250
250
|
|
|
@@ -271,7 +271,9 @@ are staged until overwrite confirmation; no packages are installed and no
|
|
|
271
271
|
commands connect to the database during scaffolding.
|
|
272
272
|
|
|
273
273
|
The printed install commands omit version constraints for `prisma`,
|
|
274
|
-
`@prisma/cli-engine`, `@prisma/orm-postgres`, `temporal-polyfill`, and `dotenv`. Already declared dependencies are kept.
|
|
274
|
+
`@prisma/cli-engine`, `@prisma/orm-postgres`, `temporal-polyfill`, and `dotenv`. Already declared dependencies are kept.
|
|
275
|
+
The CLI also reminds you to add `!<rootFolder>/shared/infrastructure/prisma` to
|
|
276
|
+
your linter ignores. This is a PostgreSQL
|
|
275
277
|
preset for Prisma 8 RC, not a Prisma 7 migration tool.
|
|
276
278
|
|
|
277
279
|
After installing dependencies, configure `DATABASE_URL` (the CLI loads `.env`;
|
|
@@ -281,6 +283,52 @@ Use Node.js 22.18+, TypeScript 5.9+, ESM and JSON import support. Review planned
|
|
|
281
283
|
migrations before running the apply script. Generated contract files and
|
|
282
284
|
migration history are managed by Prisma, not by this scaffolder.
|
|
283
285
|
|
|
286
|
+
### Vitest
|
|
287
|
+
|
|
288
|
+
Choose **Add integration → Vitest**. The integration creates `vitest.config.ts`
|
|
289
|
+
in the project root (the directory containing `package.json`) with
|
|
290
|
+
`resolve.tsconfigPaths` and V8 coverage for `<rootFolder>/bounded-contexts` and
|
|
291
|
+
`<rootFolder>/shared`. Specs, infrastructure, REST presentation and wiring are
|
|
292
|
+
excluded from coverage. When `@domain-first/handlers-next` is declared, the
|
|
293
|
+
config also inlines it so Vitest can resolve its `next/headers` import.
|
|
294
|
+
|
|
295
|
+
It sets `testingLibrary` to `vitest`, so generators scaffold unit tests; if
|
|
296
|
+
another testing library is configured, the CLI asks before replacing it. It also
|
|
297
|
+
adds `/coverage/` to the project `.gitignore` and these package scripts:
|
|
298
|
+
|
|
299
|
+
```json
|
|
300
|
+
{
|
|
301
|
+
"test": "vitest run --reporter=dot --silent=passed-only",
|
|
302
|
+
"test:coverage": "vitest run --coverage --reporter=dot --silent=passed-only"
|
|
303
|
+
}
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
Script conflicts and overwrite confirmation work as in the other integrations.
|
|
307
|
+
The printed install command omits version constraints for `vitest` and
|
|
308
|
+
`@vitest/coverage-v8`; already declared dependencies are kept.
|
|
309
|
+
`resolve.tsconfigPaths` requires Vite 8+. The config excludes `specs/e2e`, which
|
|
310
|
+
belongs to Playwright.
|
|
311
|
+
|
|
312
|
+
### Playwright
|
|
313
|
+
|
|
314
|
+
Choose **Add integration → Playwright**. The integration creates
|
|
315
|
+
`playwright.config.ts` in the project root with `testDir: './specs/e2e'`, an
|
|
316
|
+
HTML reporter, traces on retry, screenshots and videos on failure, and projects
|
|
317
|
+
for Chromium, Firefox, WebKit, Mobile Chrome and Mobile Safari, all running on
|
|
318
|
+
Playwright's own browser builds.
|
|
319
|
+
The web server runs `npm run dev` at `http://localhost:3000` and is reused
|
|
320
|
+
outside CI; adjust `baseURL` and `webServer.url` for another port.
|
|
321
|
+
|
|
322
|
+
A mock example goes to `specs/e2e/home`: `home.e2e.spec.ts` and a `README.MD`
|
|
323
|
+
with its user stories. Existing example files are never overwritten. The
|
|
324
|
+
integration adds a `test:e2e` script (`playwright test`) and ignores
|
|
325
|
+
`/test-results/`, `/playwright-report/`, `/blob-report/`, `/playwright/.cache/`
|
|
326
|
+
and `/playwright/.auth/` in `.gitignore`.
|
|
327
|
+
|
|
328
|
+
After writing, the CLI prints `npm install --save-dev @playwright/test` if the
|
|
329
|
+
package is missing and `npx playwright install --with-deps` for the browsers and
|
|
330
|
+
their system dependencies. Then run `npm run test:e2e`.
|
|
331
|
+
|
|
284
332
|
## Configuration
|
|
285
333
|
|
|
286
334
|
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/index.cjs
CHANGED
|
@@ -220,11 +220,8 @@ const missingDomainFirstPackages = ()=>{
|
|
|
220
220
|
...new Set(packages)
|
|
221
221
|
].filter((name)=>!Object.hasOwn(dependencies, name));
|
|
222
222
|
return missing.length ? [
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
] : [
|
|
226
|
-
'All configured domain-first packages are already declared in package.json.'
|
|
227
|
-
];
|
|
223
|
+
`npm i ${missing.join(' ')}`
|
|
224
|
+
] : [];
|
|
228
225
|
};
|
|
229
226
|
const addPackageScripts = async (file, additions)=>{
|
|
230
227
|
const original = file.data;
|
|
@@ -260,6 +257,128 @@ const addPackageScripts = async (file, additions)=>{
|
|
|
260
257
|
}
|
|
261
258
|
return selected;
|
|
262
259
|
};
|
|
260
|
+
const describeScripts = (selected, descriptions)=>Object.entries(descriptions).filter(([name])=>selected[name]).map(([name, description])=>`npm run ${selected[name]} — ${description}`);
|
|
261
|
+
const addGitignoreEntry = (root, entry)=>{
|
|
262
|
+
const gitignore = new File(external_node_path_default().join(root, '.gitignore'));
|
|
263
|
+
const ignored = gitignore.exists ? gitignore.data : '';
|
|
264
|
+
if (ignored.split(/\r?\n/).includes(entry)) return;
|
|
265
|
+
const newline = ignored.includes('\r\n') ? '\r\n' : '\n';
|
|
266
|
+
gitignore.update(`${ignored}${ignored && !ignored.endsWith('\n') ? newline : ''}${entry}${newline}`);
|
|
267
|
+
};
|
|
268
|
+
const playwrightScripts = {
|
|
269
|
+
'test:e2e': 'playwright test'
|
|
270
|
+
};
|
|
271
|
+
const playwrightConfig = `import { defineConfig, devices } from '@playwright/test';
|
|
272
|
+
|
|
273
|
+
export default defineConfig({
|
|
274
|
+
testDir: './specs/e2e',
|
|
275
|
+
fullyParallel: true,
|
|
276
|
+
forbidOnly: !!process.env.CI,
|
|
277
|
+
retries: process.env.CI ? 2 : 0,
|
|
278
|
+
workers: process.env.CI ? 1 : undefined,
|
|
279
|
+
reporter: 'html',
|
|
280
|
+
use: {
|
|
281
|
+
baseURL: 'http://localhost:3000',
|
|
282
|
+
trace: 'on-first-retry',
|
|
283
|
+
screenshot: 'only-on-failure',
|
|
284
|
+
video: 'retain-on-failure'
|
|
285
|
+
},
|
|
286
|
+
|
|
287
|
+
projects: [
|
|
288
|
+
{
|
|
289
|
+
name: 'chromium',
|
|
290
|
+
use: { ...devices['Desktop Chrome'] }
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
name: 'firefox',
|
|
294
|
+
use: { ...devices['Desktop Firefox'] }
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
name: 'webkit',
|
|
298
|
+
use: { ...devices['Desktop Safari'] }
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
name: 'Mobile Chrome',
|
|
302
|
+
use: { ...devices['Pixel 5'] }
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
name: 'Mobile Safari',
|
|
306
|
+
use: { ...devices['iPhone 12'] }
|
|
307
|
+
}
|
|
308
|
+
],
|
|
309
|
+
|
|
310
|
+
webServer: {
|
|
311
|
+
// Playwright only stops the dev server on a clean shutdown. If its process dies any other
|
|
312
|
+
// way (SIGHUP, SIGKILL), the dev server lives on in its own process group, so it is killed
|
|
313
|
+
// as soon as Playwright is gone.
|
|
314
|
+
command:
|
|
315
|
+
process.platform === 'win32'
|
|
316
|
+
? 'npm run dev'
|
|
317
|
+
: \`npm run dev & while kill -0 \${process.pid} 2>/dev/null && kill -0 $! 2>/dev/null; do sleep 1; done; kill 0\`,
|
|
318
|
+
url: 'http://localhost:3000',
|
|
319
|
+
timeout: 120000,
|
|
320
|
+
reuseExistingServer: !process.env.CI
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
`;
|
|
324
|
+
const exampleSpec = `import { expect, test } from '@playwright/test';
|
|
325
|
+
|
|
326
|
+
test.describe('home page', () => {
|
|
327
|
+
test('opens the home page', async ({ page, baseURL }) => {
|
|
328
|
+
await page.goto('/');
|
|
329
|
+
await expect(page).toHaveURL(\`\${baseURL}/\`);
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
`;
|
|
333
|
+
const exampleReadme = `# Home page e2e cases
|
|
334
|
+
|
|
335
|
+
## User Stories
|
|
336
|
+
|
|
337
|
+
1. Guest opens \`/\` and stays on the home page.
|
|
338
|
+
`;
|
|
339
|
+
const gitignoreEntries = [
|
|
340
|
+
'/test-results/',
|
|
341
|
+
'/playwright-report/',
|
|
342
|
+
'/blob-report/',
|
|
343
|
+
'/playwright/.cache/',
|
|
344
|
+
'/playwright/.auth/'
|
|
345
|
+
];
|
|
346
|
+
const addPlaywright = async ()=>{
|
|
347
|
+
const root = new ProjectRoot().path;
|
|
348
|
+
const manifestFile = new File(external_node_path_default().join(root, 'package.json'));
|
|
349
|
+
const manifest = JSON.parse(manifestFile.data);
|
|
350
|
+
const dependencies = {
|
|
351
|
+
...manifest.dependencies,
|
|
352
|
+
...manifest.devDependencies
|
|
353
|
+
};
|
|
354
|
+
const selected = await addPackageScripts(manifestFile, playwrightScripts);
|
|
355
|
+
const configFile = new File(external_node_path_default().join(root, 'playwright.config.ts'));
|
|
356
|
+
if (!configFile.exists || configFile.data !== playwrightConfig) configFile.data = playwrightConfig;
|
|
357
|
+
const exampleFolder = external_node_path_default().join(root, 'specs/e2e/home');
|
|
358
|
+
for (const [name, content] of [
|
|
359
|
+
[
|
|
360
|
+
'home.e2e.spec.ts',
|
|
361
|
+
exampleSpec
|
|
362
|
+
],
|
|
363
|
+
[
|
|
364
|
+
'README.MD',
|
|
365
|
+
exampleReadme
|
|
366
|
+
]
|
|
367
|
+
]){
|
|
368
|
+
const file = new File(external_node_path_default().join(exampleFolder, name));
|
|
369
|
+
if (!file.exists) file.data = content;
|
|
370
|
+
}
|
|
371
|
+
for (const entry of gitignoreEntries)addGitignoreEntry(root, entry);
|
|
372
|
+
return [
|
|
373
|
+
...dependencies['@playwright/test'] ? [] : [
|
|
374
|
+
'npm install --save-dev @playwright/test'
|
|
375
|
+
],
|
|
376
|
+
'npx playwright install --with-deps',
|
|
377
|
+
...describeScripts(selected, {
|
|
378
|
+
'test:e2e': 'start the dev server and run end-to-end specs from specs/e2e'
|
|
379
|
+
})
|
|
380
|
+
];
|
|
381
|
+
};
|
|
263
382
|
const runtimePackages = [
|
|
264
383
|
'@prisma/orm-postgres',
|
|
265
384
|
'temporal-polyfill',
|
|
@@ -366,24 +485,19 @@ const addPrisma = async ()=>{
|
|
|
366
485
|
const install = (packages, dev)=>{
|
|
367
486
|
const missing = packages.filter((name)=>!dependencies[name]);
|
|
368
487
|
return missing.length ? [
|
|
369
|
-
`
|
|
488
|
+
`npm install${dev ? ' --save-dev' : ''} ${missing.join(' ')}`
|
|
370
489
|
] : [];
|
|
371
490
|
};
|
|
372
|
-
const scriptCommand = (name)=>selected[name] ? `npm run ${selected[name]}` : prismaScripts(config.rootFolder)[name];
|
|
373
491
|
const relativeFolder = external_node_path_default().relative(root, prismaFolder).split(external_node_path_default().sep).join('/');
|
|
374
492
|
return [
|
|
375
|
-
'Prisma 8 configuration saved (PostgreSQL, RC preset).',
|
|
376
|
-
'Next steps (run from the project package directory):',
|
|
377
493
|
...install(runtimePackages, false),
|
|
378
494
|
...install(developmentPackages, true),
|
|
379
|
-
`
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
` Plan migrations: ${scriptCommand('prisma:migration:plan')}`,
|
|
386
|
-
` Review the generated migrations, then apply: ${scriptCommand('prisma:migration:apply')}`
|
|
495
|
+
`Add !${relativeFolder} in your linter, to ignore prisma files.`,
|
|
496
|
+
...describeScripts(selected, {
|
|
497
|
+
'prisma:emit': 'emit contract.json and contract.d.ts from contract.prisma',
|
|
498
|
+
'prisma:migration:plan': 'emit the contract and plan a migration',
|
|
499
|
+
'prisma:migration:apply': 'apply planned migrations to the database in DATABASE_URL'
|
|
500
|
+
})
|
|
387
501
|
];
|
|
388
502
|
};
|
|
389
503
|
const storybookFiles = (relativeProjectRoot)=>({
|
|
@@ -468,13 +582,7 @@ const addStorybook = async ()=>{
|
|
|
468
582
|
storybookFramework: '@storybook/react-vite'
|
|
469
583
|
});
|
|
470
584
|
const buildFolder = external_node_path_default().posix.join(config.rootFolder.replaceAll('\\', '/'), 'presentation/react/storybook-static');
|
|
471
|
-
|
|
472
|
-
const gitignore = new File(external_node_path_default().join(root, '.gitignore'));
|
|
473
|
-
const ignored = gitignore.exists ? gitignore.data : '';
|
|
474
|
-
if (!ignored.split(/\r?\n/).includes(ignoreEntry)) {
|
|
475
|
-
const newline = ignored.includes('\r\n') ? '\r\n' : '\n';
|
|
476
|
-
gitignore.update(`${ignored}${ignored && !ignored.endsWith('\n') ? newline : ''}${ignoreEntry}${newline}`);
|
|
477
|
-
}
|
|
585
|
+
addGitignoreEntry(root, `/${buildFolder}/`);
|
|
478
586
|
const dependencies = {
|
|
479
587
|
...manifest.dependencies,
|
|
480
588
|
...manifest.devDependencies
|
|
@@ -490,23 +598,91 @@ const addStorybook = async ()=>{
|
|
|
490
598
|
'react-dom'
|
|
491
599
|
].filter((name)=>!dependencies[name]);
|
|
492
600
|
return [
|
|
493
|
-
'Storybook configuration saved (React + Vite).',
|
|
494
|
-
'Next steps (run from the project package directory):',
|
|
495
601
|
...missing.length ? [
|
|
496
|
-
`
|
|
602
|
+
`npm install --save-dev ${missing.join(' ')}`
|
|
497
603
|
] : [],
|
|
498
604
|
...missingReact.length ? [
|
|
499
|
-
`
|
|
605
|
+
`npm install ${missingReact.join(' ')}`
|
|
500
606
|
] : [],
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
607
|
+
...describeScripts(selected, {
|
|
608
|
+
storybook: 'start Storybook on http://localhost:6006',
|
|
609
|
+
'build-storybook': `build static Storybook into ${buildFolder}`
|
|
610
|
+
})
|
|
611
|
+
];
|
|
612
|
+
};
|
|
613
|
+
const vitestScripts = {
|
|
614
|
+
test: 'vitest run --reporter=dot --silent=passed-only',
|
|
615
|
+
'test:coverage': 'vitest run --coverage --reporter=dot --silent=passed-only'
|
|
616
|
+
};
|
|
617
|
+
const vitestConfig = (rootFolder, inlineHandlersNext)=>{
|
|
618
|
+
const folder = (subpath)=>JSON.stringify(external_node_path_default().posix.join(rootFolder.replaceAll('\\', '/'), subpath));
|
|
619
|
+
const server = inlineHandlersNext ? `,
|
|
620
|
+
server: {
|
|
621
|
+
deps: {
|
|
622
|
+
// Imports \`next/headers\` without an extension, which only a bundler can resolve
|
|
623
|
+
inline: ['@domain-first/handlers-next']
|
|
624
|
+
}
|
|
625
|
+
}` : '';
|
|
626
|
+
return `import { configDefaults, defineConfig } from 'vitest/config';
|
|
627
|
+
|
|
628
|
+
export default defineConfig({
|
|
629
|
+
resolve: {
|
|
630
|
+
tsconfigPaths: true
|
|
631
|
+
},
|
|
632
|
+
test: {
|
|
633
|
+
// Playwright runs end-to-end specs
|
|
634
|
+
exclude: [...configDefaults.exclude, 'specs/e2e/**'],
|
|
635
|
+
coverage: {
|
|
636
|
+
provider: 'v8',
|
|
637
|
+
include: [${folder('bounded-contexts/**/*.ts')}, ${folder('shared/**/*.ts')}],
|
|
638
|
+
exclude: [
|
|
639
|
+
'**/*.spec.ts',
|
|
640
|
+
${folder('shared/infrastructure/**')},
|
|
641
|
+
${folder('bounded-contexts/*/infrastructure/**')},
|
|
642
|
+
${folder('bounded-contexts/*/presentation/rest/**')},
|
|
643
|
+
${folder('shared/wiring/**')},
|
|
644
|
+
${folder('bounded-contexts/*/wiring/**')}
|
|
645
|
+
],
|
|
646
|
+
reporter: [['text', { skipFull: true }], 'html']
|
|
647
|
+
}${server}
|
|
648
|
+
}
|
|
649
|
+
});
|
|
650
|
+
`;
|
|
651
|
+
};
|
|
652
|
+
const addVitest = async ()=>{
|
|
653
|
+
const config = ConfigFile.Instance.data;
|
|
654
|
+
if (config.testingLibrary && 'vitest' !== config.testingLibrary && !await (0, prompts_namespaceObject.confirm)({
|
|
655
|
+
message: `Replace testing library "${config.testingLibrary}" with vitest for generated tests?`,
|
|
656
|
+
default: false
|
|
657
|
+
})) return [];
|
|
658
|
+
const root = new ProjectRoot().path;
|
|
659
|
+
const manifestFile = new File(external_node_path_default().join(root, 'package.json'));
|
|
660
|
+
const manifest = JSON.parse(manifestFile.data);
|
|
661
|
+
const dependencies = {
|
|
662
|
+
...manifest.dependencies,
|
|
663
|
+
...manifest.devDependencies
|
|
664
|
+
};
|
|
665
|
+
const selected = await addPackageScripts(manifestFile, vitestScripts);
|
|
666
|
+
const configFile = new File(external_node_path_default().join(root, 'vitest.config.ts'));
|
|
667
|
+
const content = vitestConfig(config.rootFolder, Boolean(dependencies['@domain-first/handlers-next']));
|
|
668
|
+
if (!configFile.exists || configFile.data !== content) configFile.data = content;
|
|
669
|
+
if ('vitest' !== config.testingLibrary) ConfigFile.write({
|
|
670
|
+
...config,
|
|
671
|
+
testingLibrary: 'vitest'
|
|
672
|
+
});
|
|
673
|
+
addGitignoreEntry(root, '/coverage/');
|
|
674
|
+
const missing = [
|
|
675
|
+
'vitest',
|
|
676
|
+
'@vitest/coverage-v8'
|
|
677
|
+
].filter((name)=>!dependencies[name]);
|
|
678
|
+
return [
|
|
679
|
+
...missing.length ? [
|
|
680
|
+
`npm install --save-dev ${missing.join(' ')}`
|
|
506
681
|
] : [],
|
|
507
|
-
...selected
|
|
508
|
-
|
|
509
|
-
|
|
682
|
+
...describeScripts(selected, {
|
|
683
|
+
test: 'run unit tests',
|
|
684
|
+
'test:coverage': 'run unit tests with a V8 coverage report in coverage/'
|
|
685
|
+
})
|
|
510
686
|
];
|
|
511
687
|
};
|
|
512
688
|
const integrations = [
|
|
@@ -518,6 +694,14 @@ const integrations = [
|
|
|
518
694
|
name: 'Prisma 8 (PostgreSQL, RC)',
|
|
519
695
|
run: addPrisma
|
|
520
696
|
},
|
|
697
|
+
{
|
|
698
|
+
name: 'Vitest',
|
|
699
|
+
run: addVitest
|
|
700
|
+
},
|
|
701
|
+
{
|
|
702
|
+
name: 'Playwright',
|
|
703
|
+
run: addPlaywright
|
|
704
|
+
},
|
|
521
705
|
{
|
|
522
706
|
name: 'Missing domain-first packages',
|
|
523
707
|
run: missingDomainFirstPackages
|
|
@@ -533,13 +717,25 @@ const addIntegration = async ()=>{
|
|
|
533
717
|
});
|
|
534
718
|
const nextSteps = await integrations[index].run();
|
|
535
719
|
if (await savePendingChanges()) {
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
720
|
+
const isCommand = (line)=>/^\s*(?:npm (?:i|install)|npx playwright install)\b/.test(line);
|
|
721
|
+
const commands = nextSteps.filter(isCommand);
|
|
722
|
+
const notes = nextSteps.filter((line)=>!isCommand(line));
|
|
723
|
+
const sections = [];
|
|
724
|
+
if (commands.length) sections.push([
|
|
725
|
+
'Run these commands to install the required dependencies:',
|
|
726
|
+
...commands.map((line)=>(0, external_node_util_namespaceObject.styleText)([
|
|
540
727
|
'bold',
|
|
541
728
|
'cyan'
|
|
542
|
-
],
|
|
729
|
+
], line))
|
|
730
|
+
].join('\n'));
|
|
731
|
+
if (notes.length) sections.push([
|
|
732
|
+
'Additional information:',
|
|
733
|
+
...notes.map((line)=>line.replace(/^(\s*Add )(!\S+)/, (_, prefix, path)=>prefix + (0, external_node_util_namespaceObject.styleText)([
|
|
734
|
+
'bold',
|
|
735
|
+
'cyan'
|
|
736
|
+
], path)))
|
|
737
|
+
].join('\n'));
|
|
738
|
+
if (sections.length) console.log(sections.join('\n\n'));
|
|
543
739
|
}
|
|
544
740
|
};
|
|
545
741
|
const initializeUseCase = async ()=>{
|
package/dist/index.js
CHANGED
|
@@ -190,11 +190,8 @@ const missingDomainFirstPackages = ()=>{
|
|
|
190
190
|
...new Set(packages)
|
|
191
191
|
].filter((name)=>!Object.hasOwn(dependencies, name));
|
|
192
192
|
return missing.length ? [
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
] : [
|
|
196
|
-
'All configured domain-first packages are already declared in package.json.'
|
|
197
|
-
];
|
|
193
|
+
`npm i ${missing.join(' ')}`
|
|
194
|
+
] : [];
|
|
198
195
|
};
|
|
199
196
|
const addPackageScripts = async (file, additions)=>{
|
|
200
197
|
const original = file.data;
|
|
@@ -230,6 +227,128 @@ const addPackageScripts = async (file, additions)=>{
|
|
|
230
227
|
}
|
|
231
228
|
return selected;
|
|
232
229
|
};
|
|
230
|
+
const describeScripts = (selected, descriptions)=>Object.entries(descriptions).filter(([name])=>selected[name]).map(([name, description])=>`npm run ${selected[name]} — ${description}`);
|
|
231
|
+
const addGitignoreEntry = (root, entry)=>{
|
|
232
|
+
const gitignore = new File(node_path.join(root, '.gitignore'));
|
|
233
|
+
const ignored = gitignore.exists ? gitignore.data : '';
|
|
234
|
+
if (ignored.split(/\r?\n/).includes(entry)) return;
|
|
235
|
+
const newline = ignored.includes('\r\n') ? '\r\n' : '\n';
|
|
236
|
+
gitignore.update(`${ignored}${ignored && !ignored.endsWith('\n') ? newline : ''}${entry}${newline}`);
|
|
237
|
+
};
|
|
238
|
+
const playwrightScripts = {
|
|
239
|
+
'test:e2e': 'playwright test'
|
|
240
|
+
};
|
|
241
|
+
const playwrightConfig = `import { defineConfig, devices } from '@playwright/test';
|
|
242
|
+
|
|
243
|
+
export default defineConfig({
|
|
244
|
+
testDir: './specs/e2e',
|
|
245
|
+
fullyParallel: true,
|
|
246
|
+
forbidOnly: !!process.env.CI,
|
|
247
|
+
retries: process.env.CI ? 2 : 0,
|
|
248
|
+
workers: process.env.CI ? 1 : undefined,
|
|
249
|
+
reporter: 'html',
|
|
250
|
+
use: {
|
|
251
|
+
baseURL: 'http://localhost:3000',
|
|
252
|
+
trace: 'on-first-retry',
|
|
253
|
+
screenshot: 'only-on-failure',
|
|
254
|
+
video: 'retain-on-failure'
|
|
255
|
+
},
|
|
256
|
+
|
|
257
|
+
projects: [
|
|
258
|
+
{
|
|
259
|
+
name: 'chromium',
|
|
260
|
+
use: { ...devices['Desktop Chrome'] }
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
name: 'firefox',
|
|
264
|
+
use: { ...devices['Desktop Firefox'] }
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
name: 'webkit',
|
|
268
|
+
use: { ...devices['Desktop Safari'] }
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
name: 'Mobile Chrome',
|
|
272
|
+
use: { ...devices['Pixel 5'] }
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
name: 'Mobile Safari',
|
|
276
|
+
use: { ...devices['iPhone 12'] }
|
|
277
|
+
}
|
|
278
|
+
],
|
|
279
|
+
|
|
280
|
+
webServer: {
|
|
281
|
+
// Playwright only stops the dev server on a clean shutdown. If its process dies any other
|
|
282
|
+
// way (SIGHUP, SIGKILL), the dev server lives on in its own process group, so it is killed
|
|
283
|
+
// as soon as Playwright is gone.
|
|
284
|
+
command:
|
|
285
|
+
process.platform === 'win32'
|
|
286
|
+
? 'npm run dev'
|
|
287
|
+
: \`npm run dev & while kill -0 \${process.pid} 2>/dev/null && kill -0 $! 2>/dev/null; do sleep 1; done; kill 0\`,
|
|
288
|
+
url: 'http://localhost:3000',
|
|
289
|
+
timeout: 120000,
|
|
290
|
+
reuseExistingServer: !process.env.CI
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
`;
|
|
294
|
+
const exampleSpec = `import { expect, test } from '@playwright/test';
|
|
295
|
+
|
|
296
|
+
test.describe('home page', () => {
|
|
297
|
+
test('opens the home page', async ({ page, baseURL }) => {
|
|
298
|
+
await page.goto('/');
|
|
299
|
+
await expect(page).toHaveURL(\`\${baseURL}/\`);
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
`;
|
|
303
|
+
const exampleReadme = `# Home page e2e cases
|
|
304
|
+
|
|
305
|
+
## User Stories
|
|
306
|
+
|
|
307
|
+
1. Guest opens \`/\` and stays on the home page.
|
|
308
|
+
`;
|
|
309
|
+
const gitignoreEntries = [
|
|
310
|
+
'/test-results/',
|
|
311
|
+
'/playwright-report/',
|
|
312
|
+
'/blob-report/',
|
|
313
|
+
'/playwright/.cache/',
|
|
314
|
+
'/playwright/.auth/'
|
|
315
|
+
];
|
|
316
|
+
const addPlaywright = async ()=>{
|
|
317
|
+
const root = new ProjectRoot().path;
|
|
318
|
+
const manifestFile = new File(node_path.join(root, 'package.json'));
|
|
319
|
+
const manifest = JSON.parse(manifestFile.data);
|
|
320
|
+
const dependencies = {
|
|
321
|
+
...manifest.dependencies,
|
|
322
|
+
...manifest.devDependencies
|
|
323
|
+
};
|
|
324
|
+
const selected = await addPackageScripts(manifestFile, playwrightScripts);
|
|
325
|
+
const configFile = new File(node_path.join(root, 'playwright.config.ts'));
|
|
326
|
+
if (!configFile.exists || configFile.data !== playwrightConfig) configFile.data = playwrightConfig;
|
|
327
|
+
const exampleFolder = node_path.join(root, 'specs/e2e/home');
|
|
328
|
+
for (const [name, content] of [
|
|
329
|
+
[
|
|
330
|
+
'home.e2e.spec.ts',
|
|
331
|
+
exampleSpec
|
|
332
|
+
],
|
|
333
|
+
[
|
|
334
|
+
'README.MD',
|
|
335
|
+
exampleReadme
|
|
336
|
+
]
|
|
337
|
+
]){
|
|
338
|
+
const file = new File(node_path.join(exampleFolder, name));
|
|
339
|
+
if (!file.exists) file.data = content;
|
|
340
|
+
}
|
|
341
|
+
for (const entry of gitignoreEntries)addGitignoreEntry(root, entry);
|
|
342
|
+
return [
|
|
343
|
+
...dependencies['@playwright/test'] ? [] : [
|
|
344
|
+
'npm install --save-dev @playwright/test'
|
|
345
|
+
],
|
|
346
|
+
'npx playwright install --with-deps',
|
|
347
|
+
...describeScripts(selected, {
|
|
348
|
+
'test:e2e': 'start the dev server and run end-to-end specs from specs/e2e'
|
|
349
|
+
})
|
|
350
|
+
];
|
|
351
|
+
};
|
|
233
352
|
const runtimePackages = [
|
|
234
353
|
'@prisma/orm-postgres',
|
|
235
354
|
'temporal-polyfill',
|
|
@@ -336,24 +455,19 @@ const addPrisma = async ()=>{
|
|
|
336
455
|
const install = (packages, dev)=>{
|
|
337
456
|
const missing = packages.filter((name)=>!dependencies[name]);
|
|
338
457
|
return missing.length ? [
|
|
339
|
-
`
|
|
458
|
+
`npm install${dev ? ' --save-dev' : ''} ${missing.join(' ')}`
|
|
340
459
|
] : [];
|
|
341
460
|
};
|
|
342
|
-
const scriptCommand = (name)=>selected[name] ? `npm run ${selected[name]}` : prismaScripts(config.rootFolder)[name];
|
|
343
461
|
const relativeFolder = node_path.relative(root, prismaFolder).split(node_path.sep).join('/');
|
|
344
462
|
return [
|
|
345
|
-
'Prisma 8 configuration saved (PostgreSQL, RC preset).',
|
|
346
|
-
'Next steps (run from the project package directory):',
|
|
347
463
|
...install(runtimePackages, false),
|
|
348
464
|
...install(developmentPackages, true),
|
|
349
|
-
`
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
` Plan migrations: ${scriptCommand('prisma:migration:plan')}`,
|
|
356
|
-
` Review the generated migrations, then apply: ${scriptCommand('prisma:migration:apply')}`
|
|
465
|
+
`Add !${relativeFolder} in your linter, to ignore prisma files.`,
|
|
466
|
+
...describeScripts(selected, {
|
|
467
|
+
'prisma:emit': 'emit contract.json and contract.d.ts from contract.prisma',
|
|
468
|
+
'prisma:migration:plan': 'emit the contract and plan a migration',
|
|
469
|
+
'prisma:migration:apply': 'apply planned migrations to the database in DATABASE_URL'
|
|
470
|
+
})
|
|
357
471
|
];
|
|
358
472
|
};
|
|
359
473
|
const storybookFiles = (relativeProjectRoot)=>({
|
|
@@ -438,13 +552,7 @@ const addStorybook = async ()=>{
|
|
|
438
552
|
storybookFramework: '@storybook/react-vite'
|
|
439
553
|
});
|
|
440
554
|
const buildFolder = node_path.posix.join(config.rootFolder.replaceAll('\\', '/'), 'presentation/react/storybook-static');
|
|
441
|
-
|
|
442
|
-
const gitignore = new File(node_path.join(root, '.gitignore'));
|
|
443
|
-
const ignored = gitignore.exists ? gitignore.data : '';
|
|
444
|
-
if (!ignored.split(/\r?\n/).includes(ignoreEntry)) {
|
|
445
|
-
const newline = ignored.includes('\r\n') ? '\r\n' : '\n';
|
|
446
|
-
gitignore.update(`${ignored}${ignored && !ignored.endsWith('\n') ? newline : ''}${ignoreEntry}${newline}`);
|
|
447
|
-
}
|
|
555
|
+
addGitignoreEntry(root, `/${buildFolder}/`);
|
|
448
556
|
const dependencies = {
|
|
449
557
|
...manifest.dependencies,
|
|
450
558
|
...manifest.devDependencies
|
|
@@ -460,23 +568,91 @@ const addStorybook = async ()=>{
|
|
|
460
568
|
'react-dom'
|
|
461
569
|
].filter((name)=>!dependencies[name]);
|
|
462
570
|
return [
|
|
463
|
-
'Storybook configuration saved (React + Vite).',
|
|
464
|
-
'Next steps (run from the project package directory):',
|
|
465
571
|
...missing.length ? [
|
|
466
|
-
`
|
|
572
|
+
`npm install --save-dev ${missing.join(' ')}`
|
|
467
573
|
] : [],
|
|
468
574
|
...missingReact.length ? [
|
|
469
|
-
`
|
|
575
|
+
`npm install ${missingReact.join(' ')}`
|
|
470
576
|
] : [],
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
577
|
+
...describeScripts(selected, {
|
|
578
|
+
storybook: 'start Storybook on http://localhost:6006',
|
|
579
|
+
'build-storybook': `build static Storybook into ${buildFolder}`
|
|
580
|
+
})
|
|
581
|
+
];
|
|
582
|
+
};
|
|
583
|
+
const vitestScripts = {
|
|
584
|
+
test: 'vitest run --reporter=dot --silent=passed-only',
|
|
585
|
+
'test:coverage': 'vitest run --coverage --reporter=dot --silent=passed-only'
|
|
586
|
+
};
|
|
587
|
+
const vitestConfig = (rootFolder, inlineHandlersNext)=>{
|
|
588
|
+
const folder = (subpath)=>JSON.stringify(node_path.posix.join(rootFolder.replaceAll('\\', '/'), subpath));
|
|
589
|
+
const server = inlineHandlersNext ? `,
|
|
590
|
+
server: {
|
|
591
|
+
deps: {
|
|
592
|
+
// Imports \`next/headers\` without an extension, which only a bundler can resolve
|
|
593
|
+
inline: ['@domain-first/handlers-next']
|
|
594
|
+
}
|
|
595
|
+
}` : '';
|
|
596
|
+
return `import { configDefaults, defineConfig } from 'vitest/config';
|
|
597
|
+
|
|
598
|
+
export default defineConfig({
|
|
599
|
+
resolve: {
|
|
600
|
+
tsconfigPaths: true
|
|
601
|
+
},
|
|
602
|
+
test: {
|
|
603
|
+
// Playwright runs end-to-end specs
|
|
604
|
+
exclude: [...configDefaults.exclude, 'specs/e2e/**'],
|
|
605
|
+
coverage: {
|
|
606
|
+
provider: 'v8',
|
|
607
|
+
include: [${folder('bounded-contexts/**/*.ts')}, ${folder('shared/**/*.ts')}],
|
|
608
|
+
exclude: [
|
|
609
|
+
'**/*.spec.ts',
|
|
610
|
+
${folder('shared/infrastructure/**')},
|
|
611
|
+
${folder('bounded-contexts/*/infrastructure/**')},
|
|
612
|
+
${folder('bounded-contexts/*/presentation/rest/**')},
|
|
613
|
+
${folder('shared/wiring/**')},
|
|
614
|
+
${folder('bounded-contexts/*/wiring/**')}
|
|
615
|
+
],
|
|
616
|
+
reporter: [['text', { skipFull: true }], 'html']
|
|
617
|
+
}${server}
|
|
618
|
+
}
|
|
619
|
+
});
|
|
620
|
+
`;
|
|
621
|
+
};
|
|
622
|
+
const addVitest = async ()=>{
|
|
623
|
+
const config = ConfigFile.Instance.data;
|
|
624
|
+
if (config.testingLibrary && 'vitest' !== config.testingLibrary && !await prompts_confirm({
|
|
625
|
+
message: `Replace testing library "${config.testingLibrary}" with vitest for generated tests?`,
|
|
626
|
+
default: false
|
|
627
|
+
})) return [];
|
|
628
|
+
const root = new ProjectRoot().path;
|
|
629
|
+
const manifestFile = new File(node_path.join(root, 'package.json'));
|
|
630
|
+
const manifest = JSON.parse(manifestFile.data);
|
|
631
|
+
const dependencies = {
|
|
632
|
+
...manifest.dependencies,
|
|
633
|
+
...manifest.devDependencies
|
|
634
|
+
};
|
|
635
|
+
const selected = await addPackageScripts(manifestFile, vitestScripts);
|
|
636
|
+
const configFile = new File(node_path.join(root, 'vitest.config.ts'));
|
|
637
|
+
const content = vitestConfig(config.rootFolder, Boolean(dependencies['@domain-first/handlers-next']));
|
|
638
|
+
if (!configFile.exists || configFile.data !== content) configFile.data = content;
|
|
639
|
+
if ('vitest' !== config.testingLibrary) ConfigFile.write({
|
|
640
|
+
...config,
|
|
641
|
+
testingLibrary: 'vitest'
|
|
642
|
+
});
|
|
643
|
+
addGitignoreEntry(root, '/coverage/');
|
|
644
|
+
const missing = [
|
|
645
|
+
'vitest',
|
|
646
|
+
'@vitest/coverage-v8'
|
|
647
|
+
].filter((name)=>!dependencies[name]);
|
|
648
|
+
return [
|
|
649
|
+
...missing.length ? [
|
|
650
|
+
`npm install --save-dev ${missing.join(' ')}`
|
|
476
651
|
] : [],
|
|
477
|
-
...selected
|
|
478
|
-
|
|
479
|
-
|
|
652
|
+
...describeScripts(selected, {
|
|
653
|
+
test: 'run unit tests',
|
|
654
|
+
'test:coverage': 'run unit tests with a V8 coverage report in coverage/'
|
|
655
|
+
})
|
|
480
656
|
];
|
|
481
657
|
};
|
|
482
658
|
const integrations = [
|
|
@@ -488,6 +664,14 @@ const integrations = [
|
|
|
488
664
|
name: 'Prisma 8 (PostgreSQL, RC)',
|
|
489
665
|
run: addPrisma
|
|
490
666
|
},
|
|
667
|
+
{
|
|
668
|
+
name: 'Vitest',
|
|
669
|
+
run: addVitest
|
|
670
|
+
},
|
|
671
|
+
{
|
|
672
|
+
name: 'Playwright',
|
|
673
|
+
run: addPlaywright
|
|
674
|
+
},
|
|
491
675
|
{
|
|
492
676
|
name: 'Missing domain-first packages',
|
|
493
677
|
run: missingDomainFirstPackages
|
|
@@ -503,13 +687,25 @@ const addIntegration = async ()=>{
|
|
|
503
687
|
});
|
|
504
688
|
const nextSteps = await integrations[index].run();
|
|
505
689
|
if (await savePendingChanges()) {
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
690
|
+
const isCommand = (line)=>/^\s*(?:npm (?:i|install)|npx playwright install)\b/.test(line);
|
|
691
|
+
const commands = nextSteps.filter(isCommand);
|
|
692
|
+
const notes = nextSteps.filter((line)=>!isCommand(line));
|
|
693
|
+
const sections = [];
|
|
694
|
+
if (commands.length) sections.push([
|
|
695
|
+
'Run these commands to install the required dependencies:',
|
|
696
|
+
...commands.map((line)=>styleText([
|
|
510
697
|
'bold',
|
|
511
698
|
'cyan'
|
|
512
|
-
],
|
|
699
|
+
], line))
|
|
700
|
+
].join('\n'));
|
|
701
|
+
if (notes.length) sections.push([
|
|
702
|
+
'Additional information:',
|
|
703
|
+
...notes.map((line)=>line.replace(/^(\s*Add )(!\S+)/, (_, prefix, path)=>prefix + styleText([
|
|
704
|
+
'bold',
|
|
705
|
+
'cyan'
|
|
706
|
+
], path)))
|
|
707
|
+
].join('\n'));
|
|
708
|
+
if (sections.length) console.log(sections.join('\n\n'));
|
|
513
709
|
}
|
|
514
710
|
};
|
|
515
711
|
const initializeUseCase = async ()=>{
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const addGitignoreEntry: (root: string, entry: string) => void;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import type { File } from '../file-system';
|
|
2
2
|
export declare const addPackageScripts: (file: File, additions: Record<string, string>) => Promise<Record<string, string>>;
|
|
3
|
+
export declare const describeScripts: (selected: Record<string, string>, descriptions: Record<string, string>) => string[];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const playwrightScripts: {
|
|
2
|
+
'test:e2e': string;
|
|
3
|
+
};
|
|
4
|
+
export declare const playwrightConfig = "import { defineConfig, devices } from '@playwright/test';\n\nexport default defineConfig({\n testDir: './specs/e2e',\n fullyParallel: true,\n forbidOnly: !!process.env.CI,\n retries: process.env.CI ? 2 : 0,\n workers: process.env.CI ? 1 : undefined,\n reporter: 'html',\n use: {\n baseURL: 'http://localhost:3000',\n trace: 'on-first-retry',\n screenshot: 'only-on-failure',\n video: 'retain-on-failure'\n },\n\n projects: [\n {\n name: 'chromium',\n use: { ...devices['Desktop Chrome'] }\n },\n {\n name: 'firefox',\n use: { ...devices['Desktop Firefox'] }\n },\n {\n name: 'webkit',\n use: { ...devices['Desktop Safari'] }\n },\n {\n name: 'Mobile Chrome',\n use: { ...devices['Pixel 5'] }\n },\n {\n name: 'Mobile Safari',\n use: { ...devices['iPhone 12'] }\n }\n ],\n\n webServer: {\n // Playwright only stops the dev server on a clean shutdown. If its process dies any other\n // way (SIGHUP, SIGKILL), the dev server lives on in its own process group, so it is killed\n // as soon as Playwright is gone.\n command:\n process.platform === 'win32'\n ? 'npm run dev'\n : `npm run dev & while kill -0 ${process.pid} 2>/dev/null && kill -0 $! 2>/dev/null; do sleep 1; done; kill 0`,\n url: 'http://localhost:3000',\n timeout: 120000,\n reuseExistingServer: !process.env.CI\n }\n});\n";
|
|
5
|
+
export declare const addPlaywright: () => Promise<string[]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|