Skip to content

Commit

Permalink
Merge branch 'quasarframework:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
zanzara authored Apr 26, 2024
2 parents b1f4335 + 8a4034c commit 0149d6c
Show file tree
Hide file tree
Showing 30 changed files with 552 additions and 168 deletions.
22 changes: 3 additions & 19 deletions app-vite/lib/app-extension/AppExtensionInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,28 +191,12 @@ export class AppExtensionInstance {
log(`${ skipPkgInstall ? 'Invoking' : 'Installing' } "${ this.extId }" Quasar App Extension`)
log()

// verify if already installed
if (skipPkgInstall === true) {
if (!this.isInstalled) {
fatal(`Tried to invoke App Extension "${ this.extId }" but its npm package is not installed`)
}
}
else if (this.isInstalled) {
const answer = await inquirer.prompt([ {
name: 'reinstall',
type: 'confirm',
message: 'Already installed. Reinstall?',
default: false
} ])

if (!answer.reinstall) {
return
}
}

if (skipPkgInstall !== true) {
await this.#installPackage()
}
else if (!this.isInstalled) {
fatal(`Tried to invoke App Extension "${ this.extId }" but its npm package is not installed`)
}

const prompts = await this.#getScriptPrompts()

Expand Down
3 changes: 0 additions & 3 deletions app-vite/lib/app-extension/api-classes/InstallAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,6 @@ export class InstallAPI extends BaseAPI {
'utf-8'
)

// we mingled with it, time to notify there's a need to update it
this.ctx.pkg.updateAppPackageJson()

if (
extPkg.dependencies
|| extPkg.devDependencies
Expand Down
63 changes: 55 additions & 8 deletions app-vite/lib/modes/cordova/cordova-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,32 @@ import { join } from 'node:path'
import { AppBuilder } from '../../app-builder.js'
import { quasarCordovaConfig } from './cordova-config.js'

import { fatal } from '../../utils/logger.js'
import { log, warn, fatal } from '../../utils/logger.js'
import { CordovaConfigFile } from './config-file.js'
import { spawn } from '../../utils/spawn.js'
import { openIDE } from '../../utils/open-ide.js'
import { onShutdown } from '../../utils/on-shutdown.js'
import { fixAndroidCleartext } from '../../utils/fix-android-cleartext.js'

const cordovaOutputFolders = {
ios: [
'platforms/ios/build/Release-iphoneos', // ios-cordova 7+
'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 @@ -52,14 +71,22 @@ export class QuasarModeBuilder extends AppBuilder {
fixAndroidCleartext(appPaths, 'cordova')
}

const buildPath = appPaths.resolve.cordova(
target === 'android'
? 'platforms/android/app/build/outputs'
: 'platforms/ios/build/emulator'
const cordovaContext = {
debug: this.quasarConf.metaConf.debugging === true,
target
}

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

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

onShutdown(() => {
this.#cleanup()
Expand All @@ -69,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', target ]
: (
this.quasarConf.cordova.getCordovaBuildParams?.(cordovaContext)
|| [ 'build', this.quasarConf.metaConf.debugging ? '--debug' : '--release', '--device', target ]
)

await this.#runCordovaCommand(
args.concat(this.argv._),
Expand All @@ -87,7 +117,24 @@ export class QuasarModeBuilder 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 outputTargetList) {
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
2 changes: 0 additions & 2 deletions app-vite/lib/quasar-config-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ export class QuasarConfigFile {
let firstBuildIsDone

const { appPaths } = this.#ctx
const { updateAppPackageJson } = this.#ctx.pkg
const tempFile = this.#tempFile

esbuildConfig.plugins.push({
Expand All @@ -313,7 +312,6 @@ export class QuasarConfigFile {
if (isFirst === false) {
log()
log('The quasar.config file (or its dependencies) changed. Reading it again...')
updateAppPackageJson()
}
})

Expand Down
40 changes: 29 additions & 11 deletions app-vite/lib/utils/get-pkg.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,43 @@
import { readFileSync } from 'node:fs'
import { readFileSync, statSync } from 'node:fs'

import { warning } from './logger.js'
import { getPackageJson } from '../utils/get-package-json.js'

export function getPkg (appPaths) {
const { appDir } = appPaths
const { appDir, cliDir } = appPaths
const appPkgPath = appPaths.resolve.app('package.json')

function readAppPackageJson () {
return JSON.parse(
readFileSync(appPkgPath, 'utf-8')
)
let appPkg = {}
let lastAppPkgModifiedTime = 0

function getAppPackageJson () {
const { mtime } = statSync(appPkgPath)

if (mtime !== lastAppPkgModifiedTime) {
lastAppPkgModifiedTime = mtime
try {
appPkg = JSON.parse(
readFileSync(appPkgPath, 'utf-8')
)
}
catch (err) {
warning('Could not parse app\'s package.json. The file is malformed:')
console.error(err)
}
}

return appPkg
}

const acc = {
appPkg: readAppPackageJson(),
updateAppPackageJson () {
acc.appPkg = readAppPackageJson()
},
quasarPkg: getPackageJson('quasar', appDir),
vitePkg: getPackageJson('vite', appDir)
vitePkg: (
getPackageJson('vite', appDir)
|| getPackageJson('vite', cliDir)
)
}

Object.defineProperty(acc, 'appPkg', { get: getAppPackageJson })

return acc
}
2 changes: 1 addition & 1 deletion app-vite/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@quasar/app-vite",
"version": "2.0.0-beta.8",
"version": "2.0.0-beta.10",
"description": "Quasar Framework App CLI with Vite",
"bin": {
"quasar": "./bin/quasar.js"
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;
}
3 changes: 0 additions & 3 deletions app-webpack/lib/app-extension/api-classes/InstallAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,6 @@ module.exports.InstallAPI = class InstallAPI extends BaseAPI {
'utf-8'
)

// we mingled with it, time to notify there's a need to update it
this.ctx.pkg.updateAppPackageJson()

if (
extPkg.dependencies
|| extPkg.devDependencies
Expand Down
63 changes: 55 additions & 8 deletions app-webpack/lib/modes/cordova/cordova-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,32 @@ const { join } = require('node:path')
const { AppBuilder } = require('../../app-builder.js')
const { quasarCordovaConfig } = require('./cordova-config.js')

const { fatal } = require('../../utils/logger.js')
const { log, warn, fatal } = require('../../utils/logger.js')
const { CordovaConfigFile } = require('./config-file.js')
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 cordovaOutputFolders = {
ios: [
'platforms/ios/build/Release-iphoneos', // ios-cordova 7+
'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 @@ -33,14 +52,22 @@ module.exports.QuasarModeBuilder = class QuasarModeBuilder extends AppBuilder {
fixAndroidCleartext(appPaths, 'cordova')
}

const buildPath = appPaths.resolve.cordova(
target === 'android'
? 'platforms/android/app/build/outputs'
: 'platforms/ios/build/emulator'
const cordovaContext = {
debug: this.quasarConf.metaConf.debugging === true,
target
}

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

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

onShutdown(() => {
this.#cleanup()
Expand All @@ -50,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', target ]
: (
this.quasarConf.cordova.getCordovaBuildParams?.(cordovaContext)
|| [ 'build', this.quasarConf.metaConf.debugging ? '--debug' : '--release', '--device', target ]
)

await this.#runCordovaCommand(
args.concat(this.argv._),
Expand All @@ -68,7 +98,24 @@ module.exports.QuasarModeBuilder = class QuasarModeBuilder 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 outputTargetList) {
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
2 changes: 0 additions & 2 deletions app-webpack/lib/quasar-config-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ module.exports.QuasarConfigFile = class QuasarConfigFile {
let firstBuildIsDone

const { appPaths } = this.#ctx
const { updateAppPackageJson } = this.#ctx.pkg
const tempFile = this.#tempFile

esbuildConfig.plugins.push({
Expand All @@ -319,7 +318,6 @@ module.exports.QuasarConfigFile = class QuasarConfigFile {
if (isFirst === false) {
log()
log('The quasar.config file (or its dependencies) changed. Reading it again...')
updateAppPackageJson()
}
})

Expand Down
Loading

0 comments on commit 0149d6c

Please sign in to comment.