-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
executable file
·57 lines (40 loc) · 1.41 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
var gutil = require('gulp-util');
var PluginError = gutil.PluginError;
// Consts
const PLUGIN_NAME = 'gulp-keycdn';
// Main function
function gulpKeyCDN(options, files) {
if (!options.apiKey) {
throw new PluginError(PLUGIN_NAME, gutil.colors.red('options.apiKey not defined'));
}
if (!options.zoneId) {
throw new PluginError(PLUGIN_NAME, gutil.colors.red('options.zoneId not defined'));
}
var KeyCDN = require('keycdn');
var keycdn = new KeyCDN(options.apiKey);
if (options.method === 'del') {
if (!files) {
throw new PluginError(PLUGIN_NAME, gutil.colors.red('files not defined'));
}
var urls = [];
gutil.log(PLUGIN_NAME, 'Purging URLs...');
keycdn.del('zones/purgeurl/' + options.zoneId + '.json', files, function (err, res) {
if (err) {
gutil.log(PLUGIN_NAME, gutil.colors.red(err));
return;
}
gutil.log(PLUGIN_NAME, gutil.colors.green(res.description));
});
} else if (options.method === 'get') {
gutil.log(PLUGIN_NAME, 'Purging Zone Cache...');
keycdn.get('zones/purge/' + options.zoneId + '.json', function (err, res) {
if (err) {
gutil.log(PLUGIN_NAME, gutil.colors.red(err));
return;
}
gutil.log(PLUGIN_NAME, gutil.colors.green(res.description));
});
}
};
// Exporting the plugin main function
module.exports = gulpKeyCDN;