@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/dist/rules.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { RUNNERS, } from "./options.js";
|
|
2
|
+
export const needsRunner = (e2e) => e2e === "supertest" || e2e === "selenium";
|
|
3
|
+
// Runners that work for a Nest version and module system
|
|
4
|
+
export function runnersFor(nest, moduleSystem) {
|
|
5
|
+
return nest === "11" && moduleSystem === "cjs"
|
|
6
|
+
? [...RUNNERS]
|
|
7
|
+
: ["vitest", "mocha"];
|
|
8
|
+
}
|
|
9
|
+
// Runner that gets the "recommended" hint in prompts
|
|
10
|
+
export const recommendedRunner = (nest, moduleSystem) => (nest === "11" && moduleSystem === "cjs" ? "jest" : "vitest");
|
|
11
|
+
// What nest new picks for each Nest version
|
|
12
|
+
export const recommendedModuleSystem = (nest) => nest === "11" ? "cjs" : "esm";
|
|
13
|
+
export const recommendedCodeQuality = (nest) => nest === "11" ? "eslint" : "oxlint";
|
|
14
|
+
// Packages TypeScript 6 must load for each runner's globals
|
|
15
|
+
export const RUNNER_TYPES = {
|
|
16
|
+
jest: ["jest"],
|
|
17
|
+
vitest: [],
|
|
18
|
+
mocha: ["mocha"],
|
|
19
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { readJson, writeJson } from "./json.js";
|
|
4
|
+
// ESM needs explicit extensions on relative imports. Templates are written without them.
|
|
5
|
+
export function rewriteRelativeImports(target) {
|
|
6
|
+
for (const rel of readdirSync(target, {
|
|
7
|
+
recursive: true,
|
|
8
|
+
encoding: "utf8",
|
|
9
|
+
})) {
|
|
10
|
+
if (!rel.endsWith(".ts"))
|
|
11
|
+
continue;
|
|
12
|
+
const file = path.join(target, rel);
|
|
13
|
+
const src = readFileSync(file, "utf8");
|
|
14
|
+
const out = src
|
|
15
|
+
.replace(/(\bfrom\s+")(\.{1,2}\/[^"]+?)(?<!\.js)"/g, '$1$2.js"')
|
|
16
|
+
.replace(/from "supertest\/types"/g, 'from "supertest/types.js"');
|
|
17
|
+
if (out !== src)
|
|
18
|
+
writeFileSync(file, out);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
// TypeScript 6 loads only the @types packages listed in `types`
|
|
22
|
+
export function addTsconfigTypes(target, types) {
|
|
23
|
+
const file = path.join(target, "tsconfig.json");
|
|
24
|
+
const tsconfig = readJson(file);
|
|
25
|
+
const current = tsconfig.compilerOptions?.types;
|
|
26
|
+
if (!current || types.length === 0)
|
|
27
|
+
return;
|
|
28
|
+
tsconfig.compilerOptions.types = [...new Set([...current, ...types])];
|
|
29
|
+
writeJson(file, tsconfig);
|
|
30
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { appendFileSync, cpSync, existsSync, readFileSync, renameSync, writeFileSync, } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { NESTED_OVERLAYS } from "../overlays.js";
|
|
5
|
+
import { mergePackageJson } from "./package-json.js";
|
|
6
|
+
const TEMPLATES = fileURLToPath(new URL("../../templates", import.meta.url));
|
|
7
|
+
const EXEC = {
|
|
8
|
+
npm: "npx",
|
|
9
|
+
pnpm: "pnpm exec",
|
|
10
|
+
yarn: "yarn",
|
|
11
|
+
bun: "bunx",
|
|
12
|
+
};
|
|
13
|
+
function fill(file, tokens) {
|
|
14
|
+
let text = readFileSync(file, "utf8");
|
|
15
|
+
for (const [key, value] of Object.entries(tokens)) {
|
|
16
|
+
text = text.replaceAll(`{{${key}}}`, value);
|
|
17
|
+
}
|
|
18
|
+
writeFileSync(file, text);
|
|
19
|
+
}
|
|
20
|
+
export function copyBase(target, projectName, pm) {
|
|
21
|
+
cpSync(path.join(TEMPLATES, "base"), target, { recursive: true });
|
|
22
|
+
// npm strips .gitignore from published packages, so it ships as "gitignore"
|
|
23
|
+
for (const name of ["gitignore", "gitattributes"]) {
|
|
24
|
+
renameSync(path.join(target, name), path.join(target, `.${name}`));
|
|
25
|
+
}
|
|
26
|
+
fill(path.join(target, "package.json"), { projectName });
|
|
27
|
+
fill(path.join(target, "README.md"), { pm, exec: EXEC[pm] });
|
|
28
|
+
}
|
|
29
|
+
// Copies the overlay's files, merges its package.json fragment and appends its gitignore
|
|
30
|
+
export function applyOverlay(name, target) {
|
|
31
|
+
const dir = path.join(TEMPLATES, name);
|
|
32
|
+
const fragment = path.join(dir, "package.json");
|
|
33
|
+
const ignore = path.join(dir, "gitignore");
|
|
34
|
+
const nested = NESTED_OVERLAYS.map((n) => path.join(TEMPLATES, n)).filter((n) => n.startsWith(dir + path.sep));
|
|
35
|
+
cpSync(dir, target, {
|
|
36
|
+
recursive: true,
|
|
37
|
+
filter: (src) => src !== fragment && src !== ignore && !nested.includes(src),
|
|
38
|
+
});
|
|
39
|
+
if (existsSync(fragment))
|
|
40
|
+
mergePackageJson(target, fragment);
|
|
41
|
+
if (existsSync(ignore)) {
|
|
42
|
+
appendFileSync(path.join(target, ".gitignore"), readFileSync(ignore, "utf8"));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { overlaysFor } from "../overlays.js";
|
|
2
|
+
import { RUNNER_TYPES } from "../rules.js";
|
|
3
|
+
import { addTsconfigTypes, rewriteRelativeImports } from "./esm.js";
|
|
4
|
+
import { applyOverlay, copyBase } from "./files.js";
|
|
5
|
+
import { pnpmMajor } from "./install.js";
|
|
6
|
+
import { approveBuildScripts, enableEsm, targetNestMajor, trustBuildScripts, } from "./package-json.js";
|
|
7
|
+
// Writes the project files. No prompts, no install, no git
|
|
8
|
+
export function scaffoldProject(target, projectName, pm, s) {
|
|
9
|
+
copyBase(target, projectName, pm);
|
|
10
|
+
for (const overlay of overlaysFor(s))
|
|
11
|
+
applyOverlay(overlay, target);
|
|
12
|
+
const runner = s.unitTests !== "none" ? s.unitTests : s.e2eRunner;
|
|
13
|
+
if (runner)
|
|
14
|
+
addTsconfigTypes(target, RUNNER_TYPES[runner]);
|
|
15
|
+
targetNestMajor(target, s.nest);
|
|
16
|
+
if (pm === "pnpm")
|
|
17
|
+
approveBuildScripts(target, pnpmMajor(target));
|
|
18
|
+
if (pm === "bun")
|
|
19
|
+
trustBuildScripts(target);
|
|
20
|
+
if (s.moduleSystem === "esm") {
|
|
21
|
+
enableEsm(target);
|
|
22
|
+
rewriteRelativeImports(target);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
export function install(pm, cwd) {
|
|
5
|
+
const result = spawnSync(pm, ["install"], {
|
|
6
|
+
cwd,
|
|
7
|
+
stdio: "inherit",
|
|
8
|
+
shell: process.platform === "win32",
|
|
9
|
+
});
|
|
10
|
+
return result.status === 0;
|
|
11
|
+
}
|
|
12
|
+
export function pnpmMajor(cwd) {
|
|
13
|
+
const result = spawnSync("pnpm", ["--version"], {
|
|
14
|
+
cwd,
|
|
15
|
+
encoding: "utf8",
|
|
16
|
+
shell: process.platform === "win32",
|
|
17
|
+
});
|
|
18
|
+
return Number.parseInt(result.stdout, 10);
|
|
19
|
+
}
|
|
20
|
+
const git = (cwd, ...args) => spawnSync("git", args, { cwd, stdio: "ignore" }).status === 0;
|
|
21
|
+
export function gitInstalled() {
|
|
22
|
+
return git(process.cwd(), "--version");
|
|
23
|
+
}
|
|
24
|
+
// The target may not exist yet, so check from its nearest existing parent
|
|
25
|
+
export function insideGitRepo(target) {
|
|
26
|
+
let dir = target;
|
|
27
|
+
while (!existsSync(dir))
|
|
28
|
+
dir = path.dirname(dir);
|
|
29
|
+
return git(dir, "rev-parse", "--is-inside-work-tree");
|
|
30
|
+
}
|
|
31
|
+
export function initGit(cwd) {
|
|
32
|
+
return git(cwd, "init");
|
|
33
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
export const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
3
|
+
export const readJson = (file) => JSON.parse(readFileSync(file, "utf8"));
|
|
4
|
+
export const writeJson = (file, data) => writeFileSync(file, `${JSON.stringify(data, null, 2)}\n`);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { writeFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { RANGES } from "../versions.js";
|
|
4
|
+
import { isObject, readJson, writeJson } from "./json.js";
|
|
5
|
+
const sortKeys = (obj) => Object.fromEntries(Object.entries(obj).sort(([a], [b]) => a.localeCompare(b)));
|
|
6
|
+
const pkgFile = (target) => path.join(target, "package.json");
|
|
7
|
+
// Objects merge per key, everything else (arrays included) is replaced
|
|
8
|
+
export function mergePackageJson(target, fragmentPath) {
|
|
9
|
+
const pkg = readJson(pkgFile(target));
|
|
10
|
+
const fragment = readJson(fragmentPath);
|
|
11
|
+
for (const [key, value] of Object.entries(fragment)) {
|
|
12
|
+
pkg[key] = isObject(value) ? { ...pkg[key], ...value } : value;
|
|
13
|
+
}
|
|
14
|
+
for (const key of ["dependencies", "devDependencies"]) {
|
|
15
|
+
if (pkg[key])
|
|
16
|
+
pkg[key] = sortKeys(pkg[key]);
|
|
17
|
+
}
|
|
18
|
+
writeJson(pkgFile(target), pkg);
|
|
19
|
+
}
|
|
20
|
+
// Point the Nest-owned packages at the chosen major
|
|
21
|
+
export function targetNestMajor(target, nest) {
|
|
22
|
+
const pkg = readJson(pkgFile(target));
|
|
23
|
+
for (const field of ["dependencies", "devDependencies"]) {
|
|
24
|
+
for (const [name, range] of Object.entries(RANGES[nest])) {
|
|
25
|
+
if (pkg[field]?.[name])
|
|
26
|
+
pkg[field][name] = range;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
writeJson(pkgFile(target), pkg);
|
|
30
|
+
}
|
|
31
|
+
export function enableEsm(target) {
|
|
32
|
+
const pkg = readJson(pkgFile(target));
|
|
33
|
+
pkg.type = "module";
|
|
34
|
+
writeJson(pkgFile(target), pkg);
|
|
35
|
+
}
|
|
36
|
+
// pnpm 10+ and bun skip dependency install scripts and fail the install unless approved
|
|
37
|
+
const BUILD_SCRIPT_PACKAGES = ["@swc/core", "cypress"];
|
|
38
|
+
const buildScriptPackages = (pkg) => BUILD_SCRIPT_PACKAGES.filter((name) => pkg.dependencies?.[name] || pkg.devDependencies?.[name]);
|
|
39
|
+
export function approveBuildScripts(target, major) {
|
|
40
|
+
const pkg = readJson(pkgFile(target));
|
|
41
|
+
const needed = buildScriptPackages(pkg);
|
|
42
|
+
if (needed.length === 0)
|
|
43
|
+
return;
|
|
44
|
+
if (major === 10) {
|
|
45
|
+
pkg.pnpm = { ...pkg.pnpm, onlyBuiltDependencies: needed };
|
|
46
|
+
writeJson(pkgFile(target), pkg);
|
|
47
|
+
}
|
|
48
|
+
else if (major >= 11) {
|
|
49
|
+
const entries = needed.map((name) => ` "${name}": true`).join("\n");
|
|
50
|
+
writeFileSync(path.join(target, "pnpm-workspace.yaml"), `allowBuilds:\n${entries}\n`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export function trustBuildScripts(target) {
|
|
54
|
+
const pkg = readJson(pkgFile(target));
|
|
55
|
+
const needed = buildScriptPackages(pkg);
|
|
56
|
+
if (needed.length === 0)
|
|
57
|
+
return;
|
|
58
|
+
pkg.trustedDependencies = [
|
|
59
|
+
...new Set([...(pkg.trustedDependencies ?? []), ...needed]),
|
|
60
|
+
];
|
|
61
|
+
writeJson(pkgFile(target), pkg);
|
|
62
|
+
}
|
package/dist/settings.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { CODE_QUALITY, E2E, ENV, MODULE_SYSTEMS, RUNNERS, UNIT_TESTS, } from "./options.js";
|
|
5
|
+
const FILE = path.join(homedir(), ".nestkit", "settings.json");
|
|
6
|
+
const isOneOf = (list, value) => list.some((item) => item === value);
|
|
7
|
+
// Undefined when nothing is saved or the file is unreadable or out of date
|
|
8
|
+
export function loadSettings() {
|
|
9
|
+
try {
|
|
10
|
+
const { moduleSystem, codeQuality, unitTests, e2e, e2eRunner, env, agentFiles, } = JSON.parse(readFileSync(FILE, "utf8"));
|
|
11
|
+
if (isOneOf(MODULE_SYSTEMS, moduleSystem) &&
|
|
12
|
+
isOneOf(CODE_QUALITY, codeQuality) &&
|
|
13
|
+
isOneOf(UNIT_TESTS, unitTests) &&
|
|
14
|
+
isOneOf(E2E, e2e) &&
|
|
15
|
+
(e2eRunner === undefined || isOneOf(RUNNERS, e2eRunner)) &&
|
|
16
|
+
isOneOf(ENV, env)) {
|
|
17
|
+
return {
|
|
18
|
+
moduleSystem,
|
|
19
|
+
codeQuality,
|
|
20
|
+
unitTests,
|
|
21
|
+
e2e,
|
|
22
|
+
e2eRunner,
|
|
23
|
+
env,
|
|
24
|
+
agentFiles: agentFiles === true,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export function saveSettings(settings) {
|
|
34
|
+
try {
|
|
35
|
+
mkdirSync(path.dirname(FILE), { recursive: true });
|
|
36
|
+
writeFileSync(FILE, `${JSON.stringify(settings, null, 2)}\n`);
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export const describeSettings = (s) => [
|
|
44
|
+
s.moduleSystem,
|
|
45
|
+
s.codeQuality,
|
|
46
|
+
s.unitTests,
|
|
47
|
+
s.e2e,
|
|
48
|
+
s.env,
|
|
49
|
+
s.agentFiles ? "agent files" : "none",
|
|
50
|
+
]
|
|
51
|
+
.filter((value) => value !== "none")
|
|
52
|
+
.join(", ");
|
package/dist/ui.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as p from "@clack/prompts";
|
|
2
|
+
export function fail(message) {
|
|
3
|
+
p.cancel(message);
|
|
4
|
+
process.exit(1);
|
|
5
|
+
}
|
|
6
|
+
export function ensure(value) {
|
|
7
|
+
if (p.isCancel(value))
|
|
8
|
+
fail("Cancelled.");
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
export function oneOf(flag, value, valid) {
|
|
12
|
+
const match = valid.find((v) => v === value);
|
|
13
|
+
if (!match)
|
|
14
|
+
fail(`Invalid --${flag} "${value}". Use: ${valid.join(", ")}`);
|
|
15
|
+
return match;
|
|
16
|
+
}
|
|
17
|
+
// Skip flag wins, then the yes flag, then the default when there is no TTY, then ask
|
|
18
|
+
export async function decide(yes, skip, message) {
|
|
19
|
+
if (skip)
|
|
20
|
+
return false;
|
|
21
|
+
if (yes || !process.stdin.isTTY)
|
|
22
|
+
return true;
|
|
23
|
+
return ensure(await p.confirm({ message, initialValue: true }));
|
|
24
|
+
}
|
package/dist/versions.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export const NEST_VERSIONS = ["11", "12"];
|
|
2
|
+
export const LATEST = "12";
|
|
3
|
+
export const PREVIOUS = "11";
|
|
4
|
+
// Ranges for the packages whose versions follow the Nest major
|
|
5
|
+
export const RANGES = {
|
|
6
|
+
"11": {
|
|
7
|
+
"@nestjs/common": "^11.0.1",
|
|
8
|
+
"@nestjs/core": "^11.0.1",
|
|
9
|
+
"@nestjs/platform-express": "^11.0.1",
|
|
10
|
+
"@nestjs/testing": "^11.0.1",
|
|
11
|
+
"@nestjs/config": "^4.0.4",
|
|
12
|
+
"@nestjs/cli": "^11.0.0",
|
|
13
|
+
"@nestjs/schematics": "^11.0.0",
|
|
14
|
+
typescript: "^5.7.3",
|
|
15
|
+
},
|
|
16
|
+
"12": {
|
|
17
|
+
"@nestjs/common": "^12.0.1",
|
|
18
|
+
"@nestjs/core": "^12.0.1",
|
|
19
|
+
"@nestjs/platform-express": "^12.0.1",
|
|
20
|
+
"@nestjs/testing": "^12.0.1",
|
|
21
|
+
"@nestjs/config": "^12.1.1",
|
|
22
|
+
"@nestjs/cli": "^12.0.0",
|
|
23
|
+
"@nestjs/schematics": "^12.0.0",
|
|
24
|
+
typescript: "~6.0.2",
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
export function resolveNest(spec) {
|
|
28
|
+
if (spec === "latest")
|
|
29
|
+
return LATEST;
|
|
30
|
+
if (spec === "previous")
|
|
31
|
+
return PREVIOUS;
|
|
32
|
+
return NEST_VERSIONS.find((v) => v === spec);
|
|
33
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@absterr/nestkit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Scaffold NestJS projects with your own stack",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/absterr/nestkit.git"
|
|
8
|
+
},
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/absterr/nestkit/issues"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://docs-nestkit.vercel.app",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"nestjs",
|
|
15
|
+
"nest",
|
|
16
|
+
"scaffold",
|
|
17
|
+
"cli",
|
|
18
|
+
"generator",
|
|
19
|
+
"starter"
|
|
20
|
+
],
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"type": "module",
|
|
23
|
+
"bin": {
|
|
24
|
+
"nestkit": "dist/cli.js"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"templates"
|
|
29
|
+
],
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=22.12"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc",
|
|
38
|
+
"dev": "tsc --watch",
|
|
39
|
+
"check": "biome check",
|
|
40
|
+
"check:fix": "biome check --write",
|
|
41
|
+
"test": "vitest run",
|
|
42
|
+
"test:watch": "vitest",
|
|
43
|
+
"check:templates": "node scripts/check-templates.mjs",
|
|
44
|
+
"prepack": "npm run build && npm run check:templates"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@clack/prompts": "^1.9.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@biomejs/biome": "^2.6.9",
|
|
51
|
+
"@types/node": "^22.20.5",
|
|
52
|
+
"typescript": "^6.0.3",
|
|
53
|
+
"vitest": "^5.1.2"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
## NestJS
|
|
4
|
+
|
|
5
|
+
This project uses NestJS 11. The documentation at https://docs.nestjs.com may describe a newer major, so verify APIs against the installed packages. https://docs.nestjs.com/llms.txt indexes it as markdown, one page per chapter.
|
|
6
|
+
|
|
7
|
+
Nest has first-party `@nestjs/*` packages for common needs (databases, configuration, queues, scheduling, caching, health checks, OpenAPI, rate limiting). Check them before adding another library or writing your own, and pick the release whose `peerDependencies` accept Nest 11, since the newest release of a package may require Nest 12.
|
|
8
|
+
|
|
9
|
+
## Validation
|
|
10
|
+
|
|
11
|
+
Use the validation library already in `package.json` (check before adding another). `ValidationPipe` works with `class-validator`.
|
|
12
|
+
|
|
13
|
+
## Project
|
|
14
|
+
|
|
15
|
+
- `src/main.ts` creates the app and listens on `PORT` (3000 by default).
|
|
16
|
+
- `src/app.module.ts` is the root module that imports the others. `AppController` and `AppService` are samples.
|
|
17
|
+
- The scripts in `package.json` are the source of truth for building, running, linting and testing. Use them instead of calling tools directly.
|
|
18
|
+
- Unit tests, if present, sit beside the code as `*.spec.ts`. End-to-end tests, if present, are in `test/`.
|
|
19
|
+
- If `package.json` has `"type": "module"`, relative imports end in `.js` and `__dirname` does not exist (use `import.meta.dirname`).
|
|
20
|
+
- Add new elements with `nest generate` (for example `nest g resource users`). It registers them in the closest module.
|
|
21
|
+
|
|
22
|
+
## Testing
|
|
23
|
+
|
|
24
|
+
Mocks use the test runner's own API (`vi.fn()` on Vitest, `jest.fn()` on Jest). When a task says how to test, follow it. When it says nothing, cover the behavior you change with focused tests rather than adding broad e2e suites.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
## NestJS
|
|
4
|
+
|
|
5
|
+
This project's version of NestJS may be newer than what you know. Check the version in `package.json` and verify APIs against the installed packages. https://docs.nestjs.com/llms.txt indexes the documentation as markdown, one page per chapter.
|
|
6
|
+
|
|
7
|
+
Optional: You can add the official NestJS agent skills by running `npx @nestjs/skills@latest add --agent all` in the project.
|
|
8
|
+
|
|
9
|
+
Nest has first-party packages for these, so check them before adding another library or writing your own:
|
|
10
|
+
|
|
11
|
+
- Databases: [`@nestjs/typeorm`](https://docs.nestjs.com/data/typeorm.md), [`@nestjs/drizzle`](https://docs.nestjs.com/data/drizzle.md), [`@nestjs/mongoose`](https://docs.nestjs.com/data/mongodb.md), [`@nestjs/sequelize`](https://docs.nestjs.com/data/sequelize.md).
|
|
12
|
+
- OpenAPI: [`@nestjs/swagger`](https://docs.nestjs.com/openapi/introduction.md). GraphQL: [`@nestjs/graphql`](https://docs.nestjs.com/graphql/quick-start.md). WebSockets: [`@nestjs/websockets`](https://docs.nestjs.com/websockets/gateways.md). Microservices: [`@nestjs/microservices`](https://docs.nestjs.com/microservices/basics.md).
|
|
13
|
+
- Sign-in: [`@nestjs/authentication`](https://docs.nestjs.com/security/authentication.md). Permissions: [`@nestjs/authorization`](https://docs.nestjs.com/security/authorization.md). Rate limiting: [`@nestjs/throttler`](https://docs.nestjs.com/security/rate-limiting.md).
|
|
14
|
+
- Configuration: [`@nestjs/config`](https://docs.nestjs.com/application/configuration.md). Caching: [`@nestjs/cache-manager`](https://docs.nestjs.com/data/caching.md). Health checks: [`@nestjs/terminus`](https://docs.nestjs.com/reliability/terminus.md). Events inside the app: [`@nestjs/event-emitter`](https://docs.nestjs.com/application/events.md).
|
|
15
|
+
- Email: [`@nestjs/mail`](https://docs.nestjs.com/application/mail.md). Files, S3 included: [`@nestjs/storage`](https://docs.nestjs.com/application/file-storage.md). Translations: [`@nestjs/i18n`](https://docs.nestjs.com/application/i18n.md).
|
|
16
|
+
- Retries, timeouts and circuit breakers: [`@nestjs/resilience`](https://docs.nestjs.com/reliability/resilience.md).
|
|
17
|
+
- Idempotency keys: [`@nestjs/idempotency`](https://docs.nestjs.com/reliability/idempotency.md). Transactional outbox: [`@nestjs/outbox`](https://docs.nestjs.com/reliability/outbox.md). Sending and receiving webhooks: [`@nestjs/webhooks`](https://docs.nestjs.com/http/webhooks.md).
|
|
18
|
+
- Queues: [`@nestjs/bullmq`](https://docs.nestjs.com/application/queues.md). Scheduled jobs: [`@nestjs/schedule`](https://docs.nestjs.com/application/task-scheduling.md).
|
|
19
|
+
- Running a scheduled job on one instance, and locks: [`@nestjs/locks`](https://docs.nestjs.com/reliability/locks.md). Processes that take days: [`@nestjs/workflows`](https://docs.nestjs.com/reliability/workflows.md).
|
|
20
|
+
- Language models, tools and agents: [`@nestjs/ai`](https://docs.nestjs.com/ai/overview.md). MCP servers: [`@nestjs/mcp`](https://docs.nestjs.com/mcp/overview.md).
|
|
21
|
+
|
|
22
|
+
## Validation
|
|
23
|
+
|
|
24
|
+
Use the validation library already in `package.json` (check before adding another).
|
|
25
|
+
|
|
26
|
+
Zod, Valibot, ArkType and any other Standard Schema library work without classes or decorator metadata: `StandardSchemaValidationPipe` with `@Body({ schema })` or `@Param('id', { schema })` (https://docs.nestjs.com/application/validation.md). `class-validator` still works, through `ValidationPipe`.
|
|
27
|
+
|
|
28
|
+
## Project
|
|
29
|
+
|
|
30
|
+
- `src/main.ts` creates the app and listens on `PORT` (3000 by default).
|
|
31
|
+
- `src/app.module.ts` is the root module that imports the others. `AppController` and `AppService` are samples.
|
|
32
|
+
- The scripts in `package.json` are the source of truth for building, running, linting and testing. Use them instead of calling tools directly.
|
|
33
|
+
- Unit tests, if present, sit beside the code as `*.spec.ts`. End-to-end tests, if present, are in `test/`.
|
|
34
|
+
- Nest's packages are ESM only. A CommonJS project loads them through `require(esm)` and does not need to convert to ESM. If `package.json` has `"type": "module"`, relative imports end in `.js` and `__dirname` does not exist (use `import.meta.dirname`).
|
|
35
|
+
- Add new elements with `nest generate` (for example `nest g resource users`). It registers them in the closest module.
|
|
36
|
+
|
|
37
|
+
## Testing
|
|
38
|
+
|
|
39
|
+
Mocks use the test runner's own API (`vi.fn()` on Vitest, `jest.fn()` on Jest). When a task says how to test, follow it. When it says nothing, cover the behavior you change with focused tests rather than adding broad e2e suites.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@AGENTS.md
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
## Description
|
|
2
|
+
|
|
3
|
+
A [NestJS](https://nestjs.com) project scaffolded with [nestkit](https://www.npmjs.com/package/@absterr/nestkit).
|
|
4
|
+
|
|
5
|
+
## Project setup
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
{{pm}} install
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Compile and run
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# development
|
|
15
|
+
{{pm}} run start
|
|
16
|
+
|
|
17
|
+
# watch mode
|
|
18
|
+
{{pm}} run start:dev
|
|
19
|
+
|
|
20
|
+
# production mode
|
|
21
|
+
{{pm}} run build
|
|
22
|
+
{{pm}} run start:prod
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The port is set in `src/main.ts`. `package.json` lists every script. Depending on the options you chose when scaffolding, there are also scripts for linting and formatting.
|
|
26
|
+
|
|
27
|
+
## Run tests
|
|
28
|
+
|
|
29
|
+
Available if you chose them when scaffolding.
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# unit tests
|
|
33
|
+
{{pm}} run test
|
|
34
|
+
|
|
35
|
+
# unit tests in watch mode
|
|
36
|
+
{{pm}} run test:watch
|
|
37
|
+
|
|
38
|
+
# e2e tests
|
|
39
|
+
{{pm}} run test:e2e
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Environment variables
|
|
43
|
+
|
|
44
|
+
If you added environment validation, variables are read from `.env.local` and then `.env`, and validated at startup. The schema is in `src/config/env/`.
|
|
45
|
+
|
|
46
|
+
## Project structure
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
src/
|
|
50
|
+
main.ts app entry point
|
|
51
|
+
app.module.ts root module
|
|
52
|
+
app.controller.ts sample controller
|
|
53
|
+
app.service.ts sample service
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The options you chose add more files, such as `test/` for end-to-end tests.
|
|
57
|
+
|
|
58
|
+
## Adding code
|
|
59
|
+
|
|
60
|
+
The project includes the Nest CLI. Generate new elements with `{{exec}} nest generate`, for example `{{exec}} nest generate resource users`. It registers new elements in the closest module.
|
|
61
|
+
|
|
62
|
+
## Deployment
|
|
63
|
+
|
|
64
|
+
See the [NestJS deployment documentation](https://docs.nestjs.com/deployment) for the steps to run your app in production.
|
|
65
|
+
|
|
66
|
+
## Resources
|
|
67
|
+
|
|
68
|
+
- [NestJS documentation](https://docs.nestjs.com)
|
|
69
|
+
- [Discord channel](https://discord.gg/G7Qnnhy) for questions and support
|
|
70
|
+
- [Official video courses](https://courses.nestjs.com)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* text=auto eol=lf
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{projectName}}",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"author": "",
|
|
6
|
+
"private": true,
|
|
7
|
+
"license": "UNLICENSED",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "nest build",
|
|
10
|
+
"start": "nest start",
|
|
11
|
+
"start:dev": "nest start --watch",
|
|
12
|
+
"start:prod": "node dist/main",
|
|
13
|
+
"start:debug": "nest start --debug --watch"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@nestjs/common": "*",
|
|
17
|
+
"@nestjs/core": "*",
|
|
18
|
+
"@nestjs/platform-express": "*",
|
|
19
|
+
"reflect-metadata": "^0.2.2",
|
|
20
|
+
"rxjs": "^7.8.1"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@nestjs/cli": "*",
|
|
24
|
+
"@nestjs/schematics": "*",
|
|
25
|
+
"@types/express": "^5.0.0",
|
|
26
|
+
"@types/node": "^22.10.7",
|
|
27
|
+
"ts-loader": "^9.5.2",
|
|
28
|
+
"ts-node": "^10.9.2",
|
|
29
|
+
"tsconfig-paths": "^4.2.0",
|
|
30
|
+
"typescript": "^5.7.3"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Controller, Get } from "@nestjs/common";
|
|
2
|
+
import { AppService } from "./app.service";
|
|
3
|
+
|
|
4
|
+
@Controller()
|
|
5
|
+
export class AppController {
|
|
6
|
+
constructor(private readonly appService: AppService) {}
|
|
7
|
+
|
|
8
|
+
@Get()
|
|
9
|
+
getHello(): string {
|
|
10
|
+
return this.appService.getHello();
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { NestFactory } from "@nestjs/core";
|
|
2
|
+
import { AppModule } from "./app.module";
|
|
3
|
+
|
|
4
|
+
async function bootstrap() {
|
|
5
|
+
const app = await NestFactory.create(AppModule);
|
|
6
|
+
const PORT = process.env.PORT ?? 3000;
|
|
7
|
+
await app.listen(PORT);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
bootstrap().catch((err) => {
|
|
11
|
+
console.error(err);
|
|
12
|
+
process.exit(1);
|
|
13
|
+
});
|