babyclara 0.0.8 → 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/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
|