-
-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build with obfuscated bundles #106
Open
simonhamp
wants to merge
16
commits into
main
Choose a base branch
from
feature/build-with-obfuscated-bundle
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
44473fe
Check for bundle and build if exists
simonhamp 42ce4b6
Fix app name setting in the package.json
simonhamp 2646655
Copy the installer icon
simonhamp a48d16a
Fix styling
simonhamp 1f429ea
Update to latest binaries
simonhamp 7daf9fd
Fix bundle copy
simonhamp 9a02339
Merge branch 'main' into feature/build-with-obfuscated-bundle
simonhamp 8b0e43d
Restore changes from other PR
simonhamp aeee3fe
Merge branch 'main' into feature/build-with-obfuscated-bundle
simonhamp 0938806
Move trait
simonhamp ecde43e
Add env file processing in build step
simonhamp 461acb3
Fix styling
simonhamp bd9419e
Don't copy builds, logs or caches
simonhamp eccd3b9
Merge branch 'main' into feature/build-with-obfuscated-bundle
simonhamp 3f5996d
Clear the view cache on boot
simonhamp 3e47d81
Merge branch 'main' into feature/build-with-obfuscated-bundle
simonhamp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,12 +33,8 @@ 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); | ||
|
@@ -47,6 +43,8 @@ try { | |
} | ||
|
||
if (isBuilding) { | ||
console.log("Current platform: ", process.platform) | ||
console.log("Current arch: ", process.arch) | ||
|
||
console.log(); | ||
console.log('==================================================================='); | ||
|
@@ -61,53 +59,69 @@ if (isBuilding) { | |
|
||
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); | ||
let bundle = join(process.env.APP_PATH, 'build', '__nativephp_app_bundle'); | ||
|
||
if (existsSync(bundle)) { | ||
copySync(bundle, join(appPath, 'bundle', '__nativephp_app_bundle')); | ||
} else { | ||
// 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')); | ||
|
||
console.warn('====================='); | ||
console.warn('* * * INSECURE BUILD * * *'); | ||
console.warn('Secure app bundle not found! Building with exposed source files.'); | ||
console.warn('See https://nativephp.com/docs/publishing/building#security for more details'); | ||
console.warn('====================='); | ||
|
||
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'), | ||
join(process.env.APP_PATH, 'build'), | ||
|
||
join(process.env.APP_PATH, 'storage', 'framework'), | ||
join(process.env.APP_PATH, 'storage', 'logs'), | ||
]; | ||
|
||
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'), {}) | ||
Comment on lines
+116
to
+121
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's better to use |
||
|
||
removeSync(tmpDir); | ||
} | ||
|
||
console.log(); | ||
console.log('Copied app to resources'); | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
existsSync
is not imported