Skip to content
Permalink
Browse files

feat(app): Terminal only build for Capacitor as default option (along…

… with --ide param)
  • Loading branch information...
rstoenescu committed Oct 8, 2019
1 parent 133da44 commit 48661136f5f02951942a3facaa171a97f0ae2965
@@ -13,11 +13,12 @@ const argv = parseArgs(process.argv.slice(2), {
A: 'arch',
b: 'bundler',
s: 'skip-pkg',
i: 'ide',
d: 'debug',
h: 'help',
P: 'publish'
},
boolean: ['h', 'd', 'u'],
boolean: ['h', 'd', 'u', 'i'],
string: ['m', 'T', 'P'],
default: {
m: 'spa'
@@ -60,12 +61,15 @@ if (argv.help) {
- Has special meaning when building with Electron mode and using
electron-builder as bundler
--debug, -d Build for debugging purposes
--skip-pkg, -s Build only UI (skips creating Cordova/Electron executables)
--skip-pkg, -s Build only UI (skips creating Cordova/Capacitor/Electron executables)
- Cordova (it only fills in /src/cordova/www folder with the UI code)
- Capacitor (it only fills in /src/capacitor/www folder with the UI code)
- Electron (it only creates the /dist/electron/UnPackaged folder)
--help, -h Displays this message
ONLY for Capacitor mode:
--ide, -i Open IDE (Android Studio / XCode) instead of finalizing with a terminal/console build
ONLY for Electron mode:
--bundler, -b Bundler (electron-packager or electron-builder)
[packager|builder]
@@ -98,6 +102,12 @@ if (argv.mode !== 'spa') {
require('../lib/mode/install-missing')(argv.mode, argv.target)
}

if (argv.mode === 'capacitor') {
// TODO - remove when out of beta
const showBanner = require('../lib/capacitor/show-beta-banner')
showBanner()
}

const
path = require('path'),
webpack = require('webpack')
@@ -119,9 +129,9 @@ function parseWebpackConfig (webpackConfig, mode) {
return webpackConfig
}

function finalize (mode, quasarConfig) {
function finalizeBuild (mode, quasarConfig) {
if (['cordova', 'capacitor'].includes(mode)) {
return require('../lib/' + mode).build(quasarConfig, argv['skip-pkg'], argv._)
return require('../lib/' + mode).build(quasarConfig, argv)
}
else if (argv['skip-pkg'] !== true && mode === 'electron') {
return require('../lib/electron').build(quasarConfig)
@@ -162,7 +172,7 @@ async function build () {
webpackConfig = quasarConfig.getWebpackConfig(),
buildConfig = quasarConfig.getBuildConfig()

let outputFolder = buildConfig.build.packagedElectronDist ||
let outputFolder = buildConfig.build.packagedDistDir ||
buildConfig.build.distDir

artifacts.clean(outputFolder)
@@ -212,7 +222,7 @@ async function build () {
}
})

finalize(argv.mode, quasarConfig).then(async () => {
finalizeBuild(argv.mode, quasarConfig).then(async () => {
outputFolder = argv.mode === 'cordova'
? path.join(outputFolder, '..')
: outputFolder
@@ -77,6 +77,12 @@ if (argv.mode !== 'spa') {
require('../lib/mode/install-missing')(argv.mode, argv.target)
}

if (argv.mode === 'capacitor') {
// TODO - remove when out of beta
const showBanner = require('../lib/capacitor/show-beta-banner')
showBanner()
}

const findPort = require('../lib/helpers/net').findClosestOpenPort

async function parseAddress ({ host, port }) {
@@ -266,7 +266,7 @@ module.exports = class Extension {
spawnSync(
nodePackager,
cmdParam.concat(this.packageFullName),
appPaths.appDir,
{ cwd: appPaths.appDir },
() => warn(`⚠️ Failed to install ${this.packageFullName}`)
)
}
@@ -282,7 +282,7 @@ module.exports = class Extension {
spawnSync(
nodePackager,
cmdParam.concat(this.packageName),
appPaths.appDir,
{ cwd: appPaths.appDir },
() => warn(`⚠️ Failed to uninstall "${this.packageName}"`)
)
}
@@ -344,7 +344,7 @@ module.exports = class Extension {
spawnSync(
nodePackager,
cmdParam,
appPaths.appDir,
{ cwd: appPaths.appDir },
() => warn(`⚠️ Failed to update dependencies`)
)
}
@@ -10,14 +10,14 @@ module.exports = function (cfg) {

file = appPaths.resolve.app(cfg.sourceFiles.indexHtmlTemplate)
if (!fs.existsSync(file)) {
console.log('⚠️ Missing /src/index.template.html file...')
console.log(' ⚠️ Missing /src/index.template.html file...')
console.log()
error = true
}
content = fs.readFileSync(file, 'utf-8')

if (content.indexOf('<base href') > -1) {
console.log(`⚠️ Please remove the tag below from /src/index.template.html
console.log(` ⚠️ Please remove the tag below from /src/index.template.html
This is taken care of by Quasar automatically.
<base href="<%= htmlWebpackPlugin.options.appBase %>">
`)
@@ -33,14 +33,14 @@ module.exports = function (cfg) {
'<% if (htmlWebpackPlugin.options.ctx.mode.cordova || htmlWebpackPlugin.options.ctx.mode.capacitor) { %>, viewport-fit=cover<% } %>'
)
fs.writeFileSync(file, content, 'utf-8')
console.log(`\n⚠️ Updated viewport-fit in /src/index.template.html to latest Quasar specs`)
console.log(`\n ⚠️ Updated viewport-fit in /src/index.template.html to latest Quasar specs`)
console.log()
}

file = appPaths.resolve.app(cfg.sourceFiles.rootComponent)
content = fs.readFileSync(file, 'utf-8')
if (content.indexOf('q-app') === -1) {
console.log(`\n⚠️ Quasar requires a minor change to the root component:
console.log(`\n ⚠️ Quasar requires a minor change to the root component:
${file}
Please add: id="q-app" (or write #q-app if using Pug)
@@ -62,7 +62,7 @@ ${green('Example:')}

file = appPaths.resolve.app('babel.config.js')
if (!fs.existsSync(file)) {
console.log('⚠️ Missing babel.config.js file...')
console.log(' ⚠️ Missing babel.config.js file...')
console.log()
process.exit(1)
}
@@ -39,7 +39,10 @@ module.exports.clean = function (folder) {
}
else if (folder.endsWith(path.join('src-capacitor', 'www'))) {
fse.emptyDirSync(folder)
fse.ensureFileSync(appPaths.resolve.capacitor('www/index.html'))
fse.copySync(
appPaths.resolve.cli('templates/capacitor/www'),
appPaths.capacitorDir
)
}
else {
fse.removeSync(folder)
@@ -1,8 +1,10 @@
const fse = require('fs-extra')

const
log = require('../helpers/logger')('app:capacitor'),
warn = require('../helpers/logger')('app:capacitor', 'red'),
CapacitorConfig = require('./capacitor-config'),
{ spawn } = require('../helpers/spawn'),
{ spawn, spawnSync } = require('../helpers/spawn'),
onShutdown = require('../helpers/on-shutdown'),
appPaths = require('../app-paths')

@@ -38,30 +40,93 @@ class CapacitorRunner {
await this.__runCapacitorCommand(['sync', cfg.ctx.targetName])

console.log()
console.log(`⚠️ `)
console.log(`⚠️ Opening ${cfg.ctx.targetName === 'ios' ? 'XCode' : 'Android Studio'} IDE...`)
console.log(`⚠️ From there, use the IDE to run the app.`)
console.log(`⚠️ `)
console.log(` ⚠️ `)
console.log(` ⚠️ Opening ${cfg.ctx.targetName === 'ios' ? 'XCode' : 'Android Studio'} IDE...`)
console.log(` ⚠️ From there, use the IDE to run the app.`)
console.log(` ⚠️ But DO NOT close the terminal as this will kill the devserver.`)
console.log(` ⚠️ `)
console.log()

await this.__runCapacitorCommand(['open', cfg.ctx.targetName])
}

async build (quasarConfig, skipPkg) {
async build (quasarConfig, argv) {
const cfg = quasarConfig.getBuildConfig()

this.config.prepare(cfg)

await this.__runCapacitorCommand(['sync', cfg.ctx.targetName])

if (skipPkg !== true) {
if (argv['skip-pkg'] === true) {
return
}

if (argv.ide === true) {
console.log()
console.log(`⚠️ `)
console.log(`⚠️ Opening ${cfg.ctx.targetName === 'ios' ? 'XCode' : 'Android Studio'}`)
console.log(`⚠️ From there, use the IDE to build the final package.`)
console.log(`⚠️ `)
console.log(` ⚠️ `)
console.log(` ⚠️ Opening ${cfg.ctx.targetName === 'ios' ? 'XCode' : 'Android Studio'}`)
console.log(` ⚠️ From there, use the IDE to build the final package.`)
console.log(` ⚠️ `)
console.log()
return this.__runCapacitorCommand(['open', cfg.ctx.targetName])

this.__runCapacitorCommand(['open', cfg.ctx.targetName], true)
process.exit(0)
}

if (cfg.ctx.targetName === 'ios') {
await this.__buildIos(argv, cfg)
}
else {
await this.__buildAndroid(argv, cfg)
}
}

async __buildIos (argv, cfg) {
const args = 'xcodebuild -workspace App.xcworkspace -scheme App -configuration release -derivedDataPath'

log('Building iOS app...')

await spawnSync(
'xcrun',
args.split(' ').concat([ cfg.build.packagedDistDir ]).concat(argv._),
{ cwd: appPaths.resolve.capacitor('ios/App') },
() => {
console.log()
console.log(` ⚠️ xcodebuild command failed!`)
console.log(` ⚠️ As an alternative, you can use the "--ide" param and build from the IDE.`)
console.log()

// cleanup build folder
fse.removeSync(
cfg.build.packagedDistDir
)
}
)
}

async __buildAndroid (argv, cfg) {
const buildPath = appPaths.resolve.capacitor(
'android/app/build/outputs/apk/' + (cfg.ctx.debug ? 'debug' : 'release')
)

// Remove old build output
fse.removeSync(buildPath)

log('Building Android app...')

await spawnSync(
`./gradlew${process.platform === 'win32' ? '.bat' : ''}`,
[ `assemble${cfg.ctx.debug ? 'Debug' : 'Release'}` ].concat(argv._),
{ cwd: appPaths.resolve.capacitor('android') },
() => {
console.log()
console.log(` ⚠️ Gradle build failed!`)
console.log(` ⚠️ As an alternative, you can use the "--ide" param and build from the IDE.`)
console.log()
}
)

fse.copySync(buildPath, cfg.build.packagedDistDir)
}

stop () {
@@ -72,22 +137,32 @@ class CapacitorRunner {
this.__cleanup()
}

__runCapacitorCommand (args) {
return new Promise(resolve => {
this.pid = spawn(
__runCapacitorCommand (args, detached = false) {
const run = resolve => {
return spawn(
capacitorCliPath,
args,
appPaths.capacitorDir,
{ cwd: appPaths.capacitorDir, detached },
code => {
this.__cleanup()

if (code) {
warn(`⚠️ [FAIL] Capacitor CLI has failed`)
process.exit(1)
}
resolve(code)

resolve && resolve(code)
}
)
})
}

if (detached !== true) {
return new Promise(resolve => {
this.pid = run(resolve)
})
}

run()
}

__cleanup () {
@@ -0,0 +1,7 @@
module.exports = function () {
console.log(` ⚠️ ----`)
console.log(` ⚠️ Quasar Capacitor mode is currently in beta.`)
console.log(` ⚠️ Do NOT use in production yet.`)
console.log(` ⚠️ ----`)
console.log()
}
@@ -42,15 +42,15 @@ class CordovaRunner {
)
}

build (quasarConfig, skipPkg, extraParams) {
build (quasarConfig, argv) {
const cfg = quasarConfig.getBuildConfig()
const args = skipPkg
const args = argv['skip-pkg']
? ['prepare', cfg.ctx.targetName]
: ['build', cfg.ctx.debug ? '--debug' : '--release', cfg.ctx.targetName]

return this.__runCordovaCommand(
cfg,
args.concat(extraParams)
args.concat(argv._)
)
}

@@ -73,7 +73,7 @@ class CordovaRunner {
this.pid = spawn(
'cordova',
args,
appPaths.cordovaDir,
{ cwd: appPaths.cordovaDir },
code => {
this.__cleanup()
if (code) {
@@ -26,7 +26,7 @@ function installBundler (bundlerName) {
spawnSync(
nodePackager,
cmdParam.concat([`electron-${bundlerName}@${'^' + versions[bundlerName]}`]),
appPath.appDir,
{ cwd: appPath.appDir },
() => warn(`⚠️ Failed to install electron-${bundlerName}`)
)
}
@@ -78,7 +78,7 @@ module.exports.getBundler = function (bundlerName) {
module.exports.ensureBuilderCompatibility = function () {
if (fs.existsSync(appPath.resolve.electron('icons/linux-256x256.png'))) {
console.log()
console.log(`\n⚠️ electron-builder requires a change to your src-electron/icons folder:
console.log(`\n ⚠️ electron-builder requires a change to your src-electron/icons folder:
* replace linux-256x256.png with a 512x512 px png file named "linux-512x512.png"
* make sure to delete the old linux-256x256.png file
`)
@@ -71,7 +71,7 @@ class ElectronRunner {
spawn(
nodePackager,
[ 'install', '--production' ],
cfg.build.distDir,
{ cwd: cfg.build.distDir },
code => {
if (code) {
warn(`⚠️ [FAIL] ${nodePackager} failed installing dependencies`)
@@ -160,7 +160,7 @@ class ElectronRunner {
'--inspect=5858',
appPaths.resolve.app('.quasar/electron/electron-main.js')
].concat(extraParams),
appPaths.appDir,
{ cwd: appPaths.appDir },
code => {
if (code) {
warn()

0 comments on commit 4866113

Please sign in to comment.
You can’t perform that action at this time.