nw-builder 4.0.1 → 4.0.3

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.
@@ -8,10 +8,8 @@ updates:
8
8
  - package-ecosystem: "npm" # See documentation for possible values
9
9
  directory: "/" # Location of package manifests
10
10
  schedule:
11
- interval: "weekly"
12
- day: "friday"
11
+ interval: "daily"
13
12
  - package-ecosystem: "github-actions" # See documentation for possible values
14
13
  directory: ".github/" # Location of package manifests
15
14
  schedule:
16
- interval: "weekly"
17
- day: "friday"
15
+ interval: "daily"
@@ -14,6 +14,7 @@ jobs:
14
14
  node-version: "18"
15
15
 
16
16
  - run: npm ci
17
+ - run: npm run cjs
17
18
  - uses: JS-DevTools/npm-publish@v1
18
19
  with:
19
20
  token: ${{ secrets.NPM_TOKEN }}
@@ -20,10 +20,9 @@ jobs:
20
20
  runs-on: ${{ matrix.os }}
21
21
  steps:
22
22
  - uses: actions/checkout@v3
23
- - uses: volta-cli/action@v1
24
- with:
25
- node-version: ${{ matrix.node-version }}
26
- npm-version: '8.5.0'
27
23
  - run: npm ci
28
24
  - run: npm run format
29
25
  - run: npm run lint
26
+ - run: npm run test:unit
27
+ - run: npm run cjs
28
+ - run: npm run test:e2e
package/README.md CHANGED
@@ -5,42 +5,328 @@
5
5
 
6
6
  Build [NW.js](https://github.com/nwjs/nw.js) applications for Mac, Windows and Linux.
7
7
 
8
- ## Installation
8
+ > Before using `nw-builder`, please go through how to [write an NW.js application](https://nwjs.readthedocs.io/en/latest/For%20Users/Getting%20Started/).
9
9
 
10
- Install via `npm` or your package manager of choice:
10
+ ## Install
11
11
 
12
- ```javascript
13
- npm install nw-builder
12
+ Install `nw-builder` via `npm` or your preferred Node package manager of choice.
13
+
14
+ ```shell
15
+ npm i -D nw-builder
14
16
  ```
15
17
 
16
18
  ## Usage
17
19
 
18
- At a glance module usage:
20
+ ### Run your first application
21
+
22
+ Module usage
19
23
 
20
24
  ```javascript
21
- import { nwbuild } from "nw-builder";
25
+ import nwbuild from "nw-builder";
22
26
 
23
27
  nwbuild({
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
- outDir: "./build",
30
- // flags with their default values
31
- cacheDir: "./cache", //directory to store nw binaries and shared libraries
32
- downloadUrl: "https://dl.nwjs.io",
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
28
+ // Globing does not matter since a process is spawned against the nwapp directory
29
+ srcDir: "./nwapp/**/*",
30
+ mode: "run",
31
+ version: "0.70.1",
32
+ flavor: "sdk",
33
+ });
34
+ ```
35
+
36
+ CLI usage
37
+
38
+ ```shell
39
+ nwbuild ./nwapp --mode=run --version=0.70.1 --flavor=sdk
40
+ ```
41
+
42
+ package.json usage
43
+
44
+ `./nwapp/package.json`
45
+
46
+ ```json
47
+ {
48
+ "name": "nwdemo",
49
+ "main": "./index.html",
50
+ "nwbuild": {
51
+ "srcDir": "./nwapp/**/*",
52
+ "mode": "run",
53
+ "version": "0.70.1",
54
+ "flavor": "sdk"
55
+ }
56
+ }
57
+ ```
58
+
59
+ ### Build your first application
60
+
61
+ Module usage
62
+
63
+ ```javascript
64
+ import nwbuild from "nw-builder";
65
+
66
+ nwbuild({
67
+ srcDir: "./nwapp/**/*",
68
+ mode: "build",
69
+ version: "0.70.1",
70
+ flavor: "normal",
71
+ platform: "linux",
72
+ arch: "x64",
73
+ outDir: "./out",
37
74
  });
38
75
  ```
39
76
 
40
- At a glance CLI usage:
77
+ CLI usage
78
+
79
+ ```shell
80
+ nwbuild ./nwapp --mode=build --version=0.70.1 --flavor=normal --platform=linux --arch=x64 --outDir=./out
81
+ ```
82
+
83
+ package.json usage
84
+
85
+ `./nwapp/package.json`
86
+
87
+ ```json
88
+ {
89
+ "name": "nwdemo",
90
+ "main": "./index.html",
91
+ "nwbuild": {
92
+ "srcDir": "./nwapp/**/*",
93
+ "mode": "build",
94
+ "version": "0.70.1",
95
+ "flavor": "normal",
96
+ "platform": "linux",
97
+ "arch": "x64",
98
+ "outDir": "./out"
99
+ }
100
+ }
101
+ ```
102
+
103
+ ## API Reference
104
+
105
+ ### Methods
106
+
107
+ `nwbuild(options) :Promise<undefined>`
108
+
109
+ | Name | Type | Default | Description |
110
+ | ----------- | ----------------------------------- | -------------------------- | ------------------------------------------------------------------------------ |
111
+ | srcDir | `string` | `./` | Directories which hold NW app code |
112
+ | mode | `run \| build` | `build` | Run or build application |
113
+ | version | `latest \| stable \| string \| lts` | `latest` | NW runtime version |
114
+ | flavor | `sdk \| normal` | `normal` | NW runtime build flavor. |
115
+ | platform | `linux \| osx \| win` | `<current platform>` | NW supported platforms |
116
+ | arch | `ia32 \| x64` | `<current architecture>` | NW supported architectures |
117
+ | outDir | `string` | `./out` | Directory to store build artifacts |
118
+ | cacheDir | `string` | `./cacheDir` | Directory to store NW binaries |
119
+ | downloadUrl | `string` | `https://dl.nwjs.io` | URI to download NW binaries from |
120
+ | manifestUrl | `string` | `https://nwjs.io/versions` | URI to download manifest from |
121
+ | cache | `boolean` | `true` | If `true` the existing cache is used. Otherwise it removes and redownloads it. |
122
+ | zip | `boolean` | `false` | If `true` the `outDir` directory is zipped |
123
+
124
+ ## Migration to v4
125
+
126
+ ### Update `nw-builder`
127
+
128
+ With npm:
129
+
130
+ ```shell
131
+ npm update nw-builder@^4.0.3
132
+ ```
133
+
134
+ With yarn:
135
+
136
+ ```shell
137
+ yarn upgrade nw-builder@^4.0.3
138
+ ```
139
+
140
+ With pnpm:
41
141
 
42
142
  ```shell
43
- nwbuild ./nwapp --version=0.70.1 --flavour=sdk --platform=linux --arch=x64 --outDir=./build
143
+ pnpm update nw-builder@^4.0.3
144
+ ```
145
+
146
+ > Note: `nw-builder` has been tested on Node 16 and 18 only.
147
+
148
+ ### Update options
149
+
150
+ Let's take an example of v3 code and migrate it to v4.
151
+
152
+ ```javascript
153
+ const NwBuilder = require("nw-builder");
154
+
155
+ const nw = new NwBuilder({
156
+ files: ["./nwapp/**/*", "./other/**/*.js"],
157
+ version: "latest",
158
+ flavor: "normal",
159
+ platforms: ["win32", "win64", "osx32", "osx64", "linux32", "linux64"],
160
+ cacheDir: "./cache",
161
+ buildDir: "./build",
162
+ buildType: "versioned",
163
+ forceDownload: true,
164
+ appName: "nwdemo",
165
+ appVersion: "0.1.0",
166
+ argv: "--nw-stderr-logging",
167
+ macCredits: "./nwapp/credits.html",
168
+ macIcns: "./nwapp/mac.icns",
169
+ macPlist: { ... },
170
+ winVersionString: { ... },
171
+ winIco: "./nwapp/win.ico",
172
+ zip: true,
173
+ macZip: false,
174
+ mergeZip: false,
175
+ });
176
+
177
+ nw.build();
178
+ ```
179
+
180
+ Update the import path
181
+
182
+ ```patch
183
+ -const NwBuilder = require("nw-builder");
184
+ +const nwbuild = require("nw-builder");
185
+ ```
186
+
187
+ Replace the `NwBuilder` initialization with a function
188
+
189
+ ```patch
190
+ -const nw = new NwBuilder({
191
+ +await nwbuild({
192
+ ```
193
+
194
+ The `files` property has been renamed to `srcDir`.S
195
+
196
+ ```patch
197
+ - files: ["./nwapp/**/*", "./other/**/*.js"],
198
+ + srcDir: "./nwapp/**/* ./other/**/*.js",
199
+ ```
200
+
201
+ Add the `mode` option and remove the now redundant `nw.build` function call.
202
+
203
+ ```patch
204
+ + mode: "build",
205
+
206
+ -nw.build();
207
+ ```
208
+
209
+ The `platforms` option has been removed and replaced with `platform` and `arch`. Notice that one `nwbuild` function call now creates one build only. Refer to the [documentation](./index.md) for valid `platform` and `arch` values.
210
+
211
+ ```patch
212
+ - platforms: ["win32", "win64", "osx32", "osx64", "linux32", "linux64"],
213
+ + platform: "linux",
214
+ + arch: "x64",
215
+ ```
216
+
217
+ > If platform is Linux then even if Windows or MacOS specific `app.*` properties are defined, only the Linux `app.*` properties will be parsed. Multiple platform `app.*` properties have been shown in this guide to cater to all platforms.
218
+
219
+ The `buildDir` option has been rename to `outDir`.
220
+
221
+ ```patch
222
+ - buildDir: "./build",
223
+ + outDir: "./build",
224
+ ```
225
+
226
+ The `buildType` option has been removed.
227
+
228
+ ```patch
229
+ - buildType: "versioned",
230
+ ```
231
+
232
+ The `forceDownload` option has been changed to `cache`.
233
+
234
+ ```patch
235
+ - forceDownload: true,
236
+ + cache: false,
237
+ ```
238
+
239
+ The `appName` option has been changed to `app.name`.
240
+
241
+ ```patch
242
+ - appName: "nwdemo",
243
+ + app: { name: "nwdemo" },
244
+ ```
245
+
246
+ The `appVersion` option has been removed. The `version` is automatically taken from `srcDir/package.json`.
247
+
248
+ ```patch
249
+ - appVersion: "0.1.0",
250
+ ```
251
+
252
+ The `macCredit` option has been removed.
253
+
254
+ ```patch
255
+ - macCredits: "./nwapp/credits.html",
256
+ ```
257
+
258
+ The `macIcns` option has been replaced with `icon`.
259
+
260
+ ```patch
261
+ - macIcns: "./nwapp/mac.icns",
262
+ + icon: "./nwapp/mac.icns",
263
+ ```
264
+
265
+ The `macPlist` option has been removed.
266
+
267
+ ```patch
268
+ - macPlist: { ... },
269
+ ```
270
+
271
+ The `winVersionString` option has been replaced with `app`.
272
+
273
+ ```patch
274
+ - winVersionString: {
275
+ - 'CompanyName': 'Some Company',
276
+ - 'FileDescription': 'Process Name',
277
+ - 'ProductName': 'Some Product',
278
+ - 'LegalCopyright': 'Copyright 2017',
279
+ - }
280
+ + app: {
281
+ + company: "Some Company",
282
+ + fileDescription: "Process Name",
283
+ + productName: "Some Product",
284
+ + legalCopyright: "Copyright 2017",
285
+ + }
286
+ ```
287
+
288
+ The `winIco` option has been replaced by `app.icon`.
289
+
290
+ ```patch
291
+ - winIco: "./nwapp/win.ico",
292
+ + app: { icon: "./nwapp/win.ico" },
293
+ ```
294
+
295
+ The `macZip` option has been removed.
296
+
297
+ ```patch
298
+ - macZip: false,
299
+ ```
300
+
301
+ The `mergeZip` option has been removed.
302
+
303
+ ```patch
304
+ - mergeZip: false,
305
+ ```
306
+
307
+ The final code should look like this.
308
+
309
+ ```javascript
310
+ const { nwbuild } = require("nw-builder");
311
+
312
+ await nwbuild({
313
+ srcDir: "./nwapp",
314
+ mode: "build",
315
+ version: "latest",
316
+ flavor: "normal",
317
+ platform: "linux",
318
+ arch: "x64",
319
+ outDir: "./build",
320
+ cache: false,
321
+ app: {
322
+ name: "Some Product",
323
+ icon: "./nwapp/icon.png",
324
+ company: "Some Company",
325
+ fileDescription: "Process Name",
326
+ productName: "Some Product",
327
+ legalCopyright: "Copyright 2017",
328
+ },
329
+ });
44
330
  ```
45
331
 
46
332
  ## Contributing
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nw-builder",
3
- "version": "4.0.1",
4
- "description": "Build NW.js desktop applications for Mac, Windows and Linux.",
3
+ "version": "4.0.3",
4
+ "description": "Build NW.js desktop applications for MacOS, Windows and Linux.",
5
5
  "keywords": [
6
6
  "NW.js",
7
7
  "node-webkit",
@@ -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": "./dist/nwbuild.cjs"
21
+ },
18
22
  "type": "module",
19
23
  "homepage": "https://github.com/nwutils/nw-builder",
20
24
  "repository": {
@@ -22,12 +26,20 @@
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
+ "test:cli": "cd ./test/e2e && nwbuild ./nwapp --mode=build --version=0.70.1 --flavour=normal --platform=win --arch=x64 --outDir=./build",
33
+ "test:unit": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
34
+ "test:e2e": "cd ./test/e2e && node bld.js",
35
+ "demo:nix": "cd ./test/e2e && node nix.js",
36
+ "demo:osx": "cd ./test/e2e && node osx.js",
37
+ "demo:win": "cd ./test/e2e && node win.js",
38
+ "cjs": "esbuild ./src/nwbuild.js --bundle --minify --legal-comments=inline --platform=node --outfile=./dist/nwbuild.cjs",
39
+ "checklist": "npm run cjs && npm run format && npm run lint && npm run test:unit && npm run test:e2e"
29
40
  },
30
41
  "devDependencies": {
42
+ "esbuild": "^0.16.12",
31
43
  "eslint": "^8.25.0",
32
44
  "eslint-config-tjw-jsdoc": "^1.0.3",
33
45
  "jest": "^29.2.0",
@@ -40,6 +52,7 @@
40
52
  "archiver": "^5.3.1",
41
53
  "cli-progress": "^3.11.2",
42
54
  "extract-zip": "^2.0.1",
55
+ "glob-promise": "^6.0.0",
43
56
  "plist": "^3.0.6",
44
57
  "progress": "^2.0.3",
45
58
  "rcedit": "^3.0.1",
@@ -73,7 +86,8 @@
73
86
  },
74
87
  "env": {
75
88
  "es6": true,
76
- "node": true
89
+ "node": true,
90
+ "jest": true
77
91
  },
78
92
  "extends": [
79
93
  "eslint:recommended",
@@ -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
  });
@@ -6,30 +6,48 @@ import { log } from "../log.js";
6
6
  * Generates a Desktop Entry file for Linux
7
7
  * https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s06.html
8
8
  *
9
- * @param {object} pkg srcDir's package.json as JSON
10
- * @param {string} outDir directory which stores build artifacts
9
+ * @param {object} app Multi platform configuration options
10
+ * @param {string} outDir Directory which stores build artifacts
11
11
  * @return {undefined}
12
12
  */
13
- export const setLinuxConfig = async (pkg, outDir) => {
13
+ export const setLinuxConfig = async (app, outDir) => {
14
14
  let desktopEntryFile = {
15
15
  Type: "Application",
16
- Name: pkg.name,
17
- Exec: pkg.name,
16
+ Version: "1.5",
17
+ Name: app.name,
18
+ GenericName: app.genericName,
19
+ NoDisplay: app.noDisplay,
20
+ Comment: app.comment,
21
+ Icon: app.icon,
22
+ Hidden: app.hidden,
23
+ OnlyShowIn: app.onlyShowIn,
24
+ NotShowIn: app.notShowIn,
25
+ DBusActivatable: app.dBusActivatable,
26
+ TryExec: app.tryExec,
27
+ Exec: app.name,
28
+ Path: app.path,
29
+ Terminal: app.terminal,
30
+ Actions: app.actions,
31
+ MimeType: app.mimeType,
32
+ Categories: app.categories,
33
+ Implements: app.implements,
34
+ Keywords: app.keywords,
35
+ StartupNotify: app.startupNotify,
36
+ StartupWMClass: app.startupWMClass,
37
+ PrefersNonDefaultGPU: app.prefersNonDefaultGPU,
38
+ SingleMainWindow: app.singleMainWindow,
18
39
  };
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
- }
40
+
41
+ await rename(`${outDir}/nw`, `${outDir}/${app.name}`);
42
+
27
43
  let fileContent = `[Desktop Entry]\n`;
28
44
  Object.keys(desktopEntryFile).forEach((key) => {
29
- fileContent += `${key}=${desktopEntryFile[key]}\n`;
30
- log.debug(`Add ${key}=${desktopEntryFile[key]} to Desktop Entry File`);
45
+ if (desktopEntryFile[key] !== undefined) {
46
+ fileContent += `${key}=${desktopEntryFile[key]}\n`;
47
+ log.debug(`Add ${key}=${desktopEntryFile[key]} to Desktop Entry File`);
48
+ }
31
49
  });
32
- let filePath = `${outDir}/${pkg.name}.desktop`;
50
+ let filePath = `${outDir}/${app.name}.desktop`;
33
51
  await writeFile(filePath, fileContent);
34
52
  log.debug("Desktop Entry file generated");
35
53
  };
package/src/bld/osxCfg.js CHANGED
@@ -1,88 +1,53 @@
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
- // 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);
6
+ import { log } from "../log.js";
7
+
8
+ /**
9
+ * OSX specific configuration steps
10
+ *
11
+ * @param {object} pkg The srcDir/package.json as a JSON
12
+ * @param {string} outDir The directory to hold build artifacts
13
+ * @return {Promise<undefined>}
14
+ */
15
+ const setOsxConfig = async (pkg, outDir) => {
16
+ try {
17
+ const outApp = path.resolve(outDir, `${pkg.name}.app`);
18
+ await fs.rename(path.resolve(outDir, "nwjs.app"), outApp);
19
+
20
+ // Rename CFBundleDisplayName in Contents/Info.plist
21
+ const contentsInfoPlistPath = path.resolve(outApp, "Contents/Info.plist");
22
+ const contentsInfoPlistJson = plist.parse(
23
+ await fs.readFile(contentsInfoPlistPath, "utf-8"),
24
+ );
25
+ contentsInfoPlistJson.CFBundleDisplayName = pkg.name;
26
+ const contentsInfoPlist = plist.build(contentsInfoPlistJson);
27
+ await fs.writeFile(contentsInfoPlistPath, contentsInfoPlist);
28
+
29
+ // Rename CFBundleDisplayName in Contents/Resources/en.lproj/InfoPlist.strings
30
+ const contentsInfoPlistStringsPath = path.resolve(
31
+ outApp,
32
+ "Contents/Resources/en.lproj/InfoPlist.strings",
33
+ );
34
+ const contentsInfoPlistStrings = await fs.readFile(
35
+ contentsInfoPlistStringsPath,
36
+ "utf-8",
37
+ );
38
+ const newPlistStrings = contentsInfoPlistStrings.replace(
39
+ /CFBundleGetInfoString = "nwjs /,
40
+ `CFBundleGetInfoString = "${pkg.name} `,
41
+ );
42
+ await fs.writeFile(contentsInfoPlistStringsPath, newPlistStrings);
43
+
44
+ // Add product_string property to package.json
45
+ // const packageJsonPath = path.resolve(outApp, "Contents/Resources/app.nw/package.json");
46
+ // pkg.product_string = pkg.name;
47
+ // await fs.writeFile(packageJsonPath, JSON.stringify(pkg, null, 4));
48
+ } catch (error) {
49
+ log.error(error);
50
+ }
86
51
  };
87
52
 
88
53
  export { setOsxConfig };