@agent8/deploy 1.0.9 → 1.1.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/bin/agent8.js +59 -15
- package/package.json +1 -1
package/bin/agent8.js
CHANGED
|
@@ -6,7 +6,11 @@ const dotenv = require("dotenv");
|
|
|
6
6
|
const axios = require("axios");
|
|
7
7
|
const FormData = require("form-data");
|
|
8
8
|
const crypto = require("crypto");
|
|
9
|
-
|
|
9
|
+
|
|
10
|
+
// Parse command line arguments
|
|
11
|
+
const args = process.argv.slice(2);
|
|
12
|
+
const previewMode = args.includes("--preview");
|
|
13
|
+
const prodMode = args.includes("--prod");
|
|
10
14
|
|
|
11
15
|
const envFilePath = path.resolve(process.cwd(), ".env");
|
|
12
16
|
const deployedFilePath = path.resolve(process.cwd(), ".deployed");
|
|
@@ -33,16 +37,46 @@ const endpoint =
|
|
|
33
37
|
"https://verse8-simple-game-backend-609824224664.asia-northeast3.run.app";
|
|
34
38
|
|
|
35
39
|
let verse = envConfig.VITE_AGENT8_VERSE;
|
|
36
|
-
let account = envConfig.VITE_AGENT8_ACCOUNT
|
|
37
|
-
|
|
40
|
+
let account = envConfig.VITE_AGENT8_ACCOUNT;
|
|
41
|
+
const accessToken = process.env.V8_ACCESS_TOKEN;
|
|
38
42
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
// Check required variables based on mode
|
|
44
|
+
if (previewMode || prodMode) {
|
|
45
|
+
if (!account) {
|
|
46
|
+
console.error("Error: VITE_AGENT8_ACCOUNT is required in .env file");
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (!accessToken) {
|
|
51
|
+
console.error("Error: V8_ACCESS_TOKEN environment variable is required");
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (prodMode && !verse) {
|
|
56
|
+
console.error(
|
|
57
|
+
"Error: VITE_AGENT8_VERSE is required in .env file for production mode"
|
|
58
|
+
);
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
43
61
|
}
|
|
44
62
|
|
|
45
|
-
|
|
63
|
+
// Determine target verse based on mode
|
|
64
|
+
let targetVerse = verse;
|
|
65
|
+
if (previewMode) {
|
|
66
|
+
targetVerse = `${account}-preview`;
|
|
67
|
+
console.log("Preview mode: Deploying to preview verse:", targetVerse);
|
|
68
|
+
} else if (prodMode) {
|
|
69
|
+
console.log("Production mode: Deploying to verse:", targetVerse);
|
|
70
|
+
} else {
|
|
71
|
+
// Default mode (original behavior)
|
|
72
|
+
if (!verse) {
|
|
73
|
+
verse = crypto.randomBytes(16).toString("hex"); // Generate a random 32-byte string
|
|
74
|
+
fs.appendFileSync(envFilePath, `\nVITE_AGENT8_VERSE=${verse}\n`);
|
|
75
|
+
console.log("Generated random verse and updated .env:", verse);
|
|
76
|
+
}
|
|
77
|
+
targetVerse = verse;
|
|
78
|
+
console.log("Default mode: Deploying to verse:", targetVerse);
|
|
79
|
+
}
|
|
46
80
|
|
|
47
81
|
// Files to upload
|
|
48
82
|
const filesToUpload = [];
|
|
@@ -78,7 +112,7 @@ if (fs.existsSync(serverFilePath)) {
|
|
|
78
112
|
}
|
|
79
113
|
}
|
|
80
114
|
|
|
81
|
-
if (
|
|
115
|
+
if (!previewMode) {
|
|
82
116
|
// Check for dist directory
|
|
83
117
|
const distDirPath = path.resolve(process.cwd(), "dist");
|
|
84
118
|
if (fs.existsSync(distDirPath) && fs.statSync(distDirPath).isDirectory()) {
|
|
@@ -121,6 +155,20 @@ if (filesToUpload.length === 0) {
|
|
|
121
155
|
|
|
122
156
|
console.log(`Found ${filesToUpload.length} files to upload...`);
|
|
123
157
|
|
|
158
|
+
// Prepare authentication headers based on mode
|
|
159
|
+
const getAuthHeaders = (formHeaders) => {
|
|
160
|
+
if (previewMode || prodMode) {
|
|
161
|
+
return {
|
|
162
|
+
...formHeaders,
|
|
163
|
+
Authorization: `Bearer ${accessToken}`,
|
|
164
|
+
};
|
|
165
|
+
} else {
|
|
166
|
+
return {
|
|
167
|
+
...formHeaders,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
|
|
124
172
|
// Upload files in parallel
|
|
125
173
|
const uploadPromises = filesToUpload.map((fileInfo) => {
|
|
126
174
|
const { filePath, uploadPath, fileName } = fileInfo;
|
|
@@ -130,14 +178,10 @@ const uploadPromises = filesToUpload.map((fileInfo) => {
|
|
|
130
178
|
form.append("path", uploadPath || "/");
|
|
131
179
|
|
|
132
180
|
return axios
|
|
133
|
-
.post(`${endpoint}/verses/${
|
|
134
|
-
headers:
|
|
135
|
-
...form.getHeaders(),
|
|
136
|
-
"X-Signature": signature,
|
|
137
|
-
},
|
|
181
|
+
.post(`${endpoint}/verses/${targetVerse}/files`, form, {
|
|
182
|
+
headers: getAuthHeaders(form.getHeaders()),
|
|
138
183
|
})
|
|
139
184
|
.then(() => {
|
|
140
|
-
// 경로 출력 처리
|
|
141
185
|
console.log(`Uploaded: ${uploadPath}/${fileName}`);
|
|
142
186
|
return true;
|
|
143
187
|
})
|