Skip to content

Commit

Permalink
feat(app-vite/app-webpack): (backport from q/app betas) add new optio…
Browse files Browse the repository at this point in the history
…ns for quasar.config file > cordova (getCordovaBuildParams & getCordovaBuildOutputFolder) #17138
  • Loading branch information
rstoenescu committed Apr 26, 2024
1 parent 3a415ad commit b12ee46
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 12 deletions.
32 changes: 26 additions & 6 deletions app-vite/lib/modes/cordova/cordova-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,25 @@ const { spawn } = require('../../helpers/spawn')
const openIde = require('../../helpers/open-ide')
const onShutdown = require('../../helpers/on-shutdown')

const cordovaOutputFiles = {
const cordovaOutputFolders = {
ios: [
'platforms/ios/build/Release-iphoneos', // ios-cordova 7+
'platforms/ios/build/device', // ios-cordova 6
'platforms/ios/build/emulator' // ios-cordova 6
'platforms/ios/build/Debug-iphoneos', // ios-cordova 7+
'platforms/ios/build/Release-iphonesimulator', // ios-cordova 7+
'platforms/ios/build/Debug-iphonesimulator', // ios-cordova 7+
'platforms/ios/build/device',
'platforms/ios/build/emulator'
],

android: [
'platforms/android/app/build/outputs'
]
}

function ensureArray (val) {
return (!val || Array.isArray(val)) ? val : [ val ]
}

class CapacitorBuilder extends AppBuilder {
#cordovaConfigFile = new CordovaConfigFile()

Expand Down Expand Up @@ -64,8 +71,18 @@ class CapacitorBuilder extends AppBuilder {
require('../../helpers/fix-android-cleartext')('cordova')
}

const cordovaContext = {
debug: this.ctx.debug === true,
target
}

const outputTargetList = (
ensureArray(this.quasarConf.cordova.getCordovaBuildOutputFolder?.(cordovaContext))
|| cordovaOutputFolders[ target ]
)

// Remove old build output
cordovaOutputFiles[ target ].forEach(outputFile => {
outputTargetList.forEach(outputFile => {
fse.removeSync(
appPaths.resolve.cordova(outputFile)
)
Expand All @@ -79,7 +96,10 @@ class CapacitorBuilder extends AppBuilder {

const args = this.argv[ 'skip-pkg' ] || this.argv.ide
? [ 'prepare', target ]
: [ 'build', this.ctx.debug ? '--debug' : '--release', '--device', target ]
: (
this.quasarConf.cordova.getCordovaBuildParams?.(cordovaContext)
|| [ 'build', this.ctx.debug ? '--debug' : '--release', '--device', target ]
)

await this.#runCordovaCommand(
args.concat(this.argv._),
Expand All @@ -94,7 +114,7 @@ class CapacitorBuilder extends AppBuilder {

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

for (const folder of cordovaOutputFiles[ target ]) {
for (const folder of outputTargetList) {
const outputFolder = appPaths.resolve.cordova(folder)
if (fse.existsSync(outputFolder)) {
log(`Copying Cordova distributables from ${ outputFolder } to ${ targetFolder }`)
Expand Down
46 changes: 46 additions & 0 deletions app-vite/types/configuration/cordova-conf.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,50 @@ export interface QuasarCordovaConfiguration {
* @default false
*/
noIosLegacyBuildFlag?: boolean;

/**
* Function to return the Cordova build command parameters that
* will be executed after the UI has compiled.
*
* @param context.debug - True if in debug mode
* @param context.target - The target platform (ios/android)
* @returns Array of strings (command parameters)
*
* @default: [ 'build', '--debug'/'--release', '--device', 'ios'/'android' ]
* @example: ({ isDebug, target }) => [ 'build', `--${isDebug ? 'debug' : 'release'}`, '--device', 'target' ]
*/
getCordovaBuildParams?: (context: { debug: boolean; target: 'ios' | 'android' }) => string[];

/**
* Function to return the Cordova output folder after the "cordova build"
* command is executed.
* The relative to /src-cordova path is used to copy the Cordova output
* to the /dist folder.
*
* @param context.debug - True if in debug mode
* @param context.target - The target platform (ios/android)
* @returns string | string[] | undefined - (relative path(s) from /src-cordova)
*
* @default ios: platforms/ios/build/... and android: platforms/android/app/build/outputs
* @example:
* ({ isDebug, target }) => {
* return target === 'ios'
* ? `platforms/ios/build/${isDebug ? 'Debug' : 'Release'}-iphoneos
* : 'platforms/android/app/build/outputs'
* }
* @example: (when interested in only one platform, leaving the other to the default value)
* ({ isDebug, target }) => {
* if (target === 'ios') {
* return `platforms/ios/build/${isDebug ? 'Debug' : 'Release'}-iphoneos`
* }
* }
* @example: ()
* ({ isDebug, target }) => {
* if (target === 'ios') {
* // try these two folders
* return [ 'platforms/ios/build/device', 'platforms/ios/build/emulator' ]
* }
* }
*/
getCordovaBuildOutputFolder?: (context: { debug: boolean; target: 'ios' | 'android' }) => string | string[] | undefined;
}
32 changes: 26 additions & 6 deletions app-webpack/lib/cordova/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,25 @@ const onShutdown = require('../helpers/on-shutdown')
const appPaths = require('../app-paths')
const openIde = require('../helpers/open-ide')

const cordovaOutputFiles = {
const cordovaOutputFolders = {
ios: [
'platforms/ios/build/Release-iphoneos', // ios-cordova 7+
'platforms/ios/build/device', // ios-cordova 6
'platforms/ios/build/emulator' // ios-cordova 6
'platforms/ios/build/Debug-iphoneos', // ios-cordova 7+
'platforms/ios/build/Release-iphonesimulator', // ios-cordova 7+
'platforms/ios/build/Debug-iphonesimulator', // ios-cordova 7+
'platforms/ios/build/device',
'platforms/ios/build/emulator'
],

android: [
'platforms/android/app/build/outputs'
]
}

function ensureArray (val) {
return (!val || Array.isArray(val)) ? val : [ val ]
}

class CordovaRunner {
constructor () {
this.pid = 0
Expand Down Expand Up @@ -77,16 +84,29 @@ class CordovaRunner {
async build (quasarConfFile, argv) {
const cfg = quasarConfFile.quasarConf

const cordovaContext = {
debug: this.ctx.debug === true,
target: this.target
}

const outputTargetList = (
ensureArray(this.quasarConf.cordova.getCordovaBuildOutputFolder?.(cordovaContext))
|| cordovaOutputFolders[ this.target ]
)

// Remove old build output
cordovaOutputFiles[ this.target ].forEach(outputFile => {
outputTargetList.forEach(outputFile => {
fse.removeSync(
appPaths.resolve.cordova(outputFile)
)
})

const args = argv[ 'skip-pkg' ] || argv.ide
? [ 'prepare', this.target ]
: [ 'build', this.ctx.debug ? '--debug' : '--release', '--device', this.target ]
: (
this.quasarConf.cordova.getCordovaBuildParams?.(cordovaContext)
|| [ 'build', this.ctx.debug ? '--debug' : '--release', '--device', this.target ]
)

await this.__runCordovaCommand(
cfg,
Expand All @@ -104,7 +124,7 @@ class CordovaRunner {

const targetFolder = cfg.build.packagedDistDir

for (const folder of cordovaOutputFiles[ this.target ]) {
for (const folder of outputTargetList) {
const outputFolder = appPaths.resolve.cordova(folder)
if (fse.existsSync(outputFolder)) {
log(`Copying Cordova distributables from ${ outputFolder } to ${ targetFolder }`)
Expand Down
46 changes: 46 additions & 0 deletions app-webpack/types/configuration/cordova-conf.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,50 @@ export interface QuasarCordovaConfiguration {
* @default false
*/
noIosLegacyBuildFlag?: boolean;

/**
* Function to return the Cordova build command parameters that
* will be executed after the UI has compiled.
*
* @param context.debug - True if in debug mode
* @param context.target - The target platform (ios/android)
* @returns Array of strings (command parameters)
*
* @default: [ 'build', '--debug'/'--release', '--device', 'ios'/'android' ]
* @example: ({ isDebug, target }) => [ 'build', `--${isDebug ? 'debug' : 'release'}`, '--device', 'target' ]
*/
getCordovaBuildParams?: (context: { debug: boolean; target: 'ios' | 'android' }) => string[];

/**
* Function to return the Cordova output folder after the "cordova build"
* command is executed.
* The relative to /src-cordova path is used to copy the Cordova output
* to the /dist folder.
*
* @param context.debug - True if in debug mode
* @param context.target - The target platform (ios/android)
* @returns string | string[] | undefined - (relative path(s) from /src-cordova)
*
* @default ios: platforms/ios/build/... and android: platforms/android/app/build/outputs
* @example:
* ({ isDebug, target }) => {
* return target === 'ios'
* ? `platforms/ios/build/${isDebug ? 'Debug' : 'Release'}-iphoneos
* : 'platforms/android/app/build/outputs'
* }
* @example: (when interested in only one platform, leaving the other to the default value)
* ({ isDebug, target }) => {
* if (target === 'ios') {
* return `platforms/ios/build/${isDebug ? 'Debug' : 'Release'}-iphoneos`
* }
* }
* @example: ()
* ({ isDebug, target }) => {
* if (target === 'ios') {
* // try these two folders
* return [ 'platforms/ios/build/device', 'platforms/ios/build/emulator' ]
* }
* }
*/
getCordovaBuildOutputFolder?: (context: { debug: boolean; target: 'ios' | 'android' }) => string | string[] | undefined;
}

0 comments on commit b12ee46

Please sign in to comment.