@agent8/deploy 1.0.1 → 1.0.2
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/agent8.js +70 -33
- package/package.json +1 -1
package/bin/agent8.js
CHANGED
|
@@ -6,13 +6,26 @@ const dotenv = require("dotenv");
|
|
|
6
6
|
const axios = require("axios");
|
|
7
7
|
const FormData = require("form-data");
|
|
8
8
|
const crypto = require("crypto");
|
|
9
|
+
const [, , command, fnName, argsString] = process.argv;
|
|
9
10
|
|
|
10
11
|
const envFilePath = path.resolve(process.cwd(), ".env");
|
|
12
|
+
const deployedFilePath = path.resolve(process.cwd(), ".deployed");
|
|
11
13
|
|
|
12
14
|
if (!fs.existsSync(envFilePath)) {
|
|
13
15
|
fs.writeFileSync(envFilePath, "");
|
|
14
16
|
}
|
|
15
17
|
|
|
18
|
+
// Load previously deployed file hashes
|
|
19
|
+
let deployedHashes = {};
|
|
20
|
+
if (fs.existsSync(deployedFilePath)) {
|
|
21
|
+
try {
|
|
22
|
+
deployedHashes = JSON.parse(fs.readFileSync(deployedFilePath, "utf8"));
|
|
23
|
+
} catch (error) {
|
|
24
|
+
console.warn("Failed to parse .deployed file, will redeploy all files");
|
|
25
|
+
deployedHashes = {};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
16
29
|
const envConfig = dotenv.parse(fs.readFileSync(envFilePath));
|
|
17
30
|
|
|
18
31
|
const endpoint =
|
|
@@ -33,48 +46,68 @@ console.log("Starting deployment to verse:", verse);
|
|
|
33
46
|
|
|
34
47
|
// Files to upload
|
|
35
48
|
const filesToUpload = [];
|
|
49
|
+
const newHashes = {};
|
|
50
|
+
|
|
51
|
+
// Calculate file hash
|
|
52
|
+
const calculateFileHash = (filePath) => {
|
|
53
|
+
const fileContent = fs.readFileSync(filePath);
|
|
54
|
+
return crypto.createHash("md5").update(fileContent).digest("hex");
|
|
55
|
+
};
|
|
36
56
|
|
|
37
57
|
// Check for server.js
|
|
38
58
|
const serverFilePath = path.resolve(process.cwd(), "server.js");
|
|
39
59
|
if (fs.existsSync(serverFilePath)) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const distDirPath = path.resolve(process.cwd(), "dist");
|
|
49
|
-
if (fs.existsSync(distDirPath) && fs.statSync(distDirPath).isDirectory()) {
|
|
50
|
-
const processDistFiles = (dirPath, basePath = "") => {
|
|
51
|
-
const files = fs.readdirSync(dirPath);
|
|
52
|
-
|
|
53
|
-
files.forEach((file) => {
|
|
54
|
-
const fullPath = path.join(dirPath, file);
|
|
55
|
-
const relativePath = path.join(basePath, file);
|
|
56
|
-
const uploadPath = path.dirname(relativePath);
|
|
57
|
-
|
|
58
|
-
if (fs.statSync(fullPath).isDirectory()) {
|
|
59
|
-
processDistFiles(fullPath, relativePath);
|
|
60
|
-
} else {
|
|
61
|
-
filesToUpload.push({
|
|
62
|
-
filePath: fullPath,
|
|
63
|
-
uploadPath: uploadPath === "." ? "" : uploadPath,
|
|
64
|
-
fileName: path.basename(file),
|
|
65
|
-
});
|
|
66
|
-
}
|
|
60
|
+
const hash = calculateFileHash(serverFilePath);
|
|
61
|
+
newHashes["server.js"] = hash;
|
|
62
|
+
|
|
63
|
+
if (hash !== deployedHashes["server.js"]) {
|
|
64
|
+
filesToUpload.push({
|
|
65
|
+
filePath: serverFilePath,
|
|
66
|
+
uploadPath: "",
|
|
67
|
+
fileName: "server.js",
|
|
67
68
|
});
|
|
68
|
-
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
69
71
|
|
|
70
|
-
|
|
72
|
+
if (command !== "server") {
|
|
73
|
+
// Check for dist directory
|
|
74
|
+
const distDirPath = path.resolve(process.cwd(), "dist");
|
|
75
|
+
if (fs.existsSync(distDirPath) && fs.statSync(distDirPath).isDirectory()) {
|
|
76
|
+
const processDistFiles = (dirPath, basePath = "") => {
|
|
77
|
+
const files = fs.readdirSync(dirPath);
|
|
78
|
+
|
|
79
|
+
files.forEach((file) => {
|
|
80
|
+
const fullPath = path.join(dirPath, file);
|
|
81
|
+
const relativePath = path.join(basePath, file);
|
|
82
|
+
const uploadPath = path.dirname(relativePath);
|
|
83
|
+
const deployKey = path
|
|
84
|
+
.join(uploadPath, path.basename(file))
|
|
85
|
+
.replace(/\\/g, "/");
|
|
86
|
+
|
|
87
|
+
if (fs.statSync(fullPath).isDirectory()) {
|
|
88
|
+
processDistFiles(fullPath, relativePath);
|
|
89
|
+
} else {
|
|
90
|
+
const hash = calculateFileHash(fullPath);
|
|
91
|
+
newHashes[deployKey] = hash;
|
|
92
|
+
|
|
93
|
+
if (hash !== deployedHashes[deployKey]) {
|
|
94
|
+
filesToUpload.push({
|
|
95
|
+
filePath: fullPath,
|
|
96
|
+
uploadPath: uploadPath === "." ? "" : uploadPath,
|
|
97
|
+
fileName: path.basename(file),
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
processDistFiles(distDirPath);
|
|
105
|
+
}
|
|
71
106
|
}
|
|
72
107
|
|
|
73
108
|
if (filesToUpload.length === 0) {
|
|
74
|
-
console.
|
|
75
|
-
|
|
76
|
-
);
|
|
77
|
-
process.exit(1);
|
|
109
|
+
console.log("No changes detected. Nothing to deploy.");
|
|
110
|
+
process.exit(0);
|
|
78
111
|
}
|
|
79
112
|
|
|
80
113
|
console.log(`Found ${filesToUpload.length} files to upload...`);
|
|
@@ -114,6 +147,10 @@ Promise.all(uploadPromises)
|
|
|
114
147
|
console.log(
|
|
115
148
|
`Deployment complete: ${successCount}/${filesToUpload.length} files uploaded successfully.`
|
|
116
149
|
);
|
|
150
|
+
|
|
151
|
+
// Save new hashes to .deployed file
|
|
152
|
+
fs.writeFileSync(deployedFilePath, JSON.stringify(newHashes, null, 2));
|
|
153
|
+
console.log("Updated .deployed file with new file hashes");
|
|
117
154
|
})
|
|
118
155
|
.catch((error) => {
|
|
119
156
|
console.error("Deployment failed:", error.message);
|