myt/index.js

72 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-11-14 01:38:56 +00:00
2020-11-14 14:53:13 +00:00
require('colors');
2020-11-14 01:38:56 +00:00
const getopts = require('getopts');
const package = require('./package.json');
const dockerRun = require('./docker-run');
2020-11-14 14:53:13 +00:00
const fs = require('fs-extra');
console.log('MyVC (MySQL Version Control)'.green, `v${package.version}`.blue);
2020-11-14 01:38:56 +00:00
const options = getopts(process.argv.slice(2), {
alias: {
dir: 'd',
env: 'e',
2020-11-14 14:53:13 +00:00
help: 'h',
version: 'v'
2020-11-14 01:38:56 +00:00
},
default: {}
})
2020-11-14 14:53:13 +00:00
function usage() {
console.log('Usage:'.gray, 'myvc [-d|--dir] [-e|--env] [-h|--help] action'.magenta);
process.exit(0);
2020-11-14 01:38:56 +00:00
}
2020-11-14 14:53:13 +00:00
if (options.help) usage();
if (options.version) process.exit(0);
let config;
let container;
2020-11-14 01:38:56 +00:00
let action = options._[0];
2020-11-14 14:53:13 +00:00
if (action) {
console.log('Action:'.gray, action.magenta);
const configFile = 'myvc.config.json';
if (!fs.existsSync(configFile)) {
console.error('Error:'.gray, `Config file '${configFile}' not found in working directory`.red);
process.exit(1);
}
config = require(`${process.cwd()}/${configFile}`);
}
2020-11-14 01:38:56 +00:00
switch (action) {
case 'structure':
dockerRun('export-structure.sh');
break;
case 'fixtures':
dockerRun('export-fixtures.sh');
break;
case 'routines':
require('./export-routines');
break;
case 'apply':
dockerRun('apply-changes.sh');
break;
2020-11-14 14:53:13 +00:00
case 'run': {
const Docker = require('./docker');
container = new Docker();
container.run();
break;
}
case 'start': {
const Docker = require('./docker');
container = new Docker();
container.start();
break;
}
default:
usage();
2020-11-14 01:38:56 +00:00
}