Fix copying directories
cpSync is still experimental.
Can you provide some context of what you are trying to do?
The current code loops through the given dir and copies files and dirs when needed,.
I have a folder called githooks.
There is a folder called pre-commit.d with multiple scripts inside. Then, there is a script called pre-commit which iterates over all the scripts in the directory in order.
When I use this script, I get an error for copying the first file inside the pre-commit.d directory after the script tried to create the folder. (Added some logging to confirm that)
Also: https://github.com/nodejs/node/pull/53127
Interessting, curious about that output.
Also, it should make more sense then, if cp just copies both folder and files, to replace the copyDir fn on line https://github.com/peacechen/node-git-hooks/pull/7/files#diff-8e53cb956f4b0661996bd517a983cd87fc5ccd2374a7e1eb4bcd9479877ac86eL33 instead of clouding up a child function with cp.
Installing Git hooks...
Error copying Git hooks: Error: ENOENT: no such file or directory, copyfile '.githooks/pre-commit.d/check-for-unresolved-conflicts' -> '.git/hooks/pre-commit.d/check-for-unresolved-conflicts'
at Object.copyFileSync (node:fs:2993:3)
at copy (/home/ccomm/Dokumente/opendtu-react-native/node_modules/node-git-hooks/install-git-hooks.js:57:6)
at copyDir (/home/ccomm/Dokumente/opendtu-react-native/node_modules/node-git-hooks/install-git-hooks.js:51:7)
at copyDir (/home/ccomm/Dokumente/opendtu-react-native/node_modules/node-git-hooks/install-git-hooks.js:46:7)
at installGitHooks (/home/ccomm/Dokumente/opendtu-react-native/node_modules/node-git-hooks/install-git-hooks.js:33:5)
at Object.<anonymous> (/home/ccomm/Dokumente/opendtu-react-native/node_modules/node-git-hooks/bin/install.js:5:8)
at Module._compile (node:internal/modules/cjs/loader:1233:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1287:10)
at Module.load (node:internal/modules/cjs/loader:1091:32)
at Module._load (node:internal/modules/cjs/loader:938:12) {
errno: -2,
syscall: 'copyfile',
code: 'ENOENT',
path: '.githooks/pre-commit.d/check-for-unresolved-conflicts',
dest: '.git/hooks/pre-commit.d/check-for-unresolved-conflicts'
}
It works fine after I run mkdir .git/hooks/pre-commit.d