Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions lib/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,14 @@ class Cmd {
build() {
program
.command('build [environment]')
.option('--logfile [logfile]', 'filename to output logs (default: none)')
.option('--loglevel [loglevel]', 'level of logging to display ["error", "warn", "info", "debug", "trace"]', /^(error|warn|info|debug|trace)$/i, 'debug')
.description('deploy and build dapp at dist/ (default: development)')
.action(function (env, _options) {
embark.build({env: env || 'development'});
_options.env = env || 'development';
_options.logFile = _options.logfile; // fix casing
_options.logLevel = _options.loglevel; // fix casing
embark.build(_options);
});
}

Expand All @@ -102,6 +107,7 @@ class Cmd {
.option('--nodashboard', 'simple mode, disables the dashboard')
.option('--no-color', 'no colors in case it\'s needed for compatbility purposes')
.option('--logfile [logfile]', 'filename to output logs (default: none)')
.option('--loglevel [loglevel]', 'level of logging to display ["error", "warn", "info", "debug", "trace"]', /^(error|warn|info|debug|trace)$/i, 'debug')
.description('run dapp (default: development)')
.action(function (env, options) {
embark.run({
Expand All @@ -110,7 +116,8 @@ class Cmd {
serverHost: options.host,
runWebserver: !options.noserver,
useDashboard: !options.nodashboard,
logfile: options.logfile
logFile: options.logfile,
logLevel: options.loglevel
});
});
}
Expand Down Expand Up @@ -169,15 +176,18 @@ class Cmd {

upload() {
program
.command('upload [platform] [environment]')
.command('upload <platform> [environment]')
.option('--logfile [logfile]', 'filename to output logs (default: none)')
.description('upload your dapp to a decentralized storage (e.g embark upload ipfs)')
.option('--loglevel [loglevel]', 'level of logging to display ["error", "warn", "info", "debug", "trace"]', /^(error|warn|info|debug|trace)$/i, 'debug')
.description('Upload your dapp to a decentralized storage (e.g embark upload ipfs).')
.action(function (platform, env, _options) {
let environment = env || 'development';
embark.initConfig(environment, {
embarkConfig: 'embark.json', interceptLogs: false
});
_options.env = environment;
_options.logFile = _options.logfile; // fix casing
_options.logLevel = _options.loglevel; // fix casing
embark.upload(platform, _options);
});
}
Expand All @@ -189,7 +199,7 @@ class Cmd {
.action(function (env, options) {
embark.graph({
env: env || 'development',
logfile: options.logfile
logFile: options.logfile
});
});
}
Expand Down
8 changes: 5 additions & 3 deletions lib/core/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ class Engine {
this.embarkConfig = options.embarkConfig;
this.interceptLogs = options.interceptLogs;
this.version = options.version;
this.logfile = options.logfile;
this.logFile = options.logFile;
this.logLevel = options.logLevel;
this.events = options.events;
}

init(_options) {
let self = this;
let options = _options || {};
this.events = new Events();
this.logger = options.logger || new Logger({logLevel: options.logLevel || 'debug', events: this.events, logfile: this.logfile});
this.events = options.events || this.events || new Events();
this.logger = options.logger || new Logger({logLevel: options.logLevel || this.logLevel || 'debug', events: this.events, logFile: this.logFile});
this.config = new Config({env: this.env, logger: this.logger, events: this.events});
this.config.loadConfigFiles({embarkConfig: this.embarkConfig, interceptLogs: this.interceptLogs});
this.plugins = this.config.plugins;
Expand Down
6 changes: 3 additions & 3 deletions lib/core/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ class Logger {
this.logLevels = ['error', 'warn', 'info', 'debug', 'trace'];
this.logLevel = options.logLevel || 'info';
this.logFunction = options.logFunction || console.log;
this.logfile = options.logfile;
this.logFile = options.logFile;
}
}

Logger.prototype.writeToFile = function (txt) {
if (!this.logfile) {
if (!this.logFile) {
return;
}

fs.appendFileSync(this.logfile, "\n" + txt);
fs.appendFileSync(this.logFile, "\n" + txt);
};

Logger.prototype.error = function (txt) {
Expand Down
61 changes: 31 additions & 30 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class Embark {
env: options.env,
version: this.version,
embarkConfig: options.embarkConfig || 'embark.json',
logfile: options.logfile
logFile: options.logFile,
logLevel: options.logLevel
});
engine.init();

Expand Down Expand Up @@ -147,16 +148,20 @@ class Embark {
});
}

build(options, engine, continueProcessing) {
if(!engine){
engine = new Engine({
env: options.env,
version: this.version,
embarkConfig: 'embark.json',
interceptLogs: false
});
engine.init();
}
build(options, continueProcessing) {
let engine = new Engine({
env: options.env,
version: this.version,
embarkConfig: 'embark.json',
interceptLogs: false,
logFile: options.logFile,
logLevel: options.logLevel,
events: options.events,
logger: options.logger,
config: options.config,
plugins: options.plugins
});
engine.init();

async.waterfall([
function startServices(callback) {
Expand Down Expand Up @@ -204,7 +209,7 @@ class Embark {
env: options.env,
version: this.version,
embarkConfig: options.embarkConfig || 'embark.json',
logfile: options.logfile
logFile: options.logFile
});
engine.init();

Expand Down Expand Up @@ -252,61 +257,57 @@ class Embark {
// TODO: should deploy if it hasn't already
upload(platform, options) {

// populate options that were instantiated with initConfig to pass around
options.buildDir = 'dist/';
options.storageConfig = this.config.storageConfig;

// initialise embark engine
let engine = new Engine({
env: options.env,
version: this.version,
embarkConfig: options.embarkConfig || 'embark.json',
logfile: options.logfile
});
engine.init();
options.events = this.events;
options.logger = this.logger;
options.config = this.config;

// load plugins
this.plugins.loadInternalPlugin('ipfs', options);
this.plugins.loadInternalPlugin('swarm', options);

let plugins = this.plugins;
// upddate our options with loaded plugins
options.plugins = this.plugins;

let cmdPlugin;
let self = this;
async.waterfall([
function setupStoragePlugin(callback){
// check use has input existing storage plugin
let cmdPlugins = plugins.getPluginsFor('uploadCmds');
let cmdPlugins = self.plugins.getPluginsFor('uploadCmds');

if (cmdPlugins.length > 0) {
cmdPlugin = cmdPlugins.find((pluginCmd) => {
return pluginCmd.name == platform;
});
}
if (!cmdPlugin) {
engine.logger.info('try "embark upload ipfs" or "embark upload swarm"'.green);
self.logger.info('try "embark upload ipfs" or "embark upload swarm"'.green);
callback({message: 'unknown platform: ' + platform});
} else {
callback();
}
},
function buildAndDeployContracts(callback){
// 2. upload to storage (outputDone event triggered after webpack finished)
engine.events.on('outputDone', function () {
engine.logger.info('deploying to ' + platform + '...');
self.events.on('outputDone', function () {
cmdPlugin.uploadCmds[0].cb()
.then((success) => {
callback(null, success);
})
.catch(callback);
});
// 1. build the contracts and dapp webpack
self.build(options, engine, true);
self.build(options, true);
}
], function (err, _result) {
if (err) {
engine.logger.error(err.message);
engine.logger.debug(err.stack);
self.logger.error(err.message);
self.logger.debug(err.stack);
} else {
engine.logger.info("finished building dapp and deploying to " + platform.underline);
self.logger.info("finished building dapp and deploying to " + platform.underline);
}

// needed due to child processes
Expand Down
7 changes: 4 additions & 3 deletions lib/modules/ipfs/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class IPFS {

deploy() {
return new Promise((resolve, reject) => {
console.log("deploying!");
console.log("deploying to ipfs!");
let self = this;
async.waterfall([
function findBinary(callback) {
Expand All @@ -29,8 +29,9 @@ class IPFS {
function runCommand(ipfs_bin, callback) {
let cmd = `"${ipfs_bin}" add -r ${self.buildDir}`;
console.log(("=== adding " + self.buildDir + " to ipfs").green);
console.log(cmd.green);
shelljs.exec(cmd, function(code, stdout, stderr){
console.trace(cmd);
shelljs.exec(cmd, {silent:true}, function(code, stdout, stderr){ // {silent:true}: don't echo cmd output so it can be controlled via logLevel
console.log(stdout.green);
callback(stderr, stdout);
});
},
Expand Down
6 changes: 4 additions & 2 deletions lib/modules/swarm/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Swarm {

deploy() {
return new Promise((resolve, reject) => {
console.log("deploying to swarm!");
let self = this;
async.waterfall([
function findBinary(callback) {
Expand All @@ -25,8 +26,9 @@ class Swarm {
function runCommand(swarm_bin, callback) {
let cmd = `"${swarm_bin}" --defaultpath ${self.buildDir} index.html --recursive up ${self.buildDir}`;
console.log(("=== adding " + self.buildDir + " to swarm").green);
console.log(cmd.green);
shelljs.exec(cmd, function(code, stdout, stderr){
console.trace(cmd);
shelljs.exec(cmd, {silent:true}, function(code, stdout, stderr){ // {silent:true}: don't echo cmd output so it can be controlled via logLevel
console.log(stdout.green);
callback(stderr, {code: code, output: stdout});
});
},
Expand Down