-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode.js
36 lines (31 loc) · 1.05 KB
/
node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const fsPromise = require('fs/promises')
const path = require('path')
const packageJSON = require('./package.json')
const child_process = require('child_process')
const nodePreCommitContent = `#! /usr/bin/env node
const child_process = require('child_process')
console.log('我还是pre-commit-新增的')
child_process.exec('${packageJSON.zzzgithooks['pre-commit']}',(err,res)=>{
if(err){
return console.log('err',err)
}
console.log(res)
})
`
fsPromise.mkdir(path.resolve(__dirname, '.test2')).then(res => {
fsPromise.writeFile(path.resolve(__dirname, '.test2', 'pre-commit'), nodePreCommitContent,{
flag:'w+'
}).then(res => {
console.log('pre-commit-res', res);
child_process.exec(`git config core.hooksPath ${path.resolve(__dirname, '.test2')} && chmod +x ${path.resolve(__dirname, '.test2', 'pre-commit')}`, (err) => {
if (err) {
return console.log('err', err)
}
console.log('hhhh');
})
}).catch(err => {
console.error('pre-commit-err', err);
});
}).catch(err => {
console.error('mkdirerr', err);
});