Add app icon generation script and update related processes

- Introduced a new script `generate-app-icons.mjs` to automate the generation of application and installer icons.
- Updated error messages in the Windows MSI build script and the finalize artifacts script to reference the new icon generation command.
- Refactored the pre-build process to call the new icon generation script, ensuring required icons are created before building.
This commit is contained in:
Tom Butcher 2026-08-04 01:11:18 +01:00
parent ee62045416
commit cfd0849cba
5 changed files with 51 additions and 25 deletions

View File

@ -92,6 +92,7 @@
"build:cloudflare": "cross-env VITE_DEPLOY_TARGET=cloudflare vite build",
"deploy": "npm run build:cloudflare && wrangler pages deploy --branch main",
"postinstall": "bun scripts/patch-electrobun-src.mjs && bun scripts/build-macos-effects.mjs",
"generate-app-icons": "bun scripts/generate-app-icons.mjs",
"build:macos-effects": "bun scripts/build-macos-effects.mjs",
"clean": "bun scripts/clean-build.mjs"
},

View File

@ -89,7 +89,7 @@ if ($outputDir -and -not (Test-Path $outputDir)) {
$installerIconPath = Join-Path $rootDir "assets\installer.ico"
if (-not (Test-Path $installerIconPath)) {
throw "Installer icon not found at $installerIconPath. Run scripts/prepare-installer-icons.mjs first."
throw "Installer icon not found at $installerIconPath. Run 'bun run generate-app-icons' first."
}
$installerIconWorkPath = Join-Path $workDir "installer.ico"

View File

@ -211,7 +211,7 @@ function findCommand(command) {
function buildInstallerIcns(destinationPath) {
if (!existsSync(MAC_INSTALLER_ICONSET_PATH)) {
throw new Error(
`Installer iconset not found at ${MAC_INSTALLER_ICONSET_PATH}. Run scripts/prepare-installer-icons.mjs first.`
`Installer iconset not found at ${MAC_INSTALLER_ICONSET_PATH}. Run \`bun run generate-app-icons\` first.`
)
}

View File

@ -0,0 +1,27 @@
import path from 'node:path'
import { spawnSync } from 'node:child_process'
import { fileURLToPath } from 'node:url'
const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
const steps = [
[
path.join(rootDir, 'scripts/prepare-app-icons.mjs'),
'assets/logos/farmcontrolicon.png'
],
[path.join(rootDir, 'scripts/prepare-installer-icons.mjs')]
]
for (const args of steps) {
const result = spawnSync('bun', args, {
cwd: rootDir,
stdio: 'inherit',
env: process.env
})
if (result.status !== 0) {
process.exit(result.status ?? 1)
}
}
console.log('generate-app-icons: done')

View File

@ -61,33 +61,31 @@ if (process.platform === "darwin") {
}
}
const requiredIconPaths = [
path.join(rootDir, "assets/icon.ico"),
path.join(rootDir, "assets/icon.png"),
path.join(rootDir, "assets/icon.iconset/icon_256x256.png"),
path.join(rootDir, "assets/installer.ico"),
];
if (buildEnv === "stable") {
const prepareIcons = spawnSync(
"bun",
[
path.join(rootDir, "scripts/prepare-app-icons.mjs"),
"assets/logos/farmcontrolicon.png",
],
[path.join(rootDir, "scripts/generate-app-icons.mjs")],
{ cwd: rootDir, stdio: "inherit", env: process.env },
);
if (prepareIcons.status !== 0) {
process.exit(prepareIcons.status ?? 1);
}
const prepareInstallerIcons = spawnSync(
"bun",
[path.join(rootDir, "scripts/prepare-installer-icons.mjs")],
{ cwd: rootDir, stdio: "inherit", env: process.env },
);
if (prepareInstallerIcons.status !== 0) {
process.exit(prepareInstallerIcons.status ?? 1);
}
const windowsIconPath = path.join(rootDir, "assets/icon.ico");
if (!existsSync(windowsIconPath)) {
const missingIcons = requiredIconPaths.filter((filePath) => !existsSync(filePath));
if (missingIcons.length > 0) {
console.error(
"pre-build: assets/icon.ico not found after prepare-app-icons (required for build.win.icon)",
`pre-build: missing generated icons:\n${missingIcons
.map((filePath) => ` - ${path.relative(rootDir, filePath)}`)
.join("\n")}\nRun \`bun run generate-app-icons\` to create them.`,
);
process.exit(1);
}