forked from bestander/gulp-deploy-azure-cdn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (46 loc) · 1.46 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
'use strict';
var through = require('through2');
var gutil = require('gulp-util');
var path = require('path');
var deploy = require('deploy-azure-cdn');
/**
* gulp plugin for deploying files to azure storage
*/
module.exports = function (opt) {
var PLUGIN_NAME = 'gulp-deploy-azure-cdn ';
var files = [];
// upload files all at once, not one by one because we want to get some speed
// doing it concurrently
return through.obj(
function (file, enc, cb) {
var self = this;
if (path.basename(file.path)[0] === '_') {
return cb();
}
if (file.isNull()) {
self.push(file);
return cb();
}
if (file.isStream()) {
self.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported'));
return cb();
}
files.push(file);
return cb();
},
function (cb) {
var self = this;
var logger = gutil.log.bind(PLUGIN_NAME);
try {
deploy(opt, files, logger, function (err) {
if (err) {
self.emit('error', new gutil.PluginError(PLUGIN_NAME, err));
}
cb();
})
} catch (err) {
self.emit('error', new gutil.PluginError(PLUGIN_NAME, err));
cb();
}
});
};