Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(bld): migrate from rcedit with resedit #1094

Merged
merged 5 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 30 additions & 81 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"glob": "^10.3.15",
"node-gyp": "^10.1.0",
"plist": "^3.1.0",
"rcedit": "^4.0.1",
"resedit": "^2.0.2",
"semver": "^7.6.2",
"tar": "^7.1.0",
"yargs": "^17.7.2",
Expand Down
52 changes: 30 additions & 22 deletions src/bld.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import fsm from "node:fs/promises";
import process from "node:process";

import compressing from "compressing";
import rcedit from "rcedit";
import * as resedit from "resedit";
// pe-library is a direct dependency of resedit
import * as peLibrary from 'pe-library';
import plist from "plist";

import util from "./util.js"
Expand Down Expand Up @@ -103,7 +105,7 @@ import util from "./util.js"
*
* @async
* @function
* @param {BuildOptions} options - Build options
* @param {BuildOptions} options - Build options
* @return {Promise<void>}
*/
async function bld({
Expand Down Expand Up @@ -311,28 +313,34 @@ const setWinConfig = async ({ app, outDir }) => {
}
});

const rcEditOptions = {
"file-version": app.version,
"product-version": app.version,
"version-string": versionString,
};

const outDirAppExe = path.resolve(outDir, `${app.name}.exe`);
await fsm.rename(path.resolve(outDir, "nw.exe"), outDirAppExe);
const exe = peLibrary.NtExecutable.from(await fsm.readFile(outDirAppExe));
const res = peLibrary.NtExecutableResource.from(exe);
if (app.icon) {
rcEditOptions.icon = app.icon;
}

try {
const outDirAppExe = path.resolve(outDir, `${app.name}.exe`);
await fsm.rename(path.resolve(outDir, "nw.exe"), outDirAppExe);
await rcedit(outDirAppExe, rcEditOptions);
} catch (error) {
if (process.platform !== "win32") {
console.warn(
"Ensure WINE is installed or build your application on Windows platform",
);
}
throw error;
const iconBuffer = await fsm.readFile(path.resolve(app.icon));
const iconFile = resedit.Data.IconFile.from(iconBuffer);
// English (United States)
const EN_US = 1033;
resedit.Resource.IconGroupEntry.replaceIconsForResource(
ayushmanchhabra marked this conversation as resolved.
Show resolved Hide resolved
res.entries,
// This is the name of the icon group nw.js uses that gets shown in file exlorers
'IDR_MAINFRAME',
EN_US,
iconFile.icons.map(i => i.data)
);
}
const [vi] = resedit.Resource.VersionInfo.fromEntries(res.entries);
const [major, minor, patch] = app.version.split(".");
vi.setFileVersion(major, minor, patch, 0, EN_US);
vi.setStringValues({
lang: EN_US,
codepage: 1200
}, versionString);
vi.outputToResourceEntries(res.entries);
res.outputResource(exe);
const outBuffer = Buffer.from(exe.generate());
await fsm.writeFile(outDirAppExe, outBuffer);
};

const setOsxConfig = async ({ outDir, app }) => {
Expand Down