BuildCommon.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. var dtsGenerator = "./Build/node_modules/dts-generator/bin/dts-generator";
  53. switch(os.platform()) {
  54. case "win32":
  55. node = "Build\\Windows\\node\\node.exe";
  56. break;
  57. case "darwin":
  58. node = "Build/Mac/node/node";
  59. break;
  60. case "linux":
  61. node = "Build/Linux/node/node";
  62. break;
  63. }
  64. var cmds = [];
  65. for (var pkgName in modules) {
  66. cmds.push(bindCmd + "Script/Packages/" + pkgName + "/ " + platform);
  67. }
  68. if (node) {
  69. // compile
  70. cmds.push(node + " " + tsc + " -p ./Script");
  71. cmds.push(node + " " + tsc + " -p ./Script/AtomicWebViewEditor");
  72. // generate combined atomic.d.ts
  73. cmds.push(node + " " + dtsGenerator + " --name Atomic --baseDir ./Script/TypeScript --exclude ./Script/TypeScript/dist/*.d.ts --out ./Script/TypeScript/dist/Atomic.d.ts ./Script/TypeScript/*.d.ts ");
  74. var lintTask = jake.Task['build:lint_typescript'];
  75. lintTask.addListener('complete', function () {
  76. console.log("\n\nLint: Typescript linting complete.\n\n");
  77. jake.exec(cmds, function() {
  78. // copy some external dependencies into the editor modules directory
  79. var editorModulesDir = "./Artifacts/Build/Resources/EditorData/AtomicEditor/EditorScripts/AtomicEditor/modules";
  80. var webeditorModulesDir = "./Data/AtomicEditor/CodeEditor/source/editorCore/modules";
  81. var nodeModulesDir = "./Build/node_modules";
  82. fs.mkdirsSync(editorModulesDir);
  83. // TypeScript
  84. fs.copySync(nodeModulesDir + "/typescript/lib/typescript.js", webeditorModulesDir + "/typescript.js")
  85. // copy lib.core.d.ts into the tool data directory
  86. fs.mkdirsSync("./Artifacts/Build/Resources/EditorData/AtomicEditor/EditorScripts/AtomicEditor/TypeScriptSupport");
  87. fs.copySync("./Build/node_modules/typescript/lib/lib.core.d.ts","./Data/AtomicEditor/TypeScriptSupport/lib.core.d.ts")
  88. // copy the combined Atomic.d.ts to the tool data directory
  89. fs.copySync("./Script/TypeScript/dist/Atomic.d.ts","./Data/AtomicEditor/TypeScriptSupport/Atomic.d.ts")
  90. complete();
  91. }, {
  92. printStdout: true
  93. });
  94. });
  95. lintTask.invoke("{./Script/AtomicEditor/**/*.ts,./Script/AtomicWebViewEditor/**/*.ts}", false);
  96. } else {
  97. throw new Error("Node not configured for this platform: " + os.platform());
  98. }
  99. });
  100. }); // end of build namespace