在審查了很多選項之後,我在代碼中放置了一個預先提交的鉤子,並配置節點腳本以在存儲庫上嘗試提交之前執行。
有一個在npmjs可用的模塊,這將使它更容易,你可以很容易地
做1.安裝模塊
npm i --save-dev pre-commit
2.develop一個腳本,將運行作爲procommit鉤子來查找代碼中的特定刺痛。
// code to find specific string
(function() {
var fs = require('fs');
var glob = require('glob-fs')();
var path = require('path');
var result = 0;
var exclude = ['LICENSE',
path.join('e2e', 'util', 'db-ca', 'rds-combined-ca-bundle.pem'),
path.join('src', 'favicon.ico')];
var files = [];
files = glob.readdirSync('**');
files.map((file) => {
try {
if (!fs.lstatSync(file).isDirectory() && file.indexOf('.json') === -1
&& exclude.indexOf(file) === -1) {
var data = fs.readFileSync(file, 'utf8');
if (data.indexOf('Copyright 2017 candifood contributors') === -1) {
console.log('Please add License text in coment in the file ' + file);
result = 1;
}
}
} catch (e) {
console.log('Error:', e.stack);
}
});
process.exit(result);
})();
3.place鉤在的package.json執行
{
"name": "project-name",
"version": 1.0.0",
"license": "Apache 2.0",
"scripts": {
"license-check": "node license-check",
},
"private": true,
"dependencies": {
},
"devDependencies": {
"pre-commit": "1.2.2",
},
"pre-commit": [
"license-check"
]
}