gulpfile.js 46 KB

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