@absterr/nestkit 0.0.0-stage → 0.1.1
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/LICENSE +22 -0
- package/README.md +92 -2
- package/dist/args.js +37 -0
- package/dist/choices/compat.js +15 -0
- package/dist/choices/preset.js +40 -0
- package/dist/choices/stack.js +111 -0
- package/dist/choices/testing.js +110 -0
- package/dist/choices/types.js +1 -0
- package/dist/cli.js +10 -0
- package/dist/new.js +114 -0
- package/dist/options.js +21 -0
- package/dist/overlays.js +61 -0
- package/dist/package-managers.js +23 -0
- package/dist/rules.js +19 -0
- package/dist/scaffold/esm.js +30 -0
- package/dist/scaffold/files.js +44 -0
- package/dist/scaffold/generate.js +24 -0
- package/dist/scaffold/install.js +33 -0
- package/dist/scaffold/json.js +4 -0
- package/dist/scaffold/package-json.js +62 -0
- package/dist/settings.js +52 -0
- package/dist/ui.js +24 -0
- package/dist/versions.js +33 -0
- package/package.json +53 -4
- package/templates/agent-files/11/AGENTS.md +24 -0
- package/templates/agent-files/12/AGENTS.md +39 -0
- package/templates/agent-files/common/CLAUDE.md +1 -0
- package/templates/base/README.md +70 -0
- package/templates/base/gitattributes +1 -0
- package/templates/base/gitignore +8 -0
- package/templates/base/nest-cli.json +11 -0
- package/templates/base/package.json +32 -0
- package/templates/base/src/app.controller.ts +12 -0
- package/templates/base/src/app.module.ts +10 -0
- package/templates/base/src/app.service.ts +8 -0
- package/templates/base/src/main.ts +13 -0
- package/templates/code-quality/biome/biome.json +47 -0
- package/templates/code-quality/biome/package.json +14 -0
- package/templates/code-quality/eslint/eslint.config.mjs +35 -0
- package/templates/code-quality/eslint/package.json +14 -0
- package/templates/code-quality/oxlint/.oxlintrc.json +8 -0
- package/templates/code-quality/oxlint/package.json +10 -0
- package/templates/code-quality/prettier/.prettierignore +10 -0
- package/templates/code-quality/prettier/.prettierrc +7 -0
- package/templates/code-quality/prettier/package.json +9 -0
- package/templates/e2e-tests/cypress/gitignore +2 -0
- package/templates/e2e-tests/cypress/package.json +12 -0
- package/templates/e2e-tests/cypress/test/app.cy.ts +10 -0
- package/templates/e2e-tests/cypress/test/cypress.config.mjs +9 -0
- package/templates/e2e-tests/cypress/test/tsconfig.json +8 -0
- package/templates/e2e-tests/e2e-scripts/package.json +5 -0
- package/templates/e2e-tests/e2e-scripts/scripts/test-e2e.mjs +48 -0
- package/templates/e2e-tests/playwright/gitignore +2 -0
- package/templates/e2e-tests/playwright/package.json +8 -0
- package/templates/e2e-tests/playwright/test/app.e2e-spec.ts +8 -0
- package/templates/e2e-tests/playwright/test/playwright.config.mjs +9 -0
- package/templates/e2e-tests/runner-configs/jest/test/jest-e2e.json +9 -0
- package/templates/e2e-tests/runner-configs/mocha/cjs-mocha/test/.mocharc.e2e.json +5 -0
- package/templates/e2e-tests/runner-configs/mocha/esm-mocha/test/.mocharc.e2e.json +5 -0
- package/templates/e2e-tests/runner-configs/vitest/test/vitest.config.e2e.mjs +15 -0
- package/templates/e2e-tests/selenium/jest-selenium/package.json +5 -0
- package/templates/e2e-tests/selenium/jest-selenium/test/app.e2e-spec.ts +25 -0
- package/templates/e2e-tests/selenium/mocha-selenium/package.json +5 -0
- package/templates/e2e-tests/selenium/mocha-selenium/test/app.e2e-spec.ts +28 -0
- package/templates/e2e-tests/selenium/package.json +6 -0
- package/templates/e2e-tests/selenium/vitest-selenium/package.json +5 -0
- package/templates/e2e-tests/selenium/vitest-selenium/test/app.e2e-spec.ts +26 -0
- package/templates/e2e-tests/supertest/jest-supertest/package.json +5 -0
- package/templates/e2e-tests/supertest/jest-supertest/test/app.e2e-spec.ts +29 -0
- package/templates/e2e-tests/supertest/mocha-supertest/package.json +5 -0
- package/templates/e2e-tests/supertest/mocha-supertest/test/app.e2e-spec.ts +30 -0
- package/templates/e2e-tests/supertest/package.json +6 -0
- package/templates/e2e-tests/supertest/vitest-supertest/package.json +5 -0
- package/templates/e2e-tests/supertest/vitest-supertest/test/app.e2e-spec.ts +30 -0
- package/templates/environment/arktype/package.json +5 -0
- package/templates/environment/arktype/src/config/env/env.schema.ts +12 -0
- package/templates/environment/arktype/src/config/env/validate.ts +12 -0
- package/templates/environment/class-validator/package.json +6 -0
- package/templates/environment/class-validator/src/config/env/env.schema.ts +15 -0
- package/templates/environment/class-validator/src/config/env/validate.ts +15 -0
- package/templates/environment/common/package.json +5 -0
- package/templates/environment/common/src/app.module.ts +11 -0
- package/templates/environment/common/src/config/env/env.module.ts +17 -0
- package/templates/environment/common/src/config/env/env.provider.ts +17 -0
- package/templates/environment/common/src/main.ts +15 -0
- package/templates/environment/joi/package.json +5 -0
- package/templates/environment/joi/src/config/env/env.schema.ts +16 -0
- package/templates/environment/joi/src/config/env/validate.ts +16 -0
- package/templates/environment/valibot/package.json +5 -0
- package/templates/environment/valibot/src/config/env/env.schema.ts +20 -0
- package/templates/environment/valibot/src/config/env/validate.ts +16 -0
- package/templates/environment/vanilla/src/config/env/env.schema.ts +26 -0
- package/templates/environment/vanilla/src/config/env/validate.ts +18 -0
- package/templates/environment/zod/package.json +5 -0
- package/templates/environment/zod/src/config/env/env.schema.ts +11 -0
- package/templates/environment/zod/src/config/env/validate.ts +19 -0
- package/templates/test-runners/common/package.json +5 -0
- package/templates/test-runners/jest/eslint-jest/eslint.config.mjs +36 -0
- package/templates/test-runners/jest/package.json +7 -0
- package/templates/test-runners/mocha/package.json +8 -0
- package/templates/test-runners/vitest/eslint-vitest/eslint.config.mjs +43 -0
- package/templates/test-runners/vitest/package.json +7 -0
- package/templates/unit-tests/common/gitignore +1 -0
- package/templates/unit-tests/common/nest-cli.json +8 -0
- package/templates/unit-tests/jest/jest.config.json +10 -0
- package/templates/unit-tests/jest/package.json +7 -0
- package/templates/unit-tests/jest/src/app.controller.spec.ts +22 -0
- package/templates/unit-tests/mocha/cjs-mocha/.mocharc.json +5 -0
- package/templates/unit-tests/mocha/cjs-mocha/package.json +5 -0
- package/templates/unit-tests/mocha/esm-mocha/.mocharc.json +5 -0
- package/templates/unit-tests/mocha/package.json +9 -0
- package/templates/unit-tests/mocha/src/app.controller.spec.ts +23 -0
- package/templates/unit-tests/vitest/package.json +10 -0
- package/templates/unit-tests/vitest/src/app.controller.spec.ts +23 -0
- package/templates/unit-tests/vitest/vitest.config.mjs +14 -0
- package/templates/versions/11/tsconfig.build.json +4 -0
- package/templates/versions/11/tsconfig.json +26 -0
- package/templates/versions/12/tsconfig.build.json +8 -0
- 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,93 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Nestkit
|
|
2
2
|
|
|
3
|
-
|
|
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
|
+
[](https://www.npmjs.com/package/@absterr/nestkit)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
|
|
8
|
+
[Documentation](https://docs-nestkit.vercel.app) · [npm](https://www.npmjs.com/package/@absterr/nestkit) · [Contributing](CONTRIBUTING.md)
|
|
9
|
+
|
|
10
|
+
## Requirements
|
|
11
|
+
|
|
12
|
+
- Node.js 22.12 or later
|
|
13
|
+
- npm, pnpm, yarn or bun (nestkit detects what is installed). Yarn has not been tested yet.
|
|
14
|
+
|
|
15
|
+
## Quick start
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npx @absterr/nestkit new my-app
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Use `bunx` instead of `npx` if you prefer. To install it globally:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install -g @absterr/nestkit
|
|
25
|
+
nestkit new my-app
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`nestkit create` is an alias for `nestkit new`. Generated projects keep `@nestjs/cli`, so `nest generate` still works.
|
|
29
|
+
|
|
30
|
+
## Presets
|
|
31
|
+
|
|
32
|
+
| Preset | What you get |
|
|
33
|
+
| --------------- | ------------------------------------------------------------------------------------------------------------------ |
|
|
34
|
+
| **Base** | Plain NestJS, no extras |
|
|
35
|
+
| **Recommended** | The defaults of `nest new` for the chosen Nest version, plus agent files |
|
|
36
|
+
| **Previous** | The choices from your last Custom run (saved in `~/.nestkit/settings.json`). Only offered once a saved file exists |
|
|
37
|
+
| **Custom** | Choose each tool yourself |
|
|
38
|
+
|
|
39
|
+
Recommended picks CommonJS, ESLint + Prettier, Jest and Supertest on Nest 11, and ESM, Oxlint + Prettier, Vitest and Supertest on Nest 12.
|
|
40
|
+
|
|
41
|
+
## Options
|
|
42
|
+
|
|
43
|
+
| Option | Choices |
|
|
44
|
+
| ---------------------- | ------------------------------------------------------------------- |
|
|
45
|
+
| NestJS | 11, 12 |
|
|
46
|
+
| Module system | CommonJS, ESM |
|
|
47
|
+
| Linting and formatting | Biome, ESLint + Prettier, Oxlint + Prettier, none |
|
|
48
|
+
| Unit tests | Jest, Vitest, Mocha, none |
|
|
49
|
+
| End-to-end tests | Supertest, Playwright, Cypress, Selenium, none |
|
|
50
|
+
| Environment validation | Joi, class-validator, Zod, Valibot, ArkType, plain TypeScript, none |
|
|
51
|
+
| Agent files | `AGENTS.md` and `CLAUDE.md` |
|
|
52
|
+
| Git and install | Initialize a repository, install dependencies |
|
|
53
|
+
|
|
54
|
+
Not every combination is offered:
|
|
55
|
+
|
|
56
|
+
- **Jest** is available only for Nest 11 with CommonJS.
|
|
57
|
+
- **ArkType** is available only with ESM.
|
|
58
|
+
|
|
59
|
+
## Non-interactive use
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
# Recommended defaults
|
|
63
|
+
nestkit new my-app --preset recommended --pm npm --skip-git
|
|
64
|
+
|
|
65
|
+
# Pick everything
|
|
66
|
+
nestkit new my-app --nest-version 12 --module-system esm \
|
|
67
|
+
--code-quality oxlint --unit-tests vitest --e2e supertest --env zod
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
With no flags and no terminal, nestkit uses the Base preset. Passing `--code-quality`, `--unit-tests`, `--e2e` or `--env` selects Custom. Explicit flags override preset values.
|
|
71
|
+
|
|
72
|
+
| Flag | Values |
|
|
73
|
+
| ------------------------------------- | ----------------------------------------------------------------------------------------- |
|
|
74
|
+
| `--pm` | `npm`, `pnpm`, `yarn`, `bun` |
|
|
75
|
+
| `--nest-version` | `latest`, `previous`, `11`, `12` |
|
|
76
|
+
| `--preset` | `base`, `recommended`, `previous`, `custom` |
|
|
77
|
+
| `--module-system` | `cjs`, `esm` |
|
|
78
|
+
| `--code-quality` | `biome`, `eslint`, `oxlint`, `none` |
|
|
79
|
+
| `--unit-tests` | `jest`, `vitest`, `mocha`, `none` |
|
|
80
|
+
| `--e2e` | `supertest`, `playwright`, `cypress`, `selenium`, `none` |
|
|
81
|
+
| `--e2e-runner` | `jest`, `vitest`, `mocha` (needed for Supertest or Selenium when there are no unit tests) |
|
|
82
|
+
| `--env` | `joi`, `class-validator`, `zod`, `valibot`, `arktype`, `vanilla`, `none` |
|
|
83
|
+
| `--agent-files`, `--skip-agent-files` | Add or skip `AGENTS.md` and `CLAUDE.md` |
|
|
84
|
+
| `--git`, `--skip-git` | Initialize a git repository or not |
|
|
85
|
+
| `--skip-install` | Do not install dependencies |
|
|
86
|
+
|
|
87
|
+
## Contributing
|
|
88
|
+
|
|
89
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
90
|
+
|
|
91
|
+
## License
|
|
92
|
+
|
|
93
|
+
[MIT](LICENSE)
|
package/dist/args.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
export const USAGE = [
|
|
3
|
+
"Usage: nestkit new [directory]",
|
|
4
|
+
"[--pm npm|pnpm|yarn|bun]",
|
|
5
|
+
"[--nest-version latest|previous|11|12]",
|
|
6
|
+
"[--preset base|recommended|previous|custom]",
|
|
7
|
+
"[--module-system cjs|esm]",
|
|
8
|
+
"[--code-quality biome|eslint|oxlint|none]",
|
|
9
|
+
"[--unit-tests jest|vitest|mocha|none]",
|
|
10
|
+
"[--e2e supertest|playwright|cypress|selenium|none]",
|
|
11
|
+
"[--e2e-runner jest|vitest|mocha]",
|
|
12
|
+
"[--env joi|class-validator|zod|valibot|arktype|vanilla|none]",
|
|
13
|
+
"[--agent-files|--skip-agent-files]",
|
|
14
|
+
"[--git|--skip-git]",
|
|
15
|
+
"[--skip-install]",
|
|
16
|
+
].join(" ");
|
|
17
|
+
export function parseCli() {
|
|
18
|
+
return parseArgs({
|
|
19
|
+
allowPositionals: true,
|
|
20
|
+
options: {
|
|
21
|
+
pm: { type: "string" },
|
|
22
|
+
"nest-version": { type: "string" },
|
|
23
|
+
"module-system": { type: "string" },
|
|
24
|
+
preset: { type: "string" },
|
|
25
|
+
"code-quality": { type: "string" },
|
|
26
|
+
"unit-tests": { type: "string" },
|
|
27
|
+
e2e: { type: "string" },
|
|
28
|
+
"e2e-runner": { type: "string" },
|
|
29
|
+
env: { type: "string" },
|
|
30
|
+
"agent-files": { type: "boolean" },
|
|
31
|
+
"skip-agent-files": { type: "boolean" },
|
|
32
|
+
git: { type: "boolean" },
|
|
33
|
+
"skip-git": { type: "boolean" },
|
|
34
|
+
"skip-install": { type: "boolean" },
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ENV, UNIT_TESTS } from "../options.js";
|
|
2
|
+
import { fail, oneOf } from "../ui.js";
|
|
3
|
+
// Reject bad flag and saved combinations now, before any further prompt
|
|
4
|
+
export function checkCompat({ flags, previous }, nest, moduleSystem, runners) {
|
|
5
|
+
const unitTests = flags["unit-tests"]
|
|
6
|
+
? oneOf("unit-tests", flags["unit-tests"], UNIT_TESTS)
|
|
7
|
+
: previous?.unitTests;
|
|
8
|
+
if (unitTests && unitTests !== "none" && !runners.isAvailable(unitTests)) {
|
|
9
|
+
fail(`${unitTests} is not available for Nest ${nest} with ${moduleSystem}.`);
|
|
10
|
+
}
|
|
11
|
+
const env = flags.env ? oneOf("env", flags.env, ENV) : previous?.env;
|
|
12
|
+
if (env === "arktype" && moduleSystem !== "esm") {
|
|
13
|
+
fail("ArkType is ESM only. Use --module-system esm or choose another library.");
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as p from "@clack/prompts";
|
|
2
|
+
import { PRESETS } from "../options.js";
|
|
3
|
+
import { describeSettings } from "../settings.js";
|
|
4
|
+
import { ensure, fail, oneOf } from "../ui.js";
|
|
5
|
+
export async function resolvePreset(flags, saved) {
|
|
6
|
+
if (flags.preset)
|
|
7
|
+
return oneOf("preset", flags.preset, PRESETS);
|
|
8
|
+
if (flags["code-quality"] || flags["unit-tests"] || flags.e2e || flags.env) {
|
|
9
|
+
return "custom";
|
|
10
|
+
}
|
|
11
|
+
if (!process.stdin.isTTY)
|
|
12
|
+
return "base";
|
|
13
|
+
return ensure(await p.select({
|
|
14
|
+
message: "Preset",
|
|
15
|
+
options: [
|
|
16
|
+
{ value: "base", label: "Base", hint: "plain NestJS, no extras" },
|
|
17
|
+
{
|
|
18
|
+
value: "recommended",
|
|
19
|
+
label: "Recommended",
|
|
20
|
+
hint: "NestJS defaults for this version",
|
|
21
|
+
},
|
|
22
|
+
...(saved
|
|
23
|
+
? [
|
|
24
|
+
{
|
|
25
|
+
value: "previous",
|
|
26
|
+
label: "Previous",
|
|
27
|
+
hint: describeSettings(saved),
|
|
28
|
+
},
|
|
29
|
+
]
|
|
30
|
+
: []),
|
|
31
|
+
{ value: "custom", label: "Custom", hint: "choose your tools" },
|
|
32
|
+
],
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
export function resolvePrevious(preset, saved) {
|
|
36
|
+
if (preset !== "previous")
|
|
37
|
+
return undefined;
|
|
38
|
+
return (saved ??
|
|
39
|
+
fail("No previous settings found. Use the custom preset once to save them."));
|
|
40
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import * as p from "@clack/prompts";
|
|
2
|
+
import { CODE_QUALITY, ENV, MODULE_SYSTEMS, } from "../options.js";
|
|
3
|
+
import { recommendedCodeQuality, recommendedModuleSystem } from "../rules.js";
|
|
4
|
+
import { ensure, oneOf } from "../ui.js";
|
|
5
|
+
export async function resolveModuleSystem({ flags, preset, previous }, nest) {
|
|
6
|
+
if (flags["module-system"]) {
|
|
7
|
+
return oneOf("module-system", flags["module-system"], MODULE_SYSTEMS);
|
|
8
|
+
}
|
|
9
|
+
if (preset === "recommended")
|
|
10
|
+
return recommendedModuleSystem(nest);
|
|
11
|
+
if (previous)
|
|
12
|
+
return previous.moduleSystem;
|
|
13
|
+
if (!process.stdin.isTTY)
|
|
14
|
+
return "cjs";
|
|
15
|
+
return ensure(await p.select({
|
|
16
|
+
message: "Module system",
|
|
17
|
+
options: [
|
|
18
|
+
{
|
|
19
|
+
value: "cjs",
|
|
20
|
+
label: "CommonJS",
|
|
21
|
+
hint: recommendedModuleSystem(nest) === "cjs" ? "recommended" : undefined,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
value: "esm",
|
|
25
|
+
label: "ESM",
|
|
26
|
+
hint: recommendedModuleSystem(nest) === "esm"
|
|
27
|
+
? "recommended"
|
|
28
|
+
: "not officially supported by Nest 11",
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
export async function resolveCodeQuality({ flags, preset, previous }, nest) {
|
|
34
|
+
if (flags["code-quality"]) {
|
|
35
|
+
return oneOf("code-quality", flags["code-quality"], CODE_QUALITY);
|
|
36
|
+
}
|
|
37
|
+
if (preset === "recommended")
|
|
38
|
+
return recommendedCodeQuality(nest);
|
|
39
|
+
if (previous)
|
|
40
|
+
return previous.codeQuality;
|
|
41
|
+
if (preset === "custom" && process.stdin.isTTY) {
|
|
42
|
+
return ensure(await p.select({
|
|
43
|
+
message: "Linting and formatting",
|
|
44
|
+
options: [
|
|
45
|
+
{ value: "biome", label: "Biome", hint: "lint + format" },
|
|
46
|
+
{ value: "eslint", label: "ESLint + Prettier" },
|
|
47
|
+
{ value: "oxlint", label: "Oxlint + Prettier" },
|
|
48
|
+
{ value: "none", label: "None" },
|
|
49
|
+
],
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
return "none";
|
|
53
|
+
}
|
|
54
|
+
export async function resolveEnv({ flags, preset, previous }, moduleSystem) {
|
|
55
|
+
if (flags.env)
|
|
56
|
+
return oneOf("env", flags.env, ENV);
|
|
57
|
+
if (previous)
|
|
58
|
+
return previous.env;
|
|
59
|
+
if (preset !== "custom" || !process.stdin.isTTY)
|
|
60
|
+
return "none";
|
|
61
|
+
const wantsEnv = ensure(await p.confirm({
|
|
62
|
+
message: "Add environment config with validation?",
|
|
63
|
+
initialValue: true,
|
|
64
|
+
}));
|
|
65
|
+
if (!wantsEnv)
|
|
66
|
+
return "none";
|
|
67
|
+
return ensure(await p.select({
|
|
68
|
+
message: moduleSystem === "cjs"
|
|
69
|
+
? "Validation library (ArkType is not available with CommonJS)"
|
|
70
|
+
: "Validation library",
|
|
71
|
+
options: [
|
|
72
|
+
{ value: "joi", label: "Joi" },
|
|
73
|
+
{
|
|
74
|
+
value: "class-validator",
|
|
75
|
+
label: "class-validator",
|
|
76
|
+
hint: "with class-transformer",
|
|
77
|
+
},
|
|
78
|
+
{ value: "zod", label: "Zod" },
|
|
79
|
+
{ value: "valibot", label: "Valibot" },
|
|
80
|
+
...(moduleSystem === "esm"
|
|
81
|
+
? [
|
|
82
|
+
{
|
|
83
|
+
value: "arktype",
|
|
84
|
+
label: "ArkType",
|
|
85
|
+
hint: "ESM-only package",
|
|
86
|
+
},
|
|
87
|
+
]
|
|
88
|
+
: []),
|
|
89
|
+
{
|
|
90
|
+
value: "vanilla",
|
|
91
|
+
label: "None",
|
|
92
|
+
hint: "plain TypeScript, no library",
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
export async function resolveAgentFiles({ flags, preset, previous, }) {
|
|
98
|
+
if (flags["skip-agent-files"])
|
|
99
|
+
return false;
|
|
100
|
+
if (flags["agent-files"] || preset === "recommended")
|
|
101
|
+
return true;
|
|
102
|
+
if (previous)
|
|
103
|
+
return previous.agentFiles;
|
|
104
|
+
if (preset === "custom" && process.stdin.isTTY) {
|
|
105
|
+
return ensure(await p.confirm({
|
|
106
|
+
message: "Add AGENTS.md and CLAUDE.md for coding agents?",
|
|
107
|
+
initialValue: true,
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import * as p from "@clack/prompts";
|
|
2
|
+
import { E2E, RUNNERS, UNIT_TESTS, } from "../options.js";
|
|
3
|
+
import { needsRunner, recommendedRunner, runnersFor } from "../rules.js";
|
|
4
|
+
import { ensure, fail, oneOf } from "../ui.js";
|
|
5
|
+
const RUNNER_LABELS = {
|
|
6
|
+
jest: "Jest",
|
|
7
|
+
vitest: "Vitest",
|
|
8
|
+
mocha: "Mocha",
|
|
9
|
+
};
|
|
10
|
+
const MODULE_LABELS = {
|
|
11
|
+
cjs: "CommonJS",
|
|
12
|
+
esm: "ESM",
|
|
13
|
+
};
|
|
14
|
+
// Runner options and prompt notes for this Nest version and module system
|
|
15
|
+
export function runnerInfo(nest, moduleSystem) {
|
|
16
|
+
const recommended = recommendedRunner(nest, moduleSystem);
|
|
17
|
+
const options = runnersFor(nest, moduleSystem).map((value) => ({
|
|
18
|
+
value,
|
|
19
|
+
label: RUNNER_LABELS[value],
|
|
20
|
+
hint: value === recommended ? "recommended" : undefined,
|
|
21
|
+
}));
|
|
22
|
+
const isAvailable = (runner) => options.some((o) => o.value === runner);
|
|
23
|
+
// Runners not offered for this Nest version with the given module system
|
|
24
|
+
const missingFor = (system) => RUNNERS.filter((r) => !runnersFor(nest, system).includes(r));
|
|
25
|
+
// e.g. "Jest is not available for Nest 11 with ESM". Undefined when everything is offered.
|
|
26
|
+
const note = () => {
|
|
27
|
+
const missing = missingFor(moduleSystem);
|
|
28
|
+
if (missing.length === 0)
|
|
29
|
+
return undefined;
|
|
30
|
+
const names = new Intl.ListFormat("en").format(missing.map((r) => RUNNER_LABELS[r]));
|
|
31
|
+
// Name the module system only when it changes what is offered
|
|
32
|
+
const sameForBoth = missingFor("cjs").join() === missingFor("esm").join();
|
|
33
|
+
const where = sameForBoth
|
|
34
|
+
? `Nest ${nest}`
|
|
35
|
+
: `Nest ${nest} with ${MODULE_LABELS[moduleSystem]}`;
|
|
36
|
+
return `${names} ${missing.length === 1 ? "is" : "are"} not available for ${where}`;
|
|
37
|
+
};
|
|
38
|
+
// Puts the note in brackets after a runner prompt's title
|
|
39
|
+
const withNote = (message) => {
|
|
40
|
+
const text = note();
|
|
41
|
+
return text ? `${message} (${text})` : message;
|
|
42
|
+
};
|
|
43
|
+
return { recommended, options, isAvailable, withNote };
|
|
44
|
+
}
|
|
45
|
+
export async function resolveUnitTests({ flags, preset, previous }, runners) {
|
|
46
|
+
if (flags["unit-tests"]) {
|
|
47
|
+
return oneOf("unit-tests", flags["unit-tests"], UNIT_TESTS);
|
|
48
|
+
}
|
|
49
|
+
if (preset === "recommended")
|
|
50
|
+
return runners.recommended;
|
|
51
|
+
if (previous)
|
|
52
|
+
return previous.unitTests;
|
|
53
|
+
if (preset === "custom" && process.stdin.isTTY) {
|
|
54
|
+
return ensure(await p.select({
|
|
55
|
+
message: runners.withNote("Unit tests"),
|
|
56
|
+
options: [...runners.options, { value: "none", label: "None" }],
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
return "none";
|
|
60
|
+
}
|
|
61
|
+
export async function resolveE2e({ flags, preset, previous, }) {
|
|
62
|
+
if (flags.e2e)
|
|
63
|
+
return oneOf("e2e", flags.e2e, E2E);
|
|
64
|
+
if (preset === "recommended")
|
|
65
|
+
return "supertest";
|
|
66
|
+
if (previous)
|
|
67
|
+
return previous.e2e;
|
|
68
|
+
if (preset === "custom" && process.stdin.isTTY) {
|
|
69
|
+
return ensure(await p.select({
|
|
70
|
+
message: "End-to-end tests",
|
|
71
|
+
options: [
|
|
72
|
+
{ value: "supertest", label: "Supertest", hint: "HTTP, recommended" },
|
|
73
|
+
{ value: "playwright", label: "Playwright" },
|
|
74
|
+
{ value: "cypress", label: "Cypress" },
|
|
75
|
+
{ value: "selenium", label: "Selenium" },
|
|
76
|
+
{ value: "none", label: "None" },
|
|
77
|
+
],
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
return "none";
|
|
81
|
+
}
|
|
82
|
+
// Supertest and selenium need a runner: reuse the unit-test one, else ask
|
|
83
|
+
export async function resolveE2eRunner({ flags, previous }, nest, moduleSystem, e2e, unitTests, runners) {
|
|
84
|
+
if (!needsRunner(e2e))
|
|
85
|
+
return undefined;
|
|
86
|
+
const flag = flags["e2e-runner"]
|
|
87
|
+
? oneOf("e2e-runner", flags["e2e-runner"], RUNNERS)
|
|
88
|
+
: undefined;
|
|
89
|
+
const chosen = flag ?? previous?.e2eRunner;
|
|
90
|
+
if (unitTests !== "none") {
|
|
91
|
+
if (flag && flag !== unitTests) {
|
|
92
|
+
fail(`--e2e-runner ${flag} conflicts with --unit-tests ${unitTests}.`);
|
|
93
|
+
}
|
|
94
|
+
p.log.info(`Using ${unitTests} for e2e tests.`);
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
if (chosen) {
|
|
98
|
+
if (!runners.isAvailable(chosen)) {
|
|
99
|
+
fail(`${chosen} is not available for Nest ${nest} with ${moduleSystem}.`);
|
|
100
|
+
}
|
|
101
|
+
return chosen;
|
|
102
|
+
}
|
|
103
|
+
if (process.stdin.isTTY) {
|
|
104
|
+
return ensure(await p.select({
|
|
105
|
+
message: runners.withNote("Test runner for e2e tests"),
|
|
106
|
+
options: runners.options,
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
return fail(`${e2e} needs a test runner. Pass --e2e-runner ${RUNNERS.join("|")}.`);
|
|
110
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { parseCli, USAGE } from "./args.js";
|
|
3
|
+
import { runNew } from "./new.js";
|
|
4
|
+
const { positionals, values } = parseCli();
|
|
5
|
+
const [command, dirArg] = positionals;
|
|
6
|
+
if (command !== "new" && command !== "create") {
|
|
7
|
+
console.error(USAGE);
|
|
8
|
+
process.exit(1);
|
|
9
|
+
}
|
|
10
|
+
await runNew(values, dirArg);
|
package/dist/new.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { existsSync, readdirSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import * as p from "@clack/prompts";
|
|
4
|
+
import { checkCompat } from "./choices/compat.js";
|
|
5
|
+
import { resolvePreset, resolvePrevious } from "./choices/preset.js";
|
|
6
|
+
import { resolveAgentFiles, resolveCodeQuality, resolveEnv, resolveModuleSystem, } from "./choices/stack.js";
|
|
7
|
+
import { resolveE2e, resolveE2eRunner, resolveUnitTests, runnerInfo, } from "./choices/testing.js";
|
|
8
|
+
import { detectInstalled, invokedBy, } from "./package-managers.js";
|
|
9
|
+
import { scaffoldProject } from "./scaffold/generate.js";
|
|
10
|
+
import { gitInstalled, initGit, insideGitRepo, install, } from "./scaffold/install.js";
|
|
11
|
+
import { loadSettings, saveSettings } from "./settings.js";
|
|
12
|
+
import { decide, ensure, fail } from "./ui.js";
|
|
13
|
+
import { resolveNest } from "./versions.js";
|
|
14
|
+
async function resolvePackageManager(requested) {
|
|
15
|
+
const installed = await detectInstalled();
|
|
16
|
+
if (installed.length === 0)
|
|
17
|
+
fail("No supported package manager found.");
|
|
18
|
+
if (requested) {
|
|
19
|
+
const match = installed.find((name) => name === requested);
|
|
20
|
+
if (!match) {
|
|
21
|
+
fail(`"${requested}" is not installed. Available: ${installed.join(", ")}`);
|
|
22
|
+
}
|
|
23
|
+
return match;
|
|
24
|
+
}
|
|
25
|
+
if (installed.length === 1)
|
|
26
|
+
return installed[0];
|
|
27
|
+
const invoked = invokedBy();
|
|
28
|
+
return ensure(await p.select({
|
|
29
|
+
message: "Package manager",
|
|
30
|
+
options: installed.map((value) => ({ value, label: value })),
|
|
31
|
+
initialValue: invoked && installed.includes(invoked) ? invoked : installed[0],
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
export async function runNew(flags, dirArg) {
|
|
35
|
+
p.intro("nestkit");
|
|
36
|
+
const nestSpec = flags["nest-version"] ?? "latest";
|
|
37
|
+
const nest = resolveNest(nestSpec);
|
|
38
|
+
if (!nest) {
|
|
39
|
+
fail(`Unsupported --nest-version "${nestSpec}". Use: latest, previous, 11, 12`);
|
|
40
|
+
}
|
|
41
|
+
p.log.info(`NestJS ${nest}${flags["nest-version"] ? "" : " (latest)"}`);
|
|
42
|
+
const pm = await resolvePackageManager(flags.pm);
|
|
43
|
+
const dir = dirArg ??
|
|
44
|
+
ensure(await p.text({
|
|
45
|
+
message: "Project name",
|
|
46
|
+
placeholder: "my-app",
|
|
47
|
+
validate: (v) => (v?.trim() ? undefined : "Required"),
|
|
48
|
+
}));
|
|
49
|
+
const target = path.resolve(dir.trim());
|
|
50
|
+
if (existsSync(target) && readdirSync(target).length > 0) {
|
|
51
|
+
fail(`${target} is not empty.`);
|
|
52
|
+
}
|
|
53
|
+
const saved = loadSettings();
|
|
54
|
+
const preset = await resolvePreset(flags, saved);
|
|
55
|
+
const previous = resolvePrevious(preset, saved);
|
|
56
|
+
const picked = { flags, preset, previous };
|
|
57
|
+
const moduleSystem = await resolveModuleSystem(picked, nest);
|
|
58
|
+
const runners = runnerInfo(nest, moduleSystem);
|
|
59
|
+
checkCompat(picked, nest, moduleSystem, runners);
|
|
60
|
+
const codeQuality = await resolveCodeQuality(picked, nest);
|
|
61
|
+
const unitTests = await resolveUnitTests(picked, runners);
|
|
62
|
+
const e2e = await resolveE2e(picked);
|
|
63
|
+
const e2eRunner = await resolveE2eRunner(picked, nest, moduleSystem, e2e, unitTests, runners);
|
|
64
|
+
const env = await resolveEnv(picked, moduleSystem);
|
|
65
|
+
const agentFiles = await resolveAgentFiles(picked);
|
|
66
|
+
const hasGit = gitInstalled();
|
|
67
|
+
if (!hasGit && !flags["skip-git"]) {
|
|
68
|
+
p.log.warn("git not found, skipping repository setup.");
|
|
69
|
+
}
|
|
70
|
+
const useGit = hasGit &&
|
|
71
|
+
!insideGitRepo(target) &&
|
|
72
|
+
(await decide(flags.git, flags["skip-git"], "Initialize a git repository?"));
|
|
73
|
+
const useInstall = !flags["skip-install"];
|
|
74
|
+
const projectName = path.basename(target).toLowerCase().replace(/\s+/g, "-");
|
|
75
|
+
scaffoldProject(target, projectName, pm, {
|
|
76
|
+
nest,
|
|
77
|
+
moduleSystem,
|
|
78
|
+
codeQuality,
|
|
79
|
+
unitTests,
|
|
80
|
+
e2e,
|
|
81
|
+
e2eRunner,
|
|
82
|
+
env,
|
|
83
|
+
agentFiles,
|
|
84
|
+
});
|
|
85
|
+
if (preset === "custom") {
|
|
86
|
+
const settings = {
|
|
87
|
+
moduleSystem,
|
|
88
|
+
codeQuality,
|
|
89
|
+
unitTests,
|
|
90
|
+
e2e,
|
|
91
|
+
e2eRunner,
|
|
92
|
+
env,
|
|
93
|
+
agentFiles,
|
|
94
|
+
};
|
|
95
|
+
if (!saveSettings(settings)) {
|
|
96
|
+
p.log.warn("Could not save settings for next time.");
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (useInstall) {
|
|
100
|
+
p.log.step(`Installing dependencies with ${pm}`);
|
|
101
|
+
if (!install(pm, target))
|
|
102
|
+
p.log.warn(`${pm} install failed, run it manually.`);
|
|
103
|
+
}
|
|
104
|
+
if (useGit && !initGit(target)) {
|
|
105
|
+
p.log.warn("Could not initialize a git repository.");
|
|
106
|
+
}
|
|
107
|
+
const relative = path.relative(process.cwd(), target);
|
|
108
|
+
const steps = [
|
|
109
|
+
relative && `cd ${relative}`,
|
|
110
|
+
!useInstall && `${pm} install`,
|
|
111
|
+
`${pm} run start:dev`,
|
|
112
|
+
].filter(Boolean);
|
|
113
|
+
p.outro(`Done. Next:\n ${steps.join("\n ")}`);
|
|
114
|
+
}
|
package/dist/options.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
];
|
package/dist/overlays.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { MODULE_SYSTEMS, RUNNERS, } from "./options.js";
|
|
2
|
+
// Prettier is shared by the eslint and oxlint paths
|
|
3
|
+
const CODE_QUALITY_OVERLAYS = {
|
|
4
|
+
biome: ["code-quality/biome"],
|
|
5
|
+
eslint: ["code-quality/prettier", "code-quality/eslint"],
|
|
6
|
+
oxlint: ["code-quality/prettier", "code-quality/oxlint"],
|
|
7
|
+
none: [],
|
|
8
|
+
};
|
|
9
|
+
// Runners that ship their own eslint.config.mjs
|
|
10
|
+
const ESLINT_VARIANTS = new Set(["jest", "vitest"]);
|
|
11
|
+
// Variant overlays live inside their parent overlay's folder
|
|
12
|
+
const eslintVariant = (r) => `test-runners/${r}/eslint-${r}`;
|
|
13
|
+
const supertestVariant = (r) => `e2e-tests/supertest/${r}-supertest`;
|
|
14
|
+
const seleniumVariant = (r) => `e2e-tests/selenium/${r}-selenium`;
|
|
15
|
+
// Mocha is configured differently per module system, so it has a folder for each
|
|
16
|
+
const mochaUnit = (m) => `unit-tests/mocha/${m}-mocha`;
|
|
17
|
+
const mochaConfig = (m) => `e2e-tests/runner-configs/mocha/${m}-mocha`;
|
|
18
|
+
// Runner config for e2e tests
|
|
19
|
+
const e2eConfig = (r, m) => r === "mocha" ? mochaConfig(m) : `e2e-tests/runner-configs/${r}`;
|
|
20
|
+
// The parent overlay must not copy these along with its own files
|
|
21
|
+
export const NESTED_OVERLAYS = [
|
|
22
|
+
...RUNNERS.flatMap((r) => [
|
|
23
|
+
eslintVariant(r),
|
|
24
|
+
supertestVariant(r),
|
|
25
|
+
seleniumVariant(r),
|
|
26
|
+
]),
|
|
27
|
+
...MODULE_SYSTEMS.flatMap((m) => [mochaUnit(m), mochaConfig(m)]),
|
|
28
|
+
];
|
|
29
|
+
// Overlays apply in order, so later ones overwrite earlier files
|
|
30
|
+
export function overlaysFor(s) {
|
|
31
|
+
const runner = s.unitTests !== "none" ? s.unitTests : s.e2eRunner;
|
|
32
|
+
const overlays = [];
|
|
33
|
+
overlays.push(`versions/${s.nest}`, ...CODE_QUALITY_OVERLAYS[s.codeQuality]);
|
|
34
|
+
if (runner) {
|
|
35
|
+
overlays.push("test-runners/common", `test-runners/${runner}`);
|
|
36
|
+
if (s.codeQuality === "eslint" && ESLINT_VARIANTS.has(runner)) {
|
|
37
|
+
overlays.push(eslintVariant(runner));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (s.unitTests !== "none") {
|
|
41
|
+
overlays.push("unit-tests/common", `unit-tests/${s.unitTests}`);
|
|
42
|
+
if (s.unitTests === "mocha")
|
|
43
|
+
overlays.push(mochaUnit(s.moduleSystem));
|
|
44
|
+
}
|
|
45
|
+
if (s.e2e === "supertest" && runner) {
|
|
46
|
+
overlays.push("e2e-tests/supertest", supertestVariant(runner), e2eConfig(runner, s.moduleSystem));
|
|
47
|
+
}
|
|
48
|
+
if (s.e2e === "selenium" && runner) {
|
|
49
|
+
overlays.push("e2e-tests/e2e-scripts", "e2e-tests/selenium", seleniumVariant(runner), e2eConfig(runner, s.moduleSystem));
|
|
50
|
+
}
|
|
51
|
+
if (s.e2e === "playwright" || s.e2e === "cypress") {
|
|
52
|
+
overlays.push("e2e-tests/e2e-scripts", `e2e-tests/${s.e2e}`);
|
|
53
|
+
}
|
|
54
|
+
if (s.env !== "none") {
|
|
55
|
+
overlays.push("environment/common", `environment/${s.env}`);
|
|
56
|
+
}
|
|
57
|
+
if (s.agentFiles) {
|
|
58
|
+
overlays.push("agent-files/common", `agent-files/${s.nest}`);
|
|
59
|
+
}
|
|
60
|
+
return overlays;
|
|
61
|
+
}
|
|
@@ -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
|
+
}
|