gulpfile.js 47 KB

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