HostCommon.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. var os = require('os');
  2. var path = require('path');
  3. // get the root folder
  4. var atomicRoot = path.resolve(__dirname, "../..") + "/";
  5. // patch in our local node_modules
  6. process.env.NODE_PATH = atomicRoot + "Build/node_modules/";
  7. require('module').Module._initPaths();
  8. var fs = require('fs-extra');
  9. function getScriptPackages() {
  10. var srcpath = atomicRoot + "Script/Packages/";
  11. return fs.readdirSync(srcpath).filter(function(file) {
  12. return fs.statSync(path.join(srcpath, file)).isDirectory();
  13. });
  14. }
  15. function cleanCreateDir(directory) {
  16. testRemoveDir(directory);
  17. testCreateDir(directory);
  18. }
  19. function testCreateDir(directory) {
  20. if (fs.existsSync(directory)) {
  21. fail("Path already exists: " + directory);
  22. }
  23. jake.mkdirP(directory);
  24. if (!fs.existsSync(directory)) {
  25. fail("Unable to create path: " + directory);
  26. }
  27. }
  28. function testRemoveDir(path) {
  29. if (fs.existsSync(path)) {
  30. jake.rmRf(path);
  31. }
  32. if (fs.existsSync(path)) {
  33. fail("Unable to remove path: " + path);
  34. }
  35. }
  36. exports.atomicRoot = atomicRoot;
  37. exports.artifactsRoot = atomicRoot + "Artifacts/";
  38. exports.cleanCreateDir = cleanCreateDir;
  39. exports.testCreateDir = testCreateDir;
  40. exports.testRemoveDir = testRemoveDir;
  41. exports.getScriptPackages = getScriptPackages;