Merge remote-tracking branch 'upstream/develop' into develop

This commit is contained in:
Andy Nogueira 2017-02-17 09:38:53 -05:00
commit 97de27e0c2
14 changed files with 101 additions and 131 deletions

View File

@ -1,15 +1,23 @@
/*jshint esversion: 6, loopfunc: true */ /*jshint esversion: 6, loopfunc: true */
var shelljs = require('shelljs');
var shelljs_global = require('shelljs/global');
var fs = require('fs');
var solc = require('solc'); var solc = require('solc');
var merge = require('merge'); var async = require('async');
function asyncEachObject(object, iterator, callback) {
async.each(
Object.keys(object || {}),
function(key, next){
iterator(key, object[key], next);
},
callback
);
}
async.eachObject = asyncEachObject;
var Compiler = function(options) { var Compiler = function(options) {
this.plugins = options.plugins; this.plugins = options.plugins;
}; };
Compiler.prototype.compile_contracts = function(contractFiles) { Compiler.prototype.compile_contracts = function(contractFiles, cb) {
var available_compilers = { var available_compilers = {
//".se": this.compile_serpent //".se": this.compile_serpent
@ -29,20 +37,25 @@ Compiler.prototype.compile_contracts = function(contractFiles) {
var compiledObject = {}; var compiledObject = {};
// TODO: warn about files it doesn't know how to compile async.eachObject(available_compilers,
for (var extension in available_compilers) { function(extension, compiler, callback) {
var compiler = available_compilers[extension]; // TODO: warn about files it doesn't know how to compile
var matchingFiles = contractFiles.filter(function(file) { var matchingFiles = contractFiles.filter(function(file) {
return (file.filename.match(/\.[0-9a-z]+$/)[0] === extension); return (file.filename.match(/\.[0-9a-z]+$/)[0] === extension);
}); });
Object.assign(compiledObject, compiler.call(compiler, matchingFiles || [])); compiler.call(compiler, matchingFiles || [], function(compileResult) {
} Object.assign(compiledObject, compileResult);
callback();
return compiledObject; });
},
function (err) {
cb(compiledObject);
}
);
}; };
Compiler.prototype.compile_solidity = function(contractFiles) { Compiler.prototype.compile_solidity = function(contractFiles, cb) {
var input = {}; var input = {};
for (var i = 0; i < contractFiles.length; i++){ for (var i = 0; i < contractFiles.length; i++){
@ -72,77 +85,7 @@ Compiler.prototype.compile_solidity = function(contractFiles) {
compiled_object[className].abiDefinition = JSON.parse(contract.interface); compiled_object[className].abiDefinition = JSON.parse(contract.interface);
} }
return compiled_object; cb(compiled_object);
};
Compiler.prototype.compile_serpent = function(contractFiles) {
var cmd, result, output, json, compiled_object;
//TODO: figure out how to compile multiple files and get the correct json
var contractFile = contractFiles[0];
cmd = "serpent compile " + contractFile;
result = exec(cmd, {silent: true});
code = result.output;
if (result.code === 1) {
throw new Error(result.output);
}
cmd = "serpent mk_full_signature " + contractFile;
result = exec(cmd, {silent: true});
if (result.code === 1) {
throw new Error(result.output);
}
json = JSON.parse(result.output.trim());
className = contractFile.split('.')[0].split("/").pop();
for (var i=0; i < json.length; i++) {
var elem = json[i];
if (elem.outputs.length > 0) {
elem.constant = true;
}
}
compiled_object = {};
compiled_object[className] = {};
compiled_object[className].code = code.trim();
compiled_object[className].info = {};
compiled_object[className].abiDefinition = json;
return compiled_object;
};
Compiler.prototype.compile = function(contractFiles) {
var solidity = [], serpent = [];
for (var i = 0; i < contractFiles.length; i++) {
var contractParts = contractFiles[i].split('.'),
extension = contractParts[contractParts.length-1];
if (extension === 'sol') {
solidity.push(contractFiles[i]);
}
else if (extension === 'se') {
serpent.push(contractFiles[i]);
}
else {
throw new Error("extension not known, got " + extension);
}
}
var contracts = [];
if (solidity.length > 0) {
contracts.concat(this.compile_solidity(solidity));
}
if (serpent.length > 0) {
contracts.concat(this.compile_serpent(serpent));
}
return contracts;
}; };
module.exports = Compiler; module.exports = Compiler;

View File

@ -198,8 +198,11 @@ Config.prototype.loadFiles = function(files) {
}).filter(function(file) { }).filter(function(file) {
if (file === 'embark.js') { if (file === 'embark.js') {
return; return;
} else if (file === 'abi.js') {
readFiles.push({filename: file, content: "", path: file});
} else {
readFiles.push({filename: file, content: fs.readFileSync(file).toString(), path: file});
} }
readFiles.push({filename: file, content: fs.readFileSync(file).toString(), path: file});
}); });
return readFiles; return readFiles;

View File

@ -2,6 +2,7 @@ var Web3 = require('web3');
var Console = function(options) { var Console = function(options) {
this.plugins = options.plugins; this.plugins = options.plugins;
this.version = options.version;
}; };
Console.prototype.runCode = function(code) { Console.prototype.runCode = function(code) {
@ -19,9 +20,12 @@ Console.prototype.executeCmd = function(cmd, callback) {
if (cmd === 'help') { if (cmd === 'help') {
var helpText = [ var helpText = [
'Welcome to Embark 2', 'Welcome to Embark ' + this.version,
'', '',
'possible commands are:', 'possible commands are:',
// TODO: only if the blockchain is actually active!
// will need to pass te current embark state here
'web3 - instantiated web3.js object configured to the current environment',
'quit - to immediatly exit', 'quit - to immediatly exit',
'', '',
'The web3 object and the interfaces for the deployed contrats and their methods are also available' 'The web3 object and the interfaces for the deployed contrats and their methods are also available'
@ -36,7 +40,11 @@ Console.prototype.executeCmd = function(cmd, callback) {
return callback(result); return callback(result);
} }
catch(e) { catch(e) {
return callback(e.message.red); if (e.message.indexOf('not defined') > 0) {
return callback(("error: " + e.message).red + ("\nType " + "help".bold + " to see the list of available commands").cyan);
} else {
return callback(e.message);
}
} }
}; };

View File

@ -39,12 +39,15 @@ ContractsManager.prototype.build = function(done) {
async.waterfall([ async.waterfall([
function compileContracts(callback) { function compileContracts(callback) {
var compiler = new Compiler({plugins: self.plugins}); var compiler = new Compiler({plugins: self.plugins});
// TODO: check if try is still needed
try { try {
self.compiledContracts = compiler.compile_contracts(self.contractFiles); compiler.compile_contracts(self.contractFiles, function(compiledObject) {
self.compiledContracts = compiledObject;
callback();
});
} catch(err) { } catch(err) {
return callback(new Error(err.message)); return callback(new Error(err.message));
} }
return callback();
}, },
function prepareContractsFromConfig(callback) { function prepareContractsFromConfig(callback) {
var className, contract; var className, contract;

View File

@ -61,7 +61,7 @@ Deploy.prototype.checkAndDeployContract = function(contract, params, callback) {
var trackedContract = self.deployTracker.getContract(contract.className, contract.code, contract.args); var trackedContract = self.deployTracker.getContract(contract.className, contract.code, contract.args);
if (trackedContract && this.web3.eth.getCode(trackedContract.address) !== "0x") { if (trackedContract && this.web3.eth.getCode(trackedContract.address) !== "0x") {
self.logger.info(contract.className + " already deployed " + trackedContract.address); self.logger.info(contract.className.bold.cyan + " already deployed at ".green + trackedContract.address.bold.cyan);
contract.deployedAddress = trackedContract.address; contract.deployedAddress = trackedContract.address;
self.logger.contractsState(self.contractsManager.contractsState()); self.logger.contractsState(self.contractsManager.contractsState());
return callback(); return callback();
@ -118,12 +118,12 @@ Deploy.prototype.deployContract = function(contract, params, callback) {
gasPrice: contract.gasPrice gasPrice: contract.gasPrice
}); });
self.logger.info("deploying " + contract.className + " with " + contract.gas + " gas"); self.logger.info("deploying " + contract.className.bold.cyan + " with ".green + contract.gas + " gas".green);
contractParams.push(function(err, transaction) { contractParams.push(function(err, transaction) {
self.logger.contractsState(self.contractsManager.contractsState()); self.logger.contractsState(self.contractsManager.contractsState());
if (err) { if (err) {
self.logger.error("error deploying contract: " + contract.className); self.logger.error("error deploying contract: " + contract.className.cyan);
var errMsg = err.toString(); var errMsg = err.toString();
if (errMsg === 'Error: The contract code couldn\'t be stored, please check your gas amount.') { if (errMsg === 'Error: The contract code couldn\'t be stored, please check your gas amount.') {
errMsg = 'The contract code couldn\'t be stored, out of gas or constructor error'; errMsg = 'The contract code couldn\'t be stored, out of gas or constructor error';
@ -132,7 +132,7 @@ Deploy.prototype.deployContract = function(contract, params, callback) {
contract.error = errMsg; contract.error = errMsg;
return callback(new Error(err)); return callback(new Error(err));
} else if (transaction.address !== undefined) { } else if (transaction.address !== undefined) {
self.logger.info(contract.className + " deployed at " + transaction.address); self.logger.info(contract.className.bold.cyan + " deployed at ".green + transaction.address.bold.cyan);
contract.deployedAddress = transaction.address; contract.deployedAddress = transaction.address;
contract.transactionHash = transaction.transactionHash; contract.transactionHash = transaction.transactionHash;
return callback(null, transaction.address); return callback(null, transaction.address);
@ -158,7 +158,7 @@ Deploy.prototype.deployAll = function(done) {
self.logger.error(err.message); self.logger.error(err.message);
self.logger.debug(err.stack); self.logger.debug(err.stack);
} }
self.logger.info("finished"); self.logger.info("finished deploying contracts");
self.logger.trace(arguments); self.logger.trace(arguments);
done(); done();
} }

View File

@ -79,7 +79,7 @@ var Embark = {
callback(); callback();
}, },
function startConsole(callback) { function startConsole(callback) {
Embark.console = new Console({plugins: self.plugins}); Embark.console = new Console({plugins: self.plugins, version: self.version});
callback(); callback();
}, },
function startMonitor(callback) { function startMonitor(callback) {
@ -101,6 +101,13 @@ var Embark = {
// TODO: do this after monitor is rendered // TODO: do this after monitor is rendered
callback(); callback();
}, },
function displayLoadedPlugins(callback) {
var pluginList = self.plugins.listPlugins();
if (pluginList.length > 0) {
self.logger.info("loaded plugins: " + pluginList.join(", "));
}
callback();
},
function monitorServices(callback) { function monitorServices(callback) {
if (!options.useDashboard) { if (!options.useDashboard) {
return callback(); return callback();
@ -117,18 +124,6 @@ var Embark = {
callback(); callback();
}, },
self.buildDeployGenerate.bind(self), self.buildDeployGenerate.bind(self),
function startAssetServer(callback) {
if (!options.runWebserver) {
return callback();
}
self.logger.setStatus("Starting Server");
var server = new Server({
logger: self.logger,
host: options.serverHost,
port: options.serverPort
});
server.start(callback);
},
function watchFilesForChanges(callback) { function watchFilesForChanges(callback) {
self.logger.setStatus("Watching for changes"); self.logger.setStatus("Watching for changes");
var watch = new Watch({logger: self.logger}); var watch = new Watch({logger: self.logger});
@ -144,19 +139,25 @@ var Embark = {
}); });
callback(); callback();
}, },
function displayLoadedPlugins(callback) { function startAssetServer(callback) {
var pluginList = self.plugins.listPlugins(); if (!options.runWebserver) {
if (pluginList.length > 0) { return callback();
self.logger.info("loaded plugins: " + pluginList.join(", "));
} }
callback(); self.logger.setStatus("Starting Server");
var server = new Server({
logger: self.logger,
host: options.serverHost,
port: options.serverPort
});
server.start(callback);
} }
], function(err, result) { ], function(err, result) {
if (err) { if (err) {
self.logger.error(err.message); self.logger.error(err.message);
} else { } else {
self.logger.setStatus("Ready".green); self.logger.setStatus("Ready".green);
self.logger.trace("finished".underline); self.logger.info("Looking for documentation? you can find it at ".cyan + "http://embark.readthedocs.io/".green.underline);
self.logger.info("Ready".underline);
} }
}); });
}, },

View File

@ -358,7 +358,7 @@ Dashboard.prototype.layoutCmd = function() {
this.input.on('submit', function(data) { this.input.on('submit', function(data) {
if (data !== '') { if (data !== '') {
self.history.addCommand(data); self.history.addCommand(data);
self.logText.log('console> ' + data); self.logText.log('console> '.bold.green + data);
self.console.executeCmd(data, function(result) { self.console.executeCmd(data, function(result) {
self.logText.log(result); self.logText.log(result);
}); });

View File

@ -21,6 +21,8 @@ Pipeline.prototype.build = function(abi) {
if (file.filename === 'embark.js') { if (file.filename === 'embark.js') {
return {content: file.content + "\n" + abi, filename: file.filename, path: file.path, modified: true}; return {content: file.content + "\n" + abi, filename: file.filename, path: file.path, modified: true};
} else if (file.filename === 'abi.js') {
return {content: abi, filename: file.filename, path: file.path, modified: true};
} else if (['web3.js', 'ipfs.js', 'ipfs-api.js', 'orbit.js'].indexOf(file.filename) >= 0) { } else if (['web3.js', 'ipfs.js', 'ipfs-api.js', 'orbit.js'].indexOf(file.filename) >= 0) {
file.modified = true; file.modified = true;
return file; return file;
@ -46,7 +48,7 @@ Pipeline.prototype.build = function(abi) {
}); });
var dir = targetFile.split('/').slice(0, -1).join('/'); var dir = targetFile.split('/').slice(0, -1).join('/');
self.logger.info("creating dir " + this.buildDir + dir); self.logger.trace("creating dir " + this.buildDir + dir);
mkdirp.sync(this.buildDir + dir); mkdirp.sync(this.buildDir + dir);
// if it's a directory // if it's a directory
@ -60,7 +62,7 @@ Pipeline.prototype.build = function(abi) {
contentFiles.map(function(file) { contentFiles.map(function(file) {
var filename = file.filename.replace('app/', ''); var filename = file.filename.replace('app/', '');
filename = filename.replace(targetDir, ''); filename = filename.replace(targetDir, '');
self.logger.info("writing file " + self.buildDir + targetDir + filename); self.logger.info("writing file " + (self.buildDir + targetDir + filename).bold.dim);
fs.writeFileSync(self.buildDir + targetDir + filename, fs.readFileSync(file.path)); fs.writeFileSync(self.buildDir + targetDir + filename, fs.readFileSync(file.path));
}); });
@ -69,7 +71,7 @@ Pipeline.prototype.build = function(abi) {
return file.content; return file.content;
}).join("\n"); }).join("\n");
self.logger.info("writing file " + this.buildDir + targetFile); self.logger.info("writing file " + (this.buildDir + targetFile).bold.dim);
fs.writeFileSync(this.buildDir + targetFile, content); fs.writeFileSync(this.buildDir + targetFile, content);
} }
} }

View File

@ -16,7 +16,7 @@ Server.prototype.start = function(callback) {
serve(req, res, finalhandler(req, res)); serve(req, res, finalhandler(req, res));
}); });
this.logger.info(("webserver available at http://" + this.hostname + ":" + this.port).underline.green); this.logger.info("webserver available at " + ("http://" + this.hostname + ":" + this.port).bold.underline.green);
server.listen(this.port, this.hostname) ; server.listen(this.port, this.hostname) ;
callback(); callback();
}; };

View File

@ -25,7 +25,7 @@ Watch.prototype.start = function() {
self.logger.trace('ready to watch config changes'); self.logger.trace('ready to watch config changes');
}); });
this.logger.info("ready to watch changes"); this.logger.info("ready to watch file changes");
}; };
Watch.prototype.watchAssets = function(embarkConfig, callback) { Watch.prototype.watchAssets = function(embarkConfig, callback) {

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,7 @@ var assert = require('assert');
describe('embark.Console', function() { describe('embark.Console', function() {
var plugins = new Plugins({plugins: {}}); var plugins = new Plugins({plugins: {}});
var console = new Console({plugins: plugins}); var console = new Console({plugins: plugins, version: '2.3.1'});
describe('#executeCmd', function() { describe('#executeCmd', function() {
@ -14,7 +14,7 @@ describe('embark.Console', function() {
it('it should provide a help text', function(done) { it('it should provide a help text', function(done) {
console.executeCmd('help', function(output) { console.executeCmd('help', function(output) {
var lines = output.split('\n'); var lines = output.split('\n');
assert.equal(lines[0], 'Welcome to Embark 2'); assert.equal(lines[0], 'Welcome to Embark 2.3.1');
assert.equal(lines[2], 'possible commands are:'); assert.equal(lines[2], 'possible commands are:');
done(); done();
}); });

8
test_app/README.md Normal file
View File

@ -0,0 +1,8 @@
Test App for integration testing purposes.
```../bin/embark run``` to check if everything is behaving as expected
```../bin/embark test``` to see tests are working as expected
```dist/index.html``` and ```dist/test.html``` to check different functionality

View File

@ -4,6 +4,7 @@
"css/app.css": ["app/css/**"], "css/app.css": ["app/css/**"],
"images/": ["app/images/**"], "images/": ["app/images/**"],
"js/app.js": ["embark.js", "app/js/_vendor/jquery.min.js", "app/js/_vendor/bootstrap.min.js", "app/js/**"], "js/app.js": ["embark.js", "app/js/_vendor/jquery.min.js", "app/js/_vendor/bootstrap.min.js", "app/js/**"],
"js/abi.js": "abi.js",
"index.html": "app/index.html", "index.html": "app/index.html",
"test.html": "app/test.html" "test.html": "app/test.html"
}, },