jmms
Version:
Jmms cli tools, Jmms is a java meta-micro-service framework
72 lines (61 loc) • 2.21 kB
JavaScript
const _ = require('lodash');
const log = require('../../log');
const fs = require('fs');
const path = require('path');
const chalk = require('chalk');
var BaseGenerator = require('../base');
module.exports = class extends BaseGenerator {
constructor(args, opts) {
super(args, opts);
}
prompting () {
return this._selectDatabaseAndConfigure((conf) => {
log.info("Validating the db config...");
this._runJavaCli( (cli) => { this._runJavaWithConfig(cli, conf) });
});
}
_runJavaWithConfig(cli, opts) {
const app = this.app;
cli.exec('db.generate', opts, (err, entities) => {
if(err) {
log.info("Validate failed!");
return;
}
//Save config.
this.prompt([
{
type: 'confirm',
name: 'yes',
message: 'Validated ok, do you wan\'t to save the config to ' + chalk.yellow(app.configPath) + '?',
default: false
}
]).then((ans) => {
if(ans.yes === true) {
this._saveDbConfig(opts);
}
//Generate entities.
if(entities.length > 0) {
this.prompt([
{
type: 'confirm',
name: 'generate',
message: 'Found ' + entities.length + " tables! Do you wan't to generate all the tables to entities?",
default: false
}
]).then((ans) => {
if(ans.generate === true) {
this._generateEntitiesWithOptions(entities);
}
});
}
});
});
}
_saveDbConfig(opts) {
const file = this.app.configPath;
log.info('Save the config to file : ' + file);
const config = this.app.config;
config.db = opts;
fs.writeFileSync(file, JSON.stringify(config,null,4));
}
};