-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
forge.config.js
172 lines (152 loc) · 3.92 KB
/
forge.config.js
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
const path = require('node:path')
const fs = require('node:fs/promises')
const { glob } = require('glob')
const sharedLinuxMakersOptions = {
name: 'notion-enhanced',
productName: 'Notion Repackaged Enhanced',
description: 'The all-in-one workspace for your notes and tasks',
version: '1.0.0',
homepage: 'https://github.com/notion-enhancer/notion-linux',
categories: ['Utility', 'Office', 'Education', 'Development'],
mimeType: ['x-scheme-handler/notion'],
icon: 'icon.ico',
}
async function removeConflictingGypBins(buildPath) {
const gypPath = path.join(
buildPath,
'node_modules',
'better-sqlite3',
'build',
'node_gyp_bins',
)
console.log('Removing gyp path:', gypPath)
await fs.rm(gypPath, {
recursive: true,
force: true,
})
}
async function setEnhancerMainField(buildPath) {
const packageJsonPath = path.join(
buildPath,
'node_modules',
'notion-enhancer',
'package.json',
)
const originalPackageJsonString = await fs.readFile(packageJsonPath, 'utf-8')
const packageJson = JSON.parse(originalPackageJsonString)
packageJson.main = 'src/init.js'
const modifiedPackageJsonString = JSON.stringify(packageJson, null, 2)
await fs.writeFile(packageJsonPath, modifiedPackageJsonString)
}
async function patchFile(enhancerPatcher, buildPath, file) {
const filePath = path.join(buildPath, file)
const contents = await fs.readFile(filePath)
const patchedContents = enhancerPatcher(file, contents)
if (contents === patchedContents) {
return false
}
await fs.writeFile(filePath, patchedContents)
return true
}
async function patchAllFiles(buildPath) {
const { default: enhancerPatcher } = await import(
'notion-enhancer/scripts/patch-desktop-app.mjs'
)
console.log('Enhancer patcher:', enhancerPatcher)
const files = await glob('**/*.js', {
cwd: buildPath,
posix: true,
nodir: true,
dot: true,
absolute: false,
ignore: ['**/node_modules/**'],
})
console.log('Files to patch:', files)
await Promise.all(
files.map(async (file) => {
console.log('Trying to patch file:', file)
const fileModified = await patchFile(enhancerPatcher, buildPath, file)
if (fileModified) {
console.log('Patcher modified file:', file)
}
}),
)
}
async function enhanceSources(buildPath) {
console.log('Enhancing sources in:', buildPath)
await patchAllFiles(buildPath)
await setEnhancerMainField(buildPath)
}
module.exports = {
packagerConfig: {
asar: true,
prune: true,
icon: 'icon.ico',
extraResource: ['./extraResources/trayIcon.ico'],
protocols: [
{
name: 'notion',
schemes: ['notion'],
},
],
},
makers: [
{
name: '@electron-forge/maker-zip',
},
{
name: '@electron-forge/maker-dmg',
config: {
format: 'ULFO',
},
},
{
name: '@electron-forge/maker-deb',
config: {
options: {
maintainer: 'Notion Enhancer',
...sharedLinuxMakersOptions,
},
},
},
{
name: '@electron-forge/maker-rpm',
config: {
options: {
license: 'MIT',
...sharedLinuxMakersOptions,
},
},
},
{
name: '@electron-forge/maker-squirrel',
config: {},
},
],
plugins: [
{
name: '@electron-forge/plugin-auto-unpack-natives',
config: {},
},
],
publishers: [
{
name: '@electron-forge/publisher-github',
config: {
repository: {
owner: 'notion-enhancer',
name: 'notion-repackaged-internal',
},
prerelease: true,
},
},
],
hooks: {
packageAfterPrune: async (_forgeConfig, buildPath) => {
console.log('Running packageAfterPrune hook, currently in:', buildPath)
console.log('Directory contents:', await fs.readdir(buildPath))
await removeConflictingGypBins(buildPath)
await enhanceSources(buildPath)
},
},
}