@absterr/nestkit 0.0.0-stage → 0.1.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.
Files changed (106) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +62 -2
  3. package/dist/cli.js +439 -0
  4. package/dist/options.js +98 -0
  5. package/dist/package-managers.js +23 -0
  6. package/dist/scaffold.js +158 -0
  7. package/dist/settings.js +52 -0
  8. package/dist/versions.js +33 -0
  9. package/package.json +47 -4
  10. package/templates/agent-files/11/AGENTS.md +24 -0
  11. package/templates/agent-files/12/AGENTS.md +39 -0
  12. package/templates/agent-files/common/CLAUDE.md +1 -0
  13. package/templates/base/README.md +70 -0
  14. package/templates/base/gitattributes +1 -0
  15. package/templates/base/gitignore +8 -0
  16. package/templates/base/nest-cli.json +11 -0
  17. package/templates/base/package.json +32 -0
  18. package/templates/base/src/app.controller.ts +12 -0
  19. package/templates/base/src/app.module.ts +10 -0
  20. package/templates/base/src/app.service.ts +8 -0
  21. package/templates/base/src/main.ts +13 -0
  22. package/templates/cjs-module/package.json +7 -0
  23. package/templates/code-quality/biome/biome.json +47 -0
  24. package/templates/code-quality/biome/package.json +14 -0
  25. package/templates/code-quality/eslint/eslint.config.mjs +35 -0
  26. package/templates/code-quality/eslint/package.json +14 -0
  27. package/templates/code-quality/oxlint/.oxlintrc.json +8 -0
  28. package/templates/code-quality/oxlint/package.json +10 -0
  29. package/templates/code-quality/prettier/.prettierignore +10 -0
  30. package/templates/code-quality/prettier/.prettierrc +7 -0
  31. package/templates/code-quality/prettier/package.json +9 -0
  32. package/templates/e2e-tests/cypress/gitignore +2 -0
  33. package/templates/e2e-tests/cypress/package.json +12 -0
  34. package/templates/e2e-tests/cypress/test/app.cy.ts +10 -0
  35. package/templates/e2e-tests/cypress/test/cypress.config.mjs +9 -0
  36. package/templates/e2e-tests/cypress/test/tsconfig.json +8 -0
  37. package/templates/e2e-tests/e2e-scripts/package.json +5 -0
  38. package/templates/e2e-tests/e2e-scripts/scripts/test-e2e.mjs +48 -0
  39. package/templates/e2e-tests/playwright/gitignore +2 -0
  40. package/templates/e2e-tests/playwright/package.json +8 -0
  41. package/templates/e2e-tests/playwright/test/app.e2e-spec.ts +8 -0
  42. package/templates/e2e-tests/playwright/test/playwright.config.mjs +9 -0
  43. package/templates/e2e-tests/runner-configs/jest/test/jest-e2e.json +9 -0
  44. package/templates/e2e-tests/runner-configs/mocha/cjs-mocha/test/.mocharc.e2e.json +5 -0
  45. package/templates/e2e-tests/runner-configs/mocha/esm-mocha/test/.mocharc.e2e.json +5 -0
  46. package/templates/e2e-tests/runner-configs/vitest/test/vitest.config.e2e.mjs +15 -0
  47. package/templates/e2e-tests/selenium/jest-selenium/package.json +5 -0
  48. package/templates/e2e-tests/selenium/jest-selenium/test/app.e2e-spec.ts +25 -0
  49. package/templates/e2e-tests/selenium/mocha-selenium/package.json +5 -0
  50. package/templates/e2e-tests/selenium/mocha-selenium/test/app.e2e-spec.ts +28 -0
  51. package/templates/e2e-tests/selenium/package.json +6 -0
  52. package/templates/e2e-tests/selenium/vitest-selenium/package.json +5 -0
  53. package/templates/e2e-tests/selenium/vitest-selenium/test/app.e2e-spec.ts +26 -0
  54. package/templates/e2e-tests/supertest/jest-supertest/package.json +5 -0
  55. package/templates/e2e-tests/supertest/jest-supertest/test/app.e2e-spec.ts +29 -0
  56. package/templates/e2e-tests/supertest/mocha-supertest/package.json +5 -0
  57. package/templates/e2e-tests/supertest/mocha-supertest/test/app.e2e-spec.ts +30 -0
  58. package/templates/e2e-tests/supertest/package.json +6 -0
  59. package/templates/e2e-tests/supertest/vitest-supertest/package.json +5 -0
  60. package/templates/e2e-tests/supertest/vitest-supertest/test/app.e2e-spec.ts +30 -0
  61. package/templates/environment/arktype/package.json +5 -0
  62. package/templates/environment/arktype/src/config/env/env.schema.ts +12 -0
  63. package/templates/environment/arktype/src/config/env/validate.ts +12 -0
  64. package/templates/environment/class-validator/package.json +6 -0
  65. package/templates/environment/class-validator/src/config/env/env.schema.ts +15 -0
  66. package/templates/environment/class-validator/src/config/env/validate.ts +15 -0
  67. package/templates/environment/common/package.json +5 -0
  68. package/templates/environment/common/src/app.module.ts +11 -0
  69. package/templates/environment/common/src/config/env/env.module.ts +17 -0
  70. package/templates/environment/common/src/config/env/env.provider.ts +17 -0
  71. package/templates/environment/common/src/main.ts +15 -0
  72. package/templates/environment/joi/package.json +5 -0
  73. package/templates/environment/joi/src/config/env/env.schema.ts +16 -0
  74. package/templates/environment/joi/src/config/env/validate.ts +16 -0
  75. package/templates/environment/valibot/package.json +5 -0
  76. package/templates/environment/valibot/src/config/env/env.schema.ts +20 -0
  77. package/templates/environment/valibot/src/config/env/validate.ts +16 -0
  78. package/templates/environment/vanilla/src/config/env/env.schema.ts +26 -0
  79. package/templates/environment/vanilla/src/config/env/validate.ts +18 -0
  80. package/templates/environment/zod/package.json +5 -0
  81. package/templates/environment/zod/src/config/env/env.schema.ts +11 -0
  82. package/templates/environment/zod/src/config/env/validate.ts +19 -0
  83. package/templates/esm-module/package.json +3 -0
  84. package/templates/test-runners/common/package.json +5 -0
  85. package/templates/test-runners/jest/eslint-jest/eslint.config.mjs +36 -0
  86. package/templates/test-runners/jest/package.json +7 -0
  87. package/templates/test-runners/mocha/package.json +8 -0
  88. package/templates/test-runners/vitest/eslint-vitest/eslint.config.mjs +43 -0
  89. package/templates/test-runners/vitest/package.json +7 -0
  90. package/templates/unit-tests/common/gitignore +1 -0
  91. package/templates/unit-tests/common/nest-cli.json +8 -0
  92. package/templates/unit-tests/jest/jest.config.json +10 -0
  93. package/templates/unit-tests/jest/package.json +7 -0
  94. package/templates/unit-tests/jest/src/app.controller.spec.ts +22 -0
  95. package/templates/unit-tests/mocha/cjs-mocha/.mocharc.json +5 -0
  96. package/templates/unit-tests/mocha/cjs-mocha/package.json +5 -0
  97. package/templates/unit-tests/mocha/esm-mocha/.mocharc.json +5 -0
  98. package/templates/unit-tests/mocha/package.json +9 -0
  99. package/templates/unit-tests/mocha/src/app.controller.spec.ts +23 -0
  100. package/templates/unit-tests/vitest/package.json +10 -0
  101. package/templates/unit-tests/vitest/src/app.controller.spec.ts +23 -0
  102. package/templates/unit-tests/vitest/vitest.config.mjs +14 -0
  103. package/templates/versions/11/tsconfig.build.json +4 -0
  104. package/templates/versions/11/tsconfig.json +26 -0
  105. package/templates/versions/12/tsconfig.build.json +8 -0
  106. package/templates/versions/12/tsconfig.json +27 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+ Abba Is'haq <https://absterr.is-a.dev>
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,63 @@
1
- # Temporary Holding Version
1
+ # nestkit
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Scaffold NestJS projects with the stack you choose, in the spirit of `create-next-app`. Pick the Nest version, module system, linting, test tools and environment validation instead of accepting one fixed setup.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@absterr/nestkit.svg)](https://www.npmjs.com/package/@absterr/nestkit)
6
+ [![license](https://img.shields.io/npm/l/@absterr/nestkit.svg)](https://github.com/absterr/nestkit/blob/main/LICENSE)
7
+
8
+ ## Prerequisites
9
+
10
+ - Node.js 22.12 or later
11
+
12
+ ## Usage
13
+
14
+ - Run it without installing:
15
+
16
+ ```bash
17
+ npx @absterr/nestkit new my-app
18
+ # or
19
+ bunx @absterr/nestkit new my-app
20
+ ```
21
+
22
+ Or install it globally:
23
+
24
+ ```bash
25
+ npm install -g @absterr/nestkit
26
+ nestkit new my-app
27
+ ```
28
+
29
+ `nestkit create` is an alias for `nestkit new`. Generated projects include the Nest CLI, so you can still use `nest generate`.
30
+
31
+ ## Presets
32
+
33
+ - **Base**: plain NestJS, no extras.
34
+ - **Recommended**: the defaults of `nest new` for the chosen Nest version.
35
+ - **Previous**: the choices from your last Custom run. Saved in `~/.nestkit/settings.json`.
36
+ - **Custom**: choose each tool yourself.
37
+
38
+ ## Options
39
+
40
+ - **NestJS**: 11 or 12 (`--nest-version`)
41
+ - **Module system**: CommonJS or ESM
42
+ - **Linting and formatting**: Biome, ESLint + Prettier, Oxlint + Prettier
43
+ - **Unit tests**: Jest, Vitest, Mocha
44
+ - **End-to-end tests**: Supertest, Playwright, Cypress, Selenium
45
+ - **Environment validation**: Joi, class-validator, Zod, Valibot, ArkType, or plain TypeScript
46
+ - **Agent files**: `AGENTS.md` and `CLAUDE.md`
47
+ - **Git** initialization and **dependency install**
48
+
49
+ Jest is only offered for Nest 11 with CommonJS, and ArkType only with ESM.
50
+
51
+ ## Non-interactive use
52
+
53
+ ```bash
54
+ nestkit new my-app --preset recommended --pm npm --skip-git
55
+ nestkit new my-app --nest-version 12 --module-system esm \
56
+ --code-quality oxlint --unit-tests vitest --e2e supertest --env zod
57
+ ```
58
+
59
+ All flags: `--pm`, `--nest-version`, `--preset`, `--module-system`, `--code-quality`, `--unit-tests`, `--e2e`, `--e2e-runner`, `--env`, `--agent-files`, `--skip-agent-files`, `--git`, `--skip-git`, `--skip-install`.
60
+
61
+ ## License
62
+
63
+ [MIT](https://github.com/absterr/nestkit/blob/main/LICENSE)
package/dist/cli.js ADDED
@@ -0,0 +1,439 @@
1
+ #!/usr/bin/env node
2
+ import * as p from "@clack/prompts";
3
+ import { existsSync, readdirSync } from "node:fs";
4
+ import path from "node:path";
5
+ import { parseArgs } from "node:util";
6
+ import { CODE_QUALITY, E2E, ENV, MODULE_SYSTEMS, PRESETS, RUNNERS, RUNNER_TYPES, UNIT_TESTS, needsRunner, overlaysFor, recommendedCodeQuality, recommendedModuleSystem, recommendedRunner, runnersFor, } from "./options.js";
7
+ import { detectInstalled, invokedBy, } from "./package-managers.js";
8
+ import { addTsconfigTypes, applyOverlay, approveBuildScripts, copyBase, gitInstalled, initGit, insideGitRepo, install, pnpmMajor, retargetNest, rewriteRelativeImports, trustBuildScripts, } from "./scaffold.js";
9
+ import { describeSettings, loadSettings, saveSettings, } from "./settings.js";
10
+ import { resolveNest } from "./versions.js";
11
+ const USAGE = [
12
+ "Usage: nestkit new [directory]",
13
+ "[--pm npm|pnpm|yarn|bun]",
14
+ "[--nest-version latest|previous|11|12]",
15
+ "[--preset base|recommended|previous|custom]",
16
+ "[--module-system cjs|esm]",
17
+ "[--code-quality biome|eslint|oxlint|none]",
18
+ "[--unit-tests jest|vitest|mocha|none]",
19
+ "[--e2e supertest|playwright|cypress|selenium|none]",
20
+ "[--e2e-runner jest|vitest|mocha]",
21
+ "[--env joi|class-validator|zod|valibot|arktype|vanilla|none]",
22
+ "[--agent-files|--skip-agent-files]",
23
+ "[--git|--skip-git]",
24
+ "[--skip-install]",
25
+ ].join(" ");
26
+ const RUNNER_LABELS = {
27
+ jest: "Jest",
28
+ vitest: "Vitest",
29
+ mocha: "Mocha",
30
+ };
31
+ function fail(message) {
32
+ p.cancel(message);
33
+ process.exit(1);
34
+ }
35
+ function ensure(value) {
36
+ if (p.isCancel(value))
37
+ fail("Cancelled.");
38
+ return value;
39
+ }
40
+ function oneOf(flag, value, valid) {
41
+ const match = valid.find((v) => v === value);
42
+ if (!match)
43
+ fail(`Invalid --${flag} "${value}". Use: ${valid.join(", ")}`);
44
+ return match;
45
+ }
46
+ // Skip flag wins, then the yes flag, then the default when there is no TTY, then ask
47
+ async function decide(yes, skip, message) {
48
+ if (skip)
49
+ return false;
50
+ if (yes || !process.stdin.isTTY)
51
+ return true;
52
+ return ensure(await p.confirm({ message, initialValue: true }));
53
+ }
54
+ const { positionals, values } = parseArgs({
55
+ allowPositionals: true,
56
+ options: {
57
+ pm: { type: "string" },
58
+ "nest-version": { type: "string" },
59
+ "module-system": { type: "string" },
60
+ preset: { type: "string" },
61
+ "code-quality": { type: "string" },
62
+ "unit-tests": { type: "string" },
63
+ e2e: { type: "string" },
64
+ "e2e-runner": { type: "string" },
65
+ env: { type: "string" },
66
+ "agent-files": { type: "boolean" },
67
+ "skip-agent-files": { type: "boolean" },
68
+ git: { type: "boolean" },
69
+ "skip-git": { type: "boolean" },
70
+ "skip-install": { type: "boolean" },
71
+ },
72
+ });
73
+ const [command, dirArg] = positionals;
74
+ if (command !== "new" && command !== "create") {
75
+ console.error(USAGE);
76
+ process.exit(1);
77
+ }
78
+ p.intro("nestkit");
79
+ const nestSpec = values["nest-version"] ?? "latest";
80
+ const nest = resolveNest(nestSpec);
81
+ if (!nest)
82
+ fail(`Unsupported --nest-version "${nestSpec}". Use: latest, previous, 11, 12`);
83
+ p.log.info(`NestJS ${nest}${values["nest-version"] ? "" : " (latest)"}`);
84
+ const installed = await detectInstalled();
85
+ if (installed.length === 0)
86
+ fail("No supported package manager found.");
87
+ let pm;
88
+ if (values.pm) {
89
+ const requested = installed.find((name) => name === values.pm);
90
+ if (!requested) {
91
+ fail(`"${values.pm}" is not installed. Available: ${installed.join(", ")}`);
92
+ }
93
+ pm = requested;
94
+ }
95
+ else if (installed.length === 1) {
96
+ pm = installed[0];
97
+ }
98
+ else {
99
+ const invoked = invokedBy();
100
+ pm = ensure(await p.select({
101
+ message: "Package manager",
102
+ options: installed.map((value) => ({ value, label: value })),
103
+ initialValue: invoked && installed.includes(invoked) ? invoked : installed[0],
104
+ }));
105
+ }
106
+ const dir = dirArg ??
107
+ ensure(await p.text({
108
+ message: "Project name",
109
+ placeholder: "my-app",
110
+ validate: (v) => (v?.trim() ? undefined : "Required"),
111
+ }));
112
+ const target = path.resolve(dir.trim());
113
+ if (existsSync(target) && readdirSync(target).length > 0) {
114
+ fail(`${target} is not empty.`);
115
+ }
116
+ const saved = loadSettings();
117
+ let preset;
118
+ if (values.preset)
119
+ preset = oneOf("preset", values.preset, PRESETS);
120
+ else if (values["code-quality"] ||
121
+ values["unit-tests"] ||
122
+ values.e2e ||
123
+ values.env) {
124
+ preset = "custom";
125
+ }
126
+ else if (!process.stdin.isTTY)
127
+ preset = "base";
128
+ else {
129
+ preset = ensure(await p.select({
130
+ message: "Preset",
131
+ options: [
132
+ { value: "base", label: "Base", hint: "plain NestJS, no extras" },
133
+ {
134
+ value: "recommended",
135
+ label: "Recommended",
136
+ hint: "NestJS defaults for this version",
137
+ },
138
+ ...(saved
139
+ ? [
140
+ {
141
+ value: "previous",
142
+ label: "Previous",
143
+ hint: describeSettings(saved),
144
+ },
145
+ ]
146
+ : []),
147
+ { value: "custom", label: "Custom", hint: "choose your tools" },
148
+ ],
149
+ }));
150
+ }
151
+ let previous;
152
+ if (preset === "previous") {
153
+ previous =
154
+ saved ??
155
+ fail("No previous settings found. Use the custom preset once to save them.");
156
+ }
157
+ let moduleSystem = "cjs";
158
+ if (values["module-system"]) {
159
+ moduleSystem = oneOf("module-system", values["module-system"], MODULE_SYSTEMS);
160
+ }
161
+ else if (preset === "recommended") {
162
+ moduleSystem = recommendedModuleSystem(nest);
163
+ }
164
+ else if (previous) {
165
+ moduleSystem = previous.moduleSystem;
166
+ }
167
+ else if (process.stdin.isTTY) {
168
+ moduleSystem = ensure(await p.select({
169
+ message: "Module system",
170
+ options: [
171
+ {
172
+ value: "cjs",
173
+ label: "CommonJS",
174
+ hint: recommendedModuleSystem(nest) === "cjs" ? "recommended" : undefined,
175
+ },
176
+ {
177
+ value: "esm",
178
+ label: "ESM",
179
+ hint: recommendedModuleSystem(nest) === "esm"
180
+ ? "recommended"
181
+ : "not officially supported by Nest 11",
182
+ },
183
+ ],
184
+ }));
185
+ }
186
+ // Runners that work for this Nest version and module system
187
+ const recommended = recommendedRunner(nest, moduleSystem);
188
+ const runnerOptions = runnersFor(nest, moduleSystem).map((value) => ({
189
+ value,
190
+ label: RUNNER_LABELS[value],
191
+ hint: value === recommended ? "recommended" : undefined,
192
+ }));
193
+ const isAvailable = (runner) => runnerOptions.some((o) => o.value === runner);
194
+ // Reject bad flag and saved combinations now, before any further prompt
195
+ const requestedUnitTests = values["unit-tests"]
196
+ ? oneOf("unit-tests", values["unit-tests"], UNIT_TESTS)
197
+ : previous?.unitTests;
198
+ if (requestedUnitTests &&
199
+ requestedUnitTests !== "none" &&
200
+ !isAvailable(requestedUnitTests)) {
201
+ fail(`${requestedUnitTests} is not available for Nest ${nest} with ${moduleSystem}.`);
202
+ }
203
+ const requestedEnv = values.env ? oneOf("env", values.env, ENV) : previous?.env;
204
+ if (requestedEnv === "arktype" && moduleSystem !== "esm") {
205
+ fail("ArkType is ESM only. Use --module-system esm or choose another library.");
206
+ }
207
+ const MODULE_LABELS = {
208
+ cjs: "CommonJS",
209
+ esm: "ESM",
210
+ };
211
+ // Runners not offered for this Nest version with the given module system
212
+ const missingFor = (system) => RUNNERS.filter((r) => !runnersFor(nest, system).includes(r));
213
+ // e.g. "Jest is not available for Nest 11 with ESM". Undefined when everything is offered.
214
+ const runnerNote = () => {
215
+ const missing = missingFor(moduleSystem);
216
+ if (missing.length === 0)
217
+ return undefined;
218
+ const names = new Intl.ListFormat("en").format(missing.map((r) => RUNNER_LABELS[r]));
219
+ // Name the module system only when it changes what is offered
220
+ const sameForBoth = missingFor("cjs").join() === missingFor("esm").join();
221
+ const where = sameForBoth
222
+ ? `Nest ${nest}`
223
+ : `Nest ${nest} with ${MODULE_LABELS[moduleSystem]}`;
224
+ return `${names} ${missing.length === 1 ? "is" : "are"} not available for ${where}`;
225
+ };
226
+ // Puts the note in brackets after a runner prompt's title
227
+ const withNote = (message) => {
228
+ const note = runnerNote();
229
+ return note ? `${message} (${note})` : message;
230
+ };
231
+ let codeQuality = "none";
232
+ if (values["code-quality"]) {
233
+ codeQuality = oneOf("code-quality", values["code-quality"], CODE_QUALITY);
234
+ }
235
+ else if (preset === "recommended") {
236
+ codeQuality = recommendedCodeQuality(nest);
237
+ }
238
+ else if (previous) {
239
+ codeQuality = previous.codeQuality;
240
+ }
241
+ else if (preset === "custom" && process.stdin.isTTY) {
242
+ codeQuality = ensure(await p.select({
243
+ message: "Linting and formatting",
244
+ options: [
245
+ { value: "biome", label: "Biome", hint: "lint + format" },
246
+ { value: "eslint", label: "ESLint + Prettier" },
247
+ { value: "oxlint", label: "Oxlint + Prettier" },
248
+ { value: "none", label: "None" },
249
+ ],
250
+ }));
251
+ }
252
+ let unitTests = "none";
253
+ if (values["unit-tests"]) {
254
+ unitTests = oneOf("unit-tests", values["unit-tests"], UNIT_TESTS);
255
+ }
256
+ else if (preset === "recommended") {
257
+ unitTests = recommended;
258
+ }
259
+ else if (previous) {
260
+ unitTests = previous.unitTests;
261
+ }
262
+ else if (preset === "custom" && process.stdin.isTTY) {
263
+ unitTests = ensure(await p.select({
264
+ message: withNote("Unit tests"),
265
+ options: [...runnerOptions, { value: "none", label: "None" }],
266
+ }));
267
+ }
268
+ let e2e = "none";
269
+ if (values.e2e) {
270
+ e2e = oneOf("e2e", values.e2e, E2E);
271
+ }
272
+ else if (preset === "recommended") {
273
+ e2e = "supertest";
274
+ }
275
+ else if (previous) {
276
+ e2e = previous.e2e;
277
+ }
278
+ else if (preset === "custom" && process.stdin.isTTY) {
279
+ e2e = ensure(await p.select({
280
+ message: "End-to-end tests",
281
+ options: [
282
+ { value: "supertest", label: "Supertest", hint: "HTTP, recommended" },
283
+ { value: "playwright", label: "Playwright" },
284
+ { value: "cypress", label: "Cypress" },
285
+ { value: "selenium", label: "Selenium" },
286
+ { value: "none", label: "None" },
287
+ ],
288
+ }));
289
+ }
290
+ // Supertest and selenium need a runner: reuse the unit-test one, else ask
291
+ let e2eRunner;
292
+ if (needsRunner(e2e)) {
293
+ const flag = values["e2e-runner"]
294
+ ? oneOf("e2e-runner", values["e2e-runner"], RUNNERS)
295
+ : undefined;
296
+ const chosen = flag ?? previous?.e2eRunner;
297
+ if (unitTests !== "none") {
298
+ if (flag && flag !== unitTests) {
299
+ fail(`--e2e-runner ${flag} conflicts with --unit-tests ${unitTests}.`);
300
+ }
301
+ p.log.info(`Using ${unitTests} for e2e tests.`);
302
+ }
303
+ else if (chosen) {
304
+ if (!isAvailable(chosen)) {
305
+ fail(`${chosen} is not available for Nest ${nest} with ${moduleSystem}.`);
306
+ }
307
+ e2eRunner = chosen;
308
+ }
309
+ else if (process.stdin.isTTY) {
310
+ e2eRunner = ensure(await p.select({
311
+ message: withNote("Test runner for e2e tests"),
312
+ options: runnerOptions,
313
+ }));
314
+ }
315
+ else {
316
+ fail(`${e2e} needs a test runner. Pass --e2e-runner ${RUNNERS.join("|")}.`);
317
+ }
318
+ }
319
+ let env = "none";
320
+ if (values.env) {
321
+ env = oneOf("env", values.env, ENV);
322
+ }
323
+ else if (previous) {
324
+ env = previous.env;
325
+ }
326
+ else if (preset === "custom" && process.stdin.isTTY) {
327
+ const wantsEnv = ensure(await p.confirm({
328
+ message: "Add environment config with validation?",
329
+ initialValue: true,
330
+ }));
331
+ if (wantsEnv) {
332
+ env = ensure(await p.select({
333
+ message: moduleSystem === "cjs"
334
+ ? "Validation library (ArkType is not available with CommonJS)"
335
+ : "Validation library",
336
+ options: [
337
+ { value: "joi", label: "Joi" },
338
+ {
339
+ value: "class-validator",
340
+ label: "class-validator",
341
+ hint: "with class-transformer",
342
+ },
343
+ { value: "zod", label: "Zod" },
344
+ { value: "valibot", label: "Valibot" },
345
+ ...(moduleSystem === "esm"
346
+ ? [
347
+ {
348
+ value: "arktype",
349
+ label: "ArkType",
350
+ hint: "ESM-only package",
351
+ },
352
+ ]
353
+ : []),
354
+ {
355
+ value: "vanilla",
356
+ label: "None",
357
+ hint: "plain TypeScript, no library",
358
+ },
359
+ ],
360
+ }));
361
+ }
362
+ }
363
+ let agentFiles = false;
364
+ if (values["skip-agent-files"]) {
365
+ agentFiles = false;
366
+ }
367
+ else if (values["agent-files"] || preset === "recommended") {
368
+ agentFiles = true;
369
+ }
370
+ else if (previous) {
371
+ agentFiles = previous.agentFiles;
372
+ }
373
+ else if (preset === "custom" && process.stdin.isTTY) {
374
+ agentFiles = ensure(await p.confirm({
375
+ message: "Add AGENTS.md and CLAUDE.md for coding agents?",
376
+ initialValue: true,
377
+ }));
378
+ }
379
+ const hasGit = gitInstalled();
380
+ if (!hasGit && !values["skip-git"]) {
381
+ p.log.warn("git not found, skipping repository setup.");
382
+ }
383
+ const useGit = hasGit &&
384
+ !insideGitRepo(target) &&
385
+ (await decide(values.git, values["skip-git"], "Initialize a git repository?"));
386
+ const useInstall = !values["skip-install"];
387
+ const projectName = path.basename(target).toLowerCase().replace(/\s+/g, "-");
388
+ copyBase(target, projectName, pm);
389
+ for (const overlay of overlaysFor({
390
+ nest,
391
+ moduleSystem,
392
+ codeQuality,
393
+ unitTests,
394
+ e2e,
395
+ e2eRunner,
396
+ env,
397
+ agentFiles,
398
+ })) {
399
+ applyOverlay(overlay, target);
400
+ }
401
+ const runner = unitTests !== "none" ? unitTests : e2eRunner;
402
+ if (runner)
403
+ addTsconfigTypes(target, RUNNER_TYPES[runner]);
404
+ retargetNest(target, nest);
405
+ if (pm === "pnpm")
406
+ approveBuildScripts(target, pnpmMajor(target));
407
+ if (pm === "bun")
408
+ trustBuildScripts(target);
409
+ if (moduleSystem === "esm")
410
+ rewriteRelativeImports(target);
411
+ if (preset === "custom") {
412
+ const settings = {
413
+ moduleSystem,
414
+ codeQuality,
415
+ unitTests,
416
+ e2e,
417
+ e2eRunner,
418
+ env,
419
+ agentFiles,
420
+ };
421
+ if (!saveSettings(settings)) {
422
+ p.log.warn("Could not save settings for next time.");
423
+ }
424
+ }
425
+ if (useInstall) {
426
+ p.log.step(`Installing dependencies with ${pm}`);
427
+ if (!install(pm, target))
428
+ p.log.warn(`${pm} install failed, run it manually.`);
429
+ }
430
+ if (useGit && !initGit(target)) {
431
+ p.log.warn("Could not initialize a git repository.");
432
+ }
433
+ const relative = path.relative(process.cwd(), target);
434
+ const steps = [
435
+ relative && `cd ${relative}`,
436
+ !useInstall && `${pm} install`,
437
+ `${pm} run start:dev`,
438
+ ].filter(Boolean);
439
+ p.outro(`Done. Next:\n ${steps.join("\n ")}`);
@@ -0,0 +1,98 @@
1
+ export const PRESETS = ["base", "recommended", "previous", "custom"];
2
+ export const MODULE_SYSTEMS = ["cjs", "esm"];
3
+ export const CODE_QUALITY = ["biome", "eslint", "oxlint", "none"];
4
+ export const RUNNERS = ["jest", "vitest", "mocha"];
5
+ export const UNIT_TESTS = [...RUNNERS, "none"];
6
+ export const E2E = [
7
+ "supertest",
8
+ "playwright",
9
+ "cypress",
10
+ "selenium",
11
+ "none",
12
+ ];
13
+ export const ENV = [
14
+ "joi",
15
+ "class-validator",
16
+ "zod",
17
+ "valibot",
18
+ "arktype",
19
+ "vanilla",
20
+ "none",
21
+ ];
22
+ export const needsRunner = (e2e) => e2e === "supertest" || e2e === "selenium";
23
+ // Runners that work for a Nest version and module system
24
+ export function runnersFor(nest, moduleSystem) {
25
+ return nest === "11" && moduleSystem === "cjs"
26
+ ? [...RUNNERS]
27
+ : ["vitest", "mocha"];
28
+ }
29
+ // Runner that gets the "recommended" hint in prompts
30
+ export const recommendedRunner = (nest, moduleSystem) => (nest === "11" && moduleSystem === "cjs" ? "jest" : "vitest");
31
+ // What nest new picks for each Nest version
32
+ export const recommendedModuleSystem = (nest) => nest === "11" ? "cjs" : "esm";
33
+ export const recommendedCodeQuality = (nest) => nest === "11" ? "eslint" : "oxlint";
34
+ // Packages TypeScript 6 must load for each runner's globals.
35
+ export const RUNNER_TYPES = {
36
+ jest: ["jest"],
37
+ vitest: [],
38
+ mocha: ["mocha"],
39
+ };
40
+ // Prettier is shared by the eslint and oxlint paths
41
+ const CODE_QUALITY_OVERLAYS = {
42
+ biome: ["code-quality/biome"],
43
+ eslint: ["code-quality/prettier", "code-quality/eslint"],
44
+ oxlint: ["code-quality/prettier", "code-quality/oxlint"],
45
+ none: [],
46
+ };
47
+ // Runners that ship their own eslint.config.mjs
48
+ const ESLINT_VARIANTS = new Set(["jest", "vitest"]);
49
+ // Variant overlays live inside their parent overlay's folder
50
+ const eslintVariant = (r) => `test-runners/${r}/eslint-${r}`;
51
+ const supertestVariant = (r) => `e2e-tests/supertest/${r}-supertest`;
52
+ const seleniumVariant = (r) => `e2e-tests/selenium/${r}-selenium`;
53
+ // Mocha is configured differently per module system, so it has a folder for each
54
+ const mochaUnit = (m) => `unit-tests/mocha/${m}-mocha`;
55
+ const mochaConfig = (m) => `e2e-tests/runner-configs/mocha/${m}-mocha`;
56
+ // Runner config for e2e tests
57
+ const e2eConfig = (r, m) => r === "mocha" ? mochaConfig(m) : `e2e-tests/runner-configs/${r}`;
58
+ // The parent overlay must not copy these along with its own files
59
+ export const NESTED_OVERLAYS = [
60
+ ...RUNNERS.flatMap((r) => [
61
+ eslintVariant(r),
62
+ supertestVariant(r),
63
+ seleniumVariant(r),
64
+ ]),
65
+ ...MODULE_SYSTEMS.flatMap((m) => [mochaUnit(m), mochaConfig(m)]),
66
+ ];
67
+ // Overlays apply in order, so later ones overwrite earlier files
68
+ export function overlaysFor(s) {
69
+ const runner = s.unitTests !== "none" ? s.unitTests : s.e2eRunner;
70
+ const overlays = [];
71
+ overlays.push(`versions/${s.nest}`, `${s.moduleSystem}-module`, ...CODE_QUALITY_OVERLAYS[s.codeQuality]);
72
+ if (runner) {
73
+ overlays.push("test-runners/common", `test-runners/${runner}`);
74
+ if (s.codeQuality === "eslint" && ESLINT_VARIANTS.has(runner)) {
75
+ overlays.push(eslintVariant(runner));
76
+ }
77
+ }
78
+ if (s.unitTests !== "none") {
79
+ overlays.push("unit-tests/common", `unit-tests/${s.unitTests}`);
80
+ if (s.unitTests === "mocha")
81
+ overlays.push(mochaUnit(s.moduleSystem));
82
+ }
83
+ if (s.e2e === "supertest" && runner) {
84
+ overlays.push("e2e-tests/supertest", supertestVariant(runner), e2eConfig(runner, s.moduleSystem));
85
+ }
86
+ if (s.e2e === "selenium" && runner) {
87
+ overlays.push("e2e-tests/e2e-scripts", "e2e-tests/selenium", seleniumVariant(runner), e2eConfig(runner, s.moduleSystem));
88
+ }
89
+ if (s.e2e === "playwright" || s.e2e === "cypress") {
90
+ overlays.push("e2e-tests/e2e-scripts", `e2e-tests/${s.e2e}`);
91
+ }
92
+ if (s.env !== "none") {
93
+ overlays.push("environment/common", `environment/${s.env}`);
94
+ }
95
+ if (s.agentFiles)
96
+ overlays.push("agent-files/common", `agent-files/${s.nest}`);
97
+ return overlays;
98
+ }
@@ -0,0 +1,23 @@
1
+ import { execFile } from "node:child_process";
2
+ import { promisify } from "node:util";
3
+ const run = promisify(execFile);
4
+ export const PACKAGE_MANAGERS = ["npm", "pnpm", "yarn", "bun"];
5
+ export async function detectInstalled() {
6
+ const results = await Promise.all(PACKAGE_MANAGERS.map(async (pm) => {
7
+ try {
8
+ await run(pm, ["--version"], {
9
+ shell: process.platform === "win32",
10
+ windowsHide: true,
11
+ });
12
+ return pm;
13
+ }
14
+ catch {
15
+ return undefined;
16
+ }
17
+ }));
18
+ return results.filter((pm) => pm !== undefined);
19
+ }
20
+ export function invokedBy() {
21
+ const name = process.env.npm_config_user_agent?.split("/")[0];
22
+ return PACKAGE_MANAGERS.find((pm) => pm === name);
23
+ }