diff --git a/bin/embark b/bin/embark index 38a0e6db..0f08a19b 100644 --- a/bin/embark +++ b/bin/embark @@ -51,31 +51,80 @@ program.command('deploy [env]').description('deploy contracts').action(function( program.command('build [env]').description('build dapp').action(function(env_) { var env = env_ || 'development'; - run("grunt clean"); - run("grunt deploy_contracts:" + env); - run('grunt build:' + env); + var embarkConfig = readYaml.sync("./embark.yml"); + + if (embarkConfig.type === "grunt") { + run("grunt clean"); + run("grunt deploy_contracts:" + env); + run('grunt build:' + env); + } + else if (embarkConfig.type === "meteor") { + //deploy + 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'; - run("grunt clean") - run("grunt deploy_contracts:" + env) - run('grunt build:' + env) - run('grunt ipfs:' + env) + 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) + } + else if (embarkConfig.type === "meteor") { + //deploy + //build + Embark = require('embark-framework') + 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'; - run('grunt deploy:' + env); + 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"); + } }); program.command('spec').description('run specs').action(function() { - run('jasmine'); + var embarkConfig = readYaml.sync("./embark.yml"); + + if (embarkConfig.type === "grunt") { + run('jasmine'); + } + else { + console.log("command not available in meteor or manual mode yet"); + } }); program.command('blockchain [env]').description('run blockchain').action(function(env_) { var env = env_ || 'development'; - run('grunt blockchain:' + env); + 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) + + //TODO: better with --exec, but need to fix console bug first + wrench.copyDirSyncRecursive(__dirname + "/../js", "/tmp", {forceDelete: true}); + + Embark.startBlockchain(env, true); + } }); program.command('demo').description('create a working dapp with a SimpleStorage contract').action(function() { @@ -93,6 +142,14 @@ program.command('demo').description('create a working dapp with a SimpleStorage 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.parse(process.argv) if (!process.argv.slice(2).length) { diff --git a/boilerplate/embark.yml b/boilerplate/embark.yml index 60302132..5d19d917 100644 --- a/boilerplate/embark.yml +++ b/boilerplate/embark.yml @@ -1,5 +1,5 @@ type: "grunt" #other options: meteor, manual -#contracts: ["app/contracts/**"] -#output: "generated/tmp/abi.js" +#contracts: ["app/contracts/**/*.sol"] +#output: "src/embark.js" #blockchainConfig: "config/blockchain.yml" #contractsConfig: "config/contracts.yml" diff --git a/demo_meteor/.meteor/.finished-upgraders b/demo_meteor/.meteor/.finished-upgraders new file mode 100644 index 00000000..8a761038 --- /dev/null +++ b/demo_meteor/.meteor/.finished-upgraders @@ -0,0 +1,8 @@ +# This file contains information which helps Meteor properly upgrade your +# app when you run 'meteor update'. You should check it into version control +# with your project. + +notices-for-0.9.0 +notices-for-0.9.1 +0.9.4-platform-file +notices-for-facebook-graph-api-2 diff --git a/demo_meteor/.meteor/.gitignore b/demo_meteor/.meteor/.gitignore new file mode 100644 index 00000000..40830374 --- /dev/null +++ b/demo_meteor/.meteor/.gitignore @@ -0,0 +1 @@ +local diff --git a/demo_meteor/.meteor/.id b/demo_meteor/.meteor/.id new file mode 100644 index 00000000..bc5e1676 --- /dev/null +++ b/demo_meteor/.meteor/.id @@ -0,0 +1,7 @@ +# This file contains a token that is unique to your project. +# Check it into your repository along with the rest of this directory. +# It can be used for purposes such as: +# - ensuring you don't accidentally deploy one app on top of another +# - providing package authors with aggregated statistics + +v2fbp61wvu7nd11xgkdz diff --git a/demo_meteor/.meteor/packages b/demo_meteor/.meteor/packages new file mode 100644 index 00000000..1e64d2fa --- /dev/null +++ b/demo_meteor/.meteor/packages @@ -0,0 +1,10 @@ +# Meteor packages used by this project, one per line. +# Check this file (and the other files in this directory) into your repository. +# +# 'meteor add' and 'meteor remove' will edit this file for you, +# but you can also edit it by hand. + +meteor-platform +autopublish +insecure +ethereum:web3 diff --git a/demo_meteor/.meteor/platforms b/demo_meteor/.meteor/platforms new file mode 100644 index 00000000..efeba1b5 --- /dev/null +++ b/demo_meteor/.meteor/platforms @@ -0,0 +1,2 @@ +server +browser diff --git a/demo_meteor/.meteor/release b/demo_meteor/.meteor/release new file mode 100644 index 00000000..dab6b552 --- /dev/null +++ b/demo_meteor/.meteor/release @@ -0,0 +1 @@ +METEOR@1.1.0.2 diff --git a/demo_meteor/.meteor/versions b/demo_meteor/.meteor/versions new file mode 100644 index 00000000..fbae8343 --- /dev/null +++ b/demo_meteor/.meteor/versions @@ -0,0 +1,49 @@ +autopublish@1.0.3 +autoupdate@1.2.1 +base64@1.0.3 +binary-heap@1.0.3 +blaze@2.1.2 +blaze-tools@1.0.3 +boilerplate-generator@1.0.3 +callback-hook@1.0.3 +check@1.0.5 +ddp@1.1.0 +deps@1.0.7 +ejson@1.0.6 +ethereum:web3@0.8.1 +fastclick@1.0.3 +geojson-utils@1.0.3 +html-tools@1.0.4 +htmljs@1.0.4 +http@1.1.0 +id-map@1.0.3 +insecure@1.0.3 +jquery@1.11.3_2 +json@1.0.3 +launch-screen@1.0.2 +livedata@1.0.13 +logging@1.0.7 +meteor@1.1.6 +meteor-platform@1.2.2 +minifiers@1.1.5 +minimongo@1.0.8 +mobile-status-bar@1.0.3 +mongo@1.1.0 +observe-sequence@1.0.6 +ordered-dict@1.0.3 +random@1.0.3 +reactive-dict@1.1.0 +reactive-var@1.0.5 +reload@1.1.3 +retry@1.0.3 +routepolicy@1.0.5 +session@1.1.0 +spacebars@1.0.6 +spacebars-compiler@1.0.6 +templating@1.1.1 +tracker@1.0.7 +ui@1.0.6 +underscore@1.0.3 +url@1.0.4 +webapp@1.2.0 +webapp-hashing@1.0.3 diff --git a/demo_meteor/client/embark.js b/demo_meteor/client/embark.js new file mode 100644 index 00000000..7de3dbf6 --- /dev/null +++ b/demo_meteor/client/embark.js @@ -0,0 +1 @@ +web3.setProvider(new web3.providers.HttpProvider('http://localhost:8101'));web3.eth.defaultAccount = web3.eth.accounts[0];SimpleStorageAbi = [{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"type":"function"},{"inputs":[{"name":"initialValue","type":"uint256"}],"type":"constructor"}];SimpleStorageContract = web3.eth.contract(SimpleStorageAbi);SimpleStorage = SimpleStorageContract.at('0x823802b31f5856bcf5a8a99f791934f9593afbf8'); \ No newline at end of file diff --git a/demo_meteor/client/myapp.css b/demo_meteor/client/myapp.css new file mode 100644 index 00000000..b6b4052b --- /dev/null +++ b/demo_meteor/client/myapp.css @@ -0,0 +1 @@ +/* CSS declarations go here */ diff --git a/demo_meteor/client/myapp.html b/demo_meteor/client/myapp.html new file mode 100644 index 00000000..8dc9b050 --- /dev/null +++ b/demo_meteor/client/myapp.html @@ -0,0 +1,29 @@ + + Embark - SimpleStorage Demo + + +

Embark - SimpleStorage Demo

+ + {{> set_value}} + + {{> current_value}} + +
+
+ + + + + + + diff --git a/demo_meteor/client/myapp.js b/demo_meteor/client/myapp.js new file mode 100644 index 00000000..ee408d8a --- /dev/null +++ b/demo_meteor/client/myapp.js @@ -0,0 +1,35 @@ +if (Meteor.isClient) { + Session.setDefault('value', 0); + + var addToLog = function(txt) { + $(".logs").append("
" + txt); + } + + Template.current_value.helpers({ + value: function () { + return Session.get('value'); + } + }); + + Template.current_value.events({ + 'click button': function () { + var value = SimpleStorage.get().toNumber(); + Session.set('value', value); + addToLog("SimpleStorage.get()"); + } + }); + + Template.set_value.events({ + 'click button': function () { + var value = parseInt($("input.text").val(), 10); + SimpleStorage.set(value); + addToLog("SimpleStorage.set("+value+")"); + } + }); +} + +if (Meteor.isServer) { + Meteor.startup(function () { + // code to run on server at startup + }); +} diff --git a/demo_meteor/config/blockchain.yml b/demo_meteor/config/blockchain.yml new file mode 100644 index 00000000..e1a4936b --- /dev/null +++ b/demo_meteor/config/blockchain.yml @@ -0,0 +1,23 @@ +development: + rpc_host: localhost + rpc_port: 8101 + rpc_whitelist: "*" + minerthreads: 1 + datadir: /tmp/embark + mine_when_needed: true + gas_limit: 500000 + gas_price: 10000000000000 + console: false + account: + init: true + password: config/password +staging: + rpc_host: localhost + rpc_port: 8101 + rpc_whitelist: "*" + datadir: default + network_id: 0 + console: true + account: + init: false + address: diff --git a/demo_meteor/config/contracts.yml b/demo_meteor/config/contracts.yml new file mode 100644 index 00000000..2b6d25d6 --- /dev/null +++ b/demo_meteor/config/contracts.yml @@ -0,0 +1,8 @@ +development: + SimpleStorage: + args: + - 100 +staging: + SimpleStorage: + args: + - 100 diff --git a/demo_meteor/config/password b/demo_meteor/config/password new file mode 100644 index 00000000..c747d679 --- /dev/null +++ b/demo_meteor/config/password @@ -0,0 +1 @@ +dev_password diff --git a/demo_meteor/contracts/simple_storage.sol b/demo_meteor/contracts/simple_storage.sol new file mode 100644 index 00000000..0b12e43d --- /dev/null +++ b/demo_meteor/contracts/simple_storage.sol @@ -0,0 +1,14 @@ +contract SimpleStorage { + uint public storedData; + + function SimpleStorage(uint initialValue) { + storedData = initialValue; + } + + function set(uint x) { + storedData = x; + } + function get() constant returns (uint retVal) { + return storedData; + } +} diff --git a/demo_meteor/embark.yml b/demo_meteor/embark.yml new file mode 100644 index 00000000..d39816df --- /dev/null +++ b/demo_meteor/embark.yml @@ -0,0 +1,5 @@ +type: "meteor" +contracts: ["contracts/**/*.sol"] +output: "client/embark.js" +blockchainConfig: "config/blockchain.yml" +contractsConfig: "config/contracts.yml" diff --git a/lib/blockchain.js b/lib/blockchain.js index d10805f7..fc7cc9ce 100644 --- a/lib/blockchain.js +++ b/lib/blockchain.js @@ -44,7 +44,7 @@ Blockchain.prototype.init_command = function() { return this.generate_basic_command() + "account new "; } -Blockchain.prototype.run_command = function(address) { +Blockchain.prototype.run_command = function(address, use_tmp) { var cmd = this.generate_basic_command(); var config = this.config; @@ -57,7 +57,12 @@ Blockchain.prototype.run_command = function(address) { } if (config.mine_when_needed) { - cmd += "js node_modules/embark-framework/js/mine.js"; + if (use_tmp) { + cmd += "js /tmp/mine.js"; + } + else { + cmd += "js node_modules/embark-framework/js/mine.js"; + } } return cmd; @@ -84,10 +89,10 @@ Blockchain.prototype.get_address = function() { return address; } -Blockchain.prototype.startChain = function() { +Blockchain.prototype.startChain = function(use_tmp) { var address = this.get_address(); - console.log("running: " + this.run_command(address)); - exec(this.run_command(address)); + console.log("running: " + this.run_command(address, use_tmp)); + exec(this.run_command(address, use_tmp)); } module.exports = Blockchain diff --git a/lib/index.js b/lib/index.js index b168f00d..8281b4ef 100644 --- a/lib/index.js +++ b/lib/index.js @@ -30,9 +30,9 @@ Embark = { return new Tests(this.contractsConfig, contractFiles); }, - startBlockchain: function(env) { + startBlockchain: function(env, use_tmp) { var chain = new Blockchain(this.blockchainConfig.config(env)); - chain.startChain(); + chain.startChain(use_tmp); }, deployContracts: function(env, contractFiles, destFile) { diff --git a/lib/ipfs.js b/lib/ipfs.js index 35c91c0f..5fb505f7 100644 --- a/lib/ipfs.js +++ b/lib/ipfs.js @@ -1,10 +1,8 @@ require('shelljs/global'); -ipfs = function() { +ipfs = function(build_dir) { ipfs_path = "~/go/bin"; - build_dir = "dist/dapp/"; - cmd = ipfs_path + "/ipfs add -r " + build_dir; console.log("=== adding " + cmd + " to ipfs"); diff --git a/package.json b/package.json index fdca391d..f5343263 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "hashmerge": "^1.0.2", "jasmine": "^2.3.1", "matchdep": "^0.3.0", + "meteor-build-client": "^0.1.6", "methodmissing": "^0.0.3", "python": "^0.0.4", "read-yaml": "^1.0.0", diff --git a/tasks/ipfs.coffee b/tasks/ipfs.coffee index 85b39916..f2b4dc2d 100644 --- a/tasks/ipfs.coffee +++ b/tasks/ipfs.coffee @@ -3,5 +3,5 @@ module.exports = (grunt) -> grunt.registerTask "ipfs", "distribute into ipfs", (env_) => env = env_ || "development" Embark = require('embark-framework') - Embark.release.ipfs() + Embark.release.ipfs("dist/dapp/")