@domain-first/project-structure 2.8.0 → 2.9.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
@@ -52,7 +52,7 @@ On the first run, the CLI asks for:
52
52
  | `@domain-first` packages | The integrations to use in generated templates. |
53
53
  | Default persistence implementation | A label such as `prisma`, used as the suggested implementation for execution commands and queries. |
54
54
  | React | Whether to show the React module menu. |
55
- | Unit tests | Whether to offer test generation, and which module to import test helpers from. Suggested module: `vitest`. |
55
+ | Unit tests | Whether to generate tests, and which module to import test helpers from. Suggested module: `vitest`. |
56
56
 
57
57
  Setup writes `domain-first.project-structure.config.json` beside your `package.json` and creates shared helpers for the selected `wire` and `errors` integrations. That first run then exits.
58
58
 
@@ -118,7 +118,8 @@ src/
118
118
  └── react/
119
119
  ├── pages/
120
120
  ├── widgets/
121
- └── ui-kit/
121
+ ├── ui-kit/
122
+ └── hooks/
122
123
  ```
123
124
 
124
125
  This is an example of the accumulated output; creating a context alone creates its directory and, when enabled, its error namespace.
@@ -161,7 +162,7 @@ With `@domain-first/wire`, generators create `wireClass` factories. Repositories
161
162
 
162
163
  Implementation names such as `prisma`, `api`, `in-memory`, and `mock` determine names and locations for generated classes. Add the database queries, API calls, or in-memory behavior yourself. Fill in the dependency lists in wiring factories as you implement constructors.
163
164
 
164
- When `testingLibrary` is configured, supported generators ask whether to add `.spec.ts` files. These start with construction or wiring checks; extend them with tests for your business behavior. Repository, command, query, and port test templates reference wiring factories, so use the wiring integration or adapt those tests to your own construction setup.
165
+ When `testingLibrary` is configured, supported generators always add `.spec.ts` files. These start with construction or wiring checks; extend them with tests for your business behavior. Repository, command, query, and port test templates reference wiring factories, so use the wiring integration or adapt those tests to your own construction setup.
165
166
 
166
167
  ### REST endpoints
167
168
 
@@ -182,10 +183,11 @@ Enable `useReact` and choose **Scaffold React module** from the main menu. Modul
182
183
  | Generator | Output |
183
184
  | ------------------------------ | ---------------------------------------------------------------------------------------------------------- |
184
185
  | New page | `pages/<name>-page.tsx` with a typed props object and a component. |
185
- | New widget → monolithic | `widgets/<name>/index.tsx` with props and rendering in one file. |
186
- | New widget → with separated ui | Widget entry point, `types.ts`, `ui/index.tsx`, and `hooks/use-ui-model.ts`. |
187
- | New widget → headless | Widget entry point, types, and a UI-model hook; the rendering component is supplied through the `UI` prop. |
188
- | New UI-kit component | `ui-kit/<name>/index.tsx` with a typed props object and a component; with `storybookFramework`, also `<name>.stories.tsx`. |
186
+ | New widget → monolithic | `widgets/<name>/<name>-widget.tsx` with props and rendering in one file, re-exported from `index.ts`. |
187
+ | New widget → with separated ui | `<name>-widget.tsx`, `types.ts`, `ui/<name>-widget-ui.tsx`, `hooks/use-<name>-ui-model.ts`, and `index.ts`. |
188
+ | New widget → headless | `<name>-widget.tsx`, types, a UI-model hook, and `index.ts`; the rendering component is supplied through the `UI` prop. |
189
+ | New UI-kit component | `ui-kit/<name>/<name>.tsx` with a typed props object and a component, re-exported from `index.ts`; with `storybookFramework`, also `<name>.stories.tsx`. |
190
+ | New shared hook | `hooks/use-<name>.ts` with an app-wide hook, such as `use-debounce`; a leading `use-` in the name is not repeated. |
189
191
 
190
192
  ## Configuration
191
193
 
@@ -215,7 +217,7 @@ The project configuration is stored in `domain-first.project-structure.config.js
215
217
  | `defaultPersistenceLayerImplementation` | Suggested implementation label for execution commands and queries. |
216
218
  | `useReact` | Shows or hides the React module menu. |
217
219
  | `storybookFramework` | Storybook framework package imported by generated stories (`Meta`, `StoryObj`), e.g. `@storybook/react-vite`. Omit this field to skip stories for UI-kit components. Asked during setup only when React is enabled. |
218
- | `testingLibrary` | Module imported by generated tests. Omit this field to disable test prompts. Templates expect helpers such as `describe`, `test`, `expect`, and `beforeEach`. |
220
+ | `testingLibrary` | Module imported by generated tests. Omit this field to disable test generation. Templates expect helpers such as `describe`, `test`, `expect`, and `beforeEach`. |
219
221
 
220
222
  ### Package integrations
221
223
 
package/dist/index.cjs CHANGED
@@ -254,10 +254,7 @@ const scaffoldNewAggregateUseCase = async (boundedContextFolder)=>{
254
254
  message: 'Aggregate name:'
255
255
  });
256
256
  const aggregateNaming = new UnknownFormatNaming(aggregateName);
257
- let scaffoldUnitTests;
258
- if (ConfigFile.Instance.data.testingLibrary) scaffoldUnitTests = await (0, prompts_namespaceObject.confirm)({
259
- message: 'Scaffold unit-tests'
260
- });
257
+ const scaffoldUnitTests = Boolean(ConfigFile.Instance.data.testingLibrary);
261
258
  const withRepository = await (0, prompts_namespaceObject.confirm)({
262
259
  message: 'With Repository'
263
260
  });
@@ -375,10 +372,7 @@ const scaffoldNewApplicationPort = async (boundedContextFolder)=>{
375
372
  message: 'Name: '
376
373
  });
377
374
  const naming = new UnknownFormatNaming(name);
378
- let scaffoldUnitTests;
379
- if (ConfigFile.Instance.data.testingLibrary) scaffoldUnitTests = await (0, prompts_namespaceObject.confirm)({
380
- message: 'Scaffold unit-tests'
381
- });
375
+ const scaffoldUnitTests = Boolean(ConfigFile.Instance.data.testingLibrary);
382
376
  const wiringFolder = boundedContextFolder.subitem([
383
377
  'wiring',
384
378
  'application-ports'
@@ -472,10 +466,7 @@ const scaffoldNewApplicationService = async (boundedContextFolder)=>{
472
466
  message: 'Name: '
473
467
  });
474
468
  const naming = new UnknownFormatNaming(name);
475
- let scaffoldUnitTests;
476
- if (ConfigFile.Instance.data.testingLibrary) scaffoldUnitTests = await (0, prompts_namespaceObject.confirm)({
477
- message: 'Scaffold unit-tests'
478
- });
469
+ const scaffoldUnitTests = Boolean(ConfigFile.Instance.data.testingLibrary);
479
470
  const withWiring = ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
480
471
  const wiringFolder = boundedContextFolder.subitem([
481
472
  'wiring',
@@ -551,10 +542,7 @@ const scaffoldNewCommand = async (boundedContextFolder)=>{
551
542
  const commandName = await (0, prompts_namespaceObject.input)({
552
543
  message: 'Name: '
553
544
  });
554
- let scaffoldUnitTests;
555
- if (ConfigFile.Instance.data.testingLibrary) scaffoldUnitTests = await (0, prompts_namespaceObject.confirm)({
556
- message: 'Scaffold unit-tests'
557
- });
545
+ const scaffoldUnitTests = Boolean(ConfigFile.Instance.data.testingLibrary);
558
546
  const naming = new UnknownFormatNaming(commandName);
559
547
  const commandType = await (0, prompts_namespaceObject.select)({
560
548
  choices: [
@@ -736,10 +724,7 @@ const scaffoldNewDomainService = async (boundedContextFolder)=>{
736
724
  message: 'Name:'
737
725
  });
738
726
  const naming = new UnknownFormatNaming(portName);
739
- let scaffoldUnitTests;
740
- if (ConfigFile.Instance.data.testingLibrary) scaffoldUnitTests = await (0, prompts_namespaceObject.confirm)({
741
- message: 'Scaffold unit-tests'
742
- });
727
+ const scaffoldUnitTests = Boolean(ConfigFile.Instance.data.testingLibrary);
743
728
  const withWiring = ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
744
729
  const domainServicesFolder = boundedContextFolder.subitem([
745
730
  'domain',
@@ -925,10 +910,7 @@ const scaffoldNewInfrastructureService = async (boundedContextFolder)=>{
925
910
  message: 'Name: '
926
911
  });
927
912
  const naming = new UnknownFormatNaming(name);
928
- let scaffoldUnitTests;
929
- if (ConfigFile.Instance.data.testingLibrary) scaffoldUnitTests = await (0, prompts_namespaceObject.confirm)({
930
- message: 'Scaffold unit-tests'
931
- });
913
+ const scaffoldUnitTests = Boolean(ConfigFile.Instance.data.testingLibrary);
932
914
  const withWiring = ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
933
915
  const wiringFolder = boundedContextFolder.subitem([
934
916
  'wiring',
@@ -975,10 +957,7 @@ const scaffoldNewPresentationService = async (boundedContextFolder)=>{
975
957
  message: 'Name: '
976
958
  });
977
959
  const naming = new UnknownFormatNaming(name);
978
- let scaffoldUnitTests;
979
- if (ConfigFile.Instance.data.testingLibrary) scaffoldUnitTests = await (0, prompts_namespaceObject.confirm)({
980
- message: 'Scaffold unit-tests'
981
- });
960
+ const scaffoldUnitTests = Boolean(ConfigFile.Instance.data.testingLibrary);
982
961
  const withWiring = ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
983
962
  const wiringFolder = boundedContextFolder.subitem([
984
963
  'wiring',
@@ -1033,10 +1012,7 @@ const scaffoldNewQuery = async (boundedContextFolder)=>{
1033
1012
  message: 'Name: '
1034
1013
  });
1035
1014
  const naming = new UnknownFormatNaming(queryName);
1036
- let scaffoldUnitTests;
1037
- if (ConfigFile.Instance.data.testingLibrary) scaffoldUnitTests = await (0, prompts_namespaceObject.confirm)({
1038
- message: 'Scaffold unit-tests'
1039
- });
1015
+ const scaffoldUnitTests = Boolean(ConfigFile.Instance.data.testingLibrary);
1040
1016
  const queryType = await (0, prompts_namespaceObject.select)({
1041
1017
  choices: [
1042
1018
  'Execution (with infrastructure implementation)',
@@ -1221,10 +1197,7 @@ const scaffoldNewUseCase = async (boundedContextFolder)=>{
1221
1197
  message: 'Name: '
1222
1198
  });
1223
1199
  const naming = new UnknownFormatNaming(useCaseName);
1224
- let scaffoldUnitTests;
1225
- if (ConfigFile.Instance.data.testingLibrary) scaffoldUnitTests = await (0, prompts_namespaceObject.confirm)({
1226
- message: 'Scaffold unit-tests'
1227
- });
1200
+ const scaffoldUnitTests = Boolean(ConfigFile.Instance.data.testingLibrary);
1228
1201
  const withWiring = ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
1229
1202
  useCasesFolder.createFile(`${naming.fileName}-use-case.ts`, ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers') ? `
1230
1203
  import { defineHandler } from '@domain-first/handlers'
@@ -1296,6 +1269,19 @@ export const ${ClassName}Page: FC<${ClassName}PageProps> = (props) => {
1296
1269
  }
1297
1270
  `.trim());
1298
1271
  };
1272
+ const scaffoldReactSharedHook = async (presentationReactFolder)=>{
1273
+ const name = await (0, prompts_namespaceObject.input)({
1274
+ message: 'Name without "use" (e.g. debounce): '
1275
+ });
1276
+ const { ClassName, fileName } = new UnknownFormatNaming(name.trim().replace(/^use-/, ''));
1277
+ presentationReactFolder.subitem([
1278
+ 'hooks'
1279
+ ]).createFile(`use-${fileName}.ts`, `
1280
+ export const use${ClassName} = () => {
1281
+ return {}
1282
+ }
1283
+ `.trim());
1284
+ };
1299
1285
  const scaffoldReactUIKitComponent = async (presentationReactFolder)=>{
1300
1286
  const name = await (0, prompts_namespaceObject.input)({
1301
1287
  message: 'Name: '
@@ -1305,7 +1291,8 @@ const scaffoldReactUIKitComponent = async (presentationReactFolder)=>{
1305
1291
  'ui-kit',
1306
1292
  fileName
1307
1293
  ]);
1308
- componentFolder.createFile('index.tsx', `
1294
+ componentFolder.createFile('index.ts', `export * from './${fileName}'`);
1295
+ componentFolder.createFile(`${fileName}.tsx`, `
1309
1296
  import { type FC } from 'react'
1310
1297
 
1311
1298
  export type ${ClassName}Props = {}
@@ -1317,7 +1304,7 @@ export const ${ClassName}: FC<${ClassName}Props> = (props) => {
1317
1304
  const { storybookFramework } = ConfigFile.Instance.data;
1318
1305
  if (storybookFramework) componentFolder.createFile(`${fileName}.stories.tsx`, `
1319
1306
  import type { Meta, StoryObj } from '${storybookFramework}'
1320
- import { ${ClassName} } from '.'
1307
+ import { ${ClassName} } from './${fileName}'
1321
1308
 
1322
1309
  const meta = {
1323
1310
  title: 'UI-kit/${ClassName}',
@@ -1350,9 +1337,13 @@ const scaffoldReactWidget = async (presentationReactFolder)=>{
1350
1337
  'widgets',
1351
1338
  fileName
1352
1339
  ]);
1340
+ const widgetFileName = `${fileName}-widget`;
1341
+ const uiFileName = `${fileName}-widget-ui`;
1342
+ const uiModelFileName = `use-${fileName}-ui-model`;
1343
+ folder.createFile('index.ts', `export * from './${widgetFileName}'`);
1353
1344
  switch(widgetType){
1354
1345
  case 'monolithic':
1355
- folder.createFile('index.tsx', `
1346
+ folder.createFile(`${widgetFileName}.tsx`, `
1356
1347
  import { type FC } from 'react'
1357
1348
 
1358
1349
  export type ${ClassName}WidgetProps = {}
@@ -1368,14 +1359,14 @@ export type ${ClassName}WidgetProps = { }
1368
1359
 
1369
1360
  export type ${ClassName}WidgetUIProps = { }
1370
1361
  `.trim());
1371
- folder.createFile('index.tsx', `
1362
+ folder.createFile(`${widgetFileName}.tsx`, `
1372
1363
  import { type FC } from 'react'
1373
1364
  import type { ${ClassName}WidgetProps } from './types'
1374
- import { ${ClassName}WidgetUI } from './ui'
1375
- import { useUIModel } from './hooks/use-ui-model'
1365
+ import { ${ClassName}WidgetUI } from './ui/${uiFileName}'
1366
+ import { use${ClassName}UIModel } from './hooks/${uiModelFileName}'
1376
1367
 
1377
1368
  export const ${ClassName}Widget: FC<${ClassName}WidgetProps> = (props) => {
1378
- const uiModel = useUIModel(props)
1369
+ const uiModel = use${ClassName}UIModel(props)
1379
1370
  return <${ClassName}WidgetUI {...uiModel} />
1380
1371
  }
1381
1372
 
@@ -1383,7 +1374,7 @@ export type { ${ClassName}WidgetProps }
1383
1374
  `.trim());
1384
1375
  folder.subitem([
1385
1376
  'ui'
1386
- ]).createFile('index.tsx', `
1377
+ ]).createFile(`${uiFileName}.tsx`, `
1387
1378
  import { FC } from 'react'
1388
1379
  import type { ${ClassName}WidgetUIProps } from '../types'
1389
1380
 
@@ -1393,10 +1384,10 @@ export const ${ClassName}WidgetUI: FC<${ClassName}WidgetUIProps> = (props) => {
1393
1384
  `.trim());
1394
1385
  folder.subitem([
1395
1386
  'hooks'
1396
- ]).createFile('use-ui-model.ts', `
1387
+ ]).createFile(`${uiModelFileName}.ts`, `
1397
1388
  import type { ${ClassName}WidgetProps, ${ClassName}WidgetUIProps } from '../types'
1398
1389
 
1399
- export const useUIModel = (widgetProps: ${ClassName}WidgetProps): ${ClassName}WidgetUIProps => {
1390
+ export const use${ClassName}UIModel = (widgetProps: ${ClassName}WidgetProps): ${ClassName}WidgetUIProps => {
1400
1391
  return {}
1401
1392
  }
1402
1393
  `.trim());
@@ -1412,13 +1403,13 @@ export type ${ClassName}WidgetProps = {
1412
1403
  }
1413
1404
 
1414
1405
  `.trim());
1415
- folder.createFile('index.tsx', `
1406
+ folder.createFile(`${widgetFileName}.tsx`, `
1416
1407
  import { type FC } from 'react'
1417
1408
  import type { ${ClassName}WidgetProps } from './types'
1418
- import { useUIModel } from './hooks/use-ui-model'
1409
+ import { use${ClassName}UIModel } from './hooks/${uiModelFileName}'
1419
1410
 
1420
1411
  export const ${ClassName}Widget: FC<${ClassName}WidgetProps> = (props) => {
1421
- const uiModel = useUIModel(props)
1412
+ const uiModel = use${ClassName}UIModel(props)
1422
1413
  return <props.UI {...uiModel} />
1423
1414
  }
1424
1415
 
@@ -1426,10 +1417,10 @@ export type { ${ClassName}WidgetProps }
1426
1417
  `.trim());
1427
1418
  folder.subitem([
1428
1419
  'hooks'
1429
- ]).createFile('use-ui-model.ts', `
1420
+ ]).createFile(`${uiModelFileName}.ts`, `
1430
1421
  import type { ${ClassName}WidgetProps, ${ClassName}WidgetUIProps } from '../types'
1431
1422
 
1432
- export const useUIModel = (widgetProps: Omit<${ClassName}WidgetProps, 'UI'>): ${ClassName}WidgetUIProps => {
1423
+ export const use${ClassName}UIModel = (widgetProps: Omit<${ClassName}WidgetProps, 'UI'>): ${ClassName}WidgetUIProps => {
1433
1424
  return {}
1434
1425
  }
1435
1426
  `.trim());
@@ -1480,7 +1471,8 @@ const main = async ()=>{
1480
1471
  choices: [
1481
1472
  'New widget',
1482
1473
  'New page',
1483
- 'New UI-kit component'
1474
+ 'New UI-kit component',
1475
+ 'New shared hook'
1484
1476
  ]
1485
1477
  });
1486
1478
  switch(action){
@@ -1490,6 +1482,8 @@ const main = async ()=>{
1490
1482
  return void await scaffoldReactPage(reactFolder);
1491
1483
  case 'New UI-kit component':
1492
1484
  return void await scaffoldReactUIKitComponent(reactFolder);
1485
+ case 'New shared hook':
1486
+ return void await scaffoldReactSharedHook(reactFolder);
1493
1487
  default:
1494
1488
  return;
1495
1489
  }
package/dist/index.js CHANGED
@@ -224,10 +224,7 @@ const scaffoldNewAggregateUseCase = async (boundedContextFolder)=>{
224
224
  message: 'Aggregate name:'
225
225
  });
226
226
  const aggregateNaming = new UnknownFormatNaming(aggregateName);
227
- let scaffoldUnitTests;
228
- if (ConfigFile.Instance.data.testingLibrary) scaffoldUnitTests = await prompts_confirm({
229
- message: 'Scaffold unit-tests'
230
- });
227
+ const scaffoldUnitTests = Boolean(ConfigFile.Instance.data.testingLibrary);
231
228
  const withRepository = await prompts_confirm({
232
229
  message: 'With Repository'
233
230
  });
@@ -345,10 +342,7 @@ const scaffoldNewApplicationPort = async (boundedContextFolder)=>{
345
342
  message: 'Name: '
346
343
  });
347
344
  const naming = new UnknownFormatNaming(name);
348
- let scaffoldUnitTests;
349
- if (ConfigFile.Instance.data.testingLibrary) scaffoldUnitTests = await prompts_confirm({
350
- message: 'Scaffold unit-tests'
351
- });
345
+ const scaffoldUnitTests = Boolean(ConfigFile.Instance.data.testingLibrary);
352
346
  const wiringFolder = boundedContextFolder.subitem([
353
347
  'wiring',
354
348
  'application-ports'
@@ -442,10 +436,7 @@ const scaffoldNewApplicationService = async (boundedContextFolder)=>{
442
436
  message: 'Name: '
443
437
  });
444
438
  const naming = new UnknownFormatNaming(name);
445
- let scaffoldUnitTests;
446
- if (ConfigFile.Instance.data.testingLibrary) scaffoldUnitTests = await prompts_confirm({
447
- message: 'Scaffold unit-tests'
448
- });
439
+ const scaffoldUnitTests = Boolean(ConfigFile.Instance.data.testingLibrary);
449
440
  const withWiring = ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
450
441
  const wiringFolder = boundedContextFolder.subitem([
451
442
  'wiring',
@@ -521,10 +512,7 @@ const scaffoldNewCommand = async (boundedContextFolder)=>{
521
512
  const commandName = await input({
522
513
  message: 'Name: '
523
514
  });
524
- let scaffoldUnitTests;
525
- if (ConfigFile.Instance.data.testingLibrary) scaffoldUnitTests = await prompts_confirm({
526
- message: 'Scaffold unit-tests'
527
- });
515
+ const scaffoldUnitTests = Boolean(ConfigFile.Instance.data.testingLibrary);
528
516
  const naming = new UnknownFormatNaming(commandName);
529
517
  const commandType = await prompts_select({
530
518
  choices: [
@@ -706,10 +694,7 @@ const scaffoldNewDomainService = async (boundedContextFolder)=>{
706
694
  message: 'Name:'
707
695
  });
708
696
  const naming = new UnknownFormatNaming(portName);
709
- let scaffoldUnitTests;
710
- if (ConfigFile.Instance.data.testingLibrary) scaffoldUnitTests = await prompts_confirm({
711
- message: 'Scaffold unit-tests'
712
- });
697
+ const scaffoldUnitTests = Boolean(ConfigFile.Instance.data.testingLibrary);
713
698
  const withWiring = ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
714
699
  const domainServicesFolder = boundedContextFolder.subitem([
715
700
  'domain',
@@ -895,10 +880,7 @@ const scaffoldNewInfrastructureService = async (boundedContextFolder)=>{
895
880
  message: 'Name: '
896
881
  });
897
882
  const naming = new UnknownFormatNaming(name);
898
- let scaffoldUnitTests;
899
- if (ConfigFile.Instance.data.testingLibrary) scaffoldUnitTests = await prompts_confirm({
900
- message: 'Scaffold unit-tests'
901
- });
883
+ const scaffoldUnitTests = Boolean(ConfigFile.Instance.data.testingLibrary);
902
884
  const withWiring = ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
903
885
  const wiringFolder = boundedContextFolder.subitem([
904
886
  'wiring',
@@ -945,10 +927,7 @@ const scaffoldNewPresentationService = async (boundedContextFolder)=>{
945
927
  message: 'Name: '
946
928
  });
947
929
  const naming = new UnknownFormatNaming(name);
948
- let scaffoldUnitTests;
949
- if (ConfigFile.Instance.data.testingLibrary) scaffoldUnitTests = await prompts_confirm({
950
- message: 'Scaffold unit-tests'
951
- });
930
+ const scaffoldUnitTests = Boolean(ConfigFile.Instance.data.testingLibrary);
952
931
  const withWiring = ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
953
932
  const wiringFolder = boundedContextFolder.subitem([
954
933
  'wiring',
@@ -1003,10 +982,7 @@ const scaffoldNewQuery = async (boundedContextFolder)=>{
1003
982
  message: 'Name: '
1004
983
  });
1005
984
  const naming = new UnknownFormatNaming(queryName);
1006
- let scaffoldUnitTests;
1007
- if (ConfigFile.Instance.data.testingLibrary) scaffoldUnitTests = await prompts_confirm({
1008
- message: 'Scaffold unit-tests'
1009
- });
985
+ const scaffoldUnitTests = Boolean(ConfigFile.Instance.data.testingLibrary);
1010
986
  const queryType = await prompts_select({
1011
987
  choices: [
1012
988
  'Execution (with infrastructure implementation)',
@@ -1191,10 +1167,7 @@ const scaffoldNewUseCase = async (boundedContextFolder)=>{
1191
1167
  message: 'Name: '
1192
1168
  });
1193
1169
  const naming = new UnknownFormatNaming(useCaseName);
1194
- let scaffoldUnitTests;
1195
- if (ConfigFile.Instance.data.testingLibrary) scaffoldUnitTests = await prompts_confirm({
1196
- message: 'Scaffold unit-tests'
1197
- });
1170
+ const scaffoldUnitTests = Boolean(ConfigFile.Instance.data.testingLibrary);
1198
1171
  const withWiring = ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
1199
1172
  useCasesFolder.createFile(`${naming.fileName}-use-case.ts`, ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers') ? `
1200
1173
  import { defineHandler } from '@domain-first/handlers'
@@ -1266,6 +1239,19 @@ export const ${ClassName}Page: FC<${ClassName}PageProps> = (props) => {
1266
1239
  }
1267
1240
  `.trim());
1268
1241
  };
1242
+ const scaffoldReactSharedHook = async (presentationReactFolder)=>{
1243
+ const name = await input({
1244
+ message: 'Name without "use" (e.g. debounce): '
1245
+ });
1246
+ const { ClassName, fileName } = new UnknownFormatNaming(name.trim().replace(/^use-/, ''));
1247
+ presentationReactFolder.subitem([
1248
+ 'hooks'
1249
+ ]).createFile(`use-${fileName}.ts`, `
1250
+ export const use${ClassName} = () => {
1251
+ return {}
1252
+ }
1253
+ `.trim());
1254
+ };
1269
1255
  const scaffoldReactUIKitComponent = async (presentationReactFolder)=>{
1270
1256
  const name = await input({
1271
1257
  message: 'Name: '
@@ -1275,7 +1261,8 @@ const scaffoldReactUIKitComponent = async (presentationReactFolder)=>{
1275
1261
  'ui-kit',
1276
1262
  fileName
1277
1263
  ]);
1278
- componentFolder.createFile('index.tsx', `
1264
+ componentFolder.createFile('index.ts', `export * from './${fileName}'`);
1265
+ componentFolder.createFile(`${fileName}.tsx`, `
1279
1266
  import { type FC } from 'react'
1280
1267
 
1281
1268
  export type ${ClassName}Props = {}
@@ -1287,7 +1274,7 @@ export const ${ClassName}: FC<${ClassName}Props> = (props) => {
1287
1274
  const { storybookFramework } = ConfigFile.Instance.data;
1288
1275
  if (storybookFramework) componentFolder.createFile(`${fileName}.stories.tsx`, `
1289
1276
  import type { Meta, StoryObj } from '${storybookFramework}'
1290
- import { ${ClassName} } from '.'
1277
+ import { ${ClassName} } from './${fileName}'
1291
1278
 
1292
1279
  const meta = {
1293
1280
  title: 'UI-kit/${ClassName}',
@@ -1320,9 +1307,13 @@ const scaffoldReactWidget = async (presentationReactFolder)=>{
1320
1307
  'widgets',
1321
1308
  fileName
1322
1309
  ]);
1310
+ const widgetFileName = `${fileName}-widget`;
1311
+ const uiFileName = `${fileName}-widget-ui`;
1312
+ const uiModelFileName = `use-${fileName}-ui-model`;
1313
+ folder.createFile('index.ts', `export * from './${widgetFileName}'`);
1323
1314
  switch(widgetType){
1324
1315
  case 'monolithic':
1325
- folder.createFile('index.tsx', `
1316
+ folder.createFile(`${widgetFileName}.tsx`, `
1326
1317
  import { type FC } from 'react'
1327
1318
 
1328
1319
  export type ${ClassName}WidgetProps = {}
@@ -1338,14 +1329,14 @@ export type ${ClassName}WidgetProps = { }
1338
1329
 
1339
1330
  export type ${ClassName}WidgetUIProps = { }
1340
1331
  `.trim());
1341
- folder.createFile('index.tsx', `
1332
+ folder.createFile(`${widgetFileName}.tsx`, `
1342
1333
  import { type FC } from 'react'
1343
1334
  import type { ${ClassName}WidgetProps } from './types'
1344
- import { ${ClassName}WidgetUI } from './ui'
1345
- import { useUIModel } from './hooks/use-ui-model'
1335
+ import { ${ClassName}WidgetUI } from './ui/${uiFileName}'
1336
+ import { use${ClassName}UIModel } from './hooks/${uiModelFileName}'
1346
1337
 
1347
1338
  export const ${ClassName}Widget: FC<${ClassName}WidgetProps> = (props) => {
1348
- const uiModel = useUIModel(props)
1339
+ const uiModel = use${ClassName}UIModel(props)
1349
1340
  return <${ClassName}WidgetUI {...uiModel} />
1350
1341
  }
1351
1342
 
@@ -1353,7 +1344,7 @@ export type { ${ClassName}WidgetProps }
1353
1344
  `.trim());
1354
1345
  folder.subitem([
1355
1346
  'ui'
1356
- ]).createFile('index.tsx', `
1347
+ ]).createFile(`${uiFileName}.tsx`, `
1357
1348
  import { FC } from 'react'
1358
1349
  import type { ${ClassName}WidgetUIProps } from '../types'
1359
1350
 
@@ -1363,10 +1354,10 @@ export const ${ClassName}WidgetUI: FC<${ClassName}WidgetUIProps> = (props) => {
1363
1354
  `.trim());
1364
1355
  folder.subitem([
1365
1356
  'hooks'
1366
- ]).createFile('use-ui-model.ts', `
1357
+ ]).createFile(`${uiModelFileName}.ts`, `
1367
1358
  import type { ${ClassName}WidgetProps, ${ClassName}WidgetUIProps } from '../types'
1368
1359
 
1369
- export const useUIModel = (widgetProps: ${ClassName}WidgetProps): ${ClassName}WidgetUIProps => {
1360
+ export const use${ClassName}UIModel = (widgetProps: ${ClassName}WidgetProps): ${ClassName}WidgetUIProps => {
1370
1361
  return {}
1371
1362
  }
1372
1363
  `.trim());
@@ -1382,13 +1373,13 @@ export type ${ClassName}WidgetProps = {
1382
1373
  }
1383
1374
 
1384
1375
  `.trim());
1385
- folder.createFile('index.tsx', `
1376
+ folder.createFile(`${widgetFileName}.tsx`, `
1386
1377
  import { type FC } from 'react'
1387
1378
  import type { ${ClassName}WidgetProps } from './types'
1388
- import { useUIModel } from './hooks/use-ui-model'
1379
+ import { use${ClassName}UIModel } from './hooks/${uiModelFileName}'
1389
1380
 
1390
1381
  export const ${ClassName}Widget: FC<${ClassName}WidgetProps> = (props) => {
1391
- const uiModel = useUIModel(props)
1382
+ const uiModel = use${ClassName}UIModel(props)
1392
1383
  return <props.UI {...uiModel} />
1393
1384
  }
1394
1385
 
@@ -1396,10 +1387,10 @@ export type { ${ClassName}WidgetProps }
1396
1387
  `.trim());
1397
1388
  folder.subitem([
1398
1389
  'hooks'
1399
- ]).createFile('use-ui-model.ts', `
1390
+ ]).createFile(`${uiModelFileName}.ts`, `
1400
1391
  import type { ${ClassName}WidgetProps, ${ClassName}WidgetUIProps } from '../types'
1401
1392
 
1402
- export const useUIModel = (widgetProps: Omit<${ClassName}WidgetProps, 'UI'>): ${ClassName}WidgetUIProps => {
1393
+ export const use${ClassName}UIModel = (widgetProps: Omit<${ClassName}WidgetProps, 'UI'>): ${ClassName}WidgetUIProps => {
1403
1394
  return {}
1404
1395
  }
1405
1396
  `.trim());
@@ -1450,7 +1441,8 @@ const main = async ()=>{
1450
1441
  choices: [
1451
1442
  'New widget',
1452
1443
  'New page',
1453
- 'New UI-kit component'
1444
+ 'New UI-kit component',
1445
+ 'New shared hook'
1454
1446
  ]
1455
1447
  });
1456
1448
  switch(action){
@@ -1460,6 +1452,8 @@ const main = async ()=>{
1460
1452
  return void await scaffoldReactPage(reactFolder);
1461
1453
  case 'New UI-kit component':
1462
1454
  return void await scaffoldReactUIKitComponent(reactFolder);
1455
+ case 'New shared hook':
1456
+ return void await scaffoldReactSharedHook(reactFolder);
1463
1457
  default:
1464
1458
  return;
1465
1459
  }
@@ -12,5 +12,6 @@ export * from './scaffold-new-presentation-service';
12
12
  export * from './scaffold-new-query';
13
13
  export * from './scaffold-new-use-case';
14
14
  export * from './scaffold-react-page';
15
+ export * from './scaffold-react-shared-hook';
15
16
  export * from './scaffold-react-ui-kit-component';
16
17
  export * from './scaffold-react-widget';
@@ -0,0 +1,2 @@
1
+ import type { Folder } from '../file-system';
2
+ export declare const scaffoldReactSharedHook: (presentationReactFolder: Folder) => Promise<void>;
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.8.0",
4
+ "version": "2.9.0",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",