nw-builder 4.0.1 → 4.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nw-builder",
3
- "version": "4.0.1",
3
+ "version": "4.0.2",
4
4
  "description": "Build NW.js desktop applications for Mac, Windows and Linux.",
5
5
  "keywords": [
6
6
  "NW.js",
@@ -15,6 +15,10 @@
15
15
  },
16
16
  "license": "MIT",
17
17
  "main": "./src/nwbuild.js",
18
+ "exports": {
19
+ "import": "./src/nwbuild.js",
20
+ "require": "./nwbuild.cjs"
21
+ },
18
22
  "type": "module",
19
23
  "homepage": "https://github.com/nwutils/nw-builder",
20
24
  "repository": {
@@ -22,12 +26,15 @@
22
26
  "url": "https://github.com/nwutils/nw-builder.git"
23
27
  },
24
28
  "scripts": {
25
- "format": "prettier --write \"**/*.{js,md}\"",
29
+ "format": "prettier --write \"**/*.{js,cjs,md}\"",
26
30
  "lint": "eslint ./src",
27
31
  "docs": "jsdoc ./src/nwbuild.js -d docs",
28
- "demo": "cd ./test/demo && nwbuild ./nwapp --version=0.69.1 --flavour=sdk --platform=linux --arch=x64 --outDir=./build"
32
+ "demo": "cd ./test/demo && nwbuild ./nwapp --version=0.69.1 --flavour=sdk --platform=linux --arch=x64 --outDir=./build",
33
+ "demo:cjs": "cd ./test/demo && node bld.cjs",
34
+ "cjs": "esbuild ./src/nwbuild.js --bundle --minify --legal-comments=inline --platform=node --outfile=./nwbuild.cjs"
29
35
  },
30
36
  "devDependencies": {
37
+ "esbuild": "^0.15.15",
31
38
  "eslint": "^8.25.0",
32
39
  "eslint-config-tjw-jsdoc": "^1.0.3",
33
40
  "jest": "^29.2.0",
@@ -8,7 +8,6 @@ const compress = (outDir, type = "zip") => {
8
8
  const archive = archiver("zip");
9
9
 
10
10
  return new Promise((res, rej) => {
11
-
12
11
  output.on("close", () => {
13
12
  res(0);
14
13
  });
@@ -17,7 +17,7 @@ export const setLinuxConfig = async (pkg, outDir) => {
17
17
  Exec: pkg.name,
18
18
  };
19
19
  await rename(`${outDir}/nw`, `${outDir}/${pkg.name}`);
20
- if (typeof pkg.nwbuild.linuxCfg === "object") {
20
+ if (typeof pkg.nwbuild?.linuxCfg === "object") {
21
21
  Object.keys(pkg.nwbuild.linuxCfg).forEach((key) => {
22
22
  if (key !== "Type") {
23
23
  desktopEntryFile[key] = pkg.nwbuild.linuxCfg[key];
package/src/bld/osxCfg.js CHANGED
@@ -1,88 +1,57 @@
1
1
  import fs from "node:fs/promises";
2
+ import path from "node:path";
2
3
 
3
4
  import plist from "plist";
4
5
 
5
- const setOsxConfig = async (pkg, outDir, releaseInfo) => {
6
+ /**
7
+ * OSX specific configuration steps
8
+ *
9
+ * @param {object} pkg The srcDir/package.json as a JSON
10
+ * @param {string} outDir The directory to hold build artifacts
11
+ * @param {object} releaseInfo NW binary release metadata
12
+ */
13
+ const setOsxConfig = async (pkg, outDir) => {
14
+ // const setOsxConfig = async (pkg, outDir, releaseInfo) => {
15
+ const outApp = path.resolve(outDir, `${pkg.name}.app`);
16
+ await fs.rename(path.resolve(outDir, "nwjs.app"), outApp);
17
+
6
18
  // 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);
19
+ const contentsInfoPlistPath = path.resolve(outApp, "Contents/Info.plist");
20
+ const contentsInfoPlistJson = plist.parse(await fs.readFile(contentsInfoPlistPath, "utf-8"));
21
+ contentsInfoPlistJson.CFBundleDisplayName = pkg.name;
22
+ const contentsInfoPlist = plist.build(contentsInfoPlistJson);
23
+ await fs.writeFile(contentsInfoPlistPath, contentsInfoPlist);
14
24
 
15
25
  // 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);
26
+ const contentsInfoPlistStringsPath = path.resolve(outApp, "Contents/Resources/en.lproj/InfoPlist.strings");
27
+ const contentsInfoPlistStrings = await fs.readFile(contentsInfoPlistStringsPath, "utf-8");
28
+ const newPlistStrings = contentsInfoPlistStrings.replace(/CFBundleGetInfoString = "nwjs /, `CFBundleGetInfoString = "${pkg.name} `);
29
+ await fs.writeFile(contentsInfoPlistStringsPath, newPlistStrings);
30
+
31
+ // Add product_string property to package.json
32
+ // const packageJsonPath = path.resolve(outApp, "Contents/Resources/app.nw/package.json");
33
+ // pkg.product_string = pkg.name;
34
+ // await fs.writeFile(packageJsonPath, JSON.stringify(pkg, null, 4));
35
+
36
+ // Update Helper apps
37
+ // TODO: determine why this prevents app from launching
38
+ // for (const helperName of [" (Alerts)", " (GPU)", " (Plugin)", " (Renderer)", ""]) {
39
+ // const helperPath = (name = "nwjs") => path.resolve(
40
+ // outApp,
41
+ // `Contents/Frameworks/nwjs Framework.framework/Versions/${releaseInfo.components.chromium}/Helpers/`,
42
+ // `${name} Helper${helperName}.app`
43
+ // );
44
+
45
+ // // Rename Helper apps in Contents/Framework.framework/Versions/n.n.n.n/Helpers
46
+ // await fs.rename(helperPath(), helperPath(pkg.name));
47
+
48
+ // // Update Helper app Info.plist files in Contents/Framework.framework/Versions/n.n.n.n/Helpers
49
+ // const helperPlistPath = path.resolve(helperPath(pkg.name), "Contents/Info.plist");
50
+ // const helperPlistJson = plist.parse(await fs.readFile(helperPlistPath, "utf-8"));
51
+ // helperPlistJson.CFBundleDisplayName = pkg.name;
52
+ // const helperPlist = plist.build(helperPlistJson);
53
+ // await fs.writeFile(helperPlistPath, helperPlist);
54
+ // }
86
55
  };
87
56
 
88
57
  export { setOsxConfig };
@@ -27,7 +27,7 @@ const packager = async (srcDir, nwDir, outDir, platform, zip, releaseInfo) => {
27
27
  await cp(
28
28
  srcDir,
29
29
  `${outDir}/${
30
- platform !== "osx" ? "package.nw" : "nwjs.app/Contents/Resources/nw.app"
30
+ platform !== "osx" ? "package.nw" : "nwjs.app/Contents/Resources/app.nw"
31
31
  }`,
32
32
  {
33
33
  recursive: true,
@@ -37,7 +37,7 @@ const packager = async (srcDir, nwDir, outDir, platform, zip, releaseInfo) => {
37
37
  log.debug("Get NW's package.json as a buffer");
38
38
  let buffer = await readFile(
39
39
  `${outDir}/${
40
- platform !== "osx" ? "package.nw" : "nwjs.app/Contents/Resources/nw.app"
40
+ platform !== "osx" ? "package.nw" : "nwjs.app/Contents/Resources/app.nw"
41
41
  }/package.json`,
42
42
  );
43
43
  log.debug("Convert package.json buffer into JSON");
package/src/bld/winCfg.js CHANGED
@@ -1,7 +1,18 @@
1
+ import { rename } from "node:fs/promises";
2
+
1
3
  import rcedit from "rcedit";
2
4
 
5
+ /**
6
+ * Windows specific configuration steps
7
+ *
8
+ * @param {object} pkg The srcDir/package.json as a JSON
9
+ * @param {string} outDir The directory to hold build artifacts
10
+ */
3
11
  const setWinConfig = async (pkg, outDir) => {
4
- return rcedit(`${outDir}/nw.exe`, {
12
+ await rename(`${outDir}/nw.exe`, `${outDir}/${pkg.name}.exe`);
13
+
14
+ // https://learn.microsoft.com/en-gb/windows/win32/menurc/versioninfo-resource?redirectedfrom=MSDN#string-name
15
+ await rcedit(`${outDir}/${pkg.name}.exe`, {
5
16
  "file-version": pkg.version,
6
17
  "product-version": pkg.version,
7
18
  "icon": pkg.icon,
@@ -9,7 +20,7 @@ const setWinConfig = async (pkg, outDir) => {
9
20
  FileDescription: pkg.description,
10
21
  LegalCopyright: pkg.copyright,
11
22
  ProductName: pkg.name,
12
- OriginalFilename: "",
23
+ OriginalFilename: pkg.name,
13
24
  },
14
25
  });
15
26
  };
@@ -0,0 +1,30 @@
1
+ const { nwbuild } = require("nw-builder");
2
+
3
+ const bld = async () => {
4
+ await nwbuild({
5
+ srcDir: "./nwapp",
6
+ version: "0.70.1",
7
+ flavour: "normal",
8
+ platform: "linux",
9
+ arch: "x64",
10
+ outDir: "./build/nix",
11
+ });
12
+ await nwbuild({
13
+ srcDir: "./nwapp",
14
+ version: "0.70.1",
15
+ flavour: "normal",
16
+ platform: "osx",
17
+ arch: "x64",
18
+ outDir: "./build/osx",
19
+ });
20
+ await nwbuild({
21
+ srcDir: "./nwapp",
22
+ version: "0.70.1",
23
+ flavour: "normal",
24
+ platform: "win",
25
+ arch: "x64",
26
+ outDir: "./build/win",
27
+ });
28
+ };
29
+
30
+ bld();
@@ -1,18 +1,4 @@
1
1
  {
2
2
  "name": "nwdemo",
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
- }
3
+ "main": "index.html"
18
4
  }