@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@erik9994857/cag",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "CaG — A code library and custom language for building 3D worlds with .cagc files, .bbmodel support, and auto UV mapping",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -107,28 +107,33 @@ ExeBuilder.prototype.ensureDirectories = function () {
107
107
  };
108
108
 
109
109
  ExeBuilder.prototype.ensurePkgInstalled = function () {
110
- var pkgPath = path.join(this.projectRoot, "node_modules", ".bin", "pkg");
111
- var pkgPathWin = pkgPath + ".cmd";
110
+ var found = this.findPkgBin();
111
+ if (found !== "npx pkg") return;
112
112
 
113
- if (!fs.existsSync(pkgPath) && !fs.existsSync(pkgPathWin)) {
114
- var globalCheck;
115
- try {
116
- globalCheck = childProcess.execSync("pkg --version", { stdio: "pipe" });
117
- } catch (e) {
118
- globalCheck = null;
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
- if (!globalCheck) {
122
- try {
123
- childProcess.execSync("npm install --save-dev pkg@5.8.1", {
124
- cwd: this.projectRoot,
125
- stdio: "inherit"
126
- });
127
- } catch (e) {
128
- throw new Error(
129
- "Failed to install pkg. Run manually: npm install -g pkg"
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 = '"' + pkgBin + '" "' + entryFile + '" --target ' + target + ' --output "' + outputPath + '"';
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 localBin = path.join(this.projectRoot, "node_modules", ".bin", "pkg");
404
- if (fs.existsSync(localBin)) return localBin;
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
- var localBinCmd = localBin + ".cmd";
407
- if (fs.existsSync(localBinCmd)) return localBinCmd;
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 globalPath = childProcess.execSync("which pkg 2>/dev/null || where pkg 2>nul", {
411
- stdio: "pipe"
412
- }).toString().trim().split("\n")[0];
413
- if (globalPath && fs.existsSync(globalPath)) return globalPath;
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 () {