api2cli 0.3.11 → 0.3.13

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 +67 -8
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2227,7 +2227,8 @@ function replacePlaceholders(dir, vars) {
2227
2227
  ["{{APP_CLI}}", vars.appCli],
2228
2228
  ["{{BASE_URL}}", vars.baseUrl],
2229
2229
  ["{{AUTH_TYPE}}", vars.authType],
2230
- ["{{AUTH_HEADER}}", vars.authHeader]
2230
+ ["{{AUTH_HEADER}}", vars.authHeader],
2231
+ ["api2cli-template", vars.appCli]
2231
2232
  ];
2232
2233
  walkFiles(dir, (filePath) => {
2233
2234
  if (filePath.includes("node_modules"))
@@ -2285,7 +2286,7 @@ async function publishToMarketplace(githubUrl) {
2285
2286
  return false;
2286
2287
  }
2287
2288
  console.log(` ${import_picocolors.default.green("\u2713")} Published ${import_picocolors.default.bold(data.skill.displayName)} to marketplace`);
2288
- console.log(` ${import_picocolors.default.dim(`\u2192 ${data.skill.url || `https://api2cli.dev/cli/${data.skill.name}`}`)}`);
2289
+ console.log(` ${import_picocolors.default.dim(`\u2192 https://api2cli.dev/cli/${data.skill.name}`)}`);
2289
2290
  return true;
2290
2291
  } catch {
2291
2292
  console.error(` ${import_picocolors.default.red("\u2717")} Could not reach api2cli.dev`);
@@ -2325,7 +2326,63 @@ function askQuestion2(question) {
2325
2326
  });
2326
2327
  });
2327
2328
  }
2328
- async function promptPublish(app) {
2329
+ async function createGithubRepo(app, cliDir) {
2330
+ const repoName = `${app}-cli`;
2331
+ const env = { ...process.env, PATH: `/usr/local/bin:/opt/homebrew/bin:${process.env.PATH || ""}` };
2332
+ console.log(` ${import_picocolors2.default.dim("Initializing git repo...")}`);
2333
+ const gitInit = Bun.spawnSync(["git", "init"], {
2334
+ cwd: cliDir,
2335
+ stdout: "ignore",
2336
+ stderr: "ignore",
2337
+ env
2338
+ });
2339
+ if (gitInit.exitCode !== 0) {
2340
+ console.error(` ${import_picocolors2.default.red("\u2717")} Failed to init git repo`);
2341
+ return null;
2342
+ }
2343
+ Bun.spawnSync(["git", "add", "."], { cwd: cliDir, stdout: "ignore", stderr: "ignore", env });
2344
+ Bun.spawnSync(["git", "commit", "-m", "Initial commit"], {
2345
+ cwd: cliDir,
2346
+ stdout: "ignore",
2347
+ stderr: "ignore",
2348
+ env
2349
+ });
2350
+ const whichGh = Bun.spawnSync(["which", "gh"], {
2351
+ stdout: "pipe",
2352
+ stderr: "ignore",
2353
+ env: { ...process.env, PATH: `/usr/local/bin:/opt/homebrew/bin:${process.env.PATH || ""}` }
2354
+ });
2355
+ const ghPath = whichGh.stdout.toString().trim();
2356
+ if (!ghPath || whichGh.exitCode !== 0) {
2357
+ console.error(` ${import_picocolors2.default.red("\u2717")} GitHub CLI (gh) not found. Install it: ${import_picocolors2.default.cyan("brew install gh")}`);
2358
+ return null;
2359
+ }
2360
+ console.log(` ${import_picocolors2.default.dim("Creating GitHub repo...")}`);
2361
+ const ghCreate = Bun.spawnSync([ghPath, "repo", "create", repoName, "--public", "--source", ".", "--push"], { cwd: cliDir, stdout: "pipe", stderr: "pipe" });
2362
+ if (ghCreate.exitCode !== 0) {
2363
+ const stderr = ghCreate.stderr.toString().trim();
2364
+ if (stderr.includes("not logged")) {
2365
+ console.error(` ${import_picocolors2.default.red("\u2717")} Not logged in to GitHub. Run: ${import_picocolors2.default.cyan("gh auth login")}`);
2366
+ } else {
2367
+ console.error(` ${import_picocolors2.default.red("\u2717")} Failed to create repo: ${stderr}`);
2368
+ }
2369
+ return null;
2370
+ }
2371
+ const output = ghCreate.stdout.toString().trim();
2372
+ const urlMatch = output.match(/https:\/\/github\.com\/[^\s]+/);
2373
+ if (urlMatch)
2374
+ return urlMatch[0];
2375
+ const remote = Bun.spawnSync(["git", "remote", "get-url", "origin"], {
2376
+ cwd: cliDir,
2377
+ stdout: "pipe",
2378
+ env
2379
+ });
2380
+ const remoteUrl = remote.stdout.toString().trim();
2381
+ if (remoteUrl)
2382
+ return remoteUrl;
2383
+ return null;
2384
+ }
2385
+ async function promptPublish(app, cliDir) {
2329
2386
  const pref = getPublishPreference();
2330
2387
  if (pref === "never")
2331
2388
  return;
@@ -2342,16 +2399,17 @@ ${import_picocolors2.default.bold("Marketplace")}`);
2342
2399
  }
2343
2400
  if (answer === "a" || answer === "always") {
2344
2401
  setPublishPreference("always");
2345
- console.log(` ${import_picocolors2.default.dim("Saved. Will always prompt for publish.")}`);
2402
+ console.log(` ${import_picocolors2.default.dim("Saved. Will always publish automatically.")}`);
2346
2403
  } else if (answer !== "y" && answer !== "yes") {
2347
2404
  return;
2348
2405
  }
2349
2406
  }
2350
- const githubUrl = await askQuestion2(` GitHub repo URL ${import_picocolors2.default.dim("(e.g. user/repo)")}: `);
2407
+ const githubUrl = await createGithubRepo(app, cliDir);
2351
2408
  if (!githubUrl) {
2352
- console.log(` ${import_picocolors2.default.dim("Skipped. Publish later with:")} ${import_picocolors2.default.cyan(`api2cli publish ${app}`)}`);
2409
+ console.log(` ${import_picocolors2.default.dim("Publish later with:")} ${import_picocolors2.default.cyan(`api2cli publish ${app}`)}`);
2353
2410
  return;
2354
2411
  }
2412
+ console.log(` ${import_picocolors2.default.green("+")} Pushed to ${import_picocolors2.default.cyan(githubUrl)}`);
2355
2413
  await publishToMarketplace(githubUrl);
2356
2414
  }
2357
2415
  var createCommand2 = new Command("create").description("Generate a new CLI from API documentation").argument("<app>", "API/app name (e.g. typefully, dub, mercury)").option("--docs <url>", "URL to API documentation").option("--openapi <url>", "URL to OpenAPI/Swagger spec").option("--base-url <url>", "API base URL", "https://api.example.com").option("--auth-type <type>", "Auth type: bearer, api-key, basic, custom", "bearer").option("--auth-header <name>", "Auth header name", "Authorization").option("--force", "Overwrite existing CLI", false).addHelpText("after", `
@@ -2381,7 +2439,8 @@ ${import_picocolors2.default.bold("Creating")} ${import_picocolors2.default.cyan
2381
2439
  });
2382
2440
  console.log(` ${import_picocolors2.default.green("+")} Configured for ${import_picocolors2.default.bold(app)}`);
2383
2441
  console.log(` ${import_picocolors2.default.dim("Installing dependencies...")}`);
2384
- const install = Bun.spawn(["bun", "install"], {
2442
+ const bunPath = process.execPath;
2443
+ const install = Bun.spawn([bunPath, "install"], {
2385
2444
  cwd: cliDir,
2386
2445
  stdout: "ignore",
2387
2446
  stderr: "pipe"
@@ -2406,7 +2465,7 @@ ${import_picocolors2.default.bold("Next steps:")}`);
2406
2465
  console.log(` 2. Build: ${import_picocolors2.default.cyan(`npx api2cli bundle ${app}`)}`);
2407
2466
  console.log(` 3. Link: ${import_picocolors2.default.cyan(`npx api2cli link ${app}`)}`);
2408
2467
  console.log(` 4. Auth: ${import_picocolors2.default.cyan(`${app}-cli auth set "your-token"`)}`);
2409
- await promptPublish(app);
2468
+ await promptPublish(app, cliDir);
2410
2469
  });
2411
2470
 
2412
2471
  // src/commands/install.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api2cli",
3
- "version": "0.3.11",
3
+ "version": "0.3.13",
4
4
  "description": "Turn any REST API into a standardized, agent-ready CLI",
5
5
  "type": "module",
6
6
  "bin": {