@domain-first/project-structure 2.13.0 → 2.14.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 CHANGED
@@ -234,7 +234,9 @@ selected scripts. It does not install packages or execute scripts. Install comma
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
237
- static build goes to `<rootFolder>/presentation/react/storybook-static`.
237
+ static build goes to `<rootFolder>/presentation/react/storybook-static`; the
238
+ integration adds this directory to the project `.gitignore` without duplicating
239
+ the entry on subsequent runs.
238
240
 
239
241
  ### Missing domain-first packages
240
242
 
@@ -279,6 +281,53 @@ Use Node.js 22.18+, TypeScript 5.9+, ESM and JSON import support. Review planned
279
281
  migrations before running the apply script. Generated contract files and
280
282
  migration history are managed by Prisma, not by this scaffolder.
281
283
 
284
+ ### Vitest
285
+
286
+ Choose **Add integration → Vitest**. The integration creates `vitest.config.ts`
287
+ in the project root (the directory containing `package.json`) with
288
+ `resolve.tsconfigPaths` and V8 coverage for `<rootFolder>/bounded-contexts` and
289
+ `<rootFolder>/shared`. Specs, infrastructure, REST presentation and wiring are
290
+ excluded from coverage. When `@domain-first/handlers-next` is declared, the
291
+ config also inlines it so Vitest can resolve its `next/headers` import.
292
+
293
+ It sets `testingLibrary` to `vitest`, so generators scaffold unit tests; if
294
+ another testing library is configured, the CLI asks before replacing it. It also
295
+ adds `/coverage/` to the project `.gitignore` and these package scripts:
296
+
297
+ ```json
298
+ {
299
+ "test": "vitest run --reporter=dot --silent=passed-only",
300
+ "test:coverage": "vitest run --coverage --reporter=dot --silent=passed-only"
301
+ }
302
+ ```
303
+
304
+ Script conflicts and overwrite confirmation work as in the other integrations.
305
+ The printed install command omits version constraints for `vitest` and
306
+ `@vitest/coverage-v8`; already declared dependencies are kept.
307
+ `resolve.tsconfigPaths` requires Vite 8+. The config excludes `specs/e2e`, which
308
+ belongs to Playwright.
309
+
310
+ ### Playwright
311
+
312
+ Choose **Add integration → Playwright**. The integration creates
313
+ `playwright.config.ts` in the project root with `testDir: './specs/e2e'`, an
314
+ HTML reporter, traces on retry, screenshots and videos on failure, and projects
315
+ for Chromium, Firefox, WebKit, Mobile Chrome and Mobile Safari, all running on
316
+ Playwright's own browser builds.
317
+ The web server runs `npm run dev` at `http://localhost:3000` and is reused
318
+ outside CI; adjust `baseURL` and `webServer.url` for another port.
319
+
320
+ A mock example goes to `specs/e2e/home`: `home.e2e.spec.ts` and a `README.MD`
321
+ with its user stories. Existing example files are never overwritten. The
322
+ integration adds a `test:e2e` script (`playwright test`) and ignores
323
+ `/test-results/`, `/playwright-report/`, `/blob-report/`, `/playwright/.cache/`
324
+ and `/playwright/.auth/` in `.gitignore`.
325
+
326
+ After writing, the CLI prints the commands needed to run the specs: installing
327
+ `@playwright/test` if it is missing, `npx playwright install --with-deps` for
328
+ the browsers and their system dependencies, the `test:e2e` script and
329
+ `npx playwright show-report`.
330
+
282
331
  ## Configuration
283
332
 
284
333
  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
@@ -260,6 +260,133 @@ const addPackageScripts = async (file, additions)=>{
260
260
  }
261
261
  return selected;
262
262
  };
263
+ const addGitignoreEntry = (root, entry)=>{
264
+ const gitignore = new File(external_node_path_default().join(root, '.gitignore'));
265
+ const ignored = gitignore.exists ? gitignore.data : '';
266
+ if (ignored.split(/\r?\n/).includes(entry)) return;
267
+ const newline = ignored.includes('\r\n') ? '\r\n' : '\n';
268
+ gitignore.update(`${ignored}${ignored && !ignored.endsWith('\n') ? newline : ''}${entry}${newline}`);
269
+ };
270
+ const playwrightScripts = {
271
+ 'test:e2e': 'playwright test'
272
+ };
273
+ const playwrightConfig = `import { defineConfig, devices } from '@playwright/test';
274
+
275
+ export default defineConfig({
276
+ testDir: './specs/e2e',
277
+ fullyParallel: true,
278
+ forbidOnly: !!process.env.CI,
279
+ retries: process.env.CI ? 2 : 0,
280
+ workers: process.env.CI ? 1 : undefined,
281
+ reporter: 'html',
282
+ use: {
283
+ baseURL: 'http://localhost:3000',
284
+ trace: 'on-first-retry',
285
+ screenshot: 'only-on-failure',
286
+ video: 'retain-on-failure'
287
+ },
288
+
289
+ projects: [
290
+ {
291
+ name: 'chromium',
292
+ use: { ...devices['Desktop Chrome'] }
293
+ },
294
+ {
295
+ name: 'firefox',
296
+ use: { ...devices['Desktop Firefox'] }
297
+ },
298
+ {
299
+ name: 'webkit',
300
+ use: { ...devices['Desktop Safari'] }
301
+ },
302
+ {
303
+ name: 'Mobile Chrome',
304
+ use: { ...devices['Pixel 5'] }
305
+ },
306
+ {
307
+ name: 'Mobile Safari',
308
+ use: { ...devices['iPhone 12'] }
309
+ }
310
+ ],
311
+
312
+ webServer: {
313
+ // Playwright only stops the dev server on a clean shutdown. If its process dies any other
314
+ // way (SIGHUP, SIGKILL), the dev server lives on in its own process group, so it is killed
315
+ // as soon as Playwright is gone.
316
+ command:
317
+ process.platform === 'win32'
318
+ ? 'npm run dev'
319
+ : \`npm run dev & while kill -0 \${process.pid} 2>/dev/null && kill -0 $! 2>/dev/null; do sleep 1; done; kill 0\`,
320
+ url: 'http://localhost:3000',
321
+ timeout: 120000,
322
+ reuseExistingServer: !process.env.CI
323
+ }
324
+ });
325
+ `;
326
+ const exampleSpec = `import { expect, test } from '@playwright/test';
327
+
328
+ test.describe('home page', () => {
329
+ test('opens the home page', async ({ page, baseURL }) => {
330
+ await page.goto('/');
331
+ await expect(page).toHaveURL(\`\${baseURL}/\`);
332
+ });
333
+ });
334
+ `;
335
+ const exampleReadme = `# Home page e2e cases
336
+
337
+ ## User Stories
338
+
339
+ 1. Guest opens \`/\` and stays on the home page.
340
+ `;
341
+ const gitignoreEntries = [
342
+ '/test-results/',
343
+ '/playwright-report/',
344
+ '/blob-report/',
345
+ '/playwright/.cache/',
346
+ '/playwright/.auth/'
347
+ ];
348
+ const addPlaywright = async ()=>{
349
+ const root = new ProjectRoot().path;
350
+ const manifestFile = new File(external_node_path_default().join(root, 'package.json'));
351
+ const manifest = JSON.parse(manifestFile.data);
352
+ const dependencies = {
353
+ ...manifest.dependencies,
354
+ ...manifest.devDependencies
355
+ };
356
+ const selected = await addPackageScripts(manifestFile, playwrightScripts);
357
+ const configFile = new File(external_node_path_default().join(root, 'playwright.config.ts'));
358
+ if (!configFile.exists || configFile.data !== playwrightConfig) configFile.data = playwrightConfig;
359
+ const exampleFolder = external_node_path_default().join(root, 'specs/e2e/home');
360
+ for (const [name, content] of [
361
+ [
362
+ 'home.e2e.spec.ts',
363
+ exampleSpec
364
+ ],
365
+ [
366
+ 'README.MD',
367
+ exampleReadme
368
+ ]
369
+ ]){
370
+ const file = new File(external_node_path_default().join(exampleFolder, name));
371
+ if (!file.exists) file.data = content;
372
+ }
373
+ for (const entry of gitignoreEntries)addGitignoreEntry(root, entry);
374
+ return [
375
+ 'Playwright configuration saved.',
376
+ 'Next steps (run from the project package directory):',
377
+ ...dependencies['@playwright/test'] ? [] : [
378
+ ' npm install --save-dev @playwright/test'
379
+ ],
380
+ ' npx playwright install --with-deps',
381
+ ' Existing dependency versions were kept.',
382
+ ...manifest.scripts?.dev ? [] : [
383
+ ' Add a "dev" script: Playwright starts it as the web server.'
384
+ ],
385
+ ' Adjust baseURL and webServer.url if the dev server does not listen on http://localhost:3000.',
386
+ ` ${selected['test:e2e'] ? `npm run ${selected['test:e2e']}` : 'npx playwright test'}`,
387
+ ' Open the HTML report: npx playwright show-report'
388
+ ];
389
+ };
263
390
  const runtimePackages = [
264
391
  '@prisma/orm-postgres',
265
392
  'temporal-polyfill',
@@ -376,6 +503,7 @@ const addPrisma = async ()=>{
376
503
  'Next steps (run from the project package directory):',
377
504
  ...install(runtimePackages, false),
378
505
  ...install(developmentPackages, true),
506
+ ` Add !${relativeFolder} in your linter, to ignore prisma files.`,
379
507
  ' Existing dependency versions were kept.',
380
508
  ' Use Node.js 22.18+ and TypeScript 5.9+ with ESM and JSON import support.',
381
509
  ' Set DATABASE_URL in your project environment (.env for the CLI); load it in the application runtime too.',
@@ -466,6 +594,8 @@ const addStorybook = async ()=>{
466
594
  useReact: true,
467
595
  storybookFramework: '@storybook/react-vite'
468
596
  });
597
+ const buildFolder = external_node_path_default().posix.join(config.rootFolder.replaceAll('\\', '/'), 'presentation/react/storybook-static');
598
+ addGitignoreEntry(root, `/${buildFolder}/`);
469
599
  const dependencies = {
470
600
  ...manifest.dependencies,
471
601
  ...manifest.devDependencies
@@ -500,6 +630,86 @@ const addStorybook = async ()=>{
500
630
  ] : []
501
631
  ];
502
632
  };
633
+ const vitestScripts = {
634
+ test: 'vitest run --reporter=dot --silent=passed-only',
635
+ 'test:coverage': 'vitest run --coverage --reporter=dot --silent=passed-only'
636
+ };
637
+ const vitestConfig = (rootFolder, inlineHandlersNext)=>{
638
+ const folder = (subpath)=>JSON.stringify(external_node_path_default().posix.join(rootFolder.replaceAll('\\', '/'), subpath));
639
+ const server = inlineHandlersNext ? `,
640
+ server: {
641
+ deps: {
642
+ // Imports \`next/headers\` without an extension, which only a bundler can resolve
643
+ inline: ['@domain-first/handlers-next']
644
+ }
645
+ }` : '';
646
+ return `import { configDefaults, defineConfig } from 'vitest/config';
647
+
648
+ export default defineConfig({
649
+ resolve: {
650
+ tsconfigPaths: true
651
+ },
652
+ test: {
653
+ // Playwright runs end-to-end specs
654
+ exclude: [...configDefaults.exclude, 'specs/e2e/**'],
655
+ coverage: {
656
+ provider: 'v8',
657
+ include: [${folder('bounded-contexts/**/*.ts')}, ${folder('shared/**/*.ts')}],
658
+ exclude: [
659
+ '**/*.spec.ts',
660
+ ${folder('shared/infrastructure/**')},
661
+ ${folder('bounded-contexts/*/infrastructure/**')},
662
+ ${folder('bounded-contexts/*/presentation/rest/**')},
663
+ ${folder('shared/wiring/**')},
664
+ ${folder('bounded-contexts/*/wiring/**')}
665
+ ],
666
+ reporter: [['text', { skipFull: true }], 'html']
667
+ }${server}
668
+ }
669
+ });
670
+ `;
671
+ };
672
+ const addVitest = async ()=>{
673
+ const config = ConfigFile.Instance.data;
674
+ if (config.testingLibrary && 'vitest' !== config.testingLibrary && !await (0, prompts_namespaceObject.confirm)({
675
+ message: `Replace testing library "${config.testingLibrary}" with vitest for generated tests?`,
676
+ default: false
677
+ })) return [];
678
+ const root = new ProjectRoot().path;
679
+ const manifestFile = new File(external_node_path_default().join(root, 'package.json'));
680
+ const manifest = JSON.parse(manifestFile.data);
681
+ const dependencies = {
682
+ ...manifest.dependencies,
683
+ ...manifest.devDependencies
684
+ };
685
+ const selected = await addPackageScripts(manifestFile, vitestScripts);
686
+ const configFile = new File(external_node_path_default().join(root, 'vitest.config.ts'));
687
+ const content = vitestConfig(config.rootFolder, Boolean(dependencies['@domain-first/handlers-next']));
688
+ if (!configFile.exists || configFile.data !== content) configFile.data = content;
689
+ if ('vitest' !== config.testingLibrary) ConfigFile.write({
690
+ ...config,
691
+ testingLibrary: 'vitest'
692
+ });
693
+ addGitignoreEntry(root, '/coverage/');
694
+ const missing = [
695
+ 'vitest',
696
+ '@vitest/coverage-v8'
697
+ ].filter((name)=>!dependencies[name]);
698
+ return [
699
+ 'Vitest configuration saved.',
700
+ 'Next steps (run from the project package directory):',
701
+ ...missing.length ? [
702
+ ` npm install --save-dev ${missing.join(' ')}`
703
+ ] : [],
704
+ ' Existing dependency versions were kept; resolve.tsconfigPaths requires Vite 8+.',
705
+ ...selected.test ? [
706
+ ` npm run ${selected.test}`
707
+ ] : [],
708
+ ...selected['test:coverage'] ? [
709
+ ` npm run ${selected['test:coverage']}`
710
+ ] : []
711
+ ];
712
+ };
503
713
  const integrations = [
504
714
  {
505
715
  name: 'Storybook (React + Vite)',
@@ -509,6 +719,14 @@ const integrations = [
509
719
  name: 'Prisma 8 (PostgreSQL, RC)',
510
720
  run: addPrisma
511
721
  },
722
+ {
723
+ name: 'Vitest',
724
+ run: addVitest
725
+ },
726
+ {
727
+ name: 'Playwright',
728
+ run: addPlaywright
729
+ },
512
730
  {
513
731
  name: 'Missing domain-first packages',
514
732
  run: missingDomainFirstPackages
@@ -524,10 +742,13 @@ const addIntegration = async ()=>{
524
742
  });
525
743
  const nextSteps = await integrations[index].run();
526
744
  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)([
745
+ if (nextSteps.length) console.log(nextSteps.map((line)=>/^\s*(?:npm (?:i|install)|npx playwright install)\b/.test(line) ? (0, external_node_util_namespaceObject.styleText)([
528
746
  'bold',
529
747
  'cyan'
530
- ], line) : line).join('\n'));
748
+ ], line) : line.replace(/^(\s*Add )(!\S+)/, (_, prefix, path)=>prefix + (0, external_node_util_namespaceObject.styleText)([
749
+ 'bold',
750
+ 'cyan'
751
+ ], path))).join('\n'));
531
752
  }
532
753
  };
533
754
  const initializeUseCase = async ()=>{
package/dist/index.js CHANGED
@@ -230,6 +230,133 @@ const addPackageScripts = async (file, additions)=>{
230
230
  }
231
231
  return selected;
232
232
  };
233
+ const addGitignoreEntry = (root, entry)=>{
234
+ const gitignore = new File(node_path.join(root, '.gitignore'));
235
+ const ignored = gitignore.exists ? gitignore.data : '';
236
+ if (ignored.split(/\r?\n/).includes(entry)) return;
237
+ const newline = ignored.includes('\r\n') ? '\r\n' : '\n';
238
+ gitignore.update(`${ignored}${ignored && !ignored.endsWith('\n') ? newline : ''}${entry}${newline}`);
239
+ };
240
+ const playwrightScripts = {
241
+ 'test:e2e': 'playwright test'
242
+ };
243
+ const playwrightConfig = `import { defineConfig, devices } from '@playwright/test';
244
+
245
+ export default defineConfig({
246
+ testDir: './specs/e2e',
247
+ fullyParallel: true,
248
+ forbidOnly: !!process.env.CI,
249
+ retries: process.env.CI ? 2 : 0,
250
+ workers: process.env.CI ? 1 : undefined,
251
+ reporter: 'html',
252
+ use: {
253
+ baseURL: 'http://localhost:3000',
254
+ trace: 'on-first-retry',
255
+ screenshot: 'only-on-failure',
256
+ video: 'retain-on-failure'
257
+ },
258
+
259
+ projects: [
260
+ {
261
+ name: 'chromium',
262
+ use: { ...devices['Desktop Chrome'] }
263
+ },
264
+ {
265
+ name: 'firefox',
266
+ use: { ...devices['Desktop Firefox'] }
267
+ },
268
+ {
269
+ name: 'webkit',
270
+ use: { ...devices['Desktop Safari'] }
271
+ },
272
+ {
273
+ name: 'Mobile Chrome',
274
+ use: { ...devices['Pixel 5'] }
275
+ },
276
+ {
277
+ name: 'Mobile Safari',
278
+ use: { ...devices['iPhone 12'] }
279
+ }
280
+ ],
281
+
282
+ webServer: {
283
+ // Playwright only stops the dev server on a clean shutdown. If its process dies any other
284
+ // way (SIGHUP, SIGKILL), the dev server lives on in its own process group, so it is killed
285
+ // as soon as Playwright is gone.
286
+ command:
287
+ process.platform === 'win32'
288
+ ? 'npm run dev'
289
+ : \`npm run dev & while kill -0 \${process.pid} 2>/dev/null && kill -0 $! 2>/dev/null; do sleep 1; done; kill 0\`,
290
+ url: 'http://localhost:3000',
291
+ timeout: 120000,
292
+ reuseExistingServer: !process.env.CI
293
+ }
294
+ });
295
+ `;
296
+ const exampleSpec = `import { expect, test } from '@playwright/test';
297
+
298
+ test.describe('home page', () => {
299
+ test('opens the home page', async ({ page, baseURL }) => {
300
+ await page.goto('/');
301
+ await expect(page).toHaveURL(\`\${baseURL}/\`);
302
+ });
303
+ });
304
+ `;
305
+ const exampleReadme = `# Home page e2e cases
306
+
307
+ ## User Stories
308
+
309
+ 1. Guest opens \`/\` and stays on the home page.
310
+ `;
311
+ const gitignoreEntries = [
312
+ '/test-results/',
313
+ '/playwright-report/',
314
+ '/blob-report/',
315
+ '/playwright/.cache/',
316
+ '/playwright/.auth/'
317
+ ];
318
+ const addPlaywright = async ()=>{
319
+ const root = new ProjectRoot().path;
320
+ const manifestFile = new File(node_path.join(root, 'package.json'));
321
+ const manifest = JSON.parse(manifestFile.data);
322
+ const dependencies = {
323
+ ...manifest.dependencies,
324
+ ...manifest.devDependencies
325
+ };
326
+ const selected = await addPackageScripts(manifestFile, playwrightScripts);
327
+ const configFile = new File(node_path.join(root, 'playwright.config.ts'));
328
+ if (!configFile.exists || configFile.data !== playwrightConfig) configFile.data = playwrightConfig;
329
+ const exampleFolder = node_path.join(root, 'specs/e2e/home');
330
+ for (const [name, content] of [
331
+ [
332
+ 'home.e2e.spec.ts',
333
+ exampleSpec
334
+ ],
335
+ [
336
+ 'README.MD',
337
+ exampleReadme
338
+ ]
339
+ ]){
340
+ const file = new File(node_path.join(exampleFolder, name));
341
+ if (!file.exists) file.data = content;
342
+ }
343
+ for (const entry of gitignoreEntries)addGitignoreEntry(root, entry);
344
+ return [
345
+ 'Playwright configuration saved.',
346
+ 'Next steps (run from the project package directory):',
347
+ ...dependencies['@playwright/test'] ? [] : [
348
+ ' npm install --save-dev @playwright/test'
349
+ ],
350
+ ' npx playwright install --with-deps',
351
+ ' Existing dependency versions were kept.',
352
+ ...manifest.scripts?.dev ? [] : [
353
+ ' Add a "dev" script: Playwright starts it as the web server.'
354
+ ],
355
+ ' Adjust baseURL and webServer.url if the dev server does not listen on http://localhost:3000.',
356
+ ` ${selected['test:e2e'] ? `npm run ${selected['test:e2e']}` : 'npx playwright test'}`,
357
+ ' Open the HTML report: npx playwright show-report'
358
+ ];
359
+ };
233
360
  const runtimePackages = [
234
361
  '@prisma/orm-postgres',
235
362
  'temporal-polyfill',
@@ -346,6 +473,7 @@ const addPrisma = async ()=>{
346
473
  'Next steps (run from the project package directory):',
347
474
  ...install(runtimePackages, false),
348
475
  ...install(developmentPackages, true),
476
+ ` Add !${relativeFolder} in your linter, to ignore prisma files.`,
349
477
  ' Existing dependency versions were kept.',
350
478
  ' Use Node.js 22.18+ and TypeScript 5.9+ with ESM and JSON import support.',
351
479
  ' Set DATABASE_URL in your project environment (.env for the CLI); load it in the application runtime too.',
@@ -436,6 +564,8 @@ const addStorybook = async ()=>{
436
564
  useReact: true,
437
565
  storybookFramework: '@storybook/react-vite'
438
566
  });
567
+ const buildFolder = node_path.posix.join(config.rootFolder.replaceAll('\\', '/'), 'presentation/react/storybook-static');
568
+ addGitignoreEntry(root, `/${buildFolder}/`);
439
569
  const dependencies = {
440
570
  ...manifest.dependencies,
441
571
  ...manifest.devDependencies
@@ -470,6 +600,86 @@ const addStorybook = async ()=>{
470
600
  ] : []
471
601
  ];
472
602
  };
603
+ const vitestScripts = {
604
+ test: 'vitest run --reporter=dot --silent=passed-only',
605
+ 'test:coverage': 'vitest run --coverage --reporter=dot --silent=passed-only'
606
+ };
607
+ const vitestConfig = (rootFolder, inlineHandlersNext)=>{
608
+ const folder = (subpath)=>JSON.stringify(node_path.posix.join(rootFolder.replaceAll('\\', '/'), subpath));
609
+ const server = inlineHandlersNext ? `,
610
+ server: {
611
+ deps: {
612
+ // Imports \`next/headers\` without an extension, which only a bundler can resolve
613
+ inline: ['@domain-first/handlers-next']
614
+ }
615
+ }` : '';
616
+ return `import { configDefaults, defineConfig } from 'vitest/config';
617
+
618
+ export default defineConfig({
619
+ resolve: {
620
+ tsconfigPaths: true
621
+ },
622
+ test: {
623
+ // Playwright runs end-to-end specs
624
+ exclude: [...configDefaults.exclude, 'specs/e2e/**'],
625
+ coverage: {
626
+ provider: 'v8',
627
+ include: [${folder('bounded-contexts/**/*.ts')}, ${folder('shared/**/*.ts')}],
628
+ exclude: [
629
+ '**/*.spec.ts',
630
+ ${folder('shared/infrastructure/**')},
631
+ ${folder('bounded-contexts/*/infrastructure/**')},
632
+ ${folder('bounded-contexts/*/presentation/rest/**')},
633
+ ${folder('shared/wiring/**')},
634
+ ${folder('bounded-contexts/*/wiring/**')}
635
+ ],
636
+ reporter: [['text', { skipFull: true }], 'html']
637
+ }${server}
638
+ }
639
+ });
640
+ `;
641
+ };
642
+ const addVitest = async ()=>{
643
+ const config = ConfigFile.Instance.data;
644
+ if (config.testingLibrary && 'vitest' !== config.testingLibrary && !await prompts_confirm({
645
+ message: `Replace testing library "${config.testingLibrary}" with vitest for generated tests?`,
646
+ default: false
647
+ })) return [];
648
+ const root = new ProjectRoot().path;
649
+ const manifestFile = new File(node_path.join(root, 'package.json'));
650
+ const manifest = JSON.parse(manifestFile.data);
651
+ const dependencies = {
652
+ ...manifest.dependencies,
653
+ ...manifest.devDependencies
654
+ };
655
+ const selected = await addPackageScripts(manifestFile, vitestScripts);
656
+ const configFile = new File(node_path.join(root, 'vitest.config.ts'));
657
+ const content = vitestConfig(config.rootFolder, Boolean(dependencies['@domain-first/handlers-next']));
658
+ if (!configFile.exists || configFile.data !== content) configFile.data = content;
659
+ if ('vitest' !== config.testingLibrary) ConfigFile.write({
660
+ ...config,
661
+ testingLibrary: 'vitest'
662
+ });
663
+ addGitignoreEntry(root, '/coverage/');
664
+ const missing = [
665
+ 'vitest',
666
+ '@vitest/coverage-v8'
667
+ ].filter((name)=>!dependencies[name]);
668
+ return [
669
+ 'Vitest configuration saved.',
670
+ 'Next steps (run from the project package directory):',
671
+ ...missing.length ? [
672
+ ` npm install --save-dev ${missing.join(' ')}`
673
+ ] : [],
674
+ ' Existing dependency versions were kept; resolve.tsconfigPaths requires Vite 8+.',
675
+ ...selected.test ? [
676
+ ` npm run ${selected.test}`
677
+ ] : [],
678
+ ...selected['test:coverage'] ? [
679
+ ` npm run ${selected['test:coverage']}`
680
+ ] : []
681
+ ];
682
+ };
473
683
  const integrations = [
474
684
  {
475
685
  name: 'Storybook (React + Vite)',
@@ -479,6 +689,14 @@ const integrations = [
479
689
  name: 'Prisma 8 (PostgreSQL, RC)',
480
690
  run: addPrisma
481
691
  },
692
+ {
693
+ name: 'Vitest',
694
+ run: addVitest
695
+ },
696
+ {
697
+ name: 'Playwright',
698
+ run: addPlaywright
699
+ },
482
700
  {
483
701
  name: 'Missing domain-first packages',
484
702
  run: missingDomainFirstPackages
@@ -494,10 +712,13 @@ const addIntegration = async ()=>{
494
712
  });
495
713
  const nextSteps = await integrations[index].run();
496
714
  if (await savePendingChanges()) {
497
- if (nextSteps.length) console.log(nextSteps.map((line)=>/^\s*npm (?:i|install)\b/.test(line) ? styleText([
715
+ if (nextSteps.length) console.log(nextSteps.map((line)=>/^\s*(?:npm (?:i|install)|npx playwright install)\b/.test(line) ? styleText([
498
716
  'bold',
499
717
  'cyan'
500
- ], line) : line).join('\n'));
718
+ ], line) : line.replace(/^(\s*Add )(!\S+)/, (_, prefix, path)=>prefix + styleText([
719
+ 'bold',
720
+ 'cyan'
721
+ ], path))).join('\n'));
501
722
  }
502
723
  };
503
724
  const initializeUseCase = async ()=>{
@@ -0,0 +1 @@
1
+ export declare const addGitignoreEntry: (root: string, entry: string) => void;
@@ -1,4 +1,6 @@
1
1
  export * from './missing-domain-first-packages';
2
2
  export * from './package-scripts';
3
+ export * from './playwright';
3
4
  export * from './prisma';
4
5
  export * from './storybook';
6
+ export * from './vitest';
@@ -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,6 @@
1
+ export declare const vitestScripts: {
2
+ test: string;
3
+ 'test:coverage': string;
4
+ };
5
+ export declare const vitestConfig: (rootFolder: string, inlineHandlersNext: boolean) => string;
6
+ export declare const addVitest: () => Promise<string[]>;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@domain-first/project-structure",
3
3
  "description": "Build and manage your Domain-First project structure with CLI",
4
- "version": "2.13.0",
4
+ "version": "2.14.0",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",