phantomjs.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. module.exports = function(config,grunt) {
  2. 'use strict';
  3. grunt.registerTask('phantomjs', 'Copy phantomjs binary from node', function() {
  4. var dest = './vendor/phantomjs/phantomjs';
  5. var confDir = './node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/'
  6. if (!grunt.file.exists(confDir)) {
  7. // npm 3 or npm 2 with dedupe
  8. confDir = './node_modules/phantomjs/lib/';
  9. }
  10. if (!grunt.file.exists(dest)){
  11. var m=grunt.file.read(confDir+"location.js")
  12. var src=/= \"([^\"]*)\"/.exec(m)[1];
  13. if (!grunt.file.isPathAbsolute(src)) {
  14. src = confDir+src;
  15. }
  16. var exec = require('child_process').execFileSync;
  17. try {
  18. grunt.config('copy.phantom_bin', {
  19. src: src,
  20. dest: dest,
  21. options: { mode: true},
  22. });
  23. grunt.task.run('copy:phantom_bin');
  24. } catch (err) {
  25. grunt.verbose.writeln(err);
  26. grunt.fail.warn('No working Phantomjs binary available')
  27. }
  28. } else {
  29. grunt.log.writeln('Phantomjs already imported from node');
  30. }
  31. });
  32. };