This repository has been archived by the owner on Jun 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make all code Semistandard conformant.
- Loading branch information
Ryan Casey
committed
Jan 28, 2016
1 parent
d60be34
commit ba5e9a9
Showing
59 changed files
with
3,183 additions
and
3,102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,164 +1,162 @@ | ||
#!/usr/bin/env node | ||
"use strict"; | ||
'use strict'; | ||
|
||
// This is the file that gets executed when you run `dapple`. It uses `docopt` | ||
// to parse the arguments passed in. | ||
|
||
// Usage first. | ||
var fs = require('fs') | ||
var fs = require('fs'); | ||
var docopt = require('docopt'); | ||
var doc = fs.readFileSync(__dirname+"/docopt.txt").toString(); | ||
var doc = fs.readFileSync(__dirname + '/docopt.txt').toString(); | ||
var cli = docopt.docopt(doc); | ||
|
||
// These requires take a lot of time to import. | ||
var req = require('lazreq')({ | ||
DappleRCPrompter: "../lib/dapplerc_prompter.js", | ||
deasync: 'deasync', | ||
Installer: '../lib/installer.js', | ||
inquirer: 'inquirer', | ||
path: 'path', | ||
pipelines: '../lib/pipelines.js', | ||
userHome: 'user-home', | ||
vinyl: 'vinyl-fs' | ||
DappleRCPrompter: '../lib/dapplerc_prompter.js', | ||
deasync: 'deasync', | ||
Installer: '../lib/installer.js', | ||
inquirer: 'inquirer', | ||
path: 'path', | ||
pipelines: '../lib/pipelines.js', | ||
userHome: 'user-home', | ||
vinyl: 'vinyl-fs' | ||
}); | ||
|
||
var Workspace = require("../lib/workspace"); | ||
var VMTest = require("../lib/vmtest"); | ||
var Workspace = require('../lib/workspace'); | ||
var VMTest = require('../lib/vmtest'); | ||
var rc = Workspace.getDappleRC(); | ||
|
||
if (cli.config || typeof(rc.path) === 'undefined') { | ||
var homeRC = req.path.join(req.userHome, '.dapplerc'); | ||
var confirmed; | ||
var chosen = false; | ||
|
||
if (rc.path !== undefined && rc.path === homeRC) { | ||
console.log("You already have a .dapplerc in your home directory!"); | ||
req.inquirer.prompt([{ | ||
type: 'confirm', | ||
message: "Proceeding will overwrite ~/.dapplerc. Proceed?", | ||
name: "confirmed", | ||
default: false | ||
}], function(res) { | ||
chosen = true; | ||
confirmed = res.confirmed; | ||
}) | ||
req.deasync.loopWhile(function() {return !chosen;}); | ||
|
||
if (confirmed) { | ||
Workspace.writeDappleRC(homeRC, req.DappleRCPrompter.prompt()); | ||
} | ||
|
||
} else { | ||
console.log("No configuration found! Generating..."); | ||
Workspace.writeDappleRC(homeRC, req.DappleRCPrompter.prompt()); | ||
if (cli.config || typeof (rc.path) === 'undefined') { | ||
let homeRC = req.path.join(req.userHome, '.dapplerc'); | ||
let confirmed; | ||
let chosen = false; | ||
|
||
if (rc.path !== undefined && rc.path === homeRC) { | ||
console.log('You already have a .dapplerc in your home directory!'); | ||
req.inquirer.prompt([{ | ||
type: 'confirm', | ||
message: 'Proceeding will overwrite ~/.dapplerc. Proceed?', | ||
name: 'confirmed', | ||
default: false | ||
}], function (res) { | ||
chosen = true; | ||
confirmed = res.confirmed; | ||
}); | ||
req.deasync.loopWhile(function () { return !chosen; }); | ||
|
||
if (confirmed) { | ||
Workspace.writeDappleRC(homeRC, req.DappleRCPrompter.prompt()); | ||
} | ||
rc = Workspace.getDappleRC(); | ||
} else { | ||
console.log('No configuration found! Generating...'); | ||
Workspace.writeDappleRC(homeRC, req.DappleRCPrompter.prompt()); | ||
} | ||
rc = Workspace.getDappleRC(); | ||
} | ||
|
||
// If the user ran the `install` command, we're going to walk the dependencies | ||
// in the dappfile and pull them in as git submodules, if the current package is | ||
// a git repository. Otherwise we'll just clone them. | ||
if( cli.install ) { | ||
var workspace = Workspace.atPackageRoot(); | ||
|
||
var packages; | ||
if ( cli['<package>'] ) { | ||
packages = [cli['<package>']]; | ||
} else { | ||
packages = workspace.getDependencies(); | ||
} | ||
if (cli.install) { | ||
let workspace = Workspace.atPackageRoot(); | ||
|
||
req.Installer.install(packages, console); | ||
let packages; | ||
if (cli['<package>']) { | ||
packages = [cli['<package>']]; | ||
} else { | ||
packages = workspace.getDependencies(); | ||
} | ||
|
||
if ( cli['--save'] && cli['<package>'] ) { | ||
workspace.addDependency(cli['<package>']); | ||
workspace.writeDappfile(); | ||
} | ||
req.Installer.install(packages, console); | ||
|
||
if (cli['--save'] && cli['<package>']) { | ||
workspace.addDependency(cli['<package>']); | ||
workspace.writeDappfile(); | ||
} | ||
|
||
// If the user ran the `build` command, we're going to open the current directory | ||
// as if it were a package and commence with building. | ||
// | ||
} else if( cli.build ) { | ||
console.log("Building..."); | ||
} else if (cli.build) { | ||
console.log('Building...'); | ||
|
||
var workspace = Workspace.atPackageRoot(); | ||
var env = cli['--environment'] || workspace.getEnvironment(); | ||
var environments = workspace.getEnvironments(); | ||
let workspace = Workspace.atPackageRoot(); | ||
let env = cli['--environment'] || workspace.getEnvironment(); | ||
let environments = workspace.getEnvironments(); | ||
|
||
if (env && environments && !(env in environments)) { | ||
console.error("Could not find environment in dappfile: " + env); | ||
process.exit(1); | ||
} | ||
if (env && environments && !(env in environments)) { | ||
console.error('Could not find environment in dappfile: ' + env); | ||
process.exit(1); | ||
} | ||
|
||
// Run our build pipeline. | ||
var jsBuildPipeline = req.pipelines | ||
.JSBuildPipeline({ | ||
environment: env, | ||
environments: environments, | ||
subpackages: cli['--subpackages'] || cli['-s'] | ||
}); | ||
// Run our build pipeline. | ||
let jsBuildPipeline = req.pipelines | ||
.JSBuildPipeline({ | ||
environment: env, | ||
environments: environments, | ||
subpackages: cli['--subpackages'] || cli['-s'] | ||
}); | ||
|
||
if (!jsBuildPipeline) process.exit(1); | ||
|
||
// Write output to filesystem. | ||
jsBuildPipeline.pipe(req.vinyl.dest(Workspace.findBuildPath())); | ||
if (!jsBuildPipeline) process.exit(1); | ||
|
||
// Write output to filesystem. | ||
jsBuildPipeline.pipe(req.vinyl.dest(Workspace.findBuildPath())); | ||
|
||
// If they ran the `init` command, we just set up the current directory as a | ||
// Dapple package and exit. | ||
// | ||
} else if (cli.init) { | ||
Workspace.initialize(process.cwd()); | ||
Workspace.initialize(process.cwd()); | ||
|
||
// If they ran the `new test` command, we're going to generate the boilerplate | ||
// sol files. This command is checked for before the `test` command otherwise | ||
// that test would be triggered instead. | ||
// | ||
} else if (cli.new && cli.test) { | ||
VMTest.writeTestTemplate(cli['<class>']); | ||
VMTest.writeTestTemplate(cli['<class>']); | ||
|
||
// If they ran the `test` command, we're going to run our build pipeline and | ||
// then pass the output on to our test pipeline, finally spitting out the | ||
// results to stdout and stderr (in case of failure). | ||
// | ||
} else if (cli.test) { | ||
console.log("Testing..."); | ||
|
||
var workspace = Workspace.atPackageRoot(); | ||
var env = cli['--environment'] || workspace.getEnvironment(); | ||
var nameFilter = undefined; | ||
|
||
if (!(env in rc.data.environments)) { | ||
console.error("Environment not defined: " + env); | ||
process.exit(1); | ||
} | ||
|
||
if( cli['-r'] ) { | ||
// if filter String contains upper case letters special regex chars, | ||
// assume the filtering is case sensitive, otherwise its insensitive | ||
nameFilter = new RegExp( cli['<RegExp>'], | ||
/[A-Z\\\.\[\]\^\$\*\+\{\}\(\)\?\|]/.test(cli['<RegExp>'])?'':'i' ); | ||
} | ||
|
||
var initStream; | ||
if (cli['--skip-build']) { | ||
initStream = req.pipelines.BuiltClassesPipeline( | ||
req.vinyl.dest(Workspace.findBuildPath()), | ||
cli['--subpackages'] || cli['-s']); | ||
|
||
} else { | ||
initStream = req.pipelines | ||
.BuildPipeline({ | ||
packageRoot: Workspace.findPackageRoot(), | ||
subpackages: cli['--subpackages'] || cli['-s'] | ||
}) | ||
.pipe(req.vinyl.dest(Workspace.findBuildPath())); | ||
} | ||
|
||
initStream | ||
.pipe(req.pipelines.TestPipeline({ | ||
web3: rc.data.environments[env].ethereum || 'internal', | ||
nameFilter: nameFilter | ||
})); | ||
|
||
console.log('Testing...'); | ||
|
||
let nameFilter; | ||
let workspace = Workspace.atPackageRoot(); | ||
let env = cli['--environment'] || workspace.getEnvironment(); | ||
|
||
if (!(env in rc.data.environments)) { | ||
console.error('Environment not defined: ' + env); | ||
process.exit(1); | ||
} | ||
|
||
if (cli['-r']) { | ||
// if filter String contains upper case letters special regex chars, | ||
// assume the filtering is case sensitive, otherwise its insensitive | ||
nameFilter = new RegExp(cli['<RegExp>'], | ||
/[A-Z\\\.\[\]\^\$\*\+\{\}\(\)\?\|]/.test(cli['<RegExp>']) ? '' : 'i'); | ||
} | ||
|
||
let initStream; | ||
if (cli['--skip-build']) { | ||
initStream = req.pipelines.BuiltClassesPipeline({ | ||
buildRoot: Workspace.findBuildPath(), | ||
packageRoot: Workspace.findPackageRoot(), | ||
subpackages: cli['--subpackages'] || cli['-s'] | ||
}); | ||
} else { | ||
initStream = req.pipelines | ||
.BuildPipeline({ | ||
packageRoot: Workspace.findPackageRoot(), | ||
subpackages: cli['--subpackages'] || cli['-s'] | ||
}) | ||
.pipe(req.vinyl.dest(Workspace.findBuildPath())); | ||
} | ||
|
||
initStream | ||
.pipe(req.pipelines.TestPipeline({ | ||
web3: rc.data.environments[env].ethereum || 'internal', | ||
nameFilter: nameFilter | ||
})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,55 @@ | ||
'use strict' | ||
'use strict'; | ||
|
||
var Web3 = require('web3') | ||
var Web3 = require('web3'); | ||
|
||
var ContractWrapper = function(headers, web3) { | ||
if (!web3) { | ||
throw new Error("Must supply a Web3 connection!") | ||
} | ||
function ContractWrapper (headers, web3) { | ||
if (!web3) { | ||
throw new Error('Must supply a Web3 connection!'); | ||
} | ||
|
||
this.headers = headers | ||
this._class = web3.eth.contract(headers.interface) | ||
this.headers = headers; | ||
this._class = web3.eth.contract(headers.interface); | ||
} | ||
|
||
ContractWrapper.prototype.deploy = function() { | ||
var args = new Array(arguments) | ||
args[args.length - 1].data = this.headers.bytecode | ||
return this._class.new.apply(this._class, args) | ||
} | ||
ContractWrapper.prototype.deploy = function () { | ||
var args = new Array(arguments); | ||
args[args.length - 1].data = this.headers.bytecode; | ||
return this._class.new.apply(this._class, args); | ||
}; | ||
|
||
// Wrap pass-through functions by name. | ||
var passthroughs = ["at", "new"] | ||
for (var i=0; i < passthroughs.length; i+=1) { | ||
ContractWrapper.prototype[passthroughs[i]] = function() { | ||
return this._class[passthroughs[i]].apply(this._class, arguments) | ||
} | ||
var passthroughs = ['at', 'new']; | ||
for (var i = 0; i < passthroughs.length; i += 1) { | ||
ContractWrapper.prototype[passthroughs[i]] = function () { | ||
return this._class[passthroughs[i]].apply(this._class, arguments); | ||
}; | ||
} | ||
|
||
module.exports = function(env, web3) { | ||
if (typeof(env) === 'undefined') { | ||
env = <%= env %> | ||
} | ||
module.exports = function (env, web3) { | ||
if (typeof env === 'undefined') { | ||
env = <%= env %>; | ||
} | ||
|
||
if (typeof(web3) === 'undefined') { | ||
if (!env.rpcURL) { | ||
throw new Error("Need either a Web3 instance or an RPC URL!") | ||
} | ||
web3 = new Web3(new Web3.providers.HttpProvider(env.rpcURL)) | ||
if (typeof web3 === 'undefined') { | ||
if (!env.rpcURL) { | ||
throw new Error('Need either a Web3 instance or an RPC URL!'); | ||
} | ||
web3 = new Web3(new Web3.providers.HttpProvider(env.rpcURL)); | ||
} | ||
|
||
var header = <%= header %> | ||
this.headers = header; | ||
var header = <%= header %>; | ||
this.headers = header; | ||
|
||
this.classes = {} | ||
for (var key in header) { | ||
this.headers[key].interface = JSON.parse(this.headers[key].interface) | ||
this.classes[key] = new ContractWrapper(header[key], web3) | ||
} | ||
this.classes = {}; | ||
for (var key in header) { | ||
this.headers[key].interface = JSON.parse(this.headers[key].interface); | ||
this.classes[key] = new ContractWrapper(header[key], web3); | ||
} | ||
|
||
this.objects = {}; | ||
for (var i in env.objects) { | ||
var obj = env.objects[i]; | ||
this.objects[i] = this.classes[obj['class']].at(obj.address); | ||
} | ||
}; | ||
|
||
this.objects = {} | ||
for (var i in env.objects) { | ||
var obj = env.objects[i] | ||
this.objects[i] = this.classes[obj['class']].at(obj.address) | ||
} | ||
} |
Oops, something went wrong.