-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathforge.config.ts
More file actions
143 lines (129 loc) · 5.37 KB
/
forge.config.ts
File metadata and controls
143 lines (129 loc) · 5.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import type { ForgeConfig } from '@electron-forge/shared-types'
import { VitePlugin } from '@electron-forge/plugin-vite'
import { FusesPlugin } from '@electron-forge/plugin-fuses'
import { FuseV1Options, FuseVersion } from '@electron/fuses'
import path from 'path'
import fs from 'fs'
import { fileURLToPath } from 'node:url'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const collectNativeNodeFiles = (dir: string): string[] => {
if (!fs.existsSync(dir)) return []
const entries = fs.readdirSync(dir, { withFileTypes: true })
const files: string[] = []
for (const entry of entries) {
const fullPath = path.join(dir, entry.name)
if (entry.isDirectory()) {
files.push(...collectNativeNodeFiles(fullPath))
continue
}
if (entry.isFile() && path.extname(entry.name).toLowerCase() === '.node') {
files.push(fullPath)
}
}
return files
}
const copyNativeModules = (resourcesPath: string): void => {
const nativeModulesRoot = path.resolve(__dirname, 'nativeModules')
const modulesDestination = path.join(resourcesPath, 'modules')
if (!fs.existsSync(nativeModulesRoot)) return
fs.mkdirSync(modulesDestination, { recursive: true })
for (const addonName of fs.readdirSync(nativeModulesRoot)) {
const addonPath = path.join(nativeModulesRoot, addonName)
if (!fs.statSync(addonPath).isDirectory()) continue
const nodeFiles = collectNativeNodeFiles(addonPath)
if (nodeFiles.length === 0) continue
const addonDestination = path.join(modulesDestination, addonName)
fs.mkdirSync(addonDestination, { recursive: true })
for (const nodeFile of nodeFiles) {
fs.copyFileSync(nodeFile, path.join(addonDestination, path.basename(nodeFile)))
}
}
}
const forgeConfig: ForgeConfig = {
packagerConfig: {
icon: process.platform === 'linux' ? './icons/icon.png' : './icons/icon',
name: 'PulseSync',
executableName: process.platform === 'linux' ? 'pulsesync' : 'PulseSync',
appCopyright: `Copyright (C) ${new Date().getFullYear()} ИП «Деднев Григорий Дмитриевич»`,
asar: {
unpack: '**/.vite/renderer/**/static/assets/icon/**',
},
win32metadata: {
CompanyName: 'ИП «Деднев Григорий Дмитриевич»',
},
appBundleId: 'pulsesync.app',
extendInfo: 'Info.plist',
extraResource: ['./app-update.yml'],
},
rebuildConfig: {
ignoreModules: ['@parcel/watcher', 'bufferutil', 'utf-8-validate'],
},
plugins: [
new VitePlugin({
build: [
{
entry: 'src/index.ts',
config: 'vite.main.config.ts',
},
{
entry: 'src/main/mainWindowPreload.ts',
config: 'vite.preload.config.ts',
target: 'preload',
},
],
renderer: [
{
name: 'preloader',
config: 'vite.renderer.config.ts',
},
{
name: 'main_window',
config: 'vite.renderer.config.ts',
},
],
}),
new FusesPlugin({
version: FuseVersion.V1,
[FuseV1Options.RunAsNode]: true,
[FuseV1Options.EnableEmbeddedAsarIntegrityValidation]: true,
[FuseV1Options.EnableCookieEncryption]: true,
[FuseV1Options.OnlyLoadAppFromAsar]: true,
[FuseV1Options.EnableNodeCliInspectArguments]: true,
}),
],
hooks: {
packageAfterPrune: async (_forgeConfig, buildPath) => {
const packageJsonPath = path.resolve(buildPath, 'package.json')
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
Object.keys(pkg).forEach(key => {
switch (key) {
case 'name':
case 'version':
case 'main':
case 'author':
case 'devDependencies':
case 'homepage':
case 'buildInfo':
break
default:
delete pkg[key]
}
})
fs.writeFileSync(packageJsonPath, JSON.stringify(pkg, null, '\t'))
},
packageAfterCopy: async (_forgeConfig, buildPath, electronVersion, platform, arch) => {
const resourcesPath = path.resolve(buildPath, '..')
const iconSource = path.resolve(__dirname, 'static', 'assets', 'icon')
const iconDestination = path.join(resourcesPath, 'assets', 'icon')
fs.mkdirSync(iconDestination, { recursive: true })
fs.cpSync(iconSource, iconDestination, { recursive: true })
const pextIconSource = path.resolve(__dirname, 'icons', 'pext')
const pextIconDestination = path.join(resourcesPath, 'assets', 'pext')
fs.mkdirSync(pextIconDestination, { recursive: true })
fs.cpSync(pextIconSource, pextIconDestination, { recursive: true })
copyNativeModules(resourcesPath)
console.log(`Built app ${platform}-${arch} with Electron ${electronVersion}`)
},
},
}
export default forgeConfig