Skip to content

Commit 53da359

Browse files
enhancement / address build command papercuts (#153)
* copy app to build path before cleanup & composer install * copied CleansEnvFile trait from upstream PR #106 Co-authored-by: Simon Hamp <[email protected]> * copied updated app icon path from upstream PR #106 Co-authored-by: Simon Hamp <[email protected]> * copied app name fix from upstream PR #106 Co-authored-by: Simon Hamp <[email protected]> * tidy * tidy * added skip patterns from electron-builder & account for symlinks (for symlinked composer deps) * add more default skip patterns * merge upstream * Build plugin * wip * remove redundant electron-builder app copy logic * move php building from separate step to beforePack hook * remove explicit php building from npm scripts * tidy * make sure database, logs, sessions & cached views are never included in builds! * use 8.1 compatible syntax * refactor to use symfony finder * move vendor/bin & node_modules exclude to config file (see PR nativephp/laravel) * fix ignore paths * ignore vsc files * revert back to using RecursiveDirectoryIterator * Fix styling * use npm ci for updating electron dependencies * update mac x86 comment * add PrunesVendorDirectory trait * move default exclude list to nativephp-internal config * Fix styling * add comments for file relocation when more adapters are added later on * decouple terminal messages from the build traits * decouple source path from build traits (for testing) * consolidate namespaces with identical purpose * bring back default exclude list to electron repo * fix regression * wip - tests * Fix styling * add more tests * Fix styling * more flexibility when working with paths * boyscouting * add filesystem stub directories to gitignore * add CleanEnvFile tests * Fix styling * add more tests * fix unclosed bracket * Fix styling * dependency compatibility for php 8.1 * use php 8.1 compatible syntax * fix - native config not loaded in CI * wip - fix CI inconsistencies * wip - typo * fix typo * Fix styling * fix - yet another mistake * use platform specific directory separators Co-authored-by: @SRWieZ * speed up tests & split by type Co-authored-by: @SRWieZ * Fix styling * move app name step down * remove mac x86 naming deviation * add workflow_run trigger (for debugging) * workflow dispatch instead of run * cover unhappy path * wip - fix test in CI * wip - add dumps to debug CI errors * disable flaky test (due to tight repo coupling) * wip - fix composer version conflict after upstream merge --------- Co-authored-by: Simon Hamp <[email protected]> Co-authored-by: gwleuverink <[email protected]>
1 parent d8537f5 commit 53da359

21 files changed

+992
-434
lines changed

.github/workflows/run-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: run-tests
22

33
on:
4+
workflow_dispatch:
45
push:
56
branches: [main]
67
pull_request:

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"laravel/prompts": "^0.1.1|^0.2|^0.3",
3737
"nativephp/laravel": "*",
3838
"nativephp/php-bin": "^0.5.1",
39-
"spatie/laravel-package-tools": "^1.16.4"
39+
"spatie/laravel-package-tools": "^1.16.4",
40+
"symfony/filesystem": "^6.4|^7.2"
4041
},
4142
"require-dev": {
4243
"laravel/pint": "^1.0",

resources/js/electron-builder.js

Lines changed: 20 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
import os from 'os';
21
import { join } from 'path';
3-
import { mkdtempSync } from 'fs';
2+
import { exec } from 'child_process';
43

5-
// Workaround for CommonJS module
6-
import fs_extra from 'fs-extra';
7-
const { copySync, removeSync, writeJsonSync } = fs_extra;
8-
9-
const isBuilding = process.env.NATIVEPHP_BUILDING;
4+
const appUrl = process.env.APP_URL;
105
const appId = process.env.NATIVEPHP_APP_ID;
116
const appName = process.env.NATIVEPHP_APP_NAME;
7+
const isBuilding = process.env.NATIVEPHP_BUILDING;
8+
const appAuthor = process.env.NATIVEPHP_APP_AUTHOR;
129
const fileName = process.env.NATIVEPHP_APP_FILENAME;
1310
const appVersion = process.env.NATIVEPHP_APP_VERSION;
14-
const appUrl = process.env.APP_URL;
15-
const appAuthor = process.env.NATIVEPHP_APP_AUTHOR;
1611
const deepLinkProtocol = process.env.NATIVEPHP_DEEPLINK_SCHEME;
1712

1813
// Since we do not copy the php executable here, we only need these for building
@@ -25,20 +20,18 @@ let targetOs;
2520
if (isWindows) {
2621
targetOs = 'win';
2722
}
23+
2824
if (isLinux) {
2925
targetOs = 'linux';
3026
}
31-
// Use of isDarwin
27+
3228
if (isDarwin) {
3329
targetOs = 'mac';
3430
}
3531

3632

3733
let updaterConfig = {};
3834

39-
// We wouldn't need these since its not representing the target platform
40-
console.log("Arch: ", process.arch)
41-
console.log("Platform: ", process.platform)
4235
try {
4336
updaterConfig = process.env.NATIVEPHP_UPDATER_CONFIG;
4437
updaterConfig = JSON.parse(updaterConfig);
@@ -47,82 +40,13 @@ try {
4740
}
4841

4942
if (isBuilding) {
50-
5143
console.log();
5244
console.log('===================================================================');
5345
console.log(' Building for ' + targetOs);
5446
console.log('===================================================================');
5547
console.log();
5648
console.log('Updater config', updaterConfig);
5749
console.log();
58-
59-
try {
60-
const appPath = join(import.meta.dirname, 'resources', 'app');
61-
62-
removeSync(appPath);
63-
64-
// As we can't copy into a subdirectory of ourself we need to copy to a temp directory
65-
let tmpDir = mkdtempSync(join(os.tmpdir(), 'nativephp'));
66-
67-
copySync(process.env.APP_PATH, tmpDir, {
68-
overwrite: true,
69-
dereference: true,
70-
filter: (src, dest) => {
71-
let skip = [
72-
// Skip .git and Dev directories
73-
join(process.env.APP_PATH, '.git'),
74-
join(process.env.APP_PATH, 'docker'),
75-
join(process.env.APP_PATH, 'packages'),
76-
77-
// Only needed for local testing
78-
join(process.env.APP_PATH, 'vendor', 'nativephp', 'electron', 'vendor'),
79-
join(process.env.APP_PATH, 'vendor', 'nativephp', 'laravel', 'vendor'),
80-
81-
join(process.env.APP_PATH, 'vendor', 'nativephp', 'php-bin'),
82-
join(process.env.APP_PATH, 'vendor', 'nativephp', 'electron', 'bin'),
83-
join(process.env.APP_PATH, 'vendor', 'nativephp', 'electron', 'resources'),
84-
join(process.env.APP_PATH, 'node_modules'),
85-
join(process.env.APP_PATH, 'dist'),
86-
];
87-
88-
let shouldSkip = false;
89-
skip.forEach((path) => {
90-
if (src.indexOf(path) === 0) {
91-
shouldSkip = true;
92-
}
93-
});
94-
95-
return !shouldSkip;
96-
}
97-
});
98-
99-
copySync(tmpDir, appPath);
100-
101-
// Electron build removes empty folders, so we have to create dummy files
102-
// dotfiles unfortunately don't work.
103-
writeJsonSync(join(appPath, 'storage', 'framework', 'cache', '_native.json'), {})
104-
writeJsonSync(join(appPath, 'storage', 'framework', 'sessions', '_native.json'), {})
105-
writeJsonSync(join(appPath, 'storage', 'framework', 'testing', '_native.json'), {})
106-
writeJsonSync(join(appPath, 'storage', 'framework', 'views', '_native.json'), {})
107-
writeJsonSync(join(appPath, 'storage', 'app', 'public', '_native.json'), {})
108-
writeJsonSync(join(appPath, 'storage', 'logs', '_native.json'), {})
109-
110-
removeSync(tmpDir);
111-
112-
console.log();
113-
console.log('Copied app to resources');
114-
console.log(join(process.env.APP_PATH, 'dist'));
115-
console.log();
116-
console.log('===================================================================');
117-
console.log(' Starting build...');
118-
console.log();
119-
} catch (e) {
120-
console.error();
121-
console.error('Error copying app into build environment');
122-
console.error(e);
123-
console.error();
124-
}
125-
12650
}
12751

12852
export default {
@@ -142,6 +66,20 @@ export default {
14266
asarUnpack: [
14367
'resources/**',
14468
],
69+
beforePack: async (context) => {
70+
let arch = {
71+
1: 'x64',
72+
3: 'arm64'
73+
}[context.arch];
74+
75+
if(arch === undefined) {
76+
console.error('Cannot build PHP for unsupported architecture');
77+
process.exit(1);
78+
}
79+
80+
console.log(` • building php binary - exec php.js --${targetOs} --${arch}`);
81+
exec(`node php.js --${targetOs} --${arch}`);
82+
},
14583
afterSign: 'build/notarize.js',
14684
win: {
14785
executableName: fileName,

0 commit comments

Comments
 (0)