@kozojs/cli 0.1.12 → 0.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/index.js +91 -7
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -44,6 +44,7 @@ async function scaffoldProject(options) {
44
44
  }
45
45
  if (template === "complete") {
46
46
  await scaffoldCompleteTemplate(projectDir, projectName, kozoCoreDep, runtime, database, dbPort, auth);
47
+ if (database !== "none" && database !== "sqlite") await createDockerCompose(projectDir, projectName, database, dbPort);
47
48
  if (extras.includes("docker")) await createDockerfile(projectDir, runtime);
48
49
  if (extras.includes("github-actions")) await createGitHubActions(projectDir);
49
50
  return;
@@ -250,6 +251,9 @@ ${database === "sqlite" ? "## SQLite Notes\n\nThe database is automatically init
250
251
  - [Hono](https://hono.dev)
251
252
  `;
252
253
  await import_fs_extra.default.writeFile(import_node_path.default.join(projectDir, "README.md"), readme);
254
+ if (database !== "none" && database !== "sqlite") await createDockerCompose(projectDir, projectName, database, dbPort);
255
+ if (extras.includes("docker")) await createDockerfile(projectDir, runtime);
256
+ if (extras.includes("github-actions")) await createGitHubActions(projectDir);
253
257
  }
254
258
  function getDatabaseSchema(database) {
255
259
  if (database === "postgresql") {
@@ -448,7 +452,7 @@ async function scaffoldCompleteTemplate(projectDir, projectName, kozoCoreDep, ru
448
452
  },
449
453
  dependencies: {
450
454
  "@kozojs/core": kozoCoreDep,
451
- ...auth && { "@kozojs/auth": kozoCoreDep },
455
+ ...auth && { "@kozojs/auth": kozoCoreDep === "workspace:*" ? "workspace:*" : "^0.1.0" },
452
456
  "@hono/node-server": "^1.13.0",
453
457
  hono: "^4.6.0",
454
458
  zod: "^3.23.0",
@@ -1238,12 +1242,92 @@ await app.nativeListen();
1238
1242
  await import_fs_extra.default.writeFile(import_node_path.default.join(projectDir, "src", "index.ts"), indexTs);
1239
1243
  await import_fs_extra.default.writeFile(import_node_path.default.join(projectDir, ".gitignore"), "node_modules/\ndist/\n.env\n");
1240
1244
  }
1245
+ async function createDockerCompose(dir, projectName, database, dbPort, includeApiService = false, runtime = "node") {
1246
+ if (database === "none" || database === "sqlite") return;
1247
+ const pgPort = dbPort ?? 5436;
1248
+ let services = "";
1249
+ if (database === "postgresql") {
1250
+ const dbUrl = `postgresql://postgres:postgres@db:5432/${projectName}`;
1251
+ services += ` db:
1252
+ image: postgres:16-alpine
1253
+ restart: unless-stopped
1254
+ ports:
1255
+ - "${pgPort}:5432"
1256
+ environment:
1257
+ POSTGRES_USER: postgres
1258
+ POSTGRES_PASSWORD: postgres
1259
+ POSTGRES_DB: ${projectName}
1260
+ volumes:
1261
+ - postgres_data:/var/lib/postgresql/data
1262
+ healthcheck:
1263
+ test: ["CMD-SHELL", "pg_isready -U postgres"]
1264
+ interval: 5s
1265
+ timeout: 5s
1266
+ retries: 5
1267
+ `;
1268
+ if (includeApiService) {
1269
+ const runCmd = runtime === "bun" ? "bun dist/index.js" : "node dist/index.js";
1270
+ services += `
1271
+ api:
1272
+ build: .
1273
+ ports:
1274
+ - "3000:3000"
1275
+ environment:
1276
+ NODE_ENV: production
1277
+ DATABASE_URL: ${dbUrl}
1278
+ JWT_SECRET: \${JWT_SECRET:-change-me-in-production}
1279
+ depends_on:
1280
+ db:
1281
+ condition: service_healthy
1282
+ command: ${runCmd}
1283
+ `;
1284
+ }
1285
+ } else if (database === "mysql") {
1286
+ const dbUrl = `mysql://root:root@db:3306/${projectName}`;
1287
+ services += ` db:
1288
+ image: mysql:8-alpine
1289
+ restart: unless-stopped
1290
+ ports:
1291
+ - "3306:3306"
1292
+ environment:
1293
+ MYSQL_ROOT_PASSWORD: root
1294
+ MYSQL_DATABASE: ${projectName}
1295
+ volumes:
1296
+ - mysql_data:/var/lib/mysql
1297
+ healthcheck:
1298
+ test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
1299
+ interval: 5s
1300
+ timeout: 5s
1301
+ retries: 5
1302
+ `;
1303
+ if (includeApiService) {
1304
+ const runCmd = runtime === "bun" ? "bun dist/index.js" : "node dist/index.js";
1305
+ services += `
1306
+ api:
1307
+ build: .
1308
+ ports:
1309
+ - "3000:3000"
1310
+ environment:
1311
+ NODE_ENV: production
1312
+ DATABASE_URL: ${dbUrl}
1313
+ JWT_SECRET: \${JWT_SECRET:-change-me-in-production}
1314
+ depends_on:
1315
+ db:
1316
+ condition: service_healthy
1317
+ command: ${runCmd}
1318
+ `;
1319
+ }
1320
+ }
1321
+ const volumes = database === "postgresql" ? "\nvolumes:\n postgres_data:\n" : database === "mysql" ? "\nvolumes:\n mysql_data:\n" : "";
1322
+ const compose = `services:
1323
+ ${services}${volumes}`;
1324
+ await import_fs_extra.default.writeFile(import_node_path.default.join(dir, "docker-compose.yml"), compose);
1325
+ }
1241
1326
  async function createDockerfile(projectDir, runtime) {
1242
- const dockerfile = runtime === "bun" ? `FROM oven/bun:1 as builder
1327
+ const dockerfile = runtime === "bun" ? `FROM oven/bun:1 AS builder
1243
1328
  WORKDIR /app
1244
1329
  COPY package.json bun.lockb* ./
1245
1330
  RUN bun install --frozen-lockfile
1246
-
1247
1331
  COPY . .
1248
1332
  RUN bun run build
1249
1333
 
@@ -1253,11 +1337,10 @@ COPY --from=builder /app/dist ./dist
1253
1337
  COPY --from=builder /app/package.json ./
1254
1338
  EXPOSE 3000
1255
1339
  CMD ["bun", "dist/index.js"]
1256
- ` : `FROM node:20-alpine as builder
1340
+ ` : `FROM node:20-alpine AS builder
1257
1341
  WORKDIR /app
1258
1342
  COPY package*.json ./
1259
1343
  RUN npm ci
1260
-
1261
1344
  COPY . .
1262
1345
  RUN npm run build
1263
1346
 
@@ -1270,7 +1353,7 @@ EXPOSE 3000
1270
1353
  CMD ["node", "dist/index.js"]
1271
1354
  `;
1272
1355
  await import_fs_extra.default.writeFile(import_node_path.default.join(projectDir, "Dockerfile"), dockerfile);
1273
- await import_fs_extra.default.writeFile(import_node_path.default.join(projectDir, ".dockerignore"), "node_modules\ndist\n.git\n");
1356
+ await import_fs_extra.default.writeFile(import_node_path.default.join(projectDir, ".dockerignore"), "node_modules\ndist\n.git\n.env\n");
1274
1357
  }
1275
1358
  async function createGitHubActions(projectDir) {
1276
1359
  await import_fs_extra.default.ensureDir(import_node_path.default.join(projectDir, ".github", "workflows"));
@@ -1320,6 +1403,7 @@ async function scaffoldFullstackProject(projectDir, projectName, kozoCoreDep, ru
1320
1403
  await scaffoldFullstackApi(projectDir, projectName, kozoCoreDep, runtime, database, dbPort, auth);
1321
1404
  await scaffoldFullstackWeb(projectDir, projectName, frontend);
1322
1405
  await scaffoldFullstackReadme(projectDir, projectName);
1406
+ if (database !== "none" && database !== "sqlite") await createDockerCompose(projectDir, projectName, database, dbPort);
1323
1407
  if (extras.includes("docker")) await createDockerfile(import_node_path.default.join(projectDir, "apps", "api"), runtime);
1324
1408
  if (extras.includes("github-actions")) await createGitHubActions(projectDir);
1325
1409
  }
@@ -1376,7 +1460,7 @@ ${auth ? "JWT_SECRET=change-me-to-a-random-secret-at-least-32-chars\n" : ""}`;
1376
1460
  },
1377
1461
  dependencies: {
1378
1462
  "@kozojs/core": kozoCoreDep,
1379
- ...auth && { "@kozojs/auth": kozoCoreDep },
1463
+ ...auth && { "@kozojs/auth": kozoCoreDep === "workspace:*" ? "workspace:*" : "^0.1.0" },
1380
1464
  hono: "^4.6.0",
1381
1465
  zod: "^3.23.0",
1382
1466
  dotenv: "^16.4.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kozojs/cli",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "description": "CLI to scaffold new Kozo Framework projects - The next-gen TypeScript Backend Framework",
5
5
  "bin": {
6
6
  "create-kozo": "./lib/index.js",