gulpfile.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. "use strict";
  2. const { src, dest, series, parallel, watch } = require("gulp");
  3. const buffer = require("gulp-buffer");
  4. const browserify = require("browserify");
  5. const concat = require("gulp-concat");
  6. const connect = require("gulp-connect");
  7. const eslint = require("gulp-eslint7");
  8. const header = require("gulp-header");
  9. const log = require("gulplog");
  10. const postcss = require("gulp-postcss");
  11. const sourcemaps = require("gulp-sourcemaps");
  12. const stylelint = require("gulp-stylelint");
  13. const tap = require("gulp-tap");
  14. const terser = require("gulp-terser");
  15. const output =
  16. process.argv.indexOf("--output") != -1
  17. ? process.argv[process.argv.indexOf("--output") + 1]
  18. : "build/converted-asciidoc";
  19. function info(cb) {
  20. log.info("Writing to " + output);
  21. cb();
  22. }
  23. function css() {
  24. return src("src/main/css/site.css")
  25. .pipe(
  26. stylelint({
  27. failAfterError: true,
  28. reporters: [{ formatter: "string", console: true }],
  29. })
  30. )
  31. .pipe(sourcemaps.init())
  32. .pipe(postcss())
  33. .pipe(
  34. /* MPL 2.0 requirement */
  35. header(
  36. "/*\n\nSource Available at https://github.com/spring-io/asciidoctor-spring-backend */\n\n\n"
  37. )
  38. )
  39. .pipe(sourcemaps.write("./"))
  40. .pipe(dest(output + "/css"))
  41. .pipe(connect.reload());
  42. }
  43. function fontawesomeCss() {
  44. return src("node_modules/fontawesome-4.7/css/font-awesome.css").pipe(dest(output + "/css"));
  45. }
  46. function fontawesomeFonts() {
  47. return src("node_modules/fontawesome-4.7/fonts/*").pipe(dest(output + "/fonts"));
  48. }
  49. function img() {
  50. return src("src/main/img/*").pipe(dest(output + "/img"));
  51. }
  52. function jsSetup() {
  53. return jsFolder("setup");
  54. }
  55. function jsSite() {
  56. return jsFolder("site");
  57. }
  58. function jsFolder(name) {
  59. return src("src/main/js/" + name + "/*.js", { base: 'src/main/js' })
  60. .pipe(eslint())
  61. .pipe(eslint.format())
  62. .pipe(eslint.failAfterError())
  63. .pipe(tapBrowserify())
  64. .pipe(buffer())
  65. .pipe(initSourcemaps())
  66. .pipe(terser())
  67. .pipe(concat("js/" + name + ".js"))
  68. .pipe(sourcemaps.write("./"))
  69. .pipe(dest(output))
  70. .pipe(connect.reload());
  71. }
  72. function tapBrowserify() {
  73. return tap(function (file) {
  74. file.contents = browserify(file.path, {
  75. debug: true,
  76. })
  77. .plugin("browser-pack-flat/plugin")
  78. .bundle();
  79. });
  80. }
  81. function initSourcemaps() {
  82. return sourcemaps.init({
  83. loadMaps: true,
  84. });
  85. }
  86. function webServer(cb) {
  87. connect.server({
  88. root: output,
  89. livereload: true,
  90. });
  91. cb();
  92. }
  93. function watchFiles(cb) {
  94. watch("src/main/**", build);
  95. cb();
  96. }
  97. const build = series(info, css, fontawesomeCss, fontawesomeFonts, img, jsSetup, jsSite);
  98. exports.default = build;
  99. exports.build = build;
  100. exports.dev = series(build, parallel(webServer, watchFiles));