-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
39 lines (33 loc) · 1.06 KB
/
index.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
37
38
39
'use strict';
var gutil = require('gulp-util');
var through = require('through2');
var execSync = require('child_process').execSync;
function diffBranches(options) {
var filesChanged = [];
if (!options.baseBranch) {
throw new gutil.PluginError('gulp-gitflow-diff', 'baseBranch param is required');
}
var cmd = 'git diff --name-only $(git merge-base ' + options.baseBranch + ' HEAD)..HEAD';
filesChanged = execSync(cmd, {encoding: 'utf8'});
filesChanged = filesChanged.split("\n");
// last entry is just empty string
filesChanged.pop();
return through.obj(
function (file, enc, cb) {
if (isFileChanged(file, filesChanged)) {
this.push(file);
}
cb();
}
);
};
function isFileChanged(file, filesChanged) {
var currentFile = file.path.substr(process.cwd().length + 1);
if (filesChanged.indexOf(currentFile) != -1) {
return true;
} else {
return false;
}
}
module.exports = diffBranches;
module.exports.isFileChanged = isFileChanged;