engine7 7.1.8 → 7.1.10
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/dist/cli.mjs +20 -30
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -208,20 +208,13 @@ async function doExport(opts) {
|
|
|
208
208
|
note
|
|
209
209
|
};
|
|
210
210
|
fs.writeFileSync(path.join(stagingDir, "manifest.json"), JSON.stringify(manifest, null, 2));
|
|
211
|
-
const
|
|
211
|
+
const archiveFile = path.join(tmpDir, `${agentName}-${version}.tar.gz`);
|
|
212
212
|
console.log(`
|
|
213
213
|
\u{1F5DC}\uFE0F \u6253\u5305\u4E2D...`);
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
execSync(`powershell -Command "Compress-Archive -Path '${stagingParent}/${childName}/*' -DestinationPath '${zipFile}' -Force"`, { stdio: "pipe" });
|
|
219
|
-
fs.renameSync(zipFile, tarFile);
|
|
220
|
-
} else {
|
|
221
|
-
execSync(`tar -czf "${tarFile}" -C "${tmpDir}" ${agentName}`, { stdio: "pipe" });
|
|
222
|
-
}
|
|
223
|
-
const tarSize = fs.statSync(tarFile).size;
|
|
224
|
-
console.log(`\u2705 \u6253\u5305\u5B8C\u6210: ${tarFile} (${(tarSize / 1024 / 1024).toFixed(1)} MB, ${fileCount} \u6587\u4EF6)`);
|
|
214
|
+
const tarExe = process.platform === "win32" ? "C:\\Windows\\System32\\tar.exe" : "tar";
|
|
215
|
+
execSync(`"${tarExe}" -czf "${archiveFile}" -C "${tmpDir}" ${agentName}`, { stdio: "pipe" });
|
|
216
|
+
const archiveSize = fs.statSync(archiveFile).size;
|
|
217
|
+
console.log(`\u2705 \u6253\u5305\u5B8C\u6210: ${archiveFile} (${(archiveSize / 1024 / 1024).toFixed(1)} MB, ${fileCount} \u6587\u4EF6)`);
|
|
225
218
|
const cfg = loadTravelConfig();
|
|
226
219
|
if (!cfg || !cfg.githubToken) {
|
|
227
220
|
console.log(`
|
|
@@ -230,7 +223,7 @@ async function doExport(opts) {
|
|
|
230
223
|
console.log(` \u6216\u624B\u52A8\u4E0A\u4F20\u5230 GitHub private repo release`);
|
|
231
224
|
return;
|
|
232
225
|
}
|
|
233
|
-
await uploadToGitHub(cfg,
|
|
226
|
+
await uploadToGitHub(cfg, archiveFile, agentName, version, manifest);
|
|
234
227
|
}
|
|
235
228
|
async function doImport(opts) {
|
|
236
229
|
const { agentName, stateDir, version, dryRun: dryRun2 } = opts;
|
|
@@ -245,19 +238,16 @@ async function doImport(opts) {
|
|
|
245
238
|
}
|
|
246
239
|
const tmpDir = path.join(os.tmpdir(), `engine7-import-${agentName}-${Date.now()}`);
|
|
247
240
|
fs.mkdirSync(tmpDir, { recursive: true });
|
|
248
|
-
const
|
|
249
|
-
console.log(`\u2705 \u4E0B\u8F7D\u5B8C\u6210: ${
|
|
241
|
+
const archiveFile = await downloadFromGitHub(cfg, agentName, version, tmpDir);
|
|
242
|
+
console.log(`\u2705 \u4E0B\u8F7D\u5B8C\u6210: ${archiveFile}`);
|
|
250
243
|
if (dryRun2) {
|
|
251
244
|
console.log(`
|
|
252
245
|
[DRY RUN] \u53EA\u4E0B\u8F7D\u4E0D\u6062\u590D`);
|
|
253
246
|
return;
|
|
254
247
|
}
|
|
255
248
|
console.log(`\u{1F4C2} \u89E3\u5305\u4E2D...`);
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
} else {
|
|
259
|
-
execSync(`tar -xzf "${tarFile}" -C "${tmpDir}"`, { stdio: "pipe" });
|
|
260
|
-
}
|
|
249
|
+
const tarExe = process.platform === "win32" ? "C:\\Windows\\System32\\tar.exe" : "tar";
|
|
250
|
+
execSync(`"${tarExe}" -xzf "${archiveFile}" -C "${tmpDir}"`, { stdio: "pipe" });
|
|
261
251
|
const stagingDir = path.join(tmpDir, agentName);
|
|
262
252
|
const manifestPath = path.join(stagingDir, "manifest.json");
|
|
263
253
|
if (!fs.existsSync(manifestPath)) {
|
|
@@ -304,7 +294,7 @@ async function doImport(opts) {
|
|
|
304
294
|
\u{1F4A1} \u4E0B\u4E00\u6B65: engine7 start --config <path>`);
|
|
305
295
|
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
306
296
|
}
|
|
307
|
-
async function uploadToGitHub(cfg,
|
|
297
|
+
async function uploadToGitHub(cfg, archiveFile, agentName, version, manifest) {
|
|
308
298
|
const repo = `${cfg.githubOwner}/${cfg.repoName}`;
|
|
309
299
|
const tag = `${agentName}-${version}`;
|
|
310
300
|
console.log(`
|
|
@@ -332,8 +322,8 @@ async function uploadToGitHub(cfg, tarFile, agentName, version, manifest) {
|
|
|
332
322
|
}
|
|
333
323
|
const release = await createRes.json();
|
|
334
324
|
const uploadUrl = release.upload_url.replace("{?name,label}", "");
|
|
335
|
-
const fileBuffer = fs.readFileSync(
|
|
336
|
-
const fileName = path.basename(
|
|
325
|
+
const fileBuffer = fs.readFileSync(archiveFile);
|
|
326
|
+
const fileName = path.basename(archiveFile);
|
|
337
327
|
const uploadRes = await fetch(`${uploadUrl}?name=${fileName}`, {
|
|
338
328
|
method: "POST",
|
|
339
329
|
headers: {
|
|
@@ -352,11 +342,11 @@ async function uploadToGitHub(cfg, tarFile, agentName, version, manifest) {
|
|
|
352
342
|
console.log(` release: ${release.html_url}`);
|
|
353
343
|
} catch (e) {
|
|
354
344
|
console.error(`\u274C GitHub \u4E0A\u4F20\u5931\u8D25: ${e.message}`);
|
|
355
|
-
console.error(`
|
|
345
|
+
console.error(` archive \u4ECD\u5728: ${archiveFile}`);
|
|
356
346
|
throw e;
|
|
357
347
|
}
|
|
358
348
|
try {
|
|
359
|
-
fs.rmSync(path.dirname(
|
|
349
|
+
fs.rmSync(path.dirname(archiveFile), { recursive: true, force: true });
|
|
360
350
|
} catch {
|
|
361
351
|
}
|
|
362
352
|
}
|
|
@@ -374,9 +364,9 @@ async function downloadFromGitHub(cfg, agentName, version, destDir) {
|
|
|
374
364
|
throw new Error(`\u83B7\u53D6 release \u5931\u8D25: ${res.status}`);
|
|
375
365
|
}
|
|
376
366
|
const release = await res.json();
|
|
377
|
-
const asset = release.assets?.find((a) => a.name.endsWith(".tar.gz"));
|
|
367
|
+
const asset = release.assets?.find((a) => a.name.endsWith(".tar.gz") || a.name.endsWith(".zip"));
|
|
378
368
|
if (!asset) {
|
|
379
|
-
throw new Error(`release ${tag} \u6CA1\u6709 tar.gz asset`);
|
|
369
|
+
throw new Error(`release ${tag} \u6CA1\u6709 tar.gz/zip asset`);
|
|
380
370
|
}
|
|
381
371
|
const downloadRes = await fetch(asset.url, {
|
|
382
372
|
headers: {
|
|
@@ -388,9 +378,9 @@ async function downloadFromGitHub(cfg, agentName, version, destDir) {
|
|
|
388
378
|
throw new Error(`\u4E0B\u8F7D asset \u5931\u8D25: ${downloadRes.status}`);
|
|
389
379
|
}
|
|
390
380
|
const buffer = Buffer.from(await downloadRes.arrayBuffer());
|
|
391
|
-
const
|
|
392
|
-
fs.writeFileSync(
|
|
393
|
-
return
|
|
381
|
+
const archiveFile = path.join(destDir, asset.name);
|
|
382
|
+
fs.writeFileSync(archiveFile, buffer);
|
|
383
|
+
return archiveFile;
|
|
394
384
|
}
|
|
395
385
|
async function getLatestReleaseTag(cfg, agentName) {
|
|
396
386
|
const repo = `${cfg.githubOwner}/${cfg.repoName}`;
|