@domain-first/project-structure 5.1.2 → 7.0.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 +18 -21
- package/dist/201.js +46 -35
- package/dist/287.js +3290 -0
- package/dist/config-file.d.ts +2 -2
- package/dist/dependency-rules.d.ts +1 -1
- package/dist/file-system.d.ts +5 -0
- package/dist/in-memory-db.d.ts +5 -0
- package/dist/index.cjs +195 -2156
- package/dist/index.js +9 -3169
- package/dist/init.cjs +868 -0
- package/dist/init.d.ts +2 -0
- package/dist/init.js +36 -0
- package/dist/integration.cjs +2063 -0
- package/dist/integration.d.ts +2 -0
- package/dist/integration.js +31 -0
- package/dist/integrations/in-memory-db.d.ts +6 -0
- package/dist/integrations/index.d.ts +2 -0
- package/dist/integrations/missing-domain-first-packages.d.ts +8 -0
- package/dist/integrations/orval.d.ts +7 -4
- package/dist/integrations/rest-endpoint-generator.d.ts +18 -0
- package/dist/integrations/rest-endpoint-generator.spec.d.ts +1 -0
- package/dist/lint.cjs +8 -8
- package/dist/lint.js +7 -7
- package/dist/print-next-steps.d.ts +9 -2
- package/dist/react.cjs +915 -0
- package/dist/react.d.ts +2 -0
- package/dist/react.js +73 -0
- package/dist/use-cases/add-integration-order.spec.d.ts +1 -0
- package/dist/use-cases/rest-endpoint-generator.d.ts +1 -1
- package/package.json +5 -2
- package/skills/df-ps-implement/SKILL.md +12 -57
- package/skills/df-ps-plan-feature/SKILL.md +7 -7
- package/skills/df-ps-project-scripts/SKILL.md +1 -1
- package/skills/df-ps-react/SKILL.md +82 -0
- package/skills/df-ps-react/references/generators.md +80 -0
- package/skills/df-ps-scaffold/SKILL.md +46 -28
- package/skills/df-ps-scaffold/references/choosing-components.md +7 -28
- package/skills/df-ps-scaffold/references/generators.md +6 -179
- package/skills/df-ps-scaffold/references/units/aggregate.md +47 -0
- package/skills/df-ps-scaffold/references/units/bounded-context.md +13 -0
- package/skills/df-ps-scaffold/references/units/command-query.md +32 -0
- package/skills/df-ps-scaffold/references/units/endpoint.md +28 -0
- package/skills/df-ps-scaffold/references/units/entity-value-object.md +27 -0
- package/skills/df-ps-scaffold/references/units/errors.md +26 -0
- package/skills/df-ps-scaffold/references/units/port.md +23 -0
- package/skills/df-ps-scaffold/references/units/services.md +28 -0
- package/skills/df-ps-scaffold/references/units/use-case.md +25 -0
- package/skills/df-ps-scaffold/references/units/wire-dependency.md +15 -0
- package/skills/df-ps-scaffold/scripts/drive.mjs +12 -4
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { parseArgs } from "node:util";
|
|
3
|
+
import { ConfigFile } from "./201.js";
|
|
4
|
+
import { addIntegration } from "./287.js";
|
|
5
|
+
const help = `Usage: df-integration
|
|
6
|
+
|
|
7
|
+
Adds integrations to a Domain-First project: the REST endpoint generator,
|
|
8
|
+
the in-memory DB, Storybook, Prisma, Vitest, Playwright, integration tests,
|
|
9
|
+
OpenAPI and Orval. Several can be selected at once. Changes project files and prints
|
|
10
|
+
the install commands; nothing is installed or run.
|
|
11
|
+
|
|
12
|
+
Options:
|
|
13
|
+
-h, --help show this help`;
|
|
14
|
+
const { values: values } = parseArgs({
|
|
15
|
+
options: {
|
|
16
|
+
help: {
|
|
17
|
+
type: 'boolean',
|
|
18
|
+
short: 'h',
|
|
19
|
+
default: false
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
if (values.help) {
|
|
24
|
+
console.log(help);
|
|
25
|
+
process.exit(0);
|
|
26
|
+
}
|
|
27
|
+
if (!ConfigFile.exists) {
|
|
28
|
+
console.log('No domain-first.project-structure.config.json found: run df-init first to initialize the project.');
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
addIntegration();
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
export * from './in-memory-db';
|
|
1
2
|
export * from './missing-domain-first-packages';
|
|
2
3
|
export * from './openapi';
|
|
3
4
|
export * from './orval';
|
|
4
5
|
export * from './package-scripts';
|
|
5
6
|
export * from './playwright';
|
|
6
7
|
export * from './prisma';
|
|
8
|
+
export * from './rest-endpoint-generator';
|
|
7
9
|
export * from './storybook';
|
|
8
10
|
export * from './testcontainers';
|
|
9
11
|
export * from './vitest';
|
|
@@ -1 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether the project's manifest declares `name` in any dependency group.
|
|
3
|
+
*/
|
|
4
|
+
export declare const hasDependency: (name: string) => boolean;
|
|
5
|
+
/**
|
|
6
|
+
* The install command for the packages the manifest doesn't declare.
|
|
7
|
+
*/
|
|
8
|
+
export declare const missingPackages: (packages: string[]) => string[];
|
|
1
9
|
export declare const missingDomainFirstPackages: () => string[];
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type OrvalTarget = 'hooks' | 'client';
|
|
2
|
+
/** React Query hooks go to the React data layer, the typed client to the shared one. */
|
|
3
|
+
export declare const dataLayerFolder: (rootFolder: string, target: OrvalTarget) => string;
|
|
4
|
+
export declare const orvalScripts: (rootFolder: string, targets: OrvalTarget[]) => {
|
|
2
5
|
'client:orval': string;
|
|
3
6
|
};
|
|
4
7
|
/**
|
|
5
8
|
* Orval resolves paths relative to the config, which lives in the data layer
|
|
6
|
-
* folder next to the generated
|
|
9
|
+
* folder next to the generated code. `mutatorPath` is relative to the config.
|
|
7
10
|
*/
|
|
8
|
-
export declare const orvalConfig: (rootFolder: string, openapiPath: string, withNext: boolean) => string;
|
|
9
|
-
export declare const orvalMutator = "/** Error of the generated
|
|
11
|
+
export declare const orvalConfig: (rootFolder: string, openapiPath: string, withNext: boolean, target?: OrvalTarget, mutatorPath?: string) => string;
|
|
12
|
+
export declare const orvalMutator = "/** Error of the generated requests, with the parsed response body. */\nexport class ApiError<Body = unknown> extends Error {\n constructor(\n public readonly status: number,\n public readonly body: Body\n ) {\n super(`API error ${status}`);\n this.name = 'ApiError';\n }\n}\n\n/** Error type of the generated requests, typed per endpoint by Orval. */\nexport type ErrorType<Body> = ApiError<Body>;\n\n/** Every generated request goes through here: add auth headers, token refresh, logging. */\nexport const customInstance = async <T>(\n url: string,\n init?: RequestInit\n): Promise<T> => {\n const response = await fetch(url, init);\n const text = await response.text();\n const body = text ? JSON.parse(text) : undefined;\n\n if (!response.ok) {\n throw new ApiError(response.status, body);\n }\n\n return body as T;\n};\n";
|
|
10
13
|
export declare const queryProvider = "'use client';\n\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport { type FC, type ReactNode, useState } from 'react';\n\nexport const QueryProvider: FC<{ children: ReactNode }> = ({ children }) => {\n // One client per browser session; a module-level client would be shared between requests on the server\n const [queryClient] = useState(() => new QueryClient());\n\n return (\n <QueryClientProvider client={queryClient}>\n {children}\n </QueryClientProvider>\n );\n};\n";
|
|
11
14
|
export declare const addOrval: () => Promise<string[]>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The catch-all route serving every endpoint, relative to the project root.
|
|
3
|
+
*/
|
|
4
|
+
export declare const nextRoutePath: (root: string) => string;
|
|
5
|
+
/**
|
|
6
|
+
* Asked only in projects with `next` among their dependencies.
|
|
7
|
+
*/
|
|
8
|
+
export declare const askNextAdapter: () => Promise<boolean>;
|
|
9
|
+
/**
|
|
10
|
+
* The Shared Kernel endpoint generator and, with the Next adapter, the
|
|
11
|
+
* catch-all route. Existing files are kept: the generator is edited by
|
|
12
|
+
* hand.
|
|
13
|
+
*/
|
|
14
|
+
export declare const scaffoldRestEndpointGeneratorFiles: ({ withNextAdapter }: {
|
|
15
|
+
withNextAdapter: boolean;
|
|
16
|
+
}) => string[];
|
|
17
|
+
export declare const addRestEndpointGenerator: () => Promise<string[]>;
|
|
18
|
+
export declare const restEndpointGeneratorApplied: () => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/lint.cjs
CHANGED
|
@@ -223,7 +223,7 @@ class ProjectRoot {
|
|
|
223
223
|
}
|
|
224
224
|
const lintChecks = [
|
|
225
225
|
'context-isolation',
|
|
226
|
-
'shared-
|
|
226
|
+
'shared-kernel',
|
|
227
227
|
'layers',
|
|
228
228
|
'dependencies',
|
|
229
229
|
'react',
|
|
@@ -624,7 +624,7 @@ const isOwnContract = (file, target)=>baseName(file).endsWith(`-${baseName(targe
|
|
|
624
624
|
const importViolations = (projectRoot, rootFolder, rules)=>{
|
|
625
625
|
const root = external_node_path_default().resolve(projectRoot, rootFolder);
|
|
626
626
|
const contextsFolder = external_node_path_default().join(root, 'bounded-contexts');
|
|
627
|
-
const sharedFolder = external_node_path_default().join(root, 'shared');
|
|
627
|
+
const sharedFolder = external_node_path_default().join(root, 'shared-kernel');
|
|
628
628
|
const reactFolder = external_node_path_default().join(root, 'presentation', 'react');
|
|
629
629
|
const uiKitFolder = external_node_path_default().join(reactFolder, 'ui-kit');
|
|
630
630
|
const widgetsFolder = external_node_path_default().join(reactFolder, 'widgets');
|
|
@@ -643,7 +643,7 @@ const importViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
643
643
|
}
|
|
644
644
|
const inShared = inside(sharedFolder, file);
|
|
645
645
|
return inShared && {
|
|
646
|
-
owner: 'shared',
|
|
646
|
+
owner: 'shared-kernel',
|
|
647
647
|
segments: inShared
|
|
648
648
|
};
|
|
649
649
|
};
|
|
@@ -684,8 +684,8 @@ const importViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
684
684
|
if (ownContext) {
|
|
685
685
|
if (targetContext && targetContext !== ownContext) report('context-isolation', `[${ownContext}] imports another context:`, imported);
|
|
686
686
|
} else if (inside(sharedFolder, file)) {
|
|
687
|
-
const allowed = !to || 'shared' === to.owner || 'domain' === to.segments[0] && 'errors' === to.segments[1] || file === inMemoryDbFile && isDomainModel(to.segments, target);
|
|
688
|
-
if (!allowed) report('shared-
|
|
687
|
+
const allowed = !to || 'shared-kernel' === to.owner || 'domain' === to.segments[0] && 'errors' === to.segments[1] || file === inMemoryDbFile && isDomainModel(to.segments, target);
|
|
688
|
+
if (!allowed) report('shared-kernel', '[shared-kernel] imports a bounded context outside its domain/errors (and domain models for the in-memory DB):', imported);
|
|
689
689
|
} else if (inside(uiKitFolder, file) || inside(hooksFolder, file)) {
|
|
690
690
|
const [area] = inside(reactFolder, target) ?? [];
|
|
691
691
|
const forbidden = inside(uiKitFolder, file) ? [
|
|
@@ -717,12 +717,12 @@ const importViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
717
717
|
};
|
|
718
718
|
const wiringViolations = (projectRoot, rootFolder, rules)=>{
|
|
719
719
|
const root = external_node_path_default().resolve(projectRoot, rootFolder);
|
|
720
|
-
const sharedFolder = external_node_path_default().join(root, 'shared');
|
|
720
|
+
const sharedFolder = external_node_path_default().join(root, 'shared-kernel');
|
|
721
721
|
const contextsFolder = external_node_path_default().join(root, 'bounded-contexts');
|
|
722
722
|
const sharedModules = findWiredModules(sharedFolder);
|
|
723
723
|
const owners = [
|
|
724
724
|
{
|
|
725
|
-
name: 'shared',
|
|
725
|
+
name: 'shared-kernel',
|
|
726
726
|
modules: sharedModules
|
|
727
727
|
},
|
|
728
728
|
...external_node_fs_default().existsSync(contextsFolder) ? external_node_fs_default().readdirSync(contextsFolder, {
|
|
@@ -771,7 +771,7 @@ const wiringViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
771
771
|
const clockViolations = (projectRoot, rootFolder)=>{
|
|
772
772
|
const root = external_node_path_default().resolve(projectRoot, rootFolder);
|
|
773
773
|
const folders = [
|
|
774
|
-
external_node_path_default().join(root, 'shared'),
|
|
774
|
+
external_node_path_default().join(root, 'shared-kernel'),
|
|
775
775
|
...external_node_fs_default().existsSync(external_node_path_default().join(root, 'bounded-contexts')) ? external_node_fs_default().readdirSync(external_node_path_default().join(root, 'bounded-contexts')).map((name)=>external_node_path_default().join(root, 'bounded-contexts', name)) : []
|
|
776
776
|
].flatMap((folder)=>[
|
|
777
777
|
external_node_path_default().join(folder, 'domain'),
|
package/dist/lint.js
CHANGED
|
@@ -72,7 +72,7 @@ const isOwnContract = (file, target)=>baseName(file).endsWith(`-${baseName(targe
|
|
|
72
72
|
const importViolations = (projectRoot, rootFolder, rules)=>{
|
|
73
73
|
const root = node_path.resolve(projectRoot, rootFolder);
|
|
74
74
|
const contextsFolder = node_path.join(root, 'bounded-contexts');
|
|
75
|
-
const sharedFolder = node_path.join(root, 'shared');
|
|
75
|
+
const sharedFolder = node_path.join(root, 'shared-kernel');
|
|
76
76
|
const reactFolder = node_path.join(root, 'presentation', 'react');
|
|
77
77
|
const uiKitFolder = node_path.join(reactFolder, 'ui-kit');
|
|
78
78
|
const widgetsFolder = node_path.join(reactFolder, 'widgets');
|
|
@@ -91,7 +91,7 @@ const importViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
91
91
|
}
|
|
92
92
|
const inShared = inside(sharedFolder, file);
|
|
93
93
|
return inShared && {
|
|
94
|
-
owner: 'shared',
|
|
94
|
+
owner: 'shared-kernel',
|
|
95
95
|
segments: inShared
|
|
96
96
|
};
|
|
97
97
|
};
|
|
@@ -132,8 +132,8 @@ const importViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
132
132
|
if (ownContext) {
|
|
133
133
|
if (targetContext && targetContext !== ownContext) report('context-isolation', `[${ownContext}] imports another context:`, imported);
|
|
134
134
|
} else if (inside(sharedFolder, file)) {
|
|
135
|
-
const allowed = !to || 'shared' === to.owner || 'domain' === to.segments[0] && 'errors' === to.segments[1] || file === inMemoryDbFile && isDomainModel(to.segments, target);
|
|
136
|
-
if (!allowed) report('shared-
|
|
135
|
+
const allowed = !to || 'shared-kernel' === to.owner || 'domain' === to.segments[0] && 'errors' === to.segments[1] || file === inMemoryDbFile && isDomainModel(to.segments, target);
|
|
136
|
+
if (!allowed) report('shared-kernel', '[shared-kernel] imports a bounded context outside its domain/errors (and domain models for the in-memory DB):', imported);
|
|
137
137
|
} else if (inside(uiKitFolder, file) || inside(hooksFolder, file)) {
|
|
138
138
|
const [area] = inside(reactFolder, target) ?? [];
|
|
139
139
|
const forbidden = inside(uiKitFolder, file) ? [
|
|
@@ -165,12 +165,12 @@ const importViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
165
165
|
};
|
|
166
166
|
const wiringViolations = (projectRoot, rootFolder, rules)=>{
|
|
167
167
|
const root = node_path.resolve(projectRoot, rootFolder);
|
|
168
|
-
const sharedFolder = node_path.join(root, 'shared');
|
|
168
|
+
const sharedFolder = node_path.join(root, 'shared-kernel');
|
|
169
169
|
const contextsFolder = node_path.join(root, 'bounded-contexts');
|
|
170
170
|
const sharedModules = findWiredModules(sharedFolder);
|
|
171
171
|
const owners = [
|
|
172
172
|
{
|
|
173
|
-
name: 'shared',
|
|
173
|
+
name: 'shared-kernel',
|
|
174
174
|
modules: sharedModules
|
|
175
175
|
},
|
|
176
176
|
...node_fs.existsSync(contextsFolder) ? node_fs.readdirSync(contextsFolder, {
|
|
@@ -219,7 +219,7 @@ const wiringViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
219
219
|
const clockViolations = (projectRoot, rootFolder)=>{
|
|
220
220
|
const root = node_path.resolve(projectRoot, rootFolder);
|
|
221
221
|
const folders = [
|
|
222
|
-
node_path.join(root, 'shared'),
|
|
222
|
+
node_path.join(root, 'shared-kernel'),
|
|
223
223
|
...node_fs.existsSync(node_path.join(root, 'bounded-contexts')) ? node_fs.readdirSync(node_path.join(root, 'bounded-contexts')).map((name)=>node_path.join(root, 'bounded-contexts', name)) : []
|
|
224
224
|
].flatMap((folder)=>[
|
|
225
225
|
node_path.join(folder, 'domain'),
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Collects the packages of all install commands into one command for
|
|
3
|
+
* dependencies and one for dev dependencies. A package wanted both ways
|
|
4
|
+
* is installed as a dependency. Other commands follow, since they may
|
|
5
|
+
* need the installed packages.
|
|
6
|
+
*/
|
|
7
|
+
export declare const mergeInstallCommands: (commands: string[]) => string[];
|
|
8
|
+
/**
|
|
9
|
+
* Prints the steps left after a use case: one installation command to
|
|
10
|
+
* copy, then additional information.
|
|
4
11
|
*/
|
|
5
12
|
export declare const printNextSteps: (nextSteps: string[]) => void;
|