@domain-first/project-structure 8.9.0 → 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/{526.js → 115.js} +210 -2
- package/dist/{947.js → 201.js} +479 -2
- package/dist/287.js +28 -218
- package/dist/38.js +1 -2
- package/dist/561.js +2 -3
- package/dist/graph.js +1 -2
- package/dist/in-memory-db.d.ts +9 -0
- package/dist/index.cjs +49 -39
- package/dist/index.js +1 -1
- package/dist/init.cjs +6 -8
- package/dist/init.js +1 -1
- package/dist/integration.cjs +49 -39
- package/dist/integration.js +1 -1
- package/dist/integrations/openapi.d.ts +4 -2
- package/dist/lint.js +1 -1
- package/dist/react.cjs +49 -39
- package/dist/react.js +1 -1
- package/dist/upgrade-in-memory-db.d.ts +7 -0
- package/dist/upgrade-in-memory-db.spec.d.ts +1 -0
- package/dist/upgrade.cjs +93 -27
- package/dist/upgrade.js +25 -3
- package/dist/use-cases/scaffold-react-page.d.ts +7 -0
- package/package.json +1 -1
- package/dist/780.js +0 -481
package/dist/integration.cjs
CHANGED
|
@@ -1283,6 +1283,11 @@ const inMemoryImplementationType = 'in-memory';
|
|
|
1283
1283
|
const in_memory_db_className = 'InMemoryDbInfrastructureService';
|
|
1284
1284
|
const in_memory_db_wireName = 'wireInMemoryDbInfrastructureService';
|
|
1285
1285
|
const in_memory_db_parameterName = 'inMemoryDbInfrastructureService';
|
|
1286
|
+
const withIdLookup = ` withId: (id: TId): T | null =>
|
|
1287
|
+
globalThis.___SHARED_IN_MEMORY_DB___![key].find((entry) =>
|
|
1288
|
+
idsAreEqual(entry.id as TId, id)
|
|
1289
|
+
)?.item ?? null,
|
|
1290
|
+
`;
|
|
1286
1291
|
const inMemoryDbService = `type Entry = {
|
|
1287
1292
|
id: unknown;
|
|
1288
1293
|
item: any;
|
|
@@ -1321,9 +1326,6 @@ const defaultIdsAreEqual = (a: unknown, b: unknown): boolean => {
|
|
|
1321
1326
|
return Object.is(a, b);
|
|
1322
1327
|
};
|
|
1323
1328
|
|
|
1324
|
-
const hasId = (x: unknown): x is { id: unknown } =>
|
|
1325
|
-
typeof x === 'object' && x !== null && 'id' in x;
|
|
1326
|
-
|
|
1327
1329
|
export class InMemoryDbInfrastructureService {
|
|
1328
1330
|
protected section<T extends { id: unknown }>(
|
|
1329
1331
|
key: string,
|
|
@@ -1355,11 +1357,7 @@ export class InMemoryDbInfrastructureService {
|
|
|
1355
1357
|
items().filter(predicate),
|
|
1356
1358
|
first: (predicate: (x: T) => boolean): T | null =>
|
|
1357
1359
|
items().find(predicate) ?? null,
|
|
1358
|
-
|
|
1359
|
-
items().find(
|
|
1360
|
-
(x: T) => hasId(x) && idsAreEqual(x.id as TId, id)
|
|
1361
|
-
) ?? null,
|
|
1362
|
-
lastAddedItem: (): T | null =>
|
|
1360
|
+
${withIdLookup} lastAddedItem: (): T | null =>
|
|
1363
1361
|
globalThis.___SHARED_IN_MEMORY_DB___![key].at(-1)?.item ?? null,
|
|
1364
1362
|
save: (payload: T extends { id: TId } ? T : [TId, T]) => {
|
|
1365
1363
|
const id = Array.isArray(payload) ? payload[0] : payload.id;
|
|
@@ -1513,6 +1511,28 @@ const missing_domain_first_packages_missingPackages = (packages)=>{
|
|
|
1513
1511
|
`npm i ${missing.join(' ')}`
|
|
1514
1512
|
] : [];
|
|
1515
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
|
+
}
|
|
1516
1536
|
const usesNext = ()=>config_file_ConfigFile.exists && config_file_ConfigFile.Instance.data.frontend?.react?.framework === 'next';
|
|
1517
1537
|
const nextAppFolder = (root)=>[
|
|
1518
1538
|
'app',
|
|
@@ -1552,28 +1572,6 @@ const compilerOption = (configFile, name, seen = new Set())=>{
|
|
|
1552
1572
|
if (void 0 !== value) return value;
|
|
1553
1573
|
}
|
|
1554
1574
|
};
|
|
1555
|
-
const splitSegments = (rawSource)=>rawSource.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment);
|
|
1556
|
-
class NestedName {
|
|
1557
|
-
folders;
|
|
1558
|
-
folderName;
|
|
1559
|
-
fileName;
|
|
1560
|
-
ClassName;
|
|
1561
|
-
classNameSegments;
|
|
1562
|
-
constructor(rawSource){
|
|
1563
|
-
const segments = splitSegments(rawSource);
|
|
1564
|
-
this.folders = segments.slice(0, -1);
|
|
1565
|
-
this.folderName = new UnknownFormatNaming(segments.at(-1) ?? '').fileName;
|
|
1566
|
-
this.fileName = segments.map((segment)=>new UnknownFormatNaming(segment).fileName).join('-');
|
|
1567
|
-
this.classNameSegments = segments.map((segment)=>new UnknownFormatNaming(segment).ClassName);
|
|
1568
|
-
this.ClassName = this.classNameSegments.join('');
|
|
1569
|
-
}
|
|
1570
|
-
static validate = (rawSource)=>{
|
|
1571
|
-
const segments = splitSegments(rawSource);
|
|
1572
|
-
if (!segments.length) return 'Name is required';
|
|
1573
|
-
if (segments.some((segment)=>'.' === segment || '..' === segment)) return 'Use a path relative to the folder, without "." or ".."';
|
|
1574
|
-
return true;
|
|
1575
|
-
};
|
|
1576
|
-
}
|
|
1577
1575
|
const reactPageContent = (ClassName, { imports = [], body = '<></>' } = {})=>`
|
|
1578
1576
|
${[
|
|
1579
1577
|
...imports,
|
|
@@ -1593,13 +1591,14 @@ export default function Page() {
|
|
|
1593
1591
|
return <${ClassName}Page />
|
|
1594
1592
|
}
|
|
1595
1593
|
`.trim();
|
|
1596
|
-
const scaffoldNextRoute = (name,
|
|
1594
|
+
const scaffoldNextRoute = (name, pagePath)=>{
|
|
1597
1595
|
const root = new project_root_ProjectRoot().path;
|
|
1598
1596
|
const route = external_node_path_default().join(root, nextAppFolder(root), ...name.folders, name.folderName, 'page.tsx');
|
|
1599
1597
|
const relativeRoute = external_node_path_default().relative(root, route).split(external_node_path_default().sep).join('/');
|
|
1600
1598
|
const routeFile = new file_system_File(route);
|
|
1601
|
-
|
|
1602
|
-
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;
|
|
1603
1602
|
};
|
|
1604
1603
|
const scaffoldReactPage = async (presentationReactFolder)=>{
|
|
1605
1604
|
const name = await interaction_input({
|
|
@@ -1613,7 +1612,10 @@ const scaffoldReactPage = async (presentationReactFolder)=>{
|
|
|
1613
1612
|
'pages',
|
|
1614
1613
|
...folders
|
|
1615
1614
|
]).createFile(`${fileName}-page.tsx`, reactPageContent(ClassName));
|
|
1616
|
-
if (usesNext())
|
|
1615
|
+
if (usesNext()) {
|
|
1616
|
+
const hint = scaffoldNextRoute(nestedName, pageFile.path);
|
|
1617
|
+
if (hint) report(hint);
|
|
1618
|
+
}
|
|
1617
1619
|
};
|
|
1618
1620
|
const openapiExtractorPath = "scripts/extract-open-api-data-from-endpoint.ts";
|
|
1619
1621
|
const rootFolderSegments = (rootFolder, indent = 20)=>rootFolder.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment && '.' !== segment).map((segment)=>`'${segment}',\n${' '.repeat(indent)}`).join('');
|
|
@@ -1786,9 +1788,9 @@ const extractorPackages = [
|
|
|
1786
1788
|
'@microsoft/tsdoc'
|
|
1787
1789
|
];
|
|
1788
1790
|
const swaggerPagePath = (rootFolder)=>external_node_path_default().posix.join(rootFolder.replaceAll('\\', '/'), 'presentation/react/pages/swagger-page.tsx');
|
|
1789
|
-
const swaggerPage = (rootFolder, outputPath)=>{
|
|
1791
|
+
const swaggerPage = (rootFolder, outputPath, withNext = false)=>{
|
|
1790
1792
|
const specImport = external_node_path_default().posix.relative(external_node_path_default().posix.dirname(swaggerPagePath(rootFolder)), outputPath);
|
|
1791
|
-
|
|
1793
|
+
const page = reactPageContent('Swagger', {
|
|
1792
1794
|
imports: [
|
|
1793
1795
|
"import 'swagger-ui-react/swagger-ui.css'",
|
|
1794
1796
|
"import SwaggerUI from 'swagger-ui-react'",
|
|
@@ -1796,6 +1798,7 @@ const swaggerPage = (rootFolder, outputPath)=>{
|
|
|
1796
1798
|
],
|
|
1797
1799
|
body: '<SwaggerUI displayOperationId spec={spec} />'
|
|
1798
1800
|
});
|
|
1801
|
+
return withNext ? `'use client'\n\n${page}` : page;
|
|
1799
1802
|
};
|
|
1800
1803
|
const openapiScripts = {
|
|
1801
1804
|
openapi: `tsx --env-file-if-exists=.env ${openapiScriptPath}`
|
|
@@ -1877,10 +1880,14 @@ const addOpenapi = async ()=>{
|
|
|
1877
1880
|
const generatorFile = new file_system_File(external_node_path_default().join(root, openapiScriptPath));
|
|
1878
1881
|
const content = openapiGenerator(rootFolder, apiTitle(manifest.name), routePrefix, splitPath(outputPath).join('/'), withExtractor);
|
|
1879
1882
|
if (!generatorFile.exists || generatorFile.data !== content) generatorFile.data = content;
|
|
1883
|
+
const withNextRoute = withSwaggerPage && usesNext();
|
|
1884
|
+
let nextRouteHint;
|
|
1880
1885
|
if (withSwaggerPage) {
|
|
1881
|
-
const
|
|
1882
|
-
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);
|
|
1883
1889
|
if (!pageFile.exists || pageFile.data !== page) pageFile.data = page;
|
|
1890
|
+
if (withNextRoute) nextRouteHint = scaffoldNextRoute(new NestedName('swagger'), pagePath);
|
|
1884
1891
|
}
|
|
1885
1892
|
const resolveJsonModule = withSwaggerPage ? compilerOption(external_node_path_default().join(root, 'tsconfig.json'), 'resolveJsonModule') : true;
|
|
1886
1893
|
const hasRestHandlers = new file_system_File(external_node_path_default().join(root, rootFolder, 'presentation', 'rest', 'index.ts')).exists;
|
|
@@ -1907,9 +1914,12 @@ const addOpenapi = async ()=>{
|
|
|
1907
1914
|
...describeScripts(selected, {
|
|
1908
1915
|
openapi: `generate the OpenAPI document from restHandlers in ${splitPath(outputPath).join('/')}`
|
|
1909
1916
|
}),
|
|
1910
|
-
...withSwaggerPage ? [
|
|
1917
|
+
...withSwaggerPage && !withNextRoute ? [
|
|
1911
1918
|
`SwaggerPage from ${swaggerPagePath(rootFolder)} shows ${splitPath(outputPath).join('/')} once it is generated — render it on a route of your app`
|
|
1912
1919
|
] : [],
|
|
1920
|
+
...withNextRoute ? [
|
|
1921
|
+
nextRouteHint ?? `/swagger shows ${splitPath(outputPath).join('/')} once it is generated — the route is ${nextAppFolder(root)}/swagger/page.tsx`
|
|
1922
|
+
] : [],
|
|
1913
1923
|
...hasRestHandlers ? [] : [
|
|
1914
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`
|
|
1915
1925
|
]
|
package/dist/integration.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { parseArgs } from "node:util";
|
|
3
3
|
import { runCLI } from "./561.js";
|
|
4
|
-
import { ConfigFile, outdatedConfigMessage } from "./
|
|
4
|
+
import { ConfigFile, outdatedConfigMessage } from "./201.js";
|
|
5
5
|
import { addIntegration } from "./287.js";
|
|
6
6
|
runCLI('df-integration', async ()=>{
|
|
7
7
|
const help = `Usage: df-integration
|
|
@@ -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/lint.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { parseArgs } from "node:util";
|
|
3
|
-
import { configuredDependencyRules, ProjectRoot, outdatedConfigMessage, ConfigFile } from "./
|
|
3
|
+
import { configuredDependencyRules, ProjectRoot, outdatedConfigMessage, ConfigFile } from "./201.js";
|
|
4
4
|
import { lintProject, formatViolations } from "./38.js";
|
|
5
5
|
const help = `Usage: df-lint [rootFolder]
|
|
6
6
|
|
package/dist/react.cjs
CHANGED
|
@@ -1283,6 +1283,11 @@ const inMemoryImplementationType = 'in-memory';
|
|
|
1283
1283
|
const in_memory_db_className = 'InMemoryDbInfrastructureService';
|
|
1284
1284
|
const in_memory_db_wireName = 'wireInMemoryDbInfrastructureService';
|
|
1285
1285
|
const in_memory_db_parameterName = 'inMemoryDbInfrastructureService';
|
|
1286
|
+
const withIdLookup = ` withId: (id: TId): T | null =>
|
|
1287
|
+
globalThis.___SHARED_IN_MEMORY_DB___![key].find((entry) =>
|
|
1288
|
+
idsAreEqual(entry.id as TId, id)
|
|
1289
|
+
)?.item ?? null,
|
|
1290
|
+
`;
|
|
1286
1291
|
const inMemoryDbService = `type Entry = {
|
|
1287
1292
|
id: unknown;
|
|
1288
1293
|
item: any;
|
|
@@ -1321,9 +1326,6 @@ const defaultIdsAreEqual = (a: unknown, b: unknown): boolean => {
|
|
|
1321
1326
|
return Object.is(a, b);
|
|
1322
1327
|
};
|
|
1323
1328
|
|
|
1324
|
-
const hasId = (x: unknown): x is { id: unknown } =>
|
|
1325
|
-
typeof x === 'object' && x !== null && 'id' in x;
|
|
1326
|
-
|
|
1327
1329
|
export class InMemoryDbInfrastructureService {
|
|
1328
1330
|
protected section<T extends { id: unknown }>(
|
|
1329
1331
|
key: string,
|
|
@@ -1355,11 +1357,7 @@ export class InMemoryDbInfrastructureService {
|
|
|
1355
1357
|
items().filter(predicate),
|
|
1356
1358
|
first: (predicate: (x: T) => boolean): T | null =>
|
|
1357
1359
|
items().find(predicate) ?? null,
|
|
1358
|
-
|
|
1359
|
-
items().find(
|
|
1360
|
-
(x: T) => hasId(x) && idsAreEqual(x.id as TId, id)
|
|
1361
|
-
) ?? null,
|
|
1362
|
-
lastAddedItem: (): T | null =>
|
|
1360
|
+
${withIdLookup} lastAddedItem: (): T | null =>
|
|
1363
1361
|
globalThis.___SHARED_IN_MEMORY_DB___![key].at(-1)?.item ?? null,
|
|
1364
1362
|
save: (payload: T extends { id: TId } ? T : [TId, T]) => {
|
|
1365
1363
|
const id = Array.isArray(payload) ? payload[0] : payload.id;
|
|
@@ -1513,6 +1511,28 @@ const missing_domain_first_packages_missingPackages = (packages)=>{
|
|
|
1513
1511
|
`npm i ${missing.join(' ')}`
|
|
1514
1512
|
] : [];
|
|
1515
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
|
+
}
|
|
1516
1536
|
const usesNext = ()=>config_file_ConfigFile.exists && config_file_ConfigFile.Instance.data.frontend?.react?.framework === 'next';
|
|
1517
1537
|
const nextAppFolder = (root)=>[
|
|
1518
1538
|
'app',
|
|
@@ -1552,28 +1572,6 @@ const compilerOption = (configFile, name, seen = new Set())=>{
|
|
|
1552
1572
|
if (void 0 !== value) return value;
|
|
1553
1573
|
}
|
|
1554
1574
|
};
|
|
1555
|
-
const splitSegments = (rawSource)=>rawSource.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment);
|
|
1556
|
-
class NestedName {
|
|
1557
|
-
folders;
|
|
1558
|
-
folderName;
|
|
1559
|
-
fileName;
|
|
1560
|
-
ClassName;
|
|
1561
|
-
classNameSegments;
|
|
1562
|
-
constructor(rawSource){
|
|
1563
|
-
const segments = splitSegments(rawSource);
|
|
1564
|
-
this.folders = segments.slice(0, -1);
|
|
1565
|
-
this.folderName = new UnknownFormatNaming(segments.at(-1) ?? '').fileName;
|
|
1566
|
-
this.fileName = segments.map((segment)=>new UnknownFormatNaming(segment).fileName).join('-');
|
|
1567
|
-
this.classNameSegments = segments.map((segment)=>new UnknownFormatNaming(segment).ClassName);
|
|
1568
|
-
this.ClassName = this.classNameSegments.join('');
|
|
1569
|
-
}
|
|
1570
|
-
static validate = (rawSource)=>{
|
|
1571
|
-
const segments = splitSegments(rawSource);
|
|
1572
|
-
if (!segments.length) return 'Name is required';
|
|
1573
|
-
if (segments.some((segment)=>'.' === segment || '..' === segment)) return 'Use a path relative to the folder, without "." or ".."';
|
|
1574
|
-
return true;
|
|
1575
|
-
};
|
|
1576
|
-
}
|
|
1577
1575
|
const reactPageContent = (ClassName, { imports = [], body = '<></>' } = {})=>`
|
|
1578
1576
|
${[
|
|
1579
1577
|
...imports,
|
|
@@ -1593,13 +1591,14 @@ export default function Page() {
|
|
|
1593
1591
|
return <${ClassName}Page />
|
|
1594
1592
|
}
|
|
1595
1593
|
`.trim();
|
|
1596
|
-
const scaffoldNextRoute = (name,
|
|
1594
|
+
const scaffoldNextRoute = (name, pagePath)=>{
|
|
1597
1595
|
const root = new project_root_ProjectRoot().path;
|
|
1598
1596
|
const route = external_node_path_default().join(root, nextAppFolder(root), ...name.folders, name.folderName, 'page.tsx');
|
|
1599
1597
|
const relativeRoute = external_node_path_default().relative(root, route).split(external_node_path_default().sep).join('/');
|
|
1600
1598
|
const routeFile = new file_system_File(route);
|
|
1601
|
-
|
|
1602
|
-
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;
|
|
1603
1602
|
};
|
|
1604
1603
|
const scaffoldReactPage = async (presentationReactFolder)=>{
|
|
1605
1604
|
const name = await interaction_input({
|
|
@@ -1613,7 +1612,10 @@ const scaffoldReactPage = async (presentationReactFolder)=>{
|
|
|
1613
1612
|
'pages',
|
|
1614
1613
|
...folders
|
|
1615
1614
|
]).createFile(`${fileName}-page.tsx`, reactPageContent(ClassName));
|
|
1616
|
-
if (usesNext())
|
|
1615
|
+
if (usesNext()) {
|
|
1616
|
+
const hint = scaffoldNextRoute(nestedName, pageFile.path);
|
|
1617
|
+
if (hint) report(hint);
|
|
1618
|
+
}
|
|
1617
1619
|
};
|
|
1618
1620
|
const openapiExtractorPath = "scripts/extract-open-api-data-from-endpoint.ts";
|
|
1619
1621
|
const rootFolderSegments = (rootFolder, indent = 20)=>rootFolder.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment && '.' !== segment).map((segment)=>`'${segment}',\n${' '.repeat(indent)}`).join('');
|
|
@@ -1786,9 +1788,9 @@ const extractorPackages = [
|
|
|
1786
1788
|
'@microsoft/tsdoc'
|
|
1787
1789
|
];
|
|
1788
1790
|
const swaggerPagePath = (rootFolder)=>external_node_path_default().posix.join(rootFolder.replaceAll('\\', '/'), 'presentation/react/pages/swagger-page.tsx');
|
|
1789
|
-
const swaggerPage = (rootFolder, outputPath)=>{
|
|
1791
|
+
const swaggerPage = (rootFolder, outputPath, withNext = false)=>{
|
|
1790
1792
|
const specImport = external_node_path_default().posix.relative(external_node_path_default().posix.dirname(swaggerPagePath(rootFolder)), outputPath);
|
|
1791
|
-
|
|
1793
|
+
const page = reactPageContent('Swagger', {
|
|
1792
1794
|
imports: [
|
|
1793
1795
|
"import 'swagger-ui-react/swagger-ui.css'",
|
|
1794
1796
|
"import SwaggerUI from 'swagger-ui-react'",
|
|
@@ -1796,6 +1798,7 @@ const swaggerPage = (rootFolder, outputPath)=>{
|
|
|
1796
1798
|
],
|
|
1797
1799
|
body: '<SwaggerUI displayOperationId spec={spec} />'
|
|
1798
1800
|
});
|
|
1801
|
+
return withNext ? `'use client'\n\n${page}` : page;
|
|
1799
1802
|
};
|
|
1800
1803
|
const openapiScripts = {
|
|
1801
1804
|
openapi: `tsx --env-file-if-exists=.env ${openapiScriptPath}`
|
|
@@ -1877,10 +1880,14 @@ const addOpenapi = async ()=>{
|
|
|
1877
1880
|
const generatorFile = new file_system_File(external_node_path_default().join(root, openapiScriptPath));
|
|
1878
1881
|
const content = openapiGenerator(rootFolder, apiTitle(manifest.name), routePrefix, splitPath(outputPath).join('/'), withExtractor);
|
|
1879
1882
|
if (!generatorFile.exists || generatorFile.data !== content) generatorFile.data = content;
|
|
1883
|
+
const withNextRoute = withSwaggerPage && usesNext();
|
|
1884
|
+
let nextRouteHint;
|
|
1880
1885
|
if (withSwaggerPage) {
|
|
1881
|
-
const
|
|
1882
|
-
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);
|
|
1883
1889
|
if (!pageFile.exists || pageFile.data !== page) pageFile.data = page;
|
|
1890
|
+
if (withNextRoute) nextRouteHint = scaffoldNextRoute(new NestedName('swagger'), pagePath);
|
|
1884
1891
|
}
|
|
1885
1892
|
const resolveJsonModule = withSwaggerPage ? compilerOption(external_node_path_default().join(root, 'tsconfig.json'), 'resolveJsonModule') : true;
|
|
1886
1893
|
const hasRestHandlers = new file_system_File(external_node_path_default().join(root, rootFolder, 'presentation', 'rest', 'index.ts')).exists;
|
|
@@ -1907,9 +1914,12 @@ const addOpenapi = async ()=>{
|
|
|
1907
1914
|
...describeScripts(selected, {
|
|
1908
1915
|
openapi: `generate the OpenAPI document from restHandlers in ${splitPath(outputPath).join('/')}`
|
|
1909
1916
|
}),
|
|
1910
|
-
...withSwaggerPage ? [
|
|
1917
|
+
...withSwaggerPage && !withNextRoute ? [
|
|
1911
1918
|
`SwaggerPage from ${swaggerPagePath(rootFolder)} shows ${splitPath(outputPath).join('/')} once it is generated — render it on a route of your app`
|
|
1912
1919
|
] : [],
|
|
1920
|
+
...withNextRoute ? [
|
|
1921
|
+
nextRouteHint ?? `/swagger shows ${splitPath(outputPath).join('/')} once it is generated — the route is ${nextAppFolder(root)}/swagger/page.tsx`
|
|
1922
|
+
] : [],
|
|
1913
1923
|
...hasRestHandlers ? [] : [
|
|
1914
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`
|
|
1915
1925
|
]
|
package/dist/react.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { parseArgs } from "node:util";
|
|
3
3
|
import { select as prompts_select } from "@inquirer/prompts";
|
|
4
4
|
import { runCLI } from "./561.js";
|
|
5
|
-
import { outdatedConfigMessage, ProjectRoot, ConfigFile, Folder } from "./
|
|
5
|
+
import { outdatedConfigMessage, ProjectRoot, ConfigFile, Folder } from "./201.js";
|
|
6
6
|
import { scaffoldReactWidget, moveReactModuleUseCase, deleteReactModuleUseCase, scaffoldReactPage, scaffoldReactUIKitComponent, scaffoldReactSharedHook, savePendingChanges } from "./287.js";
|
|
7
7
|
runCLI('df-react', async ()=>{
|
|
8
8
|
const help = `Usage: df-react
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { UpgradeStep } from './upgrade-steps';
|
|
2
|
+
/**
|
|
3
|
+
* Fixes `withId` of the generated in-memory DB: items saved as an
|
|
4
|
+
* `[id, item]` tuple have no `id` of their own and were never found.
|
|
5
|
+
* Only the untouched generated lookup is replaced.
|
|
6
|
+
*/
|
|
7
|
+
export declare const inMemoryDbWithIdStep: UpgradeStep;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|