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

feat: build parallel arch, #188 #218

Draft
wants to merge 8 commits into
base: dev
Choose a base branch
from
Draft
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
118 changes: 44 additions & 74 deletions forge.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import crypto from "node:crypto"
import fs, { readdirSync } from "node:fs"
import { readdir } from "node:fs/promises"
import path, { resolve } from "node:path"
import { inspect } from "node:util"

import { FuseV1Options, FuseVersion } from "@electron/fuses"
import { MakerDMG } from "@electron-forge/maker-dmg"
Expand All @@ -11,14 +12,9 @@ import { FusesPlugin } from "@electron-forge/plugin-fuses"
import type { ForgeConfig } from "@electron-forge/shared-types"
import MakerAppImage from "@pengx17/electron-forge-maker-appimage"
import setLanguages from "electron-packager-languages"
import { dump } from "js-yaml"
import { rimraf, rimrafSync } from "rimraf"

const artifactRegex = /.*\.(?:exe|dmg|AppImage|zip)$/
const platformNamesMap = {
darwin: "macos",
linux: "linux",
win32: "windows",
}
const ymlMapsMap = {
darwin: "latest-mac.yml",
linux: "latest-linux.yml",
Expand Down Expand Up @@ -114,8 +110,9 @@ const config: ForgeConfig = {
rebuildConfig: {},
makers: [
new MakerZIP({}, ["darwin"]),
new MakerDMG({
new MakerDMG((arch) => ({
overwrite: true,
name: `Follow${arch === "universal" ? "" : `-${arch}`}`,
background: "resources/dmg-background.png",
icon: "resources/dmg-icon.icns",
iconSize: 160,
Expand All @@ -141,17 +138,18 @@ const config: ForgeConfig = {
path: "/Applications",
},
],
}),
new MakerSquirrel({
name: "Follow",
})),
new MakerSquirrel((arch) => ({
name: `Follow-${arch}`,
setupIcon: "resources/icon.ico",
}),
new MakerAppImage({
})),
new MakerAppImage((arch) => ({
options: {
name: `Follow-${arch}`,
icon: "resources/icon.png",
mimeType: ["x-scheme-handler/follow"],
},
}),
})),
],
plugins: [
// Fuses are used to enable/disable various Electron functionality
Expand Down Expand Up @@ -180,74 +178,46 @@ const config: ForgeConfig = {
],
hooks: {
postMake: async (config, makeResults) => {
const yml: {
version?: string
files: {
const updaterObject = {
version: makeResults[0].packageJSON.version,
files: [] as {
url: string
sha512: string
size: number
}[]
releaseDate?: string
} = {
version: makeResults[0].packageJSON.version,
files: [],
}[],
releaseDate: new Date().toISOString(),
}
makeResults = makeResults.map((result) => {
result.artifacts = result.artifacts.map((artifact) => {
if (artifactRegex.test(artifact)) {
const newArtifact = `${path.dirname(artifact)}/${
result.packageJSON.name
}-${result.packageJSON.version}-${
platformNamesMap[result.platform]
}-${result.arch}${path.extname(artifact)}`
fs.renameSync(artifact, newArtifact)

try {
const fileData = fs.readFileSync(newArtifact)
const hash = crypto
.createHash("sha512")
.update(fileData)
.digest("base64")
const { size } = fs.statSync(newArtifact)

yml.files.push({
url: path.basename(newArtifact),
sha512: hash,
size,
})
} catch {
console.error(`Failed to hash ${newArtifact}`)
}
return newArtifact
} else {
return artifact
}
for (const result of makeResults) {
const applicationOrExecutable = result.artifacts.find(
(artifact) =>
artifact.endsWith(".dmg") ||
artifact.endsWith(".exe") ||
artifact.endsWith(".AppImage"),
)
if (!applicationOrExecutable) {
throw new Error(`No application or executable found: ${inspect(result)}`)
}
const fileData = fs.readFileSync(
applicationOrExecutable,
)
const hash = crypto
.createHash("sha512")
.update(fileData)
.digest("base64")
const { size } = fs.statSync(applicationOrExecutable)

updaterObject.files.push({
url: path.basename(applicationOrExecutable),
sha512: hash,
size,
})
return result
})
yml.releaseDate = new Date().toISOString()
const ymlStr =
`version: ${yml.version}\n` +
`files:\n${yml.files
.map(
(file) =>
` - url: ${file.url}\n` +
` sha512: ${file.sha512}\n` +
` size: ${file.size}\n`,
)
.join("")}releaseDate: ${yml.releaseDate}\n`

const ymlPath = `${path.dirname(makeResults[0].artifacts[0])}/${
ymlMapsMap[makeResults[0].platform]
}`
fs.writeFileSync(ymlPath, ymlStr)
}

makeResults.push({
artifacts: [ymlPath],
platform: makeResults[0].platform,
arch: makeResults[0].arch,
packageJSON: makeResults[0].packageJSON,
})
fs.writeFileSync(
resolve(__dirname, "./out/make", ymlMapsMap[makeResults[0].platform]),
dump(updaterObject),
)

return makeResults
},
Expand Down
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
},
"main": "./dist/main/index.js",
"scripts": {
"build": "npm run typecheck && electron-vite build --outDir=dist && electron-forge make",
"build:macos": "npm run typecheck && electron-vite build --outDir=dist && electron-forge make --arch=universal --platform=darwin",
"build": "npm run typecheck && electron-vite build --outDir=dist && electron-forge make --arch=x64,arm64",
"build:macos": "npm run typecheck && electron-vite build --outDir=dist && electron-forge make --arch=universal,x64,arm64 --platform=darwin",
"build:web": "rm -rf out/web && vite build",
"dev": "electron-vite dev --outDir=dist",
"dev:debug": "export DEBUG=true && vite --debug",
Expand Down Expand Up @@ -146,6 +146,7 @@
"@pengx17/electron-forge-maker-appimage": "1.2.1",
"@tailwindcss/container-queries": "0.1.1",
"@tailwindcss/typography": "0.5.13",
"@types/js-yaml": "4.0.9",
"@types/lodash-es": "4.17.12",
"@types/node": "^20.14.12",
"@types/react": "^18.3.3",
Expand All @@ -161,6 +162,7 @@
"eslint-config-hyoban": "^3.0.0",
"fake-indexeddb": "6.0.0",
"hono": "4.4.7",
"js-yaml": "4.1.0",
"lint-staged": "15.2.7",
"postcss": "8.4.40",
"postcss-js": "4.0.1",
Expand All @@ -184,7 +186,9 @@
"[email protected]": "patches/[email protected]",
"[email protected]": "patches/[email protected]",
"@mozilla/[email protected]": "patches/@[email protected]",
"[email protected]": "patches/[email protected]"
"[email protected]": "patches/[email protected]",
"@pengx17/[email protected]": "patches/@[email protected]",
"@electron-forge/[email protected]": "patches/@[email protected]"
}
},
"simple-git-hooks": {
Expand Down
22 changes: 0 additions & 22 deletions patches/@[email protected]

This file was deleted.

13 changes: 13 additions & 0 deletions patches/@[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/dist/MakerSquirrel.js b/dist/MakerSquirrel.js
index 000386fe230f228dfe82a8b107d78c212e365aeb..d587de3e5ba64cfa007299e8c53086bcb8221c6f 100644
--- a/dist/MakerSquirrel.js
+++ b/dist/MakerSquirrel.js
@@ -21,7 +21,7 @@ class MakerSquirrel extends maker_base_1.MakerBase {
const outPath = path_1.default.resolve(makeDir, `squirrel.windows/${targetArch}`);
await this.ensureDirectory(outPath);
const winstallerConfig = {
- name: typeof packageJSON.name === 'string' ? packageJSON.name.replace(/-/g, '_') : undefined,
+ name: this.config.name || (typeof packageJSON.name === 'string' ? packageJSON.name.replace(/-/g, '_') : undefined),
title: appName,
noMsi: true,
exe: `${forgeConfig.packagerConfig.executableName || appName}.exe`,
31 changes: 31 additions & 0 deletions patches/@[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
diff --git a/dist/src/MakerAppimage.js b/dist/src/MakerAppimage.js
index a57b183ad759c91aa36691a430e87c385ba63f62..1aabeae41f84bcbf8dcc542f67494c8ed21179a5 100644
--- a/dist/src/MakerAppimage.js
+++ b/dist/src/MakerAppimage.js
@@ -69,7 +69,7 @@ class MakerAppImage extends maker_base_1.default {
if (maker !== undefined && isIForgeResolvableMaker(maker)) {
config = maker.config;
}
- const appFileName = `${appName}-${packageJSON.version}.AppImage`;
+ const appFileName = `${this.config.options.name || appName}-${packageJSON.version}.AppImage`;
const appPath = path_1.default.join(makeDir, appFileName);
// translate macos protocols to linux mime types.
const mimeTypes = ((_b = (_a = forgeConfig.packagerConfig) === null || _a === void 0 ? void 0 : _a.protocols) !== null && _b !== void 0 ? _b : []).flatMap((p) => p.schemes.map((s) => "x-scheme-handler/" + s.toLowerCase()));
@@ -101,7 +101,7 @@ class MakerAppImage extends maker_base_1.default {
{ file: `${iconPath}/128x128.png`, size: 128 },
{ file: `${iconPath}/256x256.png`, size: 256 },
];
- const stageDir = path_1.default.join(makeDir, "__appImage-x64");
+ const stageDir = path_1.default.join(makeDir, "__appImage-" + targetArch);
if (!(0, fs_1.existsSync)(makeDir)) {
(0, fs_1.mkdirSync)(makeDir, { recursive: true });
}
@@ -119,7 +119,7 @@ class MakerAppImage extends maker_base_1.default {
"--stage",
stageDir,
"--arch",
- "x64",
+ targetArch,
"--output",
appPath,
"--app",
25 changes: 21 additions & 4 deletions pnpm-lock.yaml

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

Loading