babyclara 0.0.2 → 0.0.4
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/index.js +43 -27
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -4,49 +4,65 @@ const fs = require("fs");
|
|
|
4
4
|
const path = require("path");
|
|
5
5
|
const { execSync } = require("child_process");
|
|
6
6
|
|
|
7
|
-
// Folders in your npm package to copy
|
|
8
|
-
// key = folder in CLI package
|
|
9
|
-
// value = destination folder name inside user's project
|
|
10
7
|
const foldersToCopy = [
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
{ from: "template", to: "." },
|
|
9
|
+
{ from: "data", to: "data" }
|
|
13
10
|
];
|
|
14
11
|
|
|
15
|
-
// Target folder (user directory)
|
|
16
12
|
const targetDir = process.cwd();
|
|
17
13
|
|
|
18
|
-
//
|
|
14
|
+
// Recursive folder copy
|
|
19
15
|
function copyFolder(src, dest) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
if (!fs.existsSync(dest)) {
|
|
17
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
18
|
+
}
|
|
23
19
|
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
const items = fs.readdirSync(src);
|
|
21
|
+
if (items.length === 0) return;
|
|
26
22
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
items.forEach(item => {
|
|
24
|
+
const from = path.join(src, item);
|
|
25
|
+
const to = path.join(dest, item);
|
|
30
26
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
if (fs.lstatSync(from).isDirectory()) {
|
|
28
|
+
copyFolder(from, to);
|
|
29
|
+
} else {
|
|
30
|
+
fs.copyFileSync(from, to);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
37
33
|
}
|
|
38
34
|
|
|
39
35
|
console.log("Generating Work Station...");
|
|
40
36
|
|
|
41
|
-
// Copy template and data folders
|
|
42
37
|
foldersToCopy.forEach(folder => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
const src = path.join(__dirname, folder.from);
|
|
39
|
+
const dest = path.join(targetDir, folder.to);
|
|
40
|
+
copyFolder(src, dest);
|
|
46
41
|
});
|
|
47
42
|
|
|
48
|
-
// Install gkrane
|
|
43
|
+
// Install gkrane
|
|
49
44
|
console.log("Installing Dependencies...");
|
|
50
|
-
execSync("npm install gkrane", { cwd: targetDir, stdio: "inherit" });
|
|
45
|
+
execSync("npm install gkrane chokidar", { cwd: targetDir, stdio: "inherit" });
|
|
46
|
+
|
|
47
|
+
// Modify package.json
|
|
48
|
+
const pkgPath = path.join(targetDir, "package.json");
|
|
49
|
+
|
|
50
|
+
if (fs.existsSync(pkgPath)) {
|
|
51
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
52
|
+
|
|
53
|
+
pkg.scripts = pkg.scripts || {};
|
|
54
|
+
|
|
55
|
+
pkg.scripts.start =
|
|
56
|
+
"npx chokidar \"**/*\" \"!apps/**\" \"!games/**\" -c \"node ./node_modules/gkrane/core/index.js\"";
|
|
57
|
+
|
|
58
|
+
pkg.scripts.dev =
|
|
59
|
+
"node ./node_modules/gkrane/core/dev.js";
|
|
60
|
+
|
|
61
|
+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
|
|
62
|
+
|
|
63
|
+
console.log("Updated package.json scripts successfully.");
|
|
64
|
+
} else {
|
|
65
|
+
console.warn("⚠️ No package.json found — cannot add scripts.");
|
|
66
|
+
}
|
|
51
67
|
|
|
52
68
|
console.log("Done!");
|