create-zhx-monorepo 0.1.5 → 0.1.7

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 -9
  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,6 +70,33 @@ async function main() {
53
70
  pkg.name = targetDir;
54
71
  await fs.writeJson(pkgPath, pkg, { spaces: 2 });
55
72
 
73
+ // Rename gitignore
74
+ const gitignoreSrc = path.join(projectPath, "gitignore");
75
+ const gitignoreDest = path.join(projectPath, ".gitignore");
76
+ if (fs.existsSync(gitignoreSrc)) {
77
+ fs.renameSync(gitignoreSrc, gitignoreDest);
78
+ }
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
+
56
100
  // Init git
57
101
  process.chdir(projectPath);
58
102
  execSync("git init", { stdio: "ignore" });
@@ -63,12 +107,11 @@ async function main() {
63
107
  execSync(`git remote add origin ${gitRemote}`, { stdio: "ignore" });
64
108
  }
65
109
 
66
- const gitignoreSrc = path.join(projectPath, "gitignore");
67
- const gitignoreDest = path.join(projectPath, ".gitignore");
68
-
69
- if (fs.existsSync(gitignoreSrc)) {
70
- fs.renameSync(gitignoreSrc, gitignoreDest);
71
- }
110
+ // Run Prisma commands
111
+ console.log(cyan("🧬 Running Prisma setup..."));
112
+ process.chdir(serverDir);
113
+ execSync("pnpm prisma:migrate:dev", { stdio: "inherit" });
114
+ execSync("pnpm prisma:generate", { stdio: "inherit" });
72
115
 
73
116
  console.log(green("✅ Project ready!"));
74
117
  console.log();
@@ -76,6 +119,6 @@ async function main() {
76
119
  console.log(` cd ${targetDir}`);
77
120
  console.log(" pnpm install");
78
121
  console.log(" pnpm dev");
79
- }
122
+ };
80
123
 
81
124
  main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-zhx-monorepo",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Create a ZHX monorepo with one command",
5
5
  "bin": {
6
6
  "create-zhx-monorepo": "bin/index.js"