@huaiyou/hooks-git 2.0.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @huaiyou/hooks-git
2
2
 
3
+ ## 2.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Fix init command to install required dependencies (husky, lint-staged, commitlint)
8
+
9
+ ## 2.1.0
10
+
11
+ ### Minor Changes
12
+
13
+ - Add TypeScript declaration files (.d.ts) for better IDE support
14
+
3
15
  ## 1.0.0
4
16
 
5
17
  ### Major Changes
package/dist/cli.cjs CHANGED
@@ -14,7 +14,7 @@ const cac__default = /*#__PURE__*/_interopDefaultCompat(cac);
14
14
  const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
15
15
  const picocolors__default = /*#__PURE__*/_interopDefaultCompat(picocolors);
16
16
 
17
- const version = "2.0.0";
17
+ const version = "2.1.1";
18
18
 
19
19
  const logger = {
20
20
  /**
@@ -55,6 +55,16 @@ const runCommand = async (command, args) => {
55
55
  throw error;
56
56
  }
57
57
  };
58
+ async function getPackageManager() {
59
+ const cwd = process.cwd();
60
+ const hasPnpmLock = fs__default.existsSync(node_path.resolve(cwd, "pnpm-lock.yaml"));
61
+ const hasYarnLock = fs__default.existsSync(node_path.resolve(cwd, "yarn.lock"));
62
+ const hasPackageLock = fs__default.existsSync(node_path.resolve(cwd, "package-lock.json"));
63
+ if (hasPnpmLock) return "pnpm";
64
+ if (hasYarnLock) return "yarn";
65
+ if (hasPackageLock) return "npm";
66
+ return "npm";
67
+ }
58
68
  const updatePackageJson = async (callback) => {
59
69
  const pkgPath = node_path.resolve(process.cwd(), "package.json");
60
70
  if (!fs__default.existsSync(pkgPath)) {
@@ -72,11 +82,29 @@ const init = async () => {
72
82
  logger.warn("Not a git repository. Initializing...");
73
83
  await runCommand("git", ["init"]);
74
84
  }
75
- logger.info("Installing Husky...");
85
+ logger.info("Installing dependencies...");
86
+ const pm = await getPackageManager();
87
+ const devDepsNeeded = [];
88
+ if (!pkg.devDependencies?.husky && !pkg.dependencies?.husky) {
89
+ devDepsNeeded.push("husky");
90
+ }
91
+ if (!pkg.devDependencies?.["lint-staged"] && !pkg.dependencies?.["lint-staged"]) {
92
+ devDepsNeeded.push("lint-staged");
93
+ }
94
+ if (!pkg.devDependencies?.["@commitlint/cli"] && !pkg.dependencies?.["@commitlint/cli"]) {
95
+ devDepsNeeded.push("@commitlint/cli");
96
+ }
97
+ if (!pkg.devDependencies?.["@commitlint/config-conventional"] && !pkg.dependencies?.["@commitlint/config-conventional"]) {
98
+ devDepsNeeded.push("@commitlint/config-conventional");
99
+ }
100
+ if (devDepsNeeded.length > 0) {
101
+ logger.info(`Installing devDependencies: ${devDepsNeeded.join(", ")}`);
102
+ await runCommand(pm, ["add", "-D", ...devDepsNeeded]);
103
+ }
76
104
  try {
77
- await runCommand("npx", ["husky", "install"]);
105
+ await runCommand(pm === "yarn" ? "npx" : pm, ["husky", "install"]);
78
106
  } catch (e) {
79
- logger.error("Failed to install husky. Make sure dependencies are installed.");
107
+ logger.error("Failed to initialize husky.");
80
108
  }
81
109
  logger.info("Adding hooks...");
82
110
  const huskyDir = node_path.resolve(process.cwd(), ".husky");
package/dist/cli.mjs CHANGED
@@ -6,7 +6,7 @@ import { consola } from 'consola';
6
6
  import { execa } from 'execa';
7
7
  import picocolors from 'picocolors';
8
8
 
9
- const version = "2.0.0";
9
+ const version = "2.1.1";
10
10
 
11
11
  const logger = {
12
12
  /**
@@ -47,6 +47,16 @@ const runCommand = async (command, args) => {
47
47
  throw error;
48
48
  }
49
49
  };
50
+ async function getPackageManager() {
51
+ const cwd = process.cwd();
52
+ const hasPnpmLock = fs.existsSync(resolve(cwd, "pnpm-lock.yaml"));
53
+ const hasYarnLock = fs.existsSync(resolve(cwd, "yarn.lock"));
54
+ const hasPackageLock = fs.existsSync(resolve(cwd, "package-lock.json"));
55
+ if (hasPnpmLock) return "pnpm";
56
+ if (hasYarnLock) return "yarn";
57
+ if (hasPackageLock) return "npm";
58
+ return "npm";
59
+ }
50
60
  const updatePackageJson = async (callback) => {
51
61
  const pkgPath = resolve(process.cwd(), "package.json");
52
62
  if (!fs.existsSync(pkgPath)) {
@@ -64,11 +74,29 @@ const init = async () => {
64
74
  logger.warn("Not a git repository. Initializing...");
65
75
  await runCommand("git", ["init"]);
66
76
  }
67
- logger.info("Installing Husky...");
77
+ logger.info("Installing dependencies...");
78
+ const pm = await getPackageManager();
79
+ const devDepsNeeded = [];
80
+ if (!pkg.devDependencies?.husky && !pkg.dependencies?.husky) {
81
+ devDepsNeeded.push("husky");
82
+ }
83
+ if (!pkg.devDependencies?.["lint-staged"] && !pkg.dependencies?.["lint-staged"]) {
84
+ devDepsNeeded.push("lint-staged");
85
+ }
86
+ if (!pkg.devDependencies?.["@commitlint/cli"] && !pkg.dependencies?.["@commitlint/cli"]) {
87
+ devDepsNeeded.push("@commitlint/cli");
88
+ }
89
+ if (!pkg.devDependencies?.["@commitlint/config-conventional"] && !pkg.dependencies?.["@commitlint/config-conventional"]) {
90
+ devDepsNeeded.push("@commitlint/config-conventional");
91
+ }
92
+ if (devDepsNeeded.length > 0) {
93
+ logger.info(`Installing devDependencies: ${devDepsNeeded.join(", ")}`);
94
+ await runCommand(pm, ["add", "-D", ...devDepsNeeded]);
95
+ }
68
96
  try {
69
- await runCommand("npx", ["husky", "install"]);
97
+ await runCommand(pm === "yarn" ? "npx" : pm, ["husky", "install"]);
70
98
  } catch (e) {
71
- logger.error("Failed to install husky. Make sure dependencies are installed.");
99
+ logger.error("Failed to initialize husky.");
72
100
  }
73
101
  logger.info("Adding hooks...");
74
102
  const huskyDir = resolve(process.cwd(), ".husky");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huaiyou/hooks-git",
3
- "version": "2.0.0",
3
+ "version": "2.1.1",
4
4
  "description": "Git hooks configuration with Husky, Commitlint and Lint-staged",
5
5
  "bin": {
6
6
  "hy-hooks-git": "./dist/cli.mjs"