code-mon-space 0.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/codemon.js +28 -0
- package/package.json +16 -0
- package/src/clone.js +46 -0
- package/src/deploy.js +52 -0
- package/src/login.js +30 -0
package/bin/codemon.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import inquirer from "inquirer";
|
|
3
|
+
import { login } from "../src/login.js";
|
|
4
|
+
import { clone } from "../src/clone.js";
|
|
5
|
+
import { deployBuild } from "../src/deploy.js";
|
|
6
|
+
|
|
7
|
+
const args = process.argv.slice(2);
|
|
8
|
+
|
|
9
|
+
const command = args[0];
|
|
10
|
+
|
|
11
|
+
switch (command) {
|
|
12
|
+
case "login":
|
|
13
|
+
await login();
|
|
14
|
+
break;
|
|
15
|
+
case "clone":
|
|
16
|
+
if (!args[1]) {
|
|
17
|
+
console.log("Usage: codemon clone <project-name>");
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
await clone(args[1]);
|
|
21
|
+
break;
|
|
22
|
+
case "build":
|
|
23
|
+
await deployBuild();
|
|
24
|
+
break;
|
|
25
|
+
default:
|
|
26
|
+
console.log(`Unknown command: ${command}`);
|
|
27
|
+
console.log("Available commands: login, clone, build");
|
|
28
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "code-mon-space",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CodeMon CLI – build, clone and deploy projects",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"codemon": "./bin/codemon.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
"src"
|
|
12
|
+
],
|
|
13
|
+
"keywords": ["cli", "deploy", "codemon"],
|
|
14
|
+
"author": "C69P2W",
|
|
15
|
+
"license": "MIT"
|
|
16
|
+
}
|
package/src/clone.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import axios from "axios";
|
|
4
|
+
|
|
5
|
+
const CONFIG_PATH = path.join(
|
|
6
|
+
process.env.HOME || process.env.USERPROFILE,
|
|
7
|
+
".codemon.json"
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
export async function clone(projectName) {
|
|
11
|
+
if (!await fs.pathExists(CONFIG_PATH)) {
|
|
12
|
+
console.log("❌ Please login first: codemon login");
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const config = await fs.readJson(CONFIG_PATH);
|
|
17
|
+
|
|
18
|
+
// ✅ ensure project is saved
|
|
19
|
+
config.project = projectName;
|
|
20
|
+
await fs.writeJson(CONFIG_PATH, config);
|
|
21
|
+
|
|
22
|
+
const res = await axios.get(
|
|
23
|
+
`https://code-mon.codemon.workers.dev/api/list?user=${projectName}`
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const files = res.data.files;
|
|
27
|
+
|
|
28
|
+
const baseDir = path.join(process.cwd(), projectName);
|
|
29
|
+
|
|
30
|
+
for (const file of files) {
|
|
31
|
+
// 🚫 ignore bad legacy files
|
|
32
|
+
if (file.startsWith("undefined/")) continue;
|
|
33
|
+
|
|
34
|
+
const fileRes = await axios.get(
|
|
35
|
+
`https://code-mon.codemon.workers.dev/api/load?user=${projectName}&filename=${file}`
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const localPath = path.join(baseDir, file);
|
|
39
|
+
await fs.ensureDir(path.dirname(localPath));
|
|
40
|
+
await fs.writeFile(localPath, fileRes.data);
|
|
41
|
+
|
|
42
|
+
console.log(`✅ Saved: ${localPath}`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
console.log(`🎉 Project '${projectName}' cloned successfully into '${baseDir}'!`);
|
|
46
|
+
}
|
package/src/deploy.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import axios from "axios";
|
|
4
|
+
|
|
5
|
+
const CONFIG_PATH = path.join(
|
|
6
|
+
process.env.HOME || process.env.USERPROFILE,
|
|
7
|
+
".codemon.json"
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
export async function deployBuild() {
|
|
11
|
+
const buildDir = "dist"; // your build output
|
|
12
|
+
|
|
13
|
+
if (!await fs.pathExists(CONFIG_PATH)) {
|
|
14
|
+
console.log("❌ Please login first: codemon login");
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (!await fs.pathExists(buildDir)) {
|
|
19
|
+
console.log(`❌ Build folder not found: ${buildDir}`);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const { username, pass, project } = await fs.readJson(CONFIG_PATH);
|
|
24
|
+
|
|
25
|
+
console.log(`[codemon] Found build folder: ${buildDir}`);
|
|
26
|
+
|
|
27
|
+
const files = await fs.readdir(buildDir);
|
|
28
|
+
|
|
29
|
+
for (const file of files) {
|
|
30
|
+
const fullPath = path.join(buildDir, file);
|
|
31
|
+
|
|
32
|
+
if ((await fs.stat(fullPath)).isDirectory()) continue;
|
|
33
|
+
|
|
34
|
+
const content = await fs.readFile(fullPath, "utf8");
|
|
35
|
+
|
|
36
|
+
const filename = `${project}/${file}`; // 🔥 REQUIRED
|
|
37
|
+
|
|
38
|
+
await axios.post(
|
|
39
|
+
"https://code-mon.codemon.workers.dev/api/save",
|
|
40
|
+
{
|
|
41
|
+
user: username,
|
|
42
|
+
pass,
|
|
43
|
+
filename,
|
|
44
|
+
content
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
console.log(`[codemon] Uploaded: ${file}`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
console.log("🚀 Build deployed successfully!");
|
|
52
|
+
}
|
package/src/login.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import inquirer from "inquirer";
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import fs from "fs-extra";
|
|
4
|
+
import path from "path";
|
|
5
|
+
|
|
6
|
+
const CONFIG_PATH = path.join(process.env.HOME || process.env.USERPROFILE, ".codemon.json");
|
|
7
|
+
|
|
8
|
+
export async function login() {
|
|
9
|
+
const answers = await inquirer.prompt([
|
|
10
|
+
{ name: "username", message: "Username:" },
|
|
11
|
+
{ name: "pass", type: "password", message: "Password:" }
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
const { username, pass } = answers;
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
const res = await axios.get(`https://code-mon.codemon.workers.dev/api/pass?username=${username}&pass=${pass}`);
|
|
18
|
+
const data = res.data;
|
|
19
|
+
|
|
20
|
+
if (data.success) {
|
|
21
|
+
// save locally
|
|
22
|
+
await fs.writeJson(CONFIG_PATH, { username, pass });
|
|
23
|
+
console.log("✅ Login successful! Credentials saved locally.");
|
|
24
|
+
} else {
|
|
25
|
+
console.log("❌ Invalid username or password");
|
|
26
|
+
}
|
|
27
|
+
} catch (err) {
|
|
28
|
+
console.error("Login error:", err.message);
|
|
29
|
+
}
|
|
30
|
+
}
|