-
Notifications
You must be signed in to change notification settings - Fork 2
/
pre-commit
40 lines (33 loc) · 1.13 KB
/
pre-commit
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
37
38
39
40
#!/usr/bin/env node
var exec = require('child_process').exec;
var readlineSync = require('../../node_modules/readline-sync/lib/readline-sync.js');
var path = require('path')
exec('git diff --name-only --cached', {
cwd: path.resolve(__dirname, '../..')
}, function(err1, stdout1) {
if (err1) {
console.log(err1)
process.exit(-1);
}
var names = stdout1.split('\n')
var hasAppStaged = names.some(function(name) {
return name.match(/src\/.*/g)
})
var noDistStaged = !names.some(function(name) {
return name.match(/dist\/.*/g)
})
if (hasAppStaged && noDistStaged) {
var answer = readlineSync.question('本项目发布版本,依赖本地构建(npm run build)后提交到git,发现本次提交不包含构建后的内容,确定提交吗?(Y/N)')
if (answer.toUpperCase() === 'N') {
console.log('您取消了本次提交。')
process.exit(-1);
} else {
process.exit(0);
}
} else {
console.log('no errors')
process.exit(0);
}
}).stdout.on('data', function(chunk) {
process.stdout.write(chunk);
});