nw-builder 4.0.0-rc.8 → 4.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/.github/{CHANGELOG.md → CHANGELOG-3.md} +0 -0
- package/.github/workflows/cd.yml +1 -1
- package/.github/workflows/ci.yml +2 -2
- package/README.md +17 -17
- package/package.json +15 -17
- package/src/bld/compress.js +20 -35
- package/src/bld/linuxCfg.js +31 -13
- package/src/bld/osxCfg.js +88 -0
- package/src/bld/package.js +30 -9
- package/src/cli.js +1 -1
- package/src/get/getManifest.js +31 -0
- package/src/get/getReleaseInfo.js +36 -0
- package/src/log.js +24 -0
- package/src/nwbuild.js +49 -18
- package/test/demo/nwapp/package.json +15 -1
- package/test/demo/bld.js +0 -12
- package/test/demo/run.js +0 -12
|
File without changes
|
package/.github/workflows/cd.yml
CHANGED
package/.github/workflows/ci.yml
CHANGED
package/README.md
CHANGED
|
@@ -15,33 +15,33 @@ npm install nw-builder
|
|
|
15
15
|
|
|
16
16
|
## Usage
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
At a glance module usage:
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
```javascript
|
|
21
|
+
import { nwbuild } from "nw-builder";
|
|
21
22
|
|
|
22
23
|
nwbuild({
|
|
23
|
-
srcDir: "./nwapp",
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
arch: "x64",
|
|
24
|
+
srcDir: "./nwapp", // directory to store nw app files
|
|
25
|
+
version: "0.69.1", // latest or stable or 0.x.y
|
|
26
|
+
flavour: "sdk", //sdk (dev) or normal (prod)
|
|
27
|
+
platform: "linux", //linux, osx, win
|
|
28
|
+
arch: "x64", //ia32 or x64
|
|
29
29
|
outDir: "./build",
|
|
30
30
|
// flags with their default values
|
|
31
|
-
//
|
|
32
|
-
// you want to change some behaviour
|
|
31
|
+
cacheDir: "./cache", //directory to store nw binaries and shared libraries
|
|
33
32
|
downloadUrl: "https://dl.nwjs.io",
|
|
34
|
-
manifestUrl: "https://nwjs.io/versions"
|
|
35
|
-
run: false,
|
|
36
|
-
noCache: false,
|
|
37
|
-
zip: false
|
|
33
|
+
manifestUrl: "https://nwjs.io/versions",
|
|
34
|
+
run: false, //run app to quickly demo it
|
|
35
|
+
noCache: false, //delete and redownload nw version
|
|
36
|
+
zip: false, // optionally zip files
|
|
38
37
|
});
|
|
39
|
-
|
|
40
38
|
```
|
|
41
39
|
|
|
42
|
-
|
|
40
|
+
At a glance CLI usage:
|
|
43
41
|
|
|
44
|
-
|
|
42
|
+
```shell
|
|
43
|
+
nwbuild ./nwapp --version=0.70.1 --flavour=sdk --platform=linux --arch=x64 --outDir=./build
|
|
44
|
+
```
|
|
45
45
|
|
|
46
46
|
## Contributing
|
|
47
47
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nw-builder",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "Build NW.js desktop applications for Mac, Windows and Linux.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"NW.js",
|
|
@@ -8,7 +8,11 @@
|
|
|
8
8
|
"Desktop",
|
|
9
9
|
"Application"
|
|
10
10
|
],
|
|
11
|
-
"author":
|
|
11
|
+
"author": {
|
|
12
|
+
"name": "Steffen Müller",
|
|
13
|
+
"email": "steffen@mllrsohn.com",
|
|
14
|
+
"url": "https://github.com/steffenmllr"
|
|
15
|
+
},
|
|
12
16
|
"license": "MIT",
|
|
13
17
|
"main": "./src/nwbuild.js",
|
|
14
18
|
"type": "module",
|
|
@@ -18,20 +22,17 @@
|
|
|
18
22
|
"url": "https://github.com/nwutils/nw-builder.git"
|
|
19
23
|
},
|
|
20
24
|
"scripts": {
|
|
21
|
-
"format": "prettier --write
|
|
25
|
+
"format": "prettier --write \"**/*.{js,md}\"",
|
|
22
26
|
"lint": "eslint ./src",
|
|
23
27
|
"docs": "jsdoc ./src/nwbuild.js -d docs",
|
|
24
|
-
"demo
|
|
25
|
-
"demo:bld": "cd ./test/demo && node bld.js",
|
|
26
|
-
"demo:cli": "cd ./test/demo && nwbuild ./nwapp --version=0.69.1 --flavour=sdk --platform=linux --arch=x64 --outDir=./build"
|
|
28
|
+
"demo": "cd ./test/demo && nwbuild ./nwapp --version=0.69.1 --flavour=sdk --platform=linux --arch=x64 --outDir=./build"
|
|
27
29
|
},
|
|
28
30
|
"devDependencies": {
|
|
29
31
|
"eslint": "^8.25.0",
|
|
30
32
|
"eslint-config-tjw-jsdoc": "^1.0.3",
|
|
31
|
-
"eslint-plugin-jsdoc": "^39.3.3",
|
|
32
33
|
"jest": "^29.2.0",
|
|
33
34
|
"jest-environment-jsdom": "^29.2.0",
|
|
34
|
-
"jsdoc": "^
|
|
35
|
+
"jsdoc": "^4.0.0",
|
|
35
36
|
"jsdom": "^20.0.0",
|
|
36
37
|
"prettier": "^2.7.1"
|
|
37
38
|
},
|
|
@@ -39,10 +40,11 @@
|
|
|
39
40
|
"archiver": "^5.3.1",
|
|
40
41
|
"cli-progress": "^3.11.2",
|
|
41
42
|
"extract-zip": "^2.0.1",
|
|
42
|
-
"plist": "^3.0.
|
|
43
|
+
"plist": "^3.0.6",
|
|
43
44
|
"progress": "^2.0.3",
|
|
44
45
|
"rcedit": "^3.0.1",
|
|
45
46
|
"tar": "^6.1.11",
|
|
47
|
+
"winston": "^3.8.2",
|
|
46
48
|
"yargs": "^17.5.1"
|
|
47
49
|
},
|
|
48
50
|
"bin": {
|
|
@@ -77,14 +79,10 @@
|
|
|
77
79
|
"eslint:recommended",
|
|
78
80
|
"tjw-jsdoc"
|
|
79
81
|
],
|
|
80
|
-
"
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
],
|
|
85
|
-
"plugins": [
|
|
86
|
-
"jsdoc"
|
|
87
|
-
]
|
|
82
|
+
"rules": {
|
|
83
|
+
"jsdoc/require-file-overview": "off",
|
|
84
|
+
"jsdoc/match-description": "off"
|
|
85
|
+
}
|
|
88
86
|
},
|
|
89
87
|
"jest": {
|
|
90
88
|
"testEnvironment": "jsdom"
|
package/src/bld/compress.js
CHANGED
|
@@ -1,49 +1,34 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import archiver from "archiver";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
import { log } from "../log.js";
|
|
5
|
+
|
|
6
|
+
const compress = (outDir, type = "zip") => {
|
|
5
7
|
const output = fs.createWriteStream(`${outDir}.${type}`);
|
|
6
8
|
const archive = archiver("zip");
|
|
7
9
|
|
|
8
10
|
return new Promise((res, rej) => {
|
|
9
|
-
output.on('close', function() {
|
|
10
|
-
console.log(archive.pointer() + ' total bytes');
|
|
11
|
-
console.log('archiver has been finalized and the output file descriptor has closed.');
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
// This event is fired when the data source is drained no matter what was the data source.
|
|
15
|
-
// It is not part of this library but rather from the NodeJS Stream API.
|
|
16
|
-
// @see: https://nodejs.org/api/stream.html#stream_event_end
|
|
17
|
-
output.on('end', function() {
|
|
18
|
-
console.log('Data has been drained');
|
|
19
|
-
res(0);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
archive.on('warning', function(err) {
|
|
23
|
-
if (err.code === 'ENOENT') {
|
|
24
|
-
// log warning
|
|
25
|
-
console.log(err);
|
|
26
|
-
} else {
|
|
27
|
-
// throw error
|
|
28
|
-
console.log(err);
|
|
29
|
-
rej(1);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
11
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
rej(1);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
archive.pipe(output);
|
|
12
|
+
output.on("close", () => {
|
|
13
|
+
res(0);
|
|
14
|
+
});
|
|
40
15
|
|
|
41
|
-
|
|
16
|
+
archive.on("warning", (err) => {
|
|
17
|
+
if (err.code === "ENOENT") {
|
|
18
|
+
log.debug(err);
|
|
19
|
+
} else {
|
|
20
|
+
rej(err);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
42
23
|
|
|
43
|
-
|
|
24
|
+
archive.on("error", (err) => {
|
|
25
|
+
rej(err);
|
|
26
|
+
});
|
|
44
27
|
|
|
28
|
+
archive.pipe(output);
|
|
29
|
+
archive.directory(outDir, false);
|
|
30
|
+
archive.finalize();
|
|
45
31
|
});
|
|
46
|
-
|
|
47
32
|
};
|
|
48
33
|
|
|
49
|
-
export { compress };
|
|
34
|
+
export { compress };
|
package/src/bld/linuxCfg.js
CHANGED
|
@@ -1,17 +1,35 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { rename, writeFile } from "node:fs/promises";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
let fileContent = `[Desktop Entry]
|
|
5
|
-
Name=${pkg.name}
|
|
6
|
-
Version=${pkg.version}
|
|
7
|
-
Exec=bash -c "nw package.nw"
|
|
8
|
-
Type=Application
|
|
9
|
-
Terminal=false`;
|
|
3
|
+
import { log } from "../log.js";
|
|
10
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Generates a Desktop Entry file for Linux
|
|
7
|
+
* https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s06.html
|
|
8
|
+
*
|
|
9
|
+
* @param {object} pkg srcDir's package.json as JSON
|
|
10
|
+
* @param {string} outDir directory which stores build artifacts
|
|
11
|
+
* @return {undefined}
|
|
12
|
+
*/
|
|
13
|
+
export const setLinuxConfig = async (pkg, outDir) => {
|
|
14
|
+
let desktopEntryFile = {
|
|
15
|
+
Type: "Application",
|
|
16
|
+
Name: pkg.name,
|
|
17
|
+
Exec: pkg.name,
|
|
18
|
+
};
|
|
19
|
+
await rename(`${outDir}/nw`, `${outDir}/${pkg.name}`);
|
|
20
|
+
if (typeof pkg.nwbuild.linuxCfg === "object") {
|
|
21
|
+
Object.keys(pkg.nwbuild.linuxCfg).forEach((key) => {
|
|
22
|
+
if (key !== "Type") {
|
|
23
|
+
desktopEntryFile[key] = pkg.nwbuild.linuxCfg[key];
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
let fileContent = `[Desktop Entry]\n`;
|
|
28
|
+
Object.keys(desktopEntryFile).forEach((key) => {
|
|
29
|
+
fileContent += `${key}=${desktopEntryFile[key]}\n`;
|
|
30
|
+
log.debug(`Add ${key}=${desktopEntryFile[key]} to Desktop Entry File`);
|
|
31
|
+
});
|
|
11
32
|
let filePath = `${outDir}/${pkg.name}.desktop`;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return 0;
|
|
33
|
+
await writeFile(filePath, fileContent);
|
|
34
|
+
log.debug("Desktop Entry file generated");
|
|
15
35
|
};
|
|
16
|
-
|
|
17
|
-
export { setLinuxConfig };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
|
|
3
|
+
import plist from "plist";
|
|
4
|
+
|
|
5
|
+
const setOsxConfig = async (pkg, outDir, releaseInfo) => {
|
|
6
|
+
// Rename CFBundleDisplayName in Contents/Info.plist
|
|
7
|
+
let contents_info_plist_path = `${outDir}/nwjs.app/Contents/Info.plist`;
|
|
8
|
+
let contents_info_plist_json = plist.parse(
|
|
9
|
+
await fs.readFile(contents_info_plist_path, "utf-8"),
|
|
10
|
+
);
|
|
11
|
+
contents_info_plist_json.CFBundleDisplayName = pkg.name;
|
|
12
|
+
let contents_info_plist = plist.build(contents_info_plist_json);
|
|
13
|
+
await fs.writeFile(contents_info_plist_path, contents_info_plist);
|
|
14
|
+
|
|
15
|
+
// Rename CFBundleDisplayName in Contents/Resources/en.lproj/InfoPlist.strings
|
|
16
|
+
|
|
17
|
+
// Rename Helper apps in Contents/Framework.framework/Versions/n.n.n.n/Helpers
|
|
18
|
+
let helper_app_path_alerts = (name = "nwjs") =>
|
|
19
|
+
`${outDir}/nwjs.app/Contents/Frameworks/nwjs Framework.framework/Versions/${releaseInfo.components.chromium}/Helpers/${name} Helper (Alerts).app`;
|
|
20
|
+
let helper_app_path_gpu = (name = "nwjs") =>
|
|
21
|
+
`${outDir}/nwjs.app/Contents/Frameworks/nwjs Framework.framework/Versions/${releaseInfo.components.chromium}/Helpers/${name} Helper (GPU).app`;
|
|
22
|
+
let helper_app_path_plugin = (name = "nwjs") =>
|
|
23
|
+
`${outDir}/nwjs.app/Contents/Frameworks/nwjs Framework.framework/Versions/${releaseInfo.components.chromium}/Helpers/${name} Helper (Plugin).app`;
|
|
24
|
+
let helper_app_path_renderer = (name = "nwjs") =>
|
|
25
|
+
`${outDir}/nwjs.app/Contents/Frameworks/nwjs Framework.framework/Versions/${releaseInfo.components.chromium}/Helpers/${name} Helper (Renderer).app`;
|
|
26
|
+
let helper_app_path = (name = "nwjs") =>
|
|
27
|
+
`${outDir}/nwjs.app/Contents/Frameworks/nwjs Framework.framework/Versions/${releaseInfo.components.chromium}/Helpers/${name} Helper.app`;
|
|
28
|
+
await fs.rename(helper_app_path_alerts(), helper_app_path_alerts(pkg.name));
|
|
29
|
+
await fs.rename(helper_app_path_gpu(), helper_app_path_gpu(pkg.name));
|
|
30
|
+
await fs.rename(helper_app_path_plugin(), helper_app_path_plugin(pkg.name));
|
|
31
|
+
await fs.rename(
|
|
32
|
+
helper_app_path_renderer(),
|
|
33
|
+
helper_app_path_renderer(pkg.name),
|
|
34
|
+
);
|
|
35
|
+
await fs.rename(helper_app_path(), helper_app_path(pkg.name));
|
|
36
|
+
|
|
37
|
+
let helper_app_alerts_plist_path = `${helper_app_path_alerts(
|
|
38
|
+
pkg.name,
|
|
39
|
+
)}/Contents/Info.plist`;
|
|
40
|
+
let helper_app_gpu_plist_path = `${helper_app_path_gpu(
|
|
41
|
+
pkg.name,
|
|
42
|
+
)}/Contents/Info.plist`;
|
|
43
|
+
let helper_app_plugin_plist_path = `${helper_app_path_plugin(
|
|
44
|
+
pkg.name,
|
|
45
|
+
)}/Contents/Info.plist`;
|
|
46
|
+
let helper_app_render_plist_path = `${helper_app_path_renderer(
|
|
47
|
+
pkg.name,
|
|
48
|
+
)}/Contents/Info.plist`;
|
|
49
|
+
let helper_app_plist_path = `${helper_app_path(
|
|
50
|
+
pkg.name,
|
|
51
|
+
)}/Contents/Info.plist`;
|
|
52
|
+
|
|
53
|
+
let helper_app_alerts_plist_json = plist.parse(
|
|
54
|
+
await fs.readFile(helper_app_alerts_plist_path, "utf-8"),
|
|
55
|
+
);
|
|
56
|
+
let helper_app_gpu_plist_json = plist.parse(
|
|
57
|
+
await fs.readFile(helper_app_gpu_plist_path, "utf-8"),
|
|
58
|
+
);
|
|
59
|
+
let helper_app_plugin_plist_json = plist.parse(
|
|
60
|
+
await fs.readFile(helper_app_plugin_plist_path, "utf-8"),
|
|
61
|
+
);
|
|
62
|
+
let helper_app_render_plist_json = plist.parse(
|
|
63
|
+
await fs.readFile(helper_app_render_plist_path, "utf-8"),
|
|
64
|
+
);
|
|
65
|
+
let helper_app_plist_json = plist.parse(
|
|
66
|
+
await fs.readFile(helper_app_plist_path, "utf-8"),
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
helper_app_alerts_plist_json.CFBundleDisplayName = pkg.name;
|
|
70
|
+
helper_app_gpu_plist_json.CFBundleDisplayName = pkg.name;
|
|
71
|
+
helper_app_render_plist_json.CFBundleDisplayName = pkg.name;
|
|
72
|
+
helper_app_plugin_plist_json.CFBundleDisplayName = pkg.name;
|
|
73
|
+
helper_app_plist_json.CFBundleDisplayName = pkg.name;
|
|
74
|
+
|
|
75
|
+
let helper_app_alerts_plist = plist.build(helper_app_alerts_plist_json);
|
|
76
|
+
let helper_app_gpu_plist = plist.build(helper_app_gpu_plist_json);
|
|
77
|
+
let helper_app_render_plist = plist.build(helper_app_render_plist_json);
|
|
78
|
+
let helper_app_plugin_plist = plist.build(helper_app_plugin_plist_json);
|
|
79
|
+
let helper_app_plist = plist.build(helper_app_plist_json);
|
|
80
|
+
|
|
81
|
+
await fs.writeFile(helper_app_alerts_plist_path, helper_app_alerts_plist);
|
|
82
|
+
await fs.writeFile(helper_app_gpu_plist_path, helper_app_gpu_plist);
|
|
83
|
+
await fs.writeFile(helper_app_plugin_plist_path, helper_app_plugin_plist);
|
|
84
|
+
await fs.writeFile(helper_app_render_plist_path, helper_app_render_plist);
|
|
85
|
+
await fs.writeFile(helper_app_plist_path, helper_app_plist);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export { setOsxConfig };
|
package/src/bld/package.js
CHANGED
|
@@ -1,13 +1,30 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { cp, readFile, rm } from "node:fs/promises";
|
|
2
|
+
|
|
3
|
+
import { log } from "../log.js";
|
|
2
4
|
|
|
3
5
|
import { compress } from "./compress.js";
|
|
4
6
|
import { setLinuxConfig } from "./linuxCfg.js";
|
|
7
|
+
import { setOsxConfig } from "./osxCfg.js";
|
|
5
8
|
import { setWinConfig } from "./winCfg.js";
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Generate NW build artifacts
|
|
12
|
+
*
|
|
13
|
+
* @param {string} srcDir Directory to hold NW development files
|
|
14
|
+
* @param {string} nwDir Directory to hold NW binaries
|
|
15
|
+
* @param {string} outDir Directory to store build artifacts
|
|
16
|
+
* @param {"linux" | "osx" | "win"} platform Platform is the operating system type
|
|
17
|
+
* @param {"zip" | boolean} zip Specify if the build artifacts are to be zipped
|
|
18
|
+
* @param {object} releaseInfo NW version specific release information
|
|
19
|
+
* @return {undefined}
|
|
20
|
+
*/
|
|
21
|
+
const packager = async (srcDir, nwDir, outDir, platform, zip, releaseInfo) => {
|
|
22
|
+
log.debug(`Remove any files at ${outDir} directory`);
|
|
23
|
+
await rm(outDir, { force: true, recursive: true });
|
|
24
|
+
log.debug(`Copy ${nwDir} files to ${outDir} directory`);
|
|
25
|
+
await cp(nwDir, outDir, { recursive: true });
|
|
26
|
+
log.debug(`Copy ${srcDir} files to ${outDir} directory`);
|
|
27
|
+
await cp(
|
|
11
28
|
srcDir,
|
|
12
29
|
`${outDir}/${
|
|
13
30
|
platform !== "osx" ? "package.nw" : "nwjs.app/Contents/Resources/nw.app"
|
|
@@ -17,13 +34,16 @@ const packager = async (srcDir, nwDir, outDir, platform, zip) => {
|
|
|
17
34
|
},
|
|
18
35
|
);
|
|
19
36
|
|
|
20
|
-
|
|
37
|
+
log.debug("Get NW's package.json as a buffer");
|
|
38
|
+
let buffer = await readFile(
|
|
21
39
|
`${outDir}/${
|
|
22
40
|
platform !== "osx" ? "package.nw" : "nwjs.app/Contents/Resources/nw.app"
|
|
23
41
|
}/package.json`,
|
|
24
42
|
);
|
|
43
|
+
log.debug("Convert package.json buffer into JSON");
|
|
25
44
|
let pkg = JSON.parse(buffer);
|
|
26
45
|
|
|
46
|
+
log.debug(`Starting platform specific config steps for ${platform}`);
|
|
27
47
|
switch (platform) {
|
|
28
48
|
case "linux":
|
|
29
49
|
setLinuxConfig(pkg, outDir);
|
|
@@ -31,17 +51,18 @@ const packager = async (srcDir, nwDir, outDir, platform, zip) => {
|
|
|
31
51
|
case "win":
|
|
32
52
|
setWinConfig(pkg, outDir);
|
|
33
53
|
break;
|
|
54
|
+
case "osx":
|
|
55
|
+
setOsxConfig(pkg, outDir, releaseInfo);
|
|
56
|
+
break;
|
|
34
57
|
default:
|
|
35
58
|
break;
|
|
36
59
|
}
|
|
37
60
|
|
|
38
61
|
if (zip === true) {
|
|
39
62
|
await compress(outDir);
|
|
40
|
-
} else if (zip === "zip"
|
|
63
|
+
} else if (zip === "zip") {
|
|
41
64
|
await compress(outDir, zip);
|
|
42
65
|
}
|
|
43
|
-
|
|
44
|
-
return 0;
|
|
45
66
|
};
|
|
46
67
|
|
|
47
68
|
export { packager };
|
package/src/cli.js
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { get } from "node:https";
|
|
2
|
+
|
|
3
|
+
import { log } from "../log.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Get manifest (array of NW release metadata) from URL
|
|
7
|
+
*
|
|
8
|
+
* @param {string} manifestUrl Url to manifest
|
|
9
|
+
* @return {Promise <object | undefined>}
|
|
10
|
+
*/
|
|
11
|
+
export const getManifest = (manifestUrl) => {
|
|
12
|
+
let chunks = undefined;
|
|
13
|
+
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
get(manifestUrl, (res) => {
|
|
16
|
+
res.on("data", (chunk) => {
|
|
17
|
+
chunks += chunk;
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
res.on("error", (e) => {
|
|
21
|
+
log.error(e);
|
|
22
|
+
reject(undefined);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
res.on("end", () => {
|
|
26
|
+
log.debug("Succesfully cached manifest metadata");
|
|
27
|
+
resolve(chunks);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { access, readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
|
|
3
|
+
import { log } from "../log.js";
|
|
4
|
+
|
|
5
|
+
import { getManifest } from "./getManifest.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Get version specific release metadata
|
|
9
|
+
*
|
|
10
|
+
* @param {string} version NW version
|
|
11
|
+
* @param {string} cacheDir Directory to store NW binaries
|
|
12
|
+
* @param {string} manifestUrl Url to manifest
|
|
13
|
+
* @return {object} Version specific release info
|
|
14
|
+
*/
|
|
15
|
+
export const getReleaseInfo = async (version, cacheDir, manifestUrl) => {
|
|
16
|
+
let releaseData = undefined;
|
|
17
|
+
try {
|
|
18
|
+
await access(`${cacheDir}/manifest.json`);
|
|
19
|
+
log.debug(`Manifest file already exists locally under ${cacheDir}`);
|
|
20
|
+
} catch (e) {
|
|
21
|
+
log.debug(`Manifest file does not exist locally`);
|
|
22
|
+
log.debug(`Downloading latest manifest file under ${cacheDir}`);
|
|
23
|
+
const data = await getManifest(manifestUrl);
|
|
24
|
+
await writeFile(`${cacheDir}/manifest.json`, data.slice(9));
|
|
25
|
+
} finally {
|
|
26
|
+
log.debug("Store manifest metadata in memory");
|
|
27
|
+
let manifestData = await readFile(`${cacheDir}/manifest.json`);
|
|
28
|
+
log.debug("Convert manifest data into JSON");
|
|
29
|
+
let manifestJson = JSON.parse(manifestData);
|
|
30
|
+
log.debug(`Search for ${version} specific release data`);
|
|
31
|
+
releaseData = manifestJson.versions.find(
|
|
32
|
+
(release) => release.version === `v${version}`,
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
return releaseData;
|
|
36
|
+
};
|
package/src/log.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createLogger, format, transports } from "winston";
|
|
2
|
+
|
|
3
|
+
const { combine, timestamp, printf } = format;
|
|
4
|
+
|
|
5
|
+
const customFormat = printf(({ level, message, timestamp }) => {
|
|
6
|
+
return `[ ${level.toUpperCase()} ] ${timestamp} ${message}`;
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export const log = createLogger({
|
|
10
|
+
format: combine(timestamp(), customFormat),
|
|
11
|
+
transports: [
|
|
12
|
+
new transports.Console({
|
|
13
|
+
level: "info",
|
|
14
|
+
}),
|
|
15
|
+
],
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
if (process.env.NODE_ENV !== "production") {
|
|
19
|
+
log.add(
|
|
20
|
+
new transports.Console({
|
|
21
|
+
level: "debug",
|
|
22
|
+
}),
|
|
23
|
+
);
|
|
24
|
+
}
|
package/src/nwbuild.js
CHANGED
|
@@ -1,31 +1,34 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { access, constants, readFile, rm } from "node:fs/promises";
|
|
2
|
+
import { cwd } from "node:process";
|
|
2
3
|
|
|
3
4
|
import { decompress } from "./get/decompress.js";
|
|
4
5
|
import { develop } from "./run/develop.js";
|
|
5
6
|
import { download } from "./get/download.js";
|
|
7
|
+
import { getReleaseInfo } from "./get/getReleaseInfo.js";
|
|
6
8
|
import { remove } from "./get/remove.js";
|
|
7
9
|
import { packager } from "./bld/package.js";
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* Options schema
|
|
13
|
+
*
|
|
11
14
|
* @typedef {Object} OptionsSchema
|
|
12
|
-
* @property {string}
|
|
13
|
-
* @property {string}
|
|
14
|
-
* @property {string}
|
|
15
|
-
* @property {"sdk" | "normal"}
|
|
15
|
+
* @property {string} srcDir
|
|
16
|
+
* @property {string} cacheDir
|
|
17
|
+
* @property {string} version
|
|
18
|
+
* @property {"sdk" | "normal"} flavour
|
|
16
19
|
* @property {"linux" | "osx" | "win"} platform
|
|
17
|
-
* @property {"ia32" | "x64"}
|
|
18
|
-
* @property {string}
|
|
20
|
+
* @property {"ia32" | "x64"} arch
|
|
21
|
+
* @property {string} outDir
|
|
19
22
|
*/
|
|
20
23
|
|
|
21
24
|
/**
|
|
22
25
|
*
|
|
23
|
-
* @param
|
|
26
|
+
* @param {OptionsSchema} obj
|
|
24
27
|
* @return {void}
|
|
25
28
|
*/
|
|
26
29
|
const nwbuild = async ({
|
|
27
30
|
srcDir,
|
|
28
|
-
cacheDir =
|
|
31
|
+
cacheDir = `${cwd()}/cache`,
|
|
29
32
|
version,
|
|
30
33
|
flavour,
|
|
31
34
|
platform,
|
|
@@ -33,33 +36,61 @@ const nwbuild = async ({
|
|
|
33
36
|
outDir,
|
|
34
37
|
// flags
|
|
35
38
|
downloadUrl = "https://dl.nwjs.io",
|
|
36
|
-
|
|
39
|
+
manifestUrl = "https://nwjs.io/versions",
|
|
37
40
|
noCache = false,
|
|
38
41
|
zip = false,
|
|
39
42
|
run = false,
|
|
40
43
|
}) => {
|
|
41
|
-
|
|
44
|
+
let pkgPath = `${srcDir}/package.json`;
|
|
45
|
+
let pkgExist = true;
|
|
46
|
+
let pkgData = null;
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
await access(pkgPath, constants.F_OK);
|
|
50
|
+
} catch (e) {
|
|
51
|
+
pkgExist = false;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (pkgExist === true) {
|
|
55
|
+
pkgData = await readFile(pkgPath, "utf8");
|
|
56
|
+
pkgData = JSON.parse(pkgData);
|
|
57
|
+
if (pkgData.nwbuild !== undefined) {
|
|
58
|
+
srcDir = pkgData.nwbuild.srcDir ?? srcDir;
|
|
59
|
+
cacheDir = pkgData.nwbuild.cacheDir ?? cacheDir;
|
|
60
|
+
version = pkgData.nwbuild.version ?? version;
|
|
61
|
+
flavour = pkgData.nwbuild.flavour ?? flavour;
|
|
62
|
+
platform = pkgData.nwbuild.platform ?? platform;
|
|
63
|
+
arch = pkgData.nwbuild.arch ?? arch;
|
|
64
|
+
outDir = pkgData.nwbuild.outDir ?? outDir;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
42
67
|
|
|
43
68
|
let nwDir = `${cacheDir}/nwjs${
|
|
44
69
|
flavour === "sdk" ? "-sdk" : ""
|
|
45
70
|
}-v${version}-${platform}-${arch}`;
|
|
46
71
|
|
|
47
|
-
|
|
48
|
-
|
|
72
|
+
let fileExists = true;
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
await access(nwDir, constants.F_OK);
|
|
76
|
+
} catch (e) {
|
|
77
|
+
fileExists = false;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (noCache === true || fileExists === false) {
|
|
81
|
+
await rm(nwDir, { force: true, recursive: true });
|
|
49
82
|
await download(version, flavour, platform, arch, downloadUrl, cacheDir);
|
|
50
83
|
await decompress(platform, cacheDir);
|
|
51
84
|
await remove(platform, cacheDir);
|
|
52
85
|
}
|
|
53
86
|
|
|
54
|
-
|
|
87
|
+
let releaseInfo = await getReleaseInfo(version, cacheDir, manifestUrl);
|
|
55
88
|
|
|
56
89
|
if (run === true) {
|
|
57
90
|
await develop(srcDir, nwDir, platform);
|
|
58
91
|
} else {
|
|
59
|
-
await packager(srcDir, nwDir, outDir, platform, zip);
|
|
92
|
+
await packager(srcDir, nwDir, outDir, platform, zip, releaseInfo);
|
|
60
93
|
}
|
|
61
|
-
|
|
62
|
-
// macos config
|
|
63
94
|
};
|
|
64
95
|
|
|
65
|
-
export
|
|
96
|
+
export { nwbuild };
|
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nwdemo",
|
|
3
|
-
"main": "index.html"
|
|
3
|
+
"main": "index.html",
|
|
4
|
+
"product_string": "nwdemo",
|
|
5
|
+
"nwbuild": {
|
|
6
|
+
"srcDir": "./nwapp",
|
|
7
|
+
"version": "0.70.1",
|
|
8
|
+
"flavour": "sdk",
|
|
9
|
+
"platform": "linux",
|
|
10
|
+
"arch": "x64",
|
|
11
|
+
"outDir": "./build",
|
|
12
|
+
"run": false,
|
|
13
|
+
"linuxCfg": {
|
|
14
|
+
"Type": "Application",
|
|
15
|
+
"Name": "nwdemo"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
4
18
|
}
|
package/test/demo/bld.js
DELETED