@domain-first/project-structure 2.10.4 → 2.11.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
@@ -190,6 +190,8 @@ Enable `useReact` and choose **Scaffold React module** from the main menu. Modul
190
190
  | 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`. |
191
191
  | 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. |
192
192
 
193
+ Page and widget names can include folders split by `/`. For example, a page named `admin/panel/users` is created at `pages/admin/panel/users-page.tsx` as `AdminPanelUsersPage`, and a widget with the same name at `widgets/admin/panel/users/` as `AdminPanelUsersWidget` with the story title `Widgets/Admin/Panel/Users`. File names use only the last segment; code names use the whole path.
194
+
193
195
  ## Configuration
194
196
 
195
197
  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
@@ -1338,13 +1338,35 @@ export const wire${naming.ClassName}UseCase = wireClass(
1338
1338
 
1339
1339
  `.trim());
1340
1340
  };
1341
+ const splitSegments = (rawSource)=>rawSource.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment);
1342
+ class NestedName {
1343
+ folders;
1344
+ fileName;
1345
+ ClassName;
1346
+ classNameSegments;
1347
+ constructor(rawSource){
1348
+ const segments = splitSegments(rawSource);
1349
+ this.folders = segments.slice(0, -1);
1350
+ this.fileName = new UnknownFormatNaming(segments.at(-1) ?? '').fileName;
1351
+ this.classNameSegments = segments.map((segment)=>new UnknownFormatNaming(segment).ClassName);
1352
+ this.ClassName = this.classNameSegments.join('');
1353
+ }
1354
+ static validate = (rawSource)=>{
1355
+ const segments = splitSegments(rawSource);
1356
+ if (!segments.length) return 'Name is required';
1357
+ if (segments.some((segment)=>'.' === segment || '..' === segment)) return 'Use a path relative to the folder, without "." or ".."';
1358
+ return true;
1359
+ };
1360
+ }
1341
1361
  const scaffoldReactPage = async (presentationReactFolder)=>{
1342
1362
  const name = await (0, prompts_namespaceObject.input)({
1343
- message: 'Provide name:'
1363
+ message: 'Provide name (folders split by "/"):',
1364
+ validate: NestedName.validate
1344
1365
  });
1345
- const { ClassName, fileName } = new UnknownFormatNaming(name);
1366
+ const { folders, ClassName, fileName } = new NestedName(name);
1346
1367
  presentationReactFolder.subitem([
1347
- 'pages'
1368
+ 'pages',
1369
+ ...folders
1348
1370
  ]).createFile(`${fileName}-page.tsx`, `
1349
1371
  import { type FC } from 'react'
1350
1372
 
@@ -1408,7 +1430,8 @@ export const Default: Story = {
1408
1430
  };
1409
1431
  const scaffoldReactWidget = async (presentationReactFolder)=>{
1410
1432
  const widgetName = await (0, prompts_namespaceObject.input)({
1411
- message: 'Name: '
1433
+ message: 'Name (folders split by "/"): ',
1434
+ validate: NestedName.validate
1412
1435
  });
1413
1436
  const widgetType = await (0, prompts_namespaceObject.select)({
1414
1437
  choices: [
@@ -1418,11 +1441,16 @@ const scaffoldReactWidget = async (presentationReactFolder)=>{
1418
1441
  ],
1419
1442
  message: 'Type: '
1420
1443
  });
1421
- const { ClassName, fileName } = new UnknownFormatNaming(widgetName);
1444
+ const { folders, ClassName, fileName, classNameSegments } = new NestedName(widgetName);
1422
1445
  const folder = presentationReactFolder.subitem([
1423
1446
  'widgets',
1447
+ ...folders,
1424
1448
  fileName
1425
1449
  ]);
1450
+ const storyTitle = [
1451
+ 'Widgets',
1452
+ ...classNameSegments
1453
+ ].join('/');
1426
1454
  const widgetFileName = `${fileName}-widget`;
1427
1455
  const uiFileName = `${fileName}-widget-ui`;
1428
1456
  const uiModelFileName = `use-${fileName}-ui-model`;
@@ -1477,7 +1505,7 @@ import type { Meta, StoryObj } from '${storybookFramework}'
1477
1505
  import { ${ClassName}WidgetUI } from './${uiFileName}'
1478
1506
 
1479
1507
  const meta = {
1480
- title: 'Widgets/${ClassName}',
1508
+ title: '${storyTitle}',
1481
1509
  component: ${ClassName}WidgetUI
1482
1510
  } satisfies Meta<typeof ${ClassName}WidgetUI>
1483
1511
 
package/dist/index.js CHANGED
@@ -1308,13 +1308,35 @@ export const wire${naming.ClassName}UseCase = wireClass(
1308
1308
 
1309
1309
  `.trim());
1310
1310
  };
1311
+ const splitSegments = (rawSource)=>rawSource.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment);
1312
+ class NestedName {
1313
+ folders;
1314
+ fileName;
1315
+ ClassName;
1316
+ classNameSegments;
1317
+ constructor(rawSource){
1318
+ const segments = splitSegments(rawSource);
1319
+ this.folders = segments.slice(0, -1);
1320
+ this.fileName = new UnknownFormatNaming(segments.at(-1) ?? '').fileName;
1321
+ this.classNameSegments = segments.map((segment)=>new UnknownFormatNaming(segment).ClassName);
1322
+ this.ClassName = this.classNameSegments.join('');
1323
+ }
1324
+ static validate = (rawSource)=>{
1325
+ const segments = splitSegments(rawSource);
1326
+ if (!segments.length) return 'Name is required';
1327
+ if (segments.some((segment)=>'.' === segment || '..' === segment)) return 'Use a path relative to the folder, without "." or ".."';
1328
+ return true;
1329
+ };
1330
+ }
1311
1331
  const scaffoldReactPage = async (presentationReactFolder)=>{
1312
1332
  const name = await input({
1313
- message: 'Provide name:'
1333
+ message: 'Provide name (folders split by "/"):',
1334
+ validate: NestedName.validate
1314
1335
  });
1315
- const { ClassName, fileName } = new UnknownFormatNaming(name);
1336
+ const { folders, ClassName, fileName } = new NestedName(name);
1316
1337
  presentationReactFolder.subitem([
1317
- 'pages'
1338
+ 'pages',
1339
+ ...folders
1318
1340
  ]).createFile(`${fileName}-page.tsx`, `
1319
1341
  import { type FC } from 'react'
1320
1342
 
@@ -1378,7 +1400,8 @@ export const Default: Story = {
1378
1400
  };
1379
1401
  const scaffoldReactWidget = async (presentationReactFolder)=>{
1380
1402
  const widgetName = await input({
1381
- message: 'Name: '
1403
+ message: 'Name (folders split by "/"): ',
1404
+ validate: NestedName.validate
1382
1405
  });
1383
1406
  const widgetType = await prompts_select({
1384
1407
  choices: [
@@ -1388,11 +1411,16 @@ const scaffoldReactWidget = async (presentationReactFolder)=>{
1388
1411
  ],
1389
1412
  message: 'Type: '
1390
1413
  });
1391
- const { ClassName, fileName } = new UnknownFormatNaming(widgetName);
1414
+ const { folders, ClassName, fileName, classNameSegments } = new NestedName(widgetName);
1392
1415
  const folder = presentationReactFolder.subitem([
1393
1416
  'widgets',
1417
+ ...folders,
1394
1418
  fileName
1395
1419
  ]);
1420
+ const storyTitle = [
1421
+ 'Widgets',
1422
+ ...classNameSegments
1423
+ ].join('/');
1396
1424
  const widgetFileName = `${fileName}-widget`;
1397
1425
  const uiFileName = `${fileName}-widget-ui`;
1398
1426
  const uiModelFileName = `use-${fileName}-ui-model`;
@@ -1447,7 +1475,7 @@ import type { Meta, StoryObj } from '${storybookFramework}'
1447
1475
  import { ${ClassName}WidgetUI } from './${uiFileName}'
1448
1476
 
1449
1477
  const meta = {
1450
- title: 'Widgets/${ClassName}',
1478
+ title: '${storyTitle}',
1451
1479
  component: ${ClassName}WidgetUI
1452
1480
  } satisfies Meta<typeof ${ClassName}WidgetUI>
1453
1481
 
@@ -0,0 +1,19 @@
1
+ /**
2
+ * A name with optional folders before it, e.g. `admin/panel/users`.
3
+ * The last segment names the files; the whole path names the code
4
+ * (`AdminPanelUsers`), so equal names in different folders don't clash.
5
+ */
6
+ export declare class NestedName {
7
+ readonly folders: string[];
8
+ readonly fileName: string;
9
+ readonly ClassName: string;
10
+ /**
11
+ * Each segment as a class name, e.g. `['Admin', 'Panel', 'Users']`.
12
+ */
13
+ readonly classNameSegments: string[];
14
+ constructor(rawSource: string);
15
+ /**
16
+ * `.` and `..` would place files outside the target folder.
17
+ */
18
+ static validate: (rawSource: string) => true | "Name is required" | "Use a path relative to the folder, without \".\" or \"..\"";
19
+ }
@@ -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.10.4",
4
+ "version": "2.11.0",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",