working run

This commit is contained in:
Iuri Matias 2016-08-17 20:29:41 -04:00
parent 421a0af41e
commit 88381bdda1
9 changed files with 296 additions and 214 deletions

View File

@ -1,193 +1,4 @@
#!/usr/bin/env node
var program = require('commander');
var path = require('path');
var wrench = require('wrench');
var grunt = require('grunt');
require('shelljs/global');
var readYaml = require('read-yaml');
var Embark = require('..');
var run = function(cmd) {
if (exec(cmd).code != 0) {
exit();
}
}
var deploy = function(env, embarkConfig, cb) {
var contractFiles = grunt.file.expand(embarkConfig.contracts);
var destFile = embarkConfig.output;
Embark.init();
Embark.blockchainConfig.loadConfigFile(embarkConfig.blockchainConfig);
Embark.contractsConfig.loadConfigFile(embarkConfig.contractsConfig);
var chainFile = Embark.blockchainConfig.blockchainConfig[env].chains || embarkConfig.chains || './chains.json';
abi = Embark.deployContracts(env, contractFiles, destFile, chainFile, true, true, function(abi) {
grunt.file.write(destFile, abi);
cb();
});
}
program
.version('1.2.0');
program.command('new [name]').description('New application').action(function(name) {
if (name === undefined) {
console.log("please specify the app name");
exit;
}
var prefPath = path.join(__dirname + '/../boilerplate');
var targetDir = "./" + name;
wrench.copyDirSyncRecursive(prefPath, targetDir);
cd(targetDir);
run('npm install');
console.log('\n\ninit complete');
});
program.command('deploy [env]').description('deploy contracts').action(function(env_) {
var env = env_ || 'development';
var embarkConfig = readYaml.sync("./embark.yml");
if (embarkConfig.type === "grunt") {
run("grunt deploy_contracts:" + env);
}
else {
deploy(env, embarkConfig, function() { exit(); });
}
});
program.command('build [env]').description('build dapp').action(function(env_) {
var env = env_ || 'development';
var embarkConfig = readYaml.sync("./embark.yml");
if (embarkConfig.type === "grunt") {
run("grunt clean");
run("grunt deploy_contracts:" + env);
run('grunt build --env=' + env);
}
else if (embarkConfig.type === "meteor") {
deploy(env, embarkConfig);
run("meteor-build-client ./build -p ''");
}
});
program.command('ipfs [env]').description('build dapp and make it available in ipfs').action(function(env_) {
var env = env_ || 'development';
var embarkConfig = readYaml.sync("./embark.yml");
if (embarkConfig.type === "grunt") {
run("grunt clean")
run("grunt deploy_contracts:" + env)
run('grunt build --env=' + env)
run('grunt ipfs --env=' + env)
}
else if (embarkConfig.type === "meteor") {
deploy(env, embarkConfig);
run("meteor-build-client ./build -p ''");
Embark.release.ipfs("build/")
}
else {
console.log("command not available in manual mode yet");
}
});
program.command('run [env]').description('run dapp').action(function(env_) {
var env = env_ || 'development';
var embarkConfig = readYaml.sync("./embark.yml");
if (embarkConfig.type === "grunt") {
run('grunt deploy --env=' + env);
}
else {
console.log("command not available in meteor or manual mode yet");
console.log("try instead embark deploy; if using meteor then follow that with 'meteor'");
}
});
program.command('spec').description('run tests').action(function() {
var embarkConfig = readYaml.sync("./embark.yml");
if (embarkConfig.type === "grunt") {
run('mocha test/ --no-timeouts');
}
else {
console.log("command not available in meteor or manual mode yet");
console.log("note: you can use embark tests with any framework");
console.log("try running mocha test/");
}
});
program.command('blockchain [env]').description('run blockchain').action(function(env_) {
var env = env_ || 'development';
var embarkConfig = readYaml.sync("./embark.yml");
if (embarkConfig.type === "grunt") {
run('grunt blockchain:' + env);
}
else {
Embark.init()
Embark.blockchainConfig.loadConfigFile(embarkConfig.blockchainConfig)
Embark.contractsConfig.loadConfigFile(embarkConfig.contractsConfig)
Embark.copyMinerJavascriptToTemp();
Embark.startBlockchain(env, true);
}
});
program.command('geth <env> [args...]').description('run geth with specified arguments').action(function(env_, args_) {
var env = env_ || 'development';
var embarkConfig = readYaml.sync("./embark.yml");
var args = args_.join(' ');
Embark.init()
Embark.blockchainConfig.loadConfigFile(embarkConfig.blockchainConfig)
Embark.contractsConfig.loadConfigFile(embarkConfig.contractsConfig)
Embark.geth(env, args);
});
program.command('demo').description('create a working dapp with a SimpleStorage contract').action(function() {
var boilerPath = path.join(__dirname + '/../boilerplate');
var demoPath = path.join(__dirname + '/../demo');
var targetDir = "./embark_demo";
wrench.copyDirSyncRecursive(boilerPath, targetDir);
wrench.copyDirSyncRecursive(demoPath + "/app", targetDir + "/app", {forceDelete: true});
wrench.copyDirSyncRecursive(demoPath + "/config", targetDir + "/config", {forceDelete: true});
wrench.copyDirSyncRecursive(demoPath + "/test", targetDir + "/test", {forceDelete: true});
cd(targetDir);
run('npm install');
console.log('\n\ninit complete');
});
program.command('meteor_demo').description('create a working meteor dapp with a SimpleStorage contract').action(function() {
var boilerPath = path.join(__dirname + '/../demo_meteor');
var targetDir = "./embark_demo";
wrench.copyDirSyncRecursive(boilerPath, targetDir);
console.log('\n\ninit complete');
});
program.command('simulator').description('run a fast ethereum rpc simulator').action(function() {
try {
var EtherSim = require('ethersim');
} catch(e) {
console.log('EtherSim not found; Please install it with "npm install ethersim --save"');
console.log('For more information see https://github.com/iurimatias/ethersim');
exit();
}
EtherSim.startServer();
});
program.parse(process.argv)
if (!process.argv.slice(2).length) {
program.outputHelp();
}
//exit();
Embark.process(process.argv)

193
bin/old_embark Executable file
View File

@ -0,0 +1,193 @@
#!/usr/bin/env node
var program = require('commander');
var path = require('path');
var wrench = require('wrench');
var grunt = require('grunt');
require('shelljs/global');
var readYaml = require('read-yaml');
var Embark = require('..');
var run = function(cmd) {
if (exec(cmd).code != 0) {
exit();
}
}
var deploy = function(env, embarkConfig, cb) {
var contractFiles = grunt.file.expand(embarkConfig.contracts);
var destFile = embarkConfig.output;
Embark.init();
Embark.blockchainConfig.loadConfigFile(embarkConfig.blockchainConfig);
Embark.contractsConfig.loadConfigFile(embarkConfig.contractsConfig);
var chainFile = Embark.blockchainConfig.blockchainConfig[env].chains || embarkConfig.chains || './chains.json';
abi = Embark.deployContracts(env, contractFiles, destFile, chainFile, true, true, function(abi) {
grunt.file.write(destFile, abi);
cb();
});
}
program
.version('1.2.0');
program.command('new [name]').description('New application').action(function(name) {
if (name === undefined) {
console.log("please specify the app name");
exit;
}
var prefPath = path.join(__dirname + '/../boilerplate');
var targetDir = "./" + name;
wrench.copyDirSyncRecursive(prefPath, targetDir);
cd(targetDir);
run('npm install');
console.log('\n\ninit complete');
});
program.command('deploy [env]').description('deploy contracts').action(function(env_) {
var env = env_ || 'development';
var embarkConfig = readYaml.sync("./embark.yml");
if (embarkConfig.type === "grunt") {
run("grunt deploy_contracts:" + env);
}
else {
deploy(env, embarkConfig, function() { exit(); });
}
});
program.command('build [env]').description('build dapp').action(function(env_) {
var env = env_ || 'development';
var embarkConfig = readYaml.sync("./embark.yml");
if (embarkConfig.type === "grunt") {
run("grunt clean");
run("grunt deploy_contracts:" + env);
run('grunt build --env=' + env);
}
else if (embarkConfig.type === "meteor") {
deploy(env, embarkConfig);
run("meteor-build-client ./build -p ''");
}
});
program.command('ipfs [env]').description('build dapp and make it available in ipfs').action(function(env_) {
var env = env_ || 'development';
var embarkConfig = readYaml.sync("./embark.yml");
if (embarkConfig.type === "grunt") {
run("grunt clean")
run("grunt deploy_contracts:" + env)
run('grunt build --env=' + env)
run('grunt ipfs --env=' + env)
}
else if (embarkConfig.type === "meteor") {
deploy(env, embarkConfig);
run("meteor-build-client ./build -p ''");
Embark.release.ipfs("build/")
}
else {
console.log("command not available in manual mode yet");
}
});
program.command('run [env]').description('run dapp').action(function(env_) {
var env = env_ || 'development';
var embarkConfig = readYaml.sync("./embark.yml");
if (embarkConfig.type === "grunt") {
run('grunt deploy --env=' + env);
}
else {
console.log("command not available in meteor or manual mode yet");
console.log("try instead embark deploy; if using meteor then follow that with 'meteor'");
}
});
program.command('spec').description('run tests').action(function() {
var embarkConfig = readYaml.sync("./embark.yml");
if (embarkConfig.type === "grunt") {
run('mocha test/ --no-timeouts');
}
else {
console.log("command not available in meteor or manual mode yet");
console.log("note: you can use embark tests with any framework");
console.log("try running mocha test/");
}
});
program.command('blockchain [env]').description('run blockchain').action(function(env_) {
var env = env_ || 'development';
var embarkConfig = readYaml.sync("./embark.yml");
if (embarkConfig.type === "grunt") {
run('grunt blockchain:' + env);
}
else {
Embark.init()
Embark.blockchainConfig.loadConfigFile(embarkConfig.blockchainConfig)
Embark.contractsConfig.loadConfigFile(embarkConfig.contractsConfig)
Embark.copyMinerJavascriptToTemp();
Embark.startBlockchain(env, true);
}
});
program.command('geth <env> [args...]').description('run geth with specified arguments').action(function(env_, args_) {
var env = env_ || 'development';
var embarkConfig = readYaml.sync("./embark.yml");
var args = args_.join(' ');
Embark.init()
Embark.blockchainConfig.loadConfigFile(embarkConfig.blockchainConfig)
Embark.contractsConfig.loadConfigFile(embarkConfig.contractsConfig)
Embark.geth(env, args);
});
program.command('demo').description('create a working dapp with a SimpleStorage contract').action(function() {
var boilerPath = path.join(__dirname + '/../boilerplate');
var demoPath = path.join(__dirname + '/../demo');
var targetDir = "./embark_demo";
wrench.copyDirSyncRecursive(boilerPath, targetDir);
wrench.copyDirSyncRecursive(demoPath + "/app", targetDir + "/app", {forceDelete: true});
wrench.copyDirSyncRecursive(demoPath + "/config", targetDir + "/config", {forceDelete: true});
wrench.copyDirSyncRecursive(demoPath + "/test", targetDir + "/test", {forceDelete: true});
cd(targetDir);
run('npm install');
console.log('\n\ninit complete');
});
program.command('meteor_demo').description('create a working meteor dapp with a SimpleStorage contract').action(function() {
var boilerPath = path.join(__dirname + '/../demo_meteor');
var targetDir = "./embark_demo";
wrench.copyDirSyncRecursive(boilerPath, targetDir);
console.log('\n\ninit complete');
});
program.command('simulator').description('run a fast ethereum rpc simulator').action(function() {
try {
var EtherSim = require('ethersim');
} catch(e) {
console.log('EtherSim not found; Please install it with "npm install ethersim --save"');
console.log('For more information see https://github.com/iurimatias/ethersim');
exit();
}
EtherSim.startServer();
});
program.parse(process.argv)
if (!process.argv.slice(2).length) {
program.outputHelp();
}
//exit();

View File

@ -2,7 +2,7 @@
"contracts": ["app/contracts/**"],
"app": {
"css/app.css": ["app/css/**"],
"js/app.js": ["app/js/**"],
"js/app.js": ["embark.js", "app/js/**"],
"index.html": "app/index.html"
},
"config": "config/"

View File

@ -6,11 +6,12 @@ contract SimpleStorage {
}
function set(uint x) {
for (uint same3=0; same3 < 3; same3++) {
storedData = same3;
}
//storedData = x;
//for (uint same3=0; same3 < 3; same3++) {
// storedData = same3;
//}
storedData = x;
}
function get() constant returns (uint retVal) {
return storedData;
}

View File

@ -1,7 +1,7 @@
{
"development": {
"rpcHost": "localhost",
"rpcPort": 8101,
"rpcPort": 8545,
"account": {
"password": "config/development/password"
}

View File

@ -2,7 +2,7 @@
"contracts": ["app/contracts/**"],
"app": {
"css/app.css": ["app/css/**"],
"js/app.js": ["app/js/**"],
"js/app.js": ["embark.js", "app/js/**"],
"index.html": "app/index.html"
},
"config": "config/"

View File

@ -2,7 +2,7 @@
var ABIGenerator = function(contractsManager) {
this.contractsManager = contractsManager;
this.rpcHost = 'localhost';
this.rpcPort = '8101';
this.rpcPort = '8545';
};
ABIGenerator.prototype.generateProvider = function() {
@ -36,4 +36,13 @@ ABIGenerator.prototype.generateContracts = function() {
return result;
};
ABIGenerator.prototype.generateABI = function() {
var result = "";
result += this.generateProvider();
result += this.generateContracts();
return result;
};
module.exports = ABIGenerator;

54
lib/cmd.js Normal file
View File

@ -0,0 +1,54 @@
var program = require('commander');
var colors = require('colors');
var Cmd = function(Embark) {
this.Embark = Embark;
};
Cmd.prototype.process = function(args) {
this.run();
this.simulator();
this.otherCommands();
program.parse(args);
};
Cmd.prototype.run = function() {
var self = this;
program
.command('run [environment]')
.description('run dapp (default: development)')
//.option('-e', '--environment', 'choose environment to run (default: development)')
.action(function(env, options) {
//var EtherSim = require('ethersim');
//EtherSim.startServer();
self.Embark.run(env || 'development');
});
};
Cmd.prototype.simulator = function() {
program
.command('simulator')
.description('run a fast ethereum rpc simulator')
.option('--ethersim', 'use ethersim as the rpc simulator [default]')
.action(function() {
var EtherSim;
try {
EtherSim = require('ethersim');
} catch(e) {
console.log('EtherSim not found; Please install it with "npm install ethersim --save"');
console.log('For more information see https://github.com/iurimatias/ethersim');
process.exit(1);
}
EtherSim.startServer();
});
};
Cmd.prototype.otherCommands = function() {
program
.command('*')
.action(function(env){
console.log('unknown command "%s"'.red, env);
});
};
module.exports = Cmd;

View File

@ -7,18 +7,25 @@ var mkdirp = require('mkdirp');
var colors = require('colors');
var chokidar = require('chokidar');
var Cmd = require('./cmd.js');
var Deploy = require('./deploy.js');
var ContractsManager = require('./contracts.js');
var ABIGenerator = require('./abi.js');
var Embark = {
process: function(args) {
var cmd = new Cmd(Embark);
cmd.process(args);
},
initConfig: function(configDir, files, env) {
this.contractsManager = new ContractsManager(configDir, files, env);
this.contractsManager.init();
return this.contractsManager;
},
deploy: function() {
deploy: function(done) {
async.waterfall([
function loadConfig(callback) {
var contractsManager = Embark.initConfig('config/', 'app/contracts/**/*.sol', 'development');
@ -30,7 +37,7 @@ var Embark = {
},
function deployContracts(contractsManager, callback) {
var web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8101'));
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));
var deploy = new Deploy(web3, contractsManager);
deploy.deployAll(function() {
callback(null, contractsManager);
@ -38,22 +45,20 @@ var Embark = {
},
function generateABI(contractsManager, callback) {
var abiGenerator = new ABIGenerator(contractsManager);
console.log(abiGenerator.generateProvider());
console.log(abiGenerator.generateContracts());
callback(null, 'done');
callback(null, abiGenerator.generateABI());
},
], function(err, result) {
console.log(arguments);
done(result);
});
},
buildAssets: function() {
buildAssets: function(abi) {
var embarkConfig = JSON.parse(fs.readFileSync("embark.json"));
var appConfig = embarkConfig.app;
for(var targetFile in appConfig) {
var originalFiles = grunt.file.expand(appConfig[targetFile]);
var originalFiles = grunt.file.expand({nonull: true}, appConfig[targetFile]);
console.log(originalFiles);
// remove duplicates
@ -61,7 +66,11 @@ var Embark = {
return file.indexOf('.') >= 0;
}).map(function(file) {
console.log("reading " + file);
return fs.readFileSync(file);
if (file === 'embark.js') {
return fs.readFileSync("../js/web3.js") + "\n" + abi;
} else {
return fs.readFileSync(file);
}
}).join("\n");
var dir = targetFile.split('/').slice(0, -1).join('/');
@ -92,7 +101,7 @@ var Embark = {
callback();
},
watch: function() {
watch: function() {
var embarkConfig = JSON.parse(fs.readFileSync("embark.json"));
var appConfig = embarkConfig.app;
@ -115,13 +124,18 @@ var Embark = {
.on('unlink', path => console.log(`File ${path} has been removed`))
.on('ready', () => console.log('ready to watch changes'));
console.log("done!");
},
run: function(env) {
Embark.deploy(function(abi) {
Embark.buildAssets(abi);
Embark.server(function() {
Embark.watch();
});
});
}
};
//module.exports = Embark;
Embark.buildAssets();
Embark.server(function() {
Embark.watch();
});
module.exports = Embark;