BuildCommon.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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('genAtomicNET', {
  69. async:true
  70. }, function(platform, configuration) {
  71. if (configuration != "Debug" && configuration != "Release")
  72. configuration = "Release";
  73. // Compile AtomicNET assemblies
  74. var cmds = [];
  75. if (os.platform() == "win32") {
  76. cmds.push(host.atomicTool + " net compile " + atomicRoot + "Script/AtomicNET/AtomicNETProject.json " + platform + " " + configuration);
  77. }
  78. jake.exec(cmds, function() {
  79. complete();
  80. }, {
  81. printStdout: true
  82. });
  83. })
  84. task('genscripts', {
  85. async: true
  86. }, function(platform, force) {
  87. // default to true
  88. if (force != "true" && force != "false") {
  89. force = "true";
  90. }
  91. var anyZero = false;
  92. if (force != "true") {
  93. var filenames = common.getGenScriptFilenames(platform);
  94. for (var i in filenames) {
  95. if (!fileExists(filenames[i]))
  96. {
  97. console.log("genscripts: file missing, regenerating script bindings: " + filenames[i]);
  98. anyZero = true;
  99. break;
  100. }
  101. var stats = fs.statSync(filenames[i]);
  102. if (stats["size"] == 0) {
  103. console.log("genscripts: file zero size, regenerating script bindings: " + filenames[i]);
  104. anyZero = true;
  105. break;
  106. }
  107. }
  108. if (!anyZero)
  109. return;
  110. }
  111. process.chdir(atomicRoot);
  112. var modules = host.getScriptModules(platform);
  113. var bindCmd = host.atomicTool + " bind \"" + atomicRoot + "\" ";
  114. var node;
  115. var tsc = "./Build/node_modules/typescript/lib/tsc";
  116. var tslint = "./Build/node_modules/tslint/lib/tslint-cli";
  117. var dtsGenerator = "./Build/node_modules/dts-generator/bin/dts-generator";
  118. switch(os.platform()) {
  119. case "win32":
  120. node = "Build\\Windows\\node\\node.exe";
  121. break;
  122. case "darwin":
  123. node = "Build/Mac/node/node";
  124. break;
  125. case "linux":
  126. node = "Build/Linux/node/node";
  127. break;
  128. }
  129. var cmds = [];
  130. for (var pkgName in modules) {
  131. cmds.push(bindCmd + "Script/Packages/" + pkgName + "/ " + platform);
  132. }
  133. if (node) {
  134. // compile
  135. cmds.push(node + " " + tsc + " -p ./Script");
  136. cmds.push(node + " " + tsc + " -p ./Script/AtomicWebViewEditor");
  137. // generate combined atomic.d.ts
  138. cmds.push(node + " " + dtsGenerator + " --name Atomic --project ./Script/TypeScript --out ./Script/TypeScript/dist/Atomic.d.ts");
  139. var lintTask = jake.Task['build:lint_typescript'];
  140. lintTask.addListener('complete', function () {
  141. console.log("\n\nLint: Typescript linting complete.\n\n");
  142. jake.exec(cmds, function() {
  143. // copy some external dependencies into the editor modules directory
  144. var editorModulesDir = "./Artifacts/Build/Resources/EditorData/AtomicEditor/EditorScripts/AtomicEditor/modules";
  145. var webeditorModulesDir = "./Data/AtomicEditor/CodeEditor/source/editorCore/modules";
  146. var nodeModulesDir = "./Build/node_modules";
  147. fs.mkdirsSync(editorModulesDir);
  148. // TypeScript
  149. fs.copySync(nodeModulesDir + "/typescript/lib/typescript.js", webeditorModulesDir + "/typescript.js")
  150. // copy lib.core.d.ts into the tool data directory
  151. fs.mkdirsSync("./Artifacts/Build/Resources/EditorData/AtomicEditor/EditorScripts/AtomicEditor/TypeScriptSupport");
  152. fs.copySync("./Build/node_modules/typescript/lib/lib.core.d.ts","./Data/AtomicEditor/TypeScriptSupport/lib.core.d.ts")
  153. // copy the combined Atomic.d.ts to the tool data directory
  154. fs.copySync("./Script/TypeScript/dist/Atomic.d.ts","./Data/AtomicEditor/TypeScriptSupport/Atomic.d.ts")
  155. complete();
  156. }, {
  157. printStdout: true
  158. });
  159. });
  160. lintTask.invoke("{./Script/AtomicEditor/**/*.ts,./Script/AtomicWebViewEditor/**/*.ts}", false);
  161. } else {
  162. throw new Error("Node not configured for this platform: " + os.platform());
  163. }
  164. });
  165. }); // end of build namespace