gulpfile.js 47 KB

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