...
|
...
|
@@ -6,21 +6,33 @@ |
|
|
* @date 2016/10/12
|
|
|
*/
|
|
|
'use strict';
|
|
|
|
|
|
const fs = require('fs');
|
|
|
const sh = require('shelljs');
|
|
|
const moment = require('moment');
|
|
|
const path = require('path');
|
|
|
const config = require('../../config/config');
|
|
|
const mail = require('../models/mail');
|
|
|
|
|
|
class Collect {
|
|
|
constructor(projectname, gitlab, branch) {
|
|
|
this.projectname = projectname;
|
|
|
this.gitlab = gitlab;
|
|
|
this.branch = branch;
|
|
|
this.buildTime = moment().format('YYYYMMDDHHmmss');
|
|
|
this.mailOptions = {
|
|
|
from: 'automan@yoho.cn',
|
|
|
to: 'kai.bi@yoho.cn,zhimin.shen@yoho.cn',
|
|
|
subject: `项目:${projectname} 代码检查一览`
|
|
|
};
|
|
|
}
|
|
|
|
|
|
get buildPath() {
|
|
|
return path.join(config.buildDir, this.projectname, this.buildTime, this.projectname);
|
|
|
}
|
|
|
|
|
|
get rootPath() {
|
|
|
let buildTime = moment().format('YYYYMMDDHHmmss')
|
|
|
return path.join(config.buildDir, this.projectname, buildTime);
|
|
|
return path.join(config.buildDir, this.projectname, this.buildTime);
|
|
|
}
|
|
|
/**
|
|
|
* do some folder check
|
...
|
...
|
@@ -41,7 +53,7 @@ class Collect { |
|
|
_cloneCode(branch) {
|
|
|
var self = this;
|
|
|
this._log('cloning_code');
|
|
|
let clone_script = `git clone --depth 1 -b ${branch} ${this.gitlab}`;
|
|
|
let clone_script = `git clone --depth 1 -b ${branch} ${this.gitlab} `;
|
|
|
this._log(`>>>>>>>>> ${clone_script} >>>>>>>>>>>`);
|
|
|
|
|
|
return new Promise((reslove, reject) => {
|
...
|
...
|
@@ -75,7 +87,7 @@ class Collect { |
|
|
var self = this;
|
|
|
this._log('>>>>>>>> install dependencies >>>>>>>');
|
|
|
return new Promise((resolve, reject) => {
|
|
|
sh.cd(self.rootPath);
|
|
|
sh.cd(self.buildPath);
|
|
|
|
|
|
var child = sh.exec('npm i --production=false', {
|
|
|
silent: self.silent,
|
...
|
...
|
@@ -104,16 +116,32 @@ class Collect { |
|
|
var self = this;
|
|
|
this._log(`>>>>>>>>> check code >>>>>>>>>>>`);
|
|
|
return new Promise((reslove, reject) => {
|
|
|
sh.cd(self.rootPath);
|
|
|
sh.cd(self.buildPath);
|
|
|
|
|
|
var child = sh.exec('npm run build -s', {
|
|
|
var child = sh.exec('npm run lint-all', {
|
|
|
silent: self.silent,
|
|
|
async: true
|
|
|
});
|
|
|
|
|
|
child.stdout.pipe(fs.createWriteStream(self.logFile, {
|
|
|
flags: 'a'
|
|
|
}));
|
|
|
var dataText = '';
|
|
|
child.stdout.on('data', (chunk) => {
|
|
|
dataText += chunk.toString();
|
|
|
});
|
|
|
|
|
|
child.stdout.on("end", function () {
|
|
|
self.mailOptions.text = dataText;
|
|
|
mail.sendMail(self.mailOptions, function(err, info){
|
|
|
if(err){
|
|
|
self._log(error);
|
|
|
} else {
|
|
|
self._log('mail sent: ' + info.response);
|
|
|
}
|
|
|
})
|
|
|
});
|
|
|
|
|
|
// child.stdout.pipe(fs.createWriteStream(self.logFile, {
|
|
|
// flags: 'a'
|
|
|
// }));
|
|
|
child.stderr.pipe(fs.createWriteStream(self.logFile, {
|
|
|
flags: 'a'
|
|
|
}));
|
...
|
...
|
@@ -122,7 +150,7 @@ class Collect { |
|
|
if (code == 0) {
|
|
|
reslove();
|
|
|
} else {
|
|
|
reject(new Error(`${self.project.name} build code fail`));
|
|
|
reject(new Error(`${self.projectname} build code fail`));
|
|
|
}
|
|
|
});
|
|
|
});
|
...
|
...
|
|