@huaiyou/hooks-git
Advanced tools
+6
-0
| # @huaiyou/hooks-git | ||
| ## 2.1.1 | ||
| ### Patch Changes | ||
| - Fix init command to install required dependencies (husky, lint-staged, commitlint) | ||
| ## 2.1.0 | ||
@@ -4,0 +10,0 @@ |
+32
-4
@@ -17,3 +17,3 @@ #!/usr/bin/env node | ||
| const version = "2.1.0"; | ||
| const version = "2.1.1"; | ||
@@ -59,2 +59,12 @@ const logger = { | ||
| }; | ||
| async function getPackageManager() { | ||
| const cwd = process.cwd(); | ||
| const hasPnpmLock = fs__default.existsSync(node_path.resolve(cwd, "pnpm-lock.yaml")); | ||
| const hasYarnLock = fs__default.existsSync(node_path.resolve(cwd, "yarn.lock")); | ||
| const hasPackageLock = fs__default.existsSync(node_path.resolve(cwd, "package-lock.json")); | ||
| if (hasPnpmLock) return "pnpm"; | ||
| if (hasYarnLock) return "yarn"; | ||
| if (hasPackageLock) return "npm"; | ||
| return "npm"; | ||
| } | ||
| const updatePackageJson = async (callback) => { | ||
@@ -77,7 +87,25 @@ const pkgPath = node_path.resolve(process.cwd(), "package.json"); | ||
| } | ||
| logger.info("Installing Husky..."); | ||
| logger.info("Installing dependencies..."); | ||
| const pm = await getPackageManager(); | ||
| const devDepsNeeded = []; | ||
| if (!pkg.devDependencies?.husky && !pkg.dependencies?.husky) { | ||
| devDepsNeeded.push("husky"); | ||
| } | ||
| if (!pkg.devDependencies?.["lint-staged"] && !pkg.dependencies?.["lint-staged"]) { | ||
| devDepsNeeded.push("lint-staged"); | ||
| } | ||
| if (!pkg.devDependencies?.["@commitlint/cli"] && !pkg.dependencies?.["@commitlint/cli"]) { | ||
| devDepsNeeded.push("@commitlint/cli"); | ||
| } | ||
| if (!pkg.devDependencies?.["@commitlint/config-conventional"] && !pkg.dependencies?.["@commitlint/config-conventional"]) { | ||
| devDepsNeeded.push("@commitlint/config-conventional"); | ||
| } | ||
| if (devDepsNeeded.length > 0) { | ||
| logger.info(`Installing devDependencies: ${devDepsNeeded.join(", ")}`); | ||
| await runCommand(pm, ["add", "-D", ...devDepsNeeded]); | ||
| } | ||
| try { | ||
| await runCommand("npx", ["husky", "install"]); | ||
| await runCommand(pm === "yarn" ? "npx" : pm, ["husky", "install"]); | ||
| } catch (e) { | ||
| logger.error("Failed to install husky. Make sure dependencies are installed."); | ||
| logger.error("Failed to initialize husky."); | ||
| } | ||
@@ -84,0 +112,0 @@ logger.info("Adding hooks..."); |
+32
-4
@@ -9,3 +9,3 @@ #!/usr/bin/env node | ||
| const version = "2.1.0"; | ||
| const version = "2.1.1"; | ||
@@ -51,2 +51,12 @@ const logger = { | ||
| }; | ||
| async function getPackageManager() { | ||
| const cwd = process.cwd(); | ||
| const hasPnpmLock = fs.existsSync(resolve(cwd, "pnpm-lock.yaml")); | ||
| const hasYarnLock = fs.existsSync(resolve(cwd, "yarn.lock")); | ||
| const hasPackageLock = fs.existsSync(resolve(cwd, "package-lock.json")); | ||
| if (hasPnpmLock) return "pnpm"; | ||
| if (hasYarnLock) return "yarn"; | ||
| if (hasPackageLock) return "npm"; | ||
| return "npm"; | ||
| } | ||
| const updatePackageJson = async (callback) => { | ||
@@ -69,7 +79,25 @@ const pkgPath = resolve(process.cwd(), "package.json"); | ||
| } | ||
| logger.info("Installing Husky..."); | ||
| logger.info("Installing dependencies..."); | ||
| const pm = await getPackageManager(); | ||
| const devDepsNeeded = []; | ||
| if (!pkg.devDependencies?.husky && !pkg.dependencies?.husky) { | ||
| devDepsNeeded.push("husky"); | ||
| } | ||
| if (!pkg.devDependencies?.["lint-staged"] && !pkg.dependencies?.["lint-staged"]) { | ||
| devDepsNeeded.push("lint-staged"); | ||
| } | ||
| if (!pkg.devDependencies?.["@commitlint/cli"] && !pkg.dependencies?.["@commitlint/cli"]) { | ||
| devDepsNeeded.push("@commitlint/cli"); | ||
| } | ||
| if (!pkg.devDependencies?.["@commitlint/config-conventional"] && !pkg.dependencies?.["@commitlint/config-conventional"]) { | ||
| devDepsNeeded.push("@commitlint/config-conventional"); | ||
| } | ||
| if (devDepsNeeded.length > 0) { | ||
| logger.info(`Installing devDependencies: ${devDepsNeeded.join(", ")}`); | ||
| await runCommand(pm, ["add", "-D", ...devDepsNeeded]); | ||
| } | ||
| try { | ||
| await runCommand("npx", ["husky", "install"]); | ||
| await runCommand(pm === "yarn" ? "npx" : pm, ["husky", "install"]); | ||
| } catch (e) { | ||
| logger.error("Failed to install husky. Make sure dependencies are installed."); | ||
| logger.error("Failed to initialize husky."); | ||
| } | ||
@@ -76,0 +104,0 @@ logger.info("Adding hooks..."); |
+1
-1
| { | ||
| "name": "@huaiyou/hooks-git", | ||
| "version": "2.1.0", | ||
| "version": "2.1.1", | ||
| "description": "Git hooks configuration with Husky, Commitlint and Lint-staged", | ||
@@ -5,0 +5,0 @@ "bin": { |
41214
6.59%950
6.26%