nw 0.80.0 → 0.81.0-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/lib/findpath.mjs +58 -0
- package/lib/install.mjs +204 -0
- package/package.json +17 -19
- package/index.js +0 -4
- package/lib/findpath.js +0 -20
- package/scripts/install.js +0 -137
package/README.md
CHANGED
|
@@ -103,6 +103,16 @@ var nwpath = findpath();
|
|
|
103
103
|
// nwpath will equal the path to the binary depending on your environment
|
|
104
104
|
```
|
|
105
105
|
|
|
106
|
+
## finding the path to the chromedriver binary
|
|
107
|
+
|
|
108
|
+
If you would like to programmatically retrieve the path to the chromedriver use:
|
|
109
|
+
|
|
110
|
+
``` js
|
|
111
|
+
var findpath = require('nw').findpath;
|
|
112
|
+
var chromedriver_path = findpath('chromedriver');
|
|
113
|
+
// chromedriver_path will equal the path to the binary depending on your environment
|
|
114
|
+
```
|
|
115
|
+
|
|
106
116
|
Then you can use that path to run NW.js programmatically. For example, to run in the current script's directory:
|
|
107
117
|
|
|
108
118
|
```js
|
package/lib/findpath.mjs
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { dirname } from 'node:path';
|
|
2
|
+
import { env, platform } from 'node:process';
|
|
3
|
+
import { join, resolve } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Get the platform dependant path of the NW.js or ChromeDriver binary.
|
|
8
|
+
*
|
|
9
|
+
* @param {'nwjs' | 'chromedriver'} executable Path to NW.js or Chromedriver executable.
|
|
10
|
+
* @return {string}
|
|
11
|
+
*/
|
|
12
|
+
export default function findpath(executable = 'nwjs') {
|
|
13
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
14
|
+
const nwDir = resolve(__dirname, '..', 'nwjs');
|
|
15
|
+
/**
|
|
16
|
+
* File path to executable.
|
|
17
|
+
*
|
|
18
|
+
* @type {string}
|
|
19
|
+
*/
|
|
20
|
+
let binPath = '';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Host operating system
|
|
24
|
+
*
|
|
25
|
+
* @type {NodeJS.Platform}
|
|
26
|
+
*/
|
|
27
|
+
let hostOs = env.npm_config_nwjs_platform || env.NWJS_PLATFORM || platform;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Get the platform dependant path of the NW.js binary.
|
|
31
|
+
*/
|
|
32
|
+
function findNwjs() {
|
|
33
|
+
if (hostOs === 'darwin') {
|
|
34
|
+
binPath = join(nwDir, 'nwjs.app', 'Contents', 'MacOS', 'nwjs');
|
|
35
|
+
} else if (hostOs === 'win32') {
|
|
36
|
+
binPath = join(nwDir, 'nw.exe');
|
|
37
|
+
} else {
|
|
38
|
+
binPath = join(nwDir, 'nw');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Get the platform dependant path of the ChromeDriver binary.
|
|
44
|
+
*/
|
|
45
|
+
function findChromeDriver() {
|
|
46
|
+
binPath = resolve(nwDir, `chromedriver${platform === "win32" ? ".exe" : ""}`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (executable === 'nwjs') {
|
|
50
|
+
findNwjs();
|
|
51
|
+
} else if (executable === 'chromedriver') {
|
|
52
|
+
findChromeDriver();
|
|
53
|
+
} else {
|
|
54
|
+
console.error(`[ ERROR ] Expected nwjs or chromedriver, got ${executable}.`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return binPath;
|
|
58
|
+
}
|
package/lib/install.mjs
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { createWriteStream, existsSync } from 'node:fs';
|
|
2
|
+
import { rename, rm } from 'node:fs/promises';
|
|
3
|
+
import { get } from 'node:https';
|
|
4
|
+
import { dirname, resolve } from 'node:path';
|
|
5
|
+
import { arch, env, platform, exit } from 'node:process';
|
|
6
|
+
import { fileURLToPath, URL } from 'node:url';
|
|
7
|
+
|
|
8
|
+
import compressing from 'compressing';
|
|
9
|
+
import progress from 'cli-progress';
|
|
10
|
+
import semver from 'semver';
|
|
11
|
+
|
|
12
|
+
import nodeManifest from '../package.json' assert { type: 'json' };
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* NW.js build flavor
|
|
16
|
+
*
|
|
17
|
+
* @type {'sdk' | 'normal'}
|
|
18
|
+
*/
|
|
19
|
+
let buildType = env.npm_config_nwjs_build_type || env.NWJS_BUILD_TYPE || 'normal';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Parsed string version to Semver version object
|
|
23
|
+
*/
|
|
24
|
+
let parsedVersion = semver.parse(nodeManifest.version);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Version string of the format `X.Y.Z-pre`.
|
|
28
|
+
* The prerelease segment `pre` is used to specify build flavor, or other tags.
|
|
29
|
+
*
|
|
30
|
+
* @type {string}
|
|
31
|
+
*/
|
|
32
|
+
let versionString = [
|
|
33
|
+
parsedVersion.major,
|
|
34
|
+
parsedVersion.minor,
|
|
35
|
+
parsedVersion.patch
|
|
36
|
+
].join('.');
|
|
37
|
+
|
|
38
|
+
// Check if version is a prelease.
|
|
39
|
+
if (typeof parsedVersion?.prerelease?.[0] === 'string') {
|
|
40
|
+
let prerelease = parsedVersion.prerelease[0].split('-');
|
|
41
|
+
if (prerelease.length > 1) {
|
|
42
|
+
prerelease = prerelease.slice(0, -1);
|
|
43
|
+
}
|
|
44
|
+
versionString = [versionString, ...prerelease].join('-');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Check build flavor and slice that off the `versionString`.
|
|
48
|
+
if (versionString.endsWith('-sdk')) {
|
|
49
|
+
versionString = versionString.slice(0, -4);
|
|
50
|
+
buildType = 'sdk';
|
|
51
|
+
} else if (versionString.endsWith('sdk')) {
|
|
52
|
+
versionString = versionString.slice(0, -3);
|
|
53
|
+
buildType = 'sdk';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* URL to download or get binaries from.
|
|
58
|
+
*
|
|
59
|
+
* @type {string}
|
|
60
|
+
*/
|
|
61
|
+
let url = '';
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Host operating system
|
|
65
|
+
*
|
|
66
|
+
* @type {NodeJS.Platform | 'osx' | 'win'}
|
|
67
|
+
*/
|
|
68
|
+
let hostOs = env.npm_config_nwjs_platform || env.NWJS_PLATFORM || platform;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Host architecture
|
|
72
|
+
*
|
|
73
|
+
* @type {NodeJS.Architecture}
|
|
74
|
+
*/
|
|
75
|
+
let hostArch = env.npm_config_nwjs_process_arch || arch;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* URL base prepended to `url`.
|
|
79
|
+
*
|
|
80
|
+
* @type {string}
|
|
81
|
+
*/
|
|
82
|
+
let urlBase = env.npm_config_nwjs_urlbase || env.NWJS_URLBASE || 'https://dl.nwjs.io/v';
|
|
83
|
+
|
|
84
|
+
const PLATFORM_KV = {
|
|
85
|
+
darwin: 'osx',
|
|
86
|
+
linux: 'linux',
|
|
87
|
+
win32: 'win',
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const ARCH_KV = {
|
|
91
|
+
x64: 'x64',
|
|
92
|
+
ia32: 'ia32',
|
|
93
|
+
arm64: 'arm64',
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
url = [
|
|
97
|
+
urlBase,
|
|
98
|
+
versionString,
|
|
99
|
+
'/nwjs',
|
|
100
|
+
buildType === 'normal' ? '' : `-${buildType}`,
|
|
101
|
+
'-v',
|
|
102
|
+
versionString,
|
|
103
|
+
'-',
|
|
104
|
+
PLATFORM_KV[hostOs],
|
|
105
|
+
'-',
|
|
106
|
+
ARCH_KV[hostArch],
|
|
107
|
+
PLATFORM_KV[hostOs] === 'linux' ? '.tar.gz' : '.zip'
|
|
108
|
+
].join('');
|
|
109
|
+
|
|
110
|
+
if (!PLATFORM_KV[hostOs] || !ARCH_KV[hostArch]) {
|
|
111
|
+
console.error('[ ERROR ] Could not find a compatible version of nw.js to download for your platform.');
|
|
112
|
+
exit(1);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The folder where NW.js binaries are placed.
|
|
119
|
+
*
|
|
120
|
+
* @type {string}
|
|
121
|
+
*/
|
|
122
|
+
let nwDir = resolve(__dirname, '..', 'nwjs');
|
|
123
|
+
|
|
124
|
+
if (existsSync(nwDir) === true) {
|
|
125
|
+
exit(0);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
let parsedUrl = new URL(url);
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Path to the compressed binary.
|
|
132
|
+
*
|
|
133
|
+
* @type {string}
|
|
134
|
+
*/
|
|
135
|
+
let filePath = '';
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Recursively delete the passed in directory.
|
|
139
|
+
* Rename the downloaded file.
|
|
140
|
+
* @param {string} dir - directory to remove
|
|
141
|
+
*/
|
|
142
|
+
const rmAndRename = async (dir) => {
|
|
143
|
+
await rm(dir, { recursive: true, force: true });
|
|
144
|
+
await rename(`nwjs-v${versionString}-${PLATFORM_KV[hostOs]}-${ARCH_KV[hostArch]}`, 'nwjs');
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* @param {'zip' | 'tgz'} zipOrTgz
|
|
149
|
+
* @param {string} filePath
|
|
150
|
+
* @return {Promise<void>}
|
|
151
|
+
*/
|
|
152
|
+
const decompress = function (zipOrTgz, filePath) {
|
|
153
|
+
return compressing[zipOrTgz].uncompress(filePath, '.')
|
|
154
|
+
.then(async () => await rmAndRename(filePath));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// If the url is linking to the file system,
|
|
158
|
+
// then it is assumed that a compressed binary exists in that location.
|
|
159
|
+
if (parsedUrl.protocol === 'file:') {
|
|
160
|
+
filePath = resolve(decodeURIComponent(url.slice('file://'.length)));
|
|
161
|
+
|
|
162
|
+
if (existsSync(filePath) === false) {
|
|
163
|
+
console.error('[ ERROR ] Could not find ' + filePath);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// If the compressed file is of ZIP format:
|
|
167
|
+
if (filePath.endsWith('.zip')) {
|
|
168
|
+
decompress('zip', filePath);
|
|
169
|
+
// If the compressed file is of TGZ format:
|
|
170
|
+
} else if (filePath.endsWith('.tar.gz')) {
|
|
171
|
+
decompress('tgz', filePath);
|
|
172
|
+
} else {
|
|
173
|
+
console.error(`[ ERROR ] Expected .zip or .tar.gz file format. Got ${filePath}`);
|
|
174
|
+
exit(1);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
} else {
|
|
178
|
+
|
|
179
|
+
const bar = new progress.SingleBar({}, progress.Presets.rect);
|
|
180
|
+
|
|
181
|
+
const stream = createWriteStream(nwDir);
|
|
182
|
+
|
|
183
|
+
get(url, (response) => {
|
|
184
|
+
|
|
185
|
+
let chunks = 0;
|
|
186
|
+
bar.start(Number(response.headers['content-length']), 0);
|
|
187
|
+
response.on('data', async (chunk) => {
|
|
188
|
+
chunks += chunk.length;
|
|
189
|
+
bar.increment();
|
|
190
|
+
bar.update(chunks);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
response.on('error', async () => await rm(nwDir, { force: true }));
|
|
194
|
+
|
|
195
|
+
response.on('end', () => {
|
|
196
|
+
if (PLATFORM_KV[hostOs] === 'linux') {
|
|
197
|
+
decompress('tgz', nwDir);
|
|
198
|
+
} else {
|
|
199
|
+
decompress('zip', nwDir);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
response.pipe(stream);
|
|
203
|
+
});
|
|
204
|
+
}
|
package/package.json
CHANGED
|
@@ -1,45 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nw",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.81.0-1",
|
|
4
4
|
"description": "A installer for nw.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git://github.com/nwjs/npm-installer.git"
|
|
8
8
|
},
|
|
9
|
-
"main": "
|
|
9
|
+
"main": "lib/findpath.mjs",
|
|
10
10
|
"bin": {
|
|
11
11
|
"nw": "bin/nw"
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
|
-
"postinstall": "node
|
|
14
|
+
"postinstall": "node lib/install.mjs",
|
|
15
15
|
"test": "node --test-reporter=spec --test test/index.mjs"
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
18
|
"lib",
|
|
19
|
-
"bin"
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
"bin"
|
|
20
|
+
],
|
|
21
|
+
"author": {
|
|
22
|
+
"name": "Kyle Robinson Young",
|
|
23
|
+
"url": "https://github.com/shama"
|
|
24
|
+
},
|
|
25
|
+
"contributors": [
|
|
26
|
+
{
|
|
27
|
+
"name": "nwjs/npm-installer Contributors",
|
|
28
|
+
"url": "https://github.com/nwjs/npm-installer/graphs/contributors"
|
|
29
|
+
}
|
|
22
30
|
],
|
|
23
|
-
"author": "Kyle Robinson Young",
|
|
24
31
|
"license": "MIT",
|
|
25
32
|
"dependencies": {
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"file-exists": "^2.0.0",
|
|
30
|
-
"merge": "^2.1.1",
|
|
31
|
-
"progress": "^2.0.3",
|
|
32
|
-
"rimraf": "^2.2.8",
|
|
33
|
-
"semver": "^5.1.0",
|
|
33
|
+
"cli-progress": "^3.12.0",
|
|
34
|
+
"compressing": "^1.10.0",
|
|
35
|
+
"semver": "^7.5.4",
|
|
34
36
|
"yargs": "^3.2.1"
|
|
35
37
|
},
|
|
36
38
|
"devDependencies": {
|
|
37
39
|
"request": "^2.53.0"
|
|
38
40
|
},
|
|
39
|
-
"engines": {
|
|
40
|
-
"node": "v20.5.0"
|
|
41
|
-
},
|
|
42
|
-
"packageManager": "npm@9.8.1",
|
|
43
41
|
"keywords": [
|
|
44
42
|
"nw",
|
|
45
43
|
"nw.js",
|
package/index.js
DELETED
package/lib/findpath.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
var fs = require('fs');
|
|
2
|
-
var path = require('path');
|
|
3
|
-
var bindir = path.resolve(__dirname, '..', 'nwjs');
|
|
4
|
-
|
|
5
|
-
module.exports = function() {
|
|
6
|
-
var bin = bindir;
|
|
7
|
-
var platform = process.env.npm_config_nwjs_platform || process.env.NWJS_PLATFORM || process.platform;
|
|
8
|
-
if (platform === 'darwin') {
|
|
9
|
-
if (fs.existsSync(path.join(bin, 'Contents'))) {
|
|
10
|
-
bin = path.join(bin, 'Contents', 'MacOS', 'nwjs');
|
|
11
|
-
} else {
|
|
12
|
-
bin = path.join(bin, 'nwjs.app', 'Contents', 'MacOS', 'nwjs');
|
|
13
|
-
}
|
|
14
|
-
} else if (platform === 'win32') {
|
|
15
|
-
bin = path.join(bin, 'nw.exe');
|
|
16
|
-
} else {
|
|
17
|
-
bin = path.join(bin, 'nw');
|
|
18
|
-
}
|
|
19
|
-
return bin;
|
|
20
|
-
}
|
package/scripts/install.js
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
var download = require('download');
|
|
4
|
-
var rimraf = require('rimraf');
|
|
5
|
-
var semver = require('semver');
|
|
6
|
-
var ProgressBar = require('progress')
|
|
7
|
-
var path = require('path');
|
|
8
|
-
var fs = require('fs');
|
|
9
|
-
var merge = require('merge');
|
|
10
|
-
var urlModule = require('url');
|
|
11
|
-
var Decompress = require('decompress');
|
|
12
|
-
var fileExists = require('file-exists');
|
|
13
|
-
var chalk = require('chalk');
|
|
14
|
-
|
|
15
|
-
var buildType = process.env.npm_config_nwjs_build_type || process.env.NWJS_BUILD_TYPE || 'normal';
|
|
16
|
-
|
|
17
|
-
var v = semver.parse(require('../package.json').version);
|
|
18
|
-
var version = [v.major, v.minor, v.patch].join('.');
|
|
19
|
-
if (v.prerelease && typeof v.prerelease[0] === 'string') {
|
|
20
|
-
var prerelease = v.prerelease[0].split('-');
|
|
21
|
-
if (prerelease.length > 1) {
|
|
22
|
-
prerelease = prerelease.slice(0, -1);
|
|
23
|
-
}
|
|
24
|
-
version += '-' + prerelease.join('-');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if ( version.slice(-4) === '-sdk' ){
|
|
28
|
-
version = version.slice(0, -4);
|
|
29
|
-
buildType = 'sdk';
|
|
30
|
-
} else if ( version.slice(-3) === 'sdk' ){
|
|
31
|
-
version = version.slice(0, -3);
|
|
32
|
-
buildType = 'sdk';
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
var url = false;
|
|
36
|
-
var arch = process.env.npm_config_nwjs_process_arch || process.arch;
|
|
37
|
-
var urlBase = process.env.npm_config_nwjs_urlbase || process.env.NWJS_URLBASE || 'https://dl.nwjs.io/v';
|
|
38
|
-
var buildTypeSuffix = buildType === 'normal' ? '' : ('-' + buildType);
|
|
39
|
-
var platform = process.env.npm_config_nwjs_platform || process.env.NWJS_PLATFORM || process.platform;
|
|
40
|
-
|
|
41
|
-
// Determine download url
|
|
42
|
-
switch (platform) {
|
|
43
|
-
case 'win32':
|
|
44
|
-
url = urlBase + version + '/nwjs' + buildTypeSuffix + '-v' + version + '-win-' + arch +'.zip';
|
|
45
|
-
break;
|
|
46
|
-
case 'darwin':
|
|
47
|
-
url = urlBase + version + '/nwjs' + buildTypeSuffix + '-v' + version + '-osx-' + arch + '.zip';
|
|
48
|
-
break;
|
|
49
|
-
case 'linux':
|
|
50
|
-
url = urlBase + version + '/nwjs' + buildTypeSuffix + '-v' + version + '-linux-' + arch + '.tar.gz';
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function logError(e) {
|
|
55
|
-
console.error(chalk.bold.red((typeof e === 'string') ? e : e.message));
|
|
56
|
-
process.exit(1);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function cb(error) {
|
|
60
|
-
if( error != null ) {
|
|
61
|
-
return logError( error )
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
process.nextTick(function() {
|
|
65
|
-
process.exit();
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function fileExistsAndAvailable(filepath) {
|
|
70
|
-
try {
|
|
71
|
-
return fileExists(filepath);
|
|
72
|
-
} catch(err) {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (!url) logError('Could not find a compatible version of nw.js to download for your platform.');
|
|
78
|
-
|
|
79
|
-
var dest = path.resolve(__dirname, '..', 'nwjs');
|
|
80
|
-
rimraf.sync(dest);
|
|
81
|
-
|
|
82
|
-
var bar = new ProgressBar(url + ' [:bar] :current/:totalM', {total: 100, clear: true});
|
|
83
|
-
|
|
84
|
-
var total = 0;
|
|
85
|
-
var progress = 0;
|
|
86
|
-
|
|
87
|
-
var parsedUrl = urlModule.parse(url);
|
|
88
|
-
var decompressOptions = { strip: 1, mode: '755' };
|
|
89
|
-
var filePath;
|
|
90
|
-
if( parsedUrl.protocol == 'file:' ) {
|
|
91
|
-
filePath = path.resolve(
|
|
92
|
-
decodeURIComponent(
|
|
93
|
-
url.slice( 'file://'.length )
|
|
94
|
-
)
|
|
95
|
-
);
|
|
96
|
-
if ( !fileExistsAndAvailable(filePath) ) logError(
|
|
97
|
-
'Could not find ' + filePath
|
|
98
|
-
);
|
|
99
|
-
new Decompress()
|
|
100
|
-
.src( filePath )
|
|
101
|
-
.dest( dest )
|
|
102
|
-
.use( Decompress.zip(decompressOptions) )
|
|
103
|
-
.use( Decompress.targz(decompressOptions) )
|
|
104
|
-
.run( cb );
|
|
105
|
-
} else {
|
|
106
|
-
var progress = {
|
|
107
|
-
total: null,
|
|
108
|
-
downloaded: 0,
|
|
109
|
-
start: function (response) {
|
|
110
|
-
this.total = parseInt(response.headers['content-length']);
|
|
111
|
-
bar.total = (this.total / 1000000).toFixed(2);
|
|
112
|
-
},
|
|
113
|
-
recieved: function (chunk) {
|
|
114
|
-
this.downloaded += chunk.length;
|
|
115
|
-
if (this.total) {
|
|
116
|
-
bar.update(this.downloaded / this.total);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
download(url, dest, merge({ extract: true }, decompressOptions))
|
|
122
|
-
.on('response', function (response) {
|
|
123
|
-
progress.start(response);
|
|
124
|
-
})
|
|
125
|
-
.on('data', function (chunk) {
|
|
126
|
-
progress.recieved(chunk);
|
|
127
|
-
})
|
|
128
|
-
.on('end', function () {
|
|
129
|
-
bar.terminate();
|
|
130
|
-
})
|
|
131
|
-
.then(function () {
|
|
132
|
-
cb();
|
|
133
|
-
})
|
|
134
|
-
.catch(function (err) {
|
|
135
|
-
cb(err);
|
|
136
|
-
});
|
|
137
|
-
}
|