@aime-aatrick/create-fullstack-template 1.0.5

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # create-fullstack-template
2
+
3
+ Interactive installer CLI for the fullstack template.
4
+
5
+ ## Usage
6
+
7
+ ```bash
8
+ npx create-fullstack-template my-app
9
+ ```
10
+
11
+ The installer will:
12
+
13
+ - download template from `Aime-Patrick/fullstack-template`
14
+ - let you choose mode: fullstack / backend / frontend
15
+ - let you choose package manager: `pnpm` (default) or `npm`
16
+ - ask for backend/frontend ports
17
+ - ask whether to use `inmemory` or `prisma` DB provider
18
+ - create:
19
+ - `backend/.env`
20
+ - `frontend/.env.local`
21
+ - optionally install dependencies and run Prisma setup
@@ -0,0 +1,243 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { randomBytes } from "node:crypto";
4
+ import { existsSync } from "node:fs";
5
+ import { mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
6
+ import { join, resolve } from "node:path";
7
+ import { createInterface } from "node:readline/promises";
8
+ import { spawn } from "node:child_process";
9
+ import degit from "degit";
10
+
11
+ const REPO = "Aime-Patrick/fullstack-template";
12
+
13
+ const askYesNo = async (rl, message, fallback = true) => {
14
+ const hint = fallback ? "Y/n" : "y/N";
15
+ const input = (await rl.question(`${message} (${hint}): `)).trim().toLowerCase();
16
+ if (!input) return fallback;
17
+ return input === "y" || input === "yes";
18
+ };
19
+
20
+ const setEnvValue = (content, key, value) => {
21
+ const line = `${key}=${value}`;
22
+ const pattern = new RegExp(`^${key}=.*$`, "m");
23
+ if (pattern.test(content)) return content.replace(pattern, line);
24
+ return `${content.trimEnd()}\n${line}\n`;
25
+ };
26
+
27
+ const readEnvTemplate = async (path, fallback = "") => {
28
+ if (!existsSync(path)) return fallback;
29
+ return readFile(path, "utf8");
30
+ };
31
+
32
+ const run = (command, args, cwd) =>
33
+ new Promise((resolvePromise, rejectPromise) => {
34
+ const child = spawn(command, args, { cwd, stdio: "inherit", shell: true });
35
+ child.on("exit", (code) => {
36
+ if (code === 0) return resolvePromise();
37
+ rejectPromise(new Error(`${command} ${args.join(" ")} failed with code ${code}`));
38
+ });
39
+ });
40
+
41
+ const askTemplateMode = async (rl) => {
42
+ console.log("\nChoose template mode:");
43
+ console.log(" 1) fullstack (backend + frontend)");
44
+ console.log(" 2) backend");
45
+ console.log(" 3) frontend");
46
+ const choice = (await rl.question("Select mode [1]: ")).trim() || "1";
47
+
48
+ if (choice === "2" || choice.toLowerCase() === "backend") return "backend";
49
+ if (choice === "3" || choice.toLowerCase() === "frontend") return "frontend";
50
+ return "fullstack";
51
+ };
52
+
53
+ const askPackageManager = async (rl) => {
54
+ const value = (await rl.question("Package manager [pnpm/npm] (default: pnpm): "))
55
+ .trim()
56
+ .toLowerCase();
57
+ if (value === "npm") return "npm";
58
+ return "pnpm";
59
+ };
60
+
61
+ const main = async () => {
62
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
63
+
64
+ try {
65
+ const argName = process.argv[2];
66
+ const projectName =
67
+ argName || (await rl.question("Project name (folder): ")).trim();
68
+
69
+ if (!projectName) {
70
+ throw new Error("Project name is required.");
71
+ }
72
+
73
+ const targetDir = resolve(process.cwd(), projectName);
74
+ if (existsSync(targetDir)) {
75
+ const files = await readdir(targetDir);
76
+ if (files.length > 0) {
77
+ throw new Error(`Target folder is not empty: ${targetDir}`);
78
+ }
79
+ } else {
80
+ await mkdir(targetDir, { recursive: true });
81
+ }
82
+
83
+ const mode = await askTemplateMode(rl);
84
+ const packageManager = await askPackageManager(rl);
85
+ const hasBackend = mode === "fullstack" || mode === "backend";
86
+ const hasFrontend = mode === "fullstack" || mode === "frontend";
87
+
88
+ const usePrisma = hasBackend
89
+ ? await askYesNo(rl, "Use Prisma + PostgreSQL?", false)
90
+ : false;
91
+ const installDeps = await askYesNo(rl, "Install dependencies automatically?", true);
92
+ const runPrisma = usePrisma
93
+ ? await askYesNo(rl, "Run Prisma generate/migrate during setup?", true)
94
+ : false;
95
+
96
+ let databaseUrl =
97
+ "postgresql://postgres:postgres@localhost:5432/fullstack_template?schema=public";
98
+ if (usePrisma) {
99
+ const provided = (
100
+ await rl.question(
101
+ `DATABASE_URL [${databaseUrl}]: `,
102
+ )
103
+ ).trim();
104
+ if (provided) databaseUrl = provided;
105
+ }
106
+
107
+ const backendPort = hasBackend
108
+ ? (await rl.question("Backend PORT [3000]: ")).trim() || "3000"
109
+ : "3000";
110
+ const frontendPort = hasFrontend
111
+ ? (await rl.question("Frontend PORT [3001]: ")).trim() || "3001"
112
+ : "3001";
113
+
114
+ console.log(`\nScaffolding from ${REPO} ...`);
115
+ const emitter = degit(REPO, { cache: false, force: true, verbose: true });
116
+ await emitter.clone(targetDir);
117
+
118
+ if (mode === "backend") {
119
+ await rm(join(targetDir, "frontend"), { recursive: true, force: true });
120
+ } else if (mode === "frontend") {
121
+ await rm(join(targetDir, "backend"), { recursive: true, force: true });
122
+ }
123
+
124
+ if (packageManager === "npm") {
125
+ if (hasBackend) {
126
+ await rm(join(targetDir, "backend", "pnpm-lock.yaml"), {
127
+ force: true,
128
+ });
129
+ }
130
+ if (hasFrontend) {
131
+ await rm(join(targetDir, "frontend", "pnpm-lock.yaml"), {
132
+ force: true,
133
+ });
134
+ }
135
+ } else {
136
+ if (hasBackend) {
137
+ await rm(join(targetDir, "backend", "package-lock.json"), {
138
+ force: true,
139
+ });
140
+ }
141
+ if (hasFrontend) {
142
+ await rm(join(targetDir, "frontend", "package-lock.json"), {
143
+ force: true,
144
+ });
145
+ }
146
+ }
147
+
148
+ const backendEnvExample = join(targetDir, "backend", ".env.example");
149
+ const frontendEnvExample = join(targetDir, "frontend", ".env.example");
150
+ const backendEnvPath = join(targetDir, "backend", ".env");
151
+ const frontendEnvPath = join(targetDir, "frontend", ".env.local");
152
+
153
+ if (hasBackend) {
154
+ let backendEnv = await readEnvTemplate(
155
+ backendEnvExample,
156
+ [
157
+ "PORT=3000",
158
+ "CORS_ORIGIN=http://localhost:3001",
159
+ "DB_PROVIDER=inmemory",
160
+ 'DATABASE_URL=""',
161
+ "JWT_SECRET=",
162
+ "",
163
+ ].join("\n"),
164
+ );
165
+ backendEnv = setEnvValue(backendEnv, "PORT", backendPort);
166
+ backendEnv = setEnvValue(
167
+ backendEnv,
168
+ "CORS_ORIGIN",
169
+ `http://localhost:${frontendPort}`,
170
+ );
171
+ backendEnv = setEnvValue(
172
+ backendEnv,
173
+ "DB_PROVIDER",
174
+ usePrisma ? "prisma" : "inmemory",
175
+ );
176
+ backendEnv = setEnvValue(
177
+ backendEnv,
178
+ "DATABASE_URL",
179
+ usePrisma ? `"${databaseUrl}"` : '""',
180
+ );
181
+ backendEnv = setEnvValue(
182
+ backendEnv,
183
+ "JWT_SECRET",
184
+ randomBytes(32).toString("hex"),
185
+ );
186
+ await writeFile(backendEnvPath, backendEnv, "utf8");
187
+ }
188
+
189
+ if (hasFrontend) {
190
+ let frontendEnv = await readEnvTemplate(
191
+ frontendEnvExample,
192
+ ["NEXT_PUBLIC_API_URL=http://localhost:3000", ""].join("\n"),
193
+ );
194
+ frontendEnv = setEnvValue(
195
+ frontendEnv,
196
+ "NEXT_PUBLIC_API_URL",
197
+ `http://localhost:${backendPort}`,
198
+ );
199
+ await writeFile(frontendEnvPath, frontendEnv, "utf8");
200
+ }
201
+
202
+ if (installDeps) {
203
+ if (hasBackend) {
204
+ console.log("\nInstalling backend dependencies...");
205
+ await run(packageManager, ["install"], join(targetDir, "backend"));
206
+ }
207
+ if (hasFrontend) {
208
+ console.log("\nInstalling frontend dependencies...");
209
+ await run(packageManager, ["install"], join(targetDir, "frontend"));
210
+ }
211
+ }
212
+
213
+ if (installDeps && hasBackend && usePrisma && runPrisma) {
214
+ console.log("\nRunning Prisma setup...");
215
+ await run(packageManager, ["run", "prisma:generate"], join(targetDir, "backend"));
216
+ await run(packageManager, ["run", "prisma:migrate"], join(targetDir, "backend"));
217
+ }
218
+
219
+ console.log("\nSetup complete.");
220
+ console.log(`\nNext steps:\n cd ${projectName}`);
221
+ if (hasBackend) {
222
+ console.log(` cd backend && ${packageManager} run start:dev`);
223
+ }
224
+ if (hasFrontend) {
225
+ if (hasBackend) {
226
+ console.log(
227
+ ` cd ../frontend && ${packageManager} run dev -- --port ${frontendPort}`,
228
+ );
229
+ } else {
230
+ console.log(
231
+ ` cd frontend && ${packageManager} run dev -- --port ${frontendPort}`,
232
+ );
233
+ }
234
+ }
235
+ } catch (error) {
236
+ console.error(`\nError: ${error.message}`);
237
+ process.exit(1);
238
+ } finally {
239
+ rl.close();
240
+ }
241
+ };
242
+
243
+ void main();
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@aime-aatrick/create-fullstack-template",
3
+ "version": "1.0.5",
4
+ "description": "Interactive installer for the fullstack template",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "bin": {
8
+ "create-fullstack-template": "./bin/create-fullstack-template.mjs"
9
+ },
10
+ "files": [
11
+ "bin",
12
+ "README.md",
13
+ "LICENSE",
14
+ "package.json"
15
+ ],
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "scripts": {
20
+ "start": "node ./bin/create-fullstack-template.mjs"
21
+ },
22
+ "dependencies": {
23
+ "degit": "^2.8.4"
24
+ }
25
+ }