Skip to content

Instantly share code, notes, and snippets.

@jacaetevha
Created January 29, 2014 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacaetevha/8689681 to your computer and use it in GitHub Desktop.
Save jacaetevha/8689681 to your computer and use it in GitHub Desktop.
Given an exercism.io directory for JavaScript, edit the given spec file, create a test directory, and write the necessary node.js files.
#!/bin/bash
cat <<HERE > `pwd`/package.json
{
"dependencies": {
"underscore": "*"
},
"devDependencies": {
"jasmine-node": "*"
}
}
HERE
cat <<HERE > `pwd`/Makefile
test:
@./node_modules/.bin/jasmine-node test
.PHONY: test
HERE
mkdir -p test
filename=`grep require *.spec.js | cut -d'(' -f2 | cut -d ')' -f1 | cut -d"'" -f2 | cut -d"/" -f2`.js
cat <<HERE >$filename
var _ = require('underscore');
function renameMe(){}
module.exports = renameMe;
HERE
mv *.spec.js test
cd test
pattern='require(\.\/'
replace='require(\.\/\.\.\/'
echo
echo 'updating spec file'
echo
spec=`ls *.spec.js`
ed -s $spec <<< $'H\n/require/\ns/\./.\/../\n,wq'
cd ..
npm install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment