Last active
December 21, 2015 12:59
-
-
Save azu/6309397 to your computer and use it in GitHub Desktop.
espower runner
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
/** | |
* Created by azu on 2013/08/23. | |
*/ | |
var espower = require('espower'), esprima = require('esprima'), escodegen = require('escodegen'); | |
var fs = require('fs'), path = require('path'); | |
var sys = require('sys'); | |
var userArgs = process.argv.slice(2); | |
var filePath = path.resolve(process.cwd(), userArgs[0]); | |
var absPath = fs.realpathSync(filePath), jsCode = fs.readFileSync(filePath, 'utf-8'); | |
var jsAst = esprima.parse(jsCode, {tolerant: true, loc: true, range: true}); | |
var espowerOptions = { | |
path: absPath, | |
source: jsCode | |
}; | |
var modifiedAst = espower(jsAst, espowerOptions); | |
sys.print(escodegen.generate(modifiedAst)); |
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
#!/bin/sh | |
set -e | |
if [ $# != 1 ]; then | |
echo "Usage: ./espowerun.sh path/to/test.js" | |
exit 0 | |
fi | |
tmpdir="`basename ${0}`.$$" | |
mkdir -p ${tmpdir} | |
trap 'rm -r ${tmpdir}' 0 | |
node `dirname ${0}`/espowerun.js "$1" > ${tmpdir}/$$.js | |
mocha ${tmpdir} | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment