Refactor/Fix release script (#13619)

This commit is contained in:
fisker Cheung authored and GitHub committed 2022-10-14 17:17:47 +08:00
1 parent 8df3b5ee60
commit 76d0890142
23 files changed
+289 -202

No files matched your search

+27 -19
View File
@@ -1,19 +1,35 @@
import { execa } from "execa";
import enquirer from "enquirer";
import { logPromise } from "../utils.js";
import { waitForEnter } from "../utils.js";
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");
}
/**
* Retry "npm publish" when to enter OTP is failed.
*/
async function retryNpmPublish() {
const runNpmPublish = async () => {
const { otp } = await enquirer.prompt({
type: "input",
name: "otp",
message: "Please enter your npm OTP",
});
await execa("npm", ["publish", "--otp", otp], { cwd: "./dist" });
const args = [...commonArgs];
if (!dry) {
const { otp } = await enquirer.prompt({
type: "input",
name: "otp",
message: "Please enter your npm OTP",
});
args.push("--otp", otp);
}
await execa("npm", args, { cwd: "./dist" });
};
/**
* Retry "npm publish" when to enter OTP is failed.
*/
for (let i = 5; i > 0; i--) {
try {
return await runNpmPublish();
@@ -26,11 +42,3 @@ async function retryNpmPublish() {
}
}
}
export default async function publishToNpm({ dry }) {
if (dry) {
return;
}
await logPromise("Publishing to npm", retryNpmPublish());
}