code-mon-space 0.1.5 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/deploy.js +63 -34
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "code-mon-space",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "codemon": "bin/codemon.js"
package/src/deploy.js CHANGED
@@ -8,22 +8,29 @@ const CONFIG_PATH = path.join(
8
8
  ".codemon.json"
9
9
  );
10
10
 
11
- // 🔁 Recursively walk directory
12
- async function walkDir(dir, baseDir) {
13
- const entries = await fs.readdir(dir);
14
- let files = [];
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
+ }
15
22
 
16
- for (const entry of entries) {
17
- const fullPath = path.join(dir, entry);
18
- const stat = await fs.stat(fullPath);
23
+ // recursively collect all files
24
+ async function getAllFiles(dir) {
25
+ const entries = await fs.readdir(dir, { withFileTypes: true });
26
+ const files = [];
19
27
 
20
- if (stat.isDirectory()) {
21
- files.push(...await walkDir(fullPath, baseDir));
28
+ for (const entry of entries) {
29
+ const fullPath = path.join(dir, entry.name);
30
+ if (entry.isDirectory()) {
31
+ files.push(...await getAllFiles(fullPath));
22
32
  } else {
23
- files.push({
24
- localPath: fullPath,
25
- relativePath: path.relative(baseDir, fullPath)
26
- });
33
+ files.push(fullPath);
27
34
  }
28
35
  }
29
36
 
@@ -36,7 +43,7 @@ export async function deployBuild() {
36
43
  process.exit(1);
37
44
  }
38
45
 
39
- // 🔥 Ask for build directory
46
+ // 🔥 ask build folder
40
47
  const { buildDir } = await inquirer.prompt([
41
48
  {
42
49
  type: "input",
@@ -55,26 +62,48 @@ export async function deployBuild() {
55
62
 
56
63
  console.log(`[codemon] Found build folder: ${buildDir}`);
57
64
 
58
- // 🔥 Walk entire build directory
59
- const files = await walkDir(buildDir, buildDir);
60
-
61
- for (const file of files) {
62
- const content = await fs.readFile(file.localPath, "utf8");
63
-
64
- // FULL PATH: buildDir + relative file path
65
- const filename = `${buildDir}/${file.relativePath}`;
66
-
67
- await axios.post(
68
- "https://code-mon.codemon.workers.dev/api/save",
69
- {
70
- user: username,
71
- pass,
72
- filename,
73
- content
74
- }
75
- );
76
-
77
- console.log(`[codemon] Uploaded: ${filename}`);
65
+ const allFiles = await getAllFiles(buildDir);
66
+
67
+ for (const fullPath of allFiles) {
68
+ const relativePath = path.relative(process.cwd(), fullPath);
69
+ const filename = relativePath.replace(/\\/g, "/"); // windows-safe
70
+
71
+ if (isBinaryFile(fullPath)) {
72
+ // 🔥 BINARY UPLOAD
73
+ const binary = await fs.readFile(fullPath);
74
+
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
+ );
89
+
90
+ console.log(`[codemon] Uploaded (binary): ${filename}`);
91
+ } else {
92
+ // 🔥 TEXT UPLOAD
93
+ const content = await fs.readFile(fullPath, "utf8");
94
+
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
+ );
104
+
105
+ console.log(`[codemon] Uploaded: ${filename}`);
106
+ }
78
107
  }
79
108
 
80
109
  console.log("🚀 Build deployed successfully!");