-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathforge.config.js
More file actions
160 lines (141 loc) · 4.52 KB
/
forge.config.js
File metadata and controls
160 lines (141 loc) · 4.52 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import { readdirSync, existsSync } from 'fs';
import { join } from 'path';
// @electron/rebuild's dep walker doesn't reach transitive native modules.
// Scan node_modules for all packages with binding.gyp so they get rebuilt for Electron's ABI.
function findNativeModules(dir = 'node_modules', prefix = '') {
const result = [];
for (const entry of readdirSync(dir)) {
if (entry.startsWith('.')) continue;
const fullPath = join(dir, entry);
if (entry.startsWith('@')) {
result.push(...findNativeModules(fullPath, entry + '/'));
} else if (existsSync(join(fullPath, 'binding.gyp'))) {
result.push(prefix + entry);
}
}
return result;
}
export default {
packagerConfig: {
name: 'plebones',
executableName: 'plebones',
appBundleId: 'plebones.desktop',
// Unpack native modules and kubo binary from ASAR so they can be executed
asar: {
unpack: '{*.node,*.dll,*.dylib,*.so,**/kubo/kubo/**}'
},
// Exclude unnecessary files
ignore: [
/^\/src$/,
/^\/android$/,
/^\/public$/,
/^\/config$/,
/^\/\.plebbit$/,
/^\/dist$/,
/^\/bin$/,
/^\/out$/,
/^\/squashfs-root$/,
/^\/original-assets$/,
/^\/scripts$/,
/\.map$/,
/\.md$/,
/\.git/,
/\.ts$/,
/\.test\.js$/,
/\.spec\.js$/,
/tsconfig\.json$/,
/\.eslintrc/,
/\.prettierrc/,
/CHANGELOG/
]
},
rebuildConfig: {
force: true,
extraModules: findNativeModules()
},
hooks: {
postPackage: async (config, options) => {
const { execSync } = await import('child_process');
const globPkg = await import('glob');
const globSync = globPkg.sync || globPkg.default?.sync;
for (const result of options.outputPaths) {
// Strip .node files (native modules)
const nodeFiles = globSync('**/*.node', { cwd: result, absolute: true });
for (const file of nodeFiles) {
try {
execSync(`strip --strip-debug "${file}"`, { stdio: 'pipe' });
} catch (e) { /* ignore failures */ }
}
// Strip kubo binary (executable files without extensions)
const kuboFiles = globSync('**/kubo/kubo/**/!(*.*)' , { cwd: result, absolute: true });
for (const file of kuboFiles) {
try {
execSync(`strip --strip-debug "${file}"`, { stdio: 'pipe' });
} catch (e) { /* ignore failures */ }
}
}
},
postMake: async (config, makeResults) => {
// Only create HTML archive on Linux (to avoid duplicates across platforms)
if (process.platform !== 'linux') {
return makeResults;
}
const fs = await import('fs');
const fsPromises = await import('fs/promises');
const path = await import('path');
const { spawnSync } = await import('child_process');
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
const buildFolder = path.resolve('.', 'build');
const folderName = `plebones-html-${packageJson.version}`;
const tempFolder = path.resolve('.', 'out', 'make', folderName);
const outputFile = path.resolve('.', 'out', 'make', `${folderName}.zip`);
// Copy build folder to temp folder with correct name
await fsPromises.cp(buildFolder, tempFolder, { recursive: true });
// Create zip from parent directory so folder name is included
const result = spawnSync('zip', ['-r', `${folderName}.zip`, folderName], {
cwd: path.resolve('.', 'out', 'make'),
stdio: 'inherit'
});
// Clean up temp folder
await fsPromises.rm(tempFolder, { recursive: true });
if (result.status !== 0) {
throw new Error(`Failed to create HTML archive: zip exited with code ${result.status}`);
}
console.log(`Created HTML archive: ${outputFile}`);
return makeResults;
}
},
makers: [
// Windows
{
name: '@electron-forge/maker-squirrel',
platforms: ['win32'],
config: { name: 'plebones' }
},
{
name: '@electron-forge/maker-zip',
platforms: ['win32']
},
// macOS
{
name: '@electron-forge/maker-dmg',
platforms: ['darwin'],
config: { format: 'ULFO' }
},
{
name: '@electron-forge/maker-zip',
platforms: ['darwin']
},
// Linux
{
name: '@reforged/maker-appimage',
platforms: ['linux'],
config: {
options: {
categories: ['Network'],
genericName: 'Plebbit Client'
}
}
}
]
};