Skip to content

Instantly share code, notes, and snippets.

@datapimp
Created December 9, 2010 04:54
Show Gist options
  • Save datapimp/734352 to your computer and use it in GitHub Desktop.
Save datapimp/734352 to your computer and use it in GitHub Desktop.
// piping code into this script
// like echo "alert('hi')" |./this-script
//
// products 1 ^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@alert('hi')
//
var stdin = process.openStdin(),
code = ''
stdin.setEncoding('utf8')
stdin.on("data",function(chunk){
code+=chunk
})
stdin.on("end",function(){
assets.store('asset-name',code)
})
/* this is what the store function looks like */
module.exports.store = function(asset,content){
var asset_path = path.join(watcher.assets_directory(),"reloaded.assets")
exec("mkdir -p " + asset_path)
fs.open( path.join(asset_path,asset),'a+',0666,function(err,fd){
fs.write(fd,content,content.length,0,0,function(err){
if(err){
throw(err)
}
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment