Skip to content

Commit 6ec5f21

Browse files
committed
wip
1 parent 81ec1e9 commit 6ec5f21

File tree

5 files changed

+13258
-843
lines changed

5 files changed

+13258
-843
lines changed

resources/js/electron-builder.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
const {copySync, removeSync} = require("fs-extra");
1+
const {copySync, removeSync, writeJsonSync} = require("fs-extra");
22
const {join} = require("path");
3+
const os = require('os');
4+
const {mkdtempSync} = require("fs");
35
const {execSync} = require("child_process");
46
const isBuilding = process.env.NATIVEPHP_BUILDING == 1;
57
const appId = process.env.NATIVEPHP_APP_ID;
@@ -56,7 +58,10 @@ if (isBuilding) {
5658
let phpBinary = join(phpBinaryPath, (isArm64 ? 'arm64' : 'x86'), 'php');
5759
copySync(phpBinary, join(__dirname, 'resources', 'php'));
5860

59-
copySync(process.env.APP_PATH, join(__dirname, 'resources', 'app'), {
61+
// As we can't copy into a subdirectory of ourself we need to copy to a temp directory
62+
let tmpDir = mkdtempSync(join(os.tmpdir(), 'nativephp'));
63+
64+
copySync(process.env.APP_PATH, tmpDir, {
6065
overwrite: true,
6166
dereference: true,
6267
filter: (src, dest) => {
@@ -82,6 +87,20 @@ if (isBuilding) {
8287
return !shouldSkip;
8388
}
8489
});
90+
91+
copySync(tmpDir, join(__dirname, 'resources', 'app'));
92+
93+
// Electron build removes empty folders, so we have to create dummy files
94+
// dotfiles unfortunately don't work.
95+
writeJsonSync(join(__dirname, 'resources', 'app', 'storage', 'framework', 'cache', '_native.json'), {})
96+
writeJsonSync(join(__dirname, 'resources', 'app', 'storage', 'framework', 'sessions', '_native.json'), {})
97+
writeJsonSync(join(__dirname, 'resources', 'app', 'storage', 'framework', 'testing', '_native.json'), {})
98+
writeJsonSync(join(__dirname, 'resources', 'app', 'storage', 'framework', 'views', '_native.json'), {})
99+
writeJsonSync(join(__dirname, 'resources', 'app', 'storage', 'app', 'public', '_native.json'), {})
100+
writeJsonSync(join(__dirname, 'resources', 'app', 'storage', 'logs', '_native.json'), {})
101+
102+
removeSync(tmpDir);
103+
85104
console.log('=====================');
86105
console.log('Copied app to resources');
87106
console.log(join(process.env.APP_PATH, 'dist'));

0 commit comments

Comments
 (0)