move code generator to a module

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

View File

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

View File

@ -1,6 +1,6 @@
let async = require('async');
let fs = require('../core/fs.js');
const utils = require('../utils/utils.js');
let fs = require('../../core/fs.js');
const utils = require('../../utils/utils.js');
require('ejs');
const Templates = {
@ -19,17 +19,24 @@ const Templates = {
};
class CodeGenerator {
constructor(options) {
this.blockchainConfig = options.blockchainConfig || {};
constructor(embark, options) {
this.blockchainConfig = embark.config.blockchainConfig || {};
this.rpcHost = this.blockchainConfig.rpcHost || '';
this.rpcPort = this.blockchainConfig.rpcPort || '';
this.contractsConfig = options.contractsConfig || {};
this.storageConfig = options.storageConfig || {};
this.communicationConfig = options.communicationConfig || {};
this.namesystemConfig = options.namesystemConfig || {};
this.contractsConfig = embark.config.contractsConfig || {};
this.storageConfig = embark.config.storageConfig || {};
this.communicationConfig = embark.config.communicationConfig || {};
this.namesystemConfig = embark.config.namesystemConfig || {};
this.env = options.env || 'development';
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() {