File: modules/typescript.js

Recommend this page to a friend!
  Classes of Thomas Björk   Node.js Background Jobs   modules/typescript.js   Download  
File: modules/typescript.js
Role: Example script
Content type: text/plain
Description: Example script
Class: Node.js Background Jobs
Run background jobs using Node.js modules
Author: By
Last change: Fixed a bug. (Forgot to close the client socket)
Date: 2 years ago
Size: 945 bytes
 

Contents

Class file image Download
exports.UExecute = function(parts) { return false; }; exports.TExecute = function(parts, client) { var crypto, exec, fileName, fs, jsName, shasum; exec = require('child_process').exec; fs = require('fs'); crypto = require('crypto'); shasum = crypto.createHash('sha1'); shasum.update(parts[1]); fileName = './modules/tmp/' + shasum.digest('hex'); jsName = fileName + '.js'; fileName = fileName + '.ts'; return fs.writeFile(fileName, parts[1], 'utf-8', function(err) { var child; return child = exec('tsc ' + fileName, function(error, stdout, stderr) { var js, status; js = fs.readFileSync(jsName, 'utf-8'); fs.unlinkSync(fileName); client.write(js); if (error !== null) { client.write('<!--'); client.write('exec error: ' + error); client.write('<!--'); status = false; } else { status = true; } client.end(); }); }); };