create-charcole 1.0.0 ā 1.1.0
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/bin/index.js +36 -10
- package/package.json +1 -1
package/bin/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
const path = require("path");
|
|
5
|
+
const { execSync } = require("child_process");
|
|
5
6
|
|
|
6
7
|
const projectName = process.argv[2];
|
|
7
8
|
|
|
@@ -22,11 +23,9 @@ if (fs.existsSync(targetDir)) {
|
|
|
22
23
|
|
|
23
24
|
function copyDir(src, dest) {
|
|
24
25
|
fs.mkdirSync(dest, { recursive: true });
|
|
25
|
-
|
|
26
26
|
for (const file of fs.readdirSync(src)) {
|
|
27
27
|
const srcPath = path.join(src, file);
|
|
28
28
|
const destPath = path.join(dest, file);
|
|
29
|
-
|
|
30
29
|
if (fs.statSync(srcPath).isDirectory()) {
|
|
31
30
|
copyDir(srcPath, destPath);
|
|
32
31
|
} else {
|
|
@@ -35,9 +34,24 @@ function copyDir(src, dest) {
|
|
|
35
34
|
}
|
|
36
35
|
}
|
|
37
36
|
|
|
37
|
+
function detectPackageManager() {
|
|
38
|
+
try {
|
|
39
|
+
execSync("bun -v", { stdio: "ignore" });
|
|
40
|
+
return "bun";
|
|
41
|
+
} catch {}
|
|
42
|
+
try {
|
|
43
|
+
execSync("pnpm -v", { stdio: "ignore" });
|
|
44
|
+
return "pnpm";
|
|
45
|
+
} catch {}
|
|
46
|
+
try {
|
|
47
|
+
execSync("yarn -v", { stdio: "ignore" });
|
|
48
|
+
return "yarn";
|
|
49
|
+
} catch {}
|
|
50
|
+
return "npm";
|
|
51
|
+
}
|
|
52
|
+
|
|
38
53
|
try {
|
|
39
54
|
console.log("š„ Creating Charcole app...");
|
|
40
|
-
|
|
41
55
|
copyDir(templateDir, targetDir);
|
|
42
56
|
|
|
43
57
|
const pkgPath = path.join(targetDir, "package.json");
|
|
@@ -47,14 +61,26 @@ try {
|
|
|
47
61
|
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
|
|
48
62
|
}
|
|
49
63
|
|
|
50
|
-
console.log("ā
|
|
51
|
-
|
|
52
|
-
|
|
64
|
+
console.log("ā
Project created successfully!");
|
|
65
|
+
|
|
66
|
+
const pkgManager = detectPackageManager();
|
|
67
|
+
console.log(`š¦ Installing dependencies using ${pkgManager}...`);
|
|
68
|
+
|
|
69
|
+
const installCmd =
|
|
70
|
+
pkgManager === "bun"
|
|
71
|
+
? "bun install"
|
|
72
|
+
: pkgManager === "yarn"
|
|
73
|
+
? "yarn"
|
|
74
|
+
: pkgManager === "pnpm"
|
|
75
|
+
? "pnpm install"
|
|
76
|
+
: "npm install";
|
|
77
|
+
|
|
78
|
+
execSync(installCmd, { cwd: targetDir, stdio: "inherit" });
|
|
79
|
+
|
|
80
|
+
console.log("\nš All set!");
|
|
53
81
|
console.log(` cd ${projectName}`);
|
|
54
|
-
console.log(" npm install");
|
|
55
82
|
console.log(" npm run dev");
|
|
56
|
-
console.log("");
|
|
57
|
-
console.log("š§± Built with Charcole ā Express, but engineered.");
|
|
83
|
+
console.log("\nš§± Built with Charcole ā Express, but engineered.");
|
|
58
84
|
} catch (err) {
|
|
59
85
|
console.error("ā Failed to create Charcole app.");
|
|
60
86
|
console.error(err.message);
|