api2cli 0.3.12 → 0.3.14
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/dist/index.js +91 -13
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2273,12 +2273,15 @@ function askQuestion(question) {
|
|
|
2273
2273
|
});
|
|
2274
2274
|
});
|
|
2275
2275
|
}
|
|
2276
|
-
async function publishToMarketplace(githubUrl) {
|
|
2276
|
+
async function publishToMarketplace(githubUrl, category) {
|
|
2277
2277
|
try {
|
|
2278
|
+
const payload = { githubUrl };
|
|
2279
|
+
if (category)
|
|
2280
|
+
payload.category = category;
|
|
2278
2281
|
const res = await fetch(`${API_URL}/api/publish-cli`, {
|
|
2279
2282
|
method: "POST",
|
|
2280
2283
|
headers: { "Content-Type": "application/json" },
|
|
2281
|
-
body: JSON.stringify(
|
|
2284
|
+
body: JSON.stringify(payload)
|
|
2282
2285
|
});
|
|
2283
2286
|
const data = await res.json();
|
|
2284
2287
|
if (!res.ok) {
|
|
@@ -2286,17 +2289,29 @@ async function publishToMarketplace(githubUrl) {
|
|
|
2286
2289
|
return false;
|
|
2287
2290
|
}
|
|
2288
2291
|
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
|
|
2292
|
+
console.log(` ${import_picocolors.default.dim(`\u2192 https://api2cli.dev/cli/${data.skill.name}`)}`);
|
|
2290
2293
|
return true;
|
|
2291
2294
|
} catch {
|
|
2292
2295
|
console.error(` ${import_picocolors.default.red("\u2717")} Could not reach api2cli.dev`);
|
|
2293
2296
|
return false;
|
|
2294
2297
|
}
|
|
2295
2298
|
}
|
|
2296
|
-
var
|
|
2299
|
+
var VALID_CATEGORIES = [
|
|
2300
|
+
"social",
|
|
2301
|
+
"finance",
|
|
2302
|
+
"devtools",
|
|
2303
|
+
"marketing",
|
|
2304
|
+
"productivity",
|
|
2305
|
+
"communication",
|
|
2306
|
+
"analytics",
|
|
2307
|
+
"ai",
|
|
2308
|
+
"ecommerce",
|
|
2309
|
+
"other"
|
|
2310
|
+
];
|
|
2311
|
+
var publishCommand = new Command("publish").description("Publish a CLI to the api2cli marketplace").argument("<app>", "CLI to publish").option("--github <url>", "GitHub repo URL (e.g. user/repo)").option("--category <cat>", `Category: ${VALID_CATEGORIES.join(", ")}`).addHelpText("after", `
|
|
2297
2312
|
Examples:
|
|
2298
|
-
api2cli publish typefully --github user/typefully-cli
|
|
2299
|
-
api2cli publish dub`).action(async (app, opts) => {
|
|
2313
|
+
api2cli publish typefully --github user/typefully-cli --category social
|
|
2314
|
+
api2cli publish dub --category marketing`).action(async (app, opts) => {
|
|
2300
2315
|
const cliDir = getCliDir(app);
|
|
2301
2316
|
if (!existsSync3(cliDir)) {
|
|
2302
2317
|
console.error(`${import_picocolors.default.red("\u2717")} ${app}-cli not found.`);
|
|
@@ -2310,10 +2325,15 @@ Examples:
|
|
|
2310
2325
|
console.log(`${import_picocolors.default.yellow("\u2717")} No GitHub URL provided. Skipped.`);
|
|
2311
2326
|
return;
|
|
2312
2327
|
}
|
|
2328
|
+
const category = opts.category?.toLowerCase();
|
|
2329
|
+
if (category && !VALID_CATEGORIES.includes(category)) {
|
|
2330
|
+
console.error(`${import_picocolors.default.red("\u2717")} Invalid category "${category}". Valid: ${VALID_CATEGORIES.join(", ")}`);
|
|
2331
|
+
process.exit(1);
|
|
2332
|
+
}
|
|
2313
2333
|
console.log(`
|
|
2314
2334
|
Publishing ${import_picocolors.default.bold(`${app}-cli`)} to marketplace...
|
|
2315
2335
|
`);
|
|
2316
|
-
await publishToMarketplace(githubUrl);
|
|
2336
|
+
await publishToMarketplace(githubUrl, category);
|
|
2317
2337
|
});
|
|
2318
2338
|
|
|
2319
2339
|
// src/commands/create.ts
|
|
@@ -2326,7 +2346,63 @@ function askQuestion2(question) {
|
|
|
2326
2346
|
});
|
|
2327
2347
|
});
|
|
2328
2348
|
}
|
|
2329
|
-
async function
|
|
2349
|
+
async function createGithubRepo(app, cliDir) {
|
|
2350
|
+
const repoName = `${app}-cli`;
|
|
2351
|
+
const env = { ...process.env, PATH: `/usr/local/bin:/opt/homebrew/bin:${process.env.PATH || ""}` };
|
|
2352
|
+
console.log(` ${import_picocolors2.default.dim("Initializing git repo...")}`);
|
|
2353
|
+
const gitInit = Bun.spawnSync(["git", "init"], {
|
|
2354
|
+
cwd: cliDir,
|
|
2355
|
+
stdout: "ignore",
|
|
2356
|
+
stderr: "ignore",
|
|
2357
|
+
env
|
|
2358
|
+
});
|
|
2359
|
+
if (gitInit.exitCode !== 0) {
|
|
2360
|
+
console.error(` ${import_picocolors2.default.red("\u2717")} Failed to init git repo`);
|
|
2361
|
+
return null;
|
|
2362
|
+
}
|
|
2363
|
+
Bun.spawnSync(["git", "add", "."], { cwd: cliDir, stdout: "ignore", stderr: "ignore", env });
|
|
2364
|
+
Bun.spawnSync(["git", "commit", "-m", "Initial commit"], {
|
|
2365
|
+
cwd: cliDir,
|
|
2366
|
+
stdout: "ignore",
|
|
2367
|
+
stderr: "ignore",
|
|
2368
|
+
env
|
|
2369
|
+
});
|
|
2370
|
+
const whichGh = Bun.spawnSync(["which", "gh"], {
|
|
2371
|
+
stdout: "pipe",
|
|
2372
|
+
stderr: "ignore",
|
|
2373
|
+
env: { ...process.env, PATH: `/usr/local/bin:/opt/homebrew/bin:${process.env.PATH || ""}` }
|
|
2374
|
+
});
|
|
2375
|
+
const ghPath = whichGh.stdout.toString().trim();
|
|
2376
|
+
if (!ghPath || whichGh.exitCode !== 0) {
|
|
2377
|
+
console.error(` ${import_picocolors2.default.red("\u2717")} GitHub CLI (gh) not found. Install it: ${import_picocolors2.default.cyan("brew install gh")}`);
|
|
2378
|
+
return null;
|
|
2379
|
+
}
|
|
2380
|
+
console.log(` ${import_picocolors2.default.dim("Creating GitHub repo...")}`);
|
|
2381
|
+
const ghCreate = Bun.spawnSync([ghPath, "repo", "create", repoName, "--public", "--source", ".", "--push"], { cwd: cliDir, stdout: "pipe", stderr: "pipe" });
|
|
2382
|
+
if (ghCreate.exitCode !== 0) {
|
|
2383
|
+
const stderr = ghCreate.stderr.toString().trim();
|
|
2384
|
+
if (stderr.includes("not logged")) {
|
|
2385
|
+
console.error(` ${import_picocolors2.default.red("\u2717")} Not logged in to GitHub. Run: ${import_picocolors2.default.cyan("gh auth login")}`);
|
|
2386
|
+
} else {
|
|
2387
|
+
console.error(` ${import_picocolors2.default.red("\u2717")} Failed to create repo: ${stderr}`);
|
|
2388
|
+
}
|
|
2389
|
+
return null;
|
|
2390
|
+
}
|
|
2391
|
+
const output = ghCreate.stdout.toString().trim();
|
|
2392
|
+
const urlMatch = output.match(/https:\/\/github\.com\/[^\s]+/);
|
|
2393
|
+
if (urlMatch)
|
|
2394
|
+
return urlMatch[0];
|
|
2395
|
+
const remote = Bun.spawnSync(["git", "remote", "get-url", "origin"], {
|
|
2396
|
+
cwd: cliDir,
|
|
2397
|
+
stdout: "pipe",
|
|
2398
|
+
env
|
|
2399
|
+
});
|
|
2400
|
+
const remoteUrl = remote.stdout.toString().trim();
|
|
2401
|
+
if (remoteUrl)
|
|
2402
|
+
return remoteUrl;
|
|
2403
|
+
return null;
|
|
2404
|
+
}
|
|
2405
|
+
async function promptPublish(app, cliDir) {
|
|
2330
2406
|
const pref = getPublishPreference();
|
|
2331
2407
|
if (pref === "never")
|
|
2332
2408
|
return;
|
|
@@ -2343,16 +2419,17 @@ ${import_picocolors2.default.bold("Marketplace")}`);
|
|
|
2343
2419
|
}
|
|
2344
2420
|
if (answer === "a" || answer === "always") {
|
|
2345
2421
|
setPublishPreference("always");
|
|
2346
|
-
console.log(` ${import_picocolors2.default.dim("Saved. Will always
|
|
2422
|
+
console.log(` ${import_picocolors2.default.dim("Saved. Will always publish automatically.")}`);
|
|
2347
2423
|
} else if (answer !== "y" && answer !== "yes") {
|
|
2348
2424
|
return;
|
|
2349
2425
|
}
|
|
2350
2426
|
}
|
|
2351
|
-
const githubUrl = await
|
|
2427
|
+
const githubUrl = await createGithubRepo(app, cliDir);
|
|
2352
2428
|
if (!githubUrl) {
|
|
2353
|
-
console.log(` ${import_picocolors2.default.dim("
|
|
2429
|
+
console.log(` ${import_picocolors2.default.dim("Publish later with:")} ${import_picocolors2.default.cyan(`api2cli publish ${app}`)}`);
|
|
2354
2430
|
return;
|
|
2355
2431
|
}
|
|
2432
|
+
console.log(` ${import_picocolors2.default.green("+")} Pushed to ${import_picocolors2.default.cyan(githubUrl)}`);
|
|
2356
2433
|
await publishToMarketplace(githubUrl);
|
|
2357
2434
|
}
|
|
2358
2435
|
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 +2459,8 @@ ${import_picocolors2.default.bold("Creating")} ${import_picocolors2.default.cyan
|
|
|
2382
2459
|
});
|
|
2383
2460
|
console.log(` ${import_picocolors2.default.green("+")} Configured for ${import_picocolors2.default.bold(app)}`);
|
|
2384
2461
|
console.log(` ${import_picocolors2.default.dim("Installing dependencies...")}`);
|
|
2385
|
-
const
|
|
2462
|
+
const bunPath = process.execPath;
|
|
2463
|
+
const install = Bun.spawn([bunPath, "install"], {
|
|
2386
2464
|
cwd: cliDir,
|
|
2387
2465
|
stdout: "ignore",
|
|
2388
2466
|
stderr: "pipe"
|
|
@@ -2407,7 +2485,7 @@ ${import_picocolors2.default.bold("Next steps:")}`);
|
|
|
2407
2485
|
console.log(` 2. Build: ${import_picocolors2.default.cyan(`npx api2cli bundle ${app}`)}`);
|
|
2408
2486
|
console.log(` 3. Link: ${import_picocolors2.default.cyan(`npx api2cli link ${app}`)}`);
|
|
2409
2487
|
console.log(` 4. Auth: ${import_picocolors2.default.cyan(`${app}-cli auth set "your-token"`)}`);
|
|
2410
|
-
await promptPublish(app);
|
|
2488
|
+
await promptPublish(app, cliDir);
|
|
2411
2489
|
});
|
|
2412
2490
|
|
|
2413
2491
|
// src/commands/install.ts
|