@arc-fusion/cli
Version:
CLI for running Arc Fusion on your local machine
276 lines (237 loc) • 7.21 kB
JavaScript
const { program } = require('commander')
const dump = require('./dump')
const help = require('./help')
const init = require('./init')
const latest = require('./latest')
const migrate = require('./migrate')
const rebuild = require('./rebuild')
const repo = require('./repo')
const types = require('./types')
const version = require('./version')
const zip = require('./zip')
const compileStyles = require('./compile-styles')
const {
cleanContainers,
cleanImages,
cleanNetworks,
cleanVolumes,
nuke
} = require('./clean')
const {
build,
daemon,
down,
generate,
run,
start,
stop
} = require('../utils/docker')
const { findCircDeps } = require('../utils/dependencies')
const { verifyBundleSize } = require('../utils/diskUsage')
const { logMessage, MESSAGES, TYPE_MESSAGE } = require('../utils/logMessage')
const {
VERIFYNG_BUNDLE
} = MESSAGES
const {
ERROR,
INFO
} = TYPE_MESSAGE
async function showVersionAndRelease (options) {
version()
await latest()
run('release', options)
}
program
// Define a global option to set the Docker compose version to use within the fusion CLI.
.option('-c, --compose <version>', 'Docker Compose version to use. "v1" uses docker-compose and "v2" uses docker compose', 'v2')
program
.command('build')
.description('Build Fusion images')
.action(async () => {
const options = program.opts()
await generate(undefined, options)
await build(undefined, options)
})
program
.command('clean')
.description('Clear stray docker artifacts')
.action(async () => {
await nuke()
})
program
.command('cleanContainers')
.description('Clear stray docker containers')
.action(async () => {
await cleanContainers()
})
program
.command('cleanImages')
.description('Clear stray docker images')
.action(async () => {
await cleanImages()
})
program
.command('cleanNetworks')
.description('Clear stray docker networks')
.action(async () => {
await cleanNetworks()
})
program
.command('cleanVolumes')
.description('Clear stray docker volumes')
.action(async () => {
await cleanVolumes()
})
program
.command('daemon')
.description('Run Fusion services in detached mode')
.option('-n, --no-admin', 'Start up fusion without admin')
.action(async (options, command) => {
// Use optsWithGlobals to merge global options with command-specific options
const mergedOptions = command.optsWithGlobals()
await generate(undefined, mergedOptions)
await down(undefined, mergedOptions)
await build(undefined, mergedOptions)
await daemon(undefined, mergedOptions)
})
program
.command('down')
.description('Stop and remove Fusion services and volumes')
.action(async () => {
await generate(undefined, { admin: true })
await down(undefined, program.opts())
})
program
.command('dump')
.description('Create a dump of the current DB in the data/dumps/ folder')
.action(async () => {
await dump()
})
program
.command('help')
.description('Display description for each of available commands')
.action(async function () {
await help()
})
program
.command('init')
.description('Bootstrap a new Fusion repository')
.action(async () => {
await init()
})
program
.command('migrate')
.description("Rename component files with a trailing 'x' to prepare for 2.1 refactor")
.action(async () => {
await migrate()
})
program
.command('nuke')
.description('Clear stray docker artifacts')
.action(async () => {
await nuke()
})
program
.command('rebuild')
.description('Manually trigger webpack to rebuild after a change if file watching fails')
.action(async () => {
await rebuild(program.opts())
})
program
.command('repo')
.description('Print the name of the repository')
.action(async () => {
await repo()
})
program
.command('start [service]')
.description('Start named fusion local development environment, or default if no name supplied')
.option('-n, --no-admin', 'Start up fusion without admin')
.option('-l, --links [blocks]', 'Link all blocks specified in blocks, devBlocks array, or a comma separated string of block names')
.option('-p, --production', 'Use published blocks')
.option('-f, --rebuild', 'Force rebuild of webpack image')
.option('-v, --verbose', 'Show verbose log output')
.action(async (name, options, command) => {
// Use optsWithGlobals to merge global options with command-specific options
const mergedOptions = command.optsWithGlobals()
try {
await latest()
await generate(undefined, mergedOptions)
await down(undefined, mergedOptions)
await build(undefined, mergedOptions)
await start(undefined, mergedOptions)
} catch (e) {
console.log(e)
throw new Error('There was an error starting local fusion environment')
} finally {
await down(undefined, mergedOptions)
}
})
program
.command('stop')
.alias('Stop')
.description('Stop fusion without removing services and volumes')
.action(async () => {
const options = program.opts()
await generate(undefined, { admin: true })
await stop(undefined, options)
})
program
.command('types')
.description('Generate TypeScript declaration files for schemas')
.action(async () => {
await types()
})
program
.command('verify')
.description('Verify the current bundle')
.option('-f, --force', 'Verify production build without running validation', false)
.option('-k, --keep-artifacts', 'Keep verify build artifacts in .fusion/ after completion', false)
.action(async (options, command) => {
// Use optsWithGlobals to merge global options with command-specific options
const mergedOptions = command.optsWithGlobals()
const { force } = mergedOptions
logMessage(INFO, VERIFYNG_BUNDLE)
if (!force) {
// Pre-build validation on source code
const { hasCircDeps, message } = await findCircDeps()
if (hasCircDeps) {
logMessage(ERROR, message)
}
}
await run('verify', mergedOptions)
if (!force) {
// Post-build validation on bundle artifacts
await verifyBundleSize()
}
})
program
.command('version')
.description('Look at the version of fusion')
.action(async () => {
const options = program.opts()
showVersionAndRelease(options)
})
program
.command('zip')
.description('Create a bundle zip file in dist/ folder')
.option('-n, --rename <name>', 'Change the generated zip file\'s name')
.option('-f, --force', 'Zip without running verify on the bundle')
.option('-k, --keep-artifacts', 'Keep verify build artifacts in .fusion/ after completion', false)
.action(async (options, command) => {
// Use optsWithGlobals to merge global options with command-specific options
const mergedOptions = command.optsWithGlobals()
if (!mergedOptions.force) {
await run('verify', mergedOptions)
}
await zip(mergedOptions)
})
program
.command('compile-styles')
.description('Compile styles using the themes container')
.action(async () => {
await compileStyles()
})
program.parse(process.argv)