gulpfile.js 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  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. if (settings.build.outputs) {
  400. settings.build.outputs.forEach(out => {
  401. let wpConfig = require(library.webpack);
  402. if (!out.minified) {
  403. wpConfig.mode = "development";
  404. }
  405. console.log(wpConfig)
  406. let wpBuild = webpackStream(wpConfig, webpack);
  407. //shoud dtsBundle create the declaration?
  408. if (settings.build.dtsBundle) {
  409. let event = wpBuild
  410. .pipe(through.obj(function (file, enc, cb) {
  411. // only declaration files
  412. const isdts = /\.d\.ts$/.test(file.path);
  413. if (isdts) this.push(file);
  414. cb();
  415. }))
  416. .pipe(gulp.dest(outputDirectory));
  417. // dts-bundle does NOT support (gulp) streams, so files have to be saved and reloaded,
  418. // until I fix it
  419. event.on("end", function () {
  420. // create the file
  421. dtsBundle.bundle(settings.build.dtsBundle);
  422. // prepend the needed reference
  423. let fileLocation = path.join(path.dirname(settings.build.dtsBundle.main), settings.build.dtsBundle.out);
  424. fs.readFile(fileLocation, function (err, data) {
  425. if (err) throw err;
  426. data = (settings.build.dtsBundle.prependText || "") + '\n' + data.toString();
  427. fs.writeFile(fileLocation, data);
  428. if (settings.build.processDeclaration) {
  429. var newData = processDeclaration(data, settings.build.processDeclaration);
  430. fs.writeFile(fileLocation.replace('.module', ''), newData);
  431. }
  432. });
  433. });
  434. }
  435. let build = wpBuild
  436. .pipe(through.obj(function (file, enc, cb) {
  437. // only pipe js files
  438. const isJs = /\.js$/.test(file.path);
  439. if (isJs) this.push(file);
  440. cb();
  441. }))
  442. .pipe(addModuleExports(library.moduleDeclaration, { subModule: false, extendsRoot: false, externalUsingBabylon: true, noBabylonInit: library.babylonIncluded }));
  443. function processDestination(dest) {
  444. var outputDirectory = config.build.outputDirectory + dest.outputDirectory;
  445. build = build
  446. .pipe(rename(dest.filename.replace(".js", library.noBundleInName ? '.js' : ".bundle.js")))
  447. .pipe(gulp.dest(outputDirectory));
  448. if (library.babylonIncluded && dest.addBabylonDeclaration) {
  449. // include the babylon declaration
  450. if (dest.addBabylonDeclaration === true) {
  451. dest.addBabylonDeclaration = [config.build.declarationFilename];
  452. }
  453. var decsToAdd = dest.addBabylonDeclaration.map(function (dec) {
  454. return config.build.outputDirectory + '/' + dec;
  455. });
  456. sequence.unshift(gulp.src(decsToAdd)
  457. .pipe(rename(function (path) {
  458. path.dirname = '';
  459. }))
  460. .pipe(gulp.dest(outputDirectory)))
  461. }
  462. }
  463. out.destinations.forEach(dest => {
  464. processDestination(dest);
  465. });
  466. sequence.push(build);
  467. });
  468. } else {
  469. let wpBuild = webpackStream(require(library.webpack), webpack);
  470. let buildEvent = wpBuild
  471. .pipe(gulp.dest(outputDirectory))
  472. //back-compat
  473. .pipe(through.obj(function (file, enc, cb) {
  474. // only js files
  475. const isjs = /\.js$/.test(file.path);
  476. if (isjs) this.push(file);
  477. cb();
  478. }))
  479. .pipe(rename(library.output.replace(".js", ".max.js")))
  480. .pipe(rename(library.output.replace(".min.max.", ".")))
  481. .pipe(rename(library.output.replace(".bundle.max.", ".")))
  482. .pipe(gulp.dest(outputDirectory));
  483. sequence.push(
  484. buildEvent
  485. );
  486. if (settings.build.dtsBundle || settings.build.processDeclaration) {
  487. buildEvent.on("end", function () {
  488. if (settings.build.dtsBundle) {
  489. dtsBundle.bundle(settings.build.dtsBundle);
  490. } if (settings.build.processDeclaration) {
  491. let fileLocation = path.join(outputDirectory, settings.build.processDeclaration.filename);
  492. fs.readFile(fileLocation, function (err, data) {
  493. if (err) throw err;
  494. var newData = processDeclaration(data, settings.build.processDeclaration);
  495. fs.writeFile(fileLocation.replace('.module', ''), newData);
  496. });
  497. }
  498. });
  499. }
  500. /*if (settings.build.processDeclaration) {
  501. sequence.push(
  502. wpBuild
  503. .pipe(through.obj(function (file, enc, cb) {
  504. // only js files
  505. const isDts = /\.d.ts$/.test(file.path);
  506. file.contents = new Buffer(processDeclaration(file.contents, settings.build.processDeclaration));
  507. if (isDts) this.push(file);
  508. cb();
  509. }))
  510. .pipe(gulp.dest(outputDirectory))
  511. )
  512. }*/
  513. }
  514. return merge2(sequence);
  515. }
  516. else {
  517. return waitAll;
  518. }
  519. }
  520. }
  521. /**
  522. * The default task, concat and min the main BJS files.
  523. */
  524. gulp.task("default", function (cb) {
  525. runSequence("typescript-all", "intellisense", "typedoc-all", "tests-unit", "tests-validation-virtualscreen", "tests-validation-browserstack", cb);
  526. });
  527. gulp.task("mainBuild", function (cb) {
  528. runSequence("buildWorker", "build", cb);
  529. });
  530. /**
  531. * Build the releasable files.
  532. */
  533. gulp.task("typescript", function (cb) {
  534. runSequence("typescript-compile", "mainBuild", cb);
  535. });
  536. /**
  537. * Dynamic module creation.
  538. */
  539. config.modules.map(function (module) {
  540. gulp.task(module, function () {
  541. return buildExternalLibraries(config[module]);
  542. });
  543. });
  544. gulp.task("typescript-libraries", config.modules, function () {
  545. });
  546. /**
  547. * Custom build with full path file control; used by profile.html
  548. */
  549. gulp.task("build-custom", function (cb) {
  550. runSequence("typescript-compile", "build", cb);
  551. });
  552. /**
  553. * Do it all.
  554. */
  555. gulp.task("typescript-all", function (cb) {
  556. runSequence("typescript", "typescript-libraries", "netlify-cleanup", cb);
  557. });
  558. /**
  559. * Watch ts files from typescript .
  560. */
  561. gulp.task("srcTscWatch", function () {
  562. // Reuse The TSC CLI from gulp to enable -w.
  563. process.argv[2] = "-w";
  564. process.argv[3] = "-p";
  565. process.argv[4] = "../../src/tsconfig.json";
  566. require("./node_modules/typescript/lib/tsc.js");
  567. });
  568. /**
  569. * Watch ts files and fire repective tasks.
  570. */
  571. gulp.task("watch", ["srcTscWatch"], function () {
  572. var interval = 1000;
  573. var tasks = [];
  574. config.modules.map(function (module) {
  575. config[module].libraries.map(function (library) {
  576. if (library.webpack) {
  577. if (library.noWatch) return;
  578. var outputDirectory = config.build.tempDirectory + config[module].build.distOutputDirectory;
  579. let wpconfig = require(library.webpack);
  580. wpconfig.watch = true;
  581. // dev mode and absolute path sourcemaps for debugging
  582. wpconfig.mode = "development";
  583. wpconfig.output.devtoolModuleFilenameTemplate = "[absolute-resource-path]";
  584. //config.stats = "minimal";
  585. tasks.push(webpackStream(wpconfig, webpack).pipe(gulp.dest(outputDirectory)))
  586. } else {
  587. tasks.push(gulp.watch(library.files, { interval: interval }, function () {
  588. console.log(library.output);
  589. return buildExternalLibrary(library, config[module], true)
  590. .pipe(debug());
  591. }));
  592. tasks.push(gulp.watch(library.shaderFiles, { interval: interval }, function () {
  593. console.log(library.output);
  594. return buildExternalLibrary(library, config[module], true)
  595. .pipe(debug())
  596. }));
  597. tasks.push(gulp.watch(library.sassFiles, { interval: interval }, function () {
  598. console.log(library.output);
  599. return buildExternalLibrary(library, config[module], true)
  600. .pipe(debug())
  601. }));
  602. }
  603. });
  604. });
  605. return tasks;
  606. });
  607. gulp.task("intellisense", function () {
  608. gulp.src(config.build.intellisenseSources)
  609. .pipe(concat(config.build.intellisenseFile))
  610. .pipe(replace(/^\s+_.*?;/gm, ""))
  611. .pipe(replace(/^\s+_[\S\s]*?}/gm, ""))
  612. .pipe(replace(/^\s*readonly _/gm, "protected readonly _"))
  613. .pipe(replace(/^\s*static _/gm, "private static _"))
  614. .pipe(replace(/^\s*abstract _/gm, ""))
  615. .pipe(gulp.dest(config.build.playgroundDirectory));
  616. });
  617. /**
  618. * Embedded local dev env management.
  619. */
  620. gulp.task("deployLocalDev", function () {
  621. gulp.src("../../localDev/template/**.*")
  622. .pipe(gulp.dest("../../localDev/src/"));
  623. });
  624. /**
  625. * Embedded webserver for test convenience.
  626. */
  627. gulp.task("webserver", function () {
  628. var options = {
  629. port: 1338,
  630. livereload: false,
  631. };
  632. if (commandLineOptions.public) {
  633. options.host = "0.0.0.0";
  634. }
  635. gulp.src("../../.").pipe(webserver(options));
  636. });
  637. /**
  638. * Combine Webserver and Watch as long as vscode does not handle multi tasks.
  639. */
  640. gulp.task("run", ["watch", "webserver"], function () {
  641. });
  642. /**
  643. * Cleans map and js files from the src folder.
  644. */
  645. gulp.task("clean-JS-MAP", function () {
  646. return del([
  647. "../../src/**/*.js.map", "../../src/**/*.js"
  648. ], { force: true });
  649. });
  650. gulp.task("netlify-cleanup", function () {
  651. //set by netlify
  652. if (process.env.REPOSITORY_URL) {
  653. return del([
  654. "../../inspector/node_modules/**/*", "../../gui/node_modules/**/*",
  655. "../../Viewer/node_modules/**/*"
  656. ], { force: true });
  657. }
  658. else {
  659. return true;
  660. }
  661. })
  662. // this is needed for the modules for the declaration files.
  663. gulp.task("modules-compile", function () {
  664. var tsResult = gulp.src(config.typescript)
  665. .pipe(sourcemaps.init())
  666. .pipe(tsProject());
  667. // If this gulp task is running on travis
  668. if (process.env.TRAVIS) {
  669. tsResult.once("error", function () {
  670. tsResult.once("finish", function () {
  671. console.log("Typescript compile failed");
  672. process.exit(1);
  673. });
  674. });
  675. }
  676. return merge2([
  677. tsResult.dts
  678. .pipe(gulp.dest(config.build.srcOutputDirectory)),
  679. tsResult.js
  680. .pipe(sourcemaps.write("./",
  681. {
  682. includeContent: false,
  683. sourceRoot: (filePath) => {
  684. return "";
  685. }
  686. }))
  687. .pipe(gulp.dest(config.build.srcOutputDirectory))
  688. ]);
  689. });
  690. // this holds the declared objects in each module
  691. let declared = {}
  692. let perFile = {};
  693. let dependencyTree = {};
  694. gulp.task('prepare-for-modules', /*["modules-compile"],*/ function () {
  695. let tasks = [];
  696. Object.keys(config.workloads).forEach((moduleName) => {
  697. let dtsFiles = config.workloads[moduleName].files.map(f => f.replace(".js", ".d.ts"))
  698. let dtsTask = gulp.src(dtsFiles)
  699. .pipe(dtsModuleSupport(moduleName, false, declared, perFile));
  700. tasks.push(dtsTask);
  701. });
  702. // now calculate internal dependencies in the .ts files!
  703. /*Object.keys(config.workloads).forEach((moduleName) => {
  704. let tsFiles = config.workloads[moduleName].files.map(f => f.replace(".js", ".ts"))
  705. let depTask = gulp.src(tsFiles)
  706. .pipe(calculateDependencies(moduleName, perFile, dependencyTree));
  707. tasks.push(depTask);
  708. });*/
  709. return merge2(tasks);
  710. });
  711. gulp.task('prepare-dependency-tree', ["prepare-for-modules"], function () {
  712. let tasks = [];
  713. // now calculate internal dependencies in the .ts files!
  714. Object.keys(config.workloads).forEach((moduleName) => {
  715. let tsFiles = config.workloads[moduleName].files.map(f => f.replace(".js", ".ts"))
  716. let depTask = gulp.src(tsFiles)
  717. .pipe(calculateDependencies(moduleName, perFile, declared, dependencyTree));
  718. tasks.push(depTask);
  719. });
  720. return merge2(tasks);
  721. });
  722. // generate the modules directory, along with commonjs modules and es6 modules
  723. // Note - the generated modules are UNMINIFIED! The user will choose whether they want to minify or not.
  724. gulp.task("modules", ["prepare-dependency-tree"], function () {
  725. let tasks = [];
  726. Object.keys(config.workloads)
  727. .forEach((moduleName) => {
  728. let shadersFiles = [];
  729. processDependency("shaders", config.workloads[moduleName], shadersFiles, true);
  730. for (var index = 0; index < shadersFiles.length; index++) {
  731. shadersFiles[index] = "../../src/Shaders/" + shadersFiles[index] + ".fx";
  732. }
  733. let shaderIncludeFiles = [];
  734. processDependency("shaderIncludes", config.workloads[moduleName], shaderIncludeFiles, true);
  735. for (var index = 0; index < shaderIncludeFiles.length; index++) {
  736. shaderIncludeFiles[index] = "../../src/Shaders/ShadersInclude/" + shaderIncludeFiles[index] + ".fx";
  737. }
  738. let commonJsTask = merge2([
  739. gulp.src(config.workloads[moduleName].files)
  740. .pipe(replace(extendsSearchRegex, ""))
  741. .pipe(replace(decorateSearchRegex, ""))
  742. .pipe(replace(referenceSearchRegex, ""))
  743. .pipe(replace(/var BABYLON;\n/g, ""))
  744. .pipe(babylonModuleExports(moduleName, dependencyTree, false, perFile, shadersFiles.length, shaderIncludeFiles.length))
  745. .pipe(rename(function (path) {
  746. path.basename = path.basename.split(".").pop()
  747. path.extname = ".js"
  748. })),
  749. gulp.src(shadersFiles)
  750. .pipe(expect.real({ errorOnFailure: true }, shadersFiles))
  751. .pipe(uncommentShader())
  752. .pipe(appendSrcToVariable("BABYLON.Effect.ShadersStore", shadersName, config.build.outputDirectory + '/commonjs/' + moduleName + ".fx", "commonjs"))
  753. .pipe(rename("shaders.js")),
  754. gulp.src(shaderIncludeFiles)
  755. .pipe(expect.real({ errorOnFailure: true }, shaderIncludeFiles))
  756. .pipe(uncommentShader())
  757. .pipe(appendSrcToVariable("BABYLON.Effect.IncludesShadersStore", includeShadersName, config.build.outputDirectory + '/commonjs/' + moduleName + ".include.fx", "commonjs"))
  758. .pipe(rename("shaderIncludes.js")),
  759. gulp.src(config.workloads[moduleName].files)
  760. .pipe(concat('index.js'))
  761. .pipe(babylonModuleExports(moduleName, dependencyTree, true, perFile))
  762. ]).pipe(gulp.dest(config.build.outputDirectory + '/modules/' + moduleName + '/'))
  763. let es6Tasks = merge2([
  764. gulp.src(config.workloads[moduleName].files)
  765. .pipe(replace(extendsSearchRegex, ""))
  766. .pipe(replace(decorateSearchRegex, ""))
  767. .pipe(replace(referenceSearchRegex, ""))
  768. .pipe(replace(/var BABYLON;\n/g, ""))
  769. .pipe(babylonES6ModuleExports(moduleName, dependencyTree, false, perFile, shadersFiles.length, shaderIncludeFiles.length))
  770. .pipe(rename(function (path) {
  771. path.basename = path.basename.split(".").pop()
  772. path.extname = ".js"
  773. })),
  774. gulp.src(shadersFiles)
  775. .pipe(expect.real({ errorOnFailure: true }, shadersFiles))
  776. .pipe(uncommentShader())
  777. .pipe(appendSrcToVariable("BABYLON.Effect.ShadersStore", shadersName, config.build.outputDirectory + '/es6/' + moduleName + ".fx", "es6"))
  778. .pipe(rename("shaders.js")),
  779. gulp.src(shaderIncludeFiles)
  780. .pipe(expect.real({ errorOnFailure: true }, shaderIncludeFiles))
  781. .pipe(uncommentShader())
  782. .pipe(appendSrcToVariable("BABYLON.Effect.IncludesShadersStore", includeShadersName, config.build.outputDirectory + '/es6/' + moduleName + ".include.fx", "es6"))
  783. .pipe(rename("shaderIncludes.js")),
  784. gulp.src(config.workloads[moduleName].files)
  785. .pipe(concat('index.js'))
  786. .pipe(babylonES6ModuleExports(moduleName, dependencyTree, true, perFile))
  787. ]).pipe(gulp.dest(config.build.outputDirectory + '/modules/' + moduleName + '/es6/'))
  788. //commonjs js generation task
  789. /*let jsTask = merge2([
  790. gulp.src(config.workloads[moduleName].files),
  791. gulp.src(shadersFiles).
  792. //pipe(expect.real({ errorOnFailure: true }, shadersFiles)).
  793. pipe(uncommentShader()).
  794. pipe(appendSrcToVariable("BABYLON.Effect.ShadersStore", shadersName, config.build.outputDirectory + '/commonjs/' + moduleName + ".fx", true)),
  795. gulp.src(shaderIncludeFiles).
  796. //pipe(expect.real({ errorOnFailure: true }, shaderIncludeFiles)).
  797. pipe(uncommentShader()).
  798. pipe(appendSrcToVariable("BABYLON.Effect.IncludesShadersStore", includeShadersName, config.build.outputDirectory + '/commonjs/' + moduleName + ".include.fx", true))
  799. ]).pipe(concat('index.js'))
  800. .pipe(replace(extendsSearchRegex, ""))
  801. .pipe(replace(decorateSearchRegex, ""))
  802. .pipe(replace(referenceSearchRegex, ""))
  803. .pipe(babylonModuleExports(moduleName, config.workloads[moduleName].dependUpon))
  804. .pipe(gulp.dest(config.build.outputDirectory + '/modules/' + moduleName + '/'));*/
  805. // es6 modules generation task
  806. /*let es6Task = merge2([
  807. gulp.src(config.workloads[moduleName].files),
  808. gulp.src(shadersFiles).
  809. //pipe(expect.real({ errorOnFailure: true }, shadersFiles)).
  810. pipe(uncommentShader()).
  811. pipe(appendSrcToVariable("BABYLON.Effect.ShadersStore", shadersName, config.build.outputDirectory + '/commonjs/' + moduleName + ".fx", true)),
  812. gulp.src(shaderIncludeFiles).
  813. //pipe(expect.real({ errorOnFailure: true }, shaderIncludeFiles)).
  814. pipe(uncommentShader()).
  815. pipe(appendSrcToVariable("BABYLON.Effect.IncludesShadersStore", includeShadersName, config.build.outputDirectory + '/commonjs/' + moduleName + ".include.fx", true))
  816. ]).pipe(concat('es6.js'))
  817. .pipe(replace(extendsSearchRegex, ""))
  818. .pipe(replace(decorateSearchRegex, ""))
  819. .pipe(replace(referenceSearchRegex, ""))
  820. .pipe(replace(/var BABYLON;/g, ""))
  821. .pipe(babylonES6ModuleExports(moduleName, config.workloads[moduleName].dependUpon))
  822. .pipe(gulp.dest(config.build.outputDirectory + '/modules/' + moduleName + '/'));
  823. // dts genration task
  824. let dtsFiles = config.workloads[moduleName].files.map(f => f.replace(".js", ".d.ts"))
  825. let dtsTask = gulp.src(dtsFiles)
  826. .pipe(concat("index.d.ts"))
  827. .pipe(replace(/declare module BABYLON {/g, `declare module 'babylonjs/${moduleName}' {`))
  828. .pipe(replace(/\ninterface /g, `\nexport interface `))
  829. .pipe(dtsModuleSupport(moduleName, true, declared, perFile, dependencyTree))
  830. .pipe(gulp.dest(config.build.outputDirectory + '/modules/' + moduleName + '/'));
  831. */
  832. tasks.push(commonJsTask, es6Tasks);
  833. });
  834. // run da tasks man!
  835. return merge2(tasks);
  836. })
  837. /**
  838. * Generate the TypeDoc JSON output in order to create code metadata.
  839. */
  840. gulp.task("typedoc-generate", function () {
  841. return gulp
  842. .src([
  843. "../../dist/preview release/babylon.d.ts",
  844. "../../dist/preview release/gui/babylon.gui.d.ts",
  845. "../../dist/preview release/loaders/babylon.glTF2FileLoader.d.ts",
  846. "../../dist/preview release/serializers/babylon.glTF2Serializer.d.ts",
  847. "../../dist/preview release/glTF2Interface/babylon.glTF2Interface.d.ts"])
  848. .pipe(typedoc({
  849. // TypeScript options (see typescript docs)
  850. mode: "modules",
  851. module: "commonjs",
  852. target: "es5",
  853. includeDeclarations: true,
  854. // Output options (see typedoc docs)
  855. json: config.build.typedocJSON,
  856. // TypeDoc options (see typedoc docs)
  857. ignoreCompilerErrors: true,
  858. readme: "none",
  859. excludeExternals: true,
  860. excludePrivate: true,
  861. excludeProtected: true,
  862. entryPoint: ["\"babylon.d\"", "BABYLON"]
  863. }));
  864. });
  865. /**
  866. * Validate the TypeDoc JSON output against the current baselin to ensure our code is correctly documented.
  867. * (in the newly introduced areas)
  868. */
  869. gulp.task("typedoc-validate", function () {
  870. return gulp.src(config.build.typedocJSON)
  871. .pipe(validateTypedoc(config.build.typedocValidationBaseline, "BABYLON", true, false));
  872. });
  873. /**
  874. * Generate the validation reference to ensure our code is correctly documented.
  875. */
  876. gulp.task("typedoc-generateValidationBaseline", function () {
  877. return gulp.src(config.build.typedocJSON)
  878. .pipe(validateTypedoc(config.build.typedocValidationBaseline, "BABYLON", true, true));
  879. });
  880. /**
  881. * Validate the code comments and style case convention through typedoc and
  882. * generate the new baseline.
  883. */
  884. gulp.task("typedoc-all", function (cb) {
  885. runSequence("typedoc-generate", "typedoc-validate", "typedoc-generateValidationBaseline", cb);
  886. });
  887. /**
  888. * Validate compile the code and check the comments and style case convention through typedoc
  889. */
  890. gulp.task("typedoc-check", function (cb) {
  891. runSequence("typescript-compile", "gui", "loaders", "serializers", "typedoc-generate", "typedoc-validate", cb);
  892. });
  893. /**
  894. * Launches the KARMA validation tests in chrome in order to debug them.
  895. * (Can only be launch locally.)
  896. */
  897. gulp.task("tests-validation-karma", function (done) {
  898. var kamaServerOptions = {
  899. configFile: __dirname + "/../../tests/validation/karma.conf.js",
  900. singleRun: false
  901. };
  902. var server = new karmaServer(kamaServerOptions, done);
  903. server.start();
  904. });
  905. /**
  906. * Launches the KARMA validation tests in ff or virtual screen ff on travis for a quick analysis during the build.
  907. * (Can only be launch on any branches.)
  908. */
  909. gulp.task("tests-validation-virtualscreen", function (done) {
  910. var kamaServerOptions = {
  911. configFile: __dirname + "/../../tests/validation/karma.conf.js",
  912. singleRun: true,
  913. browsers: ['Firefox']
  914. };
  915. var server = new karmaServer(kamaServerOptions, done);
  916. server.start();
  917. });
  918. /**
  919. * Launches the KARMA validation tests in browser stack for remote and cross devices validation tests.
  920. * (Can only be launch from secure branches.)
  921. */
  922. gulp.task("tests-validation-browserstack", function (done) {
  923. if (!process.env.BROWSER_STACK_USERNAME) {
  924. done();
  925. return;
  926. }
  927. var kamaServerOptions = {
  928. configFile: __dirname + "/../../tests/validation/karma.conf.browserstack.js",
  929. singleRun: true
  930. };
  931. var server = new karmaServer(kamaServerOptions, done);
  932. server.start();
  933. });
  934. /**
  935. * Transpiles typescript unit tests.
  936. */
  937. gulp.task("tests-unit-transpile", function (done) {
  938. var tsProject = typescript.createProject('../../tests/unit/tsconfig.json');
  939. var tsResult = gulp.src("../../tests/unit/**/*.ts", { base: "../../" })
  940. .pipe(tsProject());
  941. tsResult.once("error", function () {
  942. tsResult.once("finish", function () {
  943. console.log("Typescript compile failed");
  944. process.exit(1);
  945. });
  946. });
  947. return tsResult.js.pipe(gulp.dest("../../"));
  948. });
  949. /**
  950. * Launches the KARMA unit tests in phantomJS.
  951. * (Can only be launch on any branches.)
  952. */
  953. gulp.task("tests-unit-debug", ["tests-unit-transpile"], function (done) {
  954. var kamaServerOptions = {
  955. configFile: __dirname + "/../../tests/unit/karma.conf.js",
  956. singleRun: false,
  957. browsers: ['Chrome']
  958. };
  959. var server = new karmaServer(kamaServerOptions, done);
  960. server.start();
  961. });
  962. gulp.task("tests-babylon-unit", ["tests-unit-transpile"], function (done) {
  963. var kamaServerOptions = {
  964. configFile: __dirname + "/../../tests/unit/karma.conf.js",
  965. singleRun: true
  966. };
  967. var server = new karmaServer(kamaServerOptions, done);
  968. server.start();
  969. });
  970. /**
  971. * Launches the KARMA unit tests in phantomJS.
  972. * (Can only be launch on any branches.)
  973. */
  974. gulp.task("tests-unit", function (cb) {
  975. runSequence("tests-babylon-unit", "tests-viewer-unit", cb);
  976. });
  977. var rmDir = function (dirPath) {
  978. try { var files = fs.readdirSync(dirPath); }
  979. catch (e) { return; }
  980. if (files.length > 0)
  981. for (var i = 0; i < files.length; i++) {
  982. var filePath = dirPath + '/' + files[i];
  983. if (fs.statSync(filePath).isFile())
  984. fs.unlinkSync(filePath);
  985. else
  986. rmDir(filePath);
  987. }
  988. fs.rmdirSync(dirPath);
  989. };
  990. /**
  991. * Launches the viewer's KARMA validation tests in chrome in order to debug them.
  992. * (Can only be launch locally.)
  993. */
  994. gulp.task("tests-viewer-validation-karma", ["tests-viewer-validation-transpile"], function (done) {
  995. var kamaServerOptions = {
  996. configFile: __dirname + "/../../Viewer/tests/validation/karma.conf.js",
  997. singleRun: false
  998. };
  999. var server = new karmaServer(kamaServerOptions, done);
  1000. server.start();
  1001. });
  1002. /**
  1003. * Launches the KARMA validation tests in ff or virtual screen ff on travis for a quick analysis during the build.
  1004. * (Can only be launch on any branches.)
  1005. */
  1006. gulp.task("tests-viewer-validation-virtualscreen", ["tests-viewer-validation-transpile"], function (done) {
  1007. var kamaServerOptions = {
  1008. configFile: __dirname + "/../../Viewer/tests/validation/karma.conf.js",
  1009. singleRun: true,
  1010. browsers: ['Firefox']
  1011. };
  1012. var server = new karmaServer(kamaServerOptions, done);
  1013. server.start();
  1014. });
  1015. /**
  1016. * Launches the KARMA validation tests in browser stack for remote and cross devices validation tests.
  1017. * (Can only be launch from secure branches.)
  1018. */
  1019. gulp.task("tests-viewer-validation-browserstack", ["tests-viewer-validation-transpile"], function (done) {
  1020. if (!process.env.BROWSER_STACK_USERNAME) {
  1021. done();
  1022. return;
  1023. }
  1024. var kamaServerOptions = {
  1025. configFile: __dirname + "/../../Viewer/tests/validation/karma.conf.browserstack.js",
  1026. singleRun: true
  1027. };
  1028. var server = new karmaServer(kamaServerOptions, done);
  1029. server.start();
  1030. });
  1031. /**
  1032. * Transpiles viewer typescript unit tests.
  1033. */
  1034. gulp.task("tests-viewer-validation-transpile", function (done) {
  1035. let wpBuild = webpackStream(require('../../Viewer/webpack.gulp.config.js'), webpack);
  1036. // clean the built directory
  1037. rmDir("../../Viewer/tests/build/");
  1038. return wpBuild
  1039. .pipe(rename(function (path) {
  1040. if (path.extname === '.js') {
  1041. path.basename = "test";
  1042. }
  1043. }))
  1044. .pipe(gulp.dest("../../Viewer/tests/build/"));
  1045. });
  1046. /**
  1047. * Transpiles viewer typescript unit tests.
  1048. */
  1049. gulp.task("tests-viewer-transpile", function (done) {
  1050. let wpBuild = webpackStream(require('../../Viewer/tests/unit/webpack.config.js'), webpack);
  1051. // clean the built directory
  1052. rmDir("../../Viewer/tests/build/");
  1053. return wpBuild
  1054. .pipe(rename(function (path) {
  1055. if (path.extname === '.js') {
  1056. path.basename = "test";
  1057. }
  1058. }))
  1059. .pipe(gulp.dest("../../Viewer/tests/build/"));
  1060. });
  1061. /**
  1062. * Launches the KARMA unit tests in chrome.
  1063. * (Can be launch on any branches.)
  1064. */
  1065. gulp.task("tests-viewer-unit-debug", ["tests-viewer-transpile"], function (done) {
  1066. var kamaServerOptions = {
  1067. configFile: __dirname + "/../../Viewer/tests/karma.conf.js",
  1068. singleRun: false,
  1069. browsers: ['Chrome']
  1070. };
  1071. var server = new karmaServer(kamaServerOptions, done);
  1072. server.start();
  1073. });
  1074. /**
  1075. * Launches the KARMA unit tests in phantomJS.
  1076. * (Can be launch on any branches.)
  1077. */
  1078. gulp.task("tests-viewer-unit", ["tests-viewer-transpile"], function (done) {
  1079. var kamaServerOptions = {
  1080. configFile: __dirname + "/../../Viewer/tests/karma.conf.js",
  1081. singleRun: true
  1082. };
  1083. var server = new karmaServer(kamaServerOptions, done);
  1084. server.start();
  1085. });
  1086. gulp.task("tests-whatsnew", function (done) {
  1087. // Only checks on Travis
  1088. if (!process.env.TRAVIS) {
  1089. done();
  1090. return;
  1091. }
  1092. // Only checks on Pull Requests
  1093. if (process.env.TRAVIS_PULL_REQUEST == "false") {
  1094. done();
  1095. return;
  1096. }
  1097. // Do not check deploy
  1098. if (process.env.TRAVIS_BRANCH == "preview") {
  1099. done();
  1100. return;
  1101. }
  1102. // Compare what's new with the current one in the preview release folder.
  1103. const https = require("https");
  1104. const url = "https://rawgit.com/BabylonJS/Babylon.js/master/dist/preview%20release/what's%20new.md";
  1105. https.get(url, res => {
  1106. res.setEncoding("utf8");
  1107. let oldData = "";
  1108. res.on("data", data => {
  1109. oldData += data;
  1110. });
  1111. res.on("end", () => {
  1112. fs.readFile("../../dist/preview release/what's new.md", "utf-8", function (err, newData) {
  1113. if (err || oldData != newData) {
  1114. done();
  1115. return;
  1116. }
  1117. console.error("What's new file did not change.");
  1118. process.exit(1);
  1119. });
  1120. });
  1121. });
  1122. });