2014-04-06 00:22:39 +00:00
|
|
|
|
|
|
|
|
###
|
|
|
|
|
runscript.js
|
|
|
|
|
------------
|
|
|
|
|
|
|
|
|
|
A script that helps to track errors happening durin coffee
|
|
|
|
|
compilation and running of module code
|
|
|
|
|
###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not process.argv[ 2 ]
|
|
|
|
|
console.log 'Please provide a path to a coffee file'
|
|
|
|
|
process.exit()
|
|
|
|
|
|
|
|
|
|
fs = require 'fs'
|
|
|
|
|
vm = require 'vm'
|
|
|
|
|
cs = require 'coffee-script'
|
2014-04-06 19:36:34 +00:00
|
|
|
needle = require 'needle'
|
|
|
|
|
crypto = require 'crypto-js'
|
|
|
|
|
request = require 'request'
|
2014-04-16 15:42:56 +00:00
|
|
|
importio = require( 'import-io' ).client
|
2014-04-06 19:36:34 +00:00
|
|
|
|
|
|
|
|
params = JSON.parse fs.readFileSync 'params.json', 'utf8'
|
|
|
|
|
code = fs.readFileSync process.argv[ 2 ], 'utf8'
|
|
|
|
|
src = cs.compile code
|
2014-04-06 00:22:39 +00:00
|
|
|
|
|
|
|
|
sandbox =
|
|
|
|
|
id: 'test.vm'
|
2014-04-20 23:34:49 +00:00
|
|
|
params: params
|
2014-04-16 15:42:56 +00:00
|
|
|
needle: needle
|
|
|
|
|
request: request
|
2014-04-06 19:36:34 +00:00
|
|
|
cryptoJS: crypto
|
2014-04-16 15:42:56 +00:00
|
|
|
importio: importio
|
2014-04-06 00:22:39 +00:00
|
|
|
log: console.log
|
|
|
|
|
debug: console.log
|
2014-04-25 00:24:01 +00:00
|
|
|
setTimeout: setTimeout
|
2014-04-06 00:22:39 +00:00
|
|
|
exports: {}
|
2014-04-22 21:42:31 +00:00
|
|
|
pushEvent: ( obj ) ->
|
|
|
|
|
console.log obj
|
2014-04-20 23:34:49 +00:00
|
|
|
|
2014-04-06 00:22:39 +00:00
|
|
|
vm.runInNewContext src, sandbox, sandbox.id
|
|
|
|
|
|
2014-04-25 00:24:01 +00:00
|
|
|
# sandbox.exports[ process.argv[ 3 ] ].apply null, [ "FS14", "FS14 - CS108", "param3", "param4" ]
|
|
|
|
|
sandbox.exports[ process.argv[ 3 ] ].apply null, [
|
|
|
|
|
useraccount: "10595"
|
|
|
|
|
semester: "FS14"
|
|
|
|
|
studies: "BSC4"
|
|
|
|
|
major: "BL"
|
|
|
|
|
]
|
2014-04-06 19:36:34 +00:00
|
|
|
|
2014-04-06 00:22:39 +00:00
|
|
|
console.log "If no error happened until here it seems the script
|
|
|
|
|
compiled and ran correctly! Congrats!"
|