run.js 886 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env node
  2. var ok = require("./lint").ok;
  3. var files = new (require('node-static').Server)();
  4. var server = require('http').createServer(function (req, res) {
  5. req.addListener('end', function () {
  6. files.serve(req, res, function (err/*, result */) {
  7. if (err) {
  8. console.error(err);
  9. process.exit(1);
  10. }
  11. });
  12. }).resume();
  13. }).addListener('error', function (err) {
  14. throw err;
  15. }).listen(3000, function () {
  16. var childProcess = require('child_process');
  17. var phantomjs = require("phantomjs-prebuilt");
  18. var childArgs = [
  19. require("path").join(__dirname, 'phantom_driver.js')
  20. ];
  21. childProcess.execFile(phantomjs.path, childArgs, function (err, stdout, stderr) {
  22. server.close();
  23. console.log(stdout);
  24. if (err) console.error(err);
  25. if (stderr) console.error(stderr);
  26. process.exit(err || stderr || !ok ? 1 : 0);
  27. });
  28. });