| 1 | 'use strict'; |
| 2 | var path = require('path'); |
| 3 | var spawn = require('child_process').spawn; |
| 4 | var phantomjs = require('phantomjs-prebuilt').path; |
| 5 | |
| 6 | module.exports = function (file, args) { |
| 7 | if (!phantomjs) { |
| 8 | var err = new Error('The automatic install of PhantomJS seems to have failed.\nTry installing it manually: http://phantomjs.org/download.html'); |
| 9 | err.noStack = true; |
| 10 | throw err; |
| 11 | } |
| 12 | |
| 13 | args = [path.resolve(file)].concat(args).sort(function (a, b) { |
| 14 | // move flags to the beginning to please phantoms sucky argument parsing |
| 15 | return /^--/.test(b) ? 1 : 0; |
| 16 | }); |
| 17 | |
| 18 | return spawn(phantomjs, args); |
| 19 | }; |