UNPKG

1.03 kBJavaScriptView Raw
1var $;
2
3$ = {};
4
5$.normalizePath = require('../dist/normalizePath');
6
7$.type = require('../dist/type');
8
9$.wrapList = require('../dist/wrapList');
10
11$.parseString = require('../dist/parseString');
12
13$.info = require('../dist/info');
14
15// https://github.com/kevva/download
16module.exports = async function(...arg) {
17 var download, msg, option, source, target;
18 [source, target, option] = (function() {
19 switch (arg.length) {
20 case 2:
21 return [arg[0], arg[1], null];
22 case 3:
23 return arg;
24 default:
25 throw new Error('download_/error: invalid argument length');
26 }
27 })();
28 target = $.normalizePath(target);
29 if (($.type(option)) === 'string') {
30 option = {
31 filename: option
32 };
33 }
34 // this function download was from plugin
35 download = require('download');
36 await download(source, target, option);
37 msg = `downloaded ${$.wrapList(source)} to ${$.wrapList(target)}`;
38 if (option) {
39 msg += `, as '${$.parseString(option)}'`;
40 }
41 $.info('download', msg);
42 return this;
43};