1 Star 1 Fork 1

anydev/apihub

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
prepare.js 1.38 KB
一键复制 编辑 原始数据 按行查看 历史
Balaji Sivasakthi 提交于 2023-07-30 22:39 +08:00 . refactor: fs.mkdir error handler
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();
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/anydev/apihub.git
git@gitee.com:anydev/apihub.git
anydev
apihub
apihub
main

搜索帮助