@agent8/deploy 1.0.0 → 1.0.1
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 +90 -95
- package/package.json +1 -1
package/bin/agent8.js
CHANGED
|
@@ -6,7 +6,6 @@ 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;
|
|
10
9
|
|
|
11
10
|
const envFilePath = path.resolve(process.cwd(), ".env");
|
|
12
11
|
|
|
@@ -24,102 +23,98 @@ let verse = envConfig.VITE_AGENT8_VERSE;
|
|
|
24
23
|
let account = envConfig.VITE_AGENT8_ACCOUNT || "0xtest";
|
|
25
24
|
let signature = envConfig.VITE_AGENT8_SIGNATURE;
|
|
26
25
|
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
fileName: "server.js",
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Check for dist directory
|
|
50
|
-
const distDirPath = path.resolve(process.cwd(), "dist");
|
|
51
|
-
if (fs.existsSync(distDirPath) && fs.statSync(distDirPath).isDirectory()) {
|
|
52
|
-
const processDistFiles = (dirPath, basePath = "") => {
|
|
53
|
-
const files = fs.readdirSync(dirPath);
|
|
54
|
-
|
|
55
|
-
files.forEach((file) => {
|
|
56
|
-
const fullPath = path.join(dirPath, file);
|
|
57
|
-
const relativePath = path.join(basePath, file);
|
|
58
|
-
const uploadPath = path.dirname(relativePath);
|
|
59
|
-
|
|
60
|
-
if (fs.statSync(fullPath).isDirectory()) {
|
|
61
|
-
processDistFiles(fullPath, relativePath);
|
|
62
|
-
} else {
|
|
63
|
-
filesToUpload.push({
|
|
64
|
-
filePath: fullPath,
|
|
65
|
-
uploadPath: uploadPath === "." ? "" : uploadPath,
|
|
66
|
-
fileName: path.basename(file),
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
processDistFiles(distDirPath);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (filesToUpload.length === 0) {
|
|
76
|
-
console.error(
|
|
77
|
-
"No files found to upload. Make sure server.js or dist/ directory exists."
|
|
78
|
-
);
|
|
79
|
-
process.exit(1);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
console.log(`Found ${filesToUpload.length} files to upload...`);
|
|
83
|
-
|
|
84
|
-
// Upload files in parallel
|
|
85
|
-
const uploadPromises = filesToUpload.map((fileInfo) => {
|
|
86
|
-
const { filePath, uploadPath, fileName } = fileInfo;
|
|
87
|
-
const form = new FormData();
|
|
88
|
-
const fileContent = fs.readFileSync(filePath);
|
|
89
|
-
form.append("file", fileContent, fileName);
|
|
90
|
-
form.append("path", uploadPath || "/");
|
|
91
|
-
|
|
92
|
-
return axios
|
|
93
|
-
.post(`${endpoint}/verses/${verse}/files`, form, {
|
|
94
|
-
headers: {
|
|
95
|
-
...form.getHeaders(),
|
|
96
|
-
"X-Signature": signature,
|
|
97
|
-
},
|
|
98
|
-
})
|
|
99
|
-
.then(() => {
|
|
100
|
-
// 경로 출력 처리
|
|
101
|
-
console.log(`Uploaded: ${uploadPath}/${fileName}`);
|
|
102
|
-
return true;
|
|
103
|
-
})
|
|
104
|
-
.catch((error) => {
|
|
105
|
-
console.error(
|
|
106
|
-
`Error uploading ${uploadPath}/${fileName}:`,
|
|
107
|
-
error.message
|
|
108
|
-
);
|
|
109
|
-
return false;
|
|
110
|
-
});
|
|
26
|
+
if (!verse) {
|
|
27
|
+
verse = crypto.randomBytes(16).toString("hex"); // Generate a random 32-byte string
|
|
28
|
+
fs.appendFileSync(envFilePath, `VITE_AGENT8_VERSE=${verse}\n`);
|
|
29
|
+
console.log("Generated random verse and updated .env:", verse);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
console.log("Starting deployment to verse:", verse);
|
|
33
|
+
|
|
34
|
+
// Files to upload
|
|
35
|
+
const filesToUpload = [];
|
|
36
|
+
|
|
37
|
+
// Check for server.js
|
|
38
|
+
const serverFilePath = path.resolve(process.cwd(), "server.js");
|
|
39
|
+
if (fs.existsSync(serverFilePath)) {
|
|
40
|
+
filesToUpload.push({
|
|
41
|
+
filePath: serverFilePath,
|
|
42
|
+
uploadPath: "",
|
|
43
|
+
fileName: "server.js",
|
|
111
44
|
});
|
|
45
|
+
}
|
|
112
46
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
47
|
+
// Check for dist directory
|
|
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
|
+
}
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
processDistFiles(distDirPath);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (filesToUpload.length === 0) {
|
|
74
|
+
console.error(
|
|
75
|
+
"No files found to upload. Make sure server.js or dist/ directory exists."
|
|
76
|
+
);
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
console.log(`Found ${filesToUpload.length} files to upload...`);
|
|
81
|
+
|
|
82
|
+
// Upload files in parallel
|
|
83
|
+
const uploadPromises = filesToUpload.map((fileInfo) => {
|
|
84
|
+
const { filePath, uploadPath, fileName } = fileInfo;
|
|
85
|
+
const form = new FormData();
|
|
86
|
+
const fileContent = fs.readFileSync(filePath);
|
|
87
|
+
form.append("file", fileContent, fileName);
|
|
88
|
+
form.append("path", uploadPath || "/");
|
|
89
|
+
|
|
90
|
+
return axios
|
|
91
|
+
.post(`${endpoint}/verses/${verse}/files`, form, {
|
|
92
|
+
headers: {
|
|
93
|
+
...form.getHeaders(),
|
|
94
|
+
"X-Signature": signature,
|
|
95
|
+
},
|
|
96
|
+
})
|
|
97
|
+
.then(() => {
|
|
98
|
+
// 경로 출력 처리
|
|
99
|
+
console.log(`Uploaded: ${uploadPath}/${fileName}`);
|
|
100
|
+
return true;
|
|
119
101
|
})
|
|
120
102
|
.catch((error) => {
|
|
121
|
-
console.error(
|
|
103
|
+
console.error(
|
|
104
|
+
`Error uploading ${uploadPath}/${fileName}:`,
|
|
105
|
+
error.message
|
|
106
|
+
);
|
|
107
|
+
return false;
|
|
122
108
|
});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
Promise.all(uploadPromises)
|
|
112
|
+
.then((results) => {
|
|
113
|
+
const successCount = results.filter(Boolean).length;
|
|
114
|
+
console.log(
|
|
115
|
+
`Deployment complete: ${successCount}/${filesToUpload.length} files uploaded successfully.`
|
|
116
|
+
);
|
|
117
|
+
})
|
|
118
|
+
.catch((error) => {
|
|
119
|
+
console.error("Deployment failed:", error.message);
|
|
120
|
+
});
|