BuildCommon.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. var editorAppFolder = host.artifactsRoot + "AtomicEditor/";
  9. var toolDataFolder = editorAppFolder + "Resources/ToolData/";
  10. namespace('build', function() {
  11. // Linting task
  12. task('lint_typescript', {
  13. async: true
  14. }, function(fileMask, failOnError) {
  15. console.log("TSLINT: Linting files in " + fileMask);
  16. var lintConfig = JSON.parse(fs.readFileSync("./Script/tslint.json"));
  17. var options = {
  18. configuration: lintConfig,
  19. formatter: "prose"
  20. };
  21. // lint
  22. // Since TSLint does not yet support recursively searching for files, then we need to
  23. // create a command per file. The main issue with this is that it will abort on the first error instead
  24. // of listing out all lint errors
  25. glob(fileMask, function(err, results) {
  26. var lintErrors = [];
  27. results.forEach(function(filename) {
  28. var contents = fs.readFileSync(filename, "utf8");
  29. var ll = new Tslint(filename, contents, options);
  30. var result = ll.lint();
  31. if (result.failureCount > 0) {
  32. lintErrors.push(result.output);
  33. }
  34. });
  35. if (lintErrors.length > 0) {
  36. console.warn("TSLINT: WARNING - Lint errors detected");
  37. console.warn(lintErrors.join(''));
  38. if (failOnError) {
  39. fail("TSLint errors detected");
  40. }
  41. }
  42. complete();
  43. });
  44. });
  45. // precreate script bindgs so they can be picked up by CMake
  46. task('precreateScriptBindings', {
  47. async: true
  48. }, function(clean) {
  49. if (clean === undefined) {
  50. clean = true;
  51. }
  52. console.log("Precreating script bindings");
  53. if (clean) {
  54. common.cleanCreateDir(common.getGenScriptRootDir())
  55. }
  56. common.createGenScriptFiles();
  57. complete();
  58. });
  59. function fileExists(filePath)
  60. {
  61. try
  62. {
  63. return fs.statSync(filePath).isFile();
  64. }
  65. catch (err)
  66. {
  67. return false;
  68. }
  69. }
  70. task('genAtomicNET', {
  71. async:true
  72. }, function(platform, configuration) {
  73. if (configuration != "Debug" && configuration != "Release")
  74. configuration = "Release";
  75. // Compile AtomicNET assemblies
  76. var cmds = [];
  77. cmds.push(host.atomicTool + " net compile " + atomicRoot + "Script/AtomicNET/AtomicNETProject.json -platform " + platform + " -config " + configuration);
  78. jake.exec(cmds, function() {
  79. complete();
  80. }, {
  81. printStdout: true
  82. });
  83. })
  84. task('genscripts', {
  85. async: true
  86. }, function(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();
  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();
  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 + "/");
  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. task('genexamples', {
  166. async: true
  167. }, function() {
  168. common.cleanCreateDir( toolDataFolder + "AtomicExamples");
  169. cmds = [
  170. "git clone https://github.com/AtomicGameEngine/AtomicExamples " + toolDataFolder + "AtomicExamples",
  171. ];
  172. jake.exec(cmds, function() {
  173. fs.removeSync( toolDataFolder + "AtomicExamples/.git" );
  174. complete();
  175. console.log( "completed installing example programs" )
  176. }, {
  177. printStdout: true
  178. });
  179. });
  180. }); // end of build namespace