adaptorex
Version:
Connect all your live interactive storytelling devices and software
80 lines (69 loc) • 2.19 kB
JavaScript
const resedit = require("resedit")
const fs = require("fs")
const path = require("path")
const { execSync } = require("child_process")
const { version, description } = require("../package.json")
const lang = 1033
const codepage = 1200
const NODE_RANGE = "node22"
const PLATFORM = "win"
const ARCH = "x64"
async function main() {
const pkgFetch = require("@yao-pkg/pkg-fetch")
const fetchedPath = await pkgFetch.need({
nodeRange: NODE_RANGE,
platform: PLATFORM,
arch: ARCH
})
console.log(`Base binary: ${fetchedPath}`)
const patchedPath = fetchedPath.replace("fetched-", "patched-")
const exe = resedit.NtExecutable.from(fs.readFileSync(fetchedPath))
const res = resedit.NtExecutableResource.from(exe)
const iconFile = resedit.Data.IconFile.from(
fs.readFileSync("scripts/assets/icon.ico")
)
resedit.Resource.IconGroupEntry.replaceIconsForResource(
res.entries,
1,
lang,
iconFile.icons.map((item) => item.data)
)
const viList = resedit.Resource.VersionInfo.fromEntries(res.entries)
const vi = viList[0]
const [major, minor, patch] = version.split(".")
vi.setFileVersion(Number(major), Number(minor), Number(patch), 0, lang)
vi.setProductVersion(Number(major), Number(minor), Number(patch), 0, lang)
vi.setStringValues(
{ lang, codepage },
{
FileDescription: description,
ProductName: "adaptor:ex",
CompanyName: "machina eX",
ProductVersion: version,
FileVersion: version,
OriginalFilename: "adaptorex.exe",
LegalCopyright: `© ${new Date().getFullYear()} machina eX`
}
)
vi.outputToResourceEntries(res.entries)
res.outputResource(exe)
fs.writeFileSync(patchedPath, Buffer.from(exe.generate()))
console.log(`Running pkg with patched Binary ${patchedPath}`)
execSync(
`npx @yao-pkg/pkg . ` +
`--targets ${NODE_RANGE}-${PLATFORM}-${ARCH} ` +
`--output dist/adaptorex-win-${version}.exe ` +
`--no-bytecode --public-packages "*" --public`,
{
stdio: "inherit",
env: {
...process.env,
PKG_NODE_PATH: patchedPath
}
}
)
}
main().catch((err) => {
console.error(err)
process.exit(1)
})