A very simple npm publish tool
Install it:
npm install -D npm-publish-it
Add publish.js
in the root of your project folder:
import publish from "npm-publish-it";
publish({
title: 'your module name', // if not set, get the `name` of `package.json`,
// prePublish is a array, support multiple commands, like `['rm -rf dist', 'npm run build']`. Default value is []
prePublish: ['rm -rf dist', 'yarn test', 'yarn build'],
publishCommand: 'yarn publish', // publish command string, default is `npm publish`
needOtp: true // Set `true`, if publish needs one-time passcode, default is false.
});
Then execute the commands in the root of your project folder:
node publish
# or `npm pub` , if you have set a script like `"pub": "node publish"` in `package.json`.
if your package is not ES Module, you need to change
publish.js
topublish.mjs
and execute it withnode publish.mjs
ornpm pub
. Not forget to set"pub": "node publish.mjs"
in yourpackage.json
.