@agent8/deploy 1.2.0 → 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 +87 -17
- 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, "");
|
|
@@ -85,6 +86,64 @@ if (previewMode) {
|
|
|
85
86
|
console.log("Default mode: Deploying to verse:", targetVerse);
|
|
86
87
|
}
|
|
87
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
|
+
|
|
88
147
|
// Files to upload
|
|
89
148
|
const filesToUpload = [];
|
|
90
149
|
const newHashes = {};
|
|
@@ -156,25 +215,25 @@ if (!previewMode) {
|
|
|
156
215
|
}
|
|
157
216
|
|
|
158
217
|
if (filesToUpload.length === 0) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
console.log(`Found ${filesToUpload.length} files to upload...`);
|
|
218
|
+
if (crossrampConfig) {
|
|
219
|
+
console.log(
|
|
220
|
+
"No file changes detected. Setting up CrossRamp configuration..."
|
|
221
|
+
);
|
|
164
222
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
};
|
|
223
|
+
setupCrossRamp(targetVerse, crossrampConfig).then((success) => {
|
|
224
|
+
if (success) {
|
|
225
|
+
console.log("CrossRamp setup completed.");
|
|
226
|
+
}
|
|
227
|
+
process.exit(success ? 0 : 1);
|
|
228
|
+
});
|
|
172
229
|
} else {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
};
|
|
230
|
+
console.log("No changes detected. Nothing to deploy.");
|
|
231
|
+
process.exit(0);
|
|
176
232
|
}
|
|
177
|
-
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
console.log(`Found ${filesToUpload.length} files to upload...`);
|
|
178
237
|
|
|
179
238
|
// Upload files in parallel
|
|
180
239
|
const uploadPromises = filesToUpload.map((fileInfo) => {
|
|
@@ -202,12 +261,23 @@ const uploadPromises = filesToUpload.map((fileInfo) => {
|
|
|
202
261
|
});
|
|
203
262
|
|
|
204
263
|
Promise.all(uploadPromises)
|
|
205
|
-
.then((results) => {
|
|
264
|
+
.then(async (results) => {
|
|
206
265
|
const successCount = results.filter(Boolean).length;
|
|
207
266
|
console.log(
|
|
208
267
|
`Deployment complete: ${successCount}/${filesToUpload.length} files uploaded successfully.`
|
|
209
268
|
);
|
|
210
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
|
+
|
|
211
281
|
// Save new hashes to .deployed file
|
|
212
282
|
fs.writeFileSync(deployedFilePath, JSON.stringify(newHashes, null, 2));
|
|
213
283
|
console.log("Updated .deployed file with new file hashes");
|