Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separation of build and deploy commands #292

Merged
merged 15 commits into from
Dec 3, 2020
117 changes: 117 additions & 0 deletions src/commands/app/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
Copyright 2019 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

const ora = require('ora')
const chalk = require('chalk')

const BaseCommand = require('../../BaseCommand')
const { flags } = require('@oclif/command')
const { runPackageScript, writeConfig, wrapError } = require('../../lib/app-helper')
const RuntimeLib = require('@adobe/aio-lib-runtime')
const webLib = require('@adobe/aio-lib-web')
const fs = require('fs-extra')

class Build extends BaseCommand {
async run () {
// cli input
const { flags } = this.parse(Build)
const config = this.getAppConfig()

const spinner = ora()

await this.build(config, flags, spinner)
}

async build (config, flags, spinner) {
const onProgress = !flags.verbose ? info => {
spinner.text = info
} : info => {
spinner.info(chalk.dim(`${info}`))
spinner.start()
}

try {
const filterActions = flags.action
try {
await runPackageScript('pre-app-build')
} catch (err) {
this.log(err)
}

if (!flags['skip-actions']) {
if (config.app.hasBackend && (flags['force-build'] || !fs.existsSync(config.actions.dist))) {
spinner.start('Building actions')
await RuntimeLib.buildActions(config, filterActions)
spinner.succeed(chalk.green('Building actions'))
} else {
spinner.info('no backend or a build already exists, skipping action build')
}
}
if (!flags['skip-static']) {
if (config.app.hasFrontend && (flags['force-build'] || !fs.existsSync(config.web.distProd))) {
if (config.app.hasBackend) {
const urls = await RuntimeLib.utils.getActionUrls(config)
await writeConfig(config.web.injectedConfig, urls)
}
spinner.start('Building web assets')
await webLib.buildWeb(config, onProgress)
spinner.succeed(chalk.green('Building web assets'))
} else {
spinner.info('no frontend or a build already exists, skipping frontend build')
}
}
try {
await runPackageScript('post-app-build')
} catch (err) {
this.log(err)
}

// final message
if (flags['skip-static']) {
this.log(chalk.green(chalk.bold('Build success, your actions are ready to be deployed 👌')))
} else {
this.log(chalk.green(chalk.bold('Build success, your app is ready to be deployed 👌')))
}
} catch (error) {
spinner.stop()
this.error(wrapError(error))
}
}
}

Build.description = `Build an Adobe I/O App
`

Build.flags = {
...BaseCommand.flags,
'skip-static': flags.boolean({
description: 'Skip build of static files'
}),
'skip-actions': flags.boolean({
description: 'Skip build of actions'
}),
'force-build': flags.boolean({
description: 'Forces a build even if one already exists',
default: true,
allowNo: true
}),
action: flags.string({
description: 'Build only a specific action, the flags can be specified multiple times',
exclusive: ['skip-actions'],
char: 'a',
multiple: true
})
}

Build.args = []

module.exports = Build
61 changes: 16 additions & 45 deletions src/commands/app/deploy.js
Original file line number Diff line number Diff line change
@@ -16,12 +16,13 @@ const chalk = require('chalk')
const { cli } = require('cli-ux')

const BaseCommand = require('../../BaseCommand')
const BuildCommand = require('./build')
const webLib = require('@adobe/aio-lib-web')
const { flags } = require('@oclif/command')
const { runPackageScript, wrapError, writeConfig } = require('../../lib/app-helper')
const { runPackageScript, wrapError } = require('../../lib/app-helper')
const rtLib = require('@adobe/aio-lib-runtime')

class Deploy extends BaseCommand {
class Deploy extends BuildCommand {
async run () {
// cli input
const { flags } = this.parse(Deploy)
@@ -40,41 +41,7 @@ class Deploy extends BaseCommand {
try {
// build phase
if (!flags['skip-build']) {
try {
await runPackageScript('pre-app-build')
} catch (err) {
this.log(err)
}

if (!flags['skip-actions']) {
if (config.app.hasBackend) {
// todo: this replacement seems to be working, but the one below is not yet -jm
// await scripts.buildActions([], { filterActions })
spinner.start('Building actions')
await rtLib.buildActions(config, filterActions)
spinner.succeed(chalk.green('Building actions'))
} else {
this.log('no backend, skipping action build')
}
}
if (!flags['skip-static']) {
if (config.app.hasFrontend) {
if (config.app.hasBackend) {
const urls = await rtLib.utils.getActionUrls(config)
await writeConfig(config.web.injectedConfig, urls)
}
spinner.start('Building web assets')
await webLib.buildWeb(config, onProgress)
spinner.succeed(chalk.green('Building web assets'))
} else {
this.log('no frontend, skipping frontend build')
}
}
try {
await runPackageScript('post-app-build')
} catch (err) {
this.log(err)
}
await this.build(config, flags, spinner)
}

// deploy phase
@@ -103,7 +70,7 @@ class Deploy extends BaseCommand {
}
}
if (!flags['skip-static']) {
if (config.app && config.app.hasFrontend) {
if (config.app.hasFrontend) {
spinner.start('Deploying web assets')
deployedFrontendUrl = await webLib.deployWeb(config, onProgress)
spinner.succeed(chalk.green('Deploying web assets'))
@@ -138,12 +105,12 @@ class Deploy extends BaseCommand {
}

// final message
if (flags['skip-deploy']) {
this.log(chalk.green(chalk.bold('Build success, your app is ready to be deployed 👌')))
} else if (flags['skip-static']) {
this.log(chalk.green(chalk.bold('Well done, your actions are now online 🏄')))
} else {
this.log(chalk.green(chalk.bold('Well done, your app is now online 🏄')))
if (!flags['skip-deploy']) {
if (flags['skip-static']) {
this.log(chalk.green(chalk.bold('Well done, your actions are now online 🏄')))
} else {
this.log(chalk.green(chalk.bold('Well done, your app is now online 🏄')))
}
}
} catch (error) {
spinner.stop()
@@ -171,9 +138,13 @@ Deploy.flags = {
'skip-actions': flags.boolean({
description: 'Skip action build & deploy'
}),
'force-build': flags.boolean({
description: 'Forces a build even if one already exists',
exclusive: ['skip-build'],
default: false
shazron marked this conversation as resolved.
Show resolved Hide resolved
}),
action: flags.string({
description: 'Deploy only a specific action, the flags can be specified multiple times',
default: '',
exclusive: ['skip-actions'],
char: 'a',
multiple: true
Loading