BuildCommon.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. var fs = require('fs-extra');
  2. var os = require('os');
  3. var path = require("path");
  4. var glob = require('glob');
  5. var Tslint = require("tslint");
  6. var fso = require('fs');
  7. var spawnSync = require('child_process').spawnSync;
  8. var host = require("./Host");
  9. var config = require('./BuildConfig');
  10. var atomicRoot = config.atomicRoot;
  11. var jsDocFolder = config.artifactsRoot + "Build/JSDoc/";
  12. var cppDocFolder = config.artifactsRoot + "Build/CPPDocs/";
  13. namespace('build', function() {
  14. // Linting task
  15. task('lint_typescript', {
  16. async: true
  17. }, function(fileMask, failOnError) {
  18. console.log("TSLINT: Linting files in " + fileMask);
  19. var lintConfig = JSON.parse(fs.readFileSync("./Script/tslint.json"));
  20. var tslintConfig = {
  21. configuration: lintConfig,
  22. formatter: "prose"
  23. };
  24. // lint
  25. // Since TSLint does not yet support recursively searching for files, then we need to
  26. // create a command per file. The main issue with this is that it will abort on the first error instead
  27. // of listing out all lint errors
  28. glob(fileMask, function(err, results) {
  29. var lintErrors = [];
  30. results.forEach(function(filename) {
  31. var contents = fs.readFileSync(filename, "utf8");
  32. var ll = new Tslint(filename, contents, tslintConfig);
  33. var result = ll.lint();
  34. if (result.failureCount > 0) {
  35. lintErrors.push(result.output);
  36. }
  37. });
  38. if (lintErrors.length > 0) {
  39. console.warn("TSLINT: WARNING - Lint errors detected");
  40. console.warn(lintErrors.join(''));
  41. if (failOnError) {
  42. fail("TSLint errors detected");
  43. }
  44. }
  45. complete();
  46. });
  47. });
  48. // precreate script bindgs so they can be picked up by CMake
  49. task('precreateScriptBindings', {
  50. async: true
  51. }, function(clean) {
  52. if (clean === undefined) {
  53. clean = true;
  54. }
  55. console.log("Precreating script bindings");
  56. if (clean) {
  57. common.cleanCreateDir(common.getGenScriptRootDir())
  58. }
  59. common.createGenScriptFiles();
  60. complete();
  61. });
  62. function fileExists(filePath)
  63. {
  64. try
  65. {
  66. return fs.statSync(filePath).isFile();
  67. }
  68. catch (err)
  69. {
  70. return false;
  71. }
  72. }
  73. task('genAtomicNET', {
  74. async:true
  75. }, function(platform, configuration) {
  76. if (configuration != "Debug" && configuration != "Release")
  77. configuration = "Release";
  78. // Compile AtomicNET assemblies
  79. var cmds = [];
  80. cmds.push(host.atomicTool + " net compile " + atomicRoot + "Script/AtomicNET/AtomicNETProject.json -platform " + platform + " -config " + configuration);
  81. jake.exec(cmds, function() {
  82. complete();
  83. }, {
  84. printStdout: true
  85. });
  86. })
  87. task('genscripts', {
  88. async: true
  89. }, function(force) {
  90. // default to true
  91. if (force != "true" && force != "false") {
  92. force = "true";
  93. }
  94. var anyZero = false;
  95. if (force != "true") {
  96. var filenames = common.getGenScriptFilenames();
  97. for (var i in filenames) {
  98. if (!fileExists(filenames[i]))
  99. {
  100. console.log("genscripts: file missing, regenerating script bindings: " + filenames[i]);
  101. anyZero = true;
  102. break;
  103. }
  104. var stats = fs.statSync(filenames[i]);
  105. if (stats["size"] == 0) {
  106. console.log("genscripts: file zero size, regenerating script bindings: " + filenames[i]);
  107. anyZero = true;
  108. break;
  109. }
  110. }
  111. if (!anyZero)
  112. return;
  113. }
  114. process.chdir(atomicRoot);
  115. var modules = host.getScriptModules();
  116. var bindCmd = host.atomicTool + " bind \"" + atomicRoot + "\" ";
  117. var node = host.node;
  118. var tsc = "./Build/node_modules/typescript/lib/tsc";
  119. var tslint = "./Build/node_modules/tslint/lib/tslint-cli";
  120. var dtsGenerator = "./Build/node_modules/dts-generator/bin/dts-generator";
  121. var cmds = [];
  122. for (var pkgName in modules) {
  123. cmds.push(bindCmd + "Script/Packages/" + pkgName + "/");
  124. }
  125. if (node) {
  126. // compile
  127. cmds.push(node + " " + tsc + " -p ./Script");
  128. cmds.push(node + " " + tsc + " -p ./Script/AtomicWebViewEditor");
  129. // generate combined atomic.d.ts
  130. cmds.push(node + " " + dtsGenerator + " --name Atomic --project ./Script/TypeScript --out ./Script/TypeScript/dist/Atomic.d.ts");
  131. var lintTask = jake.Task['build:lint_typescript'];
  132. lintTask.addListener('complete', function () {
  133. console.log("\n\nLint: Typescript linting complete.\n\n");
  134. jake.exec(cmds, function() {
  135. // copy some external dependencies into the editor modules directory
  136. var editorModulesDir = "./Artifacts/Build/Resources/EditorData/AtomicEditor/EditorScripts/AtomicEditor/modules";
  137. var webeditorModulesDir = "./Data/AtomicEditor/CodeEditor/source/editorCore/modules";
  138. var nodeModulesDir = "./Build/node_modules";
  139. fs.mkdirsSync(editorModulesDir);
  140. // TypeScript
  141. fs.copySync(nodeModulesDir + "/typescript/lib/typescript.js", webeditorModulesDir + "/typescript.js")
  142. // copy lib.core.d.ts into the tool data directory
  143. fs.mkdirsSync("./Artifacts/Build/Resources/EditorData/AtomicEditor/EditorScripts/AtomicEditor/TypeScriptSupport");
  144. fs.copySync("./Build/node_modules/typescript/lib/lib.es5.d.ts","./Data/AtomicEditor/TypeScriptSupport/lib.es5.d.ts");
  145. // copy the combined Atomic.d.ts to the tool data directory
  146. fs.copySync("./Script/TypeScript/dist/Atomic.d.ts","./Data/AtomicEditor/TypeScriptSupport/Atomic.d.ts")
  147. complete();
  148. }, {
  149. printStdout: true
  150. });
  151. });
  152. lintTask.invoke("{./Script/AtomicEditor/**/*.ts,./Script/AtomicWebViewEditor/**/*.ts}", false);
  153. } else {
  154. throw new Error("Node not configured for this platform: " + os.platform());
  155. }
  156. });
  157. task('gendocs', {
  158. async: true
  159. }, function() {
  160. console.log( "Generating Docs..." );
  161. fs.copySync(atomicRoot + "Build/Docs/Readme.md", jsDocFolder + "Readme.md");
  162. fs.copySync(atomicRoot + "Build/Docs/atomic-theme", jsDocFolder + "atomic-theme");
  163. var typeDoc;
  164. if (os.platform() == "win32") {
  165. // uses system node for typedoc, which should have as require npm
  166. typeDoc = "node_modules\\.bin\\typedoc.cmd";
  167. }
  168. else
  169. typeDoc = host.node + " ./node_modules/.bin/typedoc";
  170. // tsdoc is having problems when name has spaces on Windows and Linux, tried quoting/escaping
  171. // what should happen here is instead of command line use a json config file (or maybe new version of tsdoc fixes this)
  172. var name = "Atomic-Game-Engine";
  173. cmds = [
  174. "cd " + jsDocFolder + " && echo {} > package.json", // newer versions of npm require package.json to be in the folder or else it searches up the heirarchy
  175. "cd " + jsDocFolder + " && npm install typedoc",
  176. "cd " + jsDocFolder + " && " + typeDoc + " --out out " + config.atomicRoot +
  177. "Script/TypeScript/dist/Atomic.d.ts --module commonjs --includeDeclarations --mode file --theme atomic-theme --name " +
  178. name + " --readme ./Readme.md"
  179. ];
  180. jake.exec(cmds, function() {
  181. common.cleanCreateDir( config.toolDataFolder + "Docs");
  182. fs.copySync(jsDocFolder + "out", config.toolDataFolder + "Docs/JSDocs");
  183. complete();
  184. console.log( "completed installing API documentation" );
  185. }, {
  186. printStdout: true
  187. });
  188. });
  189. task('gendoxygen', {
  190. async: true
  191. }, function() {
  192. console.log( "Generating C++ API Documentation..." );
  193. var cppDoc;
  194. if (os.platform() == "win32") {
  195. cppDoc = "doxygen"; // I dont know what to do here...
  196. }
  197. else {
  198. // use doxygen on path
  199. cppDoc = "doxygen";
  200. }
  201. cmds = [
  202. "cd " + atomicRoot + "Source && " + cppDoc + " " + atomicRoot + "Build/Docs/CPlusPlus/Doxyfile"
  203. ];
  204. jake.exec(cmds, function() {
  205. common.cleanCreateDir( config.toolDataFolder + "Docs/CPPDocs"); // clear destination
  206. fs.copySync(cppDocFolder, config.toolDataFolder + "Docs/CPPDocs"); // copy into release same place as JSDocs
  207. complete();
  208. console.log( "completed installing CPP API documentation" );
  209. }, {
  210. printStdout: true
  211. });
  212. });
  213. task('genexamples', {
  214. async: true
  215. }, function() {
  216. console.log( "Generating Examples..." );
  217. // TODO: support pulling examples from a specific branch/commit/etc
  218. var exampleSrc = atomicRoot + "Submodules/AtomicExamples/";
  219. var exampleDst = config.toolDataFolder + "AtomicExamples/";
  220. common.testRemoveDir( exampleDst);
  221. fs.copySync(exampleSrc, exampleDst);
  222. // remove the .git file/folder and save some space
  223. fs.removeSync( exampleDst + ".git" );
  224. complete();
  225. });
  226. }); // end of build namespace