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 */
var shelljs = require('shelljs');
var shelljs_global = require('shelljs/global');
var fs = require('fs');
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) {
this.plugins = options.plugins;
};
Compiler.prototype.compile_contracts = function(contractFiles) {
Compiler.prototype.compile_contracts = function(contractFiles, cb) {
var available_compilers = {
//".se": this.compile_serpent
@ -29,20 +37,25 @@ Compiler.prototype.compile_contracts = function(contractFiles) {
var compiledObject = {};
// TODO: warn about files it doesn't know how to compile
for (var extension in available_compilers) {
var compiler = available_compilers[extension];
var matchingFiles = contractFiles.filter(function(file) {
return (file.filename.match(/\.[0-9a-z]+$/)[0] === extension);
});
async.eachObject(available_compilers,
function(extension, compiler, callback) {
// TODO: warn about files it doesn't know how to compile
var matchingFiles = contractFiles.filter(function(file) {
return (file.filename.match(/\.[0-9a-z]+$/)[0] === extension);
});
Object.assign(compiledObject, compiler.call(compiler, matchingFiles || []));
}
return compiledObject;
compiler.call(compiler, matchingFiles || [], function(compileResult) {
Object.assign(compiledObject, compileResult);
callback();
});
},
function (err) {
cb(compiledObject);
}
);
};
Compiler.prototype.compile_solidity = function(contractFiles) {
Compiler.prototype.compile_solidity = function(contractFiles, cb) {
var input = {};
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);
}
return 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;
cb(compiled_object);
};
module.exports = Compiler;

View File

@ -198,8 +198,11 @@ Config.prototype.loadFiles = function(files) {
}).filter(function(file) {
if (file === 'embark.js') {
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;

View File

@ -2,6 +2,7 @@ var Web3 = require('web3');
var Console = function(options) {
this.plugins = options.plugins;
this.version = options.version;
};
Console.prototype.runCode = function(code) {
@ -19,9 +20,12 @@ Console.prototype.executeCmd = function(cmd, callback) {
if (cmd === 'help') {
var helpText = [
'Welcome to Embark 2',
'Welcome to Embark ' + this.version,
'',
'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',
'',
'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);
}
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([
function compileContracts(callback) {
var compiler = new Compiler({plugins: self.plugins});
// TODO: check if try is still needed
try {
self.compiledContracts = compiler.compile_contracts(self.contractFiles);
compiler.compile_contracts(self.contractFiles, function(compiledObject) {
self.compiledContracts = compiledObject;
callback();
});
} catch(err) {
return callback(new Error(err.message));
}
return callback();
},
function prepareContractsFromConfig(callback) {
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);
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;
self.logger.contractsState(self.contractsManager.contractsState());
return callback();
@ -118,12 +118,12 @@ Deploy.prototype.deployContract = function(contract, params, callback) {
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) {
self.logger.contractsState(self.contractsManager.contractsState());
if (err) {
self.logger.error("error deploying contract: " + contract.className);
self.logger.error("error deploying contract: " + contract.className.cyan);
var errMsg = err.toString();
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';
@ -132,7 +132,7 @@ Deploy.prototype.deployContract = function(contract, params, callback) {
contract.error = errMsg;
return callback(new Error(err));
} 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.transactionHash = transaction.transactionHash;
return callback(null, transaction.address);
@ -158,7 +158,7 @@ Deploy.prototype.deployAll = function(done) {
self.logger.error(err.message);
self.logger.debug(err.stack);
}
self.logger.info("finished");
self.logger.info("finished deploying contracts");
self.logger.trace(arguments);
done();
}

View File

@ -79,7 +79,7 @@ var Embark = {
callback();
},
function startConsole(callback) {
Embark.console = new Console({plugins: self.plugins});
Embark.console = new Console({plugins: self.plugins, version: self.version});
callback();
},
function startMonitor(callback) {
@ -101,6 +101,13 @@ var Embark = {
// TODO: do this after monitor is rendered
callback();
},
function displayLoadedPlugins(callback) {
var pluginList = self.plugins.listPlugins();
if (pluginList.length > 0) {
self.logger.info("loaded plugins: " + pluginList.join(", "));
}
callback();
},
function monitorServices(callback) {
if (!options.useDashboard) {
return callback();
@ -117,18 +124,6 @@ var Embark = {
callback();
},
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) {
self.logger.setStatus("Watching for changes");
var watch = new Watch({logger: self.logger});
@ -144,19 +139,25 @@ var Embark = {
});
callback();
},
function displayLoadedPlugins(callback) {
var pluginList = self.plugins.listPlugins();
if (pluginList.length > 0) {
self.logger.info("loaded plugins: " + pluginList.join(", "));
function startAssetServer(callback) {
if (!options.runWebserver) {
return callback();
}
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) {
if (err) {
self.logger.error(err.message);
} else {
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) {
if (data !== '') {
self.history.addCommand(data);
self.logText.log('console> ' + data);
self.logText.log('console> '.bold.green + data);
self.console.executeCmd(data, function(result) {
self.logText.log(result);
});

View File

@ -21,6 +21,8 @@ Pipeline.prototype.build = function(abi) {
if (file.filename === 'embark.js') {
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) {
file.modified = true;
return file;
@ -46,7 +48,7 @@ Pipeline.prototype.build = function(abi) {
});
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);
// if it's a directory
@ -60,7 +62,7 @@ Pipeline.prototype.build = function(abi) {
contentFiles.map(function(file) {
var filename = file.filename.replace('app/', '');
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));
});
@ -69,7 +71,7 @@ Pipeline.prototype.build = function(abi) {
return file.content;
}).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);
}
}

View File

@ -16,7 +16,7 @@ Server.prototype.start = function(callback) {
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) ;
callback();
};

View File

@ -25,7 +25,7 @@ Watch.prototype.start = function() {
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) {

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() {
var plugins = new Plugins({plugins: {}});
var console = new Console({plugins: plugins});
var console = new Console({plugins: plugins, version: '2.3.1'});
describe('#executeCmd', function() {
@ -14,7 +14,7 @@ describe('embark.Console', function() {
it('it should provide a help text', function(done) {
console.executeCmd('help', function(output) {
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:');
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/**"],
"images/": ["app/images/**"],
"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",
"test.html": "app/test.html"
},