embark-area-51/bin/embark

188 lines
5.6 KiB
Plaintext
Raw Normal View History

2015-05-24 13:03:43 +00:00
#!/usr/bin/env node
var program = require('commander');
var path = require('path');
var wrench = require('wrench');
var grunt = require('grunt');
require('shelljs/global');
2015-07-07 10:51:03 +00:00
var readYaml = require('read-yaml');
2015-10-12 13:09:11 +00:00
var EtherSim = require('ethersim');
2015-08-25 23:56:00 +00:00
var Embark = require('..');
2015-05-24 13:03:43 +00:00
2015-06-10 12:43:15 +00:00
var run = function(cmd) {
if (exec(cmd).code != 0) {
exit();
}
}
2015-10-09 17:31:09 +00:00
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';
2015-10-09 17:31:09 +00:00
abi = Embark.deployContracts(env, contractFiles, destFile, chainFile, true, true, function(abi) {
grunt.file.write(destFile, abi);
cb();
});
2015-07-15 00:58:08 +00:00
}
2015-05-24 13:03:43 +00:00
program
2015-10-12 23:27:33 +00:00
.version('1.0.1');
2015-05-24 13:03:43 +00:00
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);
2015-06-10 12:43:15 +00:00
run('npm install');
2015-05-24 13:03:43 +00:00
console.log('\n\ninit complete');
});
program.command('deploy [env]').description('deploy contracts').action(function(env_) {
2015-07-07 10:51:03 +00:00
var env = env_ || 'development';
var embarkConfig = readYaml.sync("./embark.yml");
if (embarkConfig.type === "grunt") {
run("grunt deploy_contracts:" + env);
}
else {
2015-10-09 17:31:09 +00:00
deploy(env, embarkConfig, function() {});
}
2015-05-24 13:03:43 +00:00
});
program.command('build [env]').description('build dapp').action(function(env_) {
var env = env_ || 'development';
2015-07-10 03:05:34 +00:00
var embarkConfig = readYaml.sync("./embark.yml");
if (embarkConfig.type === "grunt") {
run("grunt clean");
run("grunt deploy_contracts:" + env);
run('grunt build:' + env);
}
2015-07-13 02:11:59 +00:00
else if (embarkConfig.type === "meteor") {
2015-07-22 12:30:32 +00:00
deploy(env, embarkConfig);
2015-07-13 02:11:59 +00:00
run("meteor-build-client ./build -p ''");
}
2015-05-24 13:03:43 +00:00
});
2015-06-10 12:37:14 +00:00
program.command('ipfs [env]').description('build dapp and make it available in ipfs').action(function(env_) {
2015-06-06 02:54:50 +00:00
var env = env_ || 'development';
2015-07-10 03:05:34 +00:00
var embarkConfig = readYaml.sync("./embark.yml");
if (embarkConfig.type === "grunt") {
run("grunt clean")
run("grunt deploy_contracts:" + env)
run('grunt build:' + env)
run('grunt ipfs:' + env)
}
2015-07-13 02:11:59 +00:00
else if (embarkConfig.type === "meteor") {
2015-07-22 12:30:32 +00:00
deploy(env, embarkConfig);
2015-07-15 00:58:08 +00:00
run("meteor-build-client ./build -p ''");
2015-07-13 02:11:59 +00:00
Embark.release.ipfs("build/")
}
2015-07-10 03:05:34 +00:00
else {
2015-07-13 02:11:59 +00:00
console.log("command not available in manual mode yet");
2015-07-10 03:05:34 +00:00
}
2015-06-06 02:54:50 +00:00
});
2015-05-24 13:03:43 +00:00
program.command('run [env]').description('run dapp').action(function(env_) {
var env = env_ || 'development';
2015-07-10 03:05:34 +00:00
var embarkConfig = readYaml.sync("./embark.yml");
if (embarkConfig.type === "grunt") {
run('grunt deploy:' + env);
}
else {
console.log("command not available in meteor or manual mode yet");
2015-07-22 22:40:13 +00:00
console.log("try instead embark deploy; if using meteor then follow that with 'meteor'");
2015-07-10 03:05:34 +00:00
}
2015-05-24 13:03:43 +00:00
});
2015-10-12 14:50:52 +00:00
program.command('spec').description('run tests').action(function() {
2015-07-10 03:05:34 +00:00
var embarkConfig = readYaml.sync("./embark.yml");
if (embarkConfig.type === "grunt") {
run('mocha test/ --no-timeouts');
2015-07-10 03:05:34 +00:00
}
else {
console.log("command not available in meteor or manual mode yet");
2015-07-15 00:58:08 +00:00
console.log("note: you can use embark tests with any framework");
2015-10-12 14:50:52 +00:00
console.log("try running mocha test/");
2015-07-10 03:05:34 +00:00
}
2015-06-20 12:35:49 +00:00
});
2015-05-24 13:03:43 +00:00
program.command('blockchain [env]').description('run blockchain').action(function(env_) {
var env = env_ || 'development';
2015-07-10 03:05:34 +00:00
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);
2015-07-10 03:05:34 +00:00
}
2015-05-24 13:03:43 +00:00
});
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);
});
2015-05-24 13:21:08 +00:00
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);
2015-06-19 14:27:19 +00:00
wrench.copyDirSyncRecursive(demoPath + "/app", targetDir + "/app", {forceDelete: true});
wrench.copyDirSyncRecursive(demoPath + "/config", targetDir + "/config", {forceDelete: true});
2015-10-12 14:50:52 +00:00
wrench.copyDirSyncRecursive(demoPath + "/test", targetDir + "/test", {forceDelete: true});
2015-05-24 13:21:08 +00:00
cd(targetDir);
2015-06-10 12:43:15 +00:00
run('npm install');
2015-05-24 13:21:08 +00:00
console.log('\n\ninit complete');
});
2015-07-13 02:18:59 +00:00
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');
});
2015-10-12 13:09:11 +00:00
program.command('simulator').description('run a fast ethereum rpc simulator').action(function() {
EtherSim.startServer();
});
2015-05-24 13:03:43 +00:00
program.parse(process.argv)
if (!process.argv.slice(2).length) {
program.outputHelp();
}
2015-10-12 13:09:11 +00:00
//exit();