gulpfile.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. const path = require('path');
  2. const gulp = require('gulp');
  3. const exec = require('child_process').exec;
  4. const fs = require("fs");
  5. const fsp = fs.promises;
  6. const concat = require('gulp-concat');
  7. const connect = require('gulp-connect');
  8. const {watch} = gulp;
  9. const {createExamplesPage} = require("./src/tools/create_potree_page");
  10. const {createGithubPage} = require("./src/tools/create_github_page");
  11. const {createIconsPage} = require("./src/tools/create_icons_page");
  12. let paths = {
  13. laslaz: [
  14. "build/workers/laslaz-worker.js",
  15. "build/workers/lasdecoder-worker.js",
  16. ],
  17. html: [
  18. "src/viewer/potree.css",
  19. "src/viewer/sidebar.html",
  20. "src/viewer/profile.html"
  21. ],
  22. resources: [
  23. "resources/**/*"
  24. ]
  25. };
  26. let workers = {
  27. "LASLAZWorker": [
  28. "libs/plasio/workers/laz-perf.js",
  29. "libs/plasio/workers/laz-loader-worker.js"
  30. ],
  31. "LASDecoderWorker": [
  32. "src/workers/LASDecoderWorker.js"
  33. ],
  34. "EptLaszipDecoderWorker": [
  35. "src/workers/EptLaszipDecoderWorker.js"
  36. ],
  37. "EptBinaryDecoderWorker": [
  38. "libs/ept/ParseBuffer.js",
  39. "src/workers/EptBinaryDecoderWorker.js"
  40. ],
  41. "EptZstandardDecoderWorker": [
  42. "src/workers/EptZstandardDecoder_preamble.js",
  43. 'libs/zstd-codec/bundle.js',
  44. "libs/ept/ParseBuffer.js",
  45. "src/workers/EptZstandardDecoderWorker.js"
  46. ]
  47. };
  48. // these libs are lazily loaded
  49. // in order for the lazy loader to find them, independent of the path of the html file,
  50. // we package them together with potree
  51. let lazyLibs = {
  52. "geopackage": "libs/geopackage",
  53. "sql.js": "libs/sql.js"
  54. };
  55. let shaders = [
  56. "src/materials/shaders/pointcloud.vs",
  57. "src/materials/shaders/pointcloud.fs",
  58. "src/materials/shaders/pointcloud_sm.vs",
  59. "src/materials/shaders/pointcloud_sm.fs",
  60. "src/materials/shaders/normalize.vs",
  61. "src/materials/shaders/normalize.fs",
  62. "src/materials/shaders/normalize_and_edl.fs",
  63. "src/materials/shaders/edl.vs",
  64. "src/materials/shaders/edl.fs",
  65. "src/materials/shaders/blur.vs",
  66. "src/materials/shaders/blur.fs",
  67. ];
  68. // For development, it is now possible to use 'gulp webserver'
  69. // from the command line to start the server (default port is 8080)
  70. gulp.task('webserver', gulp.series(async function() {
  71. server = connect.server({
  72. port: 1234,
  73. https: false,
  74. });
  75. }));
  76. gulp.task('examples_page', async function(done) {
  77. await Promise.all([
  78. createExamplesPage(),
  79. createGithubPage(),
  80. ]);
  81. done();
  82. });
  83. gulp.task('icons_viewer', async function(done) {
  84. await createIconsPage();
  85. done();
  86. });
  87. gulp.task('test', async function() {
  88. console.log("asdfiae8ofh");
  89. });
  90. gulp.task("workers", async function(done){
  91. for(let workerName of Object.keys(workers)){
  92. gulp.src(workers[workerName])
  93. .pipe(concat(`${workerName}.js`))
  94. .pipe(gulp.dest('build/potree/workers'));
  95. }
  96. done();
  97. });
  98. gulp.task("lazylibs", async function(done){
  99. for(let libname of Object.keys(lazyLibs)){
  100. const libpath = lazyLibs[libname];
  101. gulp.src([`${libpath}/**/*`])
  102. .pipe(gulp.dest(`build/potree/lazylibs/${libname}`));
  103. }
  104. done();
  105. });
  106. gulp.task("shaders", async function(){
  107. const components = [
  108. "let Shaders = {};"
  109. ];
  110. for(let file of shaders){
  111. const filename = path.basename(file);
  112. const content = await fsp.readFile(file);
  113. const prep = `Shaders["${filename}"] = \`${content}\``;
  114. components.push(prep);
  115. }
  116. components.push("export {Shaders};");
  117. const content = components.join("\n\n");
  118. const targetPath = `./build/shaders/shaders.js`;
  119. if(!fs.existsSync("build/shaders")){
  120. fs.mkdirSync("build/shaders");
  121. }
  122. fs.writeFileSync(targetPath, content, {flag: "w"});
  123. });
  124. gulp.task('build',
  125. gulp.series(
  126. gulp.parallel("workers", "lazylibs", "shaders", "icons_viewer", "examples_page"),
  127. async function(done){
  128. gulp.src(paths.html).pipe(gulp.dest('build/potree'));
  129. gulp.src(paths.resources).pipe(gulp.dest('build/potree/resources'));
  130. gulp.src(["LICENSE"]).pipe(gulp.dest('build/potree'));
  131. done();
  132. }
  133. )
  134. );
  135. gulp.task("pack", async function(){
  136. exec('rollup -c', function (err, stdout, stderr) {
  137. console.log(stdout);
  138. console.log(stderr);
  139. });
  140. });
  141. gulp.task('watch', gulp.parallel("build", "pack", "webserver", async function() {
  142. let watchlist = [
  143. 'src/**/*.js',
  144. 'src/**/**/*.js',
  145. 'src/**/*.css',
  146. 'src/**/*.html',
  147. 'src/**/*.vs',
  148. 'src/**/*.fs',
  149. 'resources/**/*',
  150. 'examples//**/*.json',
  151. '!resources/icons/index.html',
  152. ];
  153. watch(watchlist, gulp.series("build", "pack"));
  154. }));