Oppaitime's version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

render_build_preview.js 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. var page = require('webpage').create();
  2. var system = require('system');
  3. var fs = require('fs');
  4. var returnStatus = {};
  5. var rootPath = system.args[1];
  6. var staticPath = system.args[2];
  7. var toolsMiscPath = system.args[4];
  8. // Check if all paths are accessible
  9. // We assume at least read rights on all paths and files
  10. if (!fs.isDirectory(rootPath) || !fs.isDirectory(rootPath + '/' + staticPath) || !fs.isDirectory(rootPath + '/' + staticPath + 'styles/' + system.args[3] + '/') || !fs.isDirectory(toolsMiscPath)) {
  11. // Incorrect paths, are they passed correctly?
  12. returnStatus.status = -1;
  13. console.log(JSON.stringify(returnStatus));
  14. phantom.exit();
  15. }
  16. fs.changeWorkingDirectory(toolsMiscPath);
  17. if (!fs.exists('render_base.html')) {
  18. // Rendering base doesn't exist, who broke things?
  19. returnStatus.status = -2;
  20. console.log(JSON.stringify(returnStatus));
  21. phantom.exit();
  22. }
  23. page.open('render_base.html', function () {
  24. // Fixed view size
  25. page.viewportSize = {
  26. width: 1200,
  27. height: 1000
  28. };
  29. // Switch to specific stylesheet subdirectory
  30. fs.changeWorkingDirectory(rootPath + '/' + staticPath + 'styles/' + system.args[3] + '/');
  31. if (!fs.isWritable(fs.workingDirectory)) {
  32. // Don't have write access.
  33. returnStatus.status = -3;
  34. console.log(JSON.stringify(returnStatus));
  35. phantom.exit();
  36. }
  37. fs.write('preview.html', page.content, 'w');
  38. if (!fs.isFile('preview.html')) {
  39. // Failed to store specific preview file.
  40. returnStatus.status = -4;
  41. console.log(JSON.stringify(returnStatus));
  42. phantom.exit();
  43. }
  44. page.close();
  45. returnStatus.status = 0;
  46. console.log(JSON.stringify(returnStatus));
  47. phantom.exit();
  48. });