engine7 7.1.8 → 7.1.9
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 +31 -25
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -208,20 +208,18 @@ 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}.zip`);
|
|
212
212
|
console.log(`
|
|
213
213
|
\u{1F5DC}\uFE0F \u6253\u5305\u4E2D...`);
|
|
214
214
|
if (process.platform === "win32") {
|
|
215
|
-
const
|
|
216
|
-
const stagingParent = path.dirname(stagingDir);
|
|
215
|
+
const stagingParent = path.dirname(stagingDir).replace(/\\/g, "/");
|
|
217
216
|
const childName = path.basename(stagingDir);
|
|
218
|
-
execSync(`powershell -Command "Compress-Archive -Path '${stagingParent}/${childName}
|
|
219
|
-
fs.renameSync(zipFile, tarFile);
|
|
217
|
+
execSync(`powershell -Command "Compress-Archive -Path '${stagingParent}/${childName}' -DestinationPath '${archiveFile}' -Force"`, { stdio: "pipe" });
|
|
220
218
|
} else {
|
|
221
|
-
execSync(`
|
|
219
|
+
execSync(`cd "${tmpDir}" && zip -r -q "${archiveFile}" ${agentName}`, { stdio: "pipe" });
|
|
222
220
|
}
|
|
223
|
-
const
|
|
224
|
-
console.log(`\u2705 \u6253\u5305\u5B8C\u6210: ${
|
|
221
|
+
const archiveSize = fs.statSync(archiveFile).size;
|
|
222
|
+
console.log(`\u2705 \u6253\u5305\u5B8C\u6210: ${archiveFile} (${(archiveSize / 1024 / 1024).toFixed(1)} MB, ${fileCount} \u6587\u4EF6)`);
|
|
225
223
|
const cfg = loadTravelConfig();
|
|
226
224
|
if (!cfg || !cfg.githubToken) {
|
|
227
225
|
console.log(`
|
|
@@ -230,7 +228,7 @@ async function doExport(opts) {
|
|
|
230
228
|
console.log(` \u6216\u624B\u52A8\u4E0A\u4F20\u5230 GitHub private repo release`);
|
|
231
229
|
return;
|
|
232
230
|
}
|
|
233
|
-
await uploadToGitHub(cfg,
|
|
231
|
+
await uploadToGitHub(cfg, archiveFile, agentName, version, manifest);
|
|
234
232
|
}
|
|
235
233
|
async function doImport(opts) {
|
|
236
234
|
const { agentName, stateDir, version, dryRun: dryRun2 } = opts;
|
|
@@ -245,18 +243,26 @@ async function doImport(opts) {
|
|
|
245
243
|
}
|
|
246
244
|
const tmpDir = path.join(os.tmpdir(), `engine7-import-${agentName}-${Date.now()}`);
|
|
247
245
|
fs.mkdirSync(tmpDir, { recursive: true });
|
|
248
|
-
const
|
|
249
|
-
console.log(`\u2705 \u4E0B\u8F7D\u5B8C\u6210: ${
|
|
246
|
+
const archiveFile = await downloadFromGitHub(cfg, agentName, version, tmpDir);
|
|
247
|
+
console.log(`\u2705 \u4E0B\u8F7D\u5B8C\u6210: ${archiveFile}`);
|
|
250
248
|
if (dryRun2) {
|
|
251
249
|
console.log(`
|
|
252
250
|
[DRY RUN] \u53EA\u4E0B\u8F7D\u4E0D\u6062\u590D`);
|
|
253
251
|
return;
|
|
254
252
|
}
|
|
255
253
|
console.log(`\u{1F4C2} \u89E3\u5305\u4E2D...`);
|
|
256
|
-
if (
|
|
257
|
-
|
|
254
|
+
if (archiveFile.endsWith(".tar.gz")) {
|
|
255
|
+
if (process.platform === "win32") {
|
|
256
|
+
execSync(`tar -xzf "${archiveFile}" -C "${tmpDir}"`, { stdio: "pipe" });
|
|
257
|
+
} else {
|
|
258
|
+
execSync(`tar -xzf "${archiveFile}" -C "${tmpDir}"`, { stdio: "pipe" });
|
|
259
|
+
}
|
|
258
260
|
} else {
|
|
259
|
-
|
|
261
|
+
if (process.platform === "win32") {
|
|
262
|
+
execSync(`powershell -Command "Expand-Archive -Path '${archiveFile}' -DestinationPath '${tmpDir}' -Force"`, { stdio: "pipe" });
|
|
263
|
+
} else {
|
|
264
|
+
execSync(`unzip -q -o "${archiveFile}" -d "${tmpDir}"`, { stdio: "pipe" });
|
|
265
|
+
}
|
|
260
266
|
}
|
|
261
267
|
const stagingDir = path.join(tmpDir, agentName);
|
|
262
268
|
const manifestPath = path.join(stagingDir, "manifest.json");
|
|
@@ -304,7 +310,7 @@ async function doImport(opts) {
|
|
|
304
310
|
\u{1F4A1} \u4E0B\u4E00\u6B65: engine7 start --config <path>`);
|
|
305
311
|
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
306
312
|
}
|
|
307
|
-
async function uploadToGitHub(cfg,
|
|
313
|
+
async function uploadToGitHub(cfg, archiveFile, agentName, version, manifest) {
|
|
308
314
|
const repo = `${cfg.githubOwner}/${cfg.repoName}`;
|
|
309
315
|
const tag = `${agentName}-${version}`;
|
|
310
316
|
console.log(`
|
|
@@ -332,14 +338,14 @@ async function uploadToGitHub(cfg, tarFile, agentName, version, manifest) {
|
|
|
332
338
|
}
|
|
333
339
|
const release = await createRes.json();
|
|
334
340
|
const uploadUrl = release.upload_url.replace("{?name,label}", "");
|
|
335
|
-
const fileBuffer = fs.readFileSync(
|
|
336
|
-
const fileName = path.basename(
|
|
341
|
+
const fileBuffer = fs.readFileSync(archiveFile);
|
|
342
|
+
const fileName = path.basename(archiveFile);
|
|
337
343
|
const uploadRes = await fetch(`${uploadUrl}?name=${fileName}`, {
|
|
338
344
|
method: "POST",
|
|
339
345
|
headers: {
|
|
340
346
|
"Authorization": `Bearer ${cfg.githubToken}`,
|
|
341
347
|
"Accept": "application/vnd.github+json",
|
|
342
|
-
"Content-Type": "application/
|
|
348
|
+
"Content-Type": "application/zip",
|
|
343
349
|
"Content-Length": String(fileBuffer.length)
|
|
344
350
|
},
|
|
345
351
|
body: fileBuffer
|
|
@@ -352,11 +358,11 @@ async function uploadToGitHub(cfg, tarFile, agentName, version, manifest) {
|
|
|
352
358
|
console.log(` release: ${release.html_url}`);
|
|
353
359
|
} catch (e) {
|
|
354
360
|
console.error(`\u274C GitHub \u4E0A\u4F20\u5931\u8D25: ${e.message}`);
|
|
355
|
-
console.error(`
|
|
361
|
+
console.error(` archive \u4ECD\u5728: ${archiveFile}`);
|
|
356
362
|
throw e;
|
|
357
363
|
}
|
|
358
364
|
try {
|
|
359
|
-
fs.rmSync(path.dirname(
|
|
365
|
+
fs.rmSync(path.dirname(archiveFile), { recursive: true, force: true });
|
|
360
366
|
} catch {
|
|
361
367
|
}
|
|
362
368
|
}
|
|
@@ -374,9 +380,9 @@ async function downloadFromGitHub(cfg, agentName, version, destDir) {
|
|
|
374
380
|
throw new Error(`\u83B7\u53D6 release \u5931\u8D25: ${res.status}`);
|
|
375
381
|
}
|
|
376
382
|
const release = await res.json();
|
|
377
|
-
const asset = release.assets?.find((a) => a.name.endsWith(".tar.gz"));
|
|
383
|
+
const asset = release.assets?.find((a) => a.name.endsWith(".zip") || a.name.endsWith(".tar.gz"));
|
|
378
384
|
if (!asset) {
|
|
379
|
-
throw new Error(`release ${tag} \u6CA1\u6709 tar.gz asset`);
|
|
385
|
+
throw new Error(`release ${tag} \u6CA1\u6709 zip/tar.gz asset`);
|
|
380
386
|
}
|
|
381
387
|
const downloadRes = await fetch(asset.url, {
|
|
382
388
|
headers: {
|
|
@@ -388,9 +394,9 @@ async function downloadFromGitHub(cfg, agentName, version, destDir) {
|
|
|
388
394
|
throw new Error(`\u4E0B\u8F7D asset \u5931\u8D25: ${downloadRes.status}`);
|
|
389
395
|
}
|
|
390
396
|
const buffer = Buffer.from(await downloadRes.arrayBuffer());
|
|
391
|
-
const
|
|
392
|
-
fs.writeFileSync(
|
|
393
|
-
return
|
|
397
|
+
const archiveFile = path.join(destDir, asset.name);
|
|
398
|
+
fs.writeFileSync(archiveFile, buffer);
|
|
399
|
+
return archiveFile;
|
|
394
400
|
}
|
|
395
401
|
async function getLatestReleaseTag(cfg, agentName) {
|
|
396
402
|
const repo = `${cfg.githubOwner}/${cfg.repoName}`;
|