embark/lib/modules/storage/index.js

43 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-07-07 16:29:04 +00:00
class Storage {
2018-07-08 20:41:37 +00:00
constructor(embark, options){
2018-07-07 18:23:51 +00:00
this.embark = embark;
this.storageConfig = embark.config.storageConfig;
2018-07-08 20:41:37 +00:00
this.plugins = options.plugins;
2018-07-07 18:23:51 +00:00
if (!this.storageConfig.enabled) return;
this.handleUploadCommand();
2018-07-07 16:49:18 +00:00
this.addSetProviders();
}
handleUploadCommand() {
const self = this;
this.embark.events.setCommandHandler('storage:upload', (cb) => {
let platform = self.storageConfig.upload.provider;
2018-07-08 20:41:37 +00:00
let uploadCmds = self.plugins.getPluginsProperty('uploadCmds', 'uploadCmds');
for (let uploadCmd of uploadCmds) {
if (uploadCmd.cmd === platform) {
return uploadCmd.cb.call(uploadCmd.cb, cb);
}
}
2018-07-07 21:02:46 +00:00
cb({message: __('platform "{{platform}}" is specified as the upload provider, however no plugins have registered an upload command for "{{platform}}".', {platform: platform})});
});
}
addSetProviders() {
let code = `\nEmbarkJS.Storage.setProviders(${JSON.stringify(this.storageConfig.dappConnection || [])});`;
let shouldInit = (storageConfig) => {
return storageConfig.enabled;
};
2018-06-01 16:53:23 +00:00
2018-07-07 18:23:51 +00:00
this.embark.addProviderInit('storage', code, shouldInit);
2018-06-01 16:53:23 +00:00
}
}
module.exports = Storage;