jmms
Version:
Jmms cli tools, Jmms is a java meta-micro-service framework
66 lines (57 loc) • 2.14 kB
JavaScript
const _ = require('lodash');
const utils = require('../../utils');
const log = require('../../log');
const chalk = require('chalk');
const BaseGenerator = require('../base');
module.exports = class extends BaseGenerator {
constructor(args, opts) {
super(args, opts);
}
generateEntityAndExit(){
const db = this.app.config.db;
const tables = this.options['tables'];
if(_.isEmpty(db)){
return this._selectDatabaseAndConfigure((opts) => {
this._runJavaCli( (cli) => { this._gen(cli, opts, tables) });
});
}else {
var opts = {}
utils.copyProperties(db, opts);
this._runJavaCli( (cli) => { this._gen(cli, opts, tables) });
}
}
_gen(cli, params, tables) {
if(!_.isEmpty(tables)) {
params.tables = tables;
}
cli.exec('db.validate', params, (err, url) => {
if(err) {
log.info("Invalid db config : " + JSON.stringify(params));
return;
}
const tableMsg = _.isEmpty(tables) ? '' : ' for tables \'' + tables + '\'';
cli.exec('db.generate', params, (err, entities) => {
if(err) {
return;
}
if(_.isEmpty(entities)) {
log.info("No entities found" + tableMsg + " at db '" + chalk.yellow(url) + "', exit!");
process.exit(0);
}
return this.prompt([
{
type: 'confirm',
name: 'yes',
message: "Found " + entities.length + " entities" + tableMsg + " at db '" + chalk.yellow(url) + "', generates them?",
default: false
}
]).then((ans) => {
if(ans.yes) {
this._generateEntitiesWithOptions(entities, this.options);
log.info("Generation done!");
}
});
});
});
}
};