Skip to content

Commit

Permalink
feat(app-vite/app-webpack): add new options for quasar.config file > …
Browse files Browse the repository at this point in the history
…cordova (getCordovaBuildParams & getCordovaBuildOutputFolder) #17138
  • Loading branch information
rstoenescu committed Apr 26, 2024
1 parent 548a2fc commit 8a4034c
Show file tree
Hide file tree
Showing 8 changed files with 296 additions and 46 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 @@ -11,18 +11,25 @@ import { openIDE } from '../../utils/open-ide.js'
import { onShutdown } from '../../utils/on-shutdown.js'
import { fixAndroidCleartext } from '../../utils/fix-android-cleartext.js'

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 ]
}

export class QuasarModeBuilder extends AppBuilder {
#cordovaConfigFile = new CordovaConfigFile()

Expand Down Expand Up @@ -64,8 +71,18 @@ export class QuasarModeBuilder extends AppBuilder {
fixAndroidCleartext(appPaths, 'cordova')
}

const cordovaContext = {
debug: this.quasarConf.metaConf.debugging === 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 @@ export class QuasarModeBuilder extends AppBuilder {

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

await this.#runCordovaCommand(
args.concat(this.argv._),
Expand All @@ -99,7 +119,7 @@ export class QuasarModeBuilder 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/modes/cordova/cordova-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,25 @@ const { openIDE } = require('../../utils/open-ide.js')
const { onShutdown } = require('../../utils/on-shutdown.js')
const { fixAndroidCleartext } = require('../../utils/fix-android-cleartext.js')

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 ]
}

module.exports.QuasarModeBuilder = class QuasarModeBuilder extends AppBuilder {
#cordovaConfigFile = new CordovaConfigFile()

Expand All @@ -45,8 +52,18 @@ module.exports.QuasarModeBuilder = class QuasarModeBuilder extends AppBuilder {
fixAndroidCleartext(appPaths, 'cordova')
}

const cordovaContext = {
debug: this.quasarConf.metaConf.debugging === 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 @@ -60,7 +77,10 @@ module.exports.QuasarModeBuilder = class QuasarModeBuilder extends AppBuilder {

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

await this.#runCordovaCommand(
args.concat(this.argv._),
Expand All @@ -80,7 +100,7 @@ module.exports.QuasarModeBuilder = class QuasarModeBuilder 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-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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,7 @@ $ quasar build -m [ios|android] -d
# ..or the longer form
$ quasar build -m [ios|android] --debug
```

::: tip
Also check `getCordovaBuildParams()` and `getCordovaBuildOutputFolder()` (quasar.config > cordova options) from [Configuring Cordova](/quasar-cli-vite/developing-cordova-apps/configuring-cordova#quasar-config-file) page.
:::
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,79 @@ For determining the values for each of the properties mentioned above, Quasar CL
1. Looks in the `/quasar.config` file for a "cordova" Object. Does it have "version", "description" and/or "androidVersionCode"? If yes, it will use them.
2. If not, then it looks into your `/package.json` for "cordovaId", "version" and "description" fields.

```js
return {
capacitor: {
// If not present, will look for package.json > version
version: '..', // string
// If not present, will look for package.json > description
description: '...', // string
androidVersionCode: '..', // string

/**
* Enable Xcode modern build even if after considering iOS-Cordova issues.
* You can enable it if you know what you are doing,
* for example if you want to specify the build type in your “build.json”.
*
* Default: false
*/
noIosLegacyBuildFlag: true/false
```js /quasar.config file > cordova
/*
return {
cordova: {
// ...defined by interface below
}
}
*/

interface QuasarCordovaConfiguration {
/** If not present, will look for `package.json > version` */
version?: string;
/** If not present, will look for `package.json > description` */
description?: string;
androidVersionCode?: string;
/**
* Enable Xcode modern build even if after considering iOS-Cordova issues.
* You can enable it if you know what you are doing,
* for example if you want to specify the build type in your “build.json”.
*
* @default false
*/
noIosLegacyBuildFlag?: boolean;

/**
* (Requires @quasar/app-vite v1.8.5+)
*
* 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[];

/**
* (Requires @quasar/app-vite v1.8.5+)
*
* 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;
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,7 @@ $ quasar build -m [ios|android] -d
# ..or the longer form
$ quasar build -m [ios|android] --debug
```

::: tip
Also check `getCordovaBuildParams()` and `getCordovaBuildOutputFolder()` (quasar.config > cordova options) from [Configuring Cordova](/quasar-cli-webpack/developing-cordova-apps/configuring-cordova#quasar-config-file) page.
:::

0 comments on commit 8a4034c

Please sign in to comment.