Files
test-repo/scripts/release/steps/publish-to-npm.js
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

44 lines
1.0 KiB
JavaScript
Raw Normal View History

2022-03-24 23:47:29 +09:00
import enquirer from "enquirer";
import spawn from "nano-spawn";
2025-12-01 07:25:25 +08:00
import { waitForEnter } from "../utilities.js";
2022-10-14 17:17:47 +08:00
export default async function publishToNpm({ dry }) {
console.log(`Ready to publish to NPM${dry ? "(--dry-run)" : ""}`);
await waitForEnter();
const commonArgs = ["publish"];
if (dry) {
commonArgs.push("--dry-run");
}
2018-06-05 16:37:52 -03:00
2022-03-24 23:47:29 +09:00
const runNpmPublish = async () => {
2022-10-14 17:17:47 +08:00
const args = [...commonArgs];
if (!dry) {
const { otp } = await enquirer.prompt({
type: "input",
name: "otp",
message: "Please enter your npm OTP",
});
args.push("--otp", otp);
}
2025-04-09 08:38:46 +08:00
await spawn("npm", args, { cwd: "./dist/prettier" });
2022-03-24 23:47:29 +09:00
};
2022-10-14 17:17:47 +08:00
/**
* Retry "npm publish" when to enter OTP is failed.
*/
for (let i = 5; i > 0; i--) {
try {
return await runNpmPublish();
} catch (error) {
if (error.code === "EOTP" && i > 0) {
console.log(`To enter OTP is failed, you can retry it ${i} times.`);
continue;
}
throw error;
}
}
}