@erik9994857/cag 1.0.1 → 1.0.2
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/package.json +1 -1
- package/src/builder/exe-builder.js +70 -30
package/package.json
CHANGED
|
@@ -107,28 +107,33 @@ ExeBuilder.prototype.ensureDirectories = function () {
|
|
|
107
107
|
};
|
|
108
108
|
|
|
109
109
|
ExeBuilder.prototype.ensurePkgInstalled = function () {
|
|
110
|
-
var
|
|
111
|
-
|
|
110
|
+
var found = this.findPkgBin();
|
|
111
|
+
if (found !== "npx pkg") return;
|
|
112
112
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
113
|
+
var npxCheck = null;
|
|
114
|
+
try {
|
|
115
|
+
npxCheck = childProcess.execSync("npx pkg --version", { stdio: "pipe" });
|
|
116
|
+
} catch (e) {
|
|
117
|
+
npxCheck = null;
|
|
118
|
+
}
|
|
120
119
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
120
|
+
if (npxCheck) return;
|
|
121
|
+
|
|
122
|
+
try {
|
|
123
|
+
childProcess.execSync("npm install -g pkg@5.8.1", {
|
|
124
|
+
cwd: this.projectRoot,
|
|
125
|
+
stdio: "inherit"
|
|
126
|
+
});
|
|
127
|
+
} catch (e) {
|
|
128
|
+
try {
|
|
129
|
+
childProcess.execSync("npm install pkg@5.8.1", {
|
|
130
|
+
cwd: this.projectRoot,
|
|
131
|
+
stdio: "inherit"
|
|
132
|
+
});
|
|
133
|
+
} catch (e2) {
|
|
134
|
+
throw new Error(
|
|
135
|
+
"Failed to install pkg. Run manually: npm install -g pkg"
|
|
136
|
+
);
|
|
132
137
|
}
|
|
133
138
|
}
|
|
134
139
|
};
|
|
@@ -382,7 +387,13 @@ ExeBuilder.prototype.getRuntimeSource = function () {
|
|
|
382
387
|
|
|
383
388
|
ExeBuilder.prototype.runPkg = function (entryFile, outputPath, target) {
|
|
384
389
|
var pkgBin = this.findPkgBin();
|
|
385
|
-
var cmd
|
|
390
|
+
var cmd;
|
|
391
|
+
|
|
392
|
+
if (pkgBin === "npx pkg") {
|
|
393
|
+
cmd = 'npx pkg "' + entryFile + '" --target ' + target + ' --output "' + outputPath + '"';
|
|
394
|
+
} else {
|
|
395
|
+
cmd = '"' + pkgBin + '" "' + entryFile + '" --target ' + target + ' --output "' + outputPath + '"';
|
|
396
|
+
}
|
|
386
397
|
|
|
387
398
|
try {
|
|
388
399
|
childProcess.execSync(cmd, {
|
|
@@ -400,20 +411,49 @@ ExeBuilder.prototype.runPkg = function (entryFile, outputPath, target) {
|
|
|
400
411
|
};
|
|
401
412
|
|
|
402
413
|
ExeBuilder.prototype.findPkgBin = function () {
|
|
403
|
-
var
|
|
404
|
-
if (fs.existsSync(
|
|
414
|
+
var projectLocal = path.join(this.projectRoot, "node_modules", ".bin", "pkg");
|
|
415
|
+
if (fs.existsSync(projectLocal)) return projectLocal;
|
|
416
|
+
var projectLocalCmd = projectLocal + ".cmd";
|
|
417
|
+
if (fs.existsSync(projectLocalCmd)) return projectLocalCmd;
|
|
418
|
+
|
|
419
|
+
var cagRoot = path.join(__dirname, "..", "..");
|
|
420
|
+
var cagLocal = path.join(cagRoot, "node_modules", ".bin", "pkg");
|
|
421
|
+
if (fs.existsSync(cagLocal)) return cagLocal;
|
|
422
|
+
var cagLocalCmd = cagLocal + ".cmd";
|
|
423
|
+
if (fs.existsSync(cagLocalCmd)) return cagLocalCmd;
|
|
424
|
+
|
|
425
|
+
var npmGlobalPrefix = "";
|
|
426
|
+
try {
|
|
427
|
+
npmGlobalPrefix = childProcess.execSync("npm config get prefix", {
|
|
428
|
+
stdio: "pipe"
|
|
429
|
+
}).toString().trim();
|
|
430
|
+
} catch (e) {
|
|
431
|
+
npmGlobalPrefix = "";
|
|
432
|
+
}
|
|
405
433
|
|
|
406
|
-
|
|
407
|
-
|
|
434
|
+
if (npmGlobalPrefix) {
|
|
435
|
+
var isWin = process.platform === "win32";
|
|
436
|
+
var globalBin;
|
|
437
|
+
if (isWin) {
|
|
438
|
+
globalBin = path.join(npmGlobalPrefix, "pkg.cmd");
|
|
439
|
+
if (fs.existsSync(globalBin)) return globalBin;
|
|
440
|
+
globalBin = path.join(npmGlobalPrefix, "node_modules", ".bin", "pkg.cmd");
|
|
441
|
+
if (fs.existsSync(globalBin)) return globalBin;
|
|
442
|
+
} else {
|
|
443
|
+
globalBin = path.join(npmGlobalPrefix, "bin", "pkg");
|
|
444
|
+
if (fs.existsSync(globalBin)) return globalBin;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
408
447
|
|
|
409
448
|
try {
|
|
410
|
-
var
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
449
|
+
var whereResult = childProcess.execSync(
|
|
450
|
+
process.platform === "win32" ? "where pkg 2>nul" : "which pkg 2>/dev/null",
|
|
451
|
+
{ stdio: "pipe" }
|
|
452
|
+
).toString().trim().split("\n")[0].trim();
|
|
453
|
+
if (whereResult && fs.existsSync(whereResult)) return whereResult;
|
|
414
454
|
} catch (e) {}
|
|
415
455
|
|
|
416
|
-
return "pkg";
|
|
456
|
+
return "npx pkg";
|
|
417
457
|
};
|
|
418
458
|
|
|
419
459
|
ExeBuilder.prototype.cleanup = function () {
|