@domain-first/project-structure 8.9.1 → 8.9.2
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/dist/287.js +26 -14
- package/dist/index.cjs +43 -31
- package/dist/integration.cjs +43 -31
- package/dist/integrations/openapi.d.ts +4 -2
- package/dist/react.cjs +43 -31
- package/dist/use-cases/scaffold-react-page.d.ts +7 -0
- package/package.json +1 -1
package/dist/287.js
CHANGED
|
@@ -385,11 +385,6 @@ const addInMemoryDb = ()=>{
|
|
|
385
385
|
return [];
|
|
386
386
|
};
|
|
387
387
|
const inMemoryDbApplied = ()=>Boolean(ConfigFile.Instance.data.backend?.withInMemoryDb) && inMemoryDbScaffolded();
|
|
388
|
-
const usesNext = ()=>ConfigFile.exists && ConfigFile.Instance.data.frontend?.react?.framework === 'next';
|
|
389
|
-
const nextAppFolder = (root)=>[
|
|
390
|
-
'app',
|
|
391
|
-
'src/app'
|
|
392
|
-
].find((folder)=>new Folder(node_path.join(root, folder)).exists) ?? 'app';
|
|
393
388
|
const splitSegments = (rawSource)=>rawSource.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment);
|
|
394
389
|
class NestedName {
|
|
395
390
|
folders;
|
|
@@ -412,6 +407,11 @@ class NestedName {
|
|
|
412
407
|
return true;
|
|
413
408
|
};
|
|
414
409
|
}
|
|
410
|
+
const usesNext = ()=>ConfigFile.exists && ConfigFile.Instance.data.frontend?.react?.framework === 'next';
|
|
411
|
+
const nextAppFolder = (root)=>[
|
|
412
|
+
'app',
|
|
413
|
+
'src/app'
|
|
414
|
+
].find((folder)=>new Folder(node_path.join(root, folder)).exists) ?? 'app';
|
|
415
415
|
const reactPageContent = (ClassName, { imports = [], body = '<></>' } = {})=>`
|
|
416
416
|
${[
|
|
417
417
|
...imports,
|
|
@@ -431,13 +431,14 @@ export default function Page() {
|
|
|
431
431
|
return <${ClassName}Page />
|
|
432
432
|
}
|
|
433
433
|
`.trim();
|
|
434
|
-
const scaffoldNextRoute = (name,
|
|
434
|
+
const scaffoldNextRoute = (name, pagePath)=>{
|
|
435
435
|
const root = new ProjectRoot().path;
|
|
436
436
|
const route = node_path.join(root, nextAppFolder(root), ...name.folders, name.folderName, 'page.tsx');
|
|
437
437
|
const relativeRoute = node_path.relative(root, route).split(node_path.sep).join('/');
|
|
438
438
|
const routeFile = new File(route);
|
|
439
|
-
|
|
440
|
-
routeFile.data
|
|
439
|
+
const content = nextRouteContent(name.ClassName, relativeImport(route, pagePath.replace(/\.tsx$/, '')));
|
|
440
|
+
if (routeFile.exists) return routeFile.data === content ? void 0 : `${relativeRoute} already exists: render ${name.ClassName}Page there yourself.`;
|
|
441
|
+
routeFile.data = content;
|
|
441
442
|
};
|
|
442
443
|
const scaffoldReactPage = async (presentationReactFolder)=>{
|
|
443
444
|
const name = await interaction_input({
|
|
@@ -451,7 +452,10 @@ const scaffoldReactPage = async (presentationReactFolder)=>{
|
|
|
451
452
|
'pages',
|
|
452
453
|
...folders
|
|
453
454
|
]).createFile(`${fileName}-page.tsx`, reactPageContent(ClassName));
|
|
454
|
-
if (usesNext())
|
|
455
|
+
if (usesNext()) {
|
|
456
|
+
const hint = scaffoldNextRoute(nestedName, pageFile.path);
|
|
457
|
+
if (hint) report(hint);
|
|
458
|
+
}
|
|
455
459
|
};
|
|
456
460
|
const openapiScriptPath = "scripts/generate-openapi.ts";
|
|
457
461
|
const defaultOpenapiPath = (withNext)=>withNext ? 'public/openapi.json' : 'openapi.json';
|
|
@@ -460,9 +464,9 @@ const extractorPackages = [
|
|
|
460
464
|
'@microsoft/tsdoc'
|
|
461
465
|
];
|
|
462
466
|
const swaggerPagePath = (rootFolder)=>node_path.posix.join(rootFolder.replaceAll('\\', '/'), 'presentation/react/pages/swagger-page.tsx');
|
|
463
|
-
const swaggerPage = (rootFolder, outputPath)=>{
|
|
467
|
+
const swaggerPage = (rootFolder, outputPath, withNext = false)=>{
|
|
464
468
|
const specImport = node_path.posix.relative(node_path.posix.dirname(swaggerPagePath(rootFolder)), outputPath);
|
|
465
|
-
|
|
469
|
+
const page = reactPageContent('Swagger', {
|
|
466
470
|
imports: [
|
|
467
471
|
"import 'swagger-ui-react/swagger-ui.css'",
|
|
468
472
|
"import SwaggerUI from 'swagger-ui-react'",
|
|
@@ -470,6 +474,7 @@ const swaggerPage = (rootFolder, outputPath)=>{
|
|
|
470
474
|
],
|
|
471
475
|
body: '<SwaggerUI displayOperationId spec={spec} />'
|
|
472
476
|
});
|
|
477
|
+
return withNext ? `'use client'\n\n${page}` : page;
|
|
473
478
|
};
|
|
474
479
|
const openapiScripts = {
|
|
475
480
|
openapi: `tsx --env-file-if-exists=.env ${openapiScriptPath}`
|
|
@@ -551,10 +556,14 @@ const addOpenapi = async ()=>{
|
|
|
551
556
|
const generatorFile = new File(node_path.join(root, openapiScriptPath));
|
|
552
557
|
const content = openapiGenerator(rootFolder, apiTitle(manifest.name), routePrefix, splitPath(outputPath).join('/'), withExtractor);
|
|
553
558
|
if (!generatorFile.exists || generatorFile.data !== content) generatorFile.data = content;
|
|
559
|
+
const withNextRoute = withSwaggerPage && usesNext();
|
|
560
|
+
let nextRouteHint;
|
|
554
561
|
if (withSwaggerPage) {
|
|
555
|
-
const
|
|
556
|
-
const
|
|
562
|
+
const pagePath = node_path.join(root, swaggerPagePath(rootFolder));
|
|
563
|
+
const pageFile = new File(pagePath);
|
|
564
|
+
const page = swaggerPage(rootFolder, splitPath(outputPath).join('/'), withNextRoute);
|
|
557
565
|
if (!pageFile.exists || pageFile.data !== page) pageFile.data = page;
|
|
566
|
+
if (withNextRoute) nextRouteHint = scaffoldNextRoute(new NestedName('swagger'), pagePath);
|
|
558
567
|
}
|
|
559
568
|
const resolveJsonModule = withSwaggerPage ? compilerOption(node_path.join(root, 'tsconfig.json'), 'resolveJsonModule') : true;
|
|
560
569
|
const hasRestHandlers = new File(node_path.join(root, rootFolder, 'presentation', 'rest', 'index.ts')).exists;
|
|
@@ -581,9 +590,12 @@ const addOpenapi = async ()=>{
|
|
|
581
590
|
...describeScripts(selected, {
|
|
582
591
|
openapi: `generate the OpenAPI document from restHandlers in ${splitPath(outputPath).join('/')}`
|
|
583
592
|
}),
|
|
584
|
-
...withSwaggerPage ? [
|
|
593
|
+
...withSwaggerPage && !withNextRoute ? [
|
|
585
594
|
`SwaggerPage from ${swaggerPagePath(rootFolder)} shows ${splitPath(outputPath).join('/')} once it is generated — render it on a route of your app`
|
|
586
595
|
] : [],
|
|
596
|
+
...withNextRoute ? [
|
|
597
|
+
nextRouteHint ?? `/swagger shows ${splitPath(outputPath).join('/')} once it is generated — the route is ${nextAppFolder(root)}/swagger/page.tsx`
|
|
598
|
+
] : [],
|
|
587
599
|
...hasRestHandlers ? [] : [
|
|
588
600
|
`restHandlers appear in ${node_path.posix.join(rootFolder, 'presentation/rest/index.ts')} with the first REST endpoint generated with @domain-first/wire`
|
|
589
601
|
]
|
package/dist/index.cjs
CHANGED
|
@@ -1511,6 +1511,28 @@ const missing_domain_first_packages_missingPackages = (packages)=>{
|
|
|
1511
1511
|
`npm i ${missing.join(' ')}`
|
|
1512
1512
|
] : [];
|
|
1513
1513
|
};
|
|
1514
|
+
const splitSegments = (rawSource)=>rawSource.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment);
|
|
1515
|
+
class NestedName {
|
|
1516
|
+
folders;
|
|
1517
|
+
folderName;
|
|
1518
|
+
fileName;
|
|
1519
|
+
ClassName;
|
|
1520
|
+
classNameSegments;
|
|
1521
|
+
constructor(rawSource){
|
|
1522
|
+
const segments = splitSegments(rawSource);
|
|
1523
|
+
this.folders = segments.slice(0, -1);
|
|
1524
|
+
this.folderName = new UnknownFormatNaming(segments.at(-1) ?? '').fileName;
|
|
1525
|
+
this.fileName = segments.map((segment)=>new UnknownFormatNaming(segment).fileName).join('-');
|
|
1526
|
+
this.classNameSegments = segments.map((segment)=>new UnknownFormatNaming(segment).ClassName);
|
|
1527
|
+
this.ClassName = this.classNameSegments.join('');
|
|
1528
|
+
}
|
|
1529
|
+
static validate = (rawSource)=>{
|
|
1530
|
+
const segments = splitSegments(rawSource);
|
|
1531
|
+
if (!segments.length) return 'Name is required';
|
|
1532
|
+
if (segments.some((segment)=>'.' === segment || '..' === segment)) return 'Use a path relative to the folder, without "." or ".."';
|
|
1533
|
+
return true;
|
|
1534
|
+
};
|
|
1535
|
+
}
|
|
1514
1536
|
const usesNext = ()=>config_file_ConfigFile.exists && config_file_ConfigFile.Instance.data.frontend?.react?.framework === 'next';
|
|
1515
1537
|
const nextAppFolder = (root)=>[
|
|
1516
1538
|
'app',
|
|
@@ -1550,28 +1572,6 @@ const compilerOption = (configFile, name, seen = new Set())=>{
|
|
|
1550
1572
|
if (void 0 !== value) return value;
|
|
1551
1573
|
}
|
|
1552
1574
|
};
|
|
1553
|
-
const splitSegments = (rawSource)=>rawSource.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment);
|
|
1554
|
-
class NestedName {
|
|
1555
|
-
folders;
|
|
1556
|
-
folderName;
|
|
1557
|
-
fileName;
|
|
1558
|
-
ClassName;
|
|
1559
|
-
classNameSegments;
|
|
1560
|
-
constructor(rawSource){
|
|
1561
|
-
const segments = splitSegments(rawSource);
|
|
1562
|
-
this.folders = segments.slice(0, -1);
|
|
1563
|
-
this.folderName = new UnknownFormatNaming(segments.at(-1) ?? '').fileName;
|
|
1564
|
-
this.fileName = segments.map((segment)=>new UnknownFormatNaming(segment).fileName).join('-');
|
|
1565
|
-
this.classNameSegments = segments.map((segment)=>new UnknownFormatNaming(segment).ClassName);
|
|
1566
|
-
this.ClassName = this.classNameSegments.join('');
|
|
1567
|
-
}
|
|
1568
|
-
static validate = (rawSource)=>{
|
|
1569
|
-
const segments = splitSegments(rawSource);
|
|
1570
|
-
if (!segments.length) return 'Name is required';
|
|
1571
|
-
if (segments.some((segment)=>'.' === segment || '..' === segment)) return 'Use a path relative to the folder, without "." or ".."';
|
|
1572
|
-
return true;
|
|
1573
|
-
};
|
|
1574
|
-
}
|
|
1575
1575
|
const reactPageContent = (ClassName, { imports = [], body = '<></>' } = {})=>`
|
|
1576
1576
|
${[
|
|
1577
1577
|
...imports,
|
|
@@ -1591,13 +1591,14 @@ export default function Page() {
|
|
|
1591
1591
|
return <${ClassName}Page />
|
|
1592
1592
|
}
|
|
1593
1593
|
`.trim();
|
|
1594
|
-
const scaffoldNextRoute = (name,
|
|
1594
|
+
const scaffoldNextRoute = (name, pagePath)=>{
|
|
1595
1595
|
const root = new project_root_ProjectRoot().path;
|
|
1596
1596
|
const route = external_node_path_default().join(root, nextAppFolder(root), ...name.folders, name.folderName, 'page.tsx');
|
|
1597
1597
|
const relativeRoute = external_node_path_default().relative(root, route).split(external_node_path_default().sep).join('/');
|
|
1598
1598
|
const routeFile = new file_system_File(route);
|
|
1599
|
-
|
|
1600
|
-
routeFile.data
|
|
1599
|
+
const content = nextRouteContent(name.ClassName, relativeImport(route, pagePath.replace(/\.tsx$/, '')));
|
|
1600
|
+
if (routeFile.exists) return routeFile.data === content ? void 0 : `${relativeRoute} already exists: render ${name.ClassName}Page there yourself.`;
|
|
1601
|
+
routeFile.data = content;
|
|
1601
1602
|
};
|
|
1602
1603
|
const scaffoldReactPage = async (presentationReactFolder)=>{
|
|
1603
1604
|
const name = await interaction_input({
|
|
@@ -1611,7 +1612,10 @@ const scaffoldReactPage = async (presentationReactFolder)=>{
|
|
|
1611
1612
|
'pages',
|
|
1612
1613
|
...folders
|
|
1613
1614
|
]).createFile(`${fileName}-page.tsx`, reactPageContent(ClassName));
|
|
1614
|
-
if (usesNext())
|
|
1615
|
+
if (usesNext()) {
|
|
1616
|
+
const hint = scaffoldNextRoute(nestedName, pageFile.path);
|
|
1617
|
+
if (hint) report(hint);
|
|
1618
|
+
}
|
|
1615
1619
|
};
|
|
1616
1620
|
const openapiExtractorPath = "scripts/extract-open-api-data-from-endpoint.ts";
|
|
1617
1621
|
const rootFolderSegments = (rootFolder, indent = 20)=>rootFolder.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment && '.' !== segment).map((segment)=>`'${segment}',\n${' '.repeat(indent)}`).join('');
|
|
@@ -1784,9 +1788,9 @@ const extractorPackages = [
|
|
|
1784
1788
|
'@microsoft/tsdoc'
|
|
1785
1789
|
];
|
|
1786
1790
|
const swaggerPagePath = (rootFolder)=>external_node_path_default().posix.join(rootFolder.replaceAll('\\', '/'), 'presentation/react/pages/swagger-page.tsx');
|
|
1787
|
-
const swaggerPage = (rootFolder, outputPath)=>{
|
|
1791
|
+
const swaggerPage = (rootFolder, outputPath, withNext = false)=>{
|
|
1788
1792
|
const specImport = external_node_path_default().posix.relative(external_node_path_default().posix.dirname(swaggerPagePath(rootFolder)), outputPath);
|
|
1789
|
-
|
|
1793
|
+
const page = reactPageContent('Swagger', {
|
|
1790
1794
|
imports: [
|
|
1791
1795
|
"import 'swagger-ui-react/swagger-ui.css'",
|
|
1792
1796
|
"import SwaggerUI from 'swagger-ui-react'",
|
|
@@ -1794,6 +1798,7 @@ const swaggerPage = (rootFolder, outputPath)=>{
|
|
|
1794
1798
|
],
|
|
1795
1799
|
body: '<SwaggerUI displayOperationId spec={spec} />'
|
|
1796
1800
|
});
|
|
1801
|
+
return withNext ? `'use client'\n\n${page}` : page;
|
|
1797
1802
|
};
|
|
1798
1803
|
const openapiScripts = {
|
|
1799
1804
|
openapi: `tsx --env-file-if-exists=.env ${openapiScriptPath}`
|
|
@@ -1875,10 +1880,14 @@ const addOpenapi = async ()=>{
|
|
|
1875
1880
|
const generatorFile = new file_system_File(external_node_path_default().join(root, openapiScriptPath));
|
|
1876
1881
|
const content = openapiGenerator(rootFolder, apiTitle(manifest.name), routePrefix, splitPath(outputPath).join('/'), withExtractor);
|
|
1877
1882
|
if (!generatorFile.exists || generatorFile.data !== content) generatorFile.data = content;
|
|
1883
|
+
const withNextRoute = withSwaggerPage && usesNext();
|
|
1884
|
+
let nextRouteHint;
|
|
1878
1885
|
if (withSwaggerPage) {
|
|
1879
|
-
const
|
|
1880
|
-
const
|
|
1886
|
+
const pagePath = external_node_path_default().join(root, swaggerPagePath(rootFolder));
|
|
1887
|
+
const pageFile = new file_system_File(pagePath);
|
|
1888
|
+
const page = swaggerPage(rootFolder, splitPath(outputPath).join('/'), withNextRoute);
|
|
1881
1889
|
if (!pageFile.exists || pageFile.data !== page) pageFile.data = page;
|
|
1890
|
+
if (withNextRoute) nextRouteHint = scaffoldNextRoute(new NestedName('swagger'), pagePath);
|
|
1882
1891
|
}
|
|
1883
1892
|
const resolveJsonModule = withSwaggerPage ? compilerOption(external_node_path_default().join(root, 'tsconfig.json'), 'resolveJsonModule') : true;
|
|
1884
1893
|
const hasRestHandlers = new file_system_File(external_node_path_default().join(root, rootFolder, 'presentation', 'rest', 'index.ts')).exists;
|
|
@@ -1905,9 +1914,12 @@ const addOpenapi = async ()=>{
|
|
|
1905
1914
|
...describeScripts(selected, {
|
|
1906
1915
|
openapi: `generate the OpenAPI document from restHandlers in ${splitPath(outputPath).join('/')}`
|
|
1907
1916
|
}),
|
|
1908
|
-
...withSwaggerPage ? [
|
|
1917
|
+
...withSwaggerPage && !withNextRoute ? [
|
|
1909
1918
|
`SwaggerPage from ${swaggerPagePath(rootFolder)} shows ${splitPath(outputPath).join('/')} once it is generated — render it on a route of your app`
|
|
1910
1919
|
] : [],
|
|
1920
|
+
...withNextRoute ? [
|
|
1921
|
+
nextRouteHint ?? `/swagger shows ${splitPath(outputPath).join('/')} once it is generated — the route is ${nextAppFolder(root)}/swagger/page.tsx`
|
|
1922
|
+
] : [],
|
|
1911
1923
|
...hasRestHandlers ? [] : [
|
|
1912
1924
|
`restHandlers appear in ${external_node_path_default().posix.join(rootFolder, 'presentation/rest/index.ts')} with the first REST endpoint generated with @domain-first/wire`
|
|
1913
1925
|
]
|
package/dist/integration.cjs
CHANGED
|
@@ -1511,6 +1511,28 @@ const missing_domain_first_packages_missingPackages = (packages)=>{
|
|
|
1511
1511
|
`npm i ${missing.join(' ')}`
|
|
1512
1512
|
] : [];
|
|
1513
1513
|
};
|
|
1514
|
+
const splitSegments = (rawSource)=>rawSource.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment);
|
|
1515
|
+
class NestedName {
|
|
1516
|
+
folders;
|
|
1517
|
+
folderName;
|
|
1518
|
+
fileName;
|
|
1519
|
+
ClassName;
|
|
1520
|
+
classNameSegments;
|
|
1521
|
+
constructor(rawSource){
|
|
1522
|
+
const segments = splitSegments(rawSource);
|
|
1523
|
+
this.folders = segments.slice(0, -1);
|
|
1524
|
+
this.folderName = new UnknownFormatNaming(segments.at(-1) ?? '').fileName;
|
|
1525
|
+
this.fileName = segments.map((segment)=>new UnknownFormatNaming(segment).fileName).join('-');
|
|
1526
|
+
this.classNameSegments = segments.map((segment)=>new UnknownFormatNaming(segment).ClassName);
|
|
1527
|
+
this.ClassName = this.classNameSegments.join('');
|
|
1528
|
+
}
|
|
1529
|
+
static validate = (rawSource)=>{
|
|
1530
|
+
const segments = splitSegments(rawSource);
|
|
1531
|
+
if (!segments.length) return 'Name is required';
|
|
1532
|
+
if (segments.some((segment)=>'.' === segment || '..' === segment)) return 'Use a path relative to the folder, without "." or ".."';
|
|
1533
|
+
return true;
|
|
1534
|
+
};
|
|
1535
|
+
}
|
|
1514
1536
|
const usesNext = ()=>config_file_ConfigFile.exists && config_file_ConfigFile.Instance.data.frontend?.react?.framework === 'next';
|
|
1515
1537
|
const nextAppFolder = (root)=>[
|
|
1516
1538
|
'app',
|
|
@@ -1550,28 +1572,6 @@ const compilerOption = (configFile, name, seen = new Set())=>{
|
|
|
1550
1572
|
if (void 0 !== value) return value;
|
|
1551
1573
|
}
|
|
1552
1574
|
};
|
|
1553
|
-
const splitSegments = (rawSource)=>rawSource.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment);
|
|
1554
|
-
class NestedName {
|
|
1555
|
-
folders;
|
|
1556
|
-
folderName;
|
|
1557
|
-
fileName;
|
|
1558
|
-
ClassName;
|
|
1559
|
-
classNameSegments;
|
|
1560
|
-
constructor(rawSource){
|
|
1561
|
-
const segments = splitSegments(rawSource);
|
|
1562
|
-
this.folders = segments.slice(0, -1);
|
|
1563
|
-
this.folderName = new UnknownFormatNaming(segments.at(-1) ?? '').fileName;
|
|
1564
|
-
this.fileName = segments.map((segment)=>new UnknownFormatNaming(segment).fileName).join('-');
|
|
1565
|
-
this.classNameSegments = segments.map((segment)=>new UnknownFormatNaming(segment).ClassName);
|
|
1566
|
-
this.ClassName = this.classNameSegments.join('');
|
|
1567
|
-
}
|
|
1568
|
-
static validate = (rawSource)=>{
|
|
1569
|
-
const segments = splitSegments(rawSource);
|
|
1570
|
-
if (!segments.length) return 'Name is required';
|
|
1571
|
-
if (segments.some((segment)=>'.' === segment || '..' === segment)) return 'Use a path relative to the folder, without "." or ".."';
|
|
1572
|
-
return true;
|
|
1573
|
-
};
|
|
1574
|
-
}
|
|
1575
1575
|
const reactPageContent = (ClassName, { imports = [], body = '<></>' } = {})=>`
|
|
1576
1576
|
${[
|
|
1577
1577
|
...imports,
|
|
@@ -1591,13 +1591,14 @@ export default function Page() {
|
|
|
1591
1591
|
return <${ClassName}Page />
|
|
1592
1592
|
}
|
|
1593
1593
|
`.trim();
|
|
1594
|
-
const scaffoldNextRoute = (name,
|
|
1594
|
+
const scaffoldNextRoute = (name, pagePath)=>{
|
|
1595
1595
|
const root = new project_root_ProjectRoot().path;
|
|
1596
1596
|
const route = external_node_path_default().join(root, nextAppFolder(root), ...name.folders, name.folderName, 'page.tsx');
|
|
1597
1597
|
const relativeRoute = external_node_path_default().relative(root, route).split(external_node_path_default().sep).join('/');
|
|
1598
1598
|
const routeFile = new file_system_File(route);
|
|
1599
|
-
|
|
1600
|
-
routeFile.data
|
|
1599
|
+
const content = nextRouteContent(name.ClassName, relativeImport(route, pagePath.replace(/\.tsx$/, '')));
|
|
1600
|
+
if (routeFile.exists) return routeFile.data === content ? void 0 : `${relativeRoute} already exists: render ${name.ClassName}Page there yourself.`;
|
|
1601
|
+
routeFile.data = content;
|
|
1601
1602
|
};
|
|
1602
1603
|
const scaffoldReactPage = async (presentationReactFolder)=>{
|
|
1603
1604
|
const name = await interaction_input({
|
|
@@ -1611,7 +1612,10 @@ const scaffoldReactPage = async (presentationReactFolder)=>{
|
|
|
1611
1612
|
'pages',
|
|
1612
1613
|
...folders
|
|
1613
1614
|
]).createFile(`${fileName}-page.tsx`, reactPageContent(ClassName));
|
|
1614
|
-
if (usesNext())
|
|
1615
|
+
if (usesNext()) {
|
|
1616
|
+
const hint = scaffoldNextRoute(nestedName, pageFile.path);
|
|
1617
|
+
if (hint) report(hint);
|
|
1618
|
+
}
|
|
1615
1619
|
};
|
|
1616
1620
|
const openapiExtractorPath = "scripts/extract-open-api-data-from-endpoint.ts";
|
|
1617
1621
|
const rootFolderSegments = (rootFolder, indent = 20)=>rootFolder.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment && '.' !== segment).map((segment)=>`'${segment}',\n${' '.repeat(indent)}`).join('');
|
|
@@ -1784,9 +1788,9 @@ const extractorPackages = [
|
|
|
1784
1788
|
'@microsoft/tsdoc'
|
|
1785
1789
|
];
|
|
1786
1790
|
const swaggerPagePath = (rootFolder)=>external_node_path_default().posix.join(rootFolder.replaceAll('\\', '/'), 'presentation/react/pages/swagger-page.tsx');
|
|
1787
|
-
const swaggerPage = (rootFolder, outputPath)=>{
|
|
1791
|
+
const swaggerPage = (rootFolder, outputPath, withNext = false)=>{
|
|
1788
1792
|
const specImport = external_node_path_default().posix.relative(external_node_path_default().posix.dirname(swaggerPagePath(rootFolder)), outputPath);
|
|
1789
|
-
|
|
1793
|
+
const page = reactPageContent('Swagger', {
|
|
1790
1794
|
imports: [
|
|
1791
1795
|
"import 'swagger-ui-react/swagger-ui.css'",
|
|
1792
1796
|
"import SwaggerUI from 'swagger-ui-react'",
|
|
@@ -1794,6 +1798,7 @@ const swaggerPage = (rootFolder, outputPath)=>{
|
|
|
1794
1798
|
],
|
|
1795
1799
|
body: '<SwaggerUI displayOperationId spec={spec} />'
|
|
1796
1800
|
});
|
|
1801
|
+
return withNext ? `'use client'\n\n${page}` : page;
|
|
1797
1802
|
};
|
|
1798
1803
|
const openapiScripts = {
|
|
1799
1804
|
openapi: `tsx --env-file-if-exists=.env ${openapiScriptPath}`
|
|
@@ -1875,10 +1880,14 @@ const addOpenapi = async ()=>{
|
|
|
1875
1880
|
const generatorFile = new file_system_File(external_node_path_default().join(root, openapiScriptPath));
|
|
1876
1881
|
const content = openapiGenerator(rootFolder, apiTitle(manifest.name), routePrefix, splitPath(outputPath).join('/'), withExtractor);
|
|
1877
1882
|
if (!generatorFile.exists || generatorFile.data !== content) generatorFile.data = content;
|
|
1883
|
+
const withNextRoute = withSwaggerPage && usesNext();
|
|
1884
|
+
let nextRouteHint;
|
|
1878
1885
|
if (withSwaggerPage) {
|
|
1879
|
-
const
|
|
1880
|
-
const
|
|
1886
|
+
const pagePath = external_node_path_default().join(root, swaggerPagePath(rootFolder));
|
|
1887
|
+
const pageFile = new file_system_File(pagePath);
|
|
1888
|
+
const page = swaggerPage(rootFolder, splitPath(outputPath).join('/'), withNextRoute);
|
|
1881
1889
|
if (!pageFile.exists || pageFile.data !== page) pageFile.data = page;
|
|
1890
|
+
if (withNextRoute) nextRouteHint = scaffoldNextRoute(new NestedName('swagger'), pagePath);
|
|
1882
1891
|
}
|
|
1883
1892
|
const resolveJsonModule = withSwaggerPage ? compilerOption(external_node_path_default().join(root, 'tsconfig.json'), 'resolveJsonModule') : true;
|
|
1884
1893
|
const hasRestHandlers = new file_system_File(external_node_path_default().join(root, rootFolder, 'presentation', 'rest', 'index.ts')).exists;
|
|
@@ -1905,9 +1914,12 @@ const addOpenapi = async ()=>{
|
|
|
1905
1914
|
...describeScripts(selected, {
|
|
1906
1915
|
openapi: `generate the OpenAPI document from restHandlers in ${splitPath(outputPath).join('/')}`
|
|
1907
1916
|
}),
|
|
1908
|
-
...withSwaggerPage ? [
|
|
1917
|
+
...withSwaggerPage && !withNextRoute ? [
|
|
1909
1918
|
`SwaggerPage from ${swaggerPagePath(rootFolder)} shows ${splitPath(outputPath).join('/')} once it is generated — render it on a route of your app`
|
|
1910
1919
|
] : [],
|
|
1920
|
+
...withNextRoute ? [
|
|
1921
|
+
nextRouteHint ?? `/swagger shows ${splitPath(outputPath).join('/')} once it is generated — the route is ${nextAppFolder(root)}/swagger/page.tsx`
|
|
1922
|
+
] : [],
|
|
1911
1923
|
...hasRestHandlers ? [] : [
|
|
1912
1924
|
`restHandlers appear in ${external_node_path_default().posix.join(rootFolder, 'presentation/rest/index.ts')} with the first REST endpoint generated with @domain-first/wire`
|
|
1913
1925
|
]
|
|
@@ -2,9 +2,11 @@ export declare const openapiScriptPath = "scripts/generate-openapi.ts";
|
|
|
2
2
|
export declare const defaultOpenapiPath: (withNext: boolean) => "public/openapi.json" | "openapi.json";
|
|
3
3
|
export declare const swaggerPagePath: (rootFolder: string) => string;
|
|
4
4
|
/**
|
|
5
|
-
* A React page rendering the OpenAPI document with Swagger UI.
|
|
5
|
+
* A React page rendering the OpenAPI document with Swagger UI. With
|
|
6
|
+
* Next.js it is a client component: Swagger UI keeps state and its App
|
|
7
|
+
* Router route is a server component.
|
|
6
8
|
*/
|
|
7
|
-
export declare const swaggerPage: (rootFolder: string, outputPath: string) => string;
|
|
9
|
+
export declare const swaggerPage: (rootFolder: string, outputPath: string, withNext?: boolean) => string;
|
|
8
10
|
export declare const openapiScripts: {
|
|
9
11
|
openapi: string;
|
|
10
12
|
};
|
package/dist/react.cjs
CHANGED
|
@@ -1511,6 +1511,28 @@ const missing_domain_first_packages_missingPackages = (packages)=>{
|
|
|
1511
1511
|
`npm i ${missing.join(' ')}`
|
|
1512
1512
|
] : [];
|
|
1513
1513
|
};
|
|
1514
|
+
const splitSegments = (rawSource)=>rawSource.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment);
|
|
1515
|
+
class NestedName {
|
|
1516
|
+
folders;
|
|
1517
|
+
folderName;
|
|
1518
|
+
fileName;
|
|
1519
|
+
ClassName;
|
|
1520
|
+
classNameSegments;
|
|
1521
|
+
constructor(rawSource){
|
|
1522
|
+
const segments = splitSegments(rawSource);
|
|
1523
|
+
this.folders = segments.slice(0, -1);
|
|
1524
|
+
this.folderName = new UnknownFormatNaming(segments.at(-1) ?? '').fileName;
|
|
1525
|
+
this.fileName = segments.map((segment)=>new UnknownFormatNaming(segment).fileName).join('-');
|
|
1526
|
+
this.classNameSegments = segments.map((segment)=>new UnknownFormatNaming(segment).ClassName);
|
|
1527
|
+
this.ClassName = this.classNameSegments.join('');
|
|
1528
|
+
}
|
|
1529
|
+
static validate = (rawSource)=>{
|
|
1530
|
+
const segments = splitSegments(rawSource);
|
|
1531
|
+
if (!segments.length) return 'Name is required';
|
|
1532
|
+
if (segments.some((segment)=>'.' === segment || '..' === segment)) return 'Use a path relative to the folder, without "." or ".."';
|
|
1533
|
+
return true;
|
|
1534
|
+
};
|
|
1535
|
+
}
|
|
1514
1536
|
const usesNext = ()=>config_file_ConfigFile.exists && config_file_ConfigFile.Instance.data.frontend?.react?.framework === 'next';
|
|
1515
1537
|
const nextAppFolder = (root)=>[
|
|
1516
1538
|
'app',
|
|
@@ -1550,28 +1572,6 @@ const compilerOption = (configFile, name, seen = new Set())=>{
|
|
|
1550
1572
|
if (void 0 !== value) return value;
|
|
1551
1573
|
}
|
|
1552
1574
|
};
|
|
1553
|
-
const splitSegments = (rawSource)=>rawSource.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment);
|
|
1554
|
-
class NestedName {
|
|
1555
|
-
folders;
|
|
1556
|
-
folderName;
|
|
1557
|
-
fileName;
|
|
1558
|
-
ClassName;
|
|
1559
|
-
classNameSegments;
|
|
1560
|
-
constructor(rawSource){
|
|
1561
|
-
const segments = splitSegments(rawSource);
|
|
1562
|
-
this.folders = segments.slice(0, -1);
|
|
1563
|
-
this.folderName = new UnknownFormatNaming(segments.at(-1) ?? '').fileName;
|
|
1564
|
-
this.fileName = segments.map((segment)=>new UnknownFormatNaming(segment).fileName).join('-');
|
|
1565
|
-
this.classNameSegments = segments.map((segment)=>new UnknownFormatNaming(segment).ClassName);
|
|
1566
|
-
this.ClassName = this.classNameSegments.join('');
|
|
1567
|
-
}
|
|
1568
|
-
static validate = (rawSource)=>{
|
|
1569
|
-
const segments = splitSegments(rawSource);
|
|
1570
|
-
if (!segments.length) return 'Name is required';
|
|
1571
|
-
if (segments.some((segment)=>'.' === segment || '..' === segment)) return 'Use a path relative to the folder, without "." or ".."';
|
|
1572
|
-
return true;
|
|
1573
|
-
};
|
|
1574
|
-
}
|
|
1575
1575
|
const reactPageContent = (ClassName, { imports = [], body = '<></>' } = {})=>`
|
|
1576
1576
|
${[
|
|
1577
1577
|
...imports,
|
|
@@ -1591,13 +1591,14 @@ export default function Page() {
|
|
|
1591
1591
|
return <${ClassName}Page />
|
|
1592
1592
|
}
|
|
1593
1593
|
`.trim();
|
|
1594
|
-
const scaffoldNextRoute = (name,
|
|
1594
|
+
const scaffoldNextRoute = (name, pagePath)=>{
|
|
1595
1595
|
const root = new project_root_ProjectRoot().path;
|
|
1596
1596
|
const route = external_node_path_default().join(root, nextAppFolder(root), ...name.folders, name.folderName, 'page.tsx');
|
|
1597
1597
|
const relativeRoute = external_node_path_default().relative(root, route).split(external_node_path_default().sep).join('/');
|
|
1598
1598
|
const routeFile = new file_system_File(route);
|
|
1599
|
-
|
|
1600
|
-
routeFile.data
|
|
1599
|
+
const content = nextRouteContent(name.ClassName, relativeImport(route, pagePath.replace(/\.tsx$/, '')));
|
|
1600
|
+
if (routeFile.exists) return routeFile.data === content ? void 0 : `${relativeRoute} already exists: render ${name.ClassName}Page there yourself.`;
|
|
1601
|
+
routeFile.data = content;
|
|
1601
1602
|
};
|
|
1602
1603
|
const scaffoldReactPage = async (presentationReactFolder)=>{
|
|
1603
1604
|
const name = await interaction_input({
|
|
@@ -1611,7 +1612,10 @@ const scaffoldReactPage = async (presentationReactFolder)=>{
|
|
|
1611
1612
|
'pages',
|
|
1612
1613
|
...folders
|
|
1613
1614
|
]).createFile(`${fileName}-page.tsx`, reactPageContent(ClassName));
|
|
1614
|
-
if (usesNext())
|
|
1615
|
+
if (usesNext()) {
|
|
1616
|
+
const hint = scaffoldNextRoute(nestedName, pageFile.path);
|
|
1617
|
+
if (hint) report(hint);
|
|
1618
|
+
}
|
|
1615
1619
|
};
|
|
1616
1620
|
const openapiExtractorPath = "scripts/extract-open-api-data-from-endpoint.ts";
|
|
1617
1621
|
const rootFolderSegments = (rootFolder, indent = 20)=>rootFolder.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment && '.' !== segment).map((segment)=>`'${segment}',\n${' '.repeat(indent)}`).join('');
|
|
@@ -1784,9 +1788,9 @@ const extractorPackages = [
|
|
|
1784
1788
|
'@microsoft/tsdoc'
|
|
1785
1789
|
];
|
|
1786
1790
|
const swaggerPagePath = (rootFolder)=>external_node_path_default().posix.join(rootFolder.replaceAll('\\', '/'), 'presentation/react/pages/swagger-page.tsx');
|
|
1787
|
-
const swaggerPage = (rootFolder, outputPath)=>{
|
|
1791
|
+
const swaggerPage = (rootFolder, outputPath, withNext = false)=>{
|
|
1788
1792
|
const specImport = external_node_path_default().posix.relative(external_node_path_default().posix.dirname(swaggerPagePath(rootFolder)), outputPath);
|
|
1789
|
-
|
|
1793
|
+
const page = reactPageContent('Swagger', {
|
|
1790
1794
|
imports: [
|
|
1791
1795
|
"import 'swagger-ui-react/swagger-ui.css'",
|
|
1792
1796
|
"import SwaggerUI from 'swagger-ui-react'",
|
|
@@ -1794,6 +1798,7 @@ const swaggerPage = (rootFolder, outputPath)=>{
|
|
|
1794
1798
|
],
|
|
1795
1799
|
body: '<SwaggerUI displayOperationId spec={spec} />'
|
|
1796
1800
|
});
|
|
1801
|
+
return withNext ? `'use client'\n\n${page}` : page;
|
|
1797
1802
|
};
|
|
1798
1803
|
const openapiScripts = {
|
|
1799
1804
|
openapi: `tsx --env-file-if-exists=.env ${openapiScriptPath}`
|
|
@@ -1875,10 +1880,14 @@ const addOpenapi = async ()=>{
|
|
|
1875
1880
|
const generatorFile = new file_system_File(external_node_path_default().join(root, openapiScriptPath));
|
|
1876
1881
|
const content = openapiGenerator(rootFolder, apiTitle(manifest.name), routePrefix, splitPath(outputPath).join('/'), withExtractor);
|
|
1877
1882
|
if (!generatorFile.exists || generatorFile.data !== content) generatorFile.data = content;
|
|
1883
|
+
const withNextRoute = withSwaggerPage && usesNext();
|
|
1884
|
+
let nextRouteHint;
|
|
1878
1885
|
if (withSwaggerPage) {
|
|
1879
|
-
const
|
|
1880
|
-
const
|
|
1886
|
+
const pagePath = external_node_path_default().join(root, swaggerPagePath(rootFolder));
|
|
1887
|
+
const pageFile = new file_system_File(pagePath);
|
|
1888
|
+
const page = swaggerPage(rootFolder, splitPath(outputPath).join('/'), withNextRoute);
|
|
1881
1889
|
if (!pageFile.exists || pageFile.data !== page) pageFile.data = page;
|
|
1890
|
+
if (withNextRoute) nextRouteHint = scaffoldNextRoute(new NestedName('swagger'), pagePath);
|
|
1882
1891
|
}
|
|
1883
1892
|
const resolveJsonModule = withSwaggerPage ? compilerOption(external_node_path_default().join(root, 'tsconfig.json'), 'resolveJsonModule') : true;
|
|
1884
1893
|
const hasRestHandlers = new file_system_File(external_node_path_default().join(root, rootFolder, 'presentation', 'rest', 'index.ts')).exists;
|
|
@@ -1905,9 +1914,12 @@ const addOpenapi = async ()=>{
|
|
|
1905
1914
|
...describeScripts(selected, {
|
|
1906
1915
|
openapi: `generate the OpenAPI document from restHandlers in ${splitPath(outputPath).join('/')}`
|
|
1907
1916
|
}),
|
|
1908
|
-
...withSwaggerPage ? [
|
|
1917
|
+
...withSwaggerPage && !withNextRoute ? [
|
|
1909
1918
|
`SwaggerPage from ${swaggerPagePath(rootFolder)} shows ${splitPath(outputPath).join('/')} once it is generated — render it on a route of your app`
|
|
1910
1919
|
] : [],
|
|
1920
|
+
...withNextRoute ? [
|
|
1921
|
+
nextRouteHint ?? `/swagger shows ${splitPath(outputPath).join('/')} once it is generated — the route is ${nextAppFolder(root)}/swagger/page.tsx`
|
|
1922
|
+
] : [],
|
|
1911
1923
|
...hasRestHandlers ? [] : [
|
|
1912
1924
|
`restHandlers appear in ${external_node_path_default().posix.join(rootFolder, 'presentation/rest/index.ts')} with the first REST endpoint generated with @domain-first/wire`
|
|
1913
1925
|
]
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Folder } from '../file-system';
|
|
2
|
+
import { NestedName } from '../nested-name';
|
|
2
3
|
/**
|
|
3
4
|
* Content of `<file>-page.tsx`: imports go before React's, `body` is
|
|
4
5
|
* what the page returns.
|
|
@@ -9,4 +10,10 @@ export declare const reactPageContent: (ClassName: string, { imports, body }?: {
|
|
|
9
10
|
}) => string;
|
|
10
11
|
/** A thin App Router route that renders the page component. */
|
|
11
12
|
export declare const nextRouteContent: (ClassName: string, pageImport: string) => string;
|
|
13
|
+
/**
|
|
14
|
+
* With Next.js, the page also gets its App Router route at the same path,
|
|
15
|
+
* e.g. `admin/users` → `app/admin/users/page.tsx`. An existing route is
|
|
16
|
+
* kept: it may hold the user's code, and the returned hint says so.
|
|
17
|
+
*/
|
|
18
|
+
export declare const scaffoldNextRoute: (name: NestedName, pagePath: string) => string | undefined;
|
|
12
19
|
export declare const scaffoldReactPage: (presentationReactFolder: Folder) => Promise<void>;
|