code-mon-space 0.1.4 → 0.1.5

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 CHANGED
@@ -3,6 +3,8 @@ import inquirer from "inquirer";
3
3
  import { login } from "../src/login.js";
4
4
  import { clone } from "../src/clone.js";
5
5
  import { deployBuild } from "../src/deploy.js";
6
+ import setProject from "../src/setproject.js";
7
+ import whoami from "../src/whoami.js";
6
8
 
7
9
  const args = process.argv.slice(2);
8
10
 
@@ -22,6 +24,13 @@ switch (command) {
22
24
  case "build":
23
25
  await deployBuild();
24
26
  break;
27
+ case "setproject":
28
+ setProject(process.argv[3]);
29
+ break;
30
+ case "whoami":
31
+ whoami();
32
+ break;
33
+
25
34
  default:
26
35
  console.log(`Unknown command: ${command}`);
27
36
  console.log("Available commands: login, clone, build");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "code-mon-space",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "codemon": "bin/codemon.js"
package/src/deploy.js CHANGED
@@ -1,39 +1,68 @@
1
1
  import fs from "fs-extra";
2
2
  import path from "path";
3
3
  import axios from "axios";
4
+ import inquirer from "inquirer";
4
5
 
5
6
  const CONFIG_PATH = path.join(
6
7
  process.env.HOME || process.env.USERPROFILE,
7
8
  ".codemon.json"
8
9
  );
9
10
 
10
- export async function deployBuild() {
11
- const buildDir = "dist"; // your build output
11
+ // 🔁 Recursively walk directory
12
+ async function walkDir(dir, baseDir) {
13
+ const entries = await fs.readdir(dir);
14
+ let files = [];
15
+
16
+ for (const entry of entries) {
17
+ const fullPath = path.join(dir, entry);
18
+ const stat = await fs.stat(fullPath);
19
+
20
+ if (stat.isDirectory()) {
21
+ files.push(...await walkDir(fullPath, baseDir));
22
+ } else {
23
+ files.push({
24
+ localPath: fullPath,
25
+ relativePath: path.relative(baseDir, fullPath)
26
+ });
27
+ }
28
+ }
29
+
30
+ return files;
31
+ }
12
32
 
13
- if (!await fs.pathExists(CONFIG_PATH)) {
33
+ export async function deployBuild() {
34
+ if (!(await fs.pathExists(CONFIG_PATH))) {
14
35
  console.log("❌ Please login first: codemon login");
15
36
  process.exit(1);
16
37
  }
17
38
 
18
- if (!await fs.pathExists(buildDir)) {
39
+ // 🔥 Ask for build directory
40
+ const { buildDir } = await inquirer.prompt([
41
+ {
42
+ type: "input",
43
+ name: "buildDir",
44
+ message: "Enter build directory (dist, build, out, etc):",
45
+ default: "dist"
46
+ }
47
+ ]);
48
+
49
+ if (!(await fs.pathExists(buildDir))) {
19
50
  console.log(`❌ Build folder not found: ${buildDir}`);
20
51
  process.exit(1);
21
52
  }
22
53
 
23
- const { username, pass, project } = await fs.readJson(CONFIG_PATH);
54
+ const { username, pass } = await fs.readJson(CONFIG_PATH);
24
55
 
25
56
  console.log(`[codemon] Found build folder: ${buildDir}`);
26
57
 
27
- const files = await fs.readdir(buildDir);
58
+ // 🔥 Walk entire build directory
59
+ const files = await walkDir(buildDir, buildDir);
28
60
 
29
61
  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");
62
+ const content = await fs.readFile(file.localPath, "utf8");
35
63
 
36
- const filename = `${project}/${file}`; // 🔥 REQUIRED
64
+ // FULL PATH: buildDir + relative file path
65
+ const filename = `${buildDir}/${file.relativePath}`;
37
66
 
38
67
  await axios.post(
39
68
  "https://code-mon.codemon.workers.dev/api/save",
@@ -45,7 +74,7 @@ export async function deployBuild() {
45
74
  }
46
75
  );
47
76
 
48
- console.log(`[codemon] Uploaded: ${file}`);
77
+ console.log(`[codemon] Uploaded: ${filename}`);
49
78
  }
50
79
 
51
80
  console.log("🚀 Build deployed successfully!");
@@ -0,0 +1,25 @@
1
+ import fs from "fs";
2
+ import os from "os";
3
+ import path from "path";
4
+
5
+ const configPath = path.join(os.homedir(), ".codemon.json");
6
+
7
+ export default function setProject(projectName) {
8
+ if (!projectName) {
9
+ console.error("❌ Please provide a project name");
10
+ process.exit(1);
11
+ }
12
+
13
+ if (!fs.existsSync(configPath)) {
14
+ console.error("❌ Not logged in. Run `codemon login`");
15
+ process.exit(1);
16
+ }
17
+
18
+ const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
19
+
20
+ config.project = projectName;
21
+
22
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
23
+
24
+ console.log(`✅ Active project set to: ${projectName}`);
25
+ }
package/src/whoami.js ADDED
@@ -0,0 +1,21 @@
1
+ import fs from "fs";
2
+ import os from "os";
3
+ import path from "path";
4
+
5
+ const configPath = path.join(os.homedir(), ".codemon.json");
6
+
7
+ export default function whoami() {
8
+ if (!fs.existsSync(configPath)) {
9
+ console.log("❌ Not logged in");
10
+ return;
11
+ }
12
+
13
+ const { username, project } = JSON.parse(
14
+ fs.readFileSync(configPath, "utf8")
15
+ );
16
+
17
+ console.log(`👤 Username: ${username}`);
18
+ if (project) {
19
+ console.log(`📦 Active project: ${project}`);
20
+ }
21
+ }