create-craftjs 1.0.9 → 1.0.10

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
@@ -1,6 +1,6 @@
1
1
  # CraftJS
2
2
 
3
- A starter kit backend powered by Express, TypeScript, EJS Engine, and Prisma — designed for rapid development, simplicity, and scalability.
3
+ A starter kit backend powered by Express, TypeScript, EJS Engine, and Prisma — designed for rapid development, simplicity, and scalability.
4
4
 
5
5
  ---
6
6
 
@@ -117,6 +117,7 @@ my-app/
117
117
  | `craft start` | Start production server |
118
118
  | `craft dev` | Run in development mode |
119
119
  | `craft build` | Build for production |
120
+ | `craft build:docker` | Deploy Docker for production |
120
121
  | `craft test` | Run Jest tests |
121
122
  | `craft db:generate` | Generate Prisma client |
122
123
  | `craft db:migrate` | Run Prisma migrations |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-craftjs",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "A starter kit backend framework powered by Express, TypeScript, EJS Engine, and Prisma — designed for rapid development, simplicity, and scalability.",
5
5
  "bin": {
6
6
  "create-craftjs": "bin/index.js"
@@ -0,0 +1,88 @@
1
+ require("dotenv").config();
2
+
3
+ const { spawnSync } = require("child_process");
4
+ const chalk = require("chalk");
5
+
6
+ function run(cmd, args) {
7
+ return spawnSync(cmd, args, {
8
+ stdio: "inherit",
9
+ shell: true,
10
+ });
11
+ }
12
+
13
+ function dockerBuild() {
14
+ const appName = process.env.APP_NAME;
15
+
16
+ if (!appName) {
17
+ console.log(chalk.red("❌ APP_NAME not found in .env"));
18
+ return;
19
+ }
20
+
21
+ console.log(chalk.blue(`🐳 Docker build for "${appName}"`));
22
+
23
+ // 1️⃣ Check docker
24
+ const dockerCheck = spawnSync("docker", ["--version"], {
25
+ stdio: "ignore",
26
+ shell: true,
27
+ });
28
+
29
+ if (dockerCheck.status !== 0) {
30
+ console.log(chalk.red("❌ Docker is not installed or not running."));
31
+ return;
32
+ }
33
+
34
+ // 2️⃣ Check container exists
35
+ const containerCheck = spawnSync(
36
+ "docker",
37
+ ["ps", "-a", "--format", "{{.Names}}"],
38
+ {
39
+ encoding: "utf8",
40
+ shell: true,
41
+ }
42
+ );
43
+
44
+ const containers = containerCheck.stdout || "";
45
+ const containerExists = containers.split("\n").includes(appName);
46
+
47
+ // 3️⃣ Down if exists
48
+ if (containerExists) {
49
+ console.log(chalk.yellow(`⚠️ Container "${appName}" exists. Stopping...`));
50
+
51
+ const down = run("docker", ["compose", "down"]);
52
+
53
+ if (down.status !== 0) {
54
+ console.log(chalk.red("❌ Failed to stop existing containers."));
55
+ return;
56
+ }
57
+ }
58
+
59
+ // 4️⃣ Build no cache
60
+ console.log(chalk.blue("🔨 Building image (no cache)..."));
61
+
62
+ const build = run("docker", [
63
+ "build",
64
+ "--no-cache",
65
+ "-t",
66
+ `${appName}_image`,
67
+ ".",
68
+ ]);
69
+
70
+ if (build.status !== 0) {
71
+ console.log(chalk.red("❌ Docker build failed."));
72
+ return;
73
+ }
74
+
75
+ // 5️⃣ Compose up
76
+ console.log(chalk.green("🚀 Starting containers..."));
77
+
78
+ const up = run("docker", ["compose", "up", "-d"]);
79
+
80
+ if (up.status !== 0) {
81
+ console.log(chalk.red("❌ Docker compose up failed."));
82
+ return;
83
+ }
84
+
85
+ console.log(chalk.green(`✅ "${appName}" is running successfully!`));
86
+ }
87
+
88
+ module.exports = dockerBuild;
package/template/craft.js CHANGED
@@ -240,6 +240,15 @@ yargs(hideBin(process.argv))
240
240
  const start = require("./craft/commands/start.js");
241
241
  start();
242
242
  }
243
+ )
244
+ .command(
245
+ "build:docker",
246
+ "Docker build for production",
247
+ () => {},
248
+ () => {
249
+ const start = require("./craft/commands/docker-build.js");
250
+ start();
251
+ }
243
252
  )
244
253
  .command(
245
254
  "test",
@@ -1,5 +1,5 @@
1
1
  services:
2
- ${APP_NAME}:
2
+ craft-js:
3
3
  container_name: ${APP_NAME}
4
4
  image: ${APP_NAME}_image
5
5
  build: .
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "craftjs",
3
3
  "description": "A starter kit backend framework powered by Express, TypeScript, EJS Engine, and Prisma — designed for rapid development, simplicity, and scalability.",
4
- "version": "1.0.8",
4
+ "version": "1.0.10",
5
5
  "keywords": [
6
6
  "express",
7
7
  "typescript",
@@ -4,11 +4,18 @@ import { Express } from "express";
4
4
  import { SwaggerTheme } from "swagger-themes";
5
5
  import { env } from "../config/env";
6
6
 
7
+ function formatAppNameForTitle(appName: string) {
8
+ return appName
9
+ .split("-") // pisahkan berdasarkan dash
10
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) // ubah huruf pertama tiap kata jadi kapital
11
+ .join(" "); // gabungkan kembali dengan spasi
12
+ }
13
+
7
14
  const swaggerOptions: swaggerJSDoc.Options = {
8
15
  definition: {
9
16
  openapi: "3.0.0",
10
17
  info: {
11
- title: `${env.APP_NAME} Api Documentation`,
18
+ title: `${formatAppNameForTitle(env.APP_NAME)} Api Documentation`,
12
19
  version: "1.0.0",
13
20
  },
14
21
  servers: [
@@ -117,7 +124,9 @@ const swaggerOptions: swaggerJSDoc.Options = {
117
124
  security: [{ bearerAuth: [] }],
118
125
  },
119
126
  // apis: ["./src/route/**/*.ts"],
120
- apis: ["./src/apidocs/**/*.ts"],
127
+ apis: env.NODE_ENV === "production"
128
+ ? ["./build/apidocs/**/*.js"]
129
+ : ["./src/apidocs/**/*.ts"],
121
130
  };
122
131
 
123
132
  const swaggerSpec = swaggerJSDoc(swaggerOptions);
@@ -129,7 +138,7 @@ export function setupSwagger(app: Express) {
129
138
  swaggerUi.serve,
130
139
  swaggerUi.setup(swaggerSpec, {
131
140
  customCss: themeCss,
132
- customSiteTitle: `${env.APP_NAME} Api Documentation`,
141
+ customSiteTitle: `${formatAppNameForTitle(env.APP_NAME)} Api Documentation`,
133
142
  })
134
143
  );
135
144
  }