babyclara 0.0.7 → 0.0.9
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/core/index.js +21 -1
- package/core/load.js +53 -0
- package/core/serve.js +62 -0
- package/functions/index.js +0 -0
- package/index.js +24 -11
- package/package.json +1 -1
package/core/index.js
CHANGED
|
@@ -1 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
const path = require("path");
|
|
2
|
+
|
|
3
|
+
const load = require("./load");
|
|
4
|
+
const serve = require("./serve");
|
|
5
|
+
|
|
6
|
+
// Dynamically load data/index.js from project root
|
|
7
|
+
const dataPath = path.join(process.cwd(), "data", "index.js");
|
|
8
|
+
const { apps = [], games = [] } = require(dataPath);
|
|
9
|
+
|
|
10
|
+
const init = async () => {
|
|
11
|
+
console.log("Work Station Launched");
|
|
12
|
+
|
|
13
|
+
// Step 1: Load all projects concurrently
|
|
14
|
+
console.log("[SETUP] Loading all projects...");
|
|
15
|
+
await Promise.all(apps.map((app) => load(app, "app")));
|
|
16
|
+
await Promise.all(games.map((game) => load(game, "game")));
|
|
17
|
+
|
|
18
|
+
// await serve();
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
init();
|
package/core/load.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
|
|
4
|
+
// const axios = require("axios");
|
|
5
|
+
|
|
6
|
+
const { createStore, createRouter, saveRoutes } = require("../functions");
|
|
7
|
+
|
|
8
|
+
const load = async (project, type) => {
|
|
9
|
+
console.log(`Loading ${type} project: ${project}`);
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
// const globalFiles = await axios.get(
|
|
13
|
+
// "https://babyclara.nw.r.appspot.com/api/userid"
|
|
14
|
+
// );
|
|
15
|
+
// const projectFiles = await axios.get(
|
|
16
|
+
// `https://babyclara.nw.r.appspot.com/api/userid/${project}`
|
|
17
|
+
// );
|
|
18
|
+
|
|
19
|
+
const projectFolder = path.join(process.cwd(), `${type}s`, project);
|
|
20
|
+
const projectSrcFolder = path.join(projectFolder, "src");
|
|
21
|
+
|
|
22
|
+
// 1️⃣ Copy global files to project root
|
|
23
|
+
for (const file of globalFiles.data) {
|
|
24
|
+
// const { fileName, data } = file;
|
|
25
|
+
// const targetPath = path.join(projectFolder, fileName);
|
|
26
|
+
// const targetDir = path.dirname(targetPath);
|
|
27
|
+
|
|
28
|
+
// fs.mkdirSync(targetDir, { recursive: true });
|
|
29
|
+
// fs.writeFileSync(targetPath, data);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
console.log(projectFiles.data)
|
|
33
|
+
|
|
34
|
+
// // 2️⃣ Copy project files to project/src
|
|
35
|
+
for (const file of projectFiles.data) {
|
|
36
|
+
// const { fileName, data } = file;
|
|
37
|
+
// const targetPath = path.join(projectSrcFolder, fileName);
|
|
38
|
+
// const targetDir = path.dirname(targetPath);
|
|
39
|
+
|
|
40
|
+
// fs.mkdirSync(targetDir, { recursive: true });
|
|
41
|
+
// fs.writeFileSync(targetPath, data);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// 3️⃣ Create Router inside /src/router
|
|
45
|
+
await saveRoutes(project);
|
|
46
|
+
await createRouter(project);
|
|
47
|
+
await createStore(project);
|
|
48
|
+
} catch (err) {
|
|
49
|
+
console.error("Failed to load files:", err);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
module.exports = load;
|
package/core/serve.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const path = require("path");
|
|
2
|
+
const { spawn } = require("child_process");
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
// Root folder containing apps/ and games/
|
|
6
|
+
const rootDir = process.cwd();
|
|
7
|
+
|
|
8
|
+
// Helper: run a command
|
|
9
|
+
function runCommand(cmd, cwd, env = {}) {
|
|
10
|
+
const [command, ...args] = cmd.split(" ");
|
|
11
|
+
const proc = spawn(command, args, {
|
|
12
|
+
cwd,
|
|
13
|
+
stdio: "inherit",
|
|
14
|
+
shell: true,
|
|
15
|
+
env: { ...process.env, ...env },
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
proc.on("close", (code) =>
|
|
20
|
+
code === 0 ? resolve() : reject(new Error(`Command failed: ${cmd}`))
|
|
21
|
+
);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const init = async () => {
|
|
26
|
+
const finalProjects = [
|
|
27
|
+
...apps.map((app) => ({
|
|
28
|
+
name: app,
|
|
29
|
+
path: path.join(rootDir, "apps", app),
|
|
30
|
+
})),
|
|
31
|
+
...games.map((game) => ({
|
|
32
|
+
name: game,
|
|
33
|
+
path: path.join(rootDir, "games", game),
|
|
34
|
+
})),
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
if (finalProjects.length === 0) {
|
|
38
|
+
console.log("❌ No apps or games found in /data.");
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const basePort = 3000;
|
|
43
|
+
|
|
44
|
+
const projectsWithPorts = finalProjects.map((proj, index) => ({
|
|
45
|
+
...proj,
|
|
46
|
+
port: basePort + index,
|
|
47
|
+
}));
|
|
48
|
+
|
|
49
|
+
projectsWithPorts.forEach(({ name, port }) => {
|
|
50
|
+
console.log(`✔ ${name} will run at http://localhost:${port}`);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
console.log("\n[SETUP] Starting Vite servers...\n");
|
|
54
|
+
|
|
55
|
+
await Promise.all(
|
|
56
|
+
projectsWithPorts.map(({ path, port }) =>
|
|
57
|
+
runCommand(`npx vite --port ${port}`, path)
|
|
58
|
+
)
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
module.exports = init;
|
|
File without changes
|
package/index.js
CHANGED
|
@@ -34,28 +34,43 @@ function copyFolder(src, dest) {
|
|
|
34
34
|
|
|
35
35
|
console.log("Generating Work Station...");
|
|
36
36
|
|
|
37
|
+
// Copy folders
|
|
37
38
|
foldersToCopy.forEach(folder => {
|
|
38
39
|
const src = path.join(__dirname, folder.from);
|
|
39
40
|
const dest = path.join(targetDir, folder.to);
|
|
40
41
|
copyFolder(src, dest);
|
|
41
42
|
});
|
|
42
43
|
|
|
43
|
-
// Install
|
|
44
|
+
// Install dependencies
|
|
44
45
|
console.log("Installing Dependencies...");
|
|
45
|
-
execSync("npm install gkrane cross-env --save", {
|
|
46
|
+
execSync("npm install gkrane cross-env --save", {
|
|
47
|
+
cwd: targetDir,
|
|
48
|
+
stdio: "inherit"
|
|
49
|
+
});
|
|
46
50
|
|
|
47
|
-
// Move local ./core into node_modules/core
|
|
51
|
+
// Move local ./core into node_modules/babyclara/core
|
|
48
52
|
const localCore = path.join(targetDir, "core");
|
|
49
|
-
const
|
|
53
|
+
const babyclaraCore = path.join(
|
|
54
|
+
targetDir,
|
|
55
|
+
"node_modules",
|
|
56
|
+
"babyclara",
|
|
57
|
+
"core"
|
|
58
|
+
);
|
|
50
59
|
|
|
51
60
|
if (fs.existsSync(localCore)) {
|
|
52
|
-
console.log("Moving ./core into node_modules/core...");
|
|
53
|
-
copyFolder(localCore,
|
|
61
|
+
console.log("Moving ./core into node_modules/babyclara/core...");
|
|
62
|
+
copyFolder(localCore, babyclaraCore);
|
|
54
63
|
fs.rmSync(localCore, { recursive: true, force: true });
|
|
55
64
|
} else {
|
|
56
65
|
console.log("No local ./core folder found, skipping move.");
|
|
57
66
|
}
|
|
58
67
|
|
|
68
|
+
// Delete template folder after setup
|
|
69
|
+
const templatePath = path.join(targetDir, "template");
|
|
70
|
+
if (fs.existsSync(templatePath)) {
|
|
71
|
+
console.log("Removing template folder...");
|
|
72
|
+
fs.rmSync(templatePath, { recursive: true, force: true });
|
|
73
|
+
}
|
|
59
74
|
|
|
60
75
|
// Modify package.json
|
|
61
76
|
const pkgPath = path.join(targetDir, "package.json");
|
|
@@ -65,15 +80,13 @@ if (fs.existsSync(pkgPath)) {
|
|
|
65
80
|
|
|
66
81
|
pkg.scripts = pkg.scripts || {};
|
|
67
82
|
|
|
68
|
-
|
|
69
|
-
|
|
83
|
+
pkg.scripts.start =
|
|
84
|
+
"node ./node_modules/babyclara/core/index.js";
|
|
70
85
|
|
|
71
|
-
// Build script (with ENV: BUILD=true)
|
|
72
86
|
pkg.scripts.build =
|
|
73
|
-
"cross-env BUILD=true node ./node_modules/core/index.js";
|
|
87
|
+
"cross-env BUILD=true node ./node_modules/babyclara/core/index.js";
|
|
74
88
|
|
|
75
89
|
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
|
|
76
|
-
|
|
77
90
|
console.log("Updated package.json scripts successfully.");
|
|
78
91
|
} else {
|
|
79
92
|
console.warn("⚠️ No package.json found — cannot add scripts.");
|