swytchcode 2.6.0 → 2.6.1

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.
Files changed (2) hide show
  1. package/bin/swytchcode.js +50 -18
  2. package/package.json +7 -7
package/bin/swytchcode.js CHANGED
@@ -1,6 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
+ process.on('SIGINT', () => {
5
+ try { process.stdin.setRawMode(false); } catch (_) {} // prevent stuck raw mode on Windows CMD
6
+ process.stdout.write('\x1b[?25h'); // restore cursor
7
+ process.exit(130);
8
+ });
9
+
4
10
  const { spawnSync, execSync } = require('child_process');
5
11
  const fs = require('fs');
6
12
  const path = require('path');
@@ -45,7 +51,20 @@ function stripAnsi(str) {
45
51
  function ask(prompt) {
46
52
  return new Promise(resolve => {
47
53
  const iface = rl.createInterface({ input: process.stdin, output: process.stdout });
48
- iface.question(prompt, answer => { iface.close(); resolve(answer.trim()); });
54
+
55
+ function onClose() {
56
+ try { process.stdin.setRawMode(false); } catch (_) {}
57
+ process.stdout.write('\x1b[?25h');
58
+ process.exit(130);
59
+ }
60
+
61
+ iface.on('close', onClose);
62
+
63
+ iface.question(prompt, answer => {
64
+ iface.removeListener('close', onClose); // only removes this specific listener
65
+ iface.close();
66
+ resolve(answer.trim());
67
+ });
49
68
  });
50
69
  }
51
70
 
@@ -188,17 +207,27 @@ function apiPost(urlStr, body) {
188
207
  // ─── Binary resolution (shared by normal pass-through AND onboarding) ────────
189
208
  function spawnBin(binPath, args, extraEnv = {}) {
190
209
  const env = { ...process.env, ...extraEnv };
210
+ let result;
191
211
  if (process.stdin.isTTY) {
192
- return spawnSync(binPath, args, { stdio: 'inherit', env });
212
+ result = spawnSync(binPath, args, { stdio: 'inherit', env });
213
+ } else {
214
+ let stdinData;
215
+ try { stdinData = fs.readFileSync(0); }
216
+ catch (_) { stdinData = Buffer.alloc(0); }
217
+ result = spawnSync(binPath, args, {
218
+ stdio: ['pipe', 'inherit', 'inherit'],
219
+ input: stdinData,
220
+ env,
221
+ });
193
222
  }
194
- let stdinData;
195
- try { stdinData = fs.readFileSync(0); }
196
- catch (_) { stdinData = Buffer.alloc(0); }
197
- return spawnSync(binPath, args, {
198
- stdio: ['pipe', 'inherit', 'inherit'],
199
- input: stdinData,
200
- env,
201
- });
223
+
224
+ if (result.signal === 'SIGINT') {
225
+ try { process.stdin.setRawMode(false); } catch (_) {}
226
+ process.stdout.write('\x1b[?25h');
227
+ process.exit(130);
228
+ }
229
+
230
+ return result;
202
231
  }
203
232
 
204
233
  function exitCode(result) {
@@ -371,10 +400,7 @@ async function runDemoSelection() {
371
400
  if (chosen !== '__skip__') {
372
401
  writeln();
373
402
  writeln(` ${c.gray}$ swytchcode demo stripe${c.reset}`);
374
- spawnSync(binPath, ['demo', 'stripe'], {
375
- stdio: 'inherit',
376
- env: { ...process.env, SWYTCHCODE_ONBOARDING: '1' }
377
- });
403
+ spawnBin(binPath, ['demo', 'stripe'], { SWYTCHCODE_ONBOARDING: '1' });
378
404
  writeln();
379
405
  writeln(` ${c.dim}That was a real API call. No credentials, no setup.${c.reset}`);
380
406
  writeln(` ${c.dim}With Swytchcode, every API integration works exactly like this.${c.reset}`);
@@ -445,6 +471,12 @@ async function runOnboardingSteps2to4() {
445
471
  execSync('npm install swytchcode', { stdio: 'pipe' });
446
472
  installSpin.stop('Installed successfully');
447
473
  } catch (e) {
474
+ if (e.signal === 'SIGINT') {
475
+ installSpin.stop('Cancelled');
476
+ try { process.stdin.setRawMode(false); } catch (_) {}
477
+ process.stdout.write('\x1b[?25h');
478
+ process.exit(130);
479
+ }
448
480
  installSpin.fail('Installation failed.');
449
481
  }
450
482
 
@@ -472,7 +504,7 @@ async function runOnboardingSteps2to4() {
472
504
  if (authChoice === 'login') {
473
505
  writeln(` ${c.dim}Opening browser for login ...${c.reset}`);
474
506
  writeln();
475
- const result = spawnSync(binPath, ['login'], { stdio: 'inherit' });
507
+ const result = spawnBin(binPath, ['login']);
476
508
  if (result.error || result.status !== 0) {
477
509
  writeln(` ${c.yellow}Login window closed or failed.${c.reset}`);
478
510
  writeln(` ${c.dim}You can log in later with:${c.reset} ${c.cyan}swytchcode login${c.reset}`);
@@ -483,7 +515,7 @@ async function runOnboardingSteps2to4() {
483
515
  writeln(` ${c.dim}Opening browser to create your account ...${c.reset}`);
484
516
  writeln();
485
517
  // login command handles both login and registration via the browser flow
486
- const result = spawnSync(binPath, ['login'], { stdio: 'inherit' });
518
+ const result = spawnBin(binPath, ['login']);
487
519
  if (result.error || result.status !== 0) {
488
520
  writeln(` ${c.yellow}Browser window closed or failed.${c.reset}`);
489
521
  writeln(` ${c.dim}Create your account at:${c.reset} ${c.cyan}https://swytchcode.com/signup${c.reset}`);
@@ -513,14 +545,14 @@ async function runOnboardingSteps2to4() {
513
545
  if (nextAction === 'init') {
514
546
  writeln(` ${c.dim}Starting project setup ...${c.reset}`);
515
547
  writeln();
516
- const result = spawnSync(binPath, ['init'], { stdio: 'inherit' });
548
+ const result = spawnBin(binPath, ['init']);
517
549
  if (result.error) {
518
550
  writeln(` ${c.red}Could not launch swytchcode init: ${result.error.message}${c.reset}`);
519
551
  }
520
552
  } else if (nextAction === 'examples') {
521
553
  writeln(` ${c.dim}Loading examples ...${c.reset}`);
522
554
  writeln();
523
- const result = spawnSync(binPath, ['examples'], { stdio: 'inherit' });
555
+ const result = spawnBin(binPath, ['examples']);
524
556
  if (result.error) {
525
557
  writeln(` ${c.red}Could not launch swytchcode examples: ${result.error.message}${c.reset}`);
526
558
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swytchcode",
3
- "version": "2.6.0",
3
+ "version": "2.6.1",
4
4
  "description": "Execution authority layer for API integrations",
5
5
  "keywords": [
6
6
  "api",
@@ -23,11 +23,11 @@
23
23
  "README.md"
24
24
  ],
25
25
  "optionalDependencies": {
26
- "swytchcode-cli-darwin-arm64": "2.6.0",
27
- "swytchcode-cli-darwin-x64": "2.6.0",
28
- "swytchcode-cli-linux-arm64": "2.6.0",
29
- "swytchcode-cli-linux-x64": "2.6.0",
30
- "swytchcode-cli-win32-arm64": "2.6.0",
31
- "swytchcode-cli-win32-x64": "2.6.0"
26
+ "swytchcode-cli-darwin-arm64": "2.6.1",
27
+ "swytchcode-cli-darwin-x64": "2.6.1",
28
+ "swytchcode-cli-linux-arm64": "2.6.1",
29
+ "swytchcode-cli-linux-x64": "2.6.1",
30
+ "swytchcode-cli-win32-arm64": "2.6.1",
31
+ "swytchcode-cli-win32-x64": "2.6.1"
32
32
  }
33
33
  }