Skip to content

Commit 3e8de30

Browse files
authored
feat: separate packaging for macOS x64 and arm64 architectures (#1389)
* feat: separate packaging for macOS x64 and arm64 architectures * feat: merge yml script * fix: outDir * fix: path * fix: path
1 parent 2ac52eb commit 3e8de30

File tree

4 files changed

+66
-11
lines changed

4 files changed

+66
-11
lines changed

forge.config.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { FusesPlugin } from "@electron-forge/plugin-fuses"
1111
import type { ForgeConfig } from "@electron-forge/shared-types"
1212
import MakerAppImage from "@pengx17/electron-forge-maker-appimage"
1313
import setLanguages from "electron-packager-languages"
14+
import yaml from "js-yaml"
1415
import { rimraf, rimrafSync } from "rimraf"
1516

1617
const artifactRegex = /.*\.(?:exe|dmg|AppImage|zip)$/
@@ -233,20 +234,14 @@ const config: ForgeConfig = {
233234
return result
234235
})
235236
yml.releaseDate = new Date().toISOString()
236-
const ymlStr =
237-
`version: ${yml.version}\n` +
238-
`files:\n${yml.files
239-
.map(
240-
(file) =>
241-
` - url: ${file.url}\n` +
242-
` sha512: ${file.sha512}\n` +
243-
` size: ${file.size}\n`,
244-
)
245-
.join("")}releaseDate: ${yml.releaseDate}\n`
246237

247238
const ymlPath = `${path.dirname(makeResults[0].artifacts[0])}/${
248239
ymlMapsMap[makeResults[0].platform]
249240
}`
241+
242+
const ymlStr = yaml.dump(yml, {
243+
lineWidth: -1,
244+
})
250245
fs.writeFileSync(ymlPath, ymlStr)
251246

252247
makeResults.push({

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"scripts": {
1717
"analyze:web": "npx vite-bundle-visualizer",
1818
"build": "electron-vite build && electron-forge make",
19-
"build:macos": "electron-vite build && electron-forge make --arch=universal --platform=darwin",
19+
"build:macos": "electron-vite build && electron-forge make --arch=x64 --platform=darwin && electron-forge make --arch=arm64 --platform=darwin && tsx scripts/merge-yml.ts",
2020
"build:web": "rm -rf out/web && vite build",
2121
"bump": "vv",
2222
"dedupe:locales": "eslint --fix locales/**/*.json",
@@ -84,6 +84,7 @@
8484
"fake-indexeddb": "6.0.0",
8585
"happy-dom": "15.8.0",
8686
"hono": "4.6.8",
87+
"js-yaml": "4.1.0",
8788
"lint-staged": "15.2.10",
8889
"nbump": "2.0.7",
8990
"postcss": "8.4.47",

pnpm-lock.yaml

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

scripts/merge-yml.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import fs from "node:fs"
2+
import path from "node:path"
3+
4+
import yaml from "js-yaml"
5+
6+
const outDir = "./out/make"
7+
8+
function findYmlFiles(dir: string): string[] {
9+
let results: string[] = []
10+
const items = fs.readdirSync(dir)
11+
12+
items.forEach((item) => {
13+
const fullPath = path.join(dir, item)
14+
if (fs.statSync(fullPath).isDirectory()) {
15+
results = results.concat(findYmlFiles(fullPath))
16+
} else if (item.endsWith(".yml")) {
17+
results.push(fullPath)
18+
}
19+
})
20+
21+
return results
22+
}
23+
24+
const ymlFiles = findYmlFiles(outDir)
25+
26+
let mergedContent = {
27+
version: "",
28+
files: [],
29+
releaseDate: "",
30+
}
31+
32+
ymlFiles.forEach((file) => {
33+
const fileContent = fs.readFileSync(file, "utf8")
34+
const ymlData = yaml.load(fileContent)
35+
36+
if (!mergedContent.version) {
37+
mergedContent.version = ymlData.version
38+
}
39+
40+
mergedContent = {
41+
version: ymlData.version,
42+
files: mergedContent.files.concat(ymlData.files),
43+
releaseDate: ymlData.releaseDate,
44+
}
45+
})
46+
47+
const mergedYml = yaml.dump(mergedContent, {
48+
lineWidth: -1,
49+
})
50+
fs.mkdirSync(path.join(outDir, "merged"), { recursive: true })
51+
const mergedFilePath = path.join(outDir, "merged", path.basename(ymlFiles[0]))
52+
fs.writeFileSync(mergedFilePath, mergedYml)
53+
54+
ymlFiles.forEach((file) => {
55+
fs.unlinkSync(file)
56+
})

0 commit comments

Comments
 (0)