gulpfile.js 45 KB

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