@pippit-dev/cli 1.0.21 → 1.0.22

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/scripts/run.js CHANGED
@@ -1,19 +1,16 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const { execFileSync } = require("child_process");
4
- const fs = require("fs");
5
- const path = require("path");
6
- const {
7
- isCanvasCommand,
8
- runCanvasCommand,
9
- } = require("./canvas-command");
10
- const { maybeWarnNewVersion } = require("./version-check");
3
+ const { execFileSync } = require('child_process');
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+ const { isCanvasCommand, runCanvasCommand } = require('./canvas-command');
7
+ const { maybeWarnNewVersion } = require('./version-check');
11
8
 
12
- const ext = process.platform === "win32" ? ".exe" : "";
13
- const bin = path.join(__dirname, "..", "bin", "pippit-tool-cli" + ext);
9
+ const ext = process.platform === 'win32' ? '.exe' : '';
10
+ const bin = path.join(__dirname, '..', 'bin', 'pippit-tool-cli' + ext);
14
11
  const args = process.argv.slice(2);
15
12
 
16
- const oldBin = bin + ".old";
13
+ const oldBin = bin + '.old';
17
14
  function restoreOldBinary() {
18
15
  try {
19
16
  if (fs.existsSync(bin)) {
@@ -26,57 +23,76 @@ function restoreOldBinary() {
26
23
  }
27
24
  }
28
25
 
29
- if (process.platform === "win32" && fs.existsSync(oldBin)) {
30
- if (!fs.existsSync(bin)) {
31
- restoreOldBinary();
32
- } else {
33
- try {
34
- execFileSync(bin, ["--help"], { stdio: "ignore", timeout: 10000 });
35
- fs.rmSync(oldBin, { force: true });
36
- } catch (_) {
26
+ function runCanvas() {
27
+ runCanvasCommand(args, {
28
+ nativeInvocation: { command: bin },
29
+ })
30
+ .then((exitCode) => {
31
+ if (exitCode) process.exitCode = exitCode;
32
+ })
33
+ .catch((error) => {
34
+ console.error(error && error.message ? error.message : String(error));
35
+ process.exitCode = 1;
36
+ });
37
+ }
38
+
39
+ function main() {
40
+ // Installation help must work before any native binary preparation.
41
+ if (args[0] === 'install') {
42
+ return require('./install-wizard.js').main(args.slice(1));
43
+ }
44
+
45
+ const helpRequested = args.includes('--help') || args.includes('-h') || args[0] === 'help';
46
+ if (isCanvasCommand(args) && (args[2] !== 'run' || helpRequested)) {
47
+ return runCanvas();
48
+ }
49
+
50
+ if (!helpRequested && args.length > 0 && process.platform === 'win32' && fs.existsSync(oldBin)) {
51
+ if (!fs.existsSync(bin)) {
37
52
  restoreOldBinary();
53
+ } else {
54
+ try {
55
+ execFileSync(bin, ['--help'], { stdio: 'ignore', timeout: 10000 });
56
+ fs.rmSync(oldBin, { force: true });
57
+ } catch (_) {
58
+ restoreOldBinary();
59
+ }
38
60
  }
39
61
  }
40
- }
41
62
 
42
- // Match the lark-cli install entry: `npx @pippit-dev/cli@latest install`
43
- // should run the JS setup flow before the native binary exists.
44
- if (args[0] === "install") {
45
- require("./install-wizard.js").main();
46
- } else {
47
- maybeWarnNewVersion(args);
63
+ if (!helpRequested && args.length > 0) maybeWarnNewVersion(args);
48
64
 
49
65
  if (!fs.existsSync(bin)) {
66
+ if (helpRequested || args.length === 0) {
67
+ console.error(
68
+ 'Native CLI binary is missing. Reinstall @pippit-dev/cli to restore native command help; canvas command --help and install --help remain available.',
69
+ );
70
+ process.exitCode = 1;
71
+ return;
72
+ }
50
73
  try {
51
- execFileSync(process.execPath, [path.join(__dirname, "install.js")], {
52
- stdio: "inherit",
53
- env: { ...process.env, PIPPIT_CLI_RUN: "true" },
74
+ execFileSync(process.execPath, [path.join(__dirname, 'install.js')], {
75
+ stdio: 'inherit',
76
+ env: { ...process.env, PIPPIT_CLI_RUN: 'true' },
54
77
  });
55
78
  } catch (_) {
56
79
  console.error(
57
- "\nFailed to prepare pippit-tool-cli binary.\n" +
58
- "Make sure Go is installed and available in PATH, then retry.\n"
80
+ '\nFailed to prepare pippit-tool-cli binary.\n' +
81
+ 'Check your network connection and reinstall the npm package to download the prebuilt binary.\n',
59
82
  );
60
83
  process.exit(1);
61
84
  }
62
85
  }
63
86
 
64
87
  if (isCanvasCommand(args)) {
65
- runCanvasCommand(args, {
66
- nativeInvocation: { command: bin },
67
- })
68
- .then((exitCode) => {
69
- if (exitCode) process.exitCode = exitCode;
70
- })
71
- .catch((error) => {
72
- console.error(error && error.message ? error.message : String(error));
73
- process.exitCode = 1;
74
- });
88
+ runCanvas();
75
89
  } else {
76
90
  try {
77
- execFileSync(bin, args, { stdio: "inherit" });
91
+ execFileSync(bin, args, { stdio: 'inherit' });
78
92
  } catch (e) {
79
93
  process.exit(e.status || 1);
80
94
  }
81
95
  }
82
96
  }
97
+
98
+ main();