gulpfile.js 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055
  1. var gulp = require("gulp");
  2. var uglify = require("gulp-uglify");
  3. var typescript = require("gulp-typescript");
  4. var sourcemaps = require("gulp-sourcemaps");
  5. var srcToVariable = require("gulp-content-to-variable");
  6. var appendSrcToVariable = require("./gulp-appendSrcToVariable");
  7. var addDtsExport = require("./gulp-addDtsExport");
  8. var addModuleExports = require("./gulp-addModuleExports");
  9. var addES6Exports = require("./gulp-addES6Exports");
  10. var babylonModuleExports = require("./gulp-babylonModule");
  11. var babylonES6ModuleExports = require("./gulp-es6ModuleExports");
  12. var dtsModuleSupport = require("./gulp-dtsModuleSupport");
  13. let calculateDependencies = require("./gulp-calculateDependencies");
  14. var merge2 = require("merge2");
  15. var concat = require("gulp-concat");
  16. var rename = require("gulp-rename");
  17. var cleants = require("gulp-clean-ts-extends");
  18. var changedInPlace = require("gulp-changed-in-place");
  19. var runSequence = require("run-sequence");
  20. var replace = require("gulp-replace");
  21. var uncommentShader = require("./gulp-removeShaderComments");
  22. var expect = require("gulp-expect-file");
  23. var optimisejs = require("gulp-optimize-js");
  24. var webserver = require("gulp-webserver");
  25. var path = require("path");
  26. var sass = require("gulp-sass");
  27. var webpack = require("webpack-stream");
  28. var typedoc = require("gulp-typedoc");
  29. var validateTypedoc = require("./gulp-validateTypedoc");
  30. var request = require('request');
  31. var fs = require("fs");
  32. var karmaServer = require('karma').Server;
  33. var config = require("./config.json");
  34. var del = require("del");
  35. var debug = require("gulp-debug");
  36. var includeShadersStream;
  37. var shadersStream;
  38. var workersStream;
  39. var extendsSearchRegex = /var\s__extends[\s\S]+?\}\)\(\);/g;
  40. var decorateSearchRegex = /var\s__decorate[\s\S]+?\};/g;
  41. var referenceSearchRegex = /\/\/\/ <reference.*/g;
  42. /**
  43. * TS configurations shared in the gulp file.
  44. */
  45. var tsConfig = {
  46. noResolve: true,
  47. target: "ES5",
  48. declarationFiles: true,
  49. typescript: require("typescript"),
  50. experimentalDecorators: true,
  51. isolatedModules: false,
  52. noImplicitAny: true,
  53. noImplicitReturns: true,
  54. noImplicitThis: true,
  55. noUnusedLocals: true,
  56. strictNullChecks: true,
  57. strictFunctionTypes: true,
  58. strict: true,
  59. types: [],
  60. lib: [
  61. "dom",
  62. "es2015.promise",
  63. "es5"
  64. ]
  65. };
  66. var tsProject = typescript.createProject(tsConfig);
  67. var externalTsConfig = {
  68. noResolve: false,
  69. target: "ES5",
  70. declarationFiles: true,
  71. typescript: require("typescript"),
  72. experimentalDecorators: true,
  73. isolatedModules: false,
  74. noImplicitAny: true,
  75. noImplicitReturns: true,
  76. noImplicitThis: true,
  77. noUnusedLocals: true,
  78. strictNullChecks: true,
  79. strict: true,
  80. types: [],
  81. lib: [
  82. "dom",
  83. "es2015.promise",
  84. "es5"
  85. ]
  86. };
  87. var minimist = require("minimist");
  88. var commandLineOptions = minimist(process.argv.slice(2), {
  89. boolean: "public"
  90. });
  91. function processDependency(kind, dependency, filesToLoad, firstLevelOnly) {
  92. if (!firstLevelOnly && dependency.dependUpon) {
  93. for (var i = 0; i < dependency.dependUpon.length; i++) {
  94. var dependencyName = dependency.dependUpon[i];
  95. var parent = config.workloads[dependencyName];
  96. processDependency(kind, parent, filesToLoad);
  97. }
  98. }
  99. var content = dependency[kind];
  100. if (!content) {
  101. return;
  102. }
  103. for (var i = 0; i < content.length; i++) {
  104. var file = content[i];
  105. if (filesToLoad.indexOf(file) === -1) {
  106. filesToLoad.push(file);
  107. }
  108. }
  109. }
  110. function determineFilesToProcess(kind) {
  111. var currentConfig = config.build.currentConfig;
  112. var buildConfiguration = config.buildConfigurations[currentConfig];
  113. var filesToLoad = [];
  114. for (var index = 0; index < buildConfiguration.length; index++) {
  115. var dependencyName = buildConfiguration[index];
  116. var dependency = config.workloads[dependencyName];
  117. if (kind === "directFiles" && !dependency) {
  118. filesToLoad.push("../../dist/preview release/" + dependencyName);
  119. }
  120. else if (dependency) {
  121. processDependency(kind, dependency, filesToLoad);
  122. }
  123. }
  124. if (kind === "shaderIncludes") {
  125. for (var index = 0; index < filesToLoad.length; index++) {
  126. filesToLoad[index] = "../../src/Shaders/ShadersInclude/" + filesToLoad[index] + ".fx";
  127. }
  128. } else if (kind === "shaders") {
  129. for (var index = 0; index < filesToLoad.length; index++) {
  130. var name = filesToLoad[index];
  131. filesToLoad[index] = "../../src/Shaders/" + filesToLoad[index] + ".fx";
  132. }
  133. }
  134. return filesToLoad;
  135. }
  136. /*
  137. * Shader Management.
  138. */
  139. function shadersName(filename) {
  140. return path.basename(filename)
  141. .replace(".fragment", "Pixel")
  142. .replace(".vertex", "Vertex")
  143. .replace(".fx", "Shader");
  144. }
  145. function includeShadersName(filename) {
  146. return path.basename(filename).replace(".fx", "");
  147. }
  148. /*
  149. * Main necessary files stream Management.
  150. */
  151. gulp.task("includeShaders", function (cb) {
  152. var filesToProcess = determineFilesToProcess("shaderIncludes");
  153. includeShadersStream = gulp.src(filesToProcess).
  154. pipe(expect.real({ errorOnFailure: true }, filesToProcess)).
  155. pipe(uncommentShader()).
  156. pipe(srcToVariable({
  157. variableName: "BABYLON.Effect.IncludesShadersStore", asMap: true, namingCallback: includeShadersName
  158. }));
  159. cb();
  160. });
  161. gulp.task("shaders", ["includeShaders"], function (cb) {
  162. var filesToProcess = determineFilesToProcess("shaders");
  163. shadersStream = gulp.src(filesToProcess).
  164. pipe(expect.real({ errorOnFailure: true }, filesToProcess)).
  165. pipe(uncommentShader()).
  166. pipe(srcToVariable({
  167. variableName: "BABYLON.Effect.ShadersStore", asMap: true, namingCallback: shadersName
  168. }));
  169. cb();
  170. });
  171. gulp.task("workers", function (cb) {
  172. workersStream = config.workers.map(function (workerDef) {
  173. return gulp.src(workerDef.files).
  174. pipe(expect.real({ errorOnFailure: true }, workerDef.files)).
  175. pipe(uglify()).
  176. pipe(srcToVariable({
  177. variableName: workerDef.variable
  178. }));
  179. });
  180. cb();
  181. });
  182. /**
  183. * Build tasks to concat minify uflify optimise the BJS js in different flavor (workers...).
  184. */
  185. gulp.task("buildWorker", ["workers", "shaders"], function () {
  186. var filesToProcess = determineFilesToProcess("files");
  187. return merge2(
  188. gulp.src(filesToProcess).
  189. pipe(expect.real({ errorOnFailure: true }, filesToProcess)),
  190. shadersStream,
  191. includeShadersStream,
  192. workersStream
  193. )
  194. .pipe(concat(config.build.minWorkerFilename))
  195. .pipe(cleants())
  196. .pipe(replace(extendsSearchRegex, ""))
  197. .pipe(replace(decorateSearchRegex, ""))
  198. .pipe(addModuleExports("BABYLON", {
  199. dependencies: config.build.dependencies
  200. }))
  201. .pipe(uglify())
  202. .pipe(optimisejs())
  203. .pipe(gulp.dest(config.build.outputDirectory));
  204. });
  205. gulp.task("build", ["shaders"], function () {
  206. var filesToProcess = determineFilesToProcess("files");
  207. var directFilesToProcess = determineFilesToProcess("directFiles");
  208. let mergedStreams = merge2(
  209. gulp.src(filesToProcess).
  210. pipe(expect.real({ errorOnFailure: true }, filesToProcess)),
  211. shadersStream,
  212. includeShadersStream,
  213. gulp.src(directFilesToProcess)
  214. )
  215. return merge2(
  216. mergedStreams
  217. .pipe(concat(config.build.filename))
  218. .pipe(cleants())
  219. .pipe(replace(extendsSearchRegex, ""))
  220. .pipe(replace(decorateSearchRegex, ""))
  221. .pipe(addModuleExports("BABYLON", {
  222. dependencies: config.build.dependencies
  223. }))
  224. .pipe(gulp.dest(config.build.outputDirectory))
  225. .pipe(rename(config.build.minFilename))
  226. .pipe(uglify())
  227. .pipe(optimisejs())
  228. .pipe(gulp.dest(config.build.outputDirectory)),
  229. mergedStreams
  230. .pipe(concat("es6.js"))
  231. .pipe(cleants())
  232. .pipe(replace(extendsSearchRegex, ""))
  233. .pipe(replace(decorateSearchRegex, ""))
  234. .pipe(addES6Exports("BABYLON"))
  235. .pipe(gulp.dest(config.build.outputDirectory))
  236. );
  237. });
  238. /*
  239. * Compiles all typescript files and creating a js and a declaration file.
  240. */
  241. gulp.task("typescript-compile", function () {
  242. var tsResult = gulp.src(config.typescript)
  243. .pipe(sourcemaps.init())
  244. .pipe(tsProject());
  245. //If this gulp task is running on travis, file the build!
  246. if (process.env.TRAVIS) {
  247. tsResult.once("error", function () {
  248. tsResult.once("finish", function () {
  249. console.log("Typescript compile failed");
  250. process.exit(1);
  251. });
  252. });
  253. }
  254. return merge2([
  255. tsResult.dts
  256. .pipe(concat(config.build.declarationFilename))
  257. .pipe(addDtsExport("BABYLON", "babylonjs"))
  258. .pipe(gulp.dest(config.build.outputDirectory)),
  259. tsResult.js
  260. .pipe(sourcemaps.write("./",
  261. {
  262. includeContent: false,
  263. sourceRoot: (filePath) => {
  264. return "";
  265. }
  266. }))
  267. .pipe(gulp.dest(config.build.srcOutputDirectory))
  268. ])
  269. });
  270. /**
  271. * Helper methods to build external library (mat, post processes, ...).
  272. */
  273. var buildExternalLibraries = function (settings) {
  274. var tasks = settings.libraries.map(function (library) {
  275. return buildExternalLibrary(library, settings, false);
  276. });
  277. let mergedTasks = merge2(tasks);
  278. if (settings.build.buildAsModule) {
  279. mergedTasks.on("end", function () {
  280. //generate js file list
  281. let files = settings.libraries.filter(function (lib) {
  282. return !lib.doNotIncludeInBundle;
  283. }).map(function (lib) {
  284. return config.build.outputDirectory + settings.build.distOutputDirectory + lib.output;
  285. });
  286. var outputDirectory = config.build.outputDirectory + settings.build.distOutputDirectory;
  287. let srcTask = gulp.src(files)
  288. .pipe(concat(settings.build.outputFilename + ".js"))
  289. .pipe(replace(extendsSearchRegex, ""))
  290. .pipe(replace(decorateSearchRegex, ""))
  291. .pipe(replace(referenceSearchRegex, ""))
  292. .pipe(addModuleExports(settings.build.moduleDeclaration, { subModule: true, extendsRoot: settings.build.extendsRoot }))
  293. .pipe(gulp.dest(outputDirectory))
  294. .pipe(cleants())
  295. .pipe(rename({ extname: ".min.js" }))
  296. .pipe(uglify())
  297. .pipe(optimisejs())
  298. .pipe(gulp.dest(outputDirectory));
  299. let dtsFiles = files.map(function (filename) {
  300. return filename.replace(".js", ".d.ts");
  301. });
  302. let dtsTask = gulp.src(dtsFiles)
  303. .pipe(concat(settings.build.outputFilename + ".module.d.ts"))
  304. .pipe(replace(referenceSearchRegex, ""))
  305. .pipe(addDtsExport(settings.build.moduleDeclaration, settings.build.moduleName, true, settings.build.extendsRoot, settings.build.extraTypesDependencies))
  306. .pipe(gulp.dest(outputDirectory));
  307. return merge2([srcTask, dtsTask]);
  308. });
  309. }
  310. return mergedTasks;
  311. }
  312. var buildExternalLibrary = function (library, settings, watch) {
  313. var tsProcess = gulp.src(library.files, { base: settings.build.srcOutputDirectory })
  314. .pipe(sourcemaps.init())
  315. .pipe(typescript(externalTsConfig));
  316. var includeShader = gulp.src(library.shadersIncludeFiles || [], { base: settings.build.srcOutputDirectory })
  317. .pipe(uncommentShader())
  318. .pipe(appendSrcToVariable("BABYLON.Effect.IncludesShadersStore", includeShadersName, library.output + ".include.fx"))
  319. .pipe(gulp.dest(settings.build.srcOutputDirectory));
  320. var shader = gulp.src(library.shaderFiles || [], { base: settings.build.srcOutputDirectory })
  321. .pipe(uncommentShader())
  322. .pipe(appendSrcToVariable("BABYLON.Effect.ShadersStore", shadersName, library.output + ".fx"))
  323. .pipe(gulp.dest(settings.build.srcOutputDirectory));
  324. var dev = tsProcess.js
  325. .pipe(sourcemaps.write("./", {
  326. includeContent: false,
  327. sourceRoot: (filePath) => {
  328. return "";
  329. }
  330. })).pipe(gulp.dest(settings.build.srcOutputDirectory));
  331. var outputDirectory = config.build.outputDirectory + settings.build.distOutputDirectory;
  332. var css = gulp.src(library.sassFiles || [])
  333. .pipe(sass().on("error", sass.logError))
  334. .pipe(concat(library.output.replace(".js", ".css")))
  335. .pipe(gulp.dest(outputDirectory));
  336. if (watch) {
  337. return merge2([shader, includeShader, dev, css]);
  338. }
  339. else {
  340. /*if (library.bundle) {
  341. // Don't remove extends and decorate functions
  342. var code = merge2([tsProcess.js, shader, includeShader])
  343. .pipe(concat(library.output));
  344. if (library.buildAsModule) {
  345. code = code.pipe(addModuleExports(library.moduleDeclaration, true))
  346. }
  347. code.pipe(gulp.dest(outputDirectory))
  348. .pipe(cleants())
  349. .pipe(rename({ extname: ".min.js" }))
  350. .pipe(uglify())
  351. .pipe(optimisejs())
  352. .pipe(gulp.dest(outputDirectory));
  353. } else {*/
  354. var code = merge2([tsProcess.js, shader, includeShader])
  355. .pipe(concat(library.output))
  356. if (library.buildAsModule) {
  357. code = code.pipe(replace(extendsSearchRegex, ""))
  358. .pipe(replace(decorateSearchRegex, ""))
  359. .pipe(addModuleExports(library.moduleDeclaration, { subModule: true, extendsRoot: library.extendsRoot }))
  360. }
  361. code = code.pipe(gulp.dest(outputDirectory))
  362. .pipe(cleants())
  363. .pipe(rename({ extname: ".min.js" }))
  364. .pipe(uglify())
  365. .pipe(optimisejs())
  366. .pipe(gulp.dest(outputDirectory));
  367. /*}*/
  368. var dts = tsProcess.dts
  369. .pipe(concat(library.output))
  370. .pipe(replace(referenceSearchRegex, ""))
  371. .pipe(rename({ extname: ".d.ts" }))
  372. .pipe(gulp.dest(outputDirectory));
  373. var waitAll;
  374. if (library.buildAsModule) {
  375. var dts2 = tsProcess.dts
  376. .pipe(concat(library.output))
  377. .pipe(replace(referenceSearchRegex, ""))
  378. .pipe(addDtsExport(library.moduleDeclaration, library.moduleName, true, library.extendsRoot, config.build.extraTypesDependencies))
  379. .pipe(rename({ extname: ".module.d.ts" }))
  380. .pipe(gulp.dest(outputDirectory));
  381. waitAll = merge2([dev, code, css, dts, dts2]);
  382. } else {
  383. waitAll = merge2([dev, code, css, dts]);
  384. }
  385. if (library.webpack) {
  386. let sequence = [waitAll];
  387. let wpBuild = webpack(require(library.webpack));
  388. if (settings.build.outputs) {
  389. let build = wpBuild
  390. .pipe(addModuleExports(library.moduleDeclaration, { subModule: false, extendsRoot: false, externalUsingBabylon: true, noBabylonInit: library.babylonIncluded }));
  391. let unminifiedOutpus = [];
  392. let minifiedOutputs = [];
  393. settings.build.outputs.forEach(out => {
  394. if (out.minified) {
  395. out.destination.forEach(dest => {
  396. minifiedOutputs.push(dest);
  397. });
  398. } else {
  399. out.destination.forEach(dest => {
  400. unminifiedOutpus.push(dest);
  401. });
  402. }
  403. });
  404. function processDestination(dest) {
  405. var outputDirectory = config.build.outputDirectory + dest.outputDirectory;
  406. build = build
  407. .pipe(rename(dest.filename.replace(".js", library.noBundleInName ? '.js' : ".bundle.js")))
  408. .pipe(gulp.dest(outputDirectory));
  409. if (library.babylonIncluded && dest.addBabylonDeclaration) {
  410. // include the babylon declaration
  411. sequence.unshift(gulp.src(config.build.outputDirectory + '/' + config.build.declarationFilename)
  412. .pipe(gulp.dest(outputDirectory)))
  413. }
  414. }
  415. unminifiedOutpus.forEach(dest => {
  416. processDestination(dest);
  417. });
  418. if (minifiedOutputs.length) {
  419. build = build
  420. .pipe(uglify())
  421. .pipe(optimisejs())
  422. }
  423. minifiedOutputs.forEach(dest => {
  424. processDestination(dest);
  425. });
  426. sequence.push(build);
  427. } else {
  428. sequence.push(
  429. wpBuild
  430. .pipe(rename(library.output.replace(".js", library.noBundleInName ? '.js' : ".bundle.js")))
  431. .pipe(addModuleExports(library.moduleDeclaration, { subModule: false, extendsRoot: library.extendsRoot, externalUsingBabylon: true }))
  432. .pipe(uglify())
  433. .pipe(optimisejs())
  434. .pipe(gulp.dest(outputDirectory))
  435. )
  436. }
  437. return merge2(sequence);
  438. }
  439. else {
  440. return waitAll;
  441. }
  442. }
  443. }
  444. /**
  445. * The default task, concat and min the main BJS files.
  446. */
  447. gulp.task("default", function (cb) {
  448. runSequence("typescript-all", "intellisense", "typedoc-all", "tests-unit", "tests-validation-virtualscreen", "tests-validation-browserstack", cb);
  449. });
  450. gulp.task("mainBuild", function (cb) {
  451. runSequence("buildWorker", "build", cb);
  452. });
  453. /**
  454. * Build the releasable files.
  455. */
  456. gulp.task("typescript", function (cb) {
  457. runSequence("typescript-compile", "mainBuild", cb);
  458. });
  459. /**
  460. * Dynamic module creation.
  461. */
  462. config.modules.map(function (module) {
  463. gulp.task(module, function () {
  464. return buildExternalLibraries(config[module]);
  465. });
  466. });
  467. gulp.task("typescript-libraries", config.modules, function () {
  468. });
  469. /**
  470. * Dynamic custom configurations.
  471. */
  472. config.buildConfigurations.distributed.map(function (customConfiguration) {
  473. gulp.task(customConfiguration, function (cb) {
  474. config.build.currentConfig = customConfiguration;
  475. config.build.outputDirectory = config.build.outputCustomConfigurationsDirectory + "/" + customConfiguration;
  476. runSequence("typescript-compile", "build", cb);
  477. });
  478. });
  479. gulp.task("typescript-customConfigurations", function (cb) {
  480. runSequence(config.buildConfigurations.distributed, cb);
  481. });
  482. /**
  483. * Custom build with full path file control; used by profile.html
  484. */
  485. gulp.task("build-custom", function (cb) {
  486. runSequence("typescript-compile", "build", cb);
  487. });
  488. /**
  489. * Do it all.
  490. */
  491. gulp.task("typescript-all", function (cb) {
  492. runSequence("typescript", "typescript-libraries", "typescript-customConfigurations", cb);
  493. });
  494. /**
  495. * Watch ts files from typescript .
  496. */
  497. gulp.task("srcTscWatch", function () {
  498. // Reuse The TSC CLI from gulp to enable -w.
  499. process.argv[2] = "-w";
  500. process.argv[3] = "-p";
  501. process.argv[4] = "../../src/tsconfig.json";
  502. require("./node_modules/typescript/lib/tsc.js");
  503. });
  504. /**
  505. * Watch ts files and fire repective tasks.
  506. */
  507. gulp.task("watch", ["srcTscWatch"], function () {
  508. var interval = 1000;
  509. var tasks = [];
  510. config.modules.map(function (module) {
  511. config[module].libraries.map(function (library) {
  512. tasks.push(gulp.watch(library.files, { interval: interval }, function () {
  513. console.log(library.output);
  514. return buildExternalLibrary(library, config[module], true)
  515. .pipe(debug());
  516. }));
  517. tasks.push(gulp.watch(library.shaderFiles, { interval: interval }, function () {
  518. console.log(library.output);
  519. return buildExternalLibrary(library, config[module], true)
  520. .pipe(debug())
  521. }));
  522. tasks.push(gulp.watch(library.sassFiles, { interval: interval }, function () {
  523. console.log(library.output);
  524. return buildExternalLibrary(library, config[module], true)
  525. .pipe(debug())
  526. }));
  527. });
  528. });
  529. return tasks;
  530. });
  531. gulp.task("intellisense", function () {
  532. gulp.src(config.build.intellisenseSources)
  533. .pipe(concat(config.build.intellisenseFile))
  534. .pipe(replace(/^\s*_.*?$/gm, ""))
  535. .pipe(replace(/^\s*private .*?$/gm, ""))
  536. .pipe(replace(/^\s*public _.*?$/gm, ""))
  537. .pipe(replace(/^\s*protected .*?$/gm, ""))
  538. .pipe(replace(/^\s*public static _.*?$/gm, ""))
  539. .pipe(replace(/^\s*static _.*?$/gm, ""))
  540. .pipe(gulp.dest(config.build.playgroundDirectory));
  541. });
  542. /**
  543. * Embedded local dev env management.
  544. */
  545. gulp.task("deployLocalDev", function () {
  546. gulp.src("../../localDev/template/**.*")
  547. .pipe(gulp.dest("../../localDev/src/"));
  548. });
  549. /**
  550. * Embedded webserver for test convenience.
  551. */
  552. gulp.task("webserver", function () {
  553. var options = {
  554. port: 1338,
  555. livereload: false,
  556. };
  557. if (commandLineOptions.public) {
  558. options.host = "0.0.0.0";
  559. }
  560. gulp.src("../../.").pipe(webserver(options));
  561. });
  562. /**
  563. * Combine Webserver and Watch as long as vscode does not handle multi tasks.
  564. */
  565. gulp.task("run", ["watch", "webserver"], function () {
  566. });
  567. /**
  568. * Cleans map and js files from the src folder.
  569. */
  570. gulp.task("clean-JS-MAP", function () {
  571. return del([
  572. "../../src/**/*.js.map", "../../src/**/*.js"
  573. ], { force: true });
  574. });
  575. // this is needed for the modules for the declaration files.
  576. gulp.task("modules-compile", function () {
  577. var tsResult = gulp.src(config.typescript)
  578. .pipe(sourcemaps.init())
  579. .pipe(tsProject());
  580. // If this gulp task is running on travis
  581. if (process.env.TRAVIS) {
  582. tsResult.once("error", function () {
  583. tsResult.once("finish", function () {
  584. console.log("Typescript compile failed");
  585. process.exit(1);
  586. });
  587. });
  588. }
  589. return merge2([
  590. tsResult.dts
  591. .pipe(gulp.dest(config.build.srcOutputDirectory)),
  592. tsResult.js
  593. .pipe(sourcemaps.write("./",
  594. {
  595. includeContent: false,
  596. sourceRoot: (filePath) => {
  597. return "";
  598. }
  599. }))
  600. .pipe(gulp.dest(config.build.srcOutputDirectory))
  601. ]);
  602. });
  603. // this holds the declared objects in each module
  604. let declared = {}
  605. let perFile = {};
  606. let dependencyTree = {};
  607. gulp.task('prepare-for-modules', /*["modules-compile"],*/ function () {
  608. let tasks = [];
  609. Object.keys(config.workloads).forEach((moduleName) => {
  610. let dtsFiles = config.workloads[moduleName].files.map(f => f.replace(".js", ".d.ts"))
  611. let dtsTask = gulp.src(dtsFiles)
  612. .pipe(dtsModuleSupport(moduleName, false, declared, perFile));
  613. tasks.push(dtsTask);
  614. });
  615. // now calculate internal dependencies in the .ts files!
  616. /*Object.keys(config.workloads).forEach((moduleName) => {
  617. let tsFiles = config.workloads[moduleName].files.map(f => f.replace(".js", ".ts"))
  618. let depTask = gulp.src(tsFiles)
  619. .pipe(calculateDependencies(moduleName, perFile, dependencyTree));
  620. tasks.push(depTask);
  621. });*/
  622. return merge2(tasks);
  623. });
  624. gulp.task('prepare-dependency-tree', ["prepare-for-modules"], function () {
  625. let tasks = [];
  626. // now calculate internal dependencies in the .ts files!
  627. Object.keys(config.workloads).forEach((moduleName) => {
  628. let tsFiles = config.workloads[moduleName].files.map(f => f.replace(".js", ".ts"))
  629. let depTask = gulp.src(tsFiles)
  630. .pipe(calculateDependencies(moduleName, perFile, declared, dependencyTree));
  631. tasks.push(depTask);
  632. });
  633. return merge2(tasks);
  634. });
  635. // generate the modules directory, along with commonjs modules and es6 modules
  636. // Note - the generated modules are UNMINIFIED! The user will choose whether they want to minify or not.
  637. gulp.task("modules", ["prepare-dependency-tree"], function () {
  638. let tasks = [];
  639. Object.keys(config.workloads)
  640. .forEach((moduleName) => {
  641. let shadersFiles = [];
  642. processDependency("shaders", config.workloads[moduleName], shadersFiles, true);
  643. for (var index = 0; index < shadersFiles.length; index++) {
  644. shadersFiles[index] = "../../src/Shaders/" + shadersFiles[index] + ".fx";
  645. }
  646. let shaderIncludeFiles = [];
  647. processDependency("shaderIncludes", config.workloads[moduleName], shaderIncludeFiles, true);
  648. for (var index = 0; index < shaderIncludeFiles.length; index++) {
  649. shaderIncludeFiles[index] = "../../src/Shaders/ShadersInclude/" + shaderIncludeFiles[index] + ".fx";
  650. }
  651. let commonJsTask = merge2([
  652. gulp.src(config.workloads[moduleName].files)
  653. .pipe(replace(extendsSearchRegex, ""))
  654. .pipe(replace(decorateSearchRegex, ""))
  655. .pipe(replace(referenceSearchRegex, ""))
  656. .pipe(replace(/var BABYLON;\n/g, ""))
  657. .pipe(babylonModuleExports(moduleName, dependencyTree, false, perFile, shadersFiles.length, shaderIncludeFiles.length))
  658. .pipe(rename(function (path) {
  659. path.basename = path.basename.split(".").pop()
  660. path.extname = ".js"
  661. })),
  662. gulp.src(shadersFiles)
  663. .pipe(expect.real({ errorOnFailure: true }, shadersFiles))
  664. .pipe(uncommentShader())
  665. .pipe(appendSrcToVariable("BABYLON.Effect.ShadersStore", shadersName, config.build.outputDirectory + '/commonjs/' + moduleName + ".fx", "commonjs"))
  666. .pipe(rename("shaders.js")),
  667. gulp.src(shaderIncludeFiles)
  668. .pipe(expect.real({ errorOnFailure: true }, shaderIncludeFiles))
  669. .pipe(uncommentShader())
  670. .pipe(appendSrcToVariable("BABYLON.Effect.IncludesShadersStore", includeShadersName, config.build.outputDirectory + '/commonjs/' + moduleName + ".include.fx", "commonjs"))
  671. .pipe(rename("shaderIncludes.js")),
  672. gulp.src(config.workloads[moduleName].files)
  673. .pipe(concat('index.js'))
  674. .pipe(babylonModuleExports(moduleName, dependencyTree, true, perFile))
  675. ]).pipe(gulp.dest(config.build.outputDirectory + '/modules/' + moduleName + '/'))
  676. let es6Tasks = merge2([
  677. gulp.src(config.workloads[moduleName].files)
  678. .pipe(replace(extendsSearchRegex, ""))
  679. .pipe(replace(decorateSearchRegex, ""))
  680. .pipe(replace(referenceSearchRegex, ""))
  681. .pipe(replace(/var BABYLON;\n/g, ""))
  682. .pipe(babylonES6ModuleExports(moduleName, dependencyTree, false, perFile, shadersFiles.length, shaderIncludeFiles.length))
  683. .pipe(rename(function (path) {
  684. path.basename = path.basename.split(".").pop()
  685. path.extname = ".js"
  686. })),
  687. gulp.src(shadersFiles)
  688. .pipe(expect.real({ errorOnFailure: true }, shadersFiles))
  689. .pipe(uncommentShader())
  690. .pipe(appendSrcToVariable("BABYLON.Effect.ShadersStore", shadersName, config.build.outputDirectory + '/es6/' + moduleName + ".fx", "es6"))
  691. .pipe(rename("shaders.js")),
  692. gulp.src(shaderIncludeFiles)
  693. .pipe(expect.real({ errorOnFailure: true }, shaderIncludeFiles))
  694. .pipe(uncommentShader())
  695. .pipe(appendSrcToVariable("BABYLON.Effect.IncludesShadersStore", includeShadersName, config.build.outputDirectory + '/es6/' + moduleName + ".include.fx", "es6"))
  696. .pipe(rename("shaderIncludes.js")),
  697. gulp.src(config.workloads[moduleName].files)
  698. .pipe(concat('index.js'))
  699. .pipe(babylonES6ModuleExports(moduleName, dependencyTree, true, perFile))
  700. ]).pipe(gulp.dest(config.build.outputDirectory + '/modules/' + moduleName + '/es6/'))
  701. //commonjs js generation task
  702. /*let jsTask = merge2([
  703. gulp.src(config.workloads[moduleName].files),
  704. gulp.src(shadersFiles).
  705. //pipe(expect.real({ errorOnFailure: true }, shadersFiles)).
  706. pipe(uncommentShader()).
  707. pipe(appendSrcToVariable("BABYLON.Effect.ShadersStore", shadersName, config.build.outputDirectory + '/commonjs/' + moduleName + ".fx", true)),
  708. gulp.src(shaderIncludeFiles).
  709. //pipe(expect.real({ errorOnFailure: true }, shaderIncludeFiles)).
  710. pipe(uncommentShader()).
  711. pipe(appendSrcToVariable("BABYLON.Effect.IncludesShadersStore", includeShadersName, config.build.outputDirectory + '/commonjs/' + moduleName + ".include.fx", true))
  712. ]).pipe(concat('index.js'))
  713. .pipe(replace(extendsSearchRegex, ""))
  714. .pipe(replace(decorateSearchRegex, ""))
  715. .pipe(replace(referenceSearchRegex, ""))
  716. .pipe(babylonModuleExports(moduleName, config.workloads[moduleName].dependUpon))
  717. .pipe(gulp.dest(config.build.outputDirectory + '/modules/' + moduleName + '/'));*/
  718. // es6 modules generation task
  719. /*let es6Task = merge2([
  720. gulp.src(config.workloads[moduleName].files),
  721. gulp.src(shadersFiles).
  722. //pipe(expect.real({ errorOnFailure: true }, shadersFiles)).
  723. pipe(uncommentShader()).
  724. pipe(appendSrcToVariable("BABYLON.Effect.ShadersStore", shadersName, config.build.outputDirectory + '/commonjs/' + moduleName + ".fx", true)),
  725. gulp.src(shaderIncludeFiles).
  726. //pipe(expect.real({ errorOnFailure: true }, shaderIncludeFiles)).
  727. pipe(uncommentShader()).
  728. pipe(appendSrcToVariable("BABYLON.Effect.IncludesShadersStore", includeShadersName, config.build.outputDirectory + '/commonjs/' + moduleName + ".include.fx", true))
  729. ]).pipe(concat('es6.js'))
  730. .pipe(replace(extendsSearchRegex, ""))
  731. .pipe(replace(decorateSearchRegex, ""))
  732. .pipe(replace(referenceSearchRegex, ""))
  733. .pipe(replace(/var BABYLON;/g, ""))
  734. .pipe(babylonES6ModuleExports(moduleName, config.workloads[moduleName].dependUpon))
  735. .pipe(gulp.dest(config.build.outputDirectory + '/modules/' + moduleName + '/'));
  736. // dts genration task
  737. let dtsFiles = config.workloads[moduleName].files.map(f => f.replace(".js", ".d.ts"))
  738. let dtsTask = gulp.src(dtsFiles)
  739. .pipe(concat("index.d.ts"))
  740. .pipe(replace(/declare module BABYLON {/g, `declare module 'babylonjs/${moduleName}' {`))
  741. .pipe(replace(/\ninterface /g, `\nexport interface `))
  742. .pipe(dtsModuleSupport(moduleName, true, declared, perFile, dependencyTree))
  743. .pipe(gulp.dest(config.build.outputDirectory + '/modules/' + moduleName + '/'));
  744. */
  745. tasks.push(commonJsTask, es6Tasks);
  746. });
  747. // run da tasks man!
  748. return merge2(tasks);
  749. })
  750. /**
  751. * Generate the TypeDoc JSON output in order to create code metadata.
  752. */
  753. gulp.task("typedoc-generate", function () {
  754. return gulp
  755. .src(["../../dist/preview release/babylon.d.ts"])
  756. .pipe(typedoc({
  757. // TypeScript options (see typescript docs)
  758. mode: "modules",
  759. module: "commonjs",
  760. target: "es5",
  761. includeDeclarations: true,
  762. // Output options (see typedoc docs)
  763. json: config.build.typedocJSON,
  764. // TypeDoc options (see typedoc docs)
  765. ignoreCompilerErrors: true,
  766. readme: "none",
  767. excludeExternals: true,
  768. excludePrivate: true,
  769. excludeProtected: true,
  770. entryPoint: ["\"babylon.d\"", "BABYLON"]
  771. }));
  772. });
  773. /**
  774. * Validate the TypeDoc JSON output against the current baselin to ensure our code is correctly documented.
  775. * (in the newly introduced areas)
  776. */
  777. gulp.task("typedoc-validate", function () {
  778. return gulp.src(config.build.typedocJSON)
  779. .pipe(validateTypedoc(config.build.typedocValidationBaseline, "BABYLON", true, false));
  780. });
  781. /**
  782. * Generate the validation reference to ensure our code is correctly documented.
  783. */
  784. gulp.task("typedoc-generateValidationBaseline", function () {
  785. return gulp.src(config.build.typedocJSON)
  786. .pipe(validateTypedoc(config.build.typedocValidationBaseline, "BABYLON", true, true));
  787. });
  788. /**
  789. * Validate the code comments and style case convention through typedoc and
  790. * generate the new baseline.
  791. */
  792. gulp.task("typedoc-all", function (cb) {
  793. runSequence("typedoc-generate", "typedoc-validate", "typedoc-generateValidationBaseline", cb);
  794. });
  795. /**
  796. * Validate compile the code and check the comments and style case convention through typedoc
  797. */
  798. gulp.task("typedoc-check", function (cb) {
  799. runSequence("typescript-compile", "typedoc-generate", "typedoc-validate", cb);
  800. });
  801. /**
  802. * Launches the KARMA validation tests in chrome in order to debug them.
  803. * (Can only be launch locally.)
  804. */
  805. gulp.task("tests-validation-karma", function (done) {
  806. var kamaServerOptions = {
  807. configFile: __dirname + "/../../tests/validation/karma.conf.js",
  808. singleRun: false
  809. };
  810. var server = new karmaServer(kamaServerOptions, done);
  811. server.start();
  812. });
  813. /**
  814. * Launches the KARMA validation tests in ff or virtual screen ff on travis for a quick analysis during the build.
  815. * (Can only be launch on any branches.)
  816. */
  817. gulp.task("tests-validation-virtualscreen", function (done) {
  818. var kamaServerOptions = {
  819. configFile: __dirname + "/../../tests/validation/karma.conf.js",
  820. singleRun: true,
  821. browsers: ['Firefox']
  822. };
  823. var server = new karmaServer(kamaServerOptions, done);
  824. server.start();
  825. });
  826. /**
  827. * Launches the KARMA validation tests in browser stack for remote and cross devices validation tests.
  828. * (Can only be launch from secure branches.)
  829. */
  830. gulp.task("tests-validation-browserstack", function (done) {
  831. if (!process.env.BROWSER_STACK_USERNAME) {
  832. done();
  833. return;
  834. }
  835. var kamaServerOptions = {
  836. configFile: __dirname + "/../../tests/validation/karma.conf.browserstack.js",
  837. singleRun: true
  838. };
  839. var server = new karmaServer(kamaServerOptions, done);
  840. server.start();
  841. });
  842. /**
  843. * Transpiles typescript unit tests.
  844. */
  845. gulp.task("tests-unit-transpile", function (done) {
  846. var tsProject = typescript.createProject('../../tests/unit/tsconfig.json');
  847. var tsResult = gulp.src("../../tests/unit/**/*.ts", { base: "../../" })
  848. .pipe(tsProject());
  849. tsResult.once("error", function () {
  850. tsResult.once("finish", function () {
  851. console.log("Typescript compile failed");
  852. process.exit(1);
  853. });
  854. });
  855. return tsResult.js.pipe(gulp.dest("../../"));
  856. });
  857. /**
  858. * Launches the KARMA unit tests in phantomJS.
  859. * (Can only be launch on any branches.)
  860. */
  861. gulp.task("tests-unit-debug", ["tests-unit-transpile"], function (done) {
  862. var kamaServerOptions = {
  863. configFile: __dirname + "/../../tests/unit/karma.conf.js",
  864. singleRun: false,
  865. browsers: ['Chrome']
  866. };
  867. var server = new karmaServer(kamaServerOptions, done);
  868. server.start();
  869. });
  870. /**
  871. * Launches the KARMA unit tests in phantomJS.
  872. * (Can only be launch on any branches.)
  873. */
  874. gulp.task("tests-unit", ["tests-unit-transpile"], function (done) {
  875. var kamaServerOptions = {
  876. configFile: __dirname + "/../../tests/unit/karma.conf.js",
  877. singleRun: true
  878. };
  879. var server = new karmaServer(kamaServerOptions, done);
  880. server.start();
  881. });
  882. gulp.task("tests-whatsnew", function (done) {
  883. // Only checks on Travis
  884. if (!process.env.TRAVIS) {
  885. done();
  886. return;
  887. }
  888. // Only checks on Pull Requests
  889. if (process.env.TRAVIS_PULL_REQUEST == "false") {
  890. done();
  891. return;
  892. }
  893. // Do not check deploy
  894. if (process.env.TRAVIS_BRANCH == "preview") {
  895. done();
  896. return;
  897. }
  898. // Compare what's new with the current one in the preview release folder.
  899. const https = require("https");
  900. const url = "https://rawgit.com/BabylonJS/Babylon.js/master/dist/preview%20release/what's%20new.md";
  901. https.get(url, res => {
  902. res.setEncoding("utf8");
  903. let oldData = "";
  904. res.on("data", data => {
  905. oldData += data;
  906. });
  907. res.on("end", () => {
  908. fs.readFile("../../dist/preview release/what's new.md", "utf-8", function (err, newData) {
  909. if (err || oldData != newData) {
  910. done();
  911. return;
  912. }
  913. console.error("What's new file did not change.");
  914. process.exit(1);
  915. });
  916. });
  917. });
  918. });