create-craftjs 1.0.9 → 1.0.11

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,10 +1,10 @@
1
- # CraftJS
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
 
7
- ## Features
7
+ ## Features
8
8
 
9
9
  - **Express.js** based API architecture
10
10
  - **TypeScript** support out of the box
@@ -36,9 +36,9 @@ res.render("index", { title: "Home Page" });
36
36
  });
37
37
  ```
38
38
 
39
- ## Getting Started
39
+ ## 🛠 Getting Started
40
40
 
41
- ### Scaffold a New Project
41
+ ### 📦 Scaffold a New Project
42
42
 
43
43
  ```bash
44
44
  npx create-craftjs my-app
@@ -74,7 +74,7 @@ node craft help
74
74
 
75
75
  ---
76
76
 
77
- ## Project Structure
77
+ ## 📦 Project Structure
78
78
 
79
79
  ```
80
80
  my-app/
@@ -110,13 +110,14 @@ my-app/
110
110
 
111
111
  ---
112
112
 
113
- ## Scripts
113
+ ## 📚 Scripts
114
114
 
115
115
  | Command | Description |
116
116
  | ----------------------- | ------------------------------ |
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.11",
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.11",
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
  }