draig-car
Version:
Database REST API interactive generator CLI and REPL OpenAPI3 based JS generator with interactive ORM/ODM REPL
68 lines (65 loc) • 1.62 kB
JavaScript
const u = require('../util')
async function runInContext(ctx, func, clear) {
let failed = await func.call(null, ctx)
if (ctx.argv._.includes('run')) process.exit(0)
if (clear && !failed) require('../init').initCtx(ctx)
ctx.repl.displayPrompt()
}
module.exports = {
list: {
help: 'Show list of available internal runnable commands',
runnable: true,
action(name) {
runInContext(this.context, c => u.listCmds(c), false)
}
},
test: {
help: 'Run "yarn test" into the API server project directory',
runnable: true,
async action(name) {
await runInContext(this.context, c => u.runPackager(c, 'test'), true)
}
},
install: {
help: 'Run "yarn install" into the API server project directory',
runnable: true,
action(name) {
runInContext(this.context, c => u.runPackager(c, 'install'), true)
}
},
start: {
help: 'Start the API server',
runnable: true,
action(name) {
runInContext(this.context, c => u.startAPI(c, false), false)
}
},
stop: {
help: 'Stop the API server',
runnable: true,
action(name) {
runInContext(this.context, c => u.stopAPI(c), false)
}
},
status: {
help: 'Check the status of the API server',
runnable: true,
action(name) {
runInContext(this.context, c => u.statusAPI(c), false)
}
},
generate: {
help: '(Re)generate the API project using current API definition',
runnable: true,
action(name) {
runInContext(this.context, c => u.generateAPI(c), true)
}
},
clean: {
help: 'Clean all generated artifacts and log files',
runnable: true,
action(name) {
runInContext(this.context, c => u.clean(c), false)
}
}
}