@zukhruf/nx 0.8.30 → 0.8.32
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 +375 -19
- package/dist/generators/add-keys.d.ts +7 -0
- package/dist/generators/add-keys.d.ts.map +1 -0
- package/dist/generators/add-keys.js +14 -0
- package/dist/generators/add-keys.js.map +1 -0
- package/dist/generators/add-lines.d.ts +8 -0
- package/dist/generators/add-lines.d.ts.map +1 -0
- package/dist/generators/add-lines.js +21 -0
- package/dist/generators/add-lines.js.map +1 -0
- package/dist/generators/app-directory.d.ts +17 -0
- package/dist/generators/app-directory.d.ts.map +1 -0
- package/dist/generators/app-directory.js +34 -0
- package/dist/generators/app-directory.js.map +1 -0
- package/dist/generators/dokploy/files.d.ts +23 -0
- package/dist/generators/dokploy/files.d.ts.map +1 -0
- package/dist/generators/dokploy/files.js +733 -0
- package/dist/generators/dokploy/files.js.map +1 -0
- package/dist/generators/dokploy/generator.d.ts +75 -0
- package/dist/generators/dokploy/generator.d.ts.map +1 -0
- package/dist/generators/dokploy/generator.js +146 -0
- package/dist/generators/dokploy/generator.js.map +1 -0
- package/dist/generators/dokploy/providers.d.ts +15 -0
- package/dist/generators/dokploy/providers.d.ts.map +1 -0
- package/dist/generators/dokploy/providers.js +114 -0
- package/dist/generators/dokploy/providers.js.map +1 -0
- package/dist/generators/init/files.d.ts.map +1 -1
- package/dist/generators/init/files.js +11 -5
- package/dist/generators/init/files.js.map +1 -1
- package/dist/generators/init/generator.d.ts.map +1 -1
- package/dist/generators/init/generator.js +1 -16
- package/dist/generators/init/generator.js.map +1 -1
- package/dist/generators/init/nx-json.d.ts +16 -3
- package/dist/generators/init/nx-json.d.ts.map +1 -1
- package/dist/generators/init/nx-json.js +20 -5
- package/dist/generators/init/nx-json.js.map +1 -1
- package/dist/generators/init/root-package-json.d.ts +6 -0
- package/dist/generators/init/root-package-json.d.ts.map +1 -1
- package/dist/generators/init/root-package-json.js +15 -12
- package/dist/generators/init/root-package-json.js.map +1 -1
- package/dist/generators/node-app/files.d.ts +43 -0
- package/dist/generators/node-app/files.d.ts.map +1 -0
- package/dist/generators/node-app/files.js +522 -0
- package/dist/generators/node-app/files.js.map +1 -0
- package/dist/generators/node-app/generator.d.ts +17 -0
- package/dist/generators/node-app/generator.d.ts.map +1 -0
- package/dist/generators/node-app/generator.js +322 -0
- package/dist/generators/node-app/generator.js.map +1 -0
- package/dist/generators/nx-plugin.d.ts +16 -0
- package/dist/generators/nx-plugin.d.ts.map +1 -0
- package/dist/generators/nx-plugin.js +27 -0
- package/dist/generators/nx-plugin.js.map +1 -0
- package/dist/generators/pair/files.d.ts +4 -0
- package/dist/generators/pair/files.d.ts.map +1 -0
- package/dist/generators/pair/files.js +73 -0
- package/dist/generators/pair/files.js.map +1 -0
- package/dist/generators/pair/generator.d.ts +19 -0
- package/dist/generators/pair/generator.d.ts.map +1 -0
- package/dist/generators/pair/generator.js +70 -0
- package/dist/generators/pair/generator.js.map +1 -0
- package/dist/generators/prisma/files.d.ts +20 -0
- package/dist/generators/prisma/files.d.ts.map +1 -0
- package/dist/generators/prisma/files.js +183 -0
- package/dist/generators/prisma/files.js.map +1 -0
- package/dist/generators/prisma/generator.d.ts +17 -0
- package/dist/generators/prisma/generator.d.ts.map +1 -0
- package/dist/generators/prisma/generator.js +258 -0
- package/dist/generators/prisma/generator.js.map +1 -0
- package/dist/generators/react-app/files.d.ts +7 -0
- package/dist/generators/react-app/files.d.ts.map +1 -0
- package/dist/generators/react-app/files.js +188 -0
- package/dist/generators/react-app/files.js.map +1 -0
- package/dist/generators/react-app/generator.d.ts +12 -0
- package/dist/generators/react-app/generator.d.ts.map +1 -0
- package/dist/generators/react-app/generator.js +243 -0
- package/dist/generators/react-app/generator.js.map +1 -0
- package/dist/generators/react.d.ts +29 -0
- package/dist/generators/react.d.ts.map +1 -0
- package/dist/generators/react.js +64 -0
- package/dist/generators/react.js.map +1 -0
- package/dist/generators/root-dependencies.d.ts +30 -0
- package/dist/generators/root-dependencies.d.ts.map +1 -0
- package/dist/generators/root-dependencies.js +63 -0
- package/dist/generators/root-dependencies.js.map +1 -0
- package/dist/generators/ui-package/files.d.ts +39 -0
- package/dist/generators/ui-package/files.d.ts.map +1 -0
- package/dist/generators/ui-package/files.js +163 -0
- package/dist/generators/ui-package/files.js.map +1 -0
- package/dist/generators/ui-package/generator.d.ts +14 -0
- package/dist/generators/ui-package/generator.d.ts.map +1 -0
- package/dist/generators/ui-package/generator.js +116 -0
- package/dist/generators/ui-package/generator.js.map +1 -0
- package/dist/generators/versions.d.ts +50 -1
- package/dist/generators/versions.d.ts.map +1 -1
- package/dist/generators/versions.js +64 -1
- package/dist/generators/versions.js.map +1 -1
- package/generators.json +30 -0
- package/package.json +24 -5
- package/src/generators/dokploy/schema.json +48 -0
- package/src/generators/node-app/schema.json +22 -0
- package/src/generators/pair/schema.json +18 -0
- package/src/generators/prisma/schema.json +21 -0
- package/src/generators/react-app/schema.json +17 -0
- package/src/generators/ui-package/schema.json +22 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type GeneratorCallback, type Tree } from '@nx/devkit';
|
|
2
|
+
export interface NodeAppOptions {
|
|
3
|
+
/** The project root, for example `apps/backend`. */
|
|
4
|
+
directory: string;
|
|
5
|
+
/** The port of the server in development, in `.env.example`, portless and `EXPOSE`. */
|
|
6
|
+
port?: number;
|
|
7
|
+
}
|
|
8
|
+
export declare const createRequireBanner = "import { createRequire as nodeCreateRequire } from 'node:module'; const require = nodeCreateRequire(import.meta.url);";
|
|
9
|
+
/**
|
|
10
|
+
* A Hono backend on @hono/node-server: evlog, terminus, a zod env, one ESM
|
|
11
|
+
* esbuild bundle, a Dockerfile whose image reports its commit at /api/healthz,
|
|
12
|
+
* and a generated sdk-it client. It runs `init` first.
|
|
13
|
+
*/
|
|
14
|
+
export default function nodeAppGenerator(tree: Tree, options: NodeAppOptions): Promise<GeneratorCallback>;
|
|
15
|
+
/** The image tag of a project name, as @nx/node sanitizes it: `@acme/backend` gives `acme-backend`. */
|
|
16
|
+
export declare function imageTagFor(projectName: string): string;
|
|
17
|
+
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generators/node-app/generator.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,iBAAiB,EAEtB,KAAK,IAAI,EAMV,MAAM,YAAY,CAAC;AAmCpB,MAAM,WAAW,cAAc;IAC7B,oDAAoD;IACpD,SAAS,EAAE,MAAM,CAAC;IAClB,uFAAuF;IACvF,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAYD,eAAO,MAAM,mBAAmB,0HACyF,CAAC;AAO1H;;;;GAIG;AACH,wBAA8B,gBAAgB,CAC5C,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,iBAAiB,CAAC,CA+F5B;AA8CD,uGAAuG;AACvG,wBAAgB,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAOvD"}
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { formatFiles, installPackagesTask, runTasksInSerial, updateJson, writeJson, } from '@nx/devkit';
|
|
2
|
+
import { addLines } from "../add-lines.js";
|
|
3
|
+
import { appDirectory, projectNameOf } from "../app-directory.js";
|
|
4
|
+
import initGenerator from "../init/generator.js";
|
|
5
|
+
import { mergeGeneratorDefaults, unique, updateTargetDefault, } from "../init/nx-json.js";
|
|
6
|
+
import { nxPlugin } from "../nx-plugin.js";
|
|
7
|
+
import { fseventsScript, rootDependencyNames, settleRootDependencies, } from "../root-dependencies.js";
|
|
8
|
+
import { appPackageVersions as versions } from "../versions.js";
|
|
9
|
+
import { workspaceScope } from "../workspace-scope.js";
|
|
10
|
+
import { appTestTs, appTs, clientManifest, clientTsconfig, dockerfile, dockerignore, envExample, envTs, eslintConfig, healthzRouteTs, loggingTs, sdkItConfig, serverTs, startupTs, } from "./files.js";
|
|
11
|
+
export const createRequireBanner = "import { createRequire as nodeCreateRequire } from 'node:module'; const require = nodeCreateRequire(import.meta.url);";
|
|
12
|
+
const tsSolutionTsconfigInput = {
|
|
13
|
+
json: '{workspaceRoot}/tsconfig.json',
|
|
14
|
+
fields: ['extends', 'files', 'include'],
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* A Hono backend on @hono/node-server: evlog, terminus, a zod env, one ESM
|
|
18
|
+
* esbuild bundle, a Dockerfile whose image reports its commit at /api/healthz,
|
|
19
|
+
* and a generated sdk-it client. It runs `init` first.
|
|
20
|
+
*/
|
|
21
|
+
export default async function nodeAppGenerator(tree, options) {
|
|
22
|
+
const initTask = await initGenerator(tree);
|
|
23
|
+
const scope = workspaceScope(tree);
|
|
24
|
+
const { projectRoot, name, rootOffset } = appDirectory(options.directory);
|
|
25
|
+
const port = options.port ?? 3000;
|
|
26
|
+
const before = rootDependencyNames(tree);
|
|
27
|
+
const { applicationGenerator } = nxPlugin('@nx/node');
|
|
28
|
+
// @nx/node adds a VS Code launch configuration; the one that was there stays.
|
|
29
|
+
const launchJson = tree.read('.vscode/launch.json');
|
|
30
|
+
const appTask = await applicationGenerator(tree, {
|
|
31
|
+
directory: projectRoot,
|
|
32
|
+
framework: 'none',
|
|
33
|
+
bundler: 'esbuild',
|
|
34
|
+
linter: 'eslint',
|
|
35
|
+
unitTestRunner: 'none',
|
|
36
|
+
e2eTestRunner: 'none',
|
|
37
|
+
docker: false,
|
|
38
|
+
useProjectJson: false,
|
|
39
|
+
addPlugin: true,
|
|
40
|
+
port,
|
|
41
|
+
skipFormat: true,
|
|
42
|
+
});
|
|
43
|
+
if (launchJson === null) {
|
|
44
|
+
tree.delete('.vscode/launch.json');
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
tree.write('.vscode/launch.json', launchJson);
|
|
48
|
+
}
|
|
49
|
+
const projectName = projectNameOf(tree, projectRoot);
|
|
50
|
+
tree.delete(`${projectRoot}/src/main.ts`);
|
|
51
|
+
tree.delete(`${projectRoot}/src/assets/.gitkeep`);
|
|
52
|
+
writeTsconfigs(tree, projectRoot, rootOffset);
|
|
53
|
+
writeProjectPackageJson(tree, {
|
|
54
|
+
projectRoot,
|
|
55
|
+
name,
|
|
56
|
+
projectName,
|
|
57
|
+
port,
|
|
58
|
+
scope,
|
|
59
|
+
});
|
|
60
|
+
tree.write(`${projectRoot}/eslint.config.mjs`, eslintConfig(projectRoot, rootOffset));
|
|
61
|
+
tree.write(`${projectRoot}/src/app.ts`, appTs);
|
|
62
|
+
tree.write(`${projectRoot}/src/app.test.ts`, appTestTs);
|
|
63
|
+
tree.write(`${projectRoot}/src/env.ts`, envTs(port));
|
|
64
|
+
tree.write(`${projectRoot}/src/logging.ts`, loggingTs(name));
|
|
65
|
+
tree.write(`${projectRoot}/src/routes/healthz.route.ts`, healthzRouteTs);
|
|
66
|
+
tree.write(`${projectRoot}/src/server.ts`, serverTs);
|
|
67
|
+
tree.write(`${projectRoot}/src/startup.ts`, startupTs);
|
|
68
|
+
// .env.example is the generator's; .env is the developer's copy.
|
|
69
|
+
tree.write(`${projectRoot}/.env.example`, envExample(port));
|
|
70
|
+
if (!tree.exists(`${projectRoot}/.env`)) {
|
|
71
|
+
tree.write(`${projectRoot}/.env`, envExample(port));
|
|
72
|
+
}
|
|
73
|
+
wireSdk(tree, { projectRoot, name, projectName, rootOffset, scope });
|
|
74
|
+
tree.write(`${projectRoot}/Dockerfile`, dockerfile({ projectRoot, projectName, port }));
|
|
75
|
+
if (!tree.exists('.dockerignore')) {
|
|
76
|
+
tree.write('.dockerignore', dockerignore);
|
|
77
|
+
}
|
|
78
|
+
mergeNodeNxJson(tree);
|
|
79
|
+
settleRootDependencies(tree, before, {
|
|
80
|
+
devDependencies: {
|
|
81
|
+
'@sdk-it/cli': versions['@sdk-it/cli'],
|
|
82
|
+
'@types/node': versions['@types/node'],
|
|
83
|
+
esbuild: versions.esbuild,
|
|
84
|
+
tslib: versions.tslib,
|
|
85
|
+
},
|
|
86
|
+
// @nx/js adds the swc toolchain, and nothing here runs it: esbuild
|
|
87
|
+
// bundles and typescript-eslint parses.
|
|
88
|
+
residue: ['@swc/cli', '@swc/core', '@swc/helpers'],
|
|
89
|
+
// esbuild's postinstall puts the native binary in place of its JS
|
|
90
|
+
// wrapper. @nx/node brings @parcel/watcher through @nx/jest, and it
|
|
91
|
+
// builds from source only when asked, so its script does not run.
|
|
92
|
+
allowScripts: {
|
|
93
|
+
esbuild: true,
|
|
94
|
+
'@parcel/watcher': false,
|
|
95
|
+
...fseventsScript,
|
|
96
|
+
},
|
|
97
|
+
// sdk-it peers on typescript ^6.0.3, and the TypeScript 6 API alias of
|
|
98
|
+
// the root is 6.0.2, the last @typescript/typescript6. Each edge takes
|
|
99
|
+
// the root typescript.
|
|
100
|
+
overrides: {
|
|
101
|
+
'@sdk-it/cli': { typescript: '$typescript' },
|
|
102
|
+
'@sdk-it/hono': { typescript: '$typescript' },
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
await formatFiles(tree);
|
|
106
|
+
return runTasksInSerial(initTask, appTask, () => installPackagesTask(tree));
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* @nx/node writes the app tsconfigs with `module: nodenext` and dist as the
|
|
110
|
+
* outDir. The app keeps the workspace base (bundler resolution) and keeps dist
|
|
111
|
+
* free of type-check output: typecheck writes to out-tsc.
|
|
112
|
+
*/
|
|
113
|
+
function writeTsconfigs(tree, projectRoot, rootOffset) {
|
|
114
|
+
const base = `${rootOffset}tsconfig.base.json`;
|
|
115
|
+
writeJson(tree, `${projectRoot}/tsconfig.json`, {
|
|
116
|
+
extends: base,
|
|
117
|
+
files: [],
|
|
118
|
+
include: [],
|
|
119
|
+
references: [
|
|
120
|
+
{ path: './tsconfig.app.json' },
|
|
121
|
+
{ path: './tsconfig.test.json' },
|
|
122
|
+
],
|
|
123
|
+
});
|
|
124
|
+
writeJson(tree, `${projectRoot}/tsconfig.app.json`, {
|
|
125
|
+
extends: base,
|
|
126
|
+
compilerOptions: {
|
|
127
|
+
outDir: 'out-tsc',
|
|
128
|
+
rootDir: 'src',
|
|
129
|
+
tsBuildInfoFile: 'out-tsc/tsconfig.app.tsbuildinfo',
|
|
130
|
+
types: ['node'],
|
|
131
|
+
},
|
|
132
|
+
include: ['src/**/*.ts'],
|
|
133
|
+
exclude: ['src/**/*.test.ts'],
|
|
134
|
+
});
|
|
135
|
+
writeJson(tree, `${projectRoot}/tsconfig.test.json`, {
|
|
136
|
+
extends: base,
|
|
137
|
+
compilerOptions: {
|
|
138
|
+
outDir: 'out-tsc',
|
|
139
|
+
rootDir: 'src',
|
|
140
|
+
tsBuildInfoFile: 'out-tsc/tsconfig.test.tsbuildinfo',
|
|
141
|
+
types: ['node'],
|
|
142
|
+
},
|
|
143
|
+
include: ['src/**/*.test.ts'],
|
|
144
|
+
references: [{ path: './tsconfig.app.json' }],
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/** The image tag of a project name, as @nx/node sanitizes it: `@acme/backend` gives `acme-backend`. */
|
|
148
|
+
export function imageTagFor(projectName) {
|
|
149
|
+
return projectName
|
|
150
|
+
.toLowerCase()
|
|
151
|
+
.replace(/[@/]/g, '-')
|
|
152
|
+
.replace(/[^a-z0-9._-]/g, '-')
|
|
153
|
+
.replace(/-+/g, '-')
|
|
154
|
+
.replace(/^-|-$/g, '');
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* The app manifest is its deploy manifest: `prune-lockfile` copies its
|
|
158
|
+
* dependencies into dist/package.json, and @nx/dependency-checks keeps them
|
|
159
|
+
* right, because the bundle leaves each npm package external.
|
|
160
|
+
*/
|
|
161
|
+
function writeProjectPackageJson(tree, app) {
|
|
162
|
+
const imageTag = imageTagFor(app.projectName);
|
|
163
|
+
updateJson(tree, `${app.projectRoot}/package.json`, (packageJson) => {
|
|
164
|
+
const targets = { ...packageJson.nx?.targets };
|
|
165
|
+
// Workspace libraries are bundled, so nothing is copied at deploy time;
|
|
166
|
+
// prune-lockfile alone writes the runtime manifest and lockfile.
|
|
167
|
+
delete targets['copy-workspace-modules'];
|
|
168
|
+
delete targets['prune'];
|
|
169
|
+
packageJson.type = 'module';
|
|
170
|
+
packageJson.scripts = {};
|
|
171
|
+
packageJson.dependencies = {
|
|
172
|
+
...packageJson.dependencies,
|
|
173
|
+
'@godaddy/terminus': versions['@godaddy/terminus'],
|
|
174
|
+
'@hono/node-server': versions['@hono/node-server'],
|
|
175
|
+
'@sdk-it/hono': versions['@sdk-it/hono'],
|
|
176
|
+
evlog: versions.evlog,
|
|
177
|
+
hono: versions.hono,
|
|
178
|
+
zod: versions.zod,
|
|
179
|
+
};
|
|
180
|
+
packageJson.nx = {
|
|
181
|
+
...packageJson.nx,
|
|
182
|
+
// @nx/node writes no projectType into package.json. @zukhruf/eslint
|
|
183
|
+
// reads it: an application bundles, so its manifest declares the npm
|
|
184
|
+
// packages of each workspace package it imports, not the package.
|
|
185
|
+
projectType: 'application',
|
|
186
|
+
targets: {
|
|
187
|
+
...targets,
|
|
188
|
+
build: buildTarget(app.projectRoot),
|
|
189
|
+
// @nx/js/tsx infers the command from the header of src/server.ts.
|
|
190
|
+
// @nx/node writes serve as continuous, and a project value wins
|
|
191
|
+
// over the discrete target default. The app turns on its
|
|
192
|
+
// development log drain only when NODE_ENV is development.
|
|
193
|
+
serve: {
|
|
194
|
+
dependsOn: ['^build'],
|
|
195
|
+
options: { env: { NODE_ENV: 'development' } },
|
|
196
|
+
},
|
|
197
|
+
portless: {
|
|
198
|
+
command: `portless --name ${app.name}.${app.scope} --app-port ${app.port} -- nx run ${app.projectName}:serve --output-style=stream-without-prefixes`,
|
|
199
|
+
},
|
|
200
|
+
'docker:build': {
|
|
201
|
+
command: `docker build --file ${app.projectRoot}/Dockerfile --build-arg BUILD_SHA=$(git rev-parse HEAD) --tag ${imageTag} .`,
|
|
202
|
+
options: { cwd: '{workspaceRoot}' },
|
|
203
|
+
},
|
|
204
|
+
'docker:run': {
|
|
205
|
+
command: `docker run --rm --publish ${app.port}:${app.port} ${imageTag}`,
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
return packageJson;
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* One ESM bundle in place of the CommonJS build of @nx/node. With `thirdParty`
|
|
214
|
+
* unset, @nx/esbuild leaves each npm package external, also one that a bundled
|
|
215
|
+
* workspace library imports, and inlines the workspace libraries.
|
|
216
|
+
* `declaration: false` stops the executor from taking `declaration` from the
|
|
217
|
+
* `composite` of the base tsconfig. The development configuration skips the
|
|
218
|
+
* type check; typecheck and the production build keep it. The banner gives
|
|
219
|
+
* the ESM bundle a `require` for an external CommonJS package.
|
|
220
|
+
*/
|
|
221
|
+
function buildTarget(projectRoot) {
|
|
222
|
+
return {
|
|
223
|
+
executor: '@nx/esbuild:esbuild',
|
|
224
|
+
outputs: ['{options.outputPath}'],
|
|
225
|
+
defaultConfiguration: 'production',
|
|
226
|
+
options: {
|
|
227
|
+
platform: 'node',
|
|
228
|
+
target: 'esnext',
|
|
229
|
+
bundle: true,
|
|
230
|
+
format: ['esm'],
|
|
231
|
+
main: `${projectRoot}/src/server.ts`,
|
|
232
|
+
tsConfig: `${projectRoot}/tsconfig.app.json`,
|
|
233
|
+
outputPath: `${projectRoot}/dist`,
|
|
234
|
+
assets: [],
|
|
235
|
+
declaration: false,
|
|
236
|
+
sourcemap: true,
|
|
237
|
+
esbuildOptions: { banner: { js: createRequireBanner } },
|
|
238
|
+
},
|
|
239
|
+
configurations: {
|
|
240
|
+
development: { skipTypeCheck: true },
|
|
241
|
+
production: {},
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
function wireSdk(tree, options) {
|
|
246
|
+
const { projectRoot, name, projectName, rootOffset, scope } = options;
|
|
247
|
+
const packageName = `@${scope}/${name}-client`;
|
|
248
|
+
tree.write(`${projectRoot}/sdk-it.config.ts`, sdkItConfig(projectName, packageName));
|
|
249
|
+
const stubPath = `${projectRoot}/.sdk-it/package.json`;
|
|
250
|
+
if (!tree.exists(stubPath)) {
|
|
251
|
+
tree.write(stubPath, clientManifest(packageName, projectName));
|
|
252
|
+
}
|
|
253
|
+
const tsconfigPath = `${projectRoot}/.sdk-it/tsconfig.json`;
|
|
254
|
+
if (!tree.exists(tsconfigPath)) {
|
|
255
|
+
tree.write(tsconfigPath, clientTsconfig(rootOffset));
|
|
256
|
+
}
|
|
257
|
+
// A path, not a glob: npm matches workspace globs without `dot`, so
|
|
258
|
+
// `apps/*/.sdk-it` never links the package.
|
|
259
|
+
updateJson(tree, 'package.json', (packageJson) => {
|
|
260
|
+
packageJson.workspaces = unique([
|
|
261
|
+
...(packageJson.workspaces ?? []),
|
|
262
|
+
`${projectRoot}/.sdk-it`,
|
|
263
|
+
]);
|
|
264
|
+
return packageJson;
|
|
265
|
+
});
|
|
266
|
+
addLines(tree, '.gitignore', '**/.sdk-it/*\n!**/.sdk-it/package.json\n!**/.sdk-it/tsconfig.json\n');
|
|
267
|
+
addLines(tree, '.prettierignore', '.sdk-it\n');
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* The nx.json keys of a backend. An executor-keyed default wins over a
|
|
271
|
+
* name-keyed one (Nx takes the first key that matches and never merges two),
|
|
272
|
+
* so the esbuild entry keeps the Tailwind sync generator of the `build`
|
|
273
|
+
* default away from a backend build. `^sdk` builds a generated client before
|
|
274
|
+
* its consumers build, serve, typecheck or test; it does nothing for a
|
|
275
|
+
* project with no such dependency, and `...` keeps the `^build` that
|
|
276
|
+
* @zukhruf/nx/test infers for test.
|
|
277
|
+
*/
|
|
278
|
+
function mergeNodeNxJson(tree) {
|
|
279
|
+
updateJson(tree, 'nx.json', (nxJson) => {
|
|
280
|
+
updateTargetDefault(nxJson, '@nx/esbuild:esbuild', (entry) => ({
|
|
281
|
+
...entry,
|
|
282
|
+
cache: true,
|
|
283
|
+
dependsOn: unique([...(entry.dependsOn ?? []), '^build']),
|
|
284
|
+
inputs: unique([
|
|
285
|
+
...(entry.inputs ?? []),
|
|
286
|
+
'production',
|
|
287
|
+
'^production',
|
|
288
|
+
tsSolutionTsconfigInput,
|
|
289
|
+
]),
|
|
290
|
+
}));
|
|
291
|
+
for (const [target, inferred] of [
|
|
292
|
+
['build', []],
|
|
293
|
+
['dev', []],
|
|
294
|
+
['typecheck', []],
|
|
295
|
+
['test', ['...']],
|
|
296
|
+
]) {
|
|
297
|
+
updateTargetDefault(nxJson, target, (entry) => ({
|
|
298
|
+
...entry,
|
|
299
|
+
dependsOn: unique([...inferred, ...(entry.dependsOn ?? []), '^sdk']),
|
|
300
|
+
}));
|
|
301
|
+
}
|
|
302
|
+
// sdk-it.config.ts imports the root CLI. Outside production, its closure
|
|
303
|
+
// stays out of the pruned runtime lockfile of the app.
|
|
304
|
+
nxJson.namedInputs ??= {};
|
|
305
|
+
nxJson.namedInputs['production'] = unique([
|
|
306
|
+
...(nxJson.namedInputs['production'] ?? ['default']),
|
|
307
|
+
'!{projectRoot}/sdk-it.config.{js,ts,mjs,mts}',
|
|
308
|
+
]);
|
|
309
|
+
nxJson.generators = mergeGeneratorDefaults(nxJson.generators, '@nx/node', {
|
|
310
|
+
application: {
|
|
311
|
+
framework: 'none',
|
|
312
|
+
bundler: 'esbuild',
|
|
313
|
+
linter: 'eslint',
|
|
314
|
+
unitTestRunner: 'none',
|
|
315
|
+
e2eTestRunner: 'none',
|
|
316
|
+
docker: false,
|
|
317
|
+
},
|
|
318
|
+
});
|
|
319
|
+
return nxJson;
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../src/generators/node-app/generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,WAAW,EACX,mBAAmB,EACnB,gBAAgB,EAChB,UAAU,EACV,SAAS,GACV,MAAM,YAAY,CAAC;AAEpB,OAAO,EAA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,OAAO,EAAE,EAAE,CAAC;YACb,CAAC,KAAK,EAAE,EAAE,CAAC;YACX,CAAC,WAAW,EAAE,EAAE,CAAC;YACjB,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC;SACT,EAAE,CAAC;YACX,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;gBAC9C,GAAG,KAAK;gBACR,SAAS,EAAE,MAAM,CAAC,CAAC,GAAG,QAAQ,EAAE,GAAG,CAAC,KAAK,CAAC,SAAS,IAAI,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;aACrE,CAAC,CAAC,CAAC;QACN,CAAC;QACD,yEAAyE;QACzE,uDAAuD;QACvD,MAAM,CAAC,WAAW,KAAK,EAAE,CAAC;QAC1B,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,GAAG,MAAM,CAAC;YACxC,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACpD,8CAA8C;SAC/C,CAAC,CAAC;QACH,MAAM,CAAC,UAAU,GAAG,sBAAsB,CAAC,MAAM,CAAC,UAAU,EAAE,UAAU,EAAE;YACxE,WAAW,EAAE;gBACX,SAAS,EAAE,MAAM;gBACjB,OAAO,EAAE,SAAS;gBAClB,MAAM,EAAE,QAAQ;gBAChB,cAAc,EAAE,MAAM;gBACtB,aAAa,EAAE,MAAM;gBACrB,MAAM,EAAE,KAAK;aACd;SACF,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** The entry points of the Nx plugins that the app generators call, by the package that holds each. */
|
|
2
|
+
interface NxPlugins {
|
|
3
|
+
'@nx/node': typeof import('@nx/node');
|
|
4
|
+
'@nx/react': typeof import('@nx/react');
|
|
5
|
+
'@nx/vitest/generators': typeof import('@nx/vitest/generators');
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Loads an Nx plugin that an app generator calls, for example `@nx/node`. It
|
|
9
|
+
* takes the copy that resolves from this package, and else installs the plugin
|
|
10
|
+
* at `nxVersion` into a temporary folder, as an Nx generator does for its own
|
|
11
|
+
* plugins (`ensurePackage` of @nx/devkit). The plugin's own generator adds it
|
|
12
|
+
* to the root package.json.
|
|
13
|
+
*/
|
|
14
|
+
export declare function nxPlugin<Entry extends keyof NxPlugins>(entry: Entry): NxPlugins[Entry];
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=nx-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nx-plugin.d.ts","sourceRoot":"","sources":["../../src/generators/nx-plugin.ts"],"names":[],"mappings":"AAQA,uGAAuG;AACvG,UAAU,SAAS;IACjB,UAAU,EAAE,cAAc,UAAU,CAAC,CAAC;IACtC,WAAW,EAAE,cAAc,WAAW,CAAC,CAAC;IACxC,uBAAuB,EAAE,cAAc,uBAAuB,CAAC,CAAC;CACjE;AAQD;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,KAAK,SAAS,MAAM,SAAS,EACpD,KAAK,EAAE,KAAK,GACX,SAAS,CAAC,KAAK,CAAC,CASlB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { ensurePackage } from '@nx/devkit';
|
|
3
|
+
import { nxVersion } from "./versions.js";
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
5
|
+
function isModuleNotFound(error) {
|
|
6
|
+
return (Error.isError(error) && 'code' in error && error.code === 'MODULE_NOT_FOUND');
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Loads an Nx plugin that an app generator calls, for example `@nx/node`. It
|
|
10
|
+
* takes the copy that resolves from this package, and else installs the plugin
|
|
11
|
+
* at `nxVersion` into a temporary folder, as an Nx generator does for its own
|
|
12
|
+
* plugins (`ensurePackage` of @nx/devkit). The plugin's own generator adds it
|
|
13
|
+
* to the root package.json.
|
|
14
|
+
*/
|
|
15
|
+
export function nxPlugin(entry) {
|
|
16
|
+
try {
|
|
17
|
+
return require(entry);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
if (!isModuleNotFound(error))
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
// ensurePackage adds the temporary folder to the paths that require reads.
|
|
24
|
+
ensurePackage(entry.split('/').slice(0, 2).join('/'), nxVersion);
|
|
25
|
+
return require(entry);
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=nx-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nx-plugin.js","sourceRoot":"","sources":["../../src/generators/nx-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAS/C,SAAS,gBAAgB,CAAC,KAAc;IACtC,OAAO,CACL,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,kBAAkB,CAC7E,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CACtB,KAAY;IAEZ,IAAI,CAAC;QACH,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC;YAAE,MAAM,KAAK,CAAC;IAC5C,CAAC;IACD,2EAA2E;IAC3E,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,SAAS,CAAC,CAAC;IACjE,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../src/generators/pair/files.ts"],"names":[],"mappings":"AAGA,wBAAgB,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAWhD;AAED,0FAA0F;AAC1F,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAwDjD"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// The content of each file that pair writes. Each is a string in a .ts
|
|
2
|
+
// module, so tsc puts it in dist with no copy step (ADR 0009).
|
|
3
|
+
export function apiTs(clientName) {
|
|
4
|
+
return `import { Client } from '${clientName}';
|
|
5
|
+
|
|
6
|
+
// Same-origin in production (the API serves this SPA) and proxied by the vite
|
|
7
|
+
// dev server in development, so the page origin is always right. The client
|
|
8
|
+
// needs an absolute URL (its interceptor calls \`new URL(baseUrl)\`), and the
|
|
9
|
+
// API mounts its routes under /api, which the sdk-it analyzer cannot see.
|
|
10
|
+
export const api = new Client({
|
|
11
|
+
baseUrl: new URL('/api', globalThis.location.origin).toString(),
|
|
12
|
+
});
|
|
13
|
+
`;
|
|
14
|
+
}
|
|
15
|
+
/** `webDist` is the web build relative to the api build, for example `../../web/dist`. */
|
|
16
|
+
export function uiRouteTs(webDist) {
|
|
17
|
+
return `import { readFile } from 'node:fs/promises';
|
|
18
|
+
import { join, relative } from 'node:path';
|
|
19
|
+
|
|
20
|
+
import { serveStatic } from '@hono/node-server/serve-static';
|
|
21
|
+
import type { Hono } from 'hono';
|
|
22
|
+
import { compress } from 'hono/compress';
|
|
23
|
+
import { etag } from 'hono/etag';
|
|
24
|
+
|
|
25
|
+
// Same-origin SPA shell: hashed assets are immutable (served precompressed
|
|
26
|
+
// when the web build emitted .br/.gz), and every other GET returns index.html
|
|
27
|
+
// so the client router owns the URL. A GET under /api/ goes on to the API
|
|
28
|
+
// routes and their notFound.
|
|
29
|
+
export default function (router: Hono): void {
|
|
30
|
+
// The path starts from the folder of the server bundle, because Nx and the
|
|
31
|
+
// runtime image keep both app outputs under the workspace root.
|
|
32
|
+
const webDist = join(
|
|
33
|
+
relative(process.cwd(), import.meta.dirname),
|
|
34
|
+
'${webDist}',
|
|
35
|
+
);
|
|
36
|
+
const indexHtml = join(webDist, 'index.html');
|
|
37
|
+
router.use(
|
|
38
|
+
'/assets/*',
|
|
39
|
+
serveStatic({
|
|
40
|
+
root: webDist,
|
|
41
|
+
precompressed: true,
|
|
42
|
+
onFound: (_path, c) => {
|
|
43
|
+
c.header('Cache-Control', 'public, max-age=31536000, immutable');
|
|
44
|
+
},
|
|
45
|
+
}),
|
|
46
|
+
);
|
|
47
|
+
router.get('*', compress(), etag(), async (c, next) => {
|
|
48
|
+
if (c.req.path.startsWith('/api/')) {
|
|
49
|
+
await next();
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const html = await readFile(indexHtml, 'utf-8').catch(() => undefined);
|
|
53
|
+
if (html === undefined) {
|
|
54
|
+
return c.json(
|
|
55
|
+
{
|
|
56
|
+
error: 'Not Found',
|
|
57
|
+
cause: {
|
|
58
|
+
code: 'ui/build-missing',
|
|
59
|
+
detail:
|
|
60
|
+
process.env.NODE_ENV === 'development'
|
|
61
|
+
? \`Build the web app first (expected \${indexHtml})\`
|
|
62
|
+
: 'The web build is not available',
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
404,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
return c.html(html);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
`;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.js","sourceRoot":"","sources":["../../../src/generators/pair/files.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,+DAA+D;AAE/D,MAAM,UAAU,KAAK,CAAC,UAAkB;IACtC,OAAO,2BAA2B,UAAU;;;;;;;;;CAS7C,CAAC;AACF,CAAC;AAED,0FAA0F;AAC1F,MAAM,UAAU,SAAS,CAAC,OAAe;IACvC,OAAO;;;;;;;;;;;;;;;;;OAiBF,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqCb,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Tree } from '@nx/devkit';
|
|
2
|
+
export interface PairOptions {
|
|
3
|
+
/** The project root of a node-app, for example `apps/backend`. */
|
|
4
|
+
api: string;
|
|
5
|
+
/** The project root of a react-app, for example `apps/web`. */
|
|
6
|
+
web: string;
|
|
7
|
+
}
|
|
8
|
+
/** PORT is the generator's line in .env.example, so it is the one line worth reading. */
|
|
9
|
+
export declare function portOf(tree: Tree, apiRoot: string): number;
|
|
10
|
+
/**
|
|
11
|
+
* Pairs a react-app with a node-app: the web gets the generated client, and
|
|
12
|
+
* the api serves the web build and puts it in its image. The app generators
|
|
13
|
+
* never name each other, so pairing is one explicit step that is safe to run
|
|
14
|
+
* again. The web depends on the api only through the client library: an
|
|
15
|
+
* app-to-app edge would make dependency-checks ask the web for the runtime
|
|
16
|
+
* dependencies of the api, and fail @nx/enforce-module-boundaries.
|
|
17
|
+
*/
|
|
18
|
+
export default function pairGenerator(tree: Tree, options: PairOptions): Promise<void>;
|
|
19
|
+
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generators/pair/generator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,IAAI,EAAqC,MAAM,YAAY,CAAC;AAO1E,MAAM,WAAW,WAAW;IAC1B,kEAAkE;IAClE,GAAG,EAAE,MAAM,CAAC;IACZ,+DAA+D;IAC/D,GAAG,EAAE,MAAM,CAAC;CACb;AAED,yFAAyF;AACzF,wBAAgB,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAI1D;AA8BD;;;;;;;GAOG;AACH,wBAA8B,aAAa,CACzC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC,IAAI,CAAC,CAgDf"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { posix } from 'node:path';
|
|
2
|
+
import { formatFiles, readJson, updateJson } from '@nx/devkit';
|
|
3
|
+
import { appDirectory, projectNameOf } from "../app-directory.js";
|
|
4
|
+
import { dockerfile } from "../node-app/files.js";
|
|
5
|
+
import { appPackageVersions as versions } from "../versions.js";
|
|
6
|
+
import { apiTs, uiRouteTs } from "./files.js";
|
|
7
|
+
/** PORT is the generator's line in .env.example, so it is the one line worth reading. */
|
|
8
|
+
export function portOf(tree, apiRoot) {
|
|
9
|
+
const example = tree.read(`${apiRoot}/.env.example`, 'utf-8') ?? '';
|
|
10
|
+
const match = /^PORT=(\d+)$/m.exec(example);
|
|
11
|
+
return match ? Number(match[1]) : 3000;
|
|
12
|
+
}
|
|
13
|
+
function mountUi(tree, apiRoot, webRoot) {
|
|
14
|
+
const appPath = `${apiRoot}/src/app.ts`;
|
|
15
|
+
const app = tree.read(appPath, 'utf-8');
|
|
16
|
+
if (app === null) {
|
|
17
|
+
throw new Error(`${appPath} does not exist.`);
|
|
18
|
+
}
|
|
19
|
+
const mount = `(await import('./routes/ui.route.ts')).default(app);`;
|
|
20
|
+
if (!app.includes(mount)) {
|
|
21
|
+
const marker = '\napp.notFound((c) =>';
|
|
22
|
+
if (!app.includes(marker)) {
|
|
23
|
+
throw new Error(`${appPath} has no app.notFound registration.`);
|
|
24
|
+
}
|
|
25
|
+
tree.write(appPath, app.replace(marker, `\n// pair fixed the path of the web build; development enters through the Vite proxy.\n${mount}\n${marker}`));
|
|
26
|
+
}
|
|
27
|
+
tree.write(`${apiRoot}/src/routes/ui.route.ts`, uiRouteTs(posix.relative(posix.join(apiRoot, 'dist'), posix.join(webRoot, 'dist'))));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Pairs a react-app with a node-app: the web gets the generated client, and
|
|
31
|
+
* the api serves the web build and puts it in its image. The app generators
|
|
32
|
+
* never name each other, so pairing is one explicit step that is safe to run
|
|
33
|
+
* again. The web depends on the api only through the client library: an
|
|
34
|
+
* app-to-app edge would make dependency-checks ask the web for the runtime
|
|
35
|
+
* dependencies of the api, and fail @nx/enforce-module-boundaries.
|
|
36
|
+
*/
|
|
37
|
+
export default async function pairGenerator(tree, options) {
|
|
38
|
+
const apiRoot = appDirectory(options.api).projectRoot;
|
|
39
|
+
const webRoot = appDirectory(options.web).projectRoot;
|
|
40
|
+
if (!tree.exists(`${apiRoot}/sdk-it.config.ts`)) {
|
|
41
|
+
throw new Error(`${apiRoot} has no sdk-it.config.ts, so it is not a node-app. Run @zukhruf/nx:node-app ${apiRoot} first.`);
|
|
42
|
+
}
|
|
43
|
+
if (!tree.exists(`${webRoot}/vite.config.ts`)) {
|
|
44
|
+
throw new Error(`${webRoot} has no vite.config.ts, so it is not a react-app. Run @zukhruf/nx:react-app ${webRoot} first.`);
|
|
45
|
+
}
|
|
46
|
+
const apiName = projectNameOf(tree, apiRoot);
|
|
47
|
+
const webName = projectNameOf(tree, webRoot);
|
|
48
|
+
const client = readJson(tree, `${apiRoot}/.sdk-it/package.json`);
|
|
49
|
+
updateJson(tree, `${webRoot}/package.json`, (packageJson) => {
|
|
50
|
+
// The web bundles the client, so the runtime dependencies of the client
|
|
51
|
+
// are in the manifest of the web (dependency-checks of a bundled app).
|
|
52
|
+
packageJson.dependencies = {
|
|
53
|
+
...packageJson.dependencies,
|
|
54
|
+
[client.name]: '*',
|
|
55
|
+
'fast-content-type-parse': versions['fast-content-type-parse'],
|
|
56
|
+
zod: versions.zod,
|
|
57
|
+
};
|
|
58
|
+
return packageJson;
|
|
59
|
+
});
|
|
60
|
+
tree.write(`${webRoot}/src/api.ts`, apiTs(client.name));
|
|
61
|
+
mountUi(tree, apiRoot, webRoot);
|
|
62
|
+
tree.write(`${apiRoot}/Dockerfile`, dockerfile({
|
|
63
|
+
projectRoot: apiRoot,
|
|
64
|
+
projectName: apiName,
|
|
65
|
+
port: portOf(tree, apiRoot),
|
|
66
|
+
spa: { projectName: webName, projectRoot: webRoot },
|
|
67
|
+
}));
|
|
68
|
+
await formatFiles(tree);
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../src/generators/pair/generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAElC,OAAO,EAAa,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE1E,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,kBAAkB,IAAI,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAS9C,yFAAyF;AACzF,MAAM,UAAU,MAAM,CAAC,IAAU,EAAE,OAAe;IAChD,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,OAAO,eAAe,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC;IACpE,MAAM,KAAK,GAAG,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5C,OAAO,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACzC,CAAC;AAED,SAAS,OAAO,CAAC,IAAU,EAAE,OAAe,EAAE,OAAe;IAC3D,MAAM,OAAO,GAAG,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W,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const schemaPrisma = "// The models go in models/*.prisma. The generate target writes the client into\n// src/prisma, which is not committed.\ngenerator client {\n provider = \"prisma-client\"\n output = \"src/prisma\"\n importFileExtension = \"ts\"\n}\n\ndatasource db {\n provider = \"postgresql\"\n}\n";
|
|
2
|
+
export declare const prismaConfigTs = "import { defineConfig, env } from 'prisma/config';\n\n// Nx loads the .env of this project into each task, and the migration image\n// gets CONNECTION_STRING from its environment. A URL is read only when it is\n// set, so `prisma generate` runs with none.\nexport default defineConfig({\n schema: '.',\n migrations: { path: 'migrations' },\n datasource: {\n url: process.env.CONNECTION_STRING ? env('CONNECTION_STRING') : undefined,\n shadowDatabaseUrl: process.env.SHADOW_CONNECTION_STRING\n ? env('SHADOW_CONNECTION_STRING')\n : undefined,\n },\n});\n";
|
|
3
|
+
export declare const migrationLockToml = "# Please do not edit this file manually\n# It should be added in your version-control system (i.e. Git)\nprovider = \"postgresql\"\n";
|
|
4
|
+
export declare const indexTs = "import { PrismaPg } from '@prisma/adapter-pg';\n\nimport { PrismaClient } from './prisma/client.ts';\n\n/**\n * A client on the Postgres adapter. It reads no environment and opens no pool\n * at import, so each caller passes its own connection string: the backend its\n * CONNECTION_STRING, and a test the database of @zukhruf/testing/postgres.\n */\nexport function createPrisma(options: {\n connectionString: string;\n}): PrismaClient {\n return new PrismaClient({ adapter: new PrismaPg(options) });\n}\n\nexport * from './prisma/client.ts';\n";
|
|
5
|
+
export declare const testingTs = "import { readFile, readdir } from 'node:fs/promises';\nimport { join, resolve } from 'node:path';\n\nimport pg from 'pg';\n\n// src/ (development) and dist/ (default) each sit one level below the package\n// root that holds migrations/.\nconst migrationsDir = resolve(import.meta.dirname, '..', 'migrations');\n\n/**\n * Builds the schema of the committed migrations in an empty database: it runs\n * each migrations/<name>/migration.sql in order. It keeps no\n * _prisma_migrations record, because a test database is thrown away and never\n * migrated again. The deploy target applies migrations everywhere else.\n */\nexport async function applySchema(connectionString: string): Promise<void> {\n const migrations = (await readdir(migrationsDir, { withFileTypes: true }))\n .filter((entry) => entry.isDirectory())\n .map((entry) => entry.name)\n .toSorted();\n const client = new pg.Client({ connectionString });\n await client.connect();\n try {\n for (const migration of migrations) {\n await client.query(\n await readFile(join(migrationsDir, migration, 'migration.sql'), 'utf8'),\n );\n }\n } finally {\n await client.end();\n }\n}\n";
|
|
6
|
+
/** The test of the db package, or of a backend that imports it. */
|
|
7
|
+
export declare function databaseTestTs(imports: {
|
|
8
|
+
client: string;
|
|
9
|
+
testing: string;
|
|
10
|
+
}): string;
|
|
11
|
+
export declare function eslintConfig(projectRoot: string, rootOffset: string): string;
|
|
12
|
+
export declare const envExample = "# Copy to `.env` (gitignored). Nx loads it into each task of this project, so\n# `nx run <project>:migrate` and `deploy` need no dotenv.\nCONNECTION_STRING=\n# Optional: the shadow database of `prisma migrate dev`.\nSHADOW_CONNECTION_STRING=\n";
|
|
13
|
+
export interface MigrationDockerfileOptions {
|
|
14
|
+
projectRoot: string;
|
|
15
|
+
packageName: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function migrationDockerfile(options: MigrationDockerfileOptions): string;
|
|
18
|
+
/** The lines that a backend's startup.ts gets: the client, connected before the app serves. */
|
|
19
|
+
export declare function startupClientTs(packageName: string): string;
|
|
20
|
+
//# sourceMappingURL=files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../src/generators/prisma/files.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY,2TAWxB,CAAC;AAEF,eAAO,MAAM,cAAc,kkBAe1B,CAAC;AAEF,eAAO,MAAM,iBAAiB,yIAG7B,CAAC;AAEF,eAAO,MAAM,OAAO,wiBAgBnB,CAAC;AAEF,eAAO,MAAM,SAAS,iqCAgCrB,CAAC;AAEF,mEAAmE;AACnE,wBAAgB,cAAc,CAAC,OAAO,EAAE;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB,GAAG,MAAM,CAsBT;AAED,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAyB5E;AAED,eAAO,MAAM,UAAU,wPAKtB,CAAC;AAEF,MAAM,WAAW,0BAA0B;IACzC,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,0BAA0B,GAClC,MAAM,CA4BR;AAED,+FAA+F;AAC/F,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAW3D"}
|