代码拉取完成,页面将自动刷新
import { spawnSync } from "child_process";
import os from "os";
import fs from "fs";
// Function to run commands depending on the OS
const runCommand = (command, args) => {
const isWindows = os.platform() === "win32";
const shell = isWindows ? true : false;
const commandArgs = isWindows ? ["/C", command, ...args] : [...args];
const result = spawnSync(isWindows ? "cmd" : command, commandArgs, {
stdio: "inherit",
shell,
});
return result.status;
};
// Function to prepare Husky
const prepareHusky = () => {
// Run husky install
const huskyInstallStatus = runCommand("npx", ["husky", "install"]);
// Check if .husky directory exists, if not, create it
fs.mkdir(".husky", (err) => {
if (err) {
console.error(err);
} else {
console.log(".husky directory created successfully!");
}
});
// Set permissions for husky on macOS/Linux
if (os.platform() !== "win32") {
const setPermissionsStatus = runCommand("chmod", ["-R", "ug+x", ".husky"]);
if (setPermissionsStatus !== 0) {
console.error("Setting permissions failed");
process.exit(1);
}
}
// Exit with appropriate status code based on husky install status
if (huskyInstallStatus === 0) {
console.log("Husky preparation executed successfully!");
process.exit(0);
} else {
console.error("Husky installation failed");
process.exit(1);
}
};
prepareHusky();
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。