@agent8/deploy 1.1.1 → 1.3.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 +96 -19
- package/package.json +1 -1
package/bin/agent8.js
CHANGED
|
@@ -14,6 +14,7 @@ const prodMode = args.includes("--prod");
|
|
|
14
14
|
|
|
15
15
|
const envFilePath = path.resolve(process.cwd(), ".env");
|
|
16
16
|
const deployedFilePath = path.resolve(process.cwd(), ".deployed");
|
|
17
|
+
const crossrampFilePath = path.resolve(process.cwd(), ".crossramp");
|
|
17
18
|
|
|
18
19
|
if (!fs.existsSync(envFilePath)) {
|
|
19
20
|
fs.writeFileSync(envFilePath, "");
|
|
@@ -34,7 +35,7 @@ const envConfig = dotenv.parse(fs.readFileSync(envFilePath));
|
|
|
34
35
|
|
|
35
36
|
const endpoint =
|
|
36
37
|
envConfig.VITE_AGENT8_REMOTE_URL ||
|
|
37
|
-
"https://verse8-
|
|
38
|
+
"https://verse8-game-backend-kr-609824224664.asia-northeast3.run.app";
|
|
38
39
|
|
|
39
40
|
let verse = envConfig.VITE_AGENT8_VERSE;
|
|
40
41
|
let account = envConfig.VITE_AGENT8_ACCOUNT;
|
|
@@ -58,12 +59,19 @@ if (previewMode || prodMode) {
|
|
|
58
59
|
);
|
|
59
60
|
process.exit(1);
|
|
60
61
|
}
|
|
62
|
+
|
|
63
|
+
if (previewMode && !verse) {
|
|
64
|
+
console.error(
|
|
65
|
+
"Error: VITE_AGENT8_VERSE is required in .env file for preview mode"
|
|
66
|
+
);
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
61
69
|
}
|
|
62
70
|
|
|
63
71
|
// Determine target verse based on mode
|
|
64
72
|
let targetVerse = verse;
|
|
65
73
|
if (previewMode) {
|
|
66
|
-
targetVerse = `${
|
|
74
|
+
targetVerse = `${verse}-preview`;
|
|
67
75
|
console.log("Preview mode: Deploying to preview verse:", targetVerse);
|
|
68
76
|
} else if (prodMode) {
|
|
69
77
|
console.log("Production mode: Deploying to verse:", targetVerse);
|
|
@@ -78,6 +86,64 @@ if (previewMode) {
|
|
|
78
86
|
console.log("Default mode: Deploying to verse:", targetVerse);
|
|
79
87
|
}
|
|
80
88
|
|
|
89
|
+
// Prepare authentication headers based on mode
|
|
90
|
+
function getAuthHeaders(formHeaders = {}) {
|
|
91
|
+
if (previewMode || prodMode) {
|
|
92
|
+
return {
|
|
93
|
+
...formHeaders,
|
|
94
|
+
Authorization: `Bearer ${accessToken}`,
|
|
95
|
+
};
|
|
96
|
+
} else {
|
|
97
|
+
return {
|
|
98
|
+
...formHeaders,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// CrossRamp setup API call
|
|
104
|
+
async function setupCrossRamp(verse, config) {
|
|
105
|
+
try {
|
|
106
|
+
const response = await axios.post(
|
|
107
|
+
`${endpoint}/verses/${verse}/crossramp/setup`,
|
|
108
|
+
{
|
|
109
|
+
uuid: config.uuid,
|
|
110
|
+
project_id: config.project_id,
|
|
111
|
+
},
|
|
112
|
+
{ headers: getAuthHeaders() }
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
console.log("CrossRamp setup successful:", response.data.config);
|
|
116
|
+
return true;
|
|
117
|
+
} catch (error) {
|
|
118
|
+
console.error(
|
|
119
|
+
"CrossRamp setup failed:",
|
|
120
|
+
error.response?.data?.message || error.message
|
|
121
|
+
);
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Load CrossRamp configuration if exists
|
|
127
|
+
let crossrampConfig = null;
|
|
128
|
+
if (fs.existsSync(crossrampFilePath)) {
|
|
129
|
+
try {
|
|
130
|
+
const content = fs.readFileSync(crossrampFilePath, "utf8");
|
|
131
|
+
crossrampConfig = JSON.parse(content);
|
|
132
|
+
|
|
133
|
+
if (!crossrampConfig.uuid || !crossrampConfig.project_id) {
|
|
134
|
+
console.error(
|
|
135
|
+
"Error: .crossramp file must contain 'uuid' and 'project_id'"
|
|
136
|
+
);
|
|
137
|
+
process.exit(1);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
console.log("CrossRamp configuration detected");
|
|
141
|
+
} catch (error) {
|
|
142
|
+
console.error("Error parsing .crossramp file:", error.message);
|
|
143
|
+
process.exit(1);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
81
147
|
// Files to upload
|
|
82
148
|
const filesToUpload = [];
|
|
83
149
|
const newHashes = {};
|
|
@@ -149,25 +215,25 @@ if (!previewMode) {
|
|
|
149
215
|
}
|
|
150
216
|
|
|
151
217
|
if (filesToUpload.length === 0) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
console.log(`Found ${filesToUpload.length} files to upload...`);
|
|
218
|
+
if (crossrampConfig) {
|
|
219
|
+
console.log(
|
|
220
|
+
"No file changes detected. Setting up CrossRamp configuration..."
|
|
221
|
+
);
|
|
157
222
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
};
|
|
223
|
+
setupCrossRamp(targetVerse, crossrampConfig).then((success) => {
|
|
224
|
+
if (success) {
|
|
225
|
+
console.log("CrossRamp setup completed.");
|
|
226
|
+
}
|
|
227
|
+
process.exit(success ? 0 : 1);
|
|
228
|
+
});
|
|
165
229
|
} else {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
};
|
|
230
|
+
console.log("No changes detected. Nothing to deploy.");
|
|
231
|
+
process.exit(0);
|
|
169
232
|
}
|
|
170
|
-
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
console.log(`Found ${filesToUpload.length} files to upload...`);
|
|
171
237
|
|
|
172
238
|
// Upload files in parallel
|
|
173
239
|
const uploadPromises = filesToUpload.map((fileInfo) => {
|
|
@@ -195,12 +261,23 @@ const uploadPromises = filesToUpload.map((fileInfo) => {
|
|
|
195
261
|
});
|
|
196
262
|
|
|
197
263
|
Promise.all(uploadPromises)
|
|
198
|
-
.then((results) => {
|
|
264
|
+
.then(async (results) => {
|
|
199
265
|
const successCount = results.filter(Boolean).length;
|
|
200
266
|
console.log(
|
|
201
267
|
`Deployment complete: ${successCount}/${filesToUpload.length} files uploaded successfully.`
|
|
202
268
|
);
|
|
203
269
|
|
|
270
|
+
// CrossRamp setup if config exists and all files uploaded successfully
|
|
271
|
+
if (crossrampConfig && successCount === filesToUpload.length) {
|
|
272
|
+
console.log("Setting up CrossRamp configuration...");
|
|
273
|
+
const success = await setupCrossRamp(targetVerse, crossrampConfig);
|
|
274
|
+
if (!success) {
|
|
275
|
+
console.warn(
|
|
276
|
+
"Warning: CrossRamp setup failed, but files were deployed"
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
204
281
|
// Save new hashes to .deployed file
|
|
205
282
|
fs.writeFileSync(deployedFilePath, JSON.stringify(newHashes, null, 2));
|
|
206
283
|
console.log("Updated .deployed file with new file hashes");
|