move code generator to a module

This commit is contained in:
Iuri Matias 2018-07-27 14:54:25 -04:00
parent b35d034692
commit b48ec4c638
14 changed files with 34 additions and 22 deletions

View File

@ -158,23 +158,28 @@ class Engine {
codeGeneratorService(_options) { codeGeneratorService(_options) {
let self = this; let self = this;
const CodeGenerator = require('../contracts/code_generator.js'); this.registerModule('code_generator', {plugins: self.plugins, env: self.env});
this.codeGenerator = new CodeGenerator({ //const CodeGenerator = require('../contracts/code_generator.js');
blockchainConfig: self.config.blockchainConfig, //this.codeGenerator = new CodeGenerator({
contractsConfig: self.config.contractsConfig, // blockchainConfig: self.config.blockchainConfig,
plugins: self.plugins, // contractsConfig: self.config.contractsConfig,
storageConfig: self.config.storageConfig, // plugins: self.plugins,
namesystemConfig: self.config.namesystemConfig, // storageConfig: self.config.storageConfig,
communicationConfig: self.config.communicationConfig, // namesystemConfig: self.config.namesystemConfig,
events: self.events, // communicationConfig: self.config.communicationConfig,
env: self.env // events: self.events,
}); // env: self.env
this.codeGenerator.listenToCommands(); //});
//this.codeGenerator.listenToCommands();
const generateCode = function () { const generateCode = function () {
self.codeGenerator.buildEmbarkJS(function() { self.events.request("code-generator:embarkjs:build", () => {
self.events.emit('code-generator-ready'); self.events.emit('code-generator-ready');
}); });
//self.codeGenerator.buildEmbarkJS(function() {
// self.events.emit('code-generator-ready');
//});
}; };
const cargo = async.cargo((_tasks, callback) => { const cargo = async.cargo((_tasks, callback) => {
generateCode(); generateCode();

View File

@ -1,6 +1,6 @@
let async = require('async'); let async = require('async');
let fs = require('../core/fs.js'); let fs = require('../../core/fs.js');
const utils = require('../utils/utils.js'); const utils = require('../../utils/utils.js');
require('ejs'); require('ejs');
const Templates = { const Templates = {
@ -19,17 +19,24 @@ const Templates = {
}; };
class CodeGenerator { class CodeGenerator {
constructor(options) { constructor(embark, options) {
this.blockchainConfig = options.blockchainConfig || {}; this.blockchainConfig = embark.config.blockchainConfig || {};
this.rpcHost = this.blockchainConfig.rpcHost || ''; this.rpcHost = this.blockchainConfig.rpcHost || '';
this.rpcPort = this.blockchainConfig.rpcPort || ''; this.rpcPort = this.blockchainConfig.rpcPort || '';
this.contractsConfig = options.contractsConfig || {}; this.contractsConfig = embark.config.contractsConfig || {};
this.storageConfig = options.storageConfig || {}; this.storageConfig = embark.config.storageConfig || {};
this.communicationConfig = options.communicationConfig || {}; this.communicationConfig = embark.config.communicationConfig || {};
this.namesystemConfig = options.namesystemConfig || {}; this.namesystemConfig = embark.config.namesystemConfig || {};
this.env = options.env || 'development'; this.env = options.env || 'development';
this.plugins = options.plugins; this.plugins = options.plugins;
this.events = options.events; this.events = embark.events;
this.listenToCommands();
const self = this;
this.events.setCommandHandler("code-generator:embarkjs:build", (cb) => {
self.buildEmbarkJS(cb);
});
} }
listenToCommands() { listenToCommands() {