api2cli-publish-to-npm
Original:🇺🇸 English
Translated
Publishes an api2cli-generated CLI package to the npm registry. Handles package.json validation, version bumping, building, and npm publish. Use when user asks to "publish to npm", "release to npm", "publish this CLI", "npm publish", "make this installable via npx", "publish a new version", or "update npm".
12installs
Sourcemelvynx/api2cli
Added on
NPX Install
npx skill4agent add melvynx/api2cli api2cli-publish-to-npmTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Publish to npm
Publish an api2cli-generated CLI to the npm registry so users can install it with or run it with .
npm i -g <name>npx <name>Phase 1: Pre-flight
Run these checks silently. Only stop if auth is missing.
Auth
Run .
npm whoami- If it succeeds: note the username, continue.
- If it fails: tell the user to run first. Stop and wait until they confirm.
npm login
Resolve package name
Read from . Determine the publish name:
namepackage.json- If has template placeholders (
name), derive the name from the directory name (e.g.{{APP_CLI}}→~/.cli/typefully-cli/).typefully-cli - Run :
npm view <name> version- 404 (not found): this is a first-time publish. Name is available; use it.
- "Unpublished": the name is frozen for 24 hours after unpublish. Ask the user to pick a different name or wait. Check alternatives like ,
<app>-cli, etc.<app>db-cli - Returns a version owned by the same npm user: this is a repeat publish.
- Returns a version owned by someone else: the name is taken. Switch to automatically.
@<npm-username>/<name>
Resolve version
- First-time publish: use the version already in .
package.json - Repeat publish: read the currently published version, increment the patch number (e.g. →
0.1.2). If the user explicitly asked for a minor or major bump, use that instead.0.1.3
Phase 2: Validate package.json
Fix so it's npm-ready. See references/package-checklist.md for details.
package.jsonApply silently:
- and
namematch resolved valuesversion - key matches the npm package name and points to
bin./dist/index.js - is
files— explicitly exclude compiled binaries (e.g.["dist/index.js", "README.md"]) which can be 50MB+dist/<app>-cli - is
type"module"
Apply and mention briefly:
- — set if missing or placeholder
description - — read from
repositorygit remote get-url origin - — default to
licenseif missing"MIT" - — add
enginesif shebang is"bun": ">=1.0"#!/usr/bin/env bun
Name changes
If the npm package name differs from the scaffold name, update and key in , all command references in , and . Do a thorough search — partial find-and-replace easily misses references in code blocks.
namebinpackage.jsonREADME.mdSKILL.mdPhase 3: Audit README for npm consumers
Before building, read the README and check it makes sense to a stranger who found this package on npmjs.com — not a monorepo contributor.
Required sections
The README must have all of the following. If any are missing or wrong, rewrite them:
-
Install section at the top with:
npm i -g <name> # or npx <name> --help -
Usage section using the final npm package name as the command (e.g.), not internal dev invocations like
breweries-cli breweries list,bun run dev --, ormake brew.bun run src/index.ts -
No absolute local paths — scan for,
/Users/,/home/, or any path that only exists on the author's machine. Remove or replace with generic instructions.~/g/ -
No monorepo-internal instructions — remove any steps that require cloning the repo, runningat a workspace root, using
bun install, or cd-ing into a sub-package. Move these to amakesection at the bottom if needed.## Development
Angle bracket escaping
npm's markdown renderer strips bare as HTML tags. Check all option descriptions and replace unescaped angle brackets:
<text>- Bad:
--format <text|json|csv|yaml> - Good: where
--format <fmt>is one of:<fmt>,text,json,csvyaml - Or: wrap in a code block where angle brackets are safe
Phase 4: Build
bash
bun run build- If build fails: STOP. Show the error. Do not continue. Help fix the build if possible, then retry.
After building, verify the shebang survived:
bash
head -1 dist/index.jsIt must be . If missing, prepend it:
#!/usr/bin/env bunbash
echo '#!/usr/bin/env bun' | cat - dist/index.js > dist/tmp && mv dist/tmp dist/index.js
chmod +x dist/index.jsPhase 5: Verify
Run and check:
npm pack --dry-run- is included
dist/index.js - No ,
src/,node_modules/, token files, or large compiled binaries leaked in.env - Total tarball size is under 200KB (typical for a bundled JS CLI). If larger, warn the user and check in package.json
files
Then show the pack summary as a final sanity check:
bash
npm pack --dry-run 2>&1 | head -30Ask the user: "Does the README look right for an npm package page?" before continuing.
Phase 6: Confirm and publish
Present one summary for confirmation:
Ready to publish:
<name>@<version> (first-time / update)
account: <npm-username>
files: dist/index.js, README.md, package.json (<size>)
install: npm i -g <name>
npx: npx <name> --helpAsk: "Publish?"
If user confirms, tell them to run this command in their terminal:
bash
cd <cli-directory> && npm publish --access publicThe agent cannot run itself because npm's 2FA requires interactive browser authentication. The user must run the command, which will:
npm publish- Show "Authenticate your account at: "
<url> - Open their browser to authenticate (passkey, OTP, etc.)
- Complete the publish
If publish fails, read the error and help the user resolve it.
Phase 7: Done
After successful publish, report:
https://www.npmjs.com/package/<name>npm i -g <name>npx <name> --help
Updating an existing npm package
When the user asks to "update npm" or "publish a new version":
- Bump version in (patch by default, e.g.
package.json→0.1.1). Do not use0.1.2(it creates git tags).npm version - Rebuild:
bun run build - Verify shebang: must be
head -1 dist/index.js#!/usr/bin/env bun - Verify pack: — confirm files and size look correct
npm pack --dry-run 2>&1 - Tell user to publish in their terminal:
cd <cli-directory> && npm publish --access public
If the update includes a name change (e.g. renaming the command), follow the Name Changes checklist in Phase 2 before building.
Do NOT
- Do not publish if the build failed.
- Do not run from the agent shell — it requires interactive browser auth. Always tell the user to run it in their terminal.
npm publish - Do not retry or handle 2FA programmatically.
npm login - Do not publish files outside and
dist/index.jsunless the user explicitly asks.README.md - Do not run (creates git tags); bump version in
npm versiondirectly.package.json - Do not include the compiled standalone binary () in the published package — it is 50MB+ and not needed for npm consumers.
dist/<app>-cli