mirror of https://github.com/embarklabs/embark.git
move upload to its own module
This commit is contained in:
parent
eb43fa2526
commit
50f1072372
|
@ -148,7 +148,7 @@ class Cmd {
|
||||||
upload() {
|
upload() {
|
||||||
program
|
program
|
||||||
.command('upload [platform] [environment]')
|
.command('upload [platform] [environment]')
|
||||||
.description('upload your dapp to a decentralized storage. possible options: ipfs, swarm (e.g embark upload swarm)')
|
.description('upload your dapp to a decentralized storage (e.g embark upload ipfs)')
|
||||||
.action(function (platform, env, _options) {
|
.action(function (platform, env, _options) {
|
||||||
// TODO: get env in cmd line as well
|
// TODO: get env in cmd line as well
|
||||||
embark.initConfig(env || 'development', {
|
embark.initConfig(env || 'development', {
|
||||||
|
|
|
@ -20,6 +20,7 @@ var Plugin = function(options) {
|
||||||
this.compilers = [];
|
this.compilers = [];
|
||||||
this.serviceChecks = [];
|
this.serviceChecks = [];
|
||||||
this.pluginTypes = [];
|
this.pluginTypes = [];
|
||||||
|
this.uploadCmds = [];
|
||||||
this.logger = options.logger;
|
this.logger = options.logger;
|
||||||
this.events = options.events;
|
this.events = options.events;
|
||||||
this.config = options.config;
|
this.config = options.config;
|
||||||
|
@ -136,6 +137,11 @@ Plugin.prototype.registerCompiler = function(extension, cb) {
|
||||||
this.pluginTypes.push('compilers');
|
this.pluginTypes.push('compilers');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Plugin.prototype.registerUploadCommand = function(cmd, cb) {
|
||||||
|
this.uploadCmds.push({cmd: cmd, cb: cb});
|
||||||
|
this.pluginTypes.push('uploadCmds');
|
||||||
|
};
|
||||||
|
|
||||||
Plugin.prototype.runCommands = function(cmd, options) {
|
Plugin.prototype.runCommands = function(cmd, options) {
|
||||||
return this.console.map(function(cb) {
|
return this.console.map(function(cb) {
|
||||||
return cb.call(this, cmd, options);
|
return cb.call(this, cmd, options);
|
||||||
|
|
27
lib/index.js
27
lib/index.js
|
@ -6,9 +6,6 @@ require('colors');
|
||||||
|
|
||||||
let Engine = require('./core/engine.js');
|
let Engine = require('./core/engine.js');
|
||||||
|
|
||||||
let IPFS = require('./upload/ipfs.js');
|
|
||||||
let Swarm = require('./upload/swarm.js');
|
|
||||||
|
|
||||||
let version = require('../package.json').version;
|
let version = require('../package.json').version;
|
||||||
|
|
||||||
class Embark {
|
class Embark {
|
||||||
|
@ -191,12 +188,24 @@ class Embark {
|
||||||
|
|
||||||
// TODO: should deploy if it hasn't already
|
// TODO: should deploy if it hasn't already
|
||||||
upload(platform) {
|
upload(platform) {
|
||||||
if (platform === 'ipfs') {
|
let options = {
|
||||||
let ipfs = new IPFS({buildDir: 'dist/', plugins: this.plugins, storageConfig: this.config.storageConfig});
|
buildDir: 'dist/',
|
||||||
ipfs.deploy();
|
storageConfig: this.config.storageConfig
|
||||||
} else if (platform === 'swarm') {
|
};
|
||||||
let swarm = new Swarm({buildDir: 'dist/', plugins: this.plugins, storageConfig: this.config.storageConfig});
|
|
||||||
swarm.deploy();
|
this.plugins.loadInternalPlugin('ipfs', options);
|
||||||
|
this.plugins.loadInternalPlugin('swarm', options);
|
||||||
|
|
||||||
|
let cmdPlugins = this.plugins.getPluginsFor('uploadCmds');
|
||||||
|
let cmdPlugin;
|
||||||
|
if (cmdPlugins.length > 0) {
|
||||||
|
cmdPlugin = cmdPlugins.find((pluginCmd) => {
|
||||||
|
return pluginCmd.name == platform;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cmdPlugin) {
|
||||||
|
cmdPlugin.uploadCmds[0].cb();
|
||||||
} else {
|
} else {
|
||||||
console.log(("unknown platform: " + platform).red);
|
console.log(("unknown platform: " + platform).red);
|
||||||
console.log('try "embark upload ipfs" or "embark upload swarm"'.green);
|
console.log('try "embark upload ipfs" or "embark upload swarm"'.green);
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
let UploadIPFS = require('./upload.js');
|
||||||
|
|
||||||
|
class IPFS {
|
||||||
|
|
||||||
|
constructor(embark, options) {
|
||||||
|
this.logger = embark.logger;
|
||||||
|
|
||||||
|
this.upload_ipfs = new UploadIPFS({
|
||||||
|
buildDir: options.buildDir || 'dist/',
|
||||||
|
storageConfig: options.storageConfig,
|
||||||
|
configIpfsBin: options.storageConfig.ipfs_bin || "ipfs"
|
||||||
|
});
|
||||||
|
|
||||||
|
embark.registerUploadCommand('ipfs', this.upload_ipfs.deploy.bind(this.upload_ipfs));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = IPFS;
|
|
@ -7,12 +7,12 @@ class IPFS {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.options = options;
|
this.options = options;
|
||||||
this.buildDir = options.buildDir || 'dist/';
|
this.buildDir = options.buildDir || 'dist/';
|
||||||
this.plugins = options.plugins;
|
|
||||||
this.storageConfig = options.storageConfig;
|
this.storageConfig = options.storageConfig;
|
||||||
this.configIpfsBin = this.storageConfig.ipfs_bin || "ipfs";
|
this.configIpfsBin = this.storageConfig.ipfs_bin || "ipfs";
|
||||||
}
|
}
|
||||||
|
|
||||||
deploy() {
|
deploy() {
|
||||||
|
console.log("deploying!");
|
||||||
let self = this;
|
let self = this;
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function findBinary(callback) {
|
function findBinary(callback) {
|
|
@ -0,0 +1,19 @@
|
||||||
|
let UploadSwarm = require('./upload.js');
|
||||||
|
|
||||||
|
class Swarm {
|
||||||
|
|
||||||
|
constructor(embark, options) {
|
||||||
|
this.logger = embark.logger;
|
||||||
|
|
||||||
|
this.upload_swarm = new UploadSwarm({
|
||||||
|
buildDir: options.buildDir || 'dist/',
|
||||||
|
storageConfig: options.storageConfig
|
||||||
|
});
|
||||||
|
|
||||||
|
embark.registerUploadCommand('swarm', this.upload_swarm.deploy.bind(this.upload_swarm));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Swarm;
|
||||||
|
|
Loading…
Reference in New Issue