code-mon-space 0.1.4 → 0.1.6

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.6",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "codemon": "bin/codemon.js"
package/src/deploy.js CHANGED
@@ -1,51 +1,109 @@
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
+ // file extensions that MUST be treated as binary
12
+ const BINARY_EXTENSIONS = new Set([
13
+ ".png", ".jpg", ".jpeg", ".gif", ".webp", ".svg",
14
+ ".mp4", ".mp3", ".wav", ".ogg",
15
+ ".woff", ".woff2", ".ttf", ".eot",
16
+ ".ico", ".pdf"
17
+ ]);
18
+
19
+ function isBinaryFile(filePath) {
20
+ return BINARY_EXTENSIONS.has(path.extname(filePath).toLowerCase());
21
+ }
22
+
23
+ // recursively collect all files
24
+ async function getAllFiles(dir) {
25
+ const entries = await fs.readdir(dir, { withFileTypes: true });
26
+ const files = [];
27
+
28
+ for (const entry of entries) {
29
+ const fullPath = path.join(dir, entry.name);
30
+ if (entry.isDirectory()) {
31
+ files.push(...await getAllFiles(fullPath));
32
+ } else {
33
+ files.push(fullPath);
34
+ }
35
+ }
36
+
37
+ return files;
38
+ }
12
39
 
13
- if (!await fs.pathExists(CONFIG_PATH)) {
40
+ export async function deployBuild() {
41
+ if (!(await fs.pathExists(CONFIG_PATH))) {
14
42
  console.log("❌ Please login first: codemon login");
15
43
  process.exit(1);
16
44
  }
17
45
 
18
- if (!await fs.pathExists(buildDir)) {
46
+ // 🔥 ask build folder
47
+ const { buildDir } = await inquirer.prompt([
48
+ {
49
+ type: "input",
50
+ name: "buildDir",
51
+ message: "Enter build directory (dist, build, out, etc):",
52
+ default: "dist"
53
+ }
54
+ ]);
55
+
56
+ if (!(await fs.pathExists(buildDir))) {
19
57
  console.log(`❌ Build folder not found: ${buildDir}`);
20
58
  process.exit(1);
21
59
  }
22
60
 
23
- const { username, pass, project } = await fs.readJson(CONFIG_PATH);
61
+ const { username, pass } = await fs.readJson(CONFIG_PATH);
24
62
 
25
63
  console.log(`[codemon] Found build folder: ${buildDir}`);
26
64
 
27
- const files = await fs.readdir(buildDir);
65
+ const allFiles = await getAllFiles(buildDir);
28
66
 
29
- for (const file of files) {
30
- const fullPath = path.join(buildDir, file);
67
+ for (const fullPath of allFiles) {
68
+ const relativePath = path.relative(process.cwd(), fullPath);
69
+ const filename = relativePath.replace(/\\/g, "/"); // windows-safe
31
70
 
32
- if ((await fs.stat(fullPath)).isDirectory()) continue;
71
+ if (isBinaryFile(fullPath)) {
72
+ // 🔥 BINARY UPLOAD
73
+ const binary = await fs.readFile(fullPath);
33
74
 
34
- const content = await fs.readFile(fullPath, "utf8");
75
+ await axios.post(
76
+ "https://code-mon.codemon.workers.dev/api/img-save",
77
+ binary,
78
+ {
79
+ headers: {
80
+ "Content-Type": "application/octet-stream",
81
+ "x-user": username,
82
+ "x-pass": pass,
83
+ "x-filename": filename
84
+ },
85
+ maxBodyLength: Infinity,
86
+ maxContentLength: Infinity
87
+ }
88
+ );
35
89
 
36
- const filename = `${project}/${file}`; // 🔥 REQUIRED
90
+ console.log(`[codemon] Uploaded (binary): ${filename}`);
91
+ } else {
92
+ // 🔥 TEXT UPLOAD
93
+ const content = await fs.readFile(fullPath, "utf8");
37
94
 
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
- );
95
+ await axios.post(
96
+ "https://code-mon.codemon.workers.dev/api/save",
97
+ {
98
+ user: username,
99
+ pass,
100
+ filename,
101
+ content
102
+ }
103
+ );
47
104
 
48
- console.log(`[codemon] Uploaded: ${file}`);
105
+ console.log(`[codemon] Uploaded: ${filename}`);
106
+ }
49
107
  }
50
108
 
51
109
  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
+ }