From d4f0bc16b86b0f1fe5cad7a4214e07f86148f713 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sun, 1 Oct 2023 17:15:07 -0400 Subject: [PATCH 01/35] test: `npm run demo` for demo app --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index fdbf525d3..8ba7f8968 100644 --- a/package.json +++ b/package.json @@ -48,8 +48,7 @@ "doc:bld": "node cfg/jsdoc.config.cjs && vitepress build doc", "test:unit": "node --test test/unit/index.js", "test:e2e": "node --test test/e2e/index.js", - "test:mod": "npm link nw-builder && cd test/fixture && node demo.js", - "test:cli": "npm link nw-builder && cd test/fixture && nwbuild --platform win --arch x64 --outDir out --no-glob app" + "demo": "npm link nw-builder && cd test/fixture && node demo.js" }, "devDependencies": { "concurrently": "^8.2.0", From b900bb902e9869ce62a664e913d0a617bcafcdca Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sun, 1 Oct 2023 17:15:49 -0400 Subject: [PATCH 02/35] test: use MacOS for demo --- test/fixture/demo.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/fixture/demo.js b/test/fixture/demo.js index b2fa72b99..3a5337dae 100644 --- a/test/fixture/demo.js +++ b/test/fixture/demo.js @@ -3,6 +3,7 @@ import nwbuild from "nw-builder"; await nwbuild({ mode: "build", version: "0.80.0", + platform: "osx", srcDir: "app", outDir: "out", glob: false, From d68b582cae17886abb9a21113ad654f274f09545 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sun, 1 Oct 2023 17:39:49 -0400 Subject: [PATCH 03/35] refactor(build): osx plist info --- src/build.js | 93 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 32 deletions(-) diff --git a/src/build.js b/src/build.js index e7a2c7c60..a60c0f71f 100644 --- a/src/build.js +++ b/src/build.js @@ -246,33 +246,60 @@ export async function build(files, nwDir, outDir, platform, zip, app) { } try { - const outApp = resolve(outDir, `${app.name}.app`); - await rename(resolve(outDir, "nwjs.app"), outApp); + let plistInfo = { + app: { + json: {}, + path: resolve(outDir, `${app.name}.app`, "Contents", "Info.plist"), + }, + icon: { + path: resolve( + outDir, + `${app.name}.app`, + "Contents", + "Resources", + "app.icns", + ), + }, + strings: { + array: [], + path: resolve( + outDir, + `${app.name}.app`, + "Contents", + "Resources", + "en.lproj", + "InfoPlist.strings", + ), + }, + }; + + // Rename MacOS app + await rename( + resolve(outDir, "nwjs.app"), + resolve(outDir, `${app.name}.app`), + ); + + // Replace default with custom icon if (app.icon !== undefined) { - await copyFile( - resolve(app.icon), - resolve(outApp, "Contents", "Resources", "app.icns"), - ); + await copyFile(resolve(app.icon), plistInfo.icon.path); } - const infoPlistPath = resolve(outApp, "Contents", "Info.plist"); - const infoPlistJson = plist.parse(await readFile(infoPlistPath, "utf-8")); - - const infoPlistStringsPath = resolve( - outApp, - "Contents", - "Resources", - "en.lproj", - "InfoPlist.strings", - ); - const infoPlistStringsData = await readFile( - infoPlistStringsPath, - "utf-8", + plistInfo.app.json = plist.parse( + await readFile(plistInfo.app.path, "utf-8"), ); - let infoPlistStringsDataArray = infoPlistStringsData.split("\n"); + plistInfo.strings.array = await readFile( + resolve( + outApp, + "Contents", + "Resources", + "en.lproj", + "InfoPlist.strings", + ), + "utf-8", + ).split("\n"); - infoPlistStringsDataArray.forEach((line, idx, arr) => { + plistInfo.strings.array.forEach((line, idx, arr) => { if (line.includes("NSHumanReadableCopyright")) { arr[ idx @@ -280,24 +307,26 @@ export async function build(files, nwDir, outDir, platform, zip, app) { } }); - infoPlistJson.LSApplicationCategoryType = app.LSApplicationCategoryType; - infoPlistJson.CFBundleIdentifier = app.CFBundleIdentifier; - infoPlistJson.CFBundleName = app.CFBundleName; - infoPlistJson.CFBundleDisplayName = app.CFBundleDisplayName; - infoPlistJson.CFBundleSpokenName = app.CFBundleSpokenName; - infoPlistJson.CFBundleVersion = app.CFBundleVersion; - infoPlistJson.CFBundleShortVersionString = app.CFBundleShortVersionString; + plistInfo.app.json.LSApplicationCategoryType = + app.LSApplicationCategoryType; + plistInfo.app.json.CFBundleIdentifier = app.CFBundleIdentifier; + plistInfo.app.json.CFBundleName = app.CFBundleName; + plistInfo.app.json.CFBundleDisplayName = app.CFBundleDisplayName; + plistInfo.app.json.CFBundleSpokenName = app.CFBundleSpokenName; + plistInfo.app.json.CFBundleVersion = app.CFBundleVersion; + plistInfo.app.json.CFBundleShortVersionString = + app.CFBundleShortVersionString; - Object.keys(infoPlistJson).forEach((option) => { + Object.keys(plistInfo.app.json).forEach((option) => { if (infoPlistJson[option] === undefined) { delete infoPlistJson[option]; } }); - await writeFile(infoPlistPath, plist.build(infoPlistJson)); + await writeFile(plistInfo.app.path, plist.build(plistInfo.app.json)); await writeFile( - infoPlistStringsPath, - infoPlistStringsDataArray.toString().replace(/,/g, "\n"), + plistInfo.strings.path, + plistInfo.strings.array.toString().replace(/,/g, "\n"), ); } catch (error) { log.error(error); From 186e3c477f9ee6400b5ee5d86b986b936c7271f4 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sun, 1 Oct 2023 18:05:23 -0400 Subject: [PATCH 04/35] feat(build): rename MacOS Helper apps --- src/build.js | 205 ++++++++++++++++++++++++++++++++++ test/fixture/app/package.json | 3 +- 2 files changed, 207 insertions(+), 1 deletion(-) diff --git a/src/build.js b/src/build.js index a60c0f71f..2ee9360fe 100644 --- a/src/build.js +++ b/src/build.js @@ -271,6 +271,73 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "InfoPlist.strings", ), }, + helper: { + alerts: { + json: {}, + path: resolve( + outDir, + `${app.name}.app`, + "Frameworks", + "nwjs Framework.framework", + "Helpers", + `${app.name} Helper (Alerts).app`, + "Contents", + "Info.plist", + ), + }, + gpu: { + json: {}, + path: resolve( + outDir, + `${app.name}.app`, + "Frameworks", + "nwjs Framework.framework", + "Helpers", + `${app.name} Helper (GPU).app`, + "Contents", + "Info.plist", + ), + }, + plugin: { + json: {}, + path: resolve( + outDir, + `${app.name}.app`, + "Frameworks", + "nwjs Framework.framework", + "Helpers", + `${app.name} Helper (Plugin).app`, + "Contents", + "Info.plist", + ), + }, + renderer: { + json: {}, + path: resolve( + outDir, + `${app.name}.app`, + "Frameworks", + "nwjs Framework.framework", + "Helpers", + `${app.name} Helper (Renderer).app`, + "Contents", + "Info.plist", + ), + }, + main: { + json: {}, + path: resolve( + outDir, + `${app.name}.app`, + "Frameworks", + "nwjs Framework.framework", + "Helpers", + `${app.name} Helper.app`, + "Contents", + "Info.plist", + ), + }, + }, }; // Rename MacOS app @@ -279,6 +346,118 @@ export async function build(files, nwDir, outDir, platform, zip, app) { resolve(outDir, `${app.name}.app`), ); + // Rename Helper apps + await rename( + resolve( + outDir, + `${app.name}.app`, + "Frameworks", + "nwjs Framework.framework", + "Helpers", + `nwjs Helper.app`, + "Contents", + "Info.plist", + ), + resolve( + outDir, + `${app.name}.app`, + "Frameworks", + "nwjs Framework.framework", + "Helpers", + `${app.name} Helper.app`, + "Contents", + "Info.plist", + ), + ); + await rename( + resolve( + outDir, + `${app.name}.app`, + "Frameworks", + "nwjs Framework.framework", + "Helpers", + `nwjs Helper (Alerts).app`, + "Contents", + "Info.plist", + ), + resolve( + outDir, + `${app.name}.app`, + "Frameworks", + "nwjs Framework.framework", + "Helpers", + `${app.name} Helper (Alerts).app`, + "Contents", + "Info.plist", + ), + ); + await rename( + resolve( + outDir, + `${app.name}.app`, + "Frameworks", + "nwjs Framework.framework", + "Helpers", + `nwjs Helper (GPU).app`, + "Contents", + "Info.plist", + ), + resolve( + outDir, + `${app.name}.app`, + "Frameworks", + "nwjs Framework.framework", + "Helpers", + `${app.name} Helper (GPU).app`, + "Contents", + "Info.plist", + ), + ); + await rename( + resolve( + outDir, + `${app.name}.app`, + "Frameworks", + "nwjs Framework.framework", + "Helpers", + `nwjs Helper (Plugin).app`, + "Contents", + "Info.plist", + ), + resolve( + outDir, + `${app.name}.app`, + "Frameworks", + "nwjs Framework.framework", + "Helpers", + `${app.name} Helper (Plugin).app`, + "Contents", + "Info.plist", + ), + ); + await rename( + resolve( + outDir, + `${app.name}.app`, + "Frameworks", + "nwjs Framework.framework", + "Helpers", + `nwjs Helper (Renderer).app`, + "Contents", + "Info.plist", + ), + resolve( + outDir, + `${app.name}.app`, + "Frameworks", + "nwjs Framework.framework", + "Helpers", + `${app.name} Helper (Renderer).app`, + "Contents", + "Info.plist", + ), + ); + // Replace default with custom icon if (app.icon !== undefined) { await copyFile(resolve(app.icon), plistInfo.icon.path); @@ -323,11 +502,37 @@ export async function build(files, nwDir, outDir, platform, zip, app) { } }); + plistInfo.helper.alerts.json.CFBundleDisplayName = app.name; + plistInfo.helper.gpu.json.CFBundleDisplayName = app.name; + plistInfo.helper.plugin.json.CFBundleDisplayName = app.name; + plistInfo.helper.renderer.json.CFBundleDisplayName = app.name; + plistInfo.helper.main.json.CFBundleDisplayName = app.name; + await writeFile(plistInfo.app.path, plist.build(plistInfo.app.json)); await writeFile( plistInfo.strings.path, plistInfo.strings.array.toString().replace(/,/g, "\n"), ); + await writeFile( + plistInfo.helper.alerts.path, + plist.build(plistInfo.helper.alerts.json), + ); + await writeFile( + plistInfo.helper.gpu.path, + plist.build(plistInfo.helper.gpu.json), + ); + await writeFile( + plistInfo.helper.plugin.path, + plist.build(plistInfo.helper.plugin.json), + ); + await writeFile( + plistInfo.helper.renderer.path, + plist.build(plistInfo.helper.renderer.json), + ); + await writeFile( + plistInfo.helper.main.path, + plist.build(plistInfo.helper.main.json), + ); } catch (error) { log.error(error); } diff --git a/test/fixture/app/package.json b/test/fixture/app/package.json index 955b4056e..9e018ac28 100644 --- a/test/fixture/app/package.json +++ b/test/fixture/app/package.json @@ -1,5 +1,6 @@ { "name": "nwapp", "main": "index.html", - "version": "0.0.0" + "version": "0.0.0", + "product_string": "nwapp" } From 063137567e1846982a2754706842ada21adbc763 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sun, 1 Oct 2023 18:23:02 -0400 Subject: [PATCH 05/35] chore: wip --- src/build.js | 23 ++++++++--------------- test/fixture/demo.js | 1 + 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/build.js b/src/build.js index 2ee9360fe..f86f679f8 100644 --- a/src/build.js +++ b/src/build.js @@ -340,7 +340,6 @@ export async function build(files, nwDir, outDir, platform, zip, app) { }, }; - // Rename MacOS app await rename( resolve(outDir, "nwjs.app"), resolve(outDir, `${app.name}.app`), @@ -468,13 +467,7 @@ export async function build(files, nwDir, outDir, platform, zip, app) { ); plistInfo.strings.array = await readFile( - resolve( - outApp, - "Contents", - "Resources", - "en.lproj", - "InfoPlist.strings", - ), + plistInfo.strings.path, "utf-8", ).split("\n"); @@ -497,16 +490,16 @@ export async function build(files, nwDir, outDir, platform, zip, app) { app.CFBundleShortVersionString; Object.keys(plistInfo.app.json).forEach((option) => { - if (infoPlistJson[option] === undefined) { - delete infoPlistJson[option]; + if (plistInfo.app.json[option] === undefined) { + delete plistInfo.app.json[option]; } }); - plistInfo.helper.alerts.json.CFBundleDisplayName = app.name; - plistInfo.helper.gpu.json.CFBundleDisplayName = app.name; - plistInfo.helper.plugin.json.CFBundleDisplayName = app.name; - plistInfo.helper.renderer.json.CFBundleDisplayName = app.name; - plistInfo.helper.main.json.CFBundleDisplayName = app.name; + plistInfo.helper.alerts.json.CFBundleDisplayName = `${app.name} Helper (Alerts)`; + plistInfo.helper.gpu.json.CFBundleDisplayName = `${app.name} Helper (GPU)`; + plistInfo.helper.plugin.json.CFBundleDisplayName = `${app.name} Helper (Plugin)`; + plistInfo.helper.renderer.json.CFBundleDisplayName = `${app.name} Helper (Renderer)`; + plistInfo.helper.main.json.CFBundleDisplayName = `${app.name} Helper`; await writeFile(plistInfo.app.path, plist.build(plistInfo.app.json)); await writeFile( diff --git a/test/fixture/demo.js b/test/fixture/demo.js index 3a5337dae..6acf75553 100644 --- a/test/fixture/demo.js +++ b/test/fixture/demo.js @@ -7,4 +7,5 @@ await nwbuild({ srcDir: "app", outDir: "out", glob: false, + logLevel: "debug", }); From d82213c66c4ff16bb1d834cb4ed9b54169039d58 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sun, 1 Oct 2023 18:33:54 -0400 Subject: [PATCH 06/35] fix: renaming helpers --- src/build.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/build.js b/src/build.js index f86f679f8..0d1a469a7 100644 --- a/src/build.js +++ b/src/build.js @@ -1,5 +1,5 @@ import { resolve } from "node:path"; -import { platform as PLATFORM } from "node:process"; +import { platform as PLATFORM, exit } from "node:process"; import { cp, copyFile, @@ -277,6 +277,7 @@ export async function build(files, nwDir, outDir, platform, zip, app) { path: resolve( outDir, `${app.name}.app`, + "Contents", "Frameworks", "nwjs Framework.framework", "Helpers", @@ -290,6 +291,7 @@ export async function build(files, nwDir, outDir, platform, zip, app) { path: resolve( outDir, `${app.name}.app`, + "Contents", "Frameworks", "nwjs Framework.framework", "Helpers", @@ -303,6 +305,7 @@ export async function build(files, nwDir, outDir, platform, zip, app) { path: resolve( outDir, `${app.name}.app`, + "Contents", "Frameworks", "nwjs Framework.framework", "Helpers", @@ -316,6 +319,7 @@ export async function build(files, nwDir, outDir, platform, zip, app) { path: resolve( outDir, `${app.name}.app`, + "Contents", "Frameworks", "nwjs Framework.framework", "Helpers", @@ -329,6 +333,7 @@ export async function build(files, nwDir, outDir, platform, zip, app) { path: resolve( outDir, `${app.name}.app`, + "Contents", "Frameworks", "nwjs Framework.framework", "Helpers", @@ -346,32 +351,31 @@ export async function build(files, nwDir, outDir, platform, zip, app) { ); // Rename Helper apps - await rename( + const e = await rename( resolve( outDir, `${app.name}.app`, + "Contents", "Frameworks", "nwjs Framework.framework", "Helpers", `nwjs Helper.app`, - "Contents", - "Info.plist", ), resolve( outDir, `${app.name}.app`, + "Contents", "Frameworks", "nwjs Framework.framework", "Helpers", `${app.name} Helper.app`, - "Contents", - "Info.plist", ), ); await rename( resolve( outDir, `${app.name}.app`, + "Contents", "Frameworks", "nwjs Framework.framework", "Helpers", @@ -382,6 +386,7 @@ export async function build(files, nwDir, outDir, platform, zip, app) { resolve( outDir, `${app.name}.app`, + "Contents", "Frameworks", "nwjs Framework.framework", "Helpers", @@ -394,6 +399,7 @@ export async function build(files, nwDir, outDir, platform, zip, app) { resolve( outDir, `${app.name}.app`, + "Contents", "Frameworks", "nwjs Framework.framework", "Helpers", @@ -404,6 +410,7 @@ export async function build(files, nwDir, outDir, platform, zip, app) { resolve( outDir, `${app.name}.app`, + "Contents", "Frameworks", "nwjs Framework.framework", "Helpers", @@ -416,6 +423,7 @@ export async function build(files, nwDir, outDir, platform, zip, app) { resolve( outDir, `${app.name}.app`, + "Contents", "Frameworks", "nwjs Framework.framework", "Helpers", @@ -426,6 +434,7 @@ export async function build(files, nwDir, outDir, platform, zip, app) { resolve( outDir, `${app.name}.app`, + "Contents", "Frameworks", "nwjs Framework.framework", "Helpers", @@ -438,6 +447,7 @@ export async function build(files, nwDir, outDir, platform, zip, app) { resolve( outDir, `${app.name}.app`, + "Contents", "Frameworks", "nwjs Framework.framework", "Helpers", @@ -448,6 +458,7 @@ export async function build(files, nwDir, outDir, platform, zip, app) { resolve( outDir, `${app.name}.app`, + "Contents", "Frameworks", "nwjs Framework.framework", "Helpers", From b85e334f14714d4cbfb1f658bce9fb9c3661db3c Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sun, 1 Oct 2023 19:08:29 -0400 Subject: [PATCH 07/35] test: import from file instead of package --- package.json | 2 +- rename.js | 27 +++++++++++++++++++++++++++ src/build.js | 42 +++++++++++++++++++++--------------------- test/fixture/demo.js | 3 +-- 4 files changed, 50 insertions(+), 24 deletions(-) create mode 100644 rename.js diff --git a/package.json b/package.json index 8ba7f8968..9a07b3c8d 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "doc:bld": "node cfg/jsdoc.config.cjs && vitepress build doc", "test:unit": "node --test test/unit/index.js", "test:e2e": "node --test test/e2e/index.js", - "demo": "npm link nw-builder && cd test/fixture && node demo.js" + "demo": "cd test/fixture && node demo.js" }, "devDependencies": { "concurrently": "^8.2.0", diff --git a/rename.js b/rename.js new file mode 100644 index 000000000..b2922c10b --- /dev/null +++ b/rename.js @@ -0,0 +1,27 @@ +import { rename } from "node:fs/promises"; +import { resolve } from "node:path"; + +await rename( + resolve( + "test", + "fixture", + "out", + "nwapp.app", + "Contents", + "Frameworks", + "nwjs Framework.framework", + "Helpers", + `nwjs Helper (Alerts).app`, + ), + resolve( + "test", + "fixture", + "out", + "nwapp.app", + "Contents", + "Frameworks", + "nwjs Framework.framework", + "Helpers", + `nwapp Helper (Alerts).app`, + ), +); diff --git a/src/build.js b/src/build.js index 0d1a469a7..9a6a37889 100644 --- a/src/build.js +++ b/src/build.js @@ -351,7 +351,7 @@ export async function build(files, nwDir, outDir, platform, zip, app) { ); // Rename Helper apps - const e = await rename( + await rename( resolve( outDir, `${app.name}.app`, @@ -359,7 +359,7 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "Frameworks", "nwjs Framework.framework", "Helpers", - `nwjs Helper.app`, + "nwjs Helper.app", ), resolve( outDir, @@ -371,6 +371,7 @@ export async function build(files, nwDir, outDir, platform, zip, app) { `${app.name} Helper.app`, ), ); + await rename( resolve( outDir, @@ -380,8 +381,6 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "nwjs Framework.framework", "Helpers", `nwjs Helper (Alerts).app`, - "Contents", - "Info.plist", ), resolve( outDir, @@ -391,8 +390,6 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "nwjs Framework.framework", "Helpers", `${app.name} Helper (Alerts).app`, - "Contents", - "Info.plist", ), ); await rename( @@ -404,8 +401,6 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "nwjs Framework.framework", "Helpers", `nwjs Helper (GPU).app`, - "Contents", - "Info.plist", ), resolve( outDir, @@ -415,8 +410,6 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "nwjs Framework.framework", "Helpers", `${app.name} Helper (GPU).app`, - "Contents", - "Info.plist", ), ); await rename( @@ -428,8 +421,6 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "nwjs Framework.framework", "Helpers", `nwjs Helper (Plugin).app`, - "Contents", - "Info.plist", ), resolve( outDir, @@ -439,8 +430,6 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "nwjs Framework.framework", "Helpers", `${app.name} Helper (Plugin).app`, - "Contents", - "Info.plist", ), ); await rename( @@ -452,8 +441,6 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "nwjs Framework.framework", "Helpers", `nwjs Helper (Renderer).app`, - "Contents", - "Info.plist", ), resolve( outDir, @@ -463,8 +450,6 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "nwjs Framework.framework", "Helpers", `${app.name} Helper (Renderer).app`, - "Contents", - "Info.plist", ), ); @@ -477,11 +462,26 @@ export async function build(files, nwDir, outDir, platform, zip, app) { await readFile(plistInfo.app.path, "utf-8"), ); - plistInfo.strings.array = await readFile( - plistInfo.strings.path, - "utf-8", + plistInfo.strings.array = ( + await readFile(plistInfo.strings.path, "utf-8") ).split("\n"); + plistInfo.helper.alerts.json = plist.parse( + await readFile(plistInfo.helper.alerts.path, "utf-8"), + ); + plistInfo.helper.gpu.json = plist.parse( + await readFile(plistInfo.helper.gpu.path, "utf-8"), + ); + plistInfo.helper.plugin.json = plist.parse( + await readFile(plistInfo.helper.plugin.path, "utf-8"), + ); + plistInfo.helper.renderer.json = plist.parse( + await readFile(plistInfo.helper.renderer.path, "utf-8"), + ); + plistInfo.helper.main.json = plist.parse( + await readFile(plistInfo.helper.main.path, "utf-8"), + ); + plistInfo.strings.array.forEach((line, idx, arr) => { if (line.includes("NSHumanReadableCopyright")) { arr[ diff --git a/test/fixture/demo.js b/test/fixture/demo.js index 6acf75553..db00202b8 100644 --- a/test/fixture/demo.js +++ b/test/fixture/demo.js @@ -1,4 +1,4 @@ -import nwbuild from "nw-builder"; +import nwbuild from "../../src/index.js"; await nwbuild({ mode: "build", @@ -7,5 +7,4 @@ await nwbuild({ srcDir: "app", outDir: "out", glob: false, - logLevel: "debug", }); From 2448ae2e6b350e1ebc4d775b52e7eb5c4850d8b8 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sun, 1 Oct 2023 19:22:17 -0400 Subject: [PATCH 08/35] feat(build): update Helper Info.plist values --- rename.js | 27 --------------------------- src/build.js | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 27 deletions(-) delete mode 100644 rename.js diff --git a/rename.js b/rename.js deleted file mode 100644 index b2922c10b..000000000 --- a/rename.js +++ /dev/null @@ -1,27 +0,0 @@ -import { rename } from "node:fs/promises"; -import { resolve } from "node:path"; - -await rename( - resolve( - "test", - "fixture", - "out", - "nwapp.app", - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Helpers", - `nwjs Helper (Alerts).app`, - ), - resolve( - "test", - "fixture", - "out", - "nwapp.app", - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Helpers", - `nwapp Helper (Alerts).app`, - ), -); diff --git a/src/build.js b/src/build.js index 9a6a37889..14ca75256 100644 --- a/src/build.js +++ b/src/build.js @@ -507,10 +507,34 @@ export async function build(files, nwDir, outDir, platform, zip, app) { }); plistInfo.helper.alerts.json.CFBundleDisplayName = `${app.name} Helper (Alerts)`; + plistInfo.helper.alerts.json.CFBundleExecutable = `${app.name} Helper (Alerts)`; + plistInfo.helper.alerts.json.CFBundleIdentifier = `${app.CFBundleIdentifier}.helper.alerts`; + plistInfo.helper.alerts.json.CFBundleName = `${app.name} Helper (Alerts)`; + plistInfo.helper.alerts.json.CFBundleShortVersionString = app.CFBundleShortVersionString; + plistInfo.helper.gpu.json.CFBundleDisplayName = `${app.name} Helper (GPU)`; + plistInfo.helper.gpu.json.CFBundleExecutable = `${app.name} Helper (GPU)`; + plistInfo.helper.gpu.json.CFBundleIdentifier = `${app.CFBundleIdentifier}.helper.gpu`; + plistInfo.helper.gpu.json.CFBundleName = `${app.name} Helper (GPU)`; + plistInfo.helper.gpu.json.CFBundleShortVersionString = app.CFBundleShortVersionString; + plistInfo.helper.plugin.json.CFBundleDisplayName = `${app.name} Helper (Plugin)`; + plistInfo.helper.plugin.json.CFBundleExecutable = `${app.name} Helper (Plugin)`; + plistInfo.helper.plugin.json.CFBundleIdentifier = `${app.CFBundleIdentifier}.helper.plugin`; + plistInfo.helper.plugin.json.CFBundleName = `${app.name} Helper (Plugin)`; + plistInfo.helper.plugin.json.CFBundleShortVersionString = app.CFBundleShortVersionString; + plistInfo.helper.renderer.json.CFBundleDisplayName = `${app.name} Helper (Renderer)`; + plistInfo.helper.renderer.json.CFBundleExecutable = `${app.name} Helper (Renderer)`; + plistInfo.helper.renderer.json.CFBundleIdentifier = `${app.CFBundleIdentifier}.helper.renderer`; + plistInfo.helper.renderer.json.CFBundleName = `${app.name} Helper (Renderer)`; + plistInfo.helper.renderer.json.CFBundleShortVersionString = app.CFBundleShortVersionString; + plistInfo.helper.main.json.CFBundleDisplayName = `${app.name} Helper`; + plistInfo.helper.main.json.CFBundleExecutable = `${app.name} Helper`; + plistInfo.helper.main.json.CFBundleIdentifier = `${app.CFBundleIdentifier}.helper`; + plistInfo.helper.main.json.CFBundleName = `${app.name} Helper`; + plistInfo.helper.main.json.CFBundleShortVersionString = app.CFBundleShortVersionString; await writeFile(plistInfo.app.path, plist.build(plistInfo.app.json)); await writeFile( From 6c96b56dc53c1023f3585faabe3ec741bc0f81d9 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Mon, 2 Oct 2023 00:54:18 -0400 Subject: [PATCH 09/35] test: update demo --- src/build.js | 45 ++++++++++++++++++++++++-------------------- test/fixture/demo.js | 10 ++++++++++ 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/build.js b/src/build.js index 14ca75256..209f3579e 100644 --- a/src/build.js +++ b/src/build.js @@ -507,34 +507,39 @@ export async function build(files, nwDir, outDir, platform, zip, app) { }); plistInfo.helper.alerts.json.CFBundleDisplayName = `${app.name} Helper (Alerts)`; - plistInfo.helper.alerts.json.CFBundleExecutable = `${app.name} Helper (Alerts)`; - plistInfo.helper.alerts.json.CFBundleIdentifier = `${app.CFBundleIdentifier}.helper.alerts`; - plistInfo.helper.alerts.json.CFBundleName = `${app.name} Helper (Alerts)`; - plistInfo.helper.alerts.json.CFBundleShortVersionString = app.CFBundleShortVersionString; + plistInfo.helper.alerts.json.CFBundleExecutable = `${app.name} Helper (Alerts)`; + plistInfo.helper.alerts.json.CFBundleIdentifier = `${app.CFBundleIdentifier}.helper.alerts`; + plistInfo.helper.alerts.json.CFBundleName = `${app.name} Helper (Alerts)`; + plistInfo.helper.alerts.json.CFBundleShortVersionString = + app.CFBundleShortVersionString; plistInfo.helper.gpu.json.CFBundleDisplayName = `${app.name} Helper (GPU)`; - plistInfo.helper.gpu.json.CFBundleExecutable = `${app.name} Helper (GPU)`; - plistInfo.helper.gpu.json.CFBundleIdentifier = `${app.CFBundleIdentifier}.helper.gpu`; - plistInfo.helper.gpu.json.CFBundleName = `${app.name} Helper (GPU)`; - plistInfo.helper.gpu.json.CFBundleShortVersionString = app.CFBundleShortVersionString; + plistInfo.helper.gpu.json.CFBundleExecutable = `${app.name} Helper (GPU)`; + plistInfo.helper.gpu.json.CFBundleIdentifier = `${app.CFBundleIdentifier}.helper.gpu`; + plistInfo.helper.gpu.json.CFBundleName = `${app.name} Helper (GPU)`; + plistInfo.helper.gpu.json.CFBundleShortVersionString = + app.CFBundleShortVersionString; plistInfo.helper.plugin.json.CFBundleDisplayName = `${app.name} Helper (Plugin)`; - plistInfo.helper.plugin.json.CFBundleExecutable = `${app.name} Helper (Plugin)`; - plistInfo.helper.plugin.json.CFBundleIdentifier = `${app.CFBundleIdentifier}.helper.plugin`; - plistInfo.helper.plugin.json.CFBundleName = `${app.name} Helper (Plugin)`; - plistInfo.helper.plugin.json.CFBundleShortVersionString = app.CFBundleShortVersionString; + plistInfo.helper.plugin.json.CFBundleExecutable = `${app.name} Helper (Plugin)`; + plistInfo.helper.plugin.json.CFBundleIdentifier = `${app.CFBundleIdentifier}.helper.plugin`; + plistInfo.helper.plugin.json.CFBundleName = `${app.name} Helper (Plugin)`; + plistInfo.helper.plugin.json.CFBundleShortVersionString = + app.CFBundleShortVersionString; plistInfo.helper.renderer.json.CFBundleDisplayName = `${app.name} Helper (Renderer)`; - plistInfo.helper.renderer.json.CFBundleExecutable = `${app.name} Helper (Renderer)`; - plistInfo.helper.renderer.json.CFBundleIdentifier = `${app.CFBundleIdentifier}.helper.renderer`; - plistInfo.helper.renderer.json.CFBundleName = `${app.name} Helper (Renderer)`; - plistInfo.helper.renderer.json.CFBundleShortVersionString = app.CFBundleShortVersionString; + plistInfo.helper.renderer.json.CFBundleExecutable = `${app.name} Helper (Renderer)`; + plistInfo.helper.renderer.json.CFBundleIdentifier = `${app.CFBundleIdentifier}.helper.renderer`; + plistInfo.helper.renderer.json.CFBundleName = `${app.name} Helper (Renderer)`; + plistInfo.helper.renderer.json.CFBundleShortVersionString = + app.CFBundleShortVersionString; plistInfo.helper.main.json.CFBundleDisplayName = `${app.name} Helper`; - plistInfo.helper.main.json.CFBundleExecutable = `${app.name} Helper`; - plistInfo.helper.main.json.CFBundleIdentifier = `${app.CFBundleIdentifier}.helper`; - plistInfo.helper.main.json.CFBundleName = `${app.name} Helper`; - plistInfo.helper.main.json.CFBundleShortVersionString = app.CFBundleShortVersionString; + plistInfo.helper.main.json.CFBundleExecutable = `${app.name} Helper`; + plistInfo.helper.main.json.CFBundleIdentifier = `${app.CFBundleIdentifier}.helper`; + plistInfo.helper.main.json.CFBundleName = `${app.name} Helper`; + plistInfo.helper.main.json.CFBundleShortVersionString = + app.CFBundleShortVersionString; await writeFile(plistInfo.app.path, plist.build(plistInfo.app.json)); await writeFile( diff --git a/test/fixture/demo.js b/test/fixture/demo.js index db00202b8..cc6e3bcd0 100644 --- a/test/fixture/demo.js +++ b/test/fixture/demo.js @@ -7,4 +7,14 @@ await nwbuild({ srcDir: "app", outDir: "out", glob: false, + app: { + name: "Demo", + icon: "icon.icns", + CFBundleIdentifier: "io.nwutils.demo", + CFBundleName: "Demo", + CFBundleDisplayName: "Demo", + CFBundleVersion: "0.0.0", + CFBundleShortVersionString: "0.0.0", + NSHumanReadableCopyright: "Copyright (c) 2023", + }, }); From 792bdb8e03bfefdf67611534037ab665e3d6c80d Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Mon, 2 Oct 2023 00:54:58 -0400 Subject: [PATCH 10/35] test: fix icon file path --- test/fixture/demo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fixture/demo.js b/test/fixture/demo.js index cc6e3bcd0..5ae979db2 100644 --- a/test/fixture/demo.js +++ b/test/fixture/demo.js @@ -9,7 +9,7 @@ await nwbuild({ glob: false, app: { name: "Demo", - icon: "icon.icns", + icon: "app/icon.icns", CFBundleIdentifier: "io.nwutils.demo", CFBundleName: "Demo", CFBundleDisplayName: "Demo", From ed78e42ffaee5822f53f80bc8e94f66b704ad67e Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Mon, 2 Oct 2023 01:01:24 -0400 Subject: [PATCH 11/35] fix: lint --- src/build.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build.js b/src/build.js index 209f3579e..bd3a72f68 100644 --- a/src/build.js +++ b/src/build.js @@ -1,5 +1,5 @@ import { resolve } from "node:path"; -import { platform as PLATFORM, exit } from "node:process"; +import { platform as PLATFORM } from "node:process"; import { cp, copyFile, From 84b2aa21d97f4cd233706dbc926ba003b67216ef Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Mon, 2 Oct 2023 14:59:38 -0400 Subject: [PATCH 12/35] fix: rename `Contents/MacOS/nwjs` to `options.app.name` --- src/build.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/build.js b/src/build.js index bd3a72f68..f9c7c763d 100644 --- a/src/build.js +++ b/src/build.js @@ -350,7 +350,13 @@ export async function build(files, nwDir, outDir, platform, zip, app) { resolve(outDir, `${app.name}.app`), ); - // Rename Helper apps + // Rename `Contents/MacOS/nwjs` + await rename( + resolve(outDir, `${app.name}.app`, "Contents", "MacOS", "nwjs"), + resolve(outDir, `${app.name}.app`, "Contents", "MacOS", `${app.name}`), + ); + + // Rename Helper app await rename( resolve( outDir, @@ -372,6 +378,7 @@ export async function build(files, nwDir, outDir, platform, zip, app) { ), ); + // Rename Alerts Helper app await rename( resolve( outDir, @@ -392,6 +399,8 @@ export async function build(files, nwDir, outDir, platform, zip, app) { `${app.name} Helper (Alerts).app`, ), ); + + // Rename GPU Helper app await rename( resolve( outDir, @@ -412,6 +421,8 @@ export async function build(files, nwDir, outDir, platform, zip, app) { `${app.name} Helper (GPU).app`, ), ); + + // Rename Plugin Helper app await rename( resolve( outDir, @@ -432,6 +443,8 @@ export async function build(files, nwDir, outDir, platform, zip, app) { `${app.name} Helper (Plugin).app`, ), ); + + // Rename Renderer Helper app await rename( resolve( outDir, @@ -495,10 +508,12 @@ export async function build(files, nwDir, outDir, platform, zip, app) { plistInfo.app.json.CFBundleIdentifier = app.CFBundleIdentifier; plistInfo.app.json.CFBundleName = app.CFBundleName; plistInfo.app.json.CFBundleDisplayName = app.CFBundleDisplayName; + plistInfo.app.json.CFBundleExecutable = app.name; plistInfo.app.json.CFBundleSpokenName = app.CFBundleSpokenName; plistInfo.app.json.CFBundleVersion = app.CFBundleVersion; plistInfo.app.json.CFBundleShortVersionString = app.CFBundleShortVersionString; + plistInfo.app.json.CFBundleExecutable = app.CFBundleExecutable; Object.keys(plistInfo.app.json).forEach((option) => { if (plistInfo.app.json[option] === undefined) { From b172c9836b411aa130f415981c4df10389187300 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Mon, 2 Oct 2023 15:05:53 -0400 Subject: [PATCH 13/35] fix: rename `Contents/MacOS/nwjs` to `options.app.name` again --- src/build.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/build.js b/src/build.js index f9c7c763d..fcb90bbeb 100644 --- a/src/build.js +++ b/src/build.js @@ -513,7 +513,6 @@ export async function build(files, nwDir, outDir, platform, zip, app) { plistInfo.app.json.CFBundleVersion = app.CFBundleVersion; plistInfo.app.json.CFBundleShortVersionString = app.CFBundleShortVersionString; - plistInfo.app.json.CFBundleExecutable = app.CFBundleExecutable; Object.keys(plistInfo.app.json).forEach((option) => { if (plistInfo.app.json[option] === undefined) { From eaa0b4b2e4d2a43b87b0a9de49ce8f38d8a3d8a6 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Mon, 2 Oct 2023 15:29:21 -0400 Subject: [PATCH 14/35] fix: rename Helper exe inside Contents/MacOS --- src/build.js | 58 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/src/build.js b/src/build.js index fcb90bbeb..faa2b46c4 100644 --- a/src/build.js +++ b/src/build.js @@ -281,7 +281,7 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "Frameworks", "nwjs Framework.framework", "Helpers", - `${app.name} Helper (Alerts).app`, + "nwjs Helper (Alerts).app", "Contents", "Info.plist", ), @@ -295,7 +295,7 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "Frameworks", "nwjs Framework.framework", "Helpers", - `${app.name} Helper (GPU).app`, + "nwjs Helper (GPU).app", "Contents", "Info.plist", ), @@ -309,7 +309,7 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "Frameworks", "nwjs Framework.framework", "Helpers", - `${app.name} Helper (Plugin).app`, + "nwjs Helper (Plugin).app", "Contents", "Info.plist", ), @@ -323,7 +323,7 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "Frameworks", "nwjs Framework.framework", "Helpers", - `${app.name} Helper (Renderer).app`, + "nwjs Helper (Renderer).app", "Contents", "Info.plist", ), @@ -337,7 +337,7 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "Frameworks", "nwjs Framework.framework", "Helpers", - `${app.name} Helper.app`, + "nwjs Helper.app", "Contents", "Info.plist", ), @@ -366,6 +366,9 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "nwjs Framework.framework", "Helpers", "nwjs Helper.app", + "Contents", + "MacOS", + "nwjs Helper", ), resolve( outDir, @@ -374,7 +377,10 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "Frameworks", "nwjs Framework.framework", "Helpers", - `${app.name} Helper.app`, + "nwjs Helper.app", + "Contents", + "MacOS", + `${app.name} Helper`, ), ); @@ -387,7 +393,10 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "Frameworks", "nwjs Framework.framework", "Helpers", - `nwjs Helper (Alerts).app`, + "nwjs Helper (Alerts).app", + "Contents", + "MacOS", + "nwjs Helper (Alerts)", ), resolve( outDir, @@ -396,7 +405,10 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "Frameworks", "nwjs Framework.framework", "Helpers", - `${app.name} Helper (Alerts).app`, + "nwjs Helper (Alerts).app", + "Contents", + "MacOS", + `${app.name} Helper (Alerts)`, ), ); @@ -409,7 +421,10 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "Frameworks", "nwjs Framework.framework", "Helpers", - `nwjs Helper (GPU).app`, + "nwjs Helper (GPU).app", + "Contents", + "MacOS", + "nwjs Helper (GPU)", ), resolve( outDir, @@ -418,7 +433,10 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "Frameworks", "nwjs Framework.framework", "Helpers", - `${app.name} Helper (GPU).app`, + "nwjs Helper (GPU).app", + "Contents", + "MacOS", + `${app.name} Helper (GPU)`, ), ); @@ -431,7 +449,10 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "Frameworks", "nwjs Framework.framework", "Helpers", - `nwjs Helper (Plugin).app`, + "nwjs Helper (Plugin).app", + "Contents", + "MacOS", + "nwjs Helper (Plugin)", ), resolve( outDir, @@ -440,7 +461,10 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "Frameworks", "nwjs Framework.framework", "Helpers", - `${app.name} Helper (Plugin).app`, + "nwjs Helper (Plugin).app", + "Contents", + "MacOS", + `${app.name} Helper (Plugin)`, ), ); @@ -453,7 +477,10 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "Frameworks", "nwjs Framework.framework", "Helpers", - `nwjs Helper (Renderer).app`, + "nwjs Helper (Renderer).app", + "Contents", + "MacOS", + "nwjs Helper (Renderer)", ), resolve( outDir, @@ -462,7 +489,10 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "Frameworks", "nwjs Framework.framework", "Helpers", - `${app.name} Helper (Renderer).app`, + "nwjs Helper (Renderer).app", + "Contents", + "MacOS", + `${app.name} Helper (Renderer)`, ), ); From febf0447b2f34b620dbd0fdb2dc287e909d26988 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Mon, 2 Oct 2023 19:43:32 -0400 Subject: [PATCH 15/35] ci: test run demo app --- .github/workflows/e2e.yml | 28 ++++++++++++++++------------ package.json | 3 ++- test/fixture/preview.js | 11 +++++++++++ 3 files changed, 29 insertions(+), 13 deletions(-) create mode 100644 test/fixture/preview.js diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index a23d37b7e..a1ecc339f 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -12,8 +12,8 @@ jobs: e2e: strategy: matrix: - os: [macos-12, ubuntu-22.04, windows-2022] - node: [16, 18, 20] + os: [macos-13] + node: [20] fail-fast: false runs-on: ${{ matrix.os }} steps: @@ -32,13 +32,17 @@ jobs: run: corepack enable - name: Install dependencies run: npm ci - - name: Check for formatting errors - run: npm run ci:fmt - - name: Check for linting errors - run: npm run ci:lnt - - name: Link module - run: npm link nw-builder - - name: Run unit tests - run: npm run test:unit - - name: Run Selenium tests - run: npm run test:e2e + - name: TMP - Build Preview + run: npm run demo + - name: TMP - Run Preview + run: npm run preview + # - name: Check for formatting errors + # run: npm run ci:fmt + # - name: Check for linting errors + # run: npm run ci:lnt + # - name: Link module + # run: npm link nw-builder + # - name: Run unit tests + # run: npm run test:unit + # - name: Run Selenium tests + # run: npm run test:e2e diff --git a/package.json b/package.json index 9a07b3c8d..768515046 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,8 @@ "doc:bld": "node cfg/jsdoc.config.cjs && vitepress build doc", "test:unit": "node --test test/unit/index.js", "test:e2e": "node --test test/e2e/index.js", - "demo": "cd test/fixture && node demo.js" + "demo": "cd test/fixture && node demo.js", + "preview": "cd test/fixture && node preview.js" }, "devDependencies": { "concurrently": "^8.2.0", diff --git a/test/fixture/preview.js b/test/fixture/preview.js new file mode 100644 index 000000000..8fa1d0eca --- /dev/null +++ b/test/fixture/preview.js @@ -0,0 +1,11 @@ +import { spawn } from "node:child_process"; +import { resolve } from "node:path"; + +const process = spawn(resolve( + "out", + "Demo.app" +)); + +process.on("error", (error) => { + console.log(error); +}); From cd585dcbd84149db79b2e00cf1191e8948de3a9c Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Mon, 2 Oct 2023 19:46:45 -0400 Subject: [PATCH 16/35] chore: unset `unzip` logic --- src/get.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/get.js b/src/get.js index a6c3f9302..c64c5d4d1 100644 --- a/src/get.js +++ b/src/get.js @@ -197,22 +197,22 @@ async function get_nwjs({ bar.stop(); if (platform === "linux") { compressing.tgz.uncompress(out, cacheDir).then(() => resolve()); - } else if (platform === "osx") { - //TODO: compressing package does not restore symlinks on some macOS (eg: circleCI) - const exec = function (cmd) { - log.debug(cmd); - const result = spawnSync(cmd, { - shell: true, - stdio: "inherit", - }); - if (result.status !== 0) { - log.debug(`Command failed with status ${result.status}`); - if (result.error) console.log(result.error); - EXIT(1); - } - return resolve(); - }; - exec(`unzip -o "${out}" -d "${cacheDir}"`); + // } else if (platform === "osx") { + // //TODO: compressing package does not restore symlinks on some macOS (eg: circleCI) + // const exec = function (cmd) { + // log.debug(cmd); + // const result = spawnSync(cmd, { + // shell: true, + // stdio: "inherit", + // }); + // if (result.status !== 0) { + // log.debug(`Command failed with status ${result.status}`); + // if (result.error) console.log(result.error); + // EXIT(1); + // } + // return resolve(); + // }; + // exec(`unzip -o "${out}" -d "${cacheDir}"`); } else { compressing.zip.uncompress(out, cacheDir).then(() => resolve()); } From e9fda7fcbb94d9be67cd79a4f6391f1c7e4ad30d Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Wed, 4 Oct 2023 22:29:43 -0400 Subject: [PATCH 17/35] fix: format --- .github/workflows/e2e.yml | 28 ++++++++++++---------------- src/get.js | 32 ++++++++++++++++---------------- test/fixture/preview.js | 11 ----------- 3 files changed, 28 insertions(+), 43 deletions(-) delete mode 100644 test/fixture/preview.js diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index a1ecc339f..a23d37b7e 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -12,8 +12,8 @@ jobs: e2e: strategy: matrix: - os: [macos-13] - node: [20] + os: [macos-12, ubuntu-22.04, windows-2022] + node: [16, 18, 20] fail-fast: false runs-on: ${{ matrix.os }} steps: @@ -32,17 +32,13 @@ jobs: run: corepack enable - name: Install dependencies run: npm ci - - name: TMP - Build Preview - run: npm run demo - - name: TMP - Run Preview - run: npm run preview - # - name: Check for formatting errors - # run: npm run ci:fmt - # - name: Check for linting errors - # run: npm run ci:lnt - # - name: Link module - # run: npm link nw-builder - # - name: Run unit tests - # run: npm run test:unit - # - name: Run Selenium tests - # run: npm run test:e2e + - name: Check for formatting errors + run: npm run ci:fmt + - name: Check for linting errors + run: npm run ci:lnt + - name: Link module + run: npm link nw-builder + - name: Run unit tests + run: npm run test:unit + - name: Run Selenium tests + run: npm run test:e2e diff --git a/src/get.js b/src/get.js index c64c5d4d1..08c23c2f0 100644 --- a/src/get.js +++ b/src/get.js @@ -197,22 +197,22 @@ async function get_nwjs({ bar.stop(); if (platform === "linux") { compressing.tgz.uncompress(out, cacheDir).then(() => resolve()); - // } else if (platform === "osx") { - // //TODO: compressing package does not restore symlinks on some macOS (eg: circleCI) - // const exec = function (cmd) { - // log.debug(cmd); - // const result = spawnSync(cmd, { - // shell: true, - // stdio: "inherit", - // }); - // if (result.status !== 0) { - // log.debug(`Command failed with status ${result.status}`); - // if (result.error) console.log(result.error); - // EXIT(1); - // } - // return resolve(); - // }; - // exec(`unzip -o "${out}" -d "${cacheDir}"`); + // } else if (platform === "osx") { + // //TODO: compressing package does not restore symlinks on some macOS (eg: circleCI) + // const exec = function (cmd) { + // log.debug(cmd); + // const result = spawnSync(cmd, { + // shell: true, + // stdio: "inherit", + // }); + // if (result.status !== 0) { + // log.debug(`Command failed with status ${result.status}`); + // if (result.error) console.log(result.error); + // EXIT(1); + // } + // return resolve(); + // }; + // exec(`unzip -o "${out}" -d "${cacheDir}"`); } else { compressing.zip.uncompress(out, cacheDir).then(() => resolve()); } diff --git a/test/fixture/preview.js b/test/fixture/preview.js deleted file mode 100644 index 8fa1d0eca..000000000 --- a/test/fixture/preview.js +++ /dev/null @@ -1,11 +0,0 @@ -import { spawn } from "node:child_process"; -import { resolve } from "node:path"; - -const process = spawn(resolve( - "out", - "Demo.app" -)); - -process.on("error", (error) => { - console.log(error); -}); From 8882226bc002b03dadd065080196db332458fe47 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Wed, 4 Oct 2023 23:28:24 -0400 Subject: [PATCH 18/35] fix: format and lint --- src/get.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/get.js b/src/get.js index 08c23c2f0..a6c3f9302 100644 --- a/src/get.js +++ b/src/get.js @@ -197,22 +197,22 @@ async function get_nwjs({ bar.stop(); if (platform === "linux") { compressing.tgz.uncompress(out, cacheDir).then(() => resolve()); - // } else if (platform === "osx") { - // //TODO: compressing package does not restore symlinks on some macOS (eg: circleCI) - // const exec = function (cmd) { - // log.debug(cmd); - // const result = spawnSync(cmd, { - // shell: true, - // stdio: "inherit", - // }); - // if (result.status !== 0) { - // log.debug(`Command failed with status ${result.status}`); - // if (result.error) console.log(result.error); - // EXIT(1); - // } - // return resolve(); - // }; - // exec(`unzip -o "${out}" -d "${cacheDir}"`); + } else if (platform === "osx") { + //TODO: compressing package does not restore symlinks on some macOS (eg: circleCI) + const exec = function (cmd) { + log.debug(cmd); + const result = spawnSync(cmd, { + shell: true, + stdio: "inherit", + }); + if (result.status !== 0) { + log.debug(`Command failed with status ${result.status}`); + if (result.error) console.log(result.error); + EXIT(1); + } + return resolve(); + }; + exec(`unzip -o "${out}" -d "${cacheDir}"`); } else { compressing.zip.uncompress(out, cacheDir).then(() => resolve()); } From 446f21840f54073aabd2c94edaa59e4981bc8404 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Wed, 4 Oct 2023 23:33:18 -0400 Subject: [PATCH 19/35] chore: revert build.js to main impl --- src/build.js | 379 +++++---------------------------------------------- 1 file changed, 34 insertions(+), 345 deletions(-) diff --git a/src/build.js b/src/build.js index faa2b46c4..e7a2c7c60 100644 --- a/src/build.js +++ b/src/build.js @@ -246,286 +246,33 @@ export async function build(files, nwDir, outDir, platform, zip, app) { } try { - let plistInfo = { - app: { - json: {}, - path: resolve(outDir, `${app.name}.app`, "Contents", "Info.plist"), - }, - icon: { - path: resolve( - outDir, - `${app.name}.app`, - "Contents", - "Resources", - "app.icns", - ), - }, - strings: { - array: [], - path: resolve( - outDir, - `${app.name}.app`, - "Contents", - "Resources", - "en.lproj", - "InfoPlist.strings", - ), - }, - helper: { - alerts: { - json: {}, - path: resolve( - outDir, - `${app.name}.app`, - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Helpers", - "nwjs Helper (Alerts).app", - "Contents", - "Info.plist", - ), - }, - gpu: { - json: {}, - path: resolve( - outDir, - `${app.name}.app`, - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Helpers", - "nwjs Helper (GPU).app", - "Contents", - "Info.plist", - ), - }, - plugin: { - json: {}, - path: resolve( - outDir, - `${app.name}.app`, - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Helpers", - "nwjs Helper (Plugin).app", - "Contents", - "Info.plist", - ), - }, - renderer: { - json: {}, - path: resolve( - outDir, - `${app.name}.app`, - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Helpers", - "nwjs Helper (Renderer).app", - "Contents", - "Info.plist", - ), - }, - main: { - json: {}, - path: resolve( - outDir, - `${app.name}.app`, - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Helpers", - "nwjs Helper.app", - "Contents", - "Info.plist", - ), - }, - }, - }; - - await rename( - resolve(outDir, "nwjs.app"), - resolve(outDir, `${app.name}.app`), - ); - - // Rename `Contents/MacOS/nwjs` - await rename( - resolve(outDir, `${app.name}.app`, "Contents", "MacOS", "nwjs"), - resolve(outDir, `${app.name}.app`, "Contents", "MacOS", `${app.name}`), - ); - - // Rename Helper app - await rename( - resolve( - outDir, - `${app.name}.app`, - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Helpers", - "nwjs Helper.app", - "Contents", - "MacOS", - "nwjs Helper", - ), - resolve( - outDir, - `${app.name}.app`, - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Helpers", - "nwjs Helper.app", - "Contents", - "MacOS", - `${app.name} Helper`, - ), - ); - - // Rename Alerts Helper app - await rename( - resolve( - outDir, - `${app.name}.app`, - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Helpers", - "nwjs Helper (Alerts).app", - "Contents", - "MacOS", - "nwjs Helper (Alerts)", - ), - resolve( - outDir, - `${app.name}.app`, - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Helpers", - "nwjs Helper (Alerts).app", - "Contents", - "MacOS", - `${app.name} Helper (Alerts)`, - ), - ); - - // Rename GPU Helper app - await rename( - resolve( - outDir, - `${app.name}.app`, - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Helpers", - "nwjs Helper (GPU).app", - "Contents", - "MacOS", - "nwjs Helper (GPU)", - ), - resolve( - outDir, - `${app.name}.app`, - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Helpers", - "nwjs Helper (GPU).app", - "Contents", - "MacOS", - `${app.name} Helper (GPU)`, - ), - ); - - // Rename Plugin Helper app - await rename( - resolve( - outDir, - `${app.name}.app`, - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Helpers", - "nwjs Helper (Plugin).app", - "Contents", - "MacOS", - "nwjs Helper (Plugin)", - ), - resolve( - outDir, - `${app.name}.app`, - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Helpers", - "nwjs Helper (Plugin).app", - "Contents", - "MacOS", - `${app.name} Helper (Plugin)`, - ), - ); - - // Rename Renderer Helper app - await rename( - resolve( - outDir, - `${app.name}.app`, - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Helpers", - "nwjs Helper (Renderer).app", - "Contents", - "MacOS", - "nwjs Helper (Renderer)", - ), - resolve( - outDir, - `${app.name}.app`, - "Contents", - "Frameworks", - "nwjs Framework.framework", - "Helpers", - "nwjs Helper (Renderer).app", - "Contents", - "MacOS", - `${app.name} Helper (Renderer)`, - ), - ); - - // Replace default with custom icon + const outApp = resolve(outDir, `${app.name}.app`); + await rename(resolve(outDir, "nwjs.app"), outApp); if (app.icon !== undefined) { - await copyFile(resolve(app.icon), plistInfo.icon.path); + await copyFile( + resolve(app.icon), + resolve(outApp, "Contents", "Resources", "app.icns"), + ); } - plistInfo.app.json = plist.parse( - await readFile(plistInfo.app.path, "utf-8"), - ); - - plistInfo.strings.array = ( - await readFile(plistInfo.strings.path, "utf-8") - ).split("\n"); + const infoPlistPath = resolve(outApp, "Contents", "Info.plist"); + const infoPlistJson = plist.parse(await readFile(infoPlistPath, "utf-8")); - plistInfo.helper.alerts.json = plist.parse( - await readFile(plistInfo.helper.alerts.path, "utf-8"), + const infoPlistStringsPath = resolve( + outApp, + "Contents", + "Resources", + "en.lproj", + "InfoPlist.strings", ); - plistInfo.helper.gpu.json = plist.parse( - await readFile(plistInfo.helper.gpu.path, "utf-8"), - ); - plistInfo.helper.plugin.json = plist.parse( - await readFile(plistInfo.helper.plugin.path, "utf-8"), - ); - plistInfo.helper.renderer.json = plist.parse( - await readFile(plistInfo.helper.renderer.path, "utf-8"), - ); - plistInfo.helper.main.json = plist.parse( - await readFile(plistInfo.helper.main.path, "utf-8"), + const infoPlistStringsData = await readFile( + infoPlistStringsPath, + "utf-8", ); - plistInfo.strings.array.forEach((line, idx, arr) => { + let infoPlistStringsDataArray = infoPlistStringsData.split("\n"); + + infoPlistStringsDataArray.forEach((line, idx, arr) => { if (line.includes("NSHumanReadableCopyright")) { arr[ idx @@ -533,82 +280,24 @@ export async function build(files, nwDir, outDir, platform, zip, app) { } }); - plistInfo.app.json.LSApplicationCategoryType = - app.LSApplicationCategoryType; - plistInfo.app.json.CFBundleIdentifier = app.CFBundleIdentifier; - plistInfo.app.json.CFBundleName = app.CFBundleName; - plistInfo.app.json.CFBundleDisplayName = app.CFBundleDisplayName; - plistInfo.app.json.CFBundleExecutable = app.name; - plistInfo.app.json.CFBundleSpokenName = app.CFBundleSpokenName; - plistInfo.app.json.CFBundleVersion = app.CFBundleVersion; - plistInfo.app.json.CFBundleShortVersionString = - app.CFBundleShortVersionString; - - Object.keys(plistInfo.app.json).forEach((option) => { - if (plistInfo.app.json[option] === undefined) { - delete plistInfo.app.json[option]; + infoPlistJson.LSApplicationCategoryType = app.LSApplicationCategoryType; + infoPlistJson.CFBundleIdentifier = app.CFBundleIdentifier; + infoPlistJson.CFBundleName = app.CFBundleName; + infoPlistJson.CFBundleDisplayName = app.CFBundleDisplayName; + infoPlistJson.CFBundleSpokenName = app.CFBundleSpokenName; + infoPlistJson.CFBundleVersion = app.CFBundleVersion; + infoPlistJson.CFBundleShortVersionString = app.CFBundleShortVersionString; + + Object.keys(infoPlistJson).forEach((option) => { + if (infoPlistJson[option] === undefined) { + delete infoPlistJson[option]; } }); - plistInfo.helper.alerts.json.CFBundleDisplayName = `${app.name} Helper (Alerts)`; - plistInfo.helper.alerts.json.CFBundleExecutable = `${app.name} Helper (Alerts)`; - plistInfo.helper.alerts.json.CFBundleIdentifier = `${app.CFBundleIdentifier}.helper.alerts`; - plistInfo.helper.alerts.json.CFBundleName = `${app.name} Helper (Alerts)`; - plistInfo.helper.alerts.json.CFBundleShortVersionString = - app.CFBundleShortVersionString; - - plistInfo.helper.gpu.json.CFBundleDisplayName = `${app.name} Helper (GPU)`; - plistInfo.helper.gpu.json.CFBundleExecutable = `${app.name} Helper (GPU)`; - plistInfo.helper.gpu.json.CFBundleIdentifier = `${app.CFBundleIdentifier}.helper.gpu`; - plistInfo.helper.gpu.json.CFBundleName = `${app.name} Helper (GPU)`; - plistInfo.helper.gpu.json.CFBundleShortVersionString = - app.CFBundleShortVersionString; - - plistInfo.helper.plugin.json.CFBundleDisplayName = `${app.name} Helper (Plugin)`; - plistInfo.helper.plugin.json.CFBundleExecutable = `${app.name} Helper (Plugin)`; - plistInfo.helper.plugin.json.CFBundleIdentifier = `${app.CFBundleIdentifier}.helper.plugin`; - plistInfo.helper.plugin.json.CFBundleName = `${app.name} Helper (Plugin)`; - plistInfo.helper.plugin.json.CFBundleShortVersionString = - app.CFBundleShortVersionString; - - plistInfo.helper.renderer.json.CFBundleDisplayName = `${app.name} Helper (Renderer)`; - plistInfo.helper.renderer.json.CFBundleExecutable = `${app.name} Helper (Renderer)`; - plistInfo.helper.renderer.json.CFBundleIdentifier = `${app.CFBundleIdentifier}.helper.renderer`; - plistInfo.helper.renderer.json.CFBundleName = `${app.name} Helper (Renderer)`; - plistInfo.helper.renderer.json.CFBundleShortVersionString = - app.CFBundleShortVersionString; - - plistInfo.helper.main.json.CFBundleDisplayName = `${app.name} Helper`; - plistInfo.helper.main.json.CFBundleExecutable = `${app.name} Helper`; - plistInfo.helper.main.json.CFBundleIdentifier = `${app.CFBundleIdentifier}.helper`; - plistInfo.helper.main.json.CFBundleName = `${app.name} Helper`; - plistInfo.helper.main.json.CFBundleShortVersionString = - app.CFBundleShortVersionString; - - await writeFile(plistInfo.app.path, plist.build(plistInfo.app.json)); - await writeFile( - plistInfo.strings.path, - plistInfo.strings.array.toString().replace(/,/g, "\n"), - ); - await writeFile( - plistInfo.helper.alerts.path, - plist.build(plistInfo.helper.alerts.json), - ); - await writeFile( - plistInfo.helper.gpu.path, - plist.build(plistInfo.helper.gpu.json), - ); - await writeFile( - plistInfo.helper.plugin.path, - plist.build(plistInfo.helper.plugin.json), - ); - await writeFile( - plistInfo.helper.renderer.path, - plist.build(plistInfo.helper.renderer.json), - ); + await writeFile(infoPlistPath, plist.build(infoPlistJson)); await writeFile( - plistInfo.helper.main.path, - plist.build(plistInfo.helper.main.json), + infoPlistStringsPath, + infoPlistStringsDataArray.toString().replace(/,/g, "\n"), ); } catch (error) { log.error(error); From 2d512bd9002fe9f3e0d9e8b3f84aa2b95b238020 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Wed, 4 Oct 2023 23:38:24 -0400 Subject: [PATCH 20/35] test: set name to `demo` across demo app --- package.json | 3 +-- test/fixture/app/package.json | 4 ++-- test/fixture/demo.js | 6 +++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 759aa7fd6..c76ee9bc8 100644 --- a/package.json +++ b/package.json @@ -48,8 +48,7 @@ "doc:bld": "node .github/jsdoc.config.cjs && vitepress build doc", "test:unit": "node --test test/unit/index.js", "test:e2e": "node --test test/e2e/index.js", - "demo": "cd test/fixture && node demo.js", - "preview": "cd test/fixture && node preview.js" + "demo": "cd test/fixture && node demo.js" }, "devDependencies": { "concurrently": "^8.2.1", diff --git a/test/fixture/app/package.json b/test/fixture/app/package.json index 9e018ac28..85ade08b6 100644 --- a/test/fixture/app/package.json +++ b/test/fixture/app/package.json @@ -1,6 +1,6 @@ { - "name": "nwapp", + "name": "demo", "main": "index.html", "version": "0.0.0", - "product_string": "nwapp" + "product_string": "demo" } diff --git a/test/fixture/demo.js b/test/fixture/demo.js index 5ae979db2..ae4d3250c 100644 --- a/test/fixture/demo.js +++ b/test/fixture/demo.js @@ -8,11 +8,11 @@ await nwbuild({ outDir: "out", glob: false, app: { - name: "Demo", + name: "demo", icon: "app/icon.icns", CFBundleIdentifier: "io.nwutils.demo", - CFBundleName: "Demo", - CFBundleDisplayName: "Demo", + CFBundleName: "demo", + CFBundleDisplayName: "demo", CFBundleVersion: "0.0.0", CFBundleShortVersionString: "0.0.0", NSHumanReadableCopyright: "Copyright (c) 2023", From 6746dc10652dd1ce0e71909f70763978b1e0c066 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Thu, 5 Oct 2023 00:09:07 -0400 Subject: [PATCH 21/35] refactor: simplify plist update process --- src/build.js | 87 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 52 insertions(+), 35 deletions(-) diff --git a/src/build.js b/src/build.js index e7a2c7c60..a9f21acaa 100644 --- a/src/build.js +++ b/src/build.js @@ -245,34 +245,66 @@ export async function build(files, nwDir, outDir, platform, zip, app) { ); } + // TODO: do not rely on symlinks - use actual file paths. + try { - const outApp = resolve(outDir, `${app.name}.app`); - await rename(resolve(outDir, "nwjs.app"), outApp); + // Rename nwjs executable to `options.app.name` + await rename( + resolve(outDir, "nwjs.app"), + resolve(outDir, `${app.name}.app`), + ); + + // Overwrite's nwjs default icon with user specified icon if (app.icon !== undefined) { await copyFile( resolve(app.icon), - resolve(outApp, "Contents", "Resources", "app.icns"), + resolve( + outDir, + `${app.name}.app`, + "Contents", + "Resources", + "app.icns", + ), ); } - const infoPlistPath = resolve(outApp, "Contents", "Info.plist"); - const infoPlistJson = plist.parse(await readFile(infoPlistPath, "utf-8")); + let infoPlist = { + main: { + path: resolve(outDir, `${app.name}.app`, "Contents", "Info.plist"), + json: plist.parse(await readFile(infoPlist.main.path, "utf-8")), + }, + // TODO: update localised string values based on language requirements + strings: { + path: resolve( + outDir, + `${app.name}.app`, + "Contents", + "Resources", + "en.lproj", + "InfoPlist.strings", + ), + list: await readFile(infoPlist.strings.path, "utf-8").split("\n"), + }, + }; - const infoPlistStringsPath = resolve( - outApp, - "Contents", - "Resources", - "en.lproj", - "InfoPlist.strings", - ); - const infoPlistStringsData = await readFile( - infoPlistStringsPath, - "utf-8", - ); + infoPlist.json.LSApplicationCategoryType = app.LSApplicationCategoryType; + infoPlist.json.CFBundleIdentifier = app.CFBundleIdentifier; + infoPlist.json.CFBundleName = app.CFBundleName; + infoPlist.json.CFBundleDisplayName = app.CFBundleDisplayName; + infoPlist.json.CFBundleSpokenName = app.CFBundleSpokenName; + infoPlist.json.CFBundleVersion = app.CFBundleVersion; + infoPlist.json.CFBundleShortVersionString = + app.CFBundleShortVersionString; + + Object.keys(infoPlist.json).forEach((option) => { + if (infoPlist.json[option] === undefined) { + delete infoPlist.json[option]; + } + }); - let infoPlistStringsDataArray = infoPlistStringsData.split("\n"); + await writeFile(infoPlist.path, plist.build(infoPlist.json)); - infoPlistStringsDataArray.forEach((line, idx, arr) => { + infoPlist.strings.list.forEach((line, idx, arr) => { if (line.includes("NSHumanReadableCopyright")) { arr[ idx @@ -280,24 +312,9 @@ export async function build(files, nwDir, outDir, platform, zip, app) { } }); - infoPlistJson.LSApplicationCategoryType = app.LSApplicationCategoryType; - infoPlistJson.CFBundleIdentifier = app.CFBundleIdentifier; - infoPlistJson.CFBundleName = app.CFBundleName; - infoPlistJson.CFBundleDisplayName = app.CFBundleDisplayName; - infoPlistJson.CFBundleSpokenName = app.CFBundleSpokenName; - infoPlistJson.CFBundleVersion = app.CFBundleVersion; - infoPlistJson.CFBundleShortVersionString = app.CFBundleShortVersionString; - - Object.keys(infoPlistJson).forEach((option) => { - if (infoPlistJson[option] === undefined) { - delete infoPlistJson[option]; - } - }); - - await writeFile(infoPlistPath, plist.build(infoPlistJson)); await writeFile( - infoPlistStringsPath, - infoPlistStringsDataArray.toString().replace(/,/g, "\n"), + infoPlist.strings.path, + infoPlist.string.list.toString().replace(/,/g, "\n"), ); } catch (error) { log.error(error); From 159f0209d244424d167304d20fd6546d9cbbcda4 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Thu, 5 Oct 2023 00:44:41 -0400 Subject: [PATCH 22/35] refactor(build): simplify plist update process some more --- src/build.js | 68 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 27 deletions(-) diff --git a/src/build.js b/src/build.js index a9f21acaa..2a813e52d 100644 --- a/src/build.js +++ b/src/build.js @@ -248,12 +248,18 @@ export async function build(files, nwDir, outDir, platform, zip, app) { // TODO: do not rely on symlinks - use actual file paths. try { - // Rename nwjs executable to `options.app.name` + // Rename nwjs.app executable to ${options.app.name}.app await rename( resolve(outDir, "nwjs.app"), resolve(outDir, `${app.name}.app`), ); + // Rename Contents/MacOS/nwjs to Contents/MacOS/${options.app.name} + await rename( + resolve(outDir, `${app.name}.app`, "Contents", "MacOS", "nwjs"), + resolve(outDir, `${app.name}.app`, "Contents", "MacOS", app.name), + ); + // Overwrite's nwjs default icon with user specified icon if (app.icon !== undefined) { await copyFile( @@ -270,40 +276,46 @@ export async function build(files, nwDir, outDir, platform, zip, app) { let infoPlist = { main: { - path: resolve(outDir, `${app.name}.app`, "Contents", "Info.plist"), - json: plist.parse(await readFile(infoPlist.main.path, "utf-8")), + path: "", + json: {}, }, // TODO: update localised string values based on language requirements strings: { - path: resolve( - outDir, - `${app.name}.app`, - "Contents", - "Resources", - "en.lproj", - "InfoPlist.strings", - ), - list: await readFile(infoPlist.strings.path, "utf-8").split("\n"), - }, + path: "", + list: [], + } }; - infoPlist.json.LSApplicationCategoryType = app.LSApplicationCategoryType; - infoPlist.json.CFBundleIdentifier = app.CFBundleIdentifier; - infoPlist.json.CFBundleName = app.CFBundleName; - infoPlist.json.CFBundleDisplayName = app.CFBundleDisplayName; - infoPlist.json.CFBundleSpokenName = app.CFBundleSpokenName; - infoPlist.json.CFBundleVersion = app.CFBundleVersion; - infoPlist.json.CFBundleShortVersionString = + // Main Info.plist: read plist data into memory + infoPlist.main.path = resolve(outDir, `${app.name}.app`, "Contents", "Info.plist"); + infoPlist.main.json = plist.parse(await readFile(infoPlist.main.path, "utf-8")); + + // Main Info.plist: update plist data + infoPlist.main.json.LSApplicationCategoryType = app.LSApplicationCategoryType; + infoPlist.main.json.CFBundleIdentifier = app.CFBundleIdentifier; + infoPlist.main.json.CFBundleName = app.CFBundleName; + infoPlist.main.json.CFBundleDisplayName = app.CFBundleDisplayName; + infoPlist.main.json.CFBundleSpokenName = app.CFBundleSpokenName; + infoPlist.main.json.CFBundleVersion = app.CFBundleVersion; + infoPlist.main.json.CFBundleShortVersionString = app.CFBundleShortVersionString; + infoPlist.main.json.CFBundleExecutable = app.name; - Object.keys(infoPlist.json).forEach((option) => { - if (infoPlist.json[option] === undefined) { - delete infoPlist.json[option]; - } - }); + // Main Info.plist: write updated plist data back to file + await writeFile(infoPlist.main.path, plist.build(infoPlist.main.json)); - await writeFile(infoPlist.path, plist.build(infoPlist.json)); + // InfoPlist.strings: read file into memory + infoPlist.strings.path = resolve( + outDir, + `${app.name}.app`, + "Contents", + "Resources", + "en.lproj", + "InfoPlist.strings", + ); + infoPlist.strings.list = (await readFile(infoPlist.strings.path, "utf-8")).split("\n") + // InfoPlist.strings: update localised InfoPlist.strings infoPlist.strings.list.forEach((line, idx, arr) => { if (line.includes("NSHumanReadableCopyright")) { arr[ @@ -312,10 +324,12 @@ export async function build(files, nwDir, outDir, platform, zip, app) { } }); + // InfoPlist.strings: write updated localised InfoPlist.strings back to file await writeFile( infoPlist.strings.path, - infoPlist.string.list.toString().replace(/,/g, "\n"), + infoPlist.strings.list.toString().replace(/,/g, "\n"), ); + } catch (error) { log.error(error); } From 7c0b721b13ab41423785ada50d0deabc87cb99ef Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Thu, 5 Oct 2023 00:47:52 -0400 Subject: [PATCH 23/35] fix: format --- src/build.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/build.js b/src/build.js index 2a813e52d..f53fa18d3 100644 --- a/src/build.js +++ b/src/build.js @@ -283,15 +283,23 @@ export async function build(files, nwDir, outDir, platform, zip, app) { strings: { path: "", list: [], - } + }, }; // Main Info.plist: read plist data into memory - infoPlist.main.path = resolve(outDir, `${app.name}.app`, "Contents", "Info.plist"); - infoPlist.main.json = plist.parse(await readFile(infoPlist.main.path, "utf-8")); + infoPlist.main.path = resolve( + outDir, + `${app.name}.app`, + "Contents", + "Info.plist", + ); + infoPlist.main.json = plist.parse( + await readFile(infoPlist.main.path, "utf-8"), + ); // Main Info.plist: update plist data - infoPlist.main.json.LSApplicationCategoryType = app.LSApplicationCategoryType; + infoPlist.main.json.LSApplicationCategoryType = + app.LSApplicationCategoryType; infoPlist.main.json.CFBundleIdentifier = app.CFBundleIdentifier; infoPlist.main.json.CFBundleName = app.CFBundleName; infoPlist.main.json.CFBundleDisplayName = app.CFBundleDisplayName; @@ -313,7 +321,9 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "en.lproj", "InfoPlist.strings", ); - infoPlist.strings.list = (await readFile(infoPlist.strings.path, "utf-8")).split("\n") + infoPlist.strings.list = ( + await readFile(infoPlist.strings.path, "utf-8") + ).split("\n"); // InfoPlist.strings: update localised InfoPlist.strings infoPlist.strings.list.forEach((line, idx, arr) => { @@ -329,7 +339,6 @@ export async function build(files, nwDir, outDir, platform, zip, app) { infoPlist.strings.path, infoPlist.strings.list.toString().replace(/,/g, "\n"), ); - } catch (error) { log.error(error); } From 03a6b2a40eaf8bd0dfa31c8c02b1539385699da6 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Thu, 5 Oct 2023 01:25:32 -0400 Subject: [PATCH 24/35] feat: rename macos helpers --- src/build.js | 310 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 310 insertions(+) diff --git a/src/build.js b/src/build.js index f53fa18d3..14c22917f 100644 --- a/src/build.js +++ b/src/build.js @@ -260,6 +260,146 @@ export async function build(files, nwDir, outDir, platform, zip, app) { resolve(outDir, `${app.name}.app`, "Contents", "MacOS", app.name), ); + // Rename main Helper app + await rename( + resolve( + outDir, + `${app.name}.app`, + "Contents", + "Frameworks", + "nwjs Framework.framework", + "Helpers", + "nwjs Helper.app", + "Contents", + "MacOS", + "nwjs Helper", + ), + resolve( + outDir, + `${app.name}.app`, + "Contents", + "Frameworks", + "nwjs Framework.framework", + "Helpers", + "nwjs Helper.app", + "Contents", + "MacOS", + `${app.name} Helper`, + ), + ); + + // Rename Alerts Helper app + await rename( + resolve( + outDir, + `${app.name}.app`, + "Contents", + "Frameworks", + "nwjs Framework.framework", + "Helpers", + "nwjs Helper (Alerts).app", + "Contents", + "MacOS", + "nwjs Helper (Alerts)", + ), + resolve( + outDir, + `${app.name}.app`, + "Contents", + "Frameworks", + "nwjs Framework.framework", + "Helpers", + "nwjs Helper (Alerts).app", + "Contents", + "MacOS", + `${app.name} Helper (Alerts)`, + ), + ); + + // Rename GPU Helper app + await rename( + resolve( + outDir, + `${app.name}.app`, + "Contents", + "Frameworks", + "nwjs Framework.framework", + "Helpers", + "nwjs Helper (GPU).app", + "Contents", + "MacOS", + "nwjs Helper (GPU)", + ), + resolve( + outDir, + `${app.name}.app`, + "Contents", + "Frameworks", + "nwjs Framework.framework", + "Helpers", + "nwjs Helper (GPU).app", + "Contents", + "MacOS", + `${app.name} Helper (GPU)`, + ), + ); + + // Rename Plugin Helper app + await rename( + resolve( + outDir, + `${app.name}.app`, + "Contents", + "Frameworks", + "nwjs Framework.framework", + "Helpers", + "nwjs Helper (Plugin).app", + "Contents", + "MacOS", + "nwjs Helper (Plugin)", + ), + resolve( + outDir, + `${app.name}.app`, + "Contents", + "Frameworks", + "nwjs Framework.framework", + "Helpers", + "nwjs Helper (Plugin).app", + "Contents", + "MacOS", + `${app.name} Helper (Plugin)`, + ), + ); + + // Rename Renderer Helper app + await rename( + resolve( + outDir, + `${app.name}.app`, + "Contents", + "Frameworks", + "nwjs Framework.framework", + "Helpers", + "nwjs Helper (Renderer).app", + "Contents", + "MacOS", + "nwjs Helper (Renderer)", + ), + resolve( + outDir, + `${app.name}.app`, + "Contents", + "Frameworks", + "nwjs Framework.framework", + "Helpers", + "nwjs Helper (Renderer).app", + "Contents", + "MacOS", + `${app.name} Helper (Renderer)`, + ), + ); + // Overwrite's nwjs default icon with user specified icon if (app.icon !== undefined) { await copyFile( @@ -284,6 +424,26 @@ export async function build(files, nwDir, outDir, platform, zip, app) { path: "", list: [], }, + helper_main: { + path: "", + json: {}, + }, + helper_Alerts: { + path: "", + json: {}, + }, + helper_GPU: { + path: "", + json: {}, + }, + helper_Plugin: { + path: "", + json: {}, + }, + helper_Renderer: { + path: "", + json: {}, + }, }; // Main Info.plist: read plist data into memory @@ -339,6 +499,156 @@ export async function build(files, nwDir, outDir, platform, zip, app) { infoPlist.strings.path, infoPlist.strings.list.toString().replace(/,/g, "\n"), ); + + // Main Helper app: read file into memory + infoPlist.helper_main.path = resolve( + outDir, + `${app.name}.app`, + "Contents", + "Frameworks", + "nwjs Framework.framework", + "Helpers", + "nwjs Helper.app", + "Contents", + "Info.plist", + ); + infoPlist.helper_main.json = plist.parse( + await readFile(infoPlist.helper_main.path, "utf-8"), + ); + + // Main Helper app: update plist data + infoPlist.helper_main.json.CFBundleDisplayName = `${app.CFBundleDisplayName} Helper`; + infoPlist.helper_main.json.CFBundleExecutable = `${app.name} Helper`; + infoPlist.helper_main.json.CFBundleIdentifier = `${app.CFBundleIdentifier}.helper`; + infoPlist.helper_main.json.CFBundleName = `${app.name} Helper`; + infoPlist.helper_main.json.CFBundleShortVersionString = + app.CFBundleShortVersionString; + + // Main Helper app: write updated plist data back to file + await writeFile( + infoPlist.helper_main.path, + plist.build(infoPlist.helper_main.json), + ); + + // Alerts Helper app: read file into memory + infoPlist.helper_Alerts.path = resolve( + outDir, + `${app.name}.app`, + "Contents", + "Frameworks", + "nwjs Framework.framework", + "Helpers", + "nwjs Helper (Alerts).app", + "Contents", + "Info.plist", + ); + infoPlist.helper_Alerts.json = plist.parse( + await readFile(infoPlist.helper_Alerts.path, "utf-8"), + ); + + // Alerts Helper app: update plist data + infoPlist.helper_Alerts.json.CFBundleDisplayName = `${app.CFBundleDisplayName} Helper (Alerts)`; + infoPlist.helper_Alerts.json.CFBundleExecutable = `${app.name} Helper (Alerts)`; + infoPlist.helper_Alerts.json.CFBundleIdentifier = `${app.CFBundleIdentifier}.helper.Alerts`; + infoPlist.helper_Alerts.json.CFBundleName = `${app.name} Helper (Alerts)`; + infoPlist.helper_Alerts.json.CFBundleShortVersionString = + app.CFBundleShortVersionString; + + // GPU Helper app: write updated plist data back to file + await writeFile( + infoPlist.helper_GPU.path, + plist.build(infoPlist.helper_GPU.json), + ); + + // GPU Helper app: read file into memory + infoPlist.helper_GPU.path = resolve( + outDir, + `${app.name}.app`, + "Contents", + "Frameworks", + "nwjs Framework.framework", + "Helpers", + "nwjs Helper (GPU).app", + "Contents", + "Info.plist", + ); + infoPlist.helper_GPU.json = plist.parse( + await readFile(infoPlist.helper_GPU.path, "utf-8"), + ); + + // GPU Helper app: update plist data + infoPlist.helper_GPU.json.CFBundleDisplayName = `${app.CFBundleDisplayName} Helper (GPU)`; + infoPlist.helper_GPU.json.CFBundleExecutable = `${app.name} Helper (GPU)`; + infoPlist.helper_GPU.json.CFBundleIdentifier = `${app.CFBundleIdentifier}.helper.GPU`; + infoPlist.helper_GPU.json.CFBundleName = `${app.name} Helper (GPU)`; + infoPlist.helper_GPU.json.CFBundleShortVersionString = + app.CFBundleShortVersionString; + + // GPU Helper app: write updated plist data back to file + await writeFile( + infoPlist.helper_GPU.path, + plist.build(infoPlist.helper_GPU.json), + ); + + // Plugin Helper app: read file into memory + infoPlist.helper_Plugin.path = resolve( + outDir, + `${app.name}.app`, + "Contents", + "Frameworks", + "nwjs Framework.framework", + "Helpers", + "nwjs Helper (Plugin).app", + "Contents", + "Info.plist", + ); + infoPlist.helper_Plugin.json = plist.parse( + await readFile(infoPlist.helper_Plugin.path, "utf-8"), + ); + + // Plugin Helper app: update plist data + infoPlist.helper_Plugin.json.CFBundleDisplayName = `${app.CFBundleDisplayName} Helper (Plugin)`; + infoPlist.helper_Plugin.json.CFBundleExecutable = `${app.name} Helper (Plugin)`; + infoPlist.helper_Plugin.json.CFBundleIdentifier = `${app.CFBundleIdentifier}.helper.Plugin`; + infoPlist.helper_Plugin.json.CFBundleName = `${app.name} Helper (Plugin)`; + infoPlist.helper_Plugin.json.CFBundleShortVersionString = + app.CFBundleShortVersionString; + + // Plugin Helper app: write updated plist data back to file + await writeFile( + infoPlist.helper_Plugin.path, + plist.build(infoPlist.helper_Plugin.json), + ); + + // Renderer Helper app: read file into memory + infoPlist.helper_Renderer.path = resolve( + outDir, + `${app.name}.app`, + "Contents", + "Frameworks", + "nwjs Framework.framework", + "Helpers", + "nwjs Helper (Renderer).app", + "Contents", + "Info.plist", + ); + infoPlist.helper_Renderer.json = plist.parse( + await readFile(infoPlist.helper_Renderer.path, "utf-8"), + ); + + // Renderer Helper app: update plist data + infoPlist.helper_Renderer.json.CFBundleDisplayName = `${app.CFBundleDisplayName} Helper (Renderer)`; + infoPlist.helper_Renderer.json.CFBundleExecutable = `${app.name} Helper (Renderer)`; + infoPlist.helper_Renderer.json.CFBundleIdentifier = `${app.CFBundleIdentifier}.helper.Renderer`; + infoPlist.helper_Renderer.json.CFBundleName = `${app.name} Helper (Renderer)`; + infoPlist.helper_Renderer.json.CFBundleShortVersionString = + app.CFBundleShortVersionString; + + // Renderer Helper app: write updated plist data back to file + await writeFile( + infoPlist.helper_Renderer.path, + plist.build(infoPlist.helper_Renderer.json), + ); } catch (error) { log.error(error); } From 554da1c457ed4c202f834a1c1d331c5403d92114 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Thu, 5 Oct 2023 01:31:22 -0400 Subject: [PATCH 25/35] fix(fs): incorrect `readFile` call --- src/build.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/build.js b/src/build.js index 14c22917f..73dff0a4d 100644 --- a/src/build.js +++ b/src/build.js @@ -554,10 +554,10 @@ export async function build(files, nwDir, outDir, platform, zip, app) { infoPlist.helper_Alerts.json.CFBundleShortVersionString = app.CFBundleShortVersionString; - // GPU Helper app: write updated plist data back to file + // ALerts Helper app: write updated plist data back to file await writeFile( - infoPlist.helper_GPU.path, - plist.build(infoPlist.helper_GPU.json), + infoPlist.helper_Alerts.path, + plist.build(infoPlist.helper_Alerts.json), ); // GPU Helper app: read file into memory From 9dd2163a1f49cf8402e43d76057f1a8475b908d5 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Thu, 5 Oct 2023 01:32:19 -0400 Subject: [PATCH 26/35] fix: code comment --- src/build.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build.js b/src/build.js index 73dff0a4d..66a97a4c6 100644 --- a/src/build.js +++ b/src/build.js @@ -554,7 +554,7 @@ export async function build(files, nwDir, outDir, platform, zip, app) { infoPlist.helper_Alerts.json.CFBundleShortVersionString = app.CFBundleShortVersionString; - // ALerts Helper app: write updated plist data back to file + // Alerts Helper app: write updated plist data back to file await writeFile( infoPlist.helper_Alerts.path, plist.build(infoPlist.helper_Alerts.json), From 34e5e274a071bf55fca050006a08b8a7fbe7713c Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Thu, 5 Oct 2023 01:37:09 -0400 Subject: [PATCH 27/35] chore: add todo comment --- src/build.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/build.js b/src/build.js index 66a97a4c6..905c5ee25 100644 --- a/src/build.js +++ b/src/build.js @@ -218,6 +218,7 @@ export async function build(files, nwDir, outDir, platform, zip, app) { } }); + // TODO: Add support for more options as specified in rcedit v4 docs. const rcEditOptions = { "file-version": app.version, "product-version": app.version, From 9bfb2e64c7c93c7b36da26242da34cbc0549233a Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Mon, 16 Oct 2023 11:38:40 -0400 Subject: [PATCH 28/35] fix: do not rely on symlinks Refs: #931 --- src/build.js | 53 +++++++++++++++++++++++++++++++++++++++++++++------- src/index.js | 1 + 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/build.js b/src/build.js index 905c5ee25..7c40143be 100644 --- a/src/build.js +++ b/src/build.js @@ -105,15 +105,24 @@ import { log } from "./log.js"; * mode: "build", * }); * - * @param {string | string[]} files Array of NW app files - * @param {string} nwDir Directory to hold NW binaries - * @param {string} outDir Directory to store build artifacts - * @param {"linux" | "osx" | "win"} platform Platform is the operating system type - * @param {"zip" | boolean} zip Specify if the build artifacts are to be zipped - * @param {LinuxRc | OsxRc | WinRc} app Multi platform configuration options + * @param {string | string[]} files Array of NW app files + * @param {string} nwDir Directory to hold NW binaries + * @param {string} outDir Directory to store build artifacts + * @param {"linux" | "osx" | "win"} platform Platform is the operating system type + * @param {"zip" | boolean} zip Specify if the build artifacts are to be zipped + * @param {LinuxRc | OsxRc | WinRc} app Multi platform configuration options + * @param {string} chromiumVer Chromium version * @return {Promise} */ -export async function build(files, nwDir, outDir, platform, zip, app) { +export async function build( + files, + nwDir, + outDir, + platform, + zip, + app, + chromiumVer, +) { log.debug(`Remove any files at ${outDir} directory`); await rm(outDir, { force: true, recursive: true }); log.debug(`Copy ${nwDir} files to ${outDir} directory`); @@ -269,6 +278,8 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "Contents", "Frameworks", "nwjs Framework.framework", + "Versions", + chromiumVer, "Helpers", "nwjs Helper.app", "Contents", @@ -281,6 +292,8 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "Contents", "Frameworks", "nwjs Framework.framework", + "Versions", + chromiumVer, "Helpers", "nwjs Helper.app", "Contents", @@ -297,6 +310,8 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "Contents", "Frameworks", "nwjs Framework.framework", + "Versions", + chromiumVer, "Helpers", "nwjs Helper (Alerts).app", "Contents", @@ -309,6 +324,8 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "Contents", "Frameworks", "nwjs Framework.framework", + "Versions", + chromiumVer, "Helpers", "nwjs Helper (Alerts).app", "Contents", @@ -325,6 +342,8 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "Contents", "Frameworks", "nwjs Framework.framework", + "Versions", + chromiumVer, "Helpers", "nwjs Helper (GPU).app", "Contents", @@ -337,6 +356,8 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "Contents", "Frameworks", "nwjs Framework.framework", + "Versions", + chromiumVer, "Helpers", "nwjs Helper (GPU).app", "Contents", @@ -353,6 +374,8 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "Contents", "Frameworks", "nwjs Framework.framework", + "Versions", + chromiumVer, "Helpers", "nwjs Helper (Plugin).app", "Contents", @@ -365,6 +388,8 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "Contents", "Frameworks", "nwjs Framework.framework", + "Versions", + chromiumVer, "Helpers", "nwjs Helper (Plugin).app", "Contents", @@ -381,6 +406,8 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "Contents", "Frameworks", "nwjs Framework.framework", + "Versions", + chromiumVer, "Helpers", "nwjs Helper (Renderer).app", "Contents", @@ -393,6 +420,8 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "Contents", "Frameworks", "nwjs Framework.framework", + "Versions", + chromiumVer, "Helpers", "nwjs Helper (Renderer).app", "Contents", @@ -508,6 +537,8 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "Contents", "Frameworks", "nwjs Framework.framework", + "Versions", + chromiumVer, "Helpers", "nwjs Helper.app", "Contents", @@ -538,6 +569,8 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "Contents", "Frameworks", "nwjs Framework.framework", + "Versions", + chromiumVer, "Helpers", "nwjs Helper (Alerts).app", "Contents", @@ -568,6 +601,8 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "Contents", "Frameworks", "nwjs Framework.framework", + "Versions", + chromiumVer, "Helpers", "nwjs Helper (GPU).app", "Contents", @@ -598,6 +633,8 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "Contents", "Frameworks", "nwjs Framework.framework", + "Versions", + chromiumVer, "Helpers", "nwjs Helper (Plugin).app", "Contents", @@ -628,6 +665,8 @@ export async function build(files, nwDir, outDir, platform, zip, app) { "Contents", "Frameworks", "nwjs Framework.framework", + "Versions", + chromiumVer, "Helpers", "nwjs Helper (Renderer).app", "Contents", diff --git a/src/index.js b/src/index.js index 182fec031..a3e812d5a 100644 --- a/src/index.js +++ b/src/index.js @@ -181,6 +181,7 @@ const nwbuild = async (options) => { options.platform, options.zip, options.app, + releaseInfo.components.chromium, ); } } catch (error) { From b2e1c31615d83aa31a5412b472831daf92492a2f Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Mon, 16 Oct 2023 12:32:26 -0400 Subject: [PATCH 29/35] test: assert exe is renamed to `options.app.name` --- test/e2e/mode.js | 68 +++++++++++++++++++++++++++++++------------- test/fixture/demo.js | 2 +- 2 files changed, 50 insertions(+), 20 deletions(-) diff --git a/test/e2e/mode.js b/test/e2e/mode.js index c6e7c91b2..e3c00899b 100644 --- a/test/e2e/mode.js +++ b/test/e2e/mode.js @@ -1,34 +1,35 @@ import { equal } from "node:assert"; import { arch, platform } from "node:process"; -import { resolve } from "node:path"; +import { basename, resolve } from "node:path"; import { describe, it } from "node:test"; import nwbuild from "nw-builder"; import { By } from "selenium-webdriver"; import chrome from "selenium-webdriver/chrome.js"; -import { getArch } from "../../src/util/arch.js"; -import { getPlatform } from "../../src/util/platform.js"; +import { ARCH_KV, PLATFORM_KV } from "../../src/util.js"; const { Driver, ServiceBuilder, Options } = chrome; describe("test modes", async () => { + let driver = undefined; - let nwOptions = { - srcDir: "test/fixture/app", - mode: "build", - version: "0.80.0", - flavor: "sdk", - platform: getPlatform(platform), - arch: getArch(arch), - outDir: "test/fixture/out", - cacheDir: "test/fixture/cache", - glob: false, - }; - - it("should run", async () => { - await nwbuild({ ...nwOptions }); + let nwOptions = {}; + + it("runs application", async () => { + + await nwbuild({ + srcDir: "test/fixture/app", + mode: "build", + version: "0.80.0", + flavor: "sdk", + platform: PLATFORM_KV[platform], + arch: ARCH_KV[arch], + outDir: "test/fixture/out", + cacheDir: "test/fixture/cache", + glob: false, + }); const options = new Options(); const args = [ @@ -39,8 +40,7 @@ describe("test modes", async () => { const chromedriverPath = resolve( nwOptions.cacheDir, - `nwjs${nwOptions.flavor === "sdk" ? "-sdk" : ""}-v${nwOptions.version}-${ - nwOptions.platform + `nwjs${nwOptions.flavor === "sdk" ? "-sdk" : ""}-v${nwOptions.version}-${nwOptions.platform }-${nwOptions.arch}`, `chromedriver${nwOptions.platform === "win" ? ".exe" : ""}`, ); @@ -51,4 +51,34 @@ describe("test modes", async () => { const text = await driver.findElement(By.id("test")).getText(); equal(text, "Hello, World!"); }); + + it("renames MacOS Helper Apps", async () => { + if (PLATFORM_KV[platform] === 'darwin') { + + await nwbuild({ + srcDir: "test/fixture/app", + mode: "build", + version: "0.80.0", + platform: PLATFORM_KV[platform], + arch: ARCH_KV[arch], + outDir: "test/fixture/out", + cacheDir: "test/fixture/cache", + glob: false, + app: { + name: "demo", + icon: "app/icon.icns", + CFBundleIdentifier: "io.nwutils.demo", + CFBundleName: "demo", + CFBundleDisplayName: "demo", + CFBundleVersion: "0.0.0", + CFBundleShortVersionString: "0.0.0", + NSHumanReadableCopyright: "Copyright (c) 2023 NW.js Utilities", + } + }); + + const appName = basename(resolve(nwOptions.outDir, `${nwOptions.app.name}.app`)); + equal(appName, "demo.app"); + + } + }); }); diff --git a/test/fixture/demo.js b/test/fixture/demo.js index c36e071ed..63b5f48a4 100644 --- a/test/fixture/demo.js +++ b/test/fixture/demo.js @@ -14,6 +14,6 @@ await nwbuild({ CFBundleDisplayName: "demo", CFBundleVersion: "0.0.0", CFBundleShortVersionString: "0.0.0", - NSHumanReadableCopyright: "Copyright (c) 2023", + NSHumanReadableCopyright: "Copyright (c) 2023 NW.js Utilities", }, }); From 3c16f431df7e7b20864705559d9ca42d19354fcf Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Mon, 16 Oct 2023 12:33:34 -0400 Subject: [PATCH 30/35] fix: format --- test/e2e/mode.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/test/e2e/mode.js b/test/e2e/mode.js index e3c00899b..e48ec22f9 100644 --- a/test/e2e/mode.js +++ b/test/e2e/mode.js @@ -12,13 +12,11 @@ import { ARCH_KV, PLATFORM_KV } from "../../src/util.js"; const { Driver, ServiceBuilder, Options } = chrome; describe("test modes", async () => { - let driver = undefined; let nwOptions = {}; it("runs application", async () => { - await nwbuild({ srcDir: "test/fixture/app", mode: "build", @@ -40,7 +38,8 @@ describe("test modes", async () => { const chromedriverPath = resolve( nwOptions.cacheDir, - `nwjs${nwOptions.flavor === "sdk" ? "-sdk" : ""}-v${nwOptions.version}-${nwOptions.platform + `nwjs${nwOptions.flavor === "sdk" ? "-sdk" : ""}-v${nwOptions.version}-${ + nwOptions.platform }-${nwOptions.arch}`, `chromedriver${nwOptions.platform === "win" ? ".exe" : ""}`, ); @@ -53,8 +52,7 @@ describe("test modes", async () => { }); it("renames MacOS Helper Apps", async () => { - if (PLATFORM_KV[platform] === 'darwin') { - + if (PLATFORM_KV[platform] === "darwin") { await nwbuild({ srcDir: "test/fixture/app", mode: "build", @@ -73,12 +71,13 @@ describe("test modes", async () => { CFBundleVersion: "0.0.0", CFBundleShortVersionString: "0.0.0", NSHumanReadableCopyright: "Copyright (c) 2023 NW.js Utilities", - } + }, }); - const appName = basename(resolve(nwOptions.outDir, `${nwOptions.app.name}.app`)); + const appName = basename( + resolve(nwOptions.outDir, `${nwOptions.app.name}.app`), + ); equal(appName, "demo.app"); - } }); }); From 8adcd53aa0e5ed49760ad3ee9c5abe8c66848cbc Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Mon, 16 Oct 2023 12:43:28 -0400 Subject: [PATCH 31/35] test: revert --- test/e2e/mode.js | 63 +++++++++++++----------------------------------- 1 file changed, 17 insertions(+), 46 deletions(-) diff --git a/test/e2e/mode.js b/test/e2e/mode.js index e48ec22f9..c6e7c91b2 100644 --- a/test/e2e/mode.js +++ b/test/e2e/mode.js @@ -1,33 +1,34 @@ import { equal } from "node:assert"; import { arch, platform } from "node:process"; -import { basename, resolve } from "node:path"; +import { resolve } from "node:path"; import { describe, it } from "node:test"; import nwbuild from "nw-builder"; import { By } from "selenium-webdriver"; import chrome from "selenium-webdriver/chrome.js"; -import { ARCH_KV, PLATFORM_KV } from "../../src/util.js"; +import { getArch } from "../../src/util/arch.js"; +import { getPlatform } from "../../src/util/platform.js"; const { Driver, ServiceBuilder, Options } = chrome; describe("test modes", async () => { let driver = undefined; - let nwOptions = {}; - - it("runs application", async () => { - await nwbuild({ - srcDir: "test/fixture/app", - mode: "build", - version: "0.80.0", - flavor: "sdk", - platform: PLATFORM_KV[platform], - arch: ARCH_KV[arch], - outDir: "test/fixture/out", - cacheDir: "test/fixture/cache", - glob: false, - }); + let nwOptions = { + srcDir: "test/fixture/app", + mode: "build", + version: "0.80.0", + flavor: "sdk", + platform: getPlatform(platform), + arch: getArch(arch), + outDir: "test/fixture/out", + cacheDir: "test/fixture/cache", + glob: false, + }; + + it("should run", async () => { + await nwbuild({ ...nwOptions }); const options = new Options(); const args = [ @@ -50,34 +51,4 @@ describe("test modes", async () => { const text = await driver.findElement(By.id("test")).getText(); equal(text, "Hello, World!"); }); - - it("renames MacOS Helper Apps", async () => { - if (PLATFORM_KV[platform] === "darwin") { - await nwbuild({ - srcDir: "test/fixture/app", - mode: "build", - version: "0.80.0", - platform: PLATFORM_KV[platform], - arch: ARCH_KV[arch], - outDir: "test/fixture/out", - cacheDir: "test/fixture/cache", - glob: false, - app: { - name: "demo", - icon: "app/icon.icns", - CFBundleIdentifier: "io.nwutils.demo", - CFBundleName: "demo", - CFBundleDisplayName: "demo", - CFBundleVersion: "0.0.0", - CFBundleShortVersionString: "0.0.0", - NSHumanReadableCopyright: "Copyright (c) 2023 NW.js Utilities", - }, - }); - - const appName = basename( - resolve(nwOptions.outDir, `${nwOptions.app.name}.app`), - ); - equal(appName, "demo.app"); - } - }); }); From 1bd0ed8291c3c9f20c947cae28b5043fc25580e5 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Mon, 16 Oct 2023 12:51:30 -0400 Subject: [PATCH 32/35] test: rename nwjs to `options.app.name` --- test/e2e/index.js | 2 ++ test/e2e/osx.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 test/e2e/osx.js diff --git a/test/e2e/index.js b/test/e2e/index.js index 34782ef6e..13e60ede0 100644 --- a/test/e2e/index.js +++ b/test/e2e/index.js @@ -1,3 +1,5 @@ import * as modeTests from "./mode.js"; +import * as osxTests from "./osx.js"; modeTests; +osxTests; diff --git a/test/e2e/osx.js b/test/e2e/osx.js new file mode 100644 index 000000000..3ba87cbef --- /dev/null +++ b/test/e2e/osx.js @@ -0,0 +1,42 @@ +import { equal } from "node:assert"; +import { basename, resolve } from "node:path"; +import { before, describe, it } from "node:test"; + +import nwbuild from "nw-builder"; + +describe("osx specific tests", () => { + let nwOptions = {}; + + before(async () => { + nwOptions = { + srcDir: "test/fixture/app", + mode: "build", + version: "0.80.0", + platform: "osx", + arch: "x64", + outDir: "test/fixture/out", + cacheDir: "test/fixture/cache", + glob: false, + app: { + name: "demo", + icon: "app/icon.icns", + CFBundleIdentifier: "io.nwutils.demo", + CFBundleName: "demo", + CFBundleDisplayName: "demo", + CFBundleVersion: "0.0.0", + CFBundleShortVersionString: "0.0.0", + NSHumanReadableCopyright: "Copyright (c) 2023 NW.js Utilities", + }, + }; + + await nwbuild(nwOptions); + }); + + it("renames nwjs.app to `options.app.name`", () => { + const appName = basename( + resolve(nwOptions.outDir, `${nwOptions.app.name}.app`), + ".app", + ); + equal(appName, "demo"); + }); +}); From b21d3a0724f1ed08bb3d1c4c9c103da4f42d32f1 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Mon, 16 Oct 2023 12:57:56 -0400 Subject: [PATCH 33/35] test --- package.json | 2 +- test/e2e/index.js | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) delete mode 100644 test/e2e/index.js diff --git a/package.json b/package.json index 6b2a2b948..ad717580c 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "doc:dev": "concurrently --kill-others \"node .github/fswatch.config.js\" \"vitepress dev doc\"", "doc:bld": "node .github/jsdoc.config.cjs && vitepress build doc", "test:unit": "node --test test/unit/index.js", - "test:e2e": "node --test test/e2e/index.js", + "test:e2e": "node --test test/e2e", "demo": "cd test/fixture && node demo.js" }, "devDependencies": { diff --git a/test/e2e/index.js b/test/e2e/index.js deleted file mode 100644 index 13e60ede0..000000000 --- a/test/e2e/index.js +++ /dev/null @@ -1,5 +0,0 @@ -import * as modeTests from "./mode.js"; -import * as osxTests from "./osx.js"; - -modeTests; -osxTests; From fdb4e2a8c83207c58cb68c9ec7cd1826cc3b46e2 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Mon, 16 Oct 2023 13:00:38 -0400 Subject: [PATCH 34/35] run tests --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ad717580c..667e65dc3 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "doc:dev": "concurrently --kill-others \"node .github/fswatch.config.js\" \"vitepress dev doc\"", "doc:bld": "node .github/jsdoc.config.cjs && vitepress build doc", "test:unit": "node --test test/unit/index.js", - "test:e2e": "node --test test/e2e", + "test:e2e": "node --test test/e2e/*.js", "demo": "cd test/fixture && node demo.js" }, "devDependencies": { From f8f971e3ba8aa553796a16a5d5b417b4a7a42a6d Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Mon, 16 Oct 2023 13:13:26 -0400 Subject: [PATCH 35/35] test: rename `Contents/MacOS/nwjs` to `Contents/MacOS/${options.app.name}` --- src/build.js | 2 -- test/e2e/osx.js | 12 +++++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/build.js b/src/build.js index 7c40143be..a3ea23516 100644 --- a/src/build.js +++ b/src/build.js @@ -255,8 +255,6 @@ export async function build( ); } - // TODO: do not rely on symlinks - use actual file paths. - try { // Rename nwjs.app executable to ${options.app.name}.app await rename( diff --git a/test/e2e/osx.js b/test/e2e/osx.js index 3ba87cbef..a4b7915eb 100644 --- a/test/e2e/osx.js +++ b/test/e2e/osx.js @@ -32,11 +32,21 @@ describe("osx specific tests", () => { await nwbuild(nwOptions); }); - it("renames nwjs.app to `options.app.name`", () => { + it("renames nwjs.app to `options.app.name`.app", () => { const appName = basename( resolve(nwOptions.outDir, `${nwOptions.app.name}.app`), ".app", ); + + equal(appName, "demo"); + }); + + it("renames Contents/MacOS/nwjs to Contents/MacOS/${options.app.name}", () => { + const appName = basename( + resolve(nwOptions.outDir, `${nwOptions.app.name}.app`, "Contents", "MacOS", nwOptions.app.name) + ); + equal(appName, "demo"); }); + });