api2cli 0.1.3 → 0.3.0

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/dist/index.js +29 -19
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2401,9 +2401,10 @@ import { existsSync as existsSync7, readdirSync as readdirSync4 } from "fs";
2401
2401
 
2402
2402
  // src/lib/shell.ts
2403
2403
  var import_picocolors5 = __toESM(require_picocolors(), 1);
2404
- import { existsSync as existsSync6, readFileSync as readFileSync2, writeFileSync as writeFileSync2, appendFileSync } from "fs";
2404
+ import { existsSync as existsSync6, readFileSync as readFileSync2, writeFileSync as writeFileSync2, appendFileSync, symlinkSync, unlinkSync, chmodSync } from "fs";
2405
2405
  import { homedir as homedir2 } from "os";
2406
2406
  import { join as join6 } from "path";
2407
+ var BIN_DIR = join6(homedir2(), ".local", "bin");
2407
2408
  var MARKER_START = "# >>> api2cli >>>";
2408
2409
  var MARKER_END = "# <<< api2cli <<<";
2409
2410
  function getShellRc() {
@@ -2417,14 +2418,12 @@ function getShellRc() {
2417
2418
  return zshrc;
2418
2419
  return join6(homedir2(), ".bashrc");
2419
2420
  }
2420
- function addToPath(app, binDir) {
2421
+ function ensureBinInPath() {
2421
2422
  const rcFile = getShellRc();
2422
2423
  const content = existsSync6(rcFile) ? readFileSync2(rcFile, "utf-8") : "";
2423
- const exportLine = `export PATH="${binDir}:$PATH"`;
2424
- if (content.includes(exportLine)) {
2425
- console.log(`${import_picocolors5.default.dim(app)} already in PATH`);
2424
+ const exportLine = `export PATH="${BIN_DIR}:$PATH"`;
2425
+ if (content.includes(BIN_DIR))
2426
2426
  return;
2427
- }
2428
2427
  if (content.includes(MARKER_START)) {
2429
2428
  const updated = content.replace(MARKER_END, `${exportLine}
2430
2429
  ${MARKER_END}`);
@@ -2436,22 +2435,33 @@ ${exportLine}
2436
2435
  ${MARKER_END}
2437
2436
  `);
2438
2437
  }
2439
- console.log(`${import_picocolors5.default.green("+")} Added ${import_picocolors5.default.bold(app)} to PATH in ${import_picocolors5.default.dim(rcFile)}`);
2440
- console.log(` Run: ${import_picocolors5.default.cyan(`source ${rcFile}`)}`);
2441
2438
  }
2442
- function removeFromPath(app, binDir) {
2443
- const rcFile = getShellRc();
2444
- if (!existsSync6(rcFile))
2445
- return;
2446
- const content = readFileSync2(rcFile, "utf-8");
2447
- const exportLine = `export PATH="${binDir}:$PATH"
2448
- `;
2449
- if (!content.includes(exportLine)) {
2450
- console.log(`${import_picocolors5.default.dim(app)} not in PATH`);
2439
+ function addToPath(app, distDir) {
2440
+ const { mkdirSync: mkdirSync3 } = __require("fs");
2441
+ mkdirSync3(BIN_DIR, { recursive: true });
2442
+ const target = join6(distDir, `${app}-cli.js`);
2443
+ const linkPath = join6(BIN_DIR, `${app}-cli`);
2444
+ if (!existsSync6(target)) {
2445
+ console.error(`${import_picocolors5.default.red("\u2717")} Built file not found: ${target}`);
2446
+ console.error(` Run: ${import_picocolors5.default.cyan(`npx api2cli bundle ${app}`)}`);
2447
+ process.exit(1);
2448
+ }
2449
+ chmodSync(target, 493);
2450
+ if (existsSync6(linkPath)) {
2451
+ unlinkSync(linkPath);
2452
+ }
2453
+ symlinkSync(target, linkPath);
2454
+ ensureBinInPath();
2455
+ console.log(`${import_picocolors5.default.green("+")} Linked ${import_picocolors5.default.bold(`${app}-cli`)} -> ${import_picocolors5.default.dim(linkPath)}`);
2456
+ }
2457
+ function removeFromPath(app, _distDir) {
2458
+ const linkPath = join6(BIN_DIR, `${app}-cli`);
2459
+ if (!existsSync6(linkPath)) {
2460
+ console.log(`${import_picocolors5.default.dim(app)} not linked`);
2451
2461
  return;
2452
2462
  }
2453
- writeFileSync2(rcFile, content.replace(exportLine, ""));
2454
- console.log(`${import_picocolors5.default.red("-")} Removed ${import_picocolors5.default.bold(app)} from PATH`);
2463
+ unlinkSync(linkPath);
2464
+ console.log(`${import_picocolors5.default.red("-")} Unlinked ${import_picocolors5.default.bold(`${app}-cli`)}`);
2455
2465
  }
2456
2466
 
2457
2467
  // src/commands/link.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api2cli",
3
- "version": "0.1.3",
3
+ "version": "0.3.0",
4
4
  "description": "Turn any REST API into a standardized, agent-ready CLI",
5
5
  "type": "module",
6
6
  "bin": {