-
-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathelectron-builder.js
190 lines (167 loc) · 6.55 KB
/
electron-builder.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
const {copySync, removeSync, writeJsonSync, existsSync} = require("fs-extra");
const {join} = require("path");
const os = require('os');
const {mkdtempSync} = require("fs");
const {execSync} = require("child_process");
const isBuilding = process.env.NATIVEPHP_BUILDING;
const appId = process.env.NATIVEPHP_APP_ID;
const appName = process.env.NATIVEPHP_APP_NAME;
const fileName = process.env.NATIVEPHP_APP_FILENAME;
const appVersion = process.env.NATIVEPHP_APP_VERSION;
const appUrl = process.env.APP_URL;
const appAuthor = process.env.NATIVEPHP_APP_AUTHOR;
const deepLinkProtocol = process.env.NATIVEPHP_DEEPLINK_SCHEME;
// Since we do not copy the php executable here, we only need these for building
const isWindows = process.argv.includes('--win');
const isLinux = process.argv.includes('--linux');
const isDarwin = process.argv.includes('--mac');
let targetOs;
if (isWindows) {
targetOs = 'win';
}
if (isLinux) {
targetOs = 'linux';
}
// Use of isDarwin
if (isDarwin) {
targetOs = 'mac';
}
let updaterConfig = {};
// We wouldn't need these since its not representing the target platform
console.log("Arch: ", process.arch)
console.log("Platform: ", process.platform)
try {
updaterConfig = process.env.NATIVEPHP_UPDATER_CONFIG;
updaterConfig = JSON.parse(updaterConfig);
} catch (e) {
updaterConfig = {};
}
if (isBuilding) {
console.log('=====================');
console.log('Building for ' + targetOs);
console.log('=====================');
console.log('updater config', updaterConfig);
console.log('=====================');
try {
const appPath = join(__dirname, 'resources', 'app');
removeSync(appPath);
// As we can't copy into a subdirectory of ourself we need to copy to a temp directory
let tmpDir = mkdtempSync(join(os.tmpdir(), 'nativephp'));
copySync(process.env.APP_PATH, tmpDir, {
overwrite: true,
dereference: true,
filter: (src, dest) => {
let skip = [
// Skip .git and Dev directories
join(process.env.APP_PATH, '.git'),
join(process.env.APP_PATH, 'docker'),
join(process.env.APP_PATH, 'packages'),
// Only needed for local testing
join(process.env.APP_PATH, 'vendor', 'nativephp', 'electron', 'vendor'),
join(process.env.APP_PATH, 'vendor', 'nativephp', 'laravel', 'vendor'),
join(process.env.APP_PATH, 'vendor', 'nativephp', 'php-bin'),
join(process.env.APP_PATH, 'vendor', 'nativephp', 'electron', 'bin'),
join(process.env.APP_PATH, 'vendor', 'nativephp', 'electron', 'resources'),
join(process.env.APP_PATH, 'node_modules'),
join(process.env.APP_PATH, 'dist'),
];
let shouldSkip = false;
skip.forEach((path) => {
if (src.indexOf(path) === 0) {
shouldSkip = true;
}
});
return !shouldSkip;
}
});
copySync(tmpDir, appPath);
// Electron build removes empty folders, so we have to create dummy files
// dotfiles unfortunately don't work.
writeJsonSync(join(appPath, 'storage', 'framework', 'cache', '_native.json'), {})
writeJsonSync(join(appPath, 'storage', 'framework', 'sessions', '_native.json'), {})
writeJsonSync(join(appPath, 'storage', 'framework', 'testing', '_native.json'), {})
writeJsonSync(join(appPath, 'storage', 'framework', 'views', '_native.json'), {})
writeJsonSync(join(appPath, 'storage', 'app', 'public', '_native.json'), {})
writeJsonSync(join(appPath, 'storage', 'logs', '_native.json'), {})
removeSync(tmpDir);
console.log('=====================');
console.log('Copied app to resources');
console.log(join(process.env.APP_PATH, 'dist'));
console.log('=====================');
const artisanPath = join(appPath, 'artisan');
// We'll use the default PATH PHP binary here, as we can cross-compile for all platforms. This shouldn't be changed.
execSync(`php ${artisanPath} native:minify ${appPath}`);
} catch (e) {
console.error('=====================');
console.error('Error copying app to resources');
console.error(e);
console.error('=====================');
}
}
module.exports = {
appId: appId,
productName: appName,
directories: {
buildResources: 'build',
output: isBuilding ? join(process.env.APP_PATH, 'dist') : undefined,
},
files: [
'!**/.vscode/*',
'!src/*',
'!electron.vite.config.{js,ts,mjs,cjs}',
'!{.eslintignore,.eslintrc.cjs,.prettierignore,.prettierrc.yaml,dev-app-update.yml,CHANGELOG.md,README.md}',
'!{.env,.env.*,.npmrc,pnpm-lock.yaml}',
],
asarUnpack: [
'resources/**',
],
afterSign: 'build/notarize.js',
win: {
executableName: fileName,
},
nsis: {
artifactName: appName + '-${version}-setup.${ext}',
shortcutName: '${productName}',
uninstallDisplayName: '${productName}',
createDesktopShortcut: 'always',
},
protocols: {
name: deepLinkProtocol,
schemes: [deepLinkProtocol],
},
mac: {
entitlementsInherit: 'build/entitlements.mac.plist',
artifactName: appName + '-${version}-${arch}.${ext}',
extendInfo: {
NSCameraUsageDescription:
"Application requests access to the device's camera.",
NSMicrophoneUsageDescription:
"Application requests access to the device's microphone.",
NSDocumentsFolderUsageDescription:
"Application requests access to the user's Documents folder.",
NSDownloadsFolderUsageDescription:
"Application requests access to the user's Downloads folder.",
NSScreenCaptureUsageDescription:
"Application requests access to the user's screen capture and system audio",
},
},
dmg: {
artifactName: appName + '-${version}-${arch}.${ext}',
},
linux: {
target: ['AppImage', 'deb'],
maintainer: appUrl,
category: 'Utility',
},
appImage: {
artifactName: appName + '-${version}.${ext}',
},
npmRebuild: false,
publish: updaterConfig,
extraMetadata: {
name: fileName,
homepage: appUrl,
version: appVersion,
author: appAuthor,
}
};