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