@pauldvlp/vp-react-ts-nestjs 0.1.0 → 0.2.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/README.md CHANGED
@@ -16,8 +16,7 @@ The api rides Vite+'s native **Oxc** transform, which emits `emitDecoratorMetada
16
16
  the production build is a Vite SSR bundle (`dist/main.js`), and a single `vp check` / `vp test` /
17
17
  `vp run -r build` covers the whole workspace.
18
18
 
19
- It's a [Bingo](https://create.bingo) template, so options can be passed on the `vp create` command line
20
- (anything after `--`).
19
+ Options can be passed on the `vp create` command line (anything after `--`) or answered interactively.
21
20
 
22
21
  ## Usage
23
22
 
@@ -32,9 +31,8 @@ vp create @pauldvlp:vp-react-ts-nestjs -- \
32
31
  --name my-app --scope @acme --apiPort 3000 --webPort 5173
33
32
  ```
34
33
 
35
- > Only **string** options parse reliably as `vp create -- --flag value`. **Boolean** options
36
- > (`--swagger`, `--serveWeb`, `--docker`, `--install`) are best left to the interactive prompt — Bingo's
37
- > CLI does not accept `--no-x` / `--x=false` cleanly. Omit them and answer the prompt.
34
+ > **Boolean** options (`--swagger`, `--serveWeb`, `--docker`, `--install`) accept both forms: pass
35
+ > `--swagger` to enable or `--no-swagger` to disable. Omit any option to answer it at the interactive prompt.
38
36
 
39
37
  ## Options
40
38
 
package/dist/index.js CHANGED
@@ -1,15 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- // bin/index.ts
4
- import { runTemplateCLI } from "bingo";
5
-
6
- // src/template.ts
7
- import path2 from "node:path";
8
- import { fileURLToPath } from "node:url";
9
-
10
3
  // ../template-kit/src/index.ts
4
+ import { execFileSync } from "node:child_process";
11
5
  import fs from "node:fs";
12
6
  import path from "node:path";
7
+ import * as prompts from "@clack/prompts";
13
8
  var RENAME = {
14
9
  _gitignore: ".gitignore",
15
10
  _dockerignore: ".dockerignore",
@@ -19,6 +14,10 @@ function toScope(name) {
19
14
  const n = name.trim();
20
15
  return n.startsWith("@") ? n : `@${n}`;
21
16
  }
17
+ function dirName(directory) {
18
+ const base = path.basename(directory || "");
19
+ return base && base !== "." ? base : "my-app";
20
+ }
22
21
  function readTree(dir, transform, base = dir) {
23
22
  const out = {};
24
23
  for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
@@ -43,60 +42,192 @@ function patchJson(tree, relPath, mutate) {
43
42
  node[key] = `${JSON.stringify(json, null, 2)}
44
43
  `;
45
44
  }
46
-
47
- // src/template.ts
48
- import { createTemplate } from "bingo";
49
- import { z } from "zod";
50
-
51
- // package.json
52
- var package_default = {
53
- name: "@pauldvlp/vp-react-ts-nestjs",
54
- version: "0.1.0",
55
- description: "Vite+ monorepo template: a React web app + a NestJS api (conformed to the Vite+ toolchain) sharing Zod contracts.",
56
- author: "pauldvlp (https://github.com/pauldvlp/vp-templates)",
57
- license: "MIT",
58
- homepage: "https://github.com/pauldvlp/vp-templates",
59
- repository: {
60
- type: "git",
61
- url: "git+https://github.com/pauldvlp/vp-templates.git",
62
- directory: "packages/vp-react-ts-nestjs"
63
- },
64
- bugs: "https://github.com/pauldvlp/vp-templates/issues",
65
- keywords: [
66
- "vite-plus-generator",
67
- "vite-plus",
68
- "nestjs",
69
- "react",
70
- "template"
71
- ],
72
- bin: "./dist/index.js",
73
- type: "module",
74
- files: [
75
- "dist",
76
- "template"
77
- ],
78
- scripts: {
79
- build: "esbuild bin/index.ts --bundle --outfile=dist/index.js --format=esm --platform=node --target=node22 --packages=external",
80
- dev: "node bin/index.ts",
81
- prepack: "pnpm run build"
82
- },
83
- dependencies: {
84
- bingo: "^0.9.3",
85
- zod: "^3.25.76"
86
- },
87
- devDependencies: {
88
- "@pauldvlp/template-kit": "workspace:*",
89
- "@types/node": "^24",
90
- esbuild: "^0.25.0",
91
- typescript: "^5"
92
- },
93
- engines: {
94
- node: ">=22.18.0"
45
+ function validateScope(value) {
46
+ return /^@?[A-Za-z0-9][A-Za-z0-9._/-]*$/.test(value.trim()) ? void 0 : "must be a package scope/name, e.g. @acme";
47
+ }
48
+ function validateName(value) {
49
+ return /^@?[A-Za-z0-9][A-Za-z0-9._/-]*$/.test(value.trim()) ? void 0 : "must be a package name, e.g. my-app or @acme/app";
50
+ }
51
+ function defineTemplate(config) {
52
+ return config;
53
+ }
54
+ function writeTree(node, dir, root = path.resolve(dir)) {
55
+ for (const [name, value] of Object.entries(node)) {
56
+ const p = path.resolve(dir, name);
57
+ const rel = path.relative(root, p);
58
+ if (rel === "" || rel === ".." || rel.startsWith(`..${path.sep}`) || path.isAbsolute(rel)) {
59
+ throw new Error(`Refusing to write outside the target directory: ${name}`);
60
+ }
61
+ if (typeof value === "string") {
62
+ fs.mkdirSync(path.dirname(p), { recursive: true });
63
+ fs.writeFileSync(p, value);
64
+ } else {
65
+ fs.mkdirSync(p, { recursive: true });
66
+ writeTree(value, p, root);
67
+ }
95
68
  }
96
- };
69
+ }
70
+ function parseArgv(argv, descriptors) {
71
+ const booleanKeys = new Set(descriptors.filter((d) => d.type === "boolean").map((d) => d.key));
72
+ const values = {};
73
+ let directory;
74
+ for (let i = 0; i < argv.length; i++) {
75
+ const arg = argv[i];
76
+ if (!arg.startsWith("--")) continue;
77
+ let body = arg.slice(2);
78
+ if (body.startsWith("no-") && booleanKeys.has(body.slice(3))) {
79
+ values[body.slice(3)] = false;
80
+ continue;
81
+ }
82
+ let inline;
83
+ const eq = body.indexOf("=");
84
+ if (eq !== -1) {
85
+ inline = body.slice(eq + 1);
86
+ body = body.slice(0, eq);
87
+ }
88
+ if (body === "directory") {
89
+ directory = inline ?? argv[++i];
90
+ continue;
91
+ }
92
+ if (booleanKeys.has(body)) {
93
+ values[body] = inline === void 0 ? true : inline !== "false";
94
+ continue;
95
+ }
96
+ values[body] = inline ?? argv[++i] ?? "";
97
+ }
98
+ return { values, directory };
99
+ }
100
+ function resolveDefault(d, options, directory) {
101
+ return typeof d.default === "function" ? d.default({ options, directory }) : d.default;
102
+ }
103
+ async function promptForOption(d, def) {
104
+ if (d.type === "boolean") {
105
+ return prompts.confirm({ message: d.message, initialValue: def === void 0 ? false : Boolean(def) });
106
+ }
107
+ if (d.type === "select") {
108
+ return prompts.select({
109
+ message: d.message,
110
+ options: (d.choices ?? []).map((c) => ({ value: c, label: c })),
111
+ initialValue: def
112
+ });
113
+ }
114
+ const fallback = def === void 0 ? void 0 : String(def);
115
+ return prompts.text({
116
+ message: d.message,
117
+ placeholder: fallback,
118
+ defaultValue: fallback,
119
+ // When a default exists, an empty submit means "use the default" — don't run validation on it,
120
+ // otherwise a rule like the port check would reject pressing Enter to accept 3000.
121
+ validate: d.validate ? (value) => !value && fallback !== void 0 ? void 0 : d.validate(value ?? "") : void 0
122
+ });
123
+ }
124
+ function printHelp(template) {
125
+ const lines = [];
126
+ if (template.about?.name) lines.push(template.about.name);
127
+ if (template.about?.description) lines.push(template.about.description);
128
+ lines.push("", "Options:", " --directory <dir> Where to scaffold");
129
+ for (const d of template.options) {
130
+ const hint = d.type === "select" && d.choices ? ` <${d.choices.join("|")}>` : d.type === "boolean" ? ` / --no-${d.key}` : " <value>";
131
+ lines.push(` --${d.key}${hint} ${d.message}`);
132
+ }
133
+ console.log(lines.join("\n"));
134
+ }
135
+ function initGit(dir) {
136
+ try {
137
+ execFileSync("git", ["rev-parse", "--is-inside-work-tree"], { cwd: dir, stdio: "ignore" });
138
+ return;
139
+ } catch {
140
+ }
141
+ try {
142
+ execFileSync("git", ["init"], { cwd: dir, stdio: "ignore" });
143
+ execFileSync("git", ["add", "-A"], { cwd: dir, stdio: "ignore" });
144
+ let identity = [];
145
+ try {
146
+ execFileSync("git", ["config", "user.email"], { cwd: dir, stdio: "ignore" });
147
+ } catch {
148
+ identity = ["-c", "user.name=create", "-c", "user.email=create@users.noreply.github.com"];
149
+ }
150
+ execFileSync("git", [...identity, "commit", "-m", "feat: initialize project", "--no-gpg-sign"], { cwd: dir, stdio: "ignore" });
151
+ } catch {
152
+ }
153
+ }
154
+ async function runTemplateCLI(template) {
155
+ const argv = process.argv.slice(2);
156
+ if (argv.includes("--help") || argv.includes("-h")) {
157
+ printHelp(template);
158
+ return 0;
159
+ }
160
+ const interactive = Boolean(process.stdout.isTTY) && !argv.includes("--no-interactive");
161
+ const { values, directory: dirArg } = parseArgv(argv, template.options);
162
+ prompts.intro(template.about?.name ?? "create");
163
+ let directory = dirArg;
164
+ if (!directory) {
165
+ if (interactive) {
166
+ const answer = await prompts.text({ message: "Where should we create your project?", placeholder: "my-app", defaultValue: "my-app" });
167
+ if (prompts.isCancel(answer)) {
168
+ prompts.cancel("Cancelled.");
169
+ return 2;
170
+ }
171
+ directory = answer || "my-app";
172
+ } else {
173
+ directory = "my-app";
174
+ }
175
+ }
176
+ const options = {};
177
+ for (const d of template.options) {
178
+ const def = resolveDefault(d, options, directory);
179
+ if (d.key in values) {
180
+ const value = values[d.key];
181
+ if (d.validate && typeof value === "string") {
182
+ const error = d.validate(value);
183
+ if (error) {
184
+ prompts.cancel(`Invalid --${d.key}: ${error}`);
185
+ return 1;
186
+ }
187
+ }
188
+ options[d.key] = value;
189
+ continue;
190
+ }
191
+ if (interactive) {
192
+ const answer = await promptForOption(d, def);
193
+ if (prompts.isCancel(answer)) {
194
+ prompts.cancel("Cancelled.");
195
+ return 2;
196
+ }
197
+ options[d.key] = answer === "" && def !== void 0 ? def : answer;
198
+ } else {
199
+ options[d.key] = def;
200
+ }
201
+ }
202
+ const creation = await template.produce({ options });
203
+ writeTree(creation.files, directory);
204
+ if (creation.scripts?.length) {
205
+ for (const step of [...creation.scripts].sort((a, b) => a.phase - b.phase)) {
206
+ for (const [program, ...commandArgs] of step.commands) {
207
+ if (!program) continue;
208
+ execFileSync(program, commandArgs, { cwd: directory, stdio: "inherit" });
209
+ }
210
+ }
211
+ }
212
+ if (template.git !== false) initGit(directory);
213
+ if (creation.suggestions?.length) {
214
+ prompts.note(creation.suggestions.join("\n"), "Next steps");
215
+ }
216
+ prompts.outro("Done!");
217
+ return 0;
218
+ }
97
219
 
98
220
  // src/template.ts
221
+ import { readFileSync } from "node:fs";
222
+ import path2 from "node:path";
223
+ import { fileURLToPath } from "node:url";
224
+ function validatePort(value) {
225
+ return /^\d+$/.test(value) && Number(value) > 0 && Number(value) < 65536 ? void 0 : "must be a number between 1 and 65535";
226
+ }
99
227
  var TEMPLATE_DIR = path2.join(path2.dirname(fileURLToPath(import.meta.url)), "..", "template");
228
+ var { name: pkgName, description: pkgDescription } = JSON.parse(
229
+ readFileSync(new URL("../package.json", import.meta.url), "utf8")
230
+ );
100
231
  var MAIN_TS = path2.join("apps", "api", "src", "main.ts");
101
232
  var SWAGGER_IMPORT = "import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'";
102
233
  var APP_MODULE = path2.join("apps", "api", "src", "app.module.ts");
@@ -108,34 +239,28 @@ var SERVEWEB_MODULE = [
108
239
  " exclude: ['/api/*path']",
109
240
  " }),"
110
241
  ].join("\n");
111
- function applyDocBlock(text, tag, keep) {
112
- return keep ? text.replace(new RegExp(`^<!-- ${tag}:(START|END) -->\\n`, "gm"), "") : text.replace(new RegExp(`<!-- ${tag}:START -->\\n[\\s\\S]*?<!-- ${tag}:END -->\\n`, "g"), "");
242
+ function applyDocBlock(text2, tag, keep) {
243
+ return keep ? text2.replace(new RegExp(`^<!-- ${tag}:(START|END) -->\\n`, "gm"), "") : text2.replace(new RegExp(`<!-- ${tag}:START -->\\n[\\s\\S]*?<!-- ${tag}:END -->\\n`, "g"), "");
113
244
  }
114
- var template_default = createTemplate({
245
+ var template_default = defineTemplate({
115
246
  about: {
116
- name: package_default.name,
117
- description: package_default.description
118
- },
119
- options: {
120
- name: z.string().describe("Root project / package name").default("my-app"),
121
- scope: z.string().describe("npm scope for workspace packages, e.g. @acme (defaults to @<name>)"),
122
- // Ports are strings, not z.number(): Bingo's clack prompt renders an option's default as a text
123
- // placeholder and calls `.slice` on it, which throws for non-string defaults. They're only ever
124
- // substituted into config files as text anyway.
125
- apiPort: z.string().describe("Port the NestJS api listens on").default("3000"),
126
- webPort: z.string().describe("Port the web dev server listens on").default("5173"),
127
- swagger: z.boolean().describe("Expose Swagger UI at /docs on the api").default(false),
128
- serveWeb: z.boolean().describe("Have the api serve the built web app (single deployable)").default(false),
129
- docker: z.boolean().describe("Add a multi-stage Dockerfile for the api").default(false),
130
- install: z.boolean().describe("Install deps after scaffolding").default(true)
131
- },
132
- // Lazily default the package scope to `@<name>` (prefixing `@` unless the name already has one),
133
- // so it tracks the project name instead of a fixed value. Falls back to `@app` when no name is set.
134
- prepare({ options }) {
135
- return {
136
- scope: () => options.name ? toScope(options.name) : "@app"
137
- };
247
+ name: pkgName,
248
+ description: pkgDescription
138
249
  },
250
+ options: [
251
+ // Default the name to the target directory the user chose, so they don't retype it.
252
+ { key: "name", type: "string", message: "Root project / package name", default: ({ directory }) => dirName(directory), validate: validateName },
253
+ // Lazily default the package scope to `@<name>` (prefixing `@` unless the name already has one),
254
+ // so it tracks the project name instead of a fixed value. Falls back to `@app` when no name is set.
255
+ { key: "scope", type: "string", message: "npm scope for workspace packages, e.g. @acme (defaults to @<name>)", default: ({ options }) => options.name ? toScope(options.name) : "@app", validate: validateScope },
256
+ // Ports stay strings (validated as integers): they're only ever substituted into config files as text.
257
+ { key: "apiPort", type: "string", message: "Port the NestJS api listens on", default: "3000", validate: validatePort },
258
+ { key: "webPort", type: "string", message: "Port the web dev server listens on", default: "5173", validate: validatePort },
259
+ { key: "swagger", type: "boolean", message: "Expose Swagger UI at /docs on the api", default: false },
260
+ { key: "serveWeb", type: "boolean", message: "Have the api serve the built web app (single deployable)", default: false },
261
+ { key: "docker", type: "boolean", message: "Add a multi-stage Dockerfile for the api", default: false },
262
+ { key: "install", type: "boolean", message: "Install deps after scaffolding", default: true }
263
+ ],
139
264
  async produce({ options }) {
140
265
  const scope = toScope(options.scope || options.name || "app");
141
266
  const swaggerSetup = [
@@ -169,7 +294,7 @@ var template_default = createTemplate({
169
294
  delete files[".dockerignore"];
170
295
  delete files.apps.api["Dockerfile"];
171
296
  }
172
- const scripts = options.install ? [{ commands: ["pnpm install --silent"], phase: 0 }] : [];
297
+ const scripts = options.install ? [{ commands: [["pnpm", "install", "--silent"]], phase: 0 }] : [];
173
298
  return {
174
299
  files,
175
300
  scripts,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pauldvlp/vp-react-ts-nestjs",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Vite+ monorepo template: a React web app + a NestJS api (conformed to the Vite+ toolchain) sharing Zod contracts.",
5
5
  "author": "pauldvlp (https://github.com/pauldvlp/vp-templates)",
6
6
  "license": "MIT",
@@ -24,8 +24,7 @@
24
24
  "template"
25
25
  ],
26
26
  "dependencies": {
27
- "bingo": "^0.9.3",
28
- "zod": "^3.25.76"
27
+ "@clack/prompts": "^1.6.0"
29
28
  },
30
29
  "devDependencies": {
31
30
  "@types/node": "^24",
@@ -19,7 +19,7 @@
19
19
  "pino-http": "^10",
20
20
  "reflect-metadata": "^0.2",
21
21
  "rxjs": "^7.8",
22
- "zod": "^3.25.76"
22
+ "zod": "^4.4.3"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@nestjs/testing": "^11",
@@ -1,16 +1,16 @@
1
1
  import { BadRequestException, type PipeTransform } from '@nestjs/common'
2
- import type { ZodSchema } from 'zod'
2
+ import { flattenError, type ZodMiniType } from 'zod/v4-mini'
3
3
 
4
4
  /**
5
5
  * Minimal, zero-dependency bridge between Zod and Nest's pipe system. Use it per-route against a
6
6
  * schema from `@app/contracts`, e.g. `@Body(new ZodValidationPipe(createItemSchema)) body: CreateItem`.
7
7
  */
8
8
  export class ZodValidationPipe<T> implements PipeTransform {
9
- constructor(private readonly schema: ZodSchema<T>) {}
9
+ constructor(private readonly schema: ZodMiniType<T>) {}
10
10
 
11
11
  transform(value: unknown): T {
12
12
  const result = this.schema.safeParse(value)
13
- if (!result.success) throw new BadRequestException(result.error.flatten())
13
+ if (!result.success) throw new BadRequestException(flattenError(result.error))
14
14
  return result.data
15
15
  }
16
16
  }
@@ -1,9 +1,9 @@
1
- import { z } from 'zod'
1
+ import * as z from 'zod/v4-mini'
2
2
 
3
3
  /** Validate `process.env` at boot — the app fails fast with a clear error if something is missing. */
4
4
  export const envSchema = z.object({
5
- NODE_ENV: z.enum(['development', 'production', 'test']).default('development'),
6
- PORT: z.coerce.number().default(__API_PORT__)
5
+ NODE_ENV: z._default(z.enum(['development', 'production', 'test']), 'development'),
6
+ PORT: z._default(z.coerce.number(), __API_PORT__)
7
7
  })
8
8
 
9
9
  export type Env = z.infer<typeof envSchema>
@@ -13,7 +13,7 @@
13
13
  "check": "vp check"
14
14
  },
15
15
  "dependencies": {
16
- "zod": "^3.25.76"
16
+ "zod": "^4.4.3"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@types/node": "catalog:",
@@ -1,18 +1,19 @@
1
- import { z } from 'zod'
1
+ import * as z from 'zod/v4-mini'
2
2
 
3
3
  /**
4
4
  * Shared API contracts. Both ends import from here so there is a single source of truth:
5
5
  * the api validates request bodies against these schemas (via the ZodValidationPipe) and the
6
- * web app uses the inferred types to type its `fetch` responses.
6
+ * web app uses the inferred types to type its `fetch` responses. Zod Mini keeps the bundle small
7
+ * for the shared package — its functional API (`z.pick`, `.check(...)`) replaces the chained methods.
7
8
  */
8
9
 
9
10
  export const itemSchema = z.object({
10
11
  id: z.string(),
11
- name: z.string().min(1),
12
+ name: z.string().check(z.minLength(1)),
12
13
  createdAt: z.string()
13
14
  })
14
15
 
15
- export const createItemSchema = itemSchema.pick({ name: true })
16
+ export const createItemSchema = z.pick(itemSchema, { name: true })
16
17
 
17
18
  export type Item = z.infer<typeof itemSchema>
18
19
  export type CreateItem = z.infer<typeof createItemSchema>