123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- "use strict";
- var gulp = require("gulp"),
- gp_clean = require("gulp-clean"),
- gp_concat = require("gulp-concat"),
- gp_less = require("gulp-less"),
- gp_util = require("gulp-util"),
- gp_watch = require("gulp-watch"),
- path = require("path"),
- webpack = require("webpack");
- var staticPrefix = "src/sentry/static/sentry",
- distPath = staticPrefix + "/dist",
- webpackStatsOptions = {
- chunkModules: false,
- colors: true
- };
- // Workaround for https://github.com/gulpjs/gulp/issues/71
- var origSrc = gulp.src;
- gulp.src = function () {
- return fixPipe(origSrc.apply(this, arguments));
- };
- function fixPipe(stream) {
- var origPipe = stream.pipe;
- stream.pipe = function (dest) {
- arguments[0] = dest.on('error', function (error) {
- var nextStreams = dest._nextStreams;
- if (nextStreams) {
- nextStreams.forEach(function (nextStream) {
- nextStream.emit('error', error.toString());
- });
- } else if (dest.listeners('error').length === 1) {
- throw error;
- }
- });
- var nextStream = fixPipe(origPipe.apply(this, arguments));
- (this._nextStreams || (this._nextStreams = [])).push(nextStream);
- return nextStream;
- };
- return stream;
- }
- function file(name) {
- return path.join(__dirname, staticPrefix, name);
- }
- function vendorFile(name) {
- return path.join(__dirname, staticPrefix, "vendor", name);
- }
- function buildCssCompileTask(name, fileList) {
- return function(){
- gulp.src(fileList)
- .pipe(gp_less({
- paths: ['node_modules/bootstrap/less']
- }))
- .pipe(gp_concat(name))
- .pipe(gulp.dest(distPath))
- .on("error", gp_util.log);
- };
- }
- gulp.task("clean", function () {
- return gulp.src(distPath, {read: false})
- .pipe(gp_clean())
- .on("error", gp_util.log);
- });
- gulp.task("dist:css:sentry", buildCssCompileTask("sentry.css", [file("less/sentry.less")]))
- gulp.task("dist:css:wall", buildCssCompileTask("wall.css", [file("less/wall.less")]))
- gulp.task("dist:css", ["dist:css:sentry", "dist:css:wall"]);
- gulp.task("dist:webpack", function(callback){
- webpack(require('./webpack.config.js'), function(err, stats) {
- if(err) throw new gutil.PluginError("webpack", err);
- gp_util.log("[webpack]", stats.toString(webpackStatsOptions));
- callback();
- });
- });
- gulp.task("dist", ["dist:css", "dist:webpack"]);
- gulp.task("watch:css:sentry", ["dist:css:sentry"], function(){
- return gp_watch(file("less/**/*.less"), function(){
- gulp.start("dist:css:sentry");
- });
- });
- gulp.task("watch:css:wall", ["dist:css:wall"], function(){
- return gp_watch(file("less/wall.less"), function(){
- gulp.start("dist:css:wall");
- });
- });
- gulp.task("watch:css", ["watch:css:sentry", "watch:css:wall"]);
- // TODO(dcramer): this is causing issues, use webpack --watch for now
- gulp.task("watch:webpack", function(callback){
- var config = require('./webpack.config.js');
- config.debug = true;
- webpack(config).watch(200, function(err, stats) {
- if(err) throw new gutil.PluginError("webpack", err);
- gp_util.log("[webpack]", stats.toString(webpackStatsOptions));
- });
- callback();
- });
- gulp.task("watch", function(){
- return gulp.start(["watch:css", "watch:webpack"]);
- });
- gulp.task("default", ["dist"]);
|