gulpfile.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. "use strict";
  2. var gulp = require("gulp"),
  3. gp_clean = require("gulp-clean"),
  4. gp_concat = require("gulp-concat"),
  5. gp_less = require("gulp-less"),
  6. gp_util = require("gulp-util"),
  7. gp_watch = require("gulp-watch"),
  8. path = require("path"),
  9. webpack = require("webpack");
  10. var staticPrefix = "src/sentry/static/sentry",
  11. distPath = staticPrefix + "/dist",
  12. webpackStatsOptions = {
  13. chunkModules: false,
  14. colors: true
  15. };
  16. // Workaround for https://github.com/gulpjs/gulp/issues/71
  17. var origSrc = gulp.src;
  18. gulp.src = function () {
  19. return fixPipe(origSrc.apply(this, arguments));
  20. };
  21. function fixPipe(stream) {
  22. var origPipe = stream.pipe;
  23. stream.pipe = function (dest) {
  24. arguments[0] = dest.on('error', function (error) {
  25. var nextStreams = dest._nextStreams;
  26. if (nextStreams) {
  27. nextStreams.forEach(function (nextStream) {
  28. nextStream.emit('error', error.toString());
  29. });
  30. } else if (dest.listeners('error').length === 1) {
  31. throw error;
  32. }
  33. });
  34. var nextStream = fixPipe(origPipe.apply(this, arguments));
  35. (this._nextStreams || (this._nextStreams = [])).push(nextStream);
  36. return nextStream;
  37. };
  38. return stream;
  39. }
  40. function file(name) {
  41. return path.join(__dirname, staticPrefix, name);
  42. }
  43. function vendorFile(name) {
  44. return path.join(__dirname, staticPrefix, "vendor", name);
  45. }
  46. function buildCssCompileTask(name, fileList) {
  47. return function(){
  48. gulp.src(fileList)
  49. .pipe(gp_less({
  50. paths: ['node_modules/bootstrap/less']
  51. }))
  52. .pipe(gp_concat(name))
  53. .pipe(gulp.dest(distPath))
  54. .on("error", gp_util.log);
  55. };
  56. }
  57. gulp.task("clean", function () {
  58. return gulp.src(distPath, {read: false})
  59. .pipe(gp_clean())
  60. .on("error", gp_util.log);
  61. });
  62. gulp.task("dist:css:sentry", buildCssCompileTask("sentry.css", [file("less/sentry.less")]))
  63. gulp.task("dist:css:wall", buildCssCompileTask("wall.css", [file("less/wall.less")]))
  64. gulp.task("dist:css", ["dist:css:sentry", "dist:css:wall"]);
  65. gulp.task("dist:webpack", function(callback){
  66. webpack(require('./webpack.config.js'), function(err, stats) {
  67. if(err) throw new gutil.PluginError("webpack", err);
  68. gp_util.log("[webpack]", stats.toString(webpackStatsOptions));
  69. callback();
  70. });
  71. });
  72. gulp.task("dist", ["dist:css", "dist:webpack"]);
  73. gulp.task("watch:css:sentry", ["dist:css:sentry"], function(){
  74. return gp_watch(file("less/**/*.less"), function(){
  75. gulp.start("dist:css:sentry");
  76. });
  77. });
  78. gulp.task("watch:css:wall", ["dist:css:wall"], function(){
  79. return gp_watch(file("less/wall.less"), function(){
  80. gulp.start("dist:css:wall");
  81. });
  82. });
  83. gulp.task("watch:css", ["watch:css:sentry", "watch:css:wall"]);
  84. // TODO(dcramer): this is causing issues, use webpack --watch for now
  85. gulp.task("watch:webpack", function(callback){
  86. var config = require('./webpack.config.js');
  87. config.debug = true;
  88. webpack(config).watch(200, function(err, stats) {
  89. if(err) throw new gutil.PluginError("webpack", err);
  90. gp_util.log("[webpack]", stats.toString(webpackStatsOptions));
  91. });
  92. callback();
  93. });
  94. gulp.task("watch", function(){
  95. return gulp.start(["watch:css", "watch:webpack"]);
  96. });
  97. gulp.task("default", ["dist"]);