-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
51 lines (34 loc) · 1015 Bytes
/
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
const mix = require('laravel-mix');
class Download {
dependencies() {
this.requiresReload = `
download has been installed. Please run "npm run dev" again.
`;
return ['download'];
}
register(config) {
if (!config.urls || config.urls.length <= 0) {
throw new Error(
'You need to provide at least 1 valid url in the urls options.'
);
}
this.config = Object.assign({
enabled: mix.inProduction(),
urls: [],
dest: '',
}, config);
}
boot() {
if (this.config.enabled) {
const download = require('download');
this.config.urls.forEach((file) => {
if (this.config.dest) {
download(file.url, this.config.dest);
} else {
download(file.url, file.dest);
}
});
}
}
}
mix.extend('download', new Download());