forked from hoffi/gulp-msbuild
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (41 loc) · 1.32 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
40
41
42
43
44
45
46
47
48
49
50
51
'use strict';
var through = require('through2'),
_ = require('lodash'),
constants = require('./lib/constants'),
msbuildRunner = require('./lib/msbuild-runner'),
didYouMean = require('didyoumean'),
gutil = require('gulp-util'),
PluginError = gutil.PluginError;
function mergeOptionsWithDefaults(options) {
return _.extend({}, constants.DEFAULTS, options);
}
function validateOptions(options) {
for (var key in options) {
var defaultKeys = Object.keys(constants.DEFAULTS);
if (defaultKeys.indexOf(key) < 0) {
var match;
var msg = "Unknown option '" + key + "'!";
if (match = didYouMean(key, defaultKeys)) {
msg += " Did you mean '" + match + "'?";
}
throw new PluginError(constants.PLUGIN_NAME, gutil.colors.red(msg));
}
}
}
module.exports = function(options) {
var mergedOptions = _.cloneDeep(mergeOptionsWithDefaults(options));
validateOptions(mergedOptions);
var stream = through.obj(function(file, enc, callback) {
var self = this;
if (!file || !file.path) {
self.push(file);
return callback();
}
return msbuildRunner.startMsBuildTask(mergedOptions, file, self, function(err) {
if (err) return callback(err);
if (mergedOptions.emitEndEvent) self.emit("end");
return callback();
});
});
return stream;
};