BuildCommon.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. // precreate script bindgs so they can be picked up by CMake
  44. task('precreateScriptBindings', {
  45. async: true
  46. }, function(platform, clean) {
  47. if (clean === undefined) {
  48. clean = true;
  49. }
  50. console.log("Precreating script bindings for platorm: " + platform);
  51. if (clean) {
  52. common.cleanCreateDir(common.getGenScriptRootDir(platform))
  53. }
  54. common.createGenScriptFiles(platform);
  55. complete();
  56. });
  57. function fileExists(filePath)
  58. {
  59. try
  60. {
  61. return fs.statSync(filePath).isFile();
  62. }
  63. catch (err)
  64. {
  65. return false;
  66. }
  67. }
  68. task('genscripts', {
  69. async: true
  70. }, function(platform, force) {
  71. if (force === undefined) {
  72. force = true;
  73. }
  74. var anyZero = false;
  75. if (!force) {
  76. var filenames = common.getGenScriptFilenames(platform);
  77. for (var i in filenames) {
  78. if (!fileExists(filenames[i]))
  79. {
  80. console.log("genscripts: file missing, regenerating script bindings: " + filenames[i]);
  81. anyZero = true;
  82. break;
  83. }
  84. var stats = fs.statSync(filenames[i]);
  85. if (stats["size"] == 0) {
  86. console.log("genscripts: file zero size, regenerating script bindings: " + filenames[i]);
  87. anyZero = true;
  88. break;
  89. }
  90. }
  91. if (!anyZero)
  92. return;
  93. }
  94. process.chdir(atomicRoot);
  95. var modules = host.getScriptModules(platform);
  96. var bindCmd = host.atomicTool + " bind \"" + atomicRoot + "\" ";
  97. var node;
  98. var tsc = "./Build/node_modules/typescript/lib/tsc";
  99. var tslint = "./Build/node_modules/tslint/lib/tslint-cli";
  100. var dtsGenerator = "./Build/node_modules/dts-generator/bin/dts-generator";
  101. switch(os.platform()) {
  102. case "win32":
  103. node = "Build\\Windows\\node\\node.exe";
  104. break;
  105. case "darwin":
  106. node = "Build/Mac/node/node";
  107. break;
  108. case "linux":
  109. node = "Build/Linux/node/node";
  110. break;
  111. }
  112. var cmds = [];
  113. for (var pkgName in modules) {
  114. cmds.push(bindCmd + "Script/Packages/" + pkgName + "/ " + platform);
  115. }
  116. if (node) {
  117. // compile
  118. cmds.push(node + " " + tsc + " -p ./Script");
  119. cmds.push(node + " " + tsc + " -p ./Script/AtomicWebViewEditor");
  120. // generate combined atomic.d.ts
  121. cmds.push(node + " " + dtsGenerator + " --name Atomic --project ./Script/TypeScript --out ./Script/TypeScript/dist/Atomic.d.ts");
  122. var lintTask = jake.Task['build:lint_typescript'];
  123. lintTask.addListener('complete', function () {
  124. console.log("\n\nLint: Typescript linting complete.\n\n");
  125. jake.exec(cmds, function() {
  126. // copy some external dependencies into the editor modules directory
  127. var editorModulesDir = "./Artifacts/Build/Resources/EditorData/AtomicEditor/EditorScripts/AtomicEditor/modules";
  128. var webeditorModulesDir = "./Data/AtomicEditor/CodeEditor/source/editorCore/modules";
  129. var nodeModulesDir = "./Build/node_modules";
  130. fs.mkdirsSync(editorModulesDir);
  131. // TypeScript
  132. fs.copySync(nodeModulesDir + "/typescript/lib/typescript.js", webeditorModulesDir + "/typescript.js")
  133. // copy lib.core.d.ts into the tool data directory
  134. fs.mkdirsSync("./Artifacts/Build/Resources/EditorData/AtomicEditor/EditorScripts/AtomicEditor/TypeScriptSupport");
  135. fs.copySync("./Build/node_modules/typescript/lib/lib.core.d.ts","./Data/AtomicEditor/TypeScriptSupport/lib.core.d.ts")
  136. // copy the combined Atomic.d.ts to the tool data directory
  137. fs.copySync("./Script/TypeScript/dist/Atomic.d.ts","./Data/AtomicEditor/TypeScriptSupport/Atomic.d.ts")
  138. complete();
  139. }, {
  140. printStdout: true
  141. });
  142. });
  143. lintTask.invoke("{./Script/AtomicEditor/**/*.ts,./Script/AtomicWebViewEditor/**/*.ts}", false);
  144. } else {
  145. throw new Error("Node not configured for this platform: " + os.platform());
  146. }
  147. });
  148. }); // end of build namespace