bun-git-hooks 0.2.3 → 0.2.5
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/dist/bin/cli.js +17 -4
- package/dist/bin/config.d.ts +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/index.js +14 -2
- package/package.json +1 -1
package/dist/bin/cli.js
CHANGED
|
@@ -604,7 +604,7 @@ class CAC extends EventEmitter {
|
|
|
604
604
|
}
|
|
605
605
|
}
|
|
606
606
|
// package.json
|
|
607
|
-
var version = "0.2.
|
|
607
|
+
var version = "0.2.5";
|
|
608
608
|
|
|
609
609
|
// src/git-hooks.ts
|
|
610
610
|
import fs from "fs";
|
|
@@ -875,18 +875,26 @@ function getGitProjectRoot(directory = process3.cwd()) {
|
|
|
875
875
|
function setHooksFromConfig(projectRootPath = process3.cwd(), options = {}) {
|
|
876
876
|
if (!config || Object.keys(config).length === 0)
|
|
877
877
|
throw new Error("[ERROR] Config was not found! Please add `.git-hooks.config.{ts,js,mjs,cjs,mts,cts,json}` or `git-hooks.config.{ts,js,mjs,cjs,mts,cts,json}` or the `git-hooks` entry in package.json.\r\nCheck README for details");
|
|
878
|
+
console.log("setHooksFromConfig config", config);
|
|
878
879
|
const hookKeys = Object.keys(config).filter((key) => key !== "preserveUnused" && key !== "verbose");
|
|
880
|
+
console.log("hookKeys", hookKeys);
|
|
879
881
|
const isValidConfig = hookKeys.every((key) => VALID_GIT_HOOKS.includes(key));
|
|
882
|
+
console.log("isValidConfig", isValidConfig);
|
|
880
883
|
if (!isValidConfig)
|
|
881
884
|
throw new Error("[ERROR] Config was not in correct format. Please check git hooks or options name");
|
|
882
885
|
const preserveUnused = Array.isArray(config.preserveUnused) ? config.preserveUnused : config.preserveUnused ? VALID_GIT_HOOKS : [];
|
|
883
886
|
for (const hook of VALID_GIT_HOOKS) {
|
|
887
|
+
console.log("hook", hook);
|
|
884
888
|
if (Object.prototype.hasOwnProperty.call(config, hook)) {
|
|
889
|
+
console.log("hook in config");
|
|
885
890
|
if (!config[hook])
|
|
886
891
|
throw new Error(`[ERROR] Command for ${hook} is not set`);
|
|
892
|
+
console.log(`Hook ${hook}: `, config[hook]);
|
|
887
893
|
_setHook(hook, config[hook], projectRootPath);
|
|
888
|
-
} else if (!preserveUnused.includes(hook))
|
|
894
|
+
} else if (!preserveUnused.includes(hook)) {
|
|
895
|
+
console.log("Remove hook", hook);
|
|
889
896
|
_removeHook(hook, projectRootPath);
|
|
897
|
+
}
|
|
890
898
|
}
|
|
891
899
|
}
|
|
892
900
|
function _setHook(hook, command, projectRoot = process3.cwd()) {
|
|
@@ -898,8 +906,12 @@ function _setHook(hook, command, projectRoot = process3.cwd()) {
|
|
|
898
906
|
const hookCommand = PREPEND_SCRIPT + command;
|
|
899
907
|
const hookDirectory = path.join(gitRoot, "hooks");
|
|
900
908
|
const hookPath = path.normalize(path.join(hookDirectory, hook));
|
|
901
|
-
|
|
909
|
+
console.log("hook", { hookPath, hookCommand, hookDirectory });
|
|
910
|
+
if (!fs.existsSync(hookDirectory)) {
|
|
911
|
+
console.log("hook folder not exists");
|
|
902
912
|
fs.mkdirSync(hookDirectory, { recursive: true });
|
|
913
|
+
}
|
|
914
|
+
console.log("Create/Write hook");
|
|
903
915
|
fs.writeFileSync(hookPath, hookCommand, { mode: 493 });
|
|
904
916
|
}
|
|
905
917
|
function removeHooks(projectRoot = process3.cwd(), verbose = false) {
|
|
@@ -928,7 +940,8 @@ cli.command("[configPath]", "Install git hooks, optionally from specified config
|
|
|
928
940
|
console.log("[DEBUG] Config path:", configPath || "using default");
|
|
929
941
|
console.log("[DEBUG] Working directory:", process4.cwd());
|
|
930
942
|
}
|
|
931
|
-
|
|
943
|
+
console.log("setHooksFromConfig", { configFile: configPath });
|
|
944
|
+
setHooksFromConfig(process4.cwd(), { configFile: configPath });
|
|
932
945
|
console.log("[INFO] Successfully set all git hooks");
|
|
933
946
|
} catch (err) {
|
|
934
947
|
console.error("[ERROR] Was not able to set git hooks. Error:", err);
|
package/dist/bin/config.d.ts
CHANGED
package/dist/config.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -646,18 +646,26 @@ function _getPackageJson(projectPath = j2.cwd()) {
|
|
|
646
646
|
function setHooksFromConfig(projectRootPath = j2.cwd(), options = {}) {
|
|
647
647
|
if (!config || Object.keys(config).length === 0)
|
|
648
648
|
throw new Error("[ERROR] Config was not found! Please add `.git-hooks.config.{ts,js,mjs,cjs,mts,cts,json}` or `git-hooks.config.{ts,js,mjs,cjs,mts,cts,json}` or the `git-hooks` entry in package.json.\r\nCheck README for details");
|
|
649
|
+
console.log("setHooksFromConfig config", config);
|
|
649
650
|
const hookKeys = Object.keys(config).filter((key) => key !== "preserveUnused" && key !== "verbose");
|
|
651
|
+
console.log("hookKeys", hookKeys);
|
|
650
652
|
const isValidConfig = hookKeys.every((key) => VALID_GIT_HOOKS.includes(key));
|
|
653
|
+
console.log("isValidConfig", isValidConfig);
|
|
651
654
|
if (!isValidConfig)
|
|
652
655
|
throw new Error("[ERROR] Config was not in correct format. Please check git hooks or options name");
|
|
653
656
|
const preserveUnused = Array.isArray(config.preserveUnused) ? config.preserveUnused : config.preserveUnused ? VALID_GIT_HOOKS : [];
|
|
654
657
|
for (const hook of VALID_GIT_HOOKS) {
|
|
658
|
+
console.log("hook", hook);
|
|
655
659
|
if (Object.prototype.hasOwnProperty.call(config, hook)) {
|
|
660
|
+
console.log("hook in config");
|
|
656
661
|
if (!config[hook])
|
|
657
662
|
throw new Error(`[ERROR] Command for ${hook} is not set`);
|
|
663
|
+
console.log(`Hook ${hook}: `, config[hook]);
|
|
658
664
|
_setHook(hook, config[hook], projectRootPath);
|
|
659
|
-
} else if (!preserveUnused.includes(hook))
|
|
665
|
+
} else if (!preserveUnused.includes(hook)) {
|
|
666
|
+
console.log("Remove hook", hook);
|
|
660
667
|
_removeHook(hook, projectRootPath);
|
|
668
|
+
}
|
|
661
669
|
}
|
|
662
670
|
}
|
|
663
671
|
function _setHook(hook, command, projectRoot = j2.cwd()) {
|
|
@@ -669,8 +677,12 @@ function _setHook(hook, command, projectRoot = j2.cwd()) {
|
|
|
669
677
|
const hookCommand = PREPEND_SCRIPT + command;
|
|
670
678
|
const hookDirectory = q.join(gitRoot, "hooks");
|
|
671
679
|
const hookPath = q.normalize(q.join(hookDirectory, hook));
|
|
672
|
-
|
|
680
|
+
console.log("hook", { hookPath, hookCommand, hookDirectory });
|
|
681
|
+
if (!fs.existsSync(hookDirectory)) {
|
|
682
|
+
console.log("hook folder not exists");
|
|
673
683
|
fs.mkdirSync(hookDirectory, { recursive: true });
|
|
684
|
+
}
|
|
685
|
+
console.log("Create/Write hook");
|
|
674
686
|
fs.writeFileSync(hookPath, hookCommand, { mode: 493 });
|
|
675
687
|
}
|
|
676
688
|
function removeHooks(projectRoot = j2.cwd(), verbose = false) {
|
package/package.json
CHANGED