Skip to content

Commit

Permalink
fix(app-vite): (backport from q/app-vite v2 beta) Capacitor/Cordova o…
Browse files Browse the repository at this point in the history
…n Windows host -> Android Studio not being launched when running "quasar build -m capacitor -T android --ide" #17420
  • Loading branch information
rstoenescu committed Aug 7, 2024
1 parent d51ad03 commit 744bbc2
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 27 deletions.
7 changes: 6 additions & 1 deletion app-vite/lib/cmd/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,14 @@ async function build () {
console.error(err)
fatal('App build failed (check the log above)', 'FAIL')
})
.then(async () => {
.then(async signal => {
artifacts.add(outputFolder)

if (signal !== void 0) {
const { SIGNAL__BUILD_SHOULD_EXIT } = await import('../helpers/signals.js')
if (signal === SIGNAL__BUILD_SHOULD_EXIT) return
}

outputFolder = argv.mode === 'cordova'
? path.join(outputFolder, '..')
: outputFolder
Expand Down
37 changes: 15 additions & 22 deletions app-vite/lib/helpers/open-ide.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,19 @@ function runMacOS (mode, target) {
? appPaths.resolve.cordova('platforms/ios')
: appPaths.resolve.capacitor('ios/App')

open(findXcodeWorkspace(folder), {
return open(findXcodeWorkspace(folder), {
wait: false
})
}
else {
const folder = mode === 'cordova'
? appPaths.resolve.cordova('platforms/android')
: appPaths.resolve.capacitor('android')

open(folder, {
app: { name: 'android studio' },
wait: false
})
}
const folder = mode === 'cordova'
? appPaths.resolve.cordova('platforms/android')
: appPaths.resolve.capacitor('android')

return open(folder, {
app: { name: 'android studio' },
wait: false
})
}

function getLinuxPath (bin) {
Expand Down Expand Up @@ -69,12 +68,10 @@ function runLinux (mode, bin, target) {
? appPaths.resolve.cordova('platforms/android')
: appPaths.resolve.capacitor('android')

open(folder, {
return open(folder, {
app: { name: studioPath },
wait: false
})

return
}
}
else if (target === 'ios') {
Expand Down Expand Up @@ -122,16 +119,10 @@ function runWindows (mode, bin, target) {
? appPaths.resolve.cordova('platforms/android')
: appPaths.resolve.capacitor('android')

open(folder, {
return open(folder, {
app: { name: studioPath },
wait: false
})

// pause required, otherwise Windows fails
// to open the process
return new Promise(resolve => {
setTimeout(resolve, 300)
})
}
}
else if (target === 'ios') {
Expand All @@ -144,10 +135,12 @@ function runWindows (mode, bin, target) {
process.exit(1)
}

module.exports = function (mode, bin, target, dev) {
// openIde() returns the result of an open() call (which is a Promise)
// so this function should be treated as async
module.exports = function openIde (mode, bin, target, dev) {
console.log()
console.log(' ⚠️ ')
console.log(` ⚠️ Opening ${ target === 'ios' ? 'XCode' : 'Android Studio' } IDE...`)
console.log(` ⚠️ Opening ${ target === 'ios' ? 'XCode' : 'Android Studio' } IDE. It might take a few seconds...`)

if (dev) {
console.log(' ⚠️ From there, use the IDE to run the app.')
Expand Down
1 change: 1 addition & 0 deletions app-vite/lib/helpers/signals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports.SIGNAL__BUILD_SHOULD_EXIT = 'SIGNAL__BUILD_SHOULD_EXIT'
5 changes: 3 additions & 2 deletions app-vite/lib/modes/capacitor/capacitor-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const CapacitorConfigFile = require('./config-file')
const { spawn, spawnSync } = require('../../helpers/spawn')
const openIde = require('../../helpers/open-ide')
const onShutdown = require('../../helpers/on-shutdown')
const { SIGNAL__BUILD_SHOULD_EXIT } = require('../../helpers/signals.js')

const { capBin } = require('./cap-cli')

Expand All @@ -21,7 +22,7 @@ class CapacitorBuilder extends AppBuilder {
this.#packagedDir = join(this.quasarConf.build.distDir, this.quasarConf.ctx.targetName)

await this.#buildFiles()
await this.#packageFiles()
return this.#packageFiles()
}

async #buildFiles () {
Expand All @@ -48,7 +49,7 @@ class CapacitorBuilder extends AppBuilder {
if (this.argv[ 'skip-pkg' ] !== true) {
if (this.argv.ide === true) {
await openIde('capacitor', this.quasarConf.bin, target)
process.exit(0)
return SIGNAL__BUILD_SHOULD_EXIT
}

if (target === 'ios') {
Expand Down
5 changes: 3 additions & 2 deletions app-vite/lib/modes/cordova/cordova-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const CordovaConfigFile = require('./config-file')
const { spawn } = require('../../helpers/spawn')
const openIde = require('../../helpers/open-ide')
const onShutdown = require('../../helpers/on-shutdown')
const { SIGNAL__BUILD_SHOULD_EXIT } = require('../../helpers/signals.js')

const cordovaOutputFolders = {
ios: [
Expand All @@ -36,7 +37,7 @@ class CapacitorBuilder extends AppBuilder {

async build () {
await this.#buildFiles()
await this.#packageFiles()
return this.#packageFiles()
}

async #buildFiles () {
Expand Down Expand Up @@ -109,7 +110,7 @@ class CapacitorBuilder extends AppBuilder {
if (this.argv[ 'skip-pkg' ] !== true) {
if (this.argv.ide) {
await openIde('cordova', this.quasarConf.bin, target)
process.exit(0)
return SIGNAL__BUILD_SHOULD_EXIT
}

const targetFolder = join(this.quasarConf.build.distDir, this.quasarConf.ctx.targetName)
Expand Down

0 comments on commit 744bbc2

Please sign in to comment.