@domain-first/project-structure 2.10.3 → 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 +2 -0
- package/dist/index.cjs +40 -8
- package/dist/index.js +40 -8
- package/dist/nested-name.d.ts +19 -0
- package/dist/nested-name.spec.d.ts +1 -0
- package/package.json +1 -1
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
|
@@ -700,6 +700,8 @@ export const wire${naming.ClassName}Command = envBranchedWire({
|
|
|
700
700
|
import { defineHandler } from '@domain-first/handlers'
|
|
701
701
|
|
|
702
702
|
export class ${naming.ClassName}Command {
|
|
703
|
+
constructor() {}
|
|
704
|
+
|
|
703
705
|
static inputSchema = {}
|
|
704
706
|
static outputSchema = {}
|
|
705
707
|
|
|
@@ -716,7 +718,7 @@ export class ${naming.ClassName}Command {
|
|
|
716
718
|
'orchestration'
|
|
717
719
|
]).createFile(`${naming.fileName}-command.ts`, `
|
|
718
720
|
export class ${naming.ClassName}Command {
|
|
719
|
-
|
|
721
|
+
constructor() {}
|
|
720
722
|
}`.trim());
|
|
721
723
|
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) boundedContextFolder.subitem([
|
|
722
724
|
'wiring',
|
|
@@ -1223,6 +1225,8 @@ export const wire${naming.ClassName}Query = envBranchedWire({
|
|
|
1223
1225
|
import { defineHandler } from '@domain-first/handlers'
|
|
1224
1226
|
|
|
1225
1227
|
export class ${naming.ClassName}Query {
|
|
1228
|
+
constructor() {}
|
|
1229
|
+
|
|
1226
1230
|
static inputSchema = {}
|
|
1227
1231
|
static outputSchema = {}
|
|
1228
1232
|
|
|
@@ -1239,7 +1243,7 @@ export class ${naming.ClassName}Query {
|
|
|
1239
1243
|
'orchestration'
|
|
1240
1244
|
]).createFile(`${naming.fileName}-query.ts`, `
|
|
1241
1245
|
export class ${naming.ClassName}Query {
|
|
1242
|
-
|
|
1246
|
+
constructor() {}
|
|
1243
1247
|
}`.trim());
|
|
1244
1248
|
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) boundedContextFolder.subitem([
|
|
1245
1249
|
'wiring',
|
|
@@ -1334,13 +1338,35 @@ export const wire${naming.ClassName}UseCase = wireClass(
|
|
|
1334
1338
|
|
|
1335
1339
|
`.trim());
|
|
1336
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
|
+
}
|
|
1337
1361
|
const scaffoldReactPage = async (presentationReactFolder)=>{
|
|
1338
1362
|
const name = await (0, prompts_namespaceObject.input)({
|
|
1339
|
-
message: 'Provide name:'
|
|
1363
|
+
message: 'Provide name (folders split by "/"):',
|
|
1364
|
+
validate: NestedName.validate
|
|
1340
1365
|
});
|
|
1341
|
-
const { ClassName, fileName } = new
|
|
1366
|
+
const { folders, ClassName, fileName } = new NestedName(name);
|
|
1342
1367
|
presentationReactFolder.subitem([
|
|
1343
|
-
'pages'
|
|
1368
|
+
'pages',
|
|
1369
|
+
...folders
|
|
1344
1370
|
]).createFile(`${fileName}-page.tsx`, `
|
|
1345
1371
|
import { type FC } from 'react'
|
|
1346
1372
|
|
|
@@ -1404,7 +1430,8 @@ export const Default: Story = {
|
|
|
1404
1430
|
};
|
|
1405
1431
|
const scaffoldReactWidget = async (presentationReactFolder)=>{
|
|
1406
1432
|
const widgetName = await (0, prompts_namespaceObject.input)({
|
|
1407
|
-
message: 'Name: '
|
|
1433
|
+
message: 'Name (folders split by "/"): ',
|
|
1434
|
+
validate: NestedName.validate
|
|
1408
1435
|
});
|
|
1409
1436
|
const widgetType = await (0, prompts_namespaceObject.select)({
|
|
1410
1437
|
choices: [
|
|
@@ -1414,11 +1441,16 @@ const scaffoldReactWidget = async (presentationReactFolder)=>{
|
|
|
1414
1441
|
],
|
|
1415
1442
|
message: 'Type: '
|
|
1416
1443
|
});
|
|
1417
|
-
const { ClassName, fileName } = new
|
|
1444
|
+
const { folders, ClassName, fileName, classNameSegments } = new NestedName(widgetName);
|
|
1418
1445
|
const folder = presentationReactFolder.subitem([
|
|
1419
1446
|
'widgets',
|
|
1447
|
+
...folders,
|
|
1420
1448
|
fileName
|
|
1421
1449
|
]);
|
|
1450
|
+
const storyTitle = [
|
|
1451
|
+
'Widgets',
|
|
1452
|
+
...classNameSegments
|
|
1453
|
+
].join('/');
|
|
1422
1454
|
const widgetFileName = `${fileName}-widget`;
|
|
1423
1455
|
const uiFileName = `${fileName}-widget-ui`;
|
|
1424
1456
|
const uiModelFileName = `use-${fileName}-ui-model`;
|
|
@@ -1473,7 +1505,7 @@ import type { Meta, StoryObj } from '${storybookFramework}'
|
|
|
1473
1505
|
import { ${ClassName}WidgetUI } from './${uiFileName}'
|
|
1474
1506
|
|
|
1475
1507
|
const meta = {
|
|
1476
|
-
title: '
|
|
1508
|
+
title: '${storyTitle}',
|
|
1477
1509
|
component: ${ClassName}WidgetUI
|
|
1478
1510
|
} satisfies Meta<typeof ${ClassName}WidgetUI>
|
|
1479
1511
|
|
package/dist/index.js
CHANGED
|
@@ -670,6 +670,8 @@ export const wire${naming.ClassName}Command = envBranchedWire({
|
|
|
670
670
|
import { defineHandler } from '@domain-first/handlers'
|
|
671
671
|
|
|
672
672
|
export class ${naming.ClassName}Command {
|
|
673
|
+
constructor() {}
|
|
674
|
+
|
|
673
675
|
static inputSchema = {}
|
|
674
676
|
static outputSchema = {}
|
|
675
677
|
|
|
@@ -686,7 +688,7 @@ export class ${naming.ClassName}Command {
|
|
|
686
688
|
'orchestration'
|
|
687
689
|
]).createFile(`${naming.fileName}-command.ts`, `
|
|
688
690
|
export class ${naming.ClassName}Command {
|
|
689
|
-
|
|
691
|
+
constructor() {}
|
|
690
692
|
}`.trim());
|
|
691
693
|
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) boundedContextFolder.subitem([
|
|
692
694
|
'wiring',
|
|
@@ -1193,6 +1195,8 @@ export const wire${naming.ClassName}Query = envBranchedWire({
|
|
|
1193
1195
|
import { defineHandler } from '@domain-first/handlers'
|
|
1194
1196
|
|
|
1195
1197
|
export class ${naming.ClassName}Query {
|
|
1198
|
+
constructor() {}
|
|
1199
|
+
|
|
1196
1200
|
static inputSchema = {}
|
|
1197
1201
|
static outputSchema = {}
|
|
1198
1202
|
|
|
@@ -1209,7 +1213,7 @@ export class ${naming.ClassName}Query {
|
|
|
1209
1213
|
'orchestration'
|
|
1210
1214
|
]).createFile(`${naming.fileName}-query.ts`, `
|
|
1211
1215
|
export class ${naming.ClassName}Query {
|
|
1212
|
-
|
|
1216
|
+
constructor() {}
|
|
1213
1217
|
}`.trim());
|
|
1214
1218
|
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) boundedContextFolder.subitem([
|
|
1215
1219
|
'wiring',
|
|
@@ -1304,13 +1308,35 @@ export const wire${naming.ClassName}UseCase = wireClass(
|
|
|
1304
1308
|
|
|
1305
1309
|
`.trim());
|
|
1306
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
|
+
}
|
|
1307
1331
|
const scaffoldReactPage = async (presentationReactFolder)=>{
|
|
1308
1332
|
const name = await input({
|
|
1309
|
-
message: 'Provide name:'
|
|
1333
|
+
message: 'Provide name (folders split by "/"):',
|
|
1334
|
+
validate: NestedName.validate
|
|
1310
1335
|
});
|
|
1311
|
-
const { ClassName, fileName } = new
|
|
1336
|
+
const { folders, ClassName, fileName } = new NestedName(name);
|
|
1312
1337
|
presentationReactFolder.subitem([
|
|
1313
|
-
'pages'
|
|
1338
|
+
'pages',
|
|
1339
|
+
...folders
|
|
1314
1340
|
]).createFile(`${fileName}-page.tsx`, `
|
|
1315
1341
|
import { type FC } from 'react'
|
|
1316
1342
|
|
|
@@ -1374,7 +1400,8 @@ export const Default: Story = {
|
|
|
1374
1400
|
};
|
|
1375
1401
|
const scaffoldReactWidget = async (presentationReactFolder)=>{
|
|
1376
1402
|
const widgetName = await input({
|
|
1377
|
-
message: 'Name: '
|
|
1403
|
+
message: 'Name (folders split by "/"): ',
|
|
1404
|
+
validate: NestedName.validate
|
|
1378
1405
|
});
|
|
1379
1406
|
const widgetType = await prompts_select({
|
|
1380
1407
|
choices: [
|
|
@@ -1384,11 +1411,16 @@ const scaffoldReactWidget = async (presentationReactFolder)=>{
|
|
|
1384
1411
|
],
|
|
1385
1412
|
message: 'Type: '
|
|
1386
1413
|
});
|
|
1387
|
-
const { ClassName, fileName } = new
|
|
1414
|
+
const { folders, ClassName, fileName, classNameSegments } = new NestedName(widgetName);
|
|
1388
1415
|
const folder = presentationReactFolder.subitem([
|
|
1389
1416
|
'widgets',
|
|
1417
|
+
...folders,
|
|
1390
1418
|
fileName
|
|
1391
1419
|
]);
|
|
1420
|
+
const storyTitle = [
|
|
1421
|
+
'Widgets',
|
|
1422
|
+
...classNameSegments
|
|
1423
|
+
].join('/');
|
|
1392
1424
|
const widgetFileName = `${fileName}-widget`;
|
|
1393
1425
|
const uiFileName = `${fileName}-widget-ui`;
|
|
1394
1426
|
const uiModelFileName = `use-${fileName}-ui-model`;
|
|
@@ -1443,7 +1475,7 @@ import type { Meta, StoryObj } from '${storybookFramework}'
|
|
|
1443
1475
|
import { ${ClassName}WidgetUI } from './${uiFileName}'
|
|
1444
1476
|
|
|
1445
1477
|
const meta = {
|
|
1446
|
-
title: '
|
|
1478
|
+
title: '${storyTitle}',
|
|
1447
1479
|
component: ${ClassName}WidgetUI
|
|
1448
1480
|
} satisfies Meta<typeof ${ClassName}WidgetUI>
|
|
1449
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 {};
|