forked from hoffi/gulp-msbuild
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
58 lines (48 loc) · 1.37 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
52
53
54
55
56
57
58
'use strict';
const through = require("through2"),
{ cloneDeep } = require("lodash"),
constants = require("./lib/constants"),
msbuildRunner = require("./lib/msbuild-runner"),
didYouMean = require("didyoumean"),
chalk = require("chalk"),
PluginError = require("plugin-error");
function mergeOptionsWithDefaults(options) {
return {
...constants.DEFAULTS,
...options
};
}
function validateOptions(options) {
for (let key in options) {
const defaultKeys = Object.keys(constants.DEFAULTS);
if (defaultKeys.indexOf(key) < 0) {
let match;
let msg = "Unknown option '" + key + "'!";
if (!!(match = didYouMean(key, defaultKeys))) {
msg += " Did you mean '" + match + "'?";
}
throw new PluginError(constants.PLUGIN_NAME, chalk.red(msg));
}
}
}
module.exports = function(options) {
const mergedOptions = cloneDeep(mergeOptionsWithDefaults(options));
validateOptions(mergedOptions);
const stream = through.obj(function (file, enc, callback) {
const 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;
};