api2cli 0.3.12 → 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 +65 -7
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2286,7 +2286,7 @@ async function publishToMarketplace(githubUrl) {
2286
2286
  return false;
2287
2287
  }
2288
2288
  console.log(` ${import_picocolors.default.green("\u2713")} Published ${import_picocolors.default.bold(data.skill.displayName)} to marketplace`);
2289
- 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}`)}`);
2290
2290
  return true;
2291
2291
  } catch {
2292
2292
  console.error(` ${import_picocolors.default.red("\u2717")} Could not reach api2cli.dev`);
@@ -2326,7 +2326,63 @@ function askQuestion2(question) {
2326
2326
  });
2327
2327
  });
2328
2328
  }
2329
- 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) {
2330
2386
  const pref = getPublishPreference();
2331
2387
  if (pref === "never")
2332
2388
  return;
@@ -2343,16 +2399,17 @@ ${import_picocolors2.default.bold("Marketplace")}`);
2343
2399
  }
2344
2400
  if (answer === "a" || answer === "always") {
2345
2401
  setPublishPreference("always");
2346
- console.log(` ${import_picocolors2.default.dim("Saved. Will always prompt for publish.")}`);
2402
+ console.log(` ${import_picocolors2.default.dim("Saved. Will always publish automatically.")}`);
2347
2403
  } else if (answer !== "y" && answer !== "yes") {
2348
2404
  return;
2349
2405
  }
2350
2406
  }
2351
- const githubUrl = await askQuestion2(` GitHub repo URL ${import_picocolors2.default.dim("(e.g. user/repo)")}: `);
2407
+ const githubUrl = await createGithubRepo(app, cliDir);
2352
2408
  if (!githubUrl) {
2353
- 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}`)}`);
2354
2410
  return;
2355
2411
  }
2412
+ console.log(` ${import_picocolors2.default.green("+")} Pushed to ${import_picocolors2.default.cyan(githubUrl)}`);
2356
2413
  await publishToMarketplace(githubUrl);
2357
2414
  }
2358
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", `
@@ -2382,7 +2439,8 @@ ${import_picocolors2.default.bold("Creating")} ${import_picocolors2.default.cyan
2382
2439
  });
2383
2440
  console.log(` ${import_picocolors2.default.green("+")} Configured for ${import_picocolors2.default.bold(app)}`);
2384
2441
  console.log(` ${import_picocolors2.default.dim("Installing dependencies...")}`);
2385
- const install = Bun.spawn(["bun", "install"], {
2442
+ const bunPath = process.execPath;
2443
+ const install = Bun.spawn([bunPath, "install"], {
2386
2444
  cwd: cliDir,
2387
2445
  stdout: "ignore",
2388
2446
  stderr: "pipe"
@@ -2407,7 +2465,7 @@ ${import_picocolors2.default.bold("Next steps:")}`);
2407
2465
  console.log(` 2. Build: ${import_picocolors2.default.cyan(`npx api2cli bundle ${app}`)}`);
2408
2466
  console.log(` 3. Link: ${import_picocolors2.default.cyan(`npx api2cli link ${app}`)}`);
2409
2467
  console.log(` 4. Auth: ${import_picocolors2.default.cyan(`${app}-cli auth set "your-token"`)}`);
2410
- await promptPublish(app);
2468
+ await promptPublish(app, cliDir);
2411
2469
  });
2412
2470
 
2413
2471
  // src/commands/install.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api2cli",
3
- "version": "0.3.12",
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": {