BuildCommon.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. var fs = require('fs-extra');
  2. var os = require('os');
  3. var path = require("path");
  4. var host = require("./Host");
  5. var atomicRoot = host.atomicRoot;
  6. var glob = require('glob');
  7. var Tslint = require("tslint");
  8. namespace('build', function() {
  9. // Linting task
  10. task('lint_typescript', {
  11. async: true
  12. }, function(fileMask, failOnError) {
  13. console.log("TSLINT: Linting files in " + fileMask);
  14. var lintConfig = JSON.parse(fs.readFileSync("./Script/tslint.json"));
  15. var options = {
  16. configuration: lintConfig,
  17. formatter: "prose"
  18. };
  19. // lint
  20. // Since TSLint does not yet support recursively searching for files, then we need to
  21. // create a command per file. The main issue with this is that it will abort on the first error instead
  22. // of listing out all lint errors
  23. glob(fileMask, function(err, results) {
  24. var lintErrors = [];
  25. results.forEach(function(filename) {
  26. var contents = fs.readFileSync(filename, "utf8");
  27. var ll = new Tslint(filename, contents, options);
  28. var result = ll.lint();
  29. if (result.failureCount > 0) {
  30. lintErrors.push(result.output);
  31. }
  32. });
  33. if (lintErrors.length > 0) {
  34. console.warn("TSLINT: WARNING - Lint errors detected");
  35. console.warn(lintErrors.join(''));
  36. if (failOnError) {
  37. fail("TSLint errors detected");
  38. }
  39. }
  40. complete();
  41. });
  42. });
  43. task('genscripts', {
  44. async: true
  45. }, function(platform) {
  46. process.chdir(atomicRoot);
  47. var modules = host.getScriptModules(platform);
  48. var bindCmd = host.atomicTool + " bind \"" + atomicRoot + "\" ";
  49. var node;
  50. var tsc = "./Build/node_modules/typescript/lib/tsc";
  51. var tslint = "./Build/node_modules/tslint/lib/tslint-cli";
  52. switch(os.platform()) {
  53. case "win32":
  54. node = "Build\\Windows\\node\\node.exe";
  55. break;
  56. case "darwin":
  57. node = "Build/Mac/node/node";
  58. break;
  59. case "linux":
  60. node = "Build/Linux/node/node";
  61. break;
  62. }
  63. var cmds = [];
  64. for (var pkgName in modules) {
  65. cmds.push(bindCmd + "Script/Packages/" + pkgName + "/ " + platform);
  66. }
  67. if (node) {
  68. // compile
  69. cmds.push(node + " " + tsc + " -p ./Script");
  70. cmds.push(node + " " + tsc + " -p ./Script/AtomicWebViewEditor");
  71. var lintTask = jake.Task['build:lint_typescript'];
  72. lintTask.addListener('complete', function () {
  73. console.log("\n\nLint: Typescript linting complete.\n\n");
  74. jake.exec(cmds, function() {
  75. complete();
  76. }, {
  77. printStdout: true
  78. });
  79. });
  80. lintTask.invoke("{./Script/AtomicEditor/**/*.ts,./Script/AtomicWebViewEditor/**/*.ts}", false);
  81. } else {
  82. throw new Error("Node not configured for this platform: " + os.platform());
  83. }
  84. });
  85. }); // end of build namespace