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.
- package/package.json +1 -1
- package/src/deploy.js +63 -34
package/package.json
CHANGED
package/src/deploy.js
CHANGED
|
@@ -8,22 +8,29 @@ const CONFIG_PATH = path.join(
|
|
|
8
8
|
".codemon.json"
|
|
9
9
|
);
|
|
10
10
|
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
21
|
-
|
|
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
|
-
// 🔥
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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!");
|