gulpfile.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. "use strict";
  2. var gulp = require("gulp"),
  3. gp_cached = require("gulp-cached"),
  4. gp_clean = require("gulp-clean"),
  5. gp_concat = require("gulp-concat"),
  6. gp_less = require("gulp-less"),
  7. gp_rename = require("gulp-rename"),
  8. gp_uglify = require("gulp-uglify"),
  9. gp_util = require("gulp-util");
  10. var path = require("path");
  11. var staticPrefix = "src/sentry/static/sentry",
  12. distPath = staticPrefix + "/dist";
  13. var jsDistros = {
  14. "app": [
  15. file("scripts/core.js"),
  16. file("scripts/models.js"),
  17. file("scripts/templates.js"),
  18. file("scripts/utils.js"),
  19. file("scripts/collections.js"),
  20. file("scripts/charts.js"),
  21. file("scripts/views.js"),
  22. file("scripts/app.js")
  23. ],
  24. "app-legacy": [
  25. file("scripts/sentry.core.js"),
  26. file("scripts/sentry.charts.js"),
  27. file("scripts/sentry.stream.js"),
  28. ],
  29. "vendor-jquery": [
  30. vendorFile("jquery/dist/jquery.min.js"),
  31. file("scripts/lib/jquery.migrate.js"),
  32. vendorFile("jquery-flot/jquery.flot.js"),
  33. vendorFile("jquery-flot/jquery.flot.resize.js"),
  34. vendorFile("jquery-flot/jquery.flot.stack.js"),
  35. vendorFile("jquery-flot/jquery.flot.time.js"),
  36. file("scripts/lib/jquery.flot.dashes.js"),
  37. file("scripts/lib/jquery.flot.tooltip.js"),
  38. file("scripts/lib/jquery.animate-colors.js"),
  39. file("scripts/lib/jquery.clippy.min.js"),
  40. file("scripts/lib/jquery.cookie.js")
  41. ],
  42. "vendor-backbone": [
  43. file("scripts/lib/json2.js"),
  44. file("scripts/lib/underscore.js"),
  45. file("scripts/lib/backbone.js")
  46. ],
  47. "vendor-bootstrap": [
  48. vendorFile("bootstrap/js/bootstrap-transition.js"),
  49. vendorFile("bootstrap/js/bootstrap-alert.js"),
  50. vendorFile("bootstrap/js/bootstrap-button.js"),
  51. vendorFile("bootstrap/js/bootstrap-carousel.js"),
  52. vendorFile("bootstrap/js/bootstrap-collapse.js"),
  53. vendorFile("bootstrap/js/bootstrap-dropdown.js"),
  54. vendorFile("bootstrap/js/bootstrap-modal.js"),
  55. vendorFile("bootstrap/js/bootstrap-tooltip.js"),
  56. vendorFile("bootstrap/js/bootstrap-popover.js"),
  57. vendorFile("bootstrap/js/bootstrap-scrollspy.js"),
  58. vendorFile("bootstrap/js/bootstrap-tab.js"),
  59. vendorFile("bootstrap/js/bootstrap-typeahead.js"),
  60. vendorFile("bootstrap/js/bootstrap-affix.js"),
  61. file("scripts/lib/bootstrap-datepicker.js")
  62. ],
  63. "vendor-misc": [
  64. vendorFile("moment/min/moment.min.js"),
  65. vendorFile("simple-slider/js/simple-slider.min.js"),
  66. file("scripts/lib/select2/select2.js")
  67. ],
  68. "raven": [
  69. vendorFile("raven-js/dist/raven.min.js")
  70. ]
  71. }
  72. function file(name) {
  73. return path.join(__dirname, staticPrefix, name);
  74. }
  75. function vendorFile(name) {
  76. return path.join(__dirname, staticPrefix, "vendor", name);
  77. }
  78. function buildJsCompileTask(name, fileList) {
  79. // TODO(dcramer): sourcemaps
  80. return function(){
  81. return gulp.src(fileList)
  82. .pipe(gp_cached('js-' + name))
  83. .pipe(gp_concat(name + ".js"))
  84. .pipe(gulp.dest(distPath))
  85. .pipe(gp_uglify())
  86. .pipe(gp_rename(name + ".min.js"))
  87. .pipe(gulp.dest(distPath))
  88. .on("error", gp_util.log);
  89. };
  90. }
  91. function buildJsWatchTask(name, fileList) {
  92. return function(){
  93. return gulp.watch(fileList, ["dist:js:" + name]);
  94. };
  95. };
  96. function buildCssCompileTask(name, fileList) {
  97. return function(){
  98. gulp.src(fileList)
  99. .pipe(gp_cached('css-' + name))
  100. .pipe(gp_less({
  101. paths: [vendorFile("bootstrap/less")]
  102. }))
  103. .pipe(gp_concat(name))
  104. .pipe(gulp.dest(distPath))
  105. .on("error", gp_util.log);
  106. };
  107. }
  108. function buildJsDistroTasks() {
  109. // create a gulp task for each JS distro
  110. var jsDistroNames = [], compileTask, watchTask, fileList;
  111. for (var distroName in jsDistros) {
  112. fileList = jsDistros[distroName];
  113. compileTask = buildJsCompileTask(distroName, fileList);
  114. gulp.task("dist:js:" + distroName, compileTask);
  115. watchTask = buildJsWatchTask(distroName, fileList);
  116. gulp.task("watch:js:" + distroName, watchTask);
  117. jsDistroNames.push(distroName);
  118. }
  119. gulp.task("dist:js", jsDistroNames.map(function(n) { return "dist:js:" + n; }));
  120. gulp.task("watch:js", jsDistroNames.map(function(n) { return "watch:js:" + n; }));
  121. }
  122. gulp.task("clean", function () {
  123. return gulp.src(distPath, {read: false})
  124. .pipe(gp_clean())
  125. .on("error", gp_util.log);
  126. });
  127. gulp.task("dist:css:sentry", buildCssCompileTask("sentry.css", [file("less/sentry.less")]))
  128. gulp.task("dist:css:wall", buildCssCompileTask("wall.css", [file("less/wall.less")]))
  129. gulp.task("dist:css", ["dist:css:sentry", "dist:css:wall"]);
  130. buildJsDistroTasks();
  131. gulp.task("dist", ["dist:js", "dist:css"]);
  132. gulp.task("watch:css:sentry", function(){
  133. return gulp.watch(file("less/sentry.less"), ["dist:css:sentry"]);
  134. });
  135. gulp.task("watch:css:wall", function(){
  136. return gulp.watch(file("less/wall.less"), ["dist:css:wall"]);
  137. });
  138. gulp.task("watch:css", ["watch:css:sentry", "watch:css:wall"]);
  139. gulp.task("watch", ["watch:js", "watch:css"]);
  140. gulp.task("default", ["dist"]);