nw 0.84.0 → 0.85.0-1-sdk
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 +61 -126
- package/bin/nw.js +27 -24
- package/lib/app_assets.js +12 -9
- package/package.json +19 -12
- package/src/decompress.js +95 -0
- package/src/decompress.test.js +27 -0
- package/src/ffmpeg.js +38 -0
- package/src/ffmpeg.test.js +31 -0
- package/src/get.js +213 -0
- package/src/index.js +8 -0
- package/src/node.js +50 -0
- package/src/node.test.js +24 -0
- package/src/nw.js +60 -0
- package/src/nw.test.js +28 -0
- package/src/postinstall.js +63 -0
- package/src/request.js +27 -0
- package/src/request.test.js +25 -0
- package/src/run.js +77 -0
- package/src/util.js +89 -0
- package/lib/findpath.js +0 -57
- package/lib/install.js +0 -229
package/README.md
CHANGED
|
@@ -1,173 +1,108 @@
|
|
|
1
1
|
# nw
|
|
2
2
|
|
|
3
|
-
An installer for [NW.js](https://nwjs.io).
|
|
3
|
+
An npm installer for [NW.js](https://nwjs.io).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/nw)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Install
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
Install locally to your project with: `npm install nw` and then in your `package.json` add a script:
|
|
9
|
+
### Latest version of normal build flavor:
|
|
11
10
|
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
"scripts": {
|
|
15
|
-
"start": "nw"
|
|
16
|
-
}
|
|
17
|
-
}
|
|
11
|
+
```shell
|
|
12
|
+
npm install --save-dev nw
|
|
18
13
|
```
|
|
19
14
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
If your project is in another folder, add the path to the project `"start": "nw path/to/app"`.
|
|
23
|
-
|
|
24
|
-
You could also call `nw` directly from `node_modules/.bin/nw` instead of adding to your `package.json`.
|
|
25
|
-
|
|
26
|
-
### global
|
|
27
|
-
You can also install globally with `npm install nw -g` and then in any project type `nw` to run the project. Installing locally is recommended though as each project can have its own dependent version of nw.js.
|
|
15
|
+
### Specific version with changes to installer:
|
|
28
16
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
1. `git clone https://github.com/zcbenz/nw-sample-apps && cd nw-sample-apps`
|
|
33
|
-
2. `npm init`
|
|
34
|
-
3. `npm install nw`
|
|
35
|
-
4. `"node_modules/.bin/nw" file-explorer`
|
|
36
|
-
|
|
37
|
-
and now you should see a file explorer demo app.
|
|
38
|
-
|
|
39
|
-
## command line options
|
|
40
|
-
There are a few (platform-specific) arguments you can pass to the `nw` executable to
|
|
41
|
-
customize your nw.js application:
|
|
42
|
-
|
|
43
|
-
* `--mac_plist <path-to-plist-file>`: (OS X only) Copies the given file to Info.plist in the app
|
|
44
|
-
bundle. This lets you do things like change your app's name and point to a different icon.
|
|
45
|
-
|
|
46
|
-
* `--mac_icon <path-to-icns-file>`: (OS X only) Copies the given .icns file to the Resources/ dir
|
|
47
|
-
in the app bundle. You will need to point to the file with a custom plist file as well (see
|
|
48
|
-
`--mac_list`)
|
|
49
|
-
|
|
50
|
-
**NOTE**: These options will keep the copied files in the app bundle for as long as the bundle is
|
|
51
|
-
on the filesystem (they're not deleted between app invocations). As a result, they're not
|
|
52
|
-
recommended if you installed nw globally using `-g`. Also note that
|
|
53
|
-
[OS X caches these files](http://proteo.me.uk/2011/08/mac-application-bundle-caching/),
|
|
54
|
-
so you may need to manually clear these cached files during development.
|
|
55
|
-
|
|
56
|
-
## install a specific version of nw.js
|
|
57
|
-
|
|
58
|
-
To install a specific version of nw.js use npm with the specific version: `npm install nw@0.12.0`
|
|
59
|
-
|
|
60
|
-
> *Please note:* This npm package version tracks the version of nw.js that will be installed, with an additional build number that is used for revisions to the installer. As such `0.12.0-1` and `0.12.0-2` will both install `nw.js@0.12.0` but the latter has newer changes to the installer.
|
|
61
|
-
|
|
62
|
-
You may use `npm view nw versions` to view the list of available versions.
|
|
17
|
+
```shell
|
|
18
|
+
npm install --save-dev nw@0.85.0-1
|
|
19
|
+
```
|
|
63
20
|
|
|
64
|
-
|
|
21
|
+
> You may use `npm view nw versions` to view the list of available versions.
|
|
65
22
|
|
|
66
|
-
|
|
23
|
+
### Specify build flavor:
|
|
67
24
|
|
|
68
|
-
```
|
|
69
|
-
npm install nw
|
|
25
|
+
```shell
|
|
26
|
+
npm install --save-dev nw@sdk
|
|
70
27
|
```
|
|
71
28
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
```
|
|
75
|
-
nwjs_build_type=sdk
|
|
76
|
-
```
|
|
29
|
+
> Optionally set `nwjs_build_type=sdk` in `.npmrc` or `NWJS_BUILD_TYPE=sdk` environment variable.
|
|
77
30
|
|
|
78
|
-
|
|
31
|
+
### Specify platform:
|
|
79
32
|
|
|
80
|
-
|
|
81
|
-
export NWJS_BUILD_TYPE=sdk
|
|
82
|
-
```
|
|
33
|
+
Set `nwjs_platform` in `.npmrc` or `NWJS_PLATFORM` environment variable. Defaults to `process.platform`.
|
|
83
34
|
|
|
84
|
-
|
|
35
|
+
### Specify architecture:
|
|
85
36
|
|
|
86
|
-
|
|
87
|
-
npm install nw@0.13.3-sdk
|
|
88
|
-
```
|
|
37
|
+
Set `nwjs_arch` in `.npmrc` or `NWJS_ARCH` environment variable. Defaults to `process.arch`.
|
|
89
38
|
|
|
90
|
-
|
|
39
|
+
### Specify cache directory:
|
|
91
40
|
|
|
92
|
-
|
|
41
|
+
Set `nwjs_cache_dir` in `.npmrc` or `NWJS_ARCH` environment variable. Defaults to `./node_modules/nw`.
|
|
93
42
|
|
|
94
|
-
|
|
43
|
+
### Specify cache flag:
|
|
95
44
|
|
|
96
|
-
|
|
45
|
+
Set `nwjs_cache` in `.npmrc` or `NWJS_ARCH` environment variable to keep or delete cached binaries. Defaults to `true`.
|
|
97
46
|
|
|
98
|
-
|
|
47
|
+
### Specify ffmpeg flag:
|
|
99
48
|
|
|
100
|
-
|
|
101
|
-
var findpath = require('nw').findpath;
|
|
102
|
-
var nwpath = findpath();
|
|
103
|
-
// nwpath will equal the path to the binary depending on your environment
|
|
104
|
-
```
|
|
49
|
+
Set `nwjs_ffmpeg` in `.npmrc` or `NWJS_ARCH` environment variable to toggle downloading [community FFmpeg binaries](https://github.com/nwjs-ffmpeg-prebuilt/nwjs-ffmpeg-prebuilt). Defaults to `false`.
|
|
105
50
|
|
|
106
|
-
|
|
51
|
+
### Specify Native Addon flag:
|
|
107
52
|
|
|
108
|
-
|
|
53
|
+
Set `nwjs_native_addon` in `.npmrc` or `NWJS_NATIVE_ADDON` environment variable to toggle downloading NW.js Node headers. Defaults to `false`.
|
|
109
54
|
|
|
110
|
-
|
|
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
|
-
```
|
|
55
|
+
### Specify download URL:
|
|
115
56
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
```js
|
|
119
|
-
require('child_process').spawn(
|
|
120
|
-
require('nw').findpath(),
|
|
121
|
-
['.'].concat( process.argv.slice(2) ),
|
|
122
|
-
{
|
|
123
|
-
cwd: __dirname,
|
|
124
|
-
detached: true,
|
|
125
|
-
stdio: 'ignore'
|
|
126
|
-
}
|
|
127
|
-
).unref();
|
|
128
|
-
```
|
|
57
|
+
Set `nwjs_urlbase` in `.npmrc` or `NWJS_URLBASE` environment variable. Defaults to `https://dl.nwjs.io`. The file system (`file://`) is also supported.
|
|
129
58
|
|
|
130
|
-
##
|
|
59
|
+
## Usage
|
|
131
60
|
|
|
132
|
-
|
|
61
|
+
Add a script in your `package.json`:
|
|
133
62
|
|
|
134
|
-
```
|
|
135
|
-
|
|
63
|
+
```json
|
|
64
|
+
{
|
|
65
|
+
"scripts": {
|
|
66
|
+
"start": "nw /path/to/app"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
136
69
|
```
|
|
137
70
|
|
|
138
|
-
|
|
71
|
+
Executing `npm start` runs the NW.js app. Omitting the file path makes NW.js check for valid project in current working directory. You can also call `nw` directly from `node_modules/.bin/nw`.
|
|
139
72
|
|
|
140
|
-
|
|
141
|
-
nwjs_urlbase=http://my.own.location/somewhere
|
|
142
|
-
```
|
|
73
|
+
## Command Line Options
|
|
143
74
|
|
|
144
|
-
|
|
75
|
+
There are a few (platform-specific) arguments you can pass to the `nw` executable to customize your nw.js application:
|
|
145
76
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
```
|
|
77
|
+
* `--mac_plist <path-to-plist-file>`: (OS X only) Copies the given file to Info.plist in the app
|
|
78
|
+
bundle. This lets you do things like change your app's name and point to a different icon.
|
|
149
79
|
|
|
150
|
-
|
|
80
|
+
* `--mac_icon <path-to-icns-file>`: (OS X only) Copies the given .icns file to the Resources/ dir
|
|
81
|
+
in the app bundle. You will need to point to the file with a custom plist file as well (see
|
|
82
|
+
`--mac_list`)
|
|
151
83
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
84
|
+
**NOTE**: These options will keep the copied files in the app bundle for as long as the bundle is
|
|
85
|
+
on the filesystem (they're not deleted between app invocations). As a result, they're not
|
|
86
|
+
recommended if you installed nw globally using `-g`. Also note that
|
|
87
|
+
[OS X caches these files](http://proteo.me.uk/2011/08/mac-application-bundle-caching/),
|
|
88
|
+
so you may need to manually clear these cached files during development.
|
|
155
89
|
|
|
156
|
-
##
|
|
90
|
+
## APIs
|
|
157
91
|
|
|
158
|
-
|
|
92
|
+
### Find path to the NW.js binary:
|
|
159
93
|
|
|
160
|
-
```
|
|
161
|
-
|
|
94
|
+
``` js
|
|
95
|
+
import { findpath } from 'nw';
|
|
96
|
+
var path = findpath();
|
|
162
97
|
```
|
|
163
98
|
|
|
164
|
-
|
|
99
|
+
## Find the path to the chromedriver binary
|
|
165
100
|
|
|
166
|
-
```
|
|
167
|
-
|
|
101
|
+
``` js
|
|
102
|
+
import { findpath } from 'nw';
|
|
103
|
+
var path = findpath('chromedriver');
|
|
168
104
|
```
|
|
169
105
|
|
|
170
|
-
|
|
106
|
+
## License
|
|
171
107
|
|
|
172
|
-
|
|
173
|
-
[nw.js](https://github.com/nwjs/nw.js)'s code and this installer use the MIT license.
|
|
108
|
+
[NW.js](https://github.com/nwjs/nw.js)'s code and this installer use the MIT license.
|
package/bin/nw.js
CHANGED
|
@@ -1,56 +1,59 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
4
|
+
import { existsSync, renameSync } from 'node:fs';
|
|
5
|
+
import { dirname, resolve } from 'node:path';
|
|
6
|
+
import { platform, argv, nextTick, exit, execPath } from 'node:process';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
import { copyAssets } from '../lib/app_assets.js';
|
|
10
|
+
import util from '../src/util.js';
|
|
11
|
+
|
|
12
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
10
13
|
|
|
11
14
|
function run() {
|
|
12
15
|
// Rename nw.js's own package.json as workaround for https://github.com/nwjs/nw.js/issues/1503
|
|
13
|
-
var packagejson =
|
|
14
|
-
var packagejsonBackup =
|
|
15
|
-
if (!
|
|
16
|
+
var packagejson = resolve(__dirname, '..', 'package.json');
|
|
17
|
+
var packagejsonBackup = resolve(__dirname, '..', 'package_backup.json');
|
|
18
|
+
if (!existsSync(packagejsonBackup)) {
|
|
16
19
|
try {
|
|
17
|
-
|
|
18
|
-
} catch (err) {}
|
|
20
|
+
renameSync(packagejson, packagejsonBackup);
|
|
21
|
+
} catch (err) { }
|
|
19
22
|
}
|
|
20
23
|
|
|
21
24
|
// copy over any asset files (icons, etc) specified via CLI args:
|
|
22
|
-
copyAssets(
|
|
25
|
+
copyAssets(platform, util.findpath());
|
|
23
26
|
|
|
24
27
|
// Normalize cli args
|
|
25
|
-
var args =
|
|
28
|
+
var args = argv.slice(2);
|
|
26
29
|
var cwd = (args.length < 1) ? '.' : args[0];
|
|
27
|
-
if (!
|
|
30
|
+
if (!existsSync(resolve(cwd))) {
|
|
28
31
|
args = ['.'].concat(args);
|
|
29
32
|
} else {
|
|
30
33
|
args = [cwd].concat(args.slice(1));
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
// Spawn node-webkit
|
|
34
|
-
var nw = spawn(findpath(), args, { stdio: 'inherit' });
|
|
35
|
-
nw.on('close', function() {
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
var nw = spawn(util.findpath(), args, { stdio: 'inherit' });
|
|
38
|
+
nw.on('close', function () {
|
|
39
|
+
nextTick(function () {
|
|
40
|
+
exit(0);
|
|
38
41
|
});
|
|
39
42
|
});
|
|
40
43
|
|
|
41
44
|
// Restore package.json shortly after nw is spawned
|
|
42
|
-
setTimeout(function() {
|
|
45
|
+
setTimeout(function () {
|
|
43
46
|
try {
|
|
44
|
-
if (
|
|
45
|
-
|
|
47
|
+
if (existsSync(packagejsonBackup)) {
|
|
48
|
+
renameSync(packagejsonBackup, packagejson);
|
|
46
49
|
}
|
|
47
|
-
} catch (err) {}
|
|
50
|
+
} catch (err) { }
|
|
48
51
|
}, 1000);
|
|
49
52
|
}
|
|
50
53
|
|
|
51
|
-
if (!
|
|
54
|
+
if (!existsSync(util.findpath())) {
|
|
52
55
|
console.log('nw.js appears to have failed to download and extract. Attempting to download and extract again...');
|
|
53
|
-
var child = spawn(
|
|
56
|
+
var child = spawn(execPath, [resolve(__dirname, '..', 'src', 'postinstall.js')], { stdio: 'inherit' });
|
|
54
57
|
child.on('close', run);
|
|
55
58
|
} else {
|
|
56
59
|
run();
|
package/lib/app_assets.js
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
import yargs from 'yargs';
|
|
5
|
+
|
|
6
|
+
const argv = yargs(process.argv.slice(2)).argv;
|
|
4
7
|
|
|
5
8
|
// Helper to simulate the shell's "cp" command
|
|
6
9
|
function copyFileSync(srcFile, destFile) {
|
|
7
|
-
|
|
10
|
+
let content = fs.readFileSync(srcFile);
|
|
8
11
|
fs.writeFileSync(destFile, content);
|
|
9
12
|
}
|
|
10
13
|
|
|
11
14
|
// Copy asset files (specified via process.argv) over to the app binary's folder
|
|
12
|
-
|
|
15
|
+
export function copyAssets(platform, binPath) {
|
|
13
16
|
// OS X: Save a custom plist file to Contents/Info.plist in the
|
|
14
17
|
// app bundle. This lets you customize things like the app's menubar
|
|
15
18
|
// name and icon (see argv.mac_icon below)
|
|
16
19
|
if (argv.mac_plist && platform === 'darwin') {
|
|
17
|
-
|
|
20
|
+
let plistPath = path.join(binPath, '..', '..', 'Info.plist');
|
|
18
21
|
copyFileSync(argv.mac_plist, plistPath);
|
|
19
22
|
}
|
|
20
23
|
|
|
@@ -22,8 +25,8 @@ exports.copyAssets = function copyAssets(platform, binPath) {
|
|
|
22
25
|
// Note that for the icon to work properly you need to point to
|
|
23
26
|
// it with a custom plist file.
|
|
24
27
|
if (argv.mac_icon && platform === 'darwin') {
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
let iconName = path.basename(argv.mac_icon); // Preserve the file's name
|
|
29
|
+
let iconPath = path.join(binPath, '..', '..', 'Resources', iconName);
|
|
27
30
|
copyFileSync(argv.mac_icon, iconPath);
|
|
28
31
|
}
|
|
29
|
-
}
|
|
32
|
+
}
|
package/package.json
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nw",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.85.0-1-sdk",
|
|
4
|
+
"description": "An installer for nw.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git://github.com/nwjs/npm-installer.git"
|
|
8
8
|
},
|
|
9
|
-
"
|
|
9
|
+
"type": "module",
|
|
10
|
+
"main": "src/index.js",
|
|
10
11
|
"bin": {
|
|
11
12
|
"nw": "bin/nw.js"
|
|
12
13
|
},
|
|
13
14
|
"scripts": {
|
|
14
|
-
"postinstall": "node
|
|
15
|
-
"test": "
|
|
16
|
-
"
|
|
15
|
+
"postinstall": "node src/postinstall.js",
|
|
16
|
+
"test": "vitest run",
|
|
17
|
+
"demo": "nw ./test/app"
|
|
17
18
|
},
|
|
18
19
|
"files": [
|
|
20
|
+
"bin",
|
|
19
21
|
"lib",
|
|
20
|
-
"
|
|
22
|
+
"src"
|
|
21
23
|
],
|
|
22
24
|
"author": {
|
|
23
25
|
"name": "Kyle Robinson Young",
|
|
@@ -31,10 +33,11 @@
|
|
|
31
33
|
],
|
|
32
34
|
"license": "MIT",
|
|
33
35
|
"dependencies": {
|
|
34
|
-
"
|
|
35
|
-
"compressing": "^1.10.0",
|
|
36
|
+
"axios": "^1.6.8",
|
|
36
37
|
"semver": "^7.5.4",
|
|
37
|
-
"
|
|
38
|
+
"tar": "^6.2.1",
|
|
39
|
+
"yargs": "^17.7.2",
|
|
40
|
+
"yauzl-promise": "^4.0.0"
|
|
38
41
|
},
|
|
39
42
|
"keywords": [
|
|
40
43
|
"nw",
|
|
@@ -47,5 +50,9 @@
|
|
|
47
50
|
"installer",
|
|
48
51
|
"desktop",
|
|
49
52
|
"application"
|
|
50
|
-
]
|
|
51
|
-
|
|
53
|
+
],
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"selenium-webdriver": "^4.18.1",
|
|
56
|
+
"vitest": "^1.4.0"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import stream from "node:stream";
|
|
4
|
+
|
|
5
|
+
import tar from "tar";
|
|
6
|
+
import yauzl from "yauzl-promise";
|
|
7
|
+
|
|
8
|
+
import util from "./util.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Decompresses a file at `filePath` to `cacheDir` directory.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} filePath - file path to compressed binary
|
|
14
|
+
* @param {string} cacheDir - directory to decompress into
|
|
15
|
+
*/
|
|
16
|
+
export default async function decompress(filePath, cacheDir) {
|
|
17
|
+
if (filePath.endsWith(".zip")) {
|
|
18
|
+
await unzip(filePath, cacheDir);
|
|
19
|
+
} else {
|
|
20
|
+
await tar.extract({
|
|
21
|
+
file: filePath,
|
|
22
|
+
C: cacheDir
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Get file mode from entry. Reference implementation is [here](https://github.com/fpsqdb/zip-lib/blob/ac447d269218d396e05cd7072d0e9cd82b5ec52c/src/unzip.ts#L380).
|
|
29
|
+
*
|
|
30
|
+
* @param {yauzl.Entry} entry - Yauzl entry
|
|
31
|
+
* @return {number} - entry's file mode
|
|
32
|
+
*/
|
|
33
|
+
function modeFromEntry(entry) {
|
|
34
|
+
const attr = entry.externalFileAttributes >> 16 || 33188;
|
|
35
|
+
|
|
36
|
+
return [448 /* S_IRWXU */, 56 /* S_IRWXG */, 7 /* S_IRWXO */]
|
|
37
|
+
.map(mask => attr & mask)
|
|
38
|
+
.reduce((a, b) => a + b, attr & 61440 /* S_IFMT */);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Unzip `zippedFile` to `cacheDir`.
|
|
43
|
+
*
|
|
44
|
+
* @async
|
|
45
|
+
* @function
|
|
46
|
+
* @param {string} zippedFile - file path to .zip file
|
|
47
|
+
* @param {string} cacheDir - directory to unzip in
|
|
48
|
+
* @return {Promise<void>}
|
|
49
|
+
*/
|
|
50
|
+
async function unzip(zippedFile, cacheDir) {
|
|
51
|
+
const zip = await yauzl.open(zippedFile);
|
|
52
|
+
let entry = await zip.readEntry();
|
|
53
|
+
const symlinks = []; // Array to hold symbolic link entries
|
|
54
|
+
|
|
55
|
+
while (entry !== null) {
|
|
56
|
+
let entryPathAbs = path.join(cacheDir, entry.filename);
|
|
57
|
+
/* Check if entry is a symbolic link */
|
|
58
|
+
const isSymlink = ((modeFromEntry(entry) & 0o170000) === 0o120000);
|
|
59
|
+
|
|
60
|
+
if (isSymlink) {
|
|
61
|
+
/* Store symlink entries to process later */
|
|
62
|
+
symlinks.push(entry);
|
|
63
|
+
} else {
|
|
64
|
+
/* Handle regular files and directories */
|
|
65
|
+
await fs.promises.mkdir(path.dirname(entryPathAbs), {recursive: true});
|
|
66
|
+
if (!entry.filename.endsWith('/')) { // Skip directories
|
|
67
|
+
const readStream = await entry.openReadStream();
|
|
68
|
+
const writeStream = fs.createWriteStream(entryPathAbs);
|
|
69
|
+
await stream.promises.pipeline(readStream, writeStream);
|
|
70
|
+
|
|
71
|
+
/* Set file permissions after the file has been written */
|
|
72
|
+
const mode = modeFromEntry(entry);
|
|
73
|
+
await fs.promises.chmod(entryPathAbs, mode);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/* Read next entry */
|
|
78
|
+
entry = await zip.readEntry();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/* Process symbolic links after all other files have been extracted */
|
|
82
|
+
for (const symlinkEntry of symlinks) {
|
|
83
|
+
let entryPathAbs = path.join(cacheDir, symlinkEntry.filename);
|
|
84
|
+
const readStream = await symlinkEntry.openReadStream();
|
|
85
|
+
const chunks = [];
|
|
86
|
+
readStream.on("data", (chunk) => chunks.push(chunk));
|
|
87
|
+
await new Promise(resolve => readStream.on("end", resolve));
|
|
88
|
+
const linkTarget = Buffer.concat(chunks).toString('utf8').trim();
|
|
89
|
+
|
|
90
|
+
const fileExists = await util.fileExists(entryPathAbs);
|
|
91
|
+
if (!fileExists) {
|
|
92
|
+
await fs.promises.symlink(linkTarget, entryPathAbs);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
|
|
3
|
+
import { beforeAll, describe, it } from "vitest";
|
|
4
|
+
|
|
5
|
+
import decompress from "./decompress.js";
|
|
6
|
+
import request from "./request.js";
|
|
7
|
+
|
|
8
|
+
describe("get/decompress", function () {
|
|
9
|
+
|
|
10
|
+
let tarUrl = "https://dl.nwjs.io/v0.83.0/nwjs-sdk-v0.83.0-linux-x64.tar.gz";
|
|
11
|
+
let zipUrl = "https://dl.nwjs.io/v0.83.0/nwjs-sdk-v0.83.0-osx-x64.zip";
|
|
12
|
+
|
|
13
|
+
beforeAll(async function () {
|
|
14
|
+
await fs.promises.mkdir("./test/fixture/cache", {recursive: true});
|
|
15
|
+
|
|
16
|
+
await request(tarUrl, "./test/fixture/cache/nw.tar.gz");
|
|
17
|
+
await request(zipUrl, "./test/fixture/cache/nw.zip");
|
|
18
|
+
}, Infinity);
|
|
19
|
+
|
|
20
|
+
it("decompresses a Linux tarball", async function () {
|
|
21
|
+
await decompress("./test/fixture/cache/nw.tar.gz", "./test/fixture/cache");
|
|
22
|
+
}, Infinity);
|
|
23
|
+
|
|
24
|
+
it("decompresses a MacOS zip", async function () {
|
|
25
|
+
await decompress("./test/fixture/cache/nw.zip", "./test/fixture/cache");
|
|
26
|
+
}, Infinity);
|
|
27
|
+
});
|
package/src/ffmpeg.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
|
|
3
|
+
import request from "./request.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Download community FFmpeg binary from `https://github.com/nwjs-ffmpeg-prebuilt/nwjs-ffmpeg-prebuilt`.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} downloadUrl - Download server
|
|
9
|
+
* @param {string} version - Runtime version
|
|
10
|
+
* @param {string} platform - NW supported platform
|
|
11
|
+
* @param {string} arch - NW supported architecture
|
|
12
|
+
* @param {string} cacheDir - Directory to store FFmpeg binary
|
|
13
|
+
* @return {Promise<string>} Path of compressed file which containscommunity FFmpeg binary.
|
|
14
|
+
*/
|
|
15
|
+
export default async function ffmpeg(downloadUrl, version, platform, arch, cacheDir) {
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* URL to download specific FFmpeg binary from.
|
|
19
|
+
*
|
|
20
|
+
* @type {string}
|
|
21
|
+
*/
|
|
22
|
+
const url = [
|
|
23
|
+
downloadUrl,
|
|
24
|
+
version,
|
|
25
|
+
`${version}-${platform}-${arch}.zip`,
|
|
26
|
+
].join('/');
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Absolute path of compressed file which contains FFmpeg binary.
|
|
30
|
+
*/
|
|
31
|
+
const ffmpegFileAbs = path.resolve(
|
|
32
|
+
cacheDir,
|
|
33
|
+
`ffmpeg-${version}-${platform}-${arch}.zip`,
|
|
34
|
+
);
|
|
35
|
+
await request(url, ffmpegFileAbs);
|
|
36
|
+
|
|
37
|
+
return ffmpegFileAbs;
|
|
38
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
|
|
4
|
+
import { afterEach, beforeAll, describe, expect, it } from "vitest";
|
|
5
|
+
|
|
6
|
+
import ffmpeg from "./ffmpeg.js";
|
|
7
|
+
import util from "./util.js";
|
|
8
|
+
|
|
9
|
+
describe("get/ffmpeg", function () {
|
|
10
|
+
|
|
11
|
+
let ffmpegFile = '';
|
|
12
|
+
|
|
13
|
+
afterEach(function () {
|
|
14
|
+
fs.promises.rm(ffmpegFile, { recursive: true, force: true });
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
beforeAll(async function () {
|
|
18
|
+
await fs.promises.mkdir("./test/fixture", { recursive: true });
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("downloades community prebuild FFmpeg for specifc platform", async function () {
|
|
22
|
+
ffmpegFile = await ffmpeg(
|
|
23
|
+
"https://github.com/nwjs-ffmpeg-prebuilt/nwjs-ffmpeg-prebuilt/releases/download",
|
|
24
|
+
"0.83.0",
|
|
25
|
+
util.PLATFORM_KV[process.platform],
|
|
26
|
+
util.ARCH_KV[process.arch],
|
|
27
|
+
"./test/fixture"
|
|
28
|
+
);
|
|
29
|
+
expect(util.fileExists(ffmpegFile)).resolves.toBe(true);
|
|
30
|
+
}, Infinity);
|
|
31
|
+
});
|