create-zhx-monorepo 0.1.6 → 0.1.8

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/bin/index.js +52 -5
  2. package/package.json +1 -1
package/bin/index.js CHANGED
@@ -9,7 +9,22 @@ import { execSync } from "child_process";
9
9
  const __filename = fileURLToPath(import.meta.url);
10
10
  const __dirname = path.dirname(__filename);
11
11
 
12
- async function main() {
12
+ const replaceDbName = async (filePath, projectName) => {
13
+ if (!(await fs.pathExists(filePath))) return;
14
+
15
+ let content = await fs.readFile(filePath, "utf-8");
16
+ content = content.replace(
17
+ /postgresql:\/\/([^/]+)\/your-proj/g,
18
+ `postgresql://$1/${projectName}`
19
+ );
20
+ await fs.writeFile(filePath, content);
21
+ };
22
+
23
+ const normalizeProjectName = (name) => {
24
+ return name.trim().toLowerCase().replace(/\s+/g, "-");
25
+ };
26
+
27
+ const main = async () => {
13
28
  let targetDir = process.argv[2];
14
29
 
15
30
  if (!targetDir) {
@@ -19,15 +34,17 @@ async function main() {
19
34
  message: "Project name:",
20
35
  validate: (value) => (value ? true : "Project name cannot be empty"),
21
36
  });
37
+
22
38
  targetDir = response.targetDir;
23
39
 
24
40
  if (!targetDir) {
25
41
  console.log(red("❌ No project name provided."));
26
- console.log(red("Exiting..."));
27
42
  process.exit(1);
28
43
  }
29
44
  }
30
45
 
46
+ targetDir = normalizeProjectName(targetDir);
47
+
31
48
  const projectPath = path.resolve(process.cwd(), targetDir);
32
49
 
33
50
  if (fs.existsSync(projectPath)) {
@@ -53,14 +70,33 @@ async function main() {
53
70
  pkg.name = targetDir;
54
71
  await fs.writeJson(pkgPath, pkg, { spaces: 2 });
55
72
 
56
- // rename gitignore to .gitignore
73
+ // Rename gitignore
57
74
  const gitignoreSrc = path.join(projectPath, "gitignore");
58
75
  const gitignoreDest = path.join(projectPath, ".gitignore");
59
-
60
76
  if (fs.existsSync(gitignoreSrc)) {
61
77
  fs.renameSync(gitignoreSrc, gitignoreDest);
62
78
  }
63
79
 
80
+ // --- SERVER SETUP ---
81
+ const serverDir = path.join(projectPath, "server");
82
+ const prismaDir = path.join(serverDir, "prisma");
83
+
84
+ // Remove prisma folders
85
+ await fs.remove(path.join(prismaDir, "migrations"));
86
+ await fs.remove(path.join(prismaDir, "generated"));
87
+
88
+ // Create .env from example
89
+ const envExamplePath = path.join(serverDir, ".env.example");
90
+ const envPath = path.join(serverDir, ".env");
91
+
92
+ if (await fs.pathExists(envExamplePath)) {
93
+ await fs.copy(envExamplePath, envPath);
94
+ }
95
+
96
+ // Replace DB name
97
+ await replaceDbName(envExamplePath, targetDir);
98
+ await replaceDbName(envPath, targetDir);
99
+
64
100
  // Init git
65
101
  process.chdir(projectPath);
66
102
  execSync("git init", { stdio: "ignore" });
@@ -71,12 +107,23 @@ async function main() {
71
107
  execSync(`git remote add origin ${gitRemote}`, { stdio: "ignore" });
72
108
  }
73
109
 
110
+ // installing deps
111
+ console.log(cyan("📦 Installing server dependencies..."));
112
+ process.chdir(projectPath);
113
+ execSync("pnpm install", { stdio: "inherit" });
114
+
115
+ // Run Prisma commands
116
+ console.log(cyan("🧬 Running Prisma setup..."));
117
+ process.chdir(serverDir);
118
+ execSync("pnpm prisma:migrate:dev", { stdio: "inherit" });
119
+ execSync("pnpm prisma:generate", { stdio: "inherit" });
120
+
74
121
  console.log(green("✅ Project ready!"));
75
122
  console.log();
76
123
  console.log("Next steps:");
77
124
  console.log(` cd ${targetDir}`);
78
125
  console.log(" pnpm install");
79
126
  console.log(" pnpm dev");
80
- }
127
+ };
81
128
 
82
129
  main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-zhx-monorepo",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Create a ZHX monorepo with one command",
5
5
  "bin": {
6
6
  "create-zhx-monorepo": "bin/index.js"