gulpfile.js 27 KB

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