mirror of https://github.com/embarklabs/embark.git
extract storage provider
This commit is contained in:
parent
9f40958e6a
commit
9ca337eeb1
|
@ -210,9 +210,17 @@ class CodeGenerator {
|
|||
|
||||
result += Templates.define_when_env_loaded();
|
||||
|
||||
if (self.storageConfig.provider === 'ipfs' && self.storageConfig.enabled === true) {
|
||||
let block = "\nEmbarkJS.Storage.setProvider('" + self.storageConfig.provider + "', {server: '" + self.storageConfig.host + "', port: '" + self.storageConfig.port + "', getUrl: '" + self.storageConfig.getUrl + "'});";
|
||||
result += Templates.exec_when_env_loaded({block: block});
|
||||
let pluginsWithCode = this.plugins.getPluginsFor('initCode');
|
||||
if (pluginsWithCode.length > 0) {
|
||||
for (let plugin of pluginsWithCode) {
|
||||
let initCodes = plugin.embarkjs_init_code.storage;
|
||||
for (let initCode of initCodes) {
|
||||
let [block, shouldInit] = initCode;
|
||||
if (shouldInit.call(plugin, self.storageConfig)) {
|
||||
result += Templates.exec_when_env_loaded({block: block});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -22,6 +22,7 @@ var Plugin = function(options) {
|
|||
this.pluginTypes = [];
|
||||
this.uploadCmds = [];
|
||||
this.embarkjs_code = [];
|
||||
this.embarkjs_init_code = {};
|
||||
this.logger = options.logger;
|
||||
this.events = options.events;
|
||||
this.config = options.config;
|
||||
|
@ -148,6 +149,12 @@ Plugin.prototype.addCodeToEmbarkJS = function(code) {
|
|||
this.pluginTypes.push('embarkjsCode');
|
||||
};
|
||||
|
||||
Plugin.prototype.addProviderInit = function(providerType, code, initCondition) {
|
||||
this.embarkjs_init_code[providerType] = this.embarkjs_init_code[providerType] || [];
|
||||
this.embarkjs_init_code[providerType].push([code, initCondition]);
|
||||
this.pluginTypes.push('initCode');
|
||||
};
|
||||
|
||||
Plugin.prototype.runCommands = function(cmd, options) {
|
||||
return this.console.map(function(cb) {
|
||||
return cb.call(this, cmd, options);
|
||||
|
|
|
@ -17,6 +17,7 @@ class IPFS {
|
|||
this.commandlineDeploy();
|
||||
this.setServiceCheck();
|
||||
this.addIPFSToEmbarkJS();
|
||||
this.addSetProvider();
|
||||
}
|
||||
|
||||
commandlineDeploy() {
|
||||
|
@ -98,6 +99,21 @@ class IPFS {
|
|||
|
||||
this.embark.addCodeToEmbarkJS(code);
|
||||
}
|
||||
|
||||
addSetProvider() {
|
||||
let config = JSON.stringify({
|
||||
server: this.storageConfig.host,
|
||||
port: this.storageConfig.port,
|
||||
getUrl: this.storageConfig.getUrl
|
||||
});
|
||||
let code = "\nEmbarkJS.Storage.setProvider('ipfs'," + config + ");";
|
||||
|
||||
let shouldInit = (storageConfig) => {
|
||||
return (storageConfig.provider === 'ipfs' && storageConfig.enabled === true);
|
||||
};
|
||||
|
||||
this.embark.addProviderInit('storage', code, shouldInit);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = IPFS;
|
||||
|
|
Loading…
Reference in New Issue