@arc-fusion/cli
Version:
CLI for running Arc Fusion on your local machine
203 lines (178 loc) • 4.55 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 version = require('./version')
const zip = require('./zip')
const {
cleanContainers,
cleanImages,
cleanNetworks,
cleanVolumes,
nuke
} = require('./clean')
const {
build,
daemon,
down,
generate,
run,
start,
stop
} = require('../utils/docker')
async function showVersionAndRelease () {
version()
await latest()
run('release')
}
program
.command('build')
.description('Build Fusion images')
.action(async () => {
await generate()
await build()
})
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) => {
await generate(undefined, options)
await down()
await build()
await daemon()
})
program
.command('down')
.description('Stop and remove Fusion services and volumes')
.action(async () => {
await generate(undefined, { admin: true })
await down()
})
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
.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')
.action(async (service, options) => {
try {
await latest()
await generate(undefined, options)
await down()
await build()
await start(undefined, options.rebuild)
} catch (e) {
console.log(e)
throw new Error('There was an error starting local fusion environment')
} finally {
await down()
}
})
program
.command('stop')
.alias('Stop')
.description('Stop Fusion docker services')
.action(async () => {
await generate(undefined, { admin: true })
await stop()
})
program
.command('verify')
.description('Verify the current bundle')
.action(async () => run('verify'))
program
.command('version')
.description('Look at the version of fusion')
.action(async () => {
showVersionAndRelease()
})
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')
.action(async (options) => {
if (!options.force) await run('verify')
await zip(options)
})
program.parse(process.argv)