-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat(client): client/src/cordova/dev action #2111
Merged
Merged
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
41177cc
feat(client): reload UI on www source change
daniellacosse c27a2bc
it works!@
daniellacosse 6dc18dc
linting issues
daniellacosse def9c6b
switch to client/src/cordova/dev
daniellacosse 400fae9
specify xcodebuild output and reload based on that
daniellacosse 6b08495
lil TODO
daniellacosse 2f19bd1
clean up package lock
daniellacosse 477e003
Merge branch 'master' into daniellacosse/ui_reload
daniellacosse 6c4626d
Merge branch 'master' into daniellacosse/ui_reload
daniellacosse 37a29fa
[BROKEN] break out makeReplacements
daniellacosse 85665ff
fix makeReplacement args
daniellacosse 1433080
changes
daniellacosse 9ee568d
Merge branch 'master' into daniellacosse/ui_reload
daniellacosse 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
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 |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright 2022 The Outline Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import path from 'path'; | ||
import url from 'url'; | ||
|
||
import {createReloadServer} from '@outline/infrastructure/build/create_reload_server.mjs'; | ||
import {getRootDir} from '@outline/infrastructure/build/get_root_dir.mjs'; | ||
import {runAction} from '@outline/infrastructure/build/run_action.mjs'; | ||
import cordovaLib from 'cordova-lib'; | ||
import {hashElement} from 'folder-hash'; | ||
import * as fs from 'fs-extra'; | ||
const {cordova} = cordovaLib; | ||
|
||
import {getBuildParameters} from '../../build/get_build_parameters.mjs'; | ||
|
||
const getUIHash = async () => { | ||
const hashResult = await hashElement( | ||
path.join(getRootDir(), 'client/src/www'), | ||
{ | ||
files: {include: ['**/*.ts', '**/*.html', '**/*.css', '**/*.js']}, | ||
} | ||
); | ||
|
||
return hashResult.hash; | ||
}; | ||
|
||
/** | ||
* @description Builds the parameterized cordova binary (ios, macos, maccatalyst, android). | ||
* | ||
* @param {string[]} parameters | ||
*/ | ||
export async function main(...parameters) { | ||
const {platform, verbose} = getBuildParameters(parameters); | ||
|
||
if (platform !== 'macos') { | ||
throw new Error('Only macos platform is currently supported'); | ||
} | ||
|
||
await runAction('client/src/www/build', ...parameters); | ||
await runAction('client/go/build', ...parameters); | ||
await runAction('client/src/cordova/setup', ...parameters); | ||
|
||
if (verbose) { | ||
cordova.on('verbose', message => | ||
console.debug(`[cordova:verbose] ${message}`) | ||
); | ||
} | ||
|
||
let previousUIHashResult = await getUIHash(); | ||
|
||
console.log('Starting reload server @ port 35729...'); | ||
createReloadServer(async () => { | ||
const currentUIHashResult = await getUIHash(); | ||
|
||
if (previousUIHashResult === currentUIHashResult) { | ||
return false; | ||
} | ||
|
||
previousUIHashResult = currentUIHashResult; | ||
|
||
await runAction('client/src/www/build', ...parameters); | ||
|
||
await fs.copy( | ||
path.join(getRootDir(), 'client/www'), | ||
// TODO: find way to programmatically get this path | ||
'/Users/daniellacosse/Library/Developer/Xcode/DerivedData/macos-XXXXXXX/Build/Products/Debug/Outline.app/Contents/Resources/www' | ||
); | ||
|
||
return true; | ||
}).listen(35729); | ||
} | ||
|
||
if (import.meta.url === url.pathToFileURL(process.argv[1]).href) { | ||
await main(...process.argv.slice(2)); | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2024 The Outline Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import {createServer} from 'node:http'; | ||
|
||
import {WebSocketServer} from 'ws'; | ||
|
||
export function createReloadServer( | ||
shouldReload = () => true, | ||
reloadCheckIntervalMs = 1000 | ||
) { | ||
const server = createServer(); | ||
const websocket = new WebSocketServer({server}); | ||
|
||
websocket.on('connection', connection => { | ||
setInterval(async () => { | ||
if (!(await shouldReload())) return; | ||
|
||
console.log('Reloading...'); | ||
connection.send('reload'); | ||
}, reloadCheckIntervalMs); | ||
}); | ||
|
||
return server; | ||
} |
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
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.
Unfortunately I can't inject this in debug mode because that mode doesn't work on MacOS.
@fortuna are there security concerns with this?
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.
If it's a problem, I can try injecting this script tag in the action after
cordova/src/www/build
is run! Maybe with jsdom?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.
Could you use a separate
index_cordova.dev.html
file and use that in the cordova setup usingmakeReplacements()
?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.
So creating a separate file would mean i'd have to breakout a whole other webpack config/build workflow so instead i opted to just call
makeReplacements()
on theindex_cordova.html
output by the webpack process. PTAL.