Skip to content

Commit

Permalink
fix(app-vite): (backport from q/app-vite v2 beta) build fails with la…
Browse files Browse the repository at this point in the history
…test cordova-ios #17138
  • Loading branch information
rstoenescu committed Apr 25, 2024
1 parent 0067f2e commit 62de0c9
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions app-vite/lib/modes/cordova/cordova-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,25 @@ const { join } = require('path')
const AppBuilder = require('../../app-builder')
const config = require('./cordova-config')

const { fatal } = require('../../helpers/logger')
const { log, warn, fatal } = require('../../helpers/logger')
const appPaths = require('../../app-paths')
const CordovaConfigFile = require('./config-file')
const { spawn } = require('../../helpers/spawn')
const openIde = require('../../helpers/open-ide')
const onShutdown = require('../../helpers/on-shutdown')

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

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

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

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

const buildPath = appPaths.resolve.cordova(
target === 'android'
? 'platforms/android/app/build/outputs'
: 'platforms/ios/build/emulator'
)

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

onShutdown(() => {
this.#cleanup()
Expand All @@ -69,7 +79,7 @@ class CapacitorBuilder extends AppBuilder {

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

await this.#runCordovaCommand(
args.concat(this.argv._),
Expand All @@ -82,7 +92,24 @@ class CapacitorBuilder extends AppBuilder {
process.exit(0)
}

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

for (const folder of cordovaOutputFiles[ target ]) {
const outputFolder = appPaths.resolve.cordova(folder)
if (fse.existsSync(outputFolder)) {
log(`Copying Cordova distributables from ${ outputFolder } to ${ targetFolder }`)
log()
fse.copySync(outputFolder, targetFolder)
return
}
}

warn(
`No output folder found for target "${ target }".`
+ ' Files have not been copied to /dist. You will need'
+ ' to manually extract the Cordova distributables.'
)
log()
}
}

Expand Down

0 comments on commit 62de0c9

Please sign in to comment.