gulpfile.js 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283
  1. var gulp = require("gulp");
  2. var uglify = require("gulp-uglify");
  3. var typescript = require("gulp-typescript");
  4. var sourcemaps = require("gulp-sourcemaps");
  5. var srcToVariable = require("gulp-content-to-variable");
  6. var appendSrcToVariable = require("./gulp-appendSrcToVariable");
  7. var addDtsExport = require("./gulp-addDtsExport");
  8. var addDecorateAndExtends = require("./gulp-decorateAndExtends");
  9. var addModuleExports = require("./gulp-addModuleExports");
  10. var addES6Exports = require("./gulp-addES6Exports");
  11. var babylonModuleExports = require("./gulp-babylonModule");
  12. var babylonES6ModuleExports = require("./gulp-es6ModuleExports");
  13. var dtsModuleSupport = require("./gulp-dtsModuleSupport");
  14. let calculateDependencies = require("./gulp-calculateDependencies");
  15. var merge2 = require("merge2");
  16. var concat = require("gulp-concat");
  17. var rename = require("gulp-rename");
  18. var cleants = require("gulp-clean-ts-extends");
  19. var runSequence = require("run-sequence");
  20. var replace = require("gulp-replace");
  21. var uncommentShader = require("./gulp-removeShaderComments");
  22. var expect = require("gulp-expect-file");
  23. var optimisejs = require("gulp-optimize-js");
  24. var webserver = require("gulp-webserver");
  25. var path = require("path");
  26. var sass = require("gulp-sass");
  27. const webpack = require('webpack');
  28. var webpackStream = require("webpack-stream");
  29. var typedoc = require("gulp-typedoc");
  30. var validateTypedoc = require("./gulp-validateTypedoc");
  31. var fs = require("fs");
  32. var dtsBundle = require('dts-bundle');
  33. const through = require('through2');
  34. var karmaServer = require('karma').Server;
  35. //viewer declaration
  36. var processDeclaration = require('./processViewerDeclaration');
  37. var config = require("./config.json");
  38. var del = require("del");
  39. var debug = require("gulp-debug");
  40. var includeShadersStream;
  41. var shadersStream;
  42. var workersStream;
  43. var extendsSearchRegex = /var\s__extends[\s\S]+?\}\)\(\);/g;
  44. var decorateSearchRegex = /var\s__decorate[\s\S]+?\};/g;
  45. var referenceSearchRegex = /\/\/\/ <reference.*/g;
  46. /**
  47. * TS configurations shared in the gulp file.
  48. */
  49. var tsConfig = {
  50. noResolve: true,
  51. target: "ES5",
  52. declarationFiles: true,
  53. typescript: require("typescript"),
  54. experimentalDecorators: true,
  55. isolatedModules: false,
  56. noImplicitAny: true,
  57. noImplicitReturns: true,
  58. noImplicitThis: true,
  59. noUnusedLocals: true,
  60. strictNullChecks: true,
  61. strictFunctionTypes: true,
  62. types: [],
  63. lib: [
  64. "dom",
  65. "es2015.promise",
  66. "es5"
  67. ]
  68. };
  69. var tsProject = typescript.createProject(tsConfig);
  70. var externalTsConfig = {
  71. noResolve: false,
  72. target: "ES5",
  73. declarationFiles: true,
  74. typescript: require("typescript"),
  75. experimentalDecorators: true,
  76. isolatedModules: false,
  77. noImplicitAny: true,
  78. noImplicitReturns: true,
  79. noImplicitThis: true,
  80. noUnusedLocals: true,
  81. strictNullChecks: true,
  82. types: [],
  83. lib: [
  84. "dom",
  85. "es2015.promise",
  86. "es5"
  87. ]
  88. };
  89. var minimist = require("minimist");
  90. var commandLineOptions = minimist(process.argv.slice(2), {
  91. boolean: "public"
  92. });
  93. function processDependency(kind, dependency, filesToLoad, firstLevelOnly) {
  94. if (!firstLevelOnly && dependency.dependUpon) {
  95. for (var i = 0; i < dependency.dependUpon.length; i++) {
  96. var dependencyName = dependency.dependUpon[i];
  97. var parent = config.workloads[dependencyName];
  98. processDependency(kind, parent, filesToLoad);
  99. }
  100. }
  101. var content = dependency[kind];
  102. if (!content) {
  103. return;
  104. }
  105. for (var i = 0; i < content.length; i++) {
  106. var file = content[i];
  107. if (filesToLoad.indexOf(file) === -1) {
  108. filesToLoad.push(file);
  109. }
  110. }
  111. }
  112. function determineFilesToProcess(kind) {
  113. var currentConfig = config.build.currentConfig;
  114. var buildConfiguration = config.buildConfigurations[currentConfig];
  115. var filesToLoad = [];
  116. for (var index = 0; index < buildConfiguration.length; index++) {
  117. var dependencyName = buildConfiguration[index];
  118. var dependency = config.workloads[dependencyName];
  119. if (kind === "directFiles" && !dependency) {
  120. filesToLoad.push("../../dist/preview release/" + dependencyName);
  121. }
  122. else if (dependency) {
  123. processDependency(kind, dependency, filesToLoad);
  124. }
  125. }
  126. if (kind === "shaderIncludes") {
  127. for (var index = 0; index < filesToLoad.length; index++) {
  128. filesToLoad[index] = "../../src/Shaders/ShadersInclude/" + filesToLoad[index] + ".fx";
  129. }
  130. } else if (kind === "shaders") {
  131. for (var index = 0; index < filesToLoad.length; index++) {
  132. var name = filesToLoad[index];
  133. filesToLoad[index] = "../../src/Shaders/" + filesToLoad[index] + ".fx";
  134. }
  135. }
  136. return filesToLoad;
  137. }
  138. /*
  139. * Shader Management.
  140. */
  141. function shadersName(filename) {
  142. return path.basename(filename)
  143. .replace(".fragment", "Pixel")
  144. .replace(".vertex", "Vertex")
  145. .replace(".fx", "Shader");
  146. }
  147. function includeShadersName(filename) {
  148. return path.basename(filename).replace(".fx", "");
  149. }
  150. /*
  151. * Main necessary files stream Management.
  152. */
  153. gulp.task("includeShaders", function (cb) {
  154. var filesToProcess = determineFilesToProcess("shaderIncludes");
  155. includeShadersStream = gulp.src(filesToProcess).
  156. pipe(expect.real({ errorOnFailure: true }, filesToProcess)).
  157. pipe(uncommentShader()).
  158. pipe(srcToVariable({
  159. variableName: "BABYLON.Effect.IncludesShadersStore", asMap: true, namingCallback: includeShadersName
  160. }));
  161. cb();
  162. });
  163. gulp.task("shaders", ["includeShaders"], function (cb) {
  164. var filesToProcess = determineFilesToProcess("shaders");
  165. shadersStream = gulp.src(filesToProcess).
  166. pipe(expect.real({ errorOnFailure: true }, filesToProcess)).
  167. pipe(uncommentShader()).
  168. pipe(srcToVariable({
  169. variableName: "BABYLON.Effect.ShadersStore", asMap: true, namingCallback: shadersName
  170. }));
  171. cb();
  172. });
  173. gulp.task("workers", function (cb) {
  174. workersStream = config.workers.map(function (workerDef) {
  175. return gulp.src(workerDef.files).
  176. pipe(expect.real({ errorOnFailure: true }, workerDef.files)).
  177. pipe(uglify()).
  178. pipe(srcToVariable({
  179. variableName: workerDef.variable
  180. }));
  181. });
  182. cb();
  183. });
  184. /**
  185. * Build tasks to concat minify uflify optimise the BJS js in different flavor (workers...).
  186. */
  187. gulp.task("buildWorker", ["workers", "shaders"], function () {
  188. var filesToProcess = determineFilesToProcess("files");
  189. return merge2(
  190. gulp.src(filesToProcess).
  191. pipe(expect.real({ errorOnFailure: true }, filesToProcess)),
  192. shadersStream,
  193. includeShadersStream,
  194. workersStream
  195. )
  196. .pipe(concat(config.build.minWorkerFilename))
  197. .pipe(cleants())
  198. .pipe(replace(extendsSearchRegex, ""))
  199. .pipe(replace(decorateSearchRegex, ""))
  200. .pipe(addDecorateAndExtends())
  201. .pipe(addModuleExports("BABYLON", {
  202. dependencies: config.build.dependencies
  203. }))
  204. .pipe(uglify())
  205. .pipe(optimisejs())
  206. .pipe(gulp.dest(config.build.outputDirectory));
  207. });
  208. gulp.task("build", ["shaders"], function () {
  209. var filesToProcess = determineFilesToProcess("files");
  210. var directFilesToProcess = determineFilesToProcess("directFiles");
  211. let mergedStreams = merge2(
  212. gulp.src(filesToProcess).
  213. pipe(expect.real({ errorOnFailure: true }, filesToProcess)),
  214. shadersStream,
  215. includeShadersStream,
  216. gulp.src(directFilesToProcess)
  217. )
  218. return merge2(
  219. mergedStreams
  220. .pipe(concat(config.build.noModuleFilename))
  221. .pipe(cleants())
  222. .pipe(replace(extendsSearchRegex, ""))
  223. .pipe(replace(decorateSearchRegex, ""))
  224. .pipe(addDecorateAndExtends())
  225. .pipe(gulp.dest(config.build.outputDirectory))
  226. .pipe(rename(config.build.filename))
  227. .pipe(addModuleExports("BABYLON", {
  228. dependencies: config.build.dependencies
  229. }))
  230. .pipe(gulp.dest(config.build.outputDirectory))
  231. .pipe(rename(config.build.minFilename))
  232. .pipe(uglify())
  233. .pipe(optimisejs())
  234. .pipe(gulp.dest(config.build.outputDirectory)),
  235. mergedStreams
  236. .pipe(concat("es6.js"))
  237. .pipe(cleants())
  238. .pipe(replace(extendsSearchRegex, ""))
  239. .pipe(replace(decorateSearchRegex, ""))
  240. .pipe(addES6Exports("BABYLON"))
  241. .pipe(gulp.dest(config.build.outputDirectory))
  242. );
  243. });
  244. /*
  245. * Compiles all typescript files and creating a js and a declaration file.
  246. */
  247. gulp.task("typescript-compile", function () {
  248. var tsResult = gulp.src(config.typescript)
  249. .pipe(sourcemaps.init())
  250. .pipe(tsProject());
  251. //If this gulp task is running on travis, file the build!
  252. if (process.env.TRAVIS) {
  253. tsResult.once("error", function () {
  254. tsResult.once("finish", function () {
  255. console.log("Typescript compile failed");
  256. process.exit(1);
  257. });
  258. });
  259. }
  260. return merge2([
  261. tsResult.dts
  262. .pipe(concat(config.build.declarationFilename))
  263. .pipe(addDtsExport("BABYLON", "babylonjs"))
  264. .pipe(gulp.dest(config.build.outputDirectory)),
  265. tsResult.js
  266. .pipe(sourcemaps.write("./",
  267. {
  268. includeContent: false,
  269. sourceRoot: (filePath) => {
  270. return "";
  271. }
  272. }))
  273. .pipe(gulp.dest(config.build.srcOutputDirectory))
  274. ])
  275. });
  276. /**
  277. * Helper methods to build external library (mat, post processes, ...).
  278. */
  279. var buildExternalLibraries = function (settings) {
  280. var tasks = settings.libraries.map(function (library) {
  281. return buildExternalLibrary(library, settings, false);
  282. });
  283. let mergedTasks = merge2(tasks);
  284. if (settings.build.buildAsModule) {
  285. mergedTasks.on("end", function () {
  286. //generate js file list
  287. let files = settings.libraries.filter(function (lib) {
  288. return !lib.doNotIncludeInBundle;
  289. }).map(function (lib) {
  290. return config.build.outputDirectory + settings.build.distOutputDirectory + lib.output;
  291. });
  292. var outputDirectory = config.build.outputDirectory + settings.build.distOutputDirectory;
  293. let srcTask = gulp.src(files)
  294. .pipe(concat(settings.build.outputFilename + ".js"))
  295. .pipe(replace(extendsSearchRegex, ""))
  296. .pipe(replace(decorateSearchRegex, ""))
  297. .pipe(replace(referenceSearchRegex, ""))
  298. .pipe(addDecorateAndExtends())
  299. .pipe(addModuleExports(settings.build.moduleDeclaration, { subModule: true, extendsRoot: settings.build.extendsRoot }))
  300. .pipe(gulp.dest(outputDirectory))
  301. .pipe(cleants())
  302. .pipe(rename({ extname: ".min.js" }))
  303. .pipe(uglify())
  304. .pipe(optimisejs())
  305. .pipe(gulp.dest(outputDirectory));
  306. let dtsFiles = files.map(function (filename) {
  307. return filename.replace(".js", ".d.ts");
  308. });
  309. let dtsModuleTask = gulp.src(dtsFiles)
  310. .pipe(concat(settings.build.outputFilename + ".module.d.ts"))
  311. .pipe(replace(referenceSearchRegex, ""))
  312. .pipe(addDtsExport(settings.build.moduleDeclaration, settings.build.moduleName, true, settings.build.extendsRoot, settings.build.extraTypesDependencies))
  313. .pipe(gulp.dest(outputDirectory));
  314. let dtsTask = gulp.src(dtsFiles)
  315. .pipe(concat(settings.build.outputFilename + ".d.ts"))
  316. .pipe(replace(referenceSearchRegex, ""))
  317. .pipe(gulp.dest(outputDirectory));
  318. return merge2([srcTask, dtsTask, dtsModuleTask]);
  319. });
  320. }
  321. return mergedTasks;
  322. }
  323. var buildExternalLibrary = function (library, settings, watch) {
  324. var tsProcess = gulp.src(library.files, { base: settings.build.srcOutputDirectory })
  325. .pipe(sourcemaps.init())
  326. .pipe(typescript(externalTsConfig));
  327. var includeShader = gulp.src(library.shadersIncludeFiles || [], { base: settings.build.srcOutputDirectory })
  328. .pipe(uncommentShader())
  329. .pipe(appendSrcToVariable("BABYLON.Effect.IncludesShadersStore", includeShadersName, library.output + ".include.fx"))
  330. .pipe(gulp.dest(settings.build.srcOutputDirectory));
  331. var shader = gulp.src(library.shaderFiles || [], { base: settings.build.srcOutputDirectory })
  332. .pipe(uncommentShader())
  333. .pipe(appendSrcToVariable("BABYLON.Effect.ShadersStore", shadersName, library.output + ".fx"))
  334. .pipe(gulp.dest(settings.build.srcOutputDirectory));
  335. var dev = tsProcess.js
  336. .pipe(sourcemaps.write("./", {
  337. includeContent: false,
  338. sourceRoot: (filePath) => {
  339. return "";
  340. }
  341. })).pipe(gulp.dest(settings.build.srcOutputDirectory));
  342. var outputDirectory = config.build.outputDirectory + settings.build.distOutputDirectory;
  343. var css = gulp.src(library.sassFiles || [])
  344. .pipe(sass().on("error", sass.logError))
  345. .pipe(concat(library.output.replace(".js", ".css")))
  346. .pipe(gulp.dest(outputDirectory));
  347. if (watch) {
  348. return merge2([shader, includeShader, dev, css]);
  349. }
  350. else {
  351. /*if (library.bundle) {
  352. // Don't remove extends and decorate functions
  353. var code = merge2([tsProcess.js, shader, includeShader])
  354. .pipe(concat(library.output));
  355. if (library.buildAsModule) {
  356. code = code.pipe(addModuleExports(library.moduleDeclaration, true))
  357. }
  358. code.pipe(gulp.dest(outputDirectory))
  359. .pipe(cleants())
  360. .pipe(rename({ extname: ".min.js" }))
  361. .pipe(uglify())
  362. .pipe(optimisejs())
  363. .pipe(gulp.dest(outputDirectory));
  364. } else {*/
  365. var code = merge2([tsProcess.js, shader, includeShader])
  366. .pipe(concat(library.output))
  367. if (library.buildAsModule) {
  368. code = code.pipe(replace(extendsSearchRegex, ""))
  369. .pipe(replace(decorateSearchRegex, ""))
  370. .pipe(addDecorateAndExtends())
  371. .pipe(addModuleExports(library.moduleDeclaration, { subModule: true, extendsRoot: library.extendsRoot }))
  372. }
  373. code = code.pipe(gulp.dest(outputDirectory))
  374. .pipe(cleants())
  375. .pipe(rename({ extname: ".min.js" }))
  376. .pipe(uglify())
  377. .pipe(optimisejs())
  378. .pipe(gulp.dest(outputDirectory));
  379. /*}*/
  380. var dts = tsProcess.dts
  381. .pipe(concat(library.output))
  382. .pipe(replace(referenceSearchRegex, ""))
  383. .pipe(rename({ extname: ".d.ts" }))
  384. .pipe(gulp.dest(outputDirectory));
  385. var waitAll;
  386. if (library.buildAsModule) {
  387. var dts2 = tsProcess.dts
  388. .pipe(concat(library.output))
  389. .pipe(replace(referenceSearchRegex, ""))
  390. .pipe(addDtsExport(library.moduleDeclaration, library.moduleName, true, library.extendsRoot, config.build.extraTypesDependencies))
  391. .pipe(rename({ extname: ".module.d.ts" }))
  392. .pipe(gulp.dest(outputDirectory));
  393. waitAll = merge2([dev, code, css, dts, dts2]);
  394. } else {
  395. waitAll = merge2([dev, code, css, dts]);
  396. }
  397. if (library.webpack) {
  398. let sequence = [waitAll];
  399. let wpBuild = webpackStream(require(library.webpack), webpack);
  400. if (settings.build.outputs) {
  401. //shoud dtsBundle create the declaration?
  402. if (settings.build.dtsBundle) {
  403. let event = wpBuild
  404. .pipe(through.obj(function (file, enc, cb) {
  405. // only declaration files
  406. const isdts = /\.d\.ts$/.test(file.path);
  407. if (isdts) this.push(file);
  408. cb();
  409. }))
  410. .pipe(gulp.dest('.'));
  411. // dts-bundle does NOT support (gulp) streams, so files have to be saved and reloaded,
  412. // until I fix it
  413. event.on("end", function () {
  414. // create the file
  415. dtsBundle.bundle(settings.build.dtsBundle);
  416. // prepend the needed reference
  417. let fileLocation = path.join(path.dirname(settings.build.dtsBundle.main), settings.build.dtsBundle.out);
  418. fs.readFile(fileLocation, function (err, data) {
  419. if (err) throw err;
  420. data = (settings.build.dtsBundle.prependText || "") + '\n' + data.toString();
  421. fs.writeFile(fileLocation, data);
  422. if (settings.build.processDeclaration) {
  423. var newData = processDeclaration(data, settings.build.processDeclaration);
  424. fs.writeFile(fileLocation.replace('.module', ''), newData);
  425. }
  426. });
  427. });
  428. }
  429. let build = wpBuild
  430. .pipe(through.obj(function (file, enc, cb) {
  431. // only pipe js files
  432. const isJs = /\.js$/.test(file.path);
  433. if (isJs) this.push(file);
  434. cb();
  435. }))
  436. .pipe(addModuleExports(library.moduleDeclaration, { subModule: false, extendsRoot: false, externalUsingBabylon: true, noBabylonInit: library.babylonIncluded }));
  437. let unminifiedOutpus = [];
  438. let minifiedOutputs = [];
  439. settings.build.outputs.forEach(out => {
  440. if (out.minified) {
  441. out.destination.forEach(dest => {
  442. minifiedOutputs.push(dest);
  443. });
  444. } else {
  445. out.destination.forEach(dest => {
  446. unminifiedOutpus.push(dest);
  447. });
  448. }
  449. });
  450. function processDestination(dest) {
  451. var outputDirectory = config.build.outputDirectory + dest.outputDirectory;
  452. build = build
  453. .pipe(rename(dest.filename.replace(".js", library.noBundleInName ? '.js' : ".bundle.js")))
  454. .pipe(gulp.dest(outputDirectory));
  455. if (library.babylonIncluded && dest.addBabylonDeclaration) {
  456. // include the babylon declaration
  457. if (dest.addBabylonDeclaration === true) {
  458. dest.addBabylonDeclaration = [config.build.declarationFilename];
  459. }
  460. var decsToAdd = dest.addBabylonDeclaration.map(function (dec) {
  461. return config.build.outputDirectory + '/' + dec;
  462. });
  463. sequence.unshift(gulp.src(decsToAdd)
  464. .pipe(rename(function (path) {
  465. path.dirname = '';
  466. }))
  467. .pipe(gulp.dest(outputDirectory)))
  468. }
  469. }
  470. unminifiedOutpus.forEach(dest => {
  471. processDestination(dest);
  472. });
  473. if (minifiedOutputs.length) {
  474. //build = build
  475. //.pipe(uglify())
  476. //.pipe(optimisejs())
  477. }
  478. minifiedOutputs.forEach(dest => {
  479. processDestination(dest);
  480. });
  481. sequence.push(build);
  482. } else {
  483. let buildEvent = wpBuild
  484. .pipe(gulp.dest(outputDirectory))
  485. //back-compat
  486. .pipe(through.obj(function (file, enc, cb) {
  487. // only js files
  488. const isjs = /\.js$/.test(file.path);
  489. if (isjs) this.push(file);
  490. cb();
  491. }))
  492. .pipe(rename(library.output.replace(".js", ".max.js")))
  493. .pipe(rename(library.output.replace(".min.max.", ".")))
  494. .pipe(gulp.dest(outputDirectory));
  495. sequence.push(
  496. buildEvent
  497. );
  498. if (settings.build.dtsBundle || settings.build.processDeclaration) {
  499. buildEvent.on("end", function () {
  500. if (settings.build.dtsBundle) {
  501. dtsBundle.bundle(settings.build.dtsBundle);
  502. } if (settings.build.processDeclaration) {
  503. let fileLocation = path.join(outputDirectory, settings.build.processDeclaration.filename);
  504. fs.readFile(fileLocation, function (err, data) {
  505. if (err) throw err;
  506. var newData = processDeclaration(data, settings.build.processDeclaration);
  507. fs.writeFile(fileLocation.replace('.module', ''), newData);
  508. });
  509. }
  510. });
  511. }
  512. /*if (settings.build.processDeclaration) {
  513. sequence.push(
  514. wpBuild
  515. .pipe(through.obj(function (file, enc, cb) {
  516. // only js files
  517. const isDts = /\.d.ts$/.test(file.path);
  518. file.contents = new Buffer(processDeclaration(file.contents, settings.build.processDeclaration));
  519. if (isDts) this.push(file);
  520. cb();
  521. }))
  522. .pipe(gulp.dest(outputDirectory))
  523. )
  524. }*/
  525. }
  526. return merge2(sequence);
  527. }
  528. else {
  529. return waitAll;
  530. }
  531. }
  532. }
  533. /**
  534. * The default task, concat and min the main BJS files.
  535. */
  536. gulp.task("default", function (cb) {
  537. runSequence("typescript-all", "intellisense", "typedoc-all", "tests-unit", "tests-validation-virtualscreen", "tests-validation-browserstack", cb);
  538. });
  539. gulp.task("mainBuild", function (cb) {
  540. runSequence("buildWorker", "build", cb);
  541. });
  542. /**
  543. * Build the releasable files.
  544. */
  545. gulp.task("typescript", function (cb) {
  546. runSequence("typescript-compile", "mainBuild", cb);
  547. });
  548. /**
  549. * Dynamic module creation.
  550. */
  551. config.modules.map(function (module) {
  552. gulp.task(module, function () {
  553. return buildExternalLibraries(config[module]);
  554. });
  555. });
  556. gulp.task("typescript-libraries", config.modules, function () {
  557. });
  558. /**
  559. * Custom build with full path file control; used by profile.html
  560. */
  561. gulp.task("build-custom", function (cb) {
  562. runSequence("typescript-compile", "build", cb);
  563. });
  564. /**
  565. * Do it all.
  566. */
  567. gulp.task("typescript-all", function (cb) {
  568. runSequence("typescript", "typescript-libraries", cb);
  569. });
  570. /**
  571. * Watch ts files from typescript .
  572. */
  573. gulp.task("srcTscWatch", function () {
  574. // Reuse The TSC CLI from gulp to enable -w.
  575. process.argv[2] = "-w";
  576. process.argv[3] = "-p";
  577. process.argv[4] = "../../src/tsconfig.json";
  578. require("./node_modules/typescript/lib/tsc.js");
  579. });
  580. /**
  581. * Watch ts files and fire repective tasks.
  582. */
  583. gulp.task("watch", ["srcTscWatch"], function () {
  584. var interval = 1000;
  585. var tasks = [];
  586. config.modules.map(function (module) {
  587. config[module].libraries.map(function (library) {
  588. if (library.webpack) {
  589. if (library.noWatch) return;
  590. var outputDirectory = config.build.outputDirectory + config[module].build.distOutputDirectory;
  591. let wpconfig = require(library.webpack);
  592. wpconfig.watch = true;
  593. // dev mode and absolute path sourcemaps for debugging
  594. wpconfig.mode = "development";
  595. wpconfig.output.devtoolModuleFilenameTemplate = "[absolute-resource-path]";
  596. //config.stats = "minimal";
  597. tasks.push(webpackStream(wpconfig, webpack).pipe(gulp.dest(outputDirectory)))
  598. } else {
  599. tasks.push(gulp.watch(library.files, { interval: interval }, function () {
  600. console.log(library.output);
  601. return buildExternalLibrary(library, config[module], true)
  602. .pipe(debug());
  603. }));
  604. tasks.push(gulp.watch(library.shaderFiles, { interval: interval }, function () {
  605. console.log(library.output);
  606. return buildExternalLibrary(library, config[module], true)
  607. .pipe(debug())
  608. }));
  609. tasks.push(gulp.watch(library.sassFiles, { interval: interval }, function () {
  610. console.log(library.output);
  611. return buildExternalLibrary(library, config[module], true)
  612. .pipe(debug())
  613. }));
  614. }
  615. });
  616. });
  617. return tasks;
  618. });
  619. gulp.task("intellisense", function () {
  620. gulp.src(config.build.intellisenseSources)
  621. .pipe(concat(config.build.intellisenseFile))
  622. .pipe(replace(/^\s+_.*?;/gm, ""))
  623. .pipe(replace(/^\s+_[\S\s]*?}/gm, ""))
  624. .pipe(replace(/^\s*readonly _/gm, "protected readonly _"))
  625. .pipe(replace(/^\s*static _/gm, "private static _"))
  626. .pipe(replace(/^\s*abstract _/gm, ""))
  627. .pipe(gulp.dest(config.build.playgroundDirectory));
  628. });
  629. /**
  630. * Embedded local dev env management.
  631. */
  632. gulp.task("deployLocalDev", function () {
  633. gulp.src("../../localDev/template/**.*")
  634. .pipe(gulp.dest("../../localDev/src/"));
  635. });
  636. /**
  637. * Embedded webserver for test convenience.
  638. */
  639. gulp.task("webserver", function () {
  640. var options = {
  641. port: 1338,
  642. livereload: false,
  643. };
  644. if (commandLineOptions.public) {
  645. options.host = "0.0.0.0";
  646. }
  647. gulp.src("../../.").pipe(webserver(options));
  648. });
  649. /**
  650. * Combine Webserver and Watch as long as vscode does not handle multi tasks.
  651. */
  652. gulp.task("run", ["watch", "webserver"], function () {
  653. });
  654. /**
  655. * Cleans map and js files from the src folder.
  656. */
  657. gulp.task("clean-JS-MAP", function () {
  658. return del([
  659. "../../src/**/*.js.map", "../../src/**/*.js"
  660. ], { force: true });
  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'));
  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'));
  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. });