feature(@embark/code_generator) generate storage config artifact

This commit is contained in:
Iuri Matias 2019-01-31 05:58:54 +01:00
parent 2c2a09ca68
commit c9febdec93
4 changed files with 26 additions and 7 deletions

View File

@ -86,6 +86,8 @@
},
"dappConfig": {
"dir": "config",
"blockchain": "blockchain.json"
"blockchain": "blockchain.json",
"storage": "storage.json",
"communication": "communication.json"
}
}

View File

@ -401,6 +401,7 @@ Config.prototype.loadStorageConfigFile = function() {
let configFilePath = this._getFileOrObject(this.configDir, 'storage', 'storage');
this.storageConfig = this._mergeConfig(configFilePath, configObject, this.env);
this.events.emit('config:load:storage', this.storageConfig);
};
Config.prototype.loadNameSystemConfigFile = function() {

View File

@ -45,7 +45,11 @@ class CodeGenerator {
let self = this;
this.events.on('config:load:contracts', (contractConfig) => {
this.generateConfigs(contractConfig);
this.generateContractConfig(contractConfig);
});
this.events.on('config:load:storage', (storageConfig) => {
this.generateStorageConfig(storageConfig);
});
this.events.setCommandHandler('code', function(cb) {
@ -146,16 +150,27 @@ class CodeGenerator {
});
}
generateConfigs(contractConfig) {
generateContractConfig(contractConfig) {
this.dappConfigs.blockchain = {
dappConnection: contractConfig.dappConnection,
dappAutoEnable: contractConfig.dappAutoEnable,
warnIfMetamask: this.blockchainConfig.isDev,
blockchainClient: this.blockchainConfig.ethereumClientName
};
this.generateConfig(this.dappConfigs.blockchain, constants.dappConfig.blockchain);
}
generateStorageConfig(storageConfig) {
this.dappConfigs.storage = {
dappConnection: storageConfig.dappConnection
};
this.generateConfig(this.dappConfigs.storage, constants.dappConfig.storage);
}
generateConfig(configObj, filepathName) {
const dir = utils.joinPath(this.embarkConfig.generationDir, constants.dappConfig.dir);
const filePath = utils.joinPath(dir, constants.dappConfig.blockchain);
const configString = JSON.stringify(this.dappConfigs.blockchain, null, 2);
const filePath = utils.joinPath(dir, filepathName);
const configString = JSON.stringify(configObj, null, 2);
async.waterfall([
(next) => {
fs.mkdirp(dir, next);
@ -338,7 +353,7 @@ class CodeGenerator {
names: this.namesystemConfig || {},
storage: this.storageConfig || {}
};
return this.plugins.getPluginsFor("initConsoleCode").reduce((acc, plugin) => {
Object.keys(codeTypes).forEach((codeTypeName) => {
(plugin.embarkjs_init_console_code[codeTypeName] || []).forEach((initCode) => {

View File

@ -27,5 +27,6 @@
"optimize": true,
"optimize-runs": 200
}
}
},
"generationDir": "embarkArtifacts"
}