forked from yohanb/spsave-webpack-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (28 loc) · 1.06 KB
/
Copy pathindex.js
File metadata and controls
39 lines (28 loc) · 1.06 KB
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
var spsave = require('spsave').spsave;
var utils = require('./lib/utils');
function apply(options, compiler) {
// When assets are being emmited (not yet on file system)
compiler.plugin('after-emit', function (compilation, callback) {
// Build promises and execute all at once
var assetsFileOptions = utils.getAssetsFileOptions(options.fileOptions.folder, compilation);
var spSavePromises = assetsFileOptions.map(function(fileOptions) {
return spsave(options.coreOptions, options.credentialOptions, fileOptions);
});
Promise.all(spSavePromises)
.then(function() {
callback();
})
.catch(function(error) {
console.log(error);
callback();
});
});
}
function SPSavePlugin(options) {
// Simple pattern to be able to easily access plugin
// options when the apply prototype is called
return {
apply: apply.bind(this, options)
};
}
module.exports = SPSavePlugin;