/
adjust_bundles_path.js
42 lines (38 loc) · 1 KB
/
adjust_bundles_path.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
var through = require("through2");
var omit = require("lodash/omit");
var clone = require("lodash/clone");
var assign = require("lodash/assign");
module.exports = function(options) {
return through.obj(function(data, enc, next) {
try {
next(null, options.target ? adjustBundlesPath(data, options) : data);
} catch (err) {
next(err);
}
});
};
/**
* Appends the target name to the bundles path
*
* Each target build should be written in its own subfolder, e.g:
*
* dist/bundles/node
* dist/bundles/web
* dist/bundles/worker
*
* This should only happen when target is explicitly set.
*/
function adjustBundlesPath(data, options) {
var path = require("path");
var configuration = clone(data.configuration);
var bundlesPath = configuration.bundlesPath;
Object.defineProperty(configuration, "bundlesPath", {
configurable: true,
get: function() {
return path.join(bundlesPath, options.target);
}
});
return assign({}, omit(data, ["configuration"]), {
configuration: configuration
});
}