@agent8/deploy 1.0.0
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/.env +0 -0
- package/bin/agent8.js +125 -0
- package/package.json +17 -0
package/.env
ADDED
|
File without changes
|
package/bin/agent8.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const dotenv = require("dotenv");
|
|
6
|
+
const axios = require("axios");
|
|
7
|
+
const FormData = require("form-data");
|
|
8
|
+
const crypto = require("crypto");
|
|
9
|
+
const [, , command, fnName, argsString] = process.argv;
|
|
10
|
+
|
|
11
|
+
const envFilePath = path.resolve(process.cwd(), ".env");
|
|
12
|
+
|
|
13
|
+
if (!fs.existsSync(envFilePath)) {
|
|
14
|
+
fs.writeFileSync(envFilePath, "");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const envConfig = dotenv.parse(fs.readFileSync(envFilePath));
|
|
18
|
+
|
|
19
|
+
const endpoint =
|
|
20
|
+
envConfig.VITE_AGENT8_REMOTE_URL ||
|
|
21
|
+
"https://verse8-simple-game-backend-609824224664.asia-northeast3.run.app";
|
|
22
|
+
|
|
23
|
+
let verse = envConfig.VITE_AGENT8_VERSE;
|
|
24
|
+
let account = envConfig.VITE_AGENT8_ACCOUNT || "0xtest";
|
|
25
|
+
let signature = envConfig.VITE_AGENT8_SIGNATURE;
|
|
26
|
+
|
|
27
|
+
if (command === "deploy") {
|
|
28
|
+
if (!verse) {
|
|
29
|
+
verse = crypto.randomBytes(16).toString("hex"); // Generate a random 32-byte string
|
|
30
|
+
fs.appendFileSync(envFilePath, `VITE_AGENT8_VERSE=${verse}\n`);
|
|
31
|
+
console.log("Generated random verse and updated .env:", verse);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
console.log("Starting deployment to verse:", verse);
|
|
35
|
+
|
|
36
|
+
// Files to upload
|
|
37
|
+
const filesToUpload = [];
|
|
38
|
+
|
|
39
|
+
// Check for server.js
|
|
40
|
+
const serverFilePath = path.resolve(process.cwd(), "server.js");
|
|
41
|
+
if (fs.existsSync(serverFilePath)) {
|
|
42
|
+
filesToUpload.push({
|
|
43
|
+
filePath: serverFilePath,
|
|
44
|
+
uploadPath: "",
|
|
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
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
Promise.all(uploadPromises)
|
|
114
|
+
.then((results) => {
|
|
115
|
+
const successCount = results.filter(Boolean).length;
|
|
116
|
+
console.log(
|
|
117
|
+
`Deployment complete: ${successCount}/${filesToUpload.length} files uploaded successfully.`
|
|
118
|
+
);
|
|
119
|
+
})
|
|
120
|
+
.catch((error) => {
|
|
121
|
+
console.error("Deployment failed:", error.message);
|
|
122
|
+
});
|
|
123
|
+
} else {
|
|
124
|
+
console.log(`Unknown command: ${command}`);
|
|
125
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agent8/deploy",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A CLI tool for running agent8 commands",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"agent8": "./bin/agent8.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"run": "node ./bin/agent8.js run"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"axios": "^1.7.9",
|
|
14
|
+
"dotenv": "^16.4.7",
|
|
15
|
+
"form-data": "^4.0.1"
|
|
16
|
+
}
|
|
17
|
+
}
|