初始化项目
This commit is contained in:
commit
d876ae9948
15 files changed
+2922
No files matched your search
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
*
|
||||
* @authors Tony.Deng (dengtongyu123@163.com)
|
||||
* @date 2018-05-17 11:18:41
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
const run = require('exec-cmd');
|
||||
const path = require('path');
|
||||
|
||||
//const cmdPath = '/Users/dengtongyu/code/webpage/';
|
||||
const cmdPath = '/var/local/githook/webpage/';
|
||||
const rootPath = 'src/pages';
|
||||
|
||||
exports.use = async (data, log4js) => {
|
||||
const logger = log4js.getLogger(path.parse(__filename).name);
|
||||
|
||||
let buildPath = {};
|
||||
|
||||
for (let i = 0; i < data.commits.length; i++) {
|
||||
let add = data.commits[i].added;
|
||||
let rm = data.commits[i].removed;
|
||||
let mdf = data.commits[i].modified;
|
||||
|
||||
if (add.length > 0) {
|
||||
for (let index = 0; index < add.length; index++) {
|
||||
let name = path.relative(rootPath, add[index]);
|
||||
logger.info(name);
|
||||
let re = /^\./
|
||||
let result = re.test(name);
|
||||
logger.info(result);
|
||||
if (!result) {
|
||||
name = name.split('/')[0];
|
||||
buildPath[name] = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (mdf.length > 0) {
|
||||
for (let index = 0; index < mdf.length; index++) {
|
||||
let name = path.relative(rootPath, mdf[index]);
|
||||
logger.info(name);
|
||||
let re = /^\./
|
||||
let result = re.test(name);
|
||||
logger.info(result);
|
||||
if (!result) {
|
||||
name = name.split('/')[0];
|
||||
buildPath[name] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let str = '';
|
||||
|
||||
if (JSON.stringify(buildPath) == '{}') {
|
||||
str = '<p>本次提交没有pages更新</p>'
|
||||
} else {
|
||||
for (let key in buildPath) {
|
||||
let cmd = await run('node app pack -n ' + key, {
|
||||
cwd: cmdPath
|
||||
})
|
||||
.then((arr) => {
|
||||
let res = arr[0];
|
||||
let code = arr[1];
|
||||
let buffer = arr[2];
|
||||
logger.info(res, code);
|
||||
|
||||
str += '<p>' + key + '构建完成!</p>';
|
||||
})
|
||||
.catch((err) => {
|
||||
logger.error(err);
|
||||
str += '<p>' + key + '构建失败!</p>';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {str:str,data:buildPath};
|
||||
}
|
||||
Reference in new issue
Block a user