diff --git a/app-vite/lib/utils/open-ide.js b/app-vite/lib/utils/open-ide.js index 09e994613bd..ef0bc89c623 100644 --- a/app-vite/lib/utils/open-ide.js +++ b/app-vite/lib/utils/open-ide.js @@ -148,7 +148,7 @@ function runWindows (mode, bin, target, appPaths) { export function openIDE ({ mode, bin, target, dev, appPaths }) { 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.') diff --git a/app-webpack/lib/cmd/build.js b/app-webpack/lib/cmd/build.js index eaef991c76d..b4b35d75205 100755 --- a/app-webpack/lib/cmd/build.js +++ b/app-webpack/lib/cmd/build.js @@ -159,7 +159,12 @@ async function runBuild () { console.error(err) fatal('App build failed (check the log above)', 'FAIL') }) - .then(async () => { + .then(async signal => { + if (signal !== void 0) { + const { SIGNAL__BUILD_SHOULD_EXIT } = await import('../utils/signals.js') + if (signal === SIGNAL__BUILD_SHOULD_EXIT) return + } + outputFolder = argv.mode === 'cordova' ? path.join(outputFolder, '..') : outputFolder diff --git a/app-webpack/lib/modes/capacitor/capacitor-builder.js b/app-webpack/lib/modes/capacitor/capacitor-builder.js index 043980c57d6..8e03b66804b 100644 --- a/app-webpack/lib/modes/capacitor/capacitor-builder.js +++ b/app-webpack/lib/modes/capacitor/capacitor-builder.js @@ -10,6 +10,7 @@ const { spawn, spawnSync } = require('../../utils/spawn.js') const { openIDE } = require('../../utils/open-ide.js') const { onShutdown } = require('../../utils/on-shutdown.js') const { fixAndroidCleartext } = require('../../utils/fix-android-cleartext.js') +const { SIGNAL__BUILD_SHOULD_EXIT } = require('../../utils/signals.js') module.exports.QuasarModeBuilder = class QuasarModeBuilder extends AppBuilder { #capacitorConfigFile = new CapacitorConfigFile() @@ -19,7 +20,7 @@ module.exports.QuasarModeBuilder = class QuasarModeBuilder extends AppBuilder { this.#packagedDir = join(this.quasarConf.build.distDir, this.ctx.targetName) await this.#buildFiles() - await this.#packageFiles() + return this.#packageFiles() } async #buildFiles () { @@ -58,7 +59,7 @@ module.exports.QuasarModeBuilder = class QuasarModeBuilder extends AppBuilder { appPaths }) - process.exit(0) + return SIGNAL__BUILD_SHOULD_EXIT } if (target === 'ios') { diff --git a/app-webpack/lib/modes/cordova/cordova-builder.js b/app-webpack/lib/modes/cordova/cordova-builder.js index 80e9f9c7a46..eb8b70338d3 100644 --- a/app-webpack/lib/modes/cordova/cordova-builder.js +++ b/app-webpack/lib/modes/cordova/cordova-builder.js @@ -10,6 +10,7 @@ const { spawn } = require('../../utils/spawn.js') const { openIDE } = require('../../utils/open-ide.js') const { onShutdown } = require('../../utils/on-shutdown.js') const { fixAndroidCleartext } = require('../../utils/fix-android-cleartext.js') +const { SIGNAL__BUILD_SHOULD_EXIT } = require('../../utils/signals.js') const cordovaOutputFolders = { ios: [ @@ -35,7 +36,7 @@ module.exports.QuasarModeBuilder = class QuasarModeBuilder extends AppBuilder { async build () { await this.#buildFiles() - await this.#packageFiles() + return this.#packageFiles() } async #buildFiles () { @@ -95,7 +96,8 @@ module.exports.QuasarModeBuilder = class QuasarModeBuilder extends AppBuilder { target, appPaths }) - process.exit(0) + + return SIGNAL__BUILD_SHOULD_EXIT } const targetFolder = join(this.quasarConf.build.distDir, this.quasarConf.ctx.targetName) diff --git a/app-webpack/lib/utils/open-ide.js b/app-webpack/lib/utils/open-ide.js index df7ed8262aa..f26e2d14ecf 100644 --- a/app-webpack/lib/utils/open-ide.js +++ b/app-webpack/lib/utils/open-ide.js @@ -22,20 +22,19 @@ function runMacOS ({ mode, target, appPaths, open }) { ? 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) { @@ -67,12 +66,10 @@ function runLinux ({ mode, bin, target, appPaths, open }) { ? appPaths.resolve.cordova('platforms/android') : appPaths.resolve.capacitor('android') - open(folder, { + return open(folder, { app: { name: studioPath }, wait: false }) - - return } } else if (target === 'ios') { @@ -120,16 +117,18 @@ function runWindows ({ mode, bin, target, appPaths, open }) { ? appPaths.resolve.cordova('platforms/android') : appPaths.resolve.capacitor('android') - open(folder, { + /** + * On Windows, after calling the below function, the Node.js process + * should NOT exit by calling process.exit(_any_code_) under any form, otherwise the + * IDE will not get a chance to be opened. + * + * However, if process.exit() must still be called, a significant delay + * (30-60 seconds, the more the better) is needed before calling it. + */ + 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') { @@ -145,7 +144,7 @@ function runWindows ({ mode, bin, target, appPaths, open }) { module.exports.openIDE = async function openIDE ({ mode, bin, target, dev, appPaths }) { 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.') diff --git a/app-webpack/lib/utils/signals.js b/app-webpack/lib/utils/signals.js new file mode 100644 index 00000000000..faa2e1adfab --- /dev/null +++ b/app-webpack/lib/utils/signals.js @@ -0,0 +1 @@ +module.exports.SIGNAL__BUILD_SHOULD_EXIT = 'SIGNAL__BUILD_SHOULD_EXIT'