Skip to content

Commit 6087691

Browse files
author
Ayush C
authored
feat: update MacOS metadata (#894)
1 parent 3c9b5a8 commit 6087691

File tree

13 files changed

+742
-236
lines changed

13 files changed

+742
-236
lines changed

doc/.vitepress/config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ export default defineConfig({
3939
text: "Windows Specific Options",
4040
link: "/api-win.md#winrc-object",
4141
},
42+
{
43+
text: "MacOS Specific Options",
44+
link: "/api-osx.md#osxrc-object",
45+
},
4246
],
4347
},
4448
{

package-lock.json

Lines changed: 658 additions & 190 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,22 @@
4141
"scripts": {
4242
"fmt": "prettier --write \"./**/*.{css,html,js,json,md,yml}\"",
4343
"lnt": "eslint --config=cfg/eslint.config.cjs --fix src",
44-
"doc:api": "jsdoc2md ./src/index.js > ./doc/api.md && jsdoc2md ./src/bld/linuxCfg.js > ./doc/api-nux.md && jsdoc2md ./src/bld/winCfg.js > ./doc/api-win.md",
44+
"doc:api": "jsdoc2md ./src/index.js > ./doc/api.md && jsdoc2md ./src/bld/linuxCfg.js > ./doc/api-nux.md && jsdoc2md ./src/bld/winCfg.js > ./doc/api-win.md && jsdoc2md ./src/bld/osxCfg.js > ./doc/api-osx.md",
4545
"doc:dev": "vitepress dev doc",
4646
"doc:bld": "vitepress build doc",
4747
"test:unit": "node --test-reporter=spec --test test/unit/index.js",
4848
"test:e2e": "node --test-reporter=spec --test test/e2e/index.js",
4949
"test:demo": "cd test/fixture && node demo.js"
5050
},
5151
"devDependencies": {
52-
"eslint": "^8.43.0",
52+
"eslint": "^8.44.0",
5353
"eslint-config-tjw-jsdoc": "^1.0.3",
5454
"gh-pages": "^5.0.0",
5555
"jsdoc": "^4.0.2",
5656
"jsdoc-to-markdown": "^8.0.0",
5757
"prettier": "^2.8.8",
5858
"selenium-webdriver": "^4.10.0",
59-
"vitepress": "^1.0.0-beta.3"
59+
"vitepress": "^1.0.0-beta.4"
6060
},
6161
"dependencies": {
6262
"cli-progress": "^3.12.0",

src/bld/linuxCfg.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { log } from "../log.js";
55

66
/**
77
* @typedef {object} LinuxRc Linux configuration options
8+
* @typedef {string} name Name of the application
89
* @property {string} genericName Generic name of the application
910
* @property {boolean} noDisplay If true the application is not displayed
1011
* @property {string} comment Tooltip for the entry, for example "View sites on the Internet".

src/bld/osxCfg.js

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
import { platform } from "node:process";
22
import fs from "node:fs/promises";
3-
import path from "node:path";
3+
import { resolve } from "node:path";
44

55
import plist from "plist";
66

77
import { log } from "../log.js";
88

9+
/**
10+
* @typedef {object} OsxRc OSX resource configuration options
11+
* @property {string} name The name of the application
12+
* @property {string} LSApplicationCategoryType The category that best describes your app for the App Store.
13+
* @property {string} CFBundleIdentifier A unique identifier for a bundle usually in reverse DNS format.
14+
* @property {string} CFBundleName A user-visible short name for the bundle.
15+
* @property {string} CFBundleDisplayName The user-visible name for the bundle.
16+
* @property {string} CFBundleSpokenName A replacement for the app name in text-to-speech operations.
17+
* @property {string} CFBundleVersion The version of the build that identifies an iteration of the bundle.
18+
* @property {string} CFBundleShortVersionString The release or version number of the bundle.
19+
* @property {string} NSHumanReadableCopyright A human-readable copyright notice for the bundle.
20+
*/
21+
922
/**
1023
* OSX specific configuration steps
24+
* https://developer.apple.com/documentation/bundleresources/information_property_list
1125
*
1226
* @param {object} app Resource configuration options for MacOS
1327
* @param {string} outDir The directory to hold build artifacts
@@ -20,37 +34,31 @@ const setOsxConfig = async (app, outDir) => {
2034
);
2135
}
2236
try {
23-
const outApp = path.resolve(outDir, `${app.name}.app`);
24-
await fs.rename(path.resolve(outDir, "nwjs.app"), outApp);
37+
const outApp = resolve(outDir, `${app.name}.app`);
38+
await fs.rename(resolve(outDir, "nwjs.app"), outApp);
2539

26-
// Rename CFBundleDisplayName in Contents/Info.plist
27-
const contentsInfoPlistPath = path.resolve(outApp, "Contents/Info.plist");
28-
const contentsInfoPlistJson = plist.parse(
29-
await fs.readFile(contentsInfoPlistPath, "utf-8")
30-
);
31-
contentsInfoPlistJson.CFBundleDisplayName = app.name;
32-
const contentsInfoPlist = plist.build(contentsInfoPlistJson);
33-
await fs.writeFile(contentsInfoPlistPath, contentsInfoPlist);
34-
35-
// Rename CFBundleDisplayName in Contents/Resources/en.lproj/InfoPlist.strings
36-
const contentsInfoPlistStringsPath = path.resolve(
37-
outApp,
38-
"Contents/Resources/en.lproj/InfoPlist.strings"
40+
const infoPlistPath = resolve(outApp, "Contents/Info.plist");
41+
const infoPlistJson = plist.parse(
42+
await fs.readFile(infoPlistPath, "utf-8")
3943
);
40-
const contentsInfoPlistStrings = await fs.readFile(
41-
contentsInfoPlistStringsPath,
42-
"utf-8"
43-
);
44-
const newPlistStrings = contentsInfoPlistStrings.replace(
45-
/CFBundleGetInfoString = "nwjs /,
46-
`CFBundleGetInfoString = "${app.name} `
47-
);
48-
await fs.writeFile(contentsInfoPlistStringsPath, newPlistStrings);
4944

50-
// Add product_string property to package.json
51-
// const packageJsonPath = path.resolve(outApp, "Contents/Resources/app.nw/package.json");
52-
// app.product_string = app.name;
53-
// await fs.writeFile(packageJsonPath, JSON.stringify(app, null, 4));
45+
infoPlistJson.LSApplicationCategoryType = app.LSApplicationCategoryType;
46+
infoPlistJson.CFBundleIdentifier = app.CFBundleIdentifier;
47+
infoPlistJson.CFBundleName = app.CFBundleName;
48+
infoPlistJson.CFBundleDisplayName = app.CFBundleDisplayName;
49+
infoPlistJson.CFBundleSpokenName = app.CFBundleSpokenName;
50+
infoPlistJson.CFBundleVersion = app.CFBundleVersion;
51+
infoPlistJson.CFBundleShortVersionString = app.CFBundleShortVersionString;
52+
infoPlistJson.NSHumanReadableCopyright = app.NSHumanReadableCopyright;
53+
infoPlistJson.CFBundleIconFile = app.CFBundleIconFile;
54+
55+
Object.keys(infoPlistJson).forEach((option) => {
56+
if (infoPlistJson[option] === undefined) {
57+
delete infoPlistJson[option];
58+
}
59+
});
60+
61+
await fs.writeFile(infoPlistPath, plist.build(infoPlistJson));
5462
} catch (error) {
5563
log.error(error);
5664
}

src/bld/winCfg.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { log } from "../log.js";
77

88
/**
99
* @typedef {object} WinRc Windows configuration options
10+
* @property {string} name The name of the application
11+
* @property {string} version The version of the application
1012
* @property {string} comments Additional information that should be displayed for diagnostic purposes.
1113
* @property {string} company Company that produced the file—for example, Microsoft Corporation or Standard Microsystems Corporation, Inc. This string is required.
1214
* @property {string} fileDescription File description to be presented to users. This string may be displayed in a list box when the user is choosing files to install. For example, Keyboard Driver for AT-Style Keyboards. This string is required.
@@ -58,7 +60,6 @@ const setWinConfig = async (app, outDir) => {
5860
await rename(resolve(outDir, "nw.exe"), outDirAppExe);
5961
await rcedit(outDirAppExe, {
6062
"file-version": app.version,
61-
icon: app.icon,
6263
"product-version": app.version,
6364
"version-string": versionString,
6465
});

src/util/parse.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export const parse = async (options, pkg) => {
4747
// TODO(#737): move this out
4848
if (options.platform === "linux") {
4949
// linux desktop entry file configurations options
50-
options.app.name = options.app.name ?? pkg.name;
5150
options.app.genericName = options.app.genericName ?? undefined;
5251
options.app.noDisplay = options.app.noDisplay ?? undefined;
5352
options.app.comment = options.app.comment ?? undefined;
@@ -73,6 +72,7 @@ export const parse = async (options, pkg) => {
7372
}
7473
if (options.platform === "win") {
7574
// windows configuration options
75+
options.app.version = options.app.version ?? pkg.version;
7676
options.app.comments = options.app.comments ?? undefined;
7777
options.app.company = options.app.company ?? pkg.author;
7878
options.app.fileDescription =
@@ -88,5 +88,22 @@ export const parse = async (options, pkg) => {
8888
options.app.specialBuild = options.app.specialBuild ?? undefined;
8989
}
9090

91+
if (options.platform === "osx") {
92+
options.app.LSApplicationCategoryType =
93+
options.app.LSApplicationCategoryType ?? undefined;
94+
options.app.CFBundleIdentifier =
95+
options.app.CFBundleIdentifier ?? options.app.name;
96+
options.app.CFBundleName = options.app.CFBundleName ?? pkg.name;
97+
options.app.CFBundleDisplayName =
98+
options.app.CFBundleDisplayName ?? pkg.name;
99+
options.app.CFBundleSpokenName = options.app.CFBundleSpokenName ?? pkg.name;
100+
options.app.CFBundleShortVersionString =
101+
options.app.CFBundleVersion ?? pkg.version;
102+
options.app.CFBundleVersion =
103+
options.app.CFBundleShortVersionString ?? pkg.version;
104+
options.app.NSHumanReadableCopyright =
105+
options.app.NSHumanReadableCopyright ?? undefined;
106+
}
107+
91108
return { ...options };
92109
};

src/util/validate.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { readdir } from "node:fs/promises";
33
/**
44
* Validate options
55
*
6-
* @param {import("../../index.js").OPTIONS} options Options
7-
* @param {object} releaseInfo Version specific NW release info
8-
* @return {Promise<undefined>} Return undefined if options are valid
6+
* @param {import("../index.js").Options} options Options
7+
* @param {object} releaseInfo Version specific NW release info
8+
* @return {Promise<undefined>} Return undefined if options are valid
99
* @throws {Error} Throw error if options are invalid
1010
*/
1111
export const validate = async (options, releaseInfo) => {

test/fixture/app/icon.ico

10.1 KB
Binary file not shown.

test/fixture/app/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{
22
"name": "nwapp",
3-
"main": "index.html"
3+
"main": "index.html",
4+
"version": "0.0.0",
5+
"window": {
6+
"icon": "icon.ico"
7+
}
48
}

0 commit comments

Comments
 (0)