-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathforge.config.js
More file actions
244 lines (226 loc) · 9.08 KB
/
Copy pathforge.config.js
File metadata and controls
244 lines (226 loc) · 9.08 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
const { FusesPlugin } = require('@electron-forge/plugin-fuses');
const { FuseV1Options, FuseVersion } = require('@electron/fuses');
const fs = require('fs');
const path = require('path');
// Sokuji localizes its product UI through i18next. Electron's locale packs
// only cover Chromium-native UI, which intentionally falls back to English.
// Windows/Linux use en-US.pak; macOS uses en.lproj.
const ELECTRON_LANGUAGES = new Set([
'en', 'en-US',
]);
function pruneElectronLocales(buildPath, platform) {
const isMac = platform === 'darwin';
const localesDir = isMac
? path.resolve(buildPath, '..')
: path.resolve(buildPath, '..', '..', 'locales');
const localeSuffix = isMac ? '.lproj' : '.pak';
if (!fs.existsSync(localesDir)) return;
for (const entry of fs.readdirSync(localesDir, { withFileTypes: true })) {
if (!entry.name.endsWith(localeSuffix)) continue;
const language = entry.name.slice(0, -localeSuffix.length);
if (!ELECTRON_LANGUAGES.has(language)) {
fs.rmSync(path.join(localesDir, entry.name), { recursive: true, force: true });
}
}
}
module.exports = {
packagerConfig: {
asar: true,
extraResource: ['assets', 'resources'],
icon: process.platform === 'win32' ? 'assets/icon.ico' : 'assets/icon',
appId: 'ai.kizunaai.sokuji',
executableName: 'sokuji',
name: 'Sokuji',
// Whitelist-based ignore: only include package.json, dist-electron/,
// build/ (minus wasm/), and node_modules/ (pruned by Forge).
// Everything else (src/, public/, model-packs/, extension/, etc.) is excluded.
ignore: (filePath) => {
// Root is always included
if (filePath === '') return false;
// Source maps are useful in local build output but not at runtime.
if (filePath.endsWith('.map')) return true;
// Allow runtime-essential top-level entries
if (filePath === '/package.json') return false;
if (filePath.startsWith('/dist-electron')) return false;
if (filePath.startsWith('/node_modules')) {
// Strip dev-only junk inside node_modules
if (/\/((@testing-library|jest|eslint|babel)[^/]*|@parcel\/watcher)(\/|$)/.test(filePath)) return true;
if (/\.(ts|flow|markdown)$/.test(filePath)) return true;
return false;
}
if (filePath.startsWith('/build')) {
// WASM runtime dirs are INCLUDED (workers need importScripts / wasmPaths):
// sherpa-onnx-asr, sherpa-onnx-asr-stream, sherpa-onnx-tts, ort, vad, piper-plus
// Model data dirs are EXCLUDED (downloaded at runtime via CDN + IndexedDB):
// sherpa-onnx-asr-sensevoice, opus-mt-*, sherpa-onnx-tts-piper-*, etc.
if (filePath.startsWith('/build/wasm')) {
// Must include the /build/wasm directory itself so its children are traversed
if (filePath === '/build/wasm') return false;
const wasmRuntimeDirs = [
'/build/wasm/sherpa-onnx-asr',
'/build/wasm/sherpa-onnx-asr-stream',
'/build/wasm/sherpa-onnx-tts',
'/build/wasm/ort',
'/build/wasm/vad',
'/build/wasm/piper-plus',
'/build/wasm/gtcrn',
];
// Keep runtime dirs and their contents, exclude everything else
if (wasmRuntimeDirs.some(dir => filePath === dir || filePath.startsWith(dir + '/'))) return false;
return true;
}
// Exclude debug assets
if (filePath.startsWith('/build/assets/test-tone') && filePath.endsWith('.mp3')) return true;
return false;
}
// Reject everything else
return true;
},
// Only include necessary files
prune: true,
// Reduce executable size by removing debug symbols
derefSymlinks: true,
// Overwrite files if they already exist
overwrite: true
},
rebuildConfig: {},
makers: [
{
name: '@electron-forge/maker-squirrel',
config: {
name: 'Sokuji',
authors: 'Kizuna AI Lab',
exe: 'sokuji.exe',
description: 'AI-powered live speech translation application',
setupIcon: 'assets/icon.ico',
iconUrl: 'https://raw.githubusercontent.com/kizuna-ai-lab/sokuji/main/assets/icon.ico',
noMsi: true
}
},
{
name: '@electron-forge/maker-dmg',
config: {
name: 'Sokuji',
overwrite: true
}
}
// PKG Installer removed - use npm run make:pkg for unsigned PKG builds
],
plugins: [
{
name: '@electron-forge/plugin-auto-unpack-natives',
config: {},
},
// Fuses are used to enable/disable various Electron functionality
// at package time, before code signing the application
new FusesPlugin({
version: FuseVersion.V1,
[FuseV1Options.RunAsNode]: false,
[FuseV1Options.EnableCookieEncryption]: true,
[FuseV1Options.EnableNodeOptionsEnvironmentVariable]: false,
[FuseV1Options.EnableNodeCliInspectArguments]: false,
[FuseV1Options.EnableEmbeddedAsarIntegrityValidation]: true,
[FuseV1Options.OnlyLoadAppFromAsar]: true,
}),
],
// Add hooks to further optimize the build
hooks: {
packageAfterCopy: async (_forgeConfig, buildPath, _electronVersion, platform) => {
pruneElectronLocales(buildPath, platform);
},
packageAfterPrune: async (forgeConfig, buildPath) => {
// List of directories to check and remove unnecessary files
const dirsToClean = [
path.join(buildPath, 'node_modules')
];
// Extensions and patterns of files to remove
const patternsToRemove = [
'.md', '.markdown', '.ts', '.map', '.flow', '.jst',
'LICENSE', 'license', 'LICENCE', 'licence',
'CONTRIBUTING', 'HISTORY', 'CHANGELOG',
'.travis.yml', '.github', '.eslintrc', '.editorconfig',
'Makefile', '.npmignore', '.gitignore', '.gitattributes',
'example', 'examples', 'test', 'tests', '__tests__',
'coverage', '.nyc_output', '.vscode', '.idea'
];
console.info('Cleaning unnecessary files from node_modules...');
// Function to recursively remove unnecessary files
const cleanDir = (dirPath) => {
if (!fs.existsSync(dirPath)) return;
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
for (const entry of entries) {
const fullPath = path.join(dirPath, entry.name);
if (entry.isDirectory()) {
// Skip essential directories
if (entry.name === 'node_modules' || entry.name === 'bin') {
cleanDir(fullPath);
continue;
}
// Check if directory name matches patterns to remove
if (patternsToRemove.some(pattern =>
entry.name === pattern ||
entry.name.endsWith(pattern)
)) {
try {
fs.rmSync(fullPath, { recursive: true, force: true });
console.debug(`Removed directory: ${fullPath}`);
} catch (err) {
console.error(`Error removing ${fullPath}:`, err);
}
} else {
cleanDir(fullPath);
}
} else if (entry.isFile()) {
// Check if file matches patterns to remove
if (patternsToRemove.some(pattern =>
entry.name === pattern ||
entry.name.endsWith(pattern)
)) {
try {
fs.unlinkSync(fullPath);
console.debug(`Removed file: ${fullPath}`);
} catch (err) {
console.error(`Error removing ${fullPath}:`, err);
}
}
}
}
};
// Clean each directory
for (const dir of dirsToClean) {
cleanDir(dir);
}
// Remove src/ directories from node_modules packages, but only when
// the package's "main" entry does NOT reference src/ (some packages
// like "debug" use src/ for runtime code)
const nmDir = path.join(buildPath, 'node_modules');
const removeSrcDirs = (dir) => {
if (!fs.existsSync(dir)) return;
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
const fullPath = path.join(dir, entry.name);
if (!entry.isDirectory()) continue;
if (entry.name.startsWith('@')) {
// Scoped package — recurse one level deeper
removeSrcDirs(fullPath);
continue;
}
const srcDir = path.join(fullPath, 'src');
if (!fs.existsSync(srcDir)) continue;
// Check if this package's main entry references src/
try {
const pkgJson = JSON.parse(fs.readFileSync(path.join(fullPath, 'package.json'), 'utf8'));
const main = pkgJson.main || 'index.js';
if (!main.includes('src/') && !main.includes('src\\')) {
fs.rmSync(srcDir, { recursive: true, force: true });
console.debug(`Removed src/ from: ${entry.name}`);
}
} catch {
// No package.json — skip
}
}
};
removeSrcDirs(nmDir);
console.info('Finished cleaning unnecessary files.');
}
}
};