2015-10-25 06:17:45 +01:00
|
|
|
/**
|
|
|
|
* Pony.fm - A community for pony fan music.
|
2018-04-21 06:25:36 +02:00
|
|
|
* Copyright (C) 2015 Feld0
|
2015-10-25 06:17:45 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2015-09-06 19:21:11 +02:00
|
|
|
var gulp = require("gulp"),
|
2016-02-14 17:14:30 +01:00
|
|
|
gutil = require("gulp-util"),
|
2015-09-06 19:21:11 +02:00
|
|
|
plug = require("gulp-load-plugins")(),
|
2015-10-25 06:17:45 +01:00
|
|
|
argv = require("yargs").argv,
|
2016-02-14 17:14:30 +01:00
|
|
|
header = require("gulp-header"),
|
|
|
|
webpack = require("webpack"),
|
|
|
|
WebpackDevServer = require("webpack-dev-server"),
|
2016-02-14 18:27:57 +01:00
|
|
|
webpackDevConfig = require("./webpack.dev.config.js"),
|
|
|
|
webpackProductionConfig = require("./webpack.production.config.js"),
|
2016-02-16 12:26:05 +01:00
|
|
|
webpackStream = require('webpack-stream'),
|
2016-12-26 01:53:16 +01:00
|
|
|
_ = require("underscore"),
|
|
|
|
runSequence = require("run-sequence"),
|
|
|
|
panini = require("panini"),
|
|
|
|
inky = require("inky"),
|
|
|
|
fs = require("fs"),
|
|
|
|
siphon = require('siphon-media-query'),
|
|
|
|
lazypipe = require('lazypipe'),
|
2016-12-26 16:50:13 +01:00
|
|
|
ext_replace = require('gulp-ext-replace'),
|
|
|
|
del = require('del');
|
2015-09-06 19:21:11 +02:00
|
|
|
|
|
|
|
var plumberOptions = {
|
2015-10-25 03:43:37 +01:00
|
|
|
errorHandler: plug.notify.onError("Error: <%= error.message %>")
|
2015-09-06 19:21:11 +02:00
|
|
|
};
|
|
|
|
|
2015-10-25 06:17:45 +01:00
|
|
|
var licenseHeader = [
|
|
|
|
"/**",
|
|
|
|
"* Pony.fm - A community for pony fan music.",
|
2018-04-21 06:25:36 +02:00
|
|
|
"* Copyright (C) 2016 Feld0 and others",
|
2015-10-25 06:17:45 +01:00
|
|
|
"*",
|
|
|
|
"* This program is free software: you can redistribute it and/or modify",
|
|
|
|
"* it under the terms of the GNU Affero General Public License as published by",
|
|
|
|
"* the Free Software Foundation, either version 3 of the License, or",
|
|
|
|
"* (at your option) any later version.",
|
|
|
|
"*",
|
|
|
|
"* This program is distributed in the hope that it will be useful,",
|
|
|
|
"* but WITHOUT ANY WARRANTY; without even the implied warranty of",
|
|
|
|
"* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the",
|
|
|
|
"* GNU Affero General Public License for more details.",
|
|
|
|
"*",
|
|
|
|
"* You should have received a copy of the GNU Affero General Public License",
|
|
|
|
"* along with this program. If not, see <http://www.gnu.org/licenses/>.",
|
|
|
|
"*/",
|
|
|
|
"",
|
|
|
|
""
|
2016-01-16 10:12:57 +01:00
|
|
|
].join('\n');
|
2015-10-25 06:17:45 +01:00
|
|
|
|
2016-02-14 17:14:30 +01:00
|
|
|
|
2016-12-26 01:53:16 +01:00
|
|
|
const PRODUCTION = !!(argv.production);
|
|
|
|
|
|
|
|
|
2016-02-14 18:27:57 +01:00
|
|
|
gulp.task("webpack-build", function() {
|
2016-02-16 12:26:05 +01:00
|
|
|
return gulp.src(_.values(webpackProductionConfig.entry))
|
2016-02-14 18:27:57 +01:00
|
|
|
.pipe(webpackStream(webpackProductionConfig))
|
|
|
|
.pipe(header(licenseHeader))
|
|
|
|
.pipe(gulp.dest('public'));
|
|
|
|
});
|
2016-02-14 17:14:30 +01:00
|
|
|
|
|
|
|
|
2016-02-14 18:27:57 +01:00
|
|
|
gulp.task("webpack-dev-server", function () {
|
|
|
|
// Starts a webpack-dev-server
|
|
|
|
var compiler = webpack(webpackDevConfig);
|
2016-02-14 17:14:30 +01:00
|
|
|
|
|
|
|
new WebpackDevServer(compiler, {
|
2016-02-14 18:27:57 +01:00
|
|
|
// server and middleware options, currently blank
|
2016-12-26 01:53:16 +01:00
|
|
|
// stats: {chunks: false}
|
|
|
|
stats: 'minimal'
|
2016-05-16 02:00:37 +02:00
|
|
|
}).listen(61999, "localhost", function (err) {
|
2016-02-14 18:27:57 +01:00
|
|
|
if (err)
|
|
|
|
throw new gutil.PluginError("webpack-dev-server", err);
|
2016-02-14 17:14:30 +01:00
|
|
|
|
2016-02-14 18:27:57 +01:00
|
|
|
// Server listening
|
2016-05-16 02:00:37 +02:00
|
|
|
gutil.log("[webpack-dev-server]", "http://localhost:61999/webpack-dev-server/index.html");
|
2016-02-14 17:14:30 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2015-10-25 03:43:37 +01:00
|
|
|
gulp.task("styles-app", function () {
|
|
|
|
var includedStyles = [
|
|
|
|
"resources/assets/styles/base/jquery-ui.css",
|
|
|
|
"resources/assets/styles/base/colorbox.css",
|
|
|
|
"resources/assets/styles/app.less"
|
|
|
|
];
|
|
|
|
|
|
|
|
if (!argv.production) {
|
|
|
|
// we also want to add the embed stuff, since we're in development mode
|
|
|
|
// we want to watch embed files and re-compile them. However, we want
|
|
|
|
// to leave this path out in production so that embed files are not bloating
|
|
|
|
// the css file
|
2016-06-17 19:01:31 +02:00
|
|
|
includedStyles.push("resources/assets/styles/embed.less");
|
2015-10-25 03:43:37 +01:00
|
|
|
|
|
|
|
// Remove app.less from the cache so that it gets recompiled
|
|
|
|
var styleCache = plug.cached.caches.styles;
|
|
|
|
for (var file in styleCache) {
|
|
|
|
if (!styleCache.hasOwnProperty(file))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!endsWith(file, "app.less"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
delete styleCache[file];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// note that we're not doing autoprefixer on dev builds for now to shave off roughly 600-700 milliseconds per
|
|
|
|
// build. It's already taking forever to recompile the less
|
|
|
|
|
|
|
|
return argv.production
|
|
|
|
// Production pipeline
|
|
|
|
? gulp.src(includedStyles, {base: "resources/assets/styles"})
|
|
|
|
.pipe(plug.plumber(plumberOptions))
|
|
|
|
.pipe(plug.if(/\.less/, plug.less()))
|
|
|
|
.pipe(plug.autoprefixer({
|
|
|
|
browsers: ["last 2 versions"],
|
|
|
|
cascade: false
|
|
|
|
}))
|
|
|
|
.pipe(plug.concat("app.css"))
|
2016-06-18 07:23:02 +02:00
|
|
|
.pipe(plug.cleanCss())
|
2015-10-25 06:17:45 +01:00
|
|
|
.pipe(header(licenseHeader))
|
2015-10-25 03:43:37 +01:00
|
|
|
.pipe(gulp.dest("public/build/styles"))
|
2016-01-16 10:12:57 +01:00
|
|
|
|
2015-10-25 03:43:37 +01:00
|
|
|
// Development pipeline
|
|
|
|
: gulp.src(includedStyles, {base: "resources/assets/styles"})
|
|
|
|
.pipe(plug.plumber(plumberOptions))
|
|
|
|
.pipe(plug.cached("styles"))
|
|
|
|
.pipe(plug.sourcemaps.init())
|
|
|
|
.pipe(plug.if(/\.less/, plug.less()))
|
2015-10-25 06:17:45 +01:00
|
|
|
.pipe(header(licenseHeader))
|
2016-01-16 10:12:57 +01:00
|
|
|
.pipe(plug.sourcemaps.write())
|
2015-10-25 03:43:37 +01:00
|
|
|
.pipe(gulp.dest("public/build/styles"))
|
|
|
|
.pipe(plug.livereload());
|
2015-09-06 19:21:11 +02:00
|
|
|
});
|
|
|
|
|
2015-10-25 03:43:37 +01:00
|
|
|
gulp.task("styles-embed", function () {
|
|
|
|
// note that this task should really only ever be invoked for production
|
|
|
|
// since development-mode watches and builds include the embed styles
|
|
|
|
// already
|
|
|
|
|
|
|
|
return gulp.src(["resources/assets/styles/embed.less"], {base: "resources/assets/styles"})
|
|
|
|
.pipe(plug.less())
|
|
|
|
.pipe(plug.autoprefixer({
|
|
|
|
browsers: ["last 2 versions"],
|
|
|
|
cascade: false
|
|
|
|
}))
|
2016-06-17 22:00:41 +02:00
|
|
|
.pipe(plug.concat("embed.css"))
|
2016-06-18 07:23:02 +02:00
|
|
|
.pipe(plug.cleanCss())
|
2015-10-25 06:17:45 +01:00
|
|
|
.pipe(header(licenseHeader))
|
2015-10-25 03:43:37 +01:00
|
|
|
.pipe(gulp.dest("public/build/styles"));
|
2015-09-06 19:21:11 +02:00
|
|
|
});
|
|
|
|
|
2015-10-25 03:43:37 +01:00
|
|
|
gulp.task('copy:templates', function () {
|
|
|
|
gulp.src([
|
|
|
|
'public/templates/**/*.html'
|
|
|
|
])
|
|
|
|
.pipe(plug.angularTemplatecache({
|
|
|
|
module: "ponyfm",
|
|
|
|
root: "/templates"
|
|
|
|
}))
|
2015-10-25 06:17:45 +01:00
|
|
|
.pipe(header(licenseHeader))
|
2015-10-25 03:43:37 +01:00
|
|
|
.pipe(gulp.dest('public/build/scripts'));
|
2015-09-06 19:21:11 +02:00
|
|
|
});
|
|
|
|
|
2016-12-26 01:53:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
//=============== ZURB Foundation Email stack =================//
|
|
|
|
|
|
|
|
// These tasks are adapted from ZURB's gulpfile (https://github.com/zurb/foundation-emails-template/blob/master/gulpfile.babel.js).
|
|
|
|
// They have been modified for ES5, Gulp 3 compatibility, and namespaced with "email-"
|
|
|
|
// to avoid collisions with Pony.fm's other Gulp tasks.
|
|
|
|
|
2016-12-26 16:50:13 +01:00
|
|
|
// Delete the "resources/views/emails/html" folder
|
2016-12-26 01:53:16 +01:00
|
|
|
// This happens every time a build starts
|
2016-12-26 16:50:13 +01:00
|
|
|
gulp.task("email-clean", function emailClean() {
|
|
|
|
return del([
|
|
|
|
'resources/views/emails/html',
|
|
|
|
'public/build/emails'
|
|
|
|
]);
|
2016-12-26 01:53:16 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Compile layouts, pages, and partials into flat HTML files
|
|
|
|
// Then parse using Inky templates
|
|
|
|
gulp.task("email-pages", function emailPages() {
|
|
|
|
return gulp.src('resources/emails/src/pages/**/*.blade.php.hbs')
|
|
|
|
.pipe(panini({
|
|
|
|
root: 'resources/emails/src/pages',
|
|
|
|
layouts: 'resources/emails/src/layouts',
|
|
|
|
partials: 'resources/emails/src/partials',
|
|
|
|
helpers: 'resources/emails/src/helpers'
|
|
|
|
}))
|
|
|
|
.pipe(inky())
|
|
|
|
.pipe(ext_replace('.blade.php', '.blade.php.hbs'))
|
2016-12-26 16:50:13 +01:00
|
|
|
.pipe(gulp.dest('resources/views/emails/html'))
|
|
|
|
// If this is the dev environment, write the templates to the "public"
|
|
|
|
// directory as well.
|
|
|
|
.pipe(plug.if(!PRODUCTION, ext_replace('.blade.php.html', '.blade.php')))
|
|
|
|
.pipe(plug.if(!PRODUCTION, gulp.dest('public/build/emails')));
|
2016-12-26 01:53:16 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Reset Panini's cache of layouts and partials
|
|
|
|
gulp.task("email-reset-pages", function emailResetPages(done) {
|
|
|
|
panini.refresh();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Compile Sass into CSS
|
|
|
|
gulp.task("email-sass", function emailSass() {
|
|
|
|
return gulp.src('resources/emails/src/assets/scss/app.scss')
|
|
|
|
.pipe(plug.if(!PRODUCTION, plug.sourcemaps.init()))
|
|
|
|
.pipe(plug.sass({
|
|
|
|
includePaths: ['node_modules/foundation-emails/scss']
|
|
|
|
}).on('error', plug.sass.logError))
|
|
|
|
.pipe(plug.if(PRODUCTION, plug.uncss(
|
2016-12-26 16:50:13 +01:00
|
|
|
{html: ['resources/views/emails/html/**/*.blade.php']})))
|
2016-12-26 01:53:16 +01:00
|
|
|
.pipe(plug.if(!PRODUCTION, plug.sourcemaps.write()))
|
2016-12-26 16:50:13 +01:00
|
|
|
// If this is the dev environment, write the CSS to the "public"
|
|
|
|
// directory as well.
|
|
|
|
.pipe(gulp.dest('resources/views/emails/html/css'))
|
|
|
|
.pipe(plug.if(!PRODUCTION, gulp.dest('public/build/emails/css')));
|
2016-12-26 01:53:16 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Copy and compress images
|
|
|
|
gulp.task("email-images", function emailImages() {
|
|
|
|
return gulp.src('resources/emails/src/assets/img/**/*')
|
|
|
|
.pipe(plug.imagemin())
|
2016-12-26 16:50:13 +01:00
|
|
|
.pipe(gulp.dest('./resources/views/emails/html/assets/img'));
|
2016-12-26 01:53:16 +01:00
|
|
|
});
|
|
|
|
|
2016-12-26 16:50:13 +01:00
|
|
|
|
|
|
|
// Inlines CSS into HTML, adds media query CSS into the <style> tag of the email, and compresses the HTML
|
|
|
|
function emailInliner(css) {
|
|
|
|
var css = fs.readFileSync(css).toString();
|
|
|
|
var mqCss = siphon(css);
|
|
|
|
|
|
|
|
return lazypipe()
|
|
|
|
.pipe(plug.inlineCss, {
|
|
|
|
applyStyleTags: false,
|
|
|
|
removeStyleTags: true,
|
|
|
|
preserveMediaQueries: true,
|
|
|
|
removeLinkTags: false
|
|
|
|
})
|
|
|
|
.pipe(plug.replace, '<!-- <style> -->', "<style>" + mqCss + "</style>")
|
|
|
|
.pipe(plug.replace, '<link rel="stylesheet" type="text/css" href="css/app.css">', '')
|
|
|
|
.pipe(plug.htmlmin, {
|
|
|
|
collapseWhitespace: true,
|
|
|
|
minifyCSS: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-12-26 01:53:16 +01:00
|
|
|
// Inline CSS and minify HTML
|
|
|
|
gulp.task("email-inline", function emailInline() {
|
2016-12-26 16:50:13 +01:00
|
|
|
return gulp.src('resources/views/emails/html/**/*.blade.php')
|
|
|
|
.pipe(emailInliner('resources/views/emails/html/css/app.css')())
|
|
|
|
.pipe(gulp.dest('resources/views/emails/html'));
|
2016-12-26 01:53:16 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Helper tasks for email watchers
|
|
|
|
gulp.task("email-rebuild-handlebars", function(callback){
|
|
|
|
runSequence("email-pages", "email-inline", callback);
|
|
|
|
});
|
|
|
|
gulp.task("email-rebuild-layouts", function(callback){
|
|
|
|
runSequence("email-reset-pages", "email-pages", "email-inline", callback);
|
|
|
|
});
|
|
|
|
gulp.task("email-rebuild-sass", function(callback){
|
|
|
|
runSequence("email-reset-pages", "email-sass", "email-pages", "email-inline", callback)
|
|
|
|
});
|
|
|
|
|
|
|
|
// Watch for file changes
|
|
|
|
gulp.task("email-watch", function (callback) {
|
|
|
|
gulp.watch('resources/emails/src/pages/**/*.blade.php.hbs', ["email-rebuild-handlebars"]);
|
|
|
|
gulp.watch(['resources/emails/src/layouts/**/*', 'resources/emails/src/partials/**/*'], ["email-rebuild-layouts"]);
|
|
|
|
gulp.watch(['resources/emails/src/assets/scss/**/*.scss'], ["email-rebuild-sass"]);
|
|
|
|
gulp.watch('resources/emails/src/assets/img/**/*', ["email-images"]);
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
|
2016-12-26 16:50:13 +01:00
|
|
|
// Build the "resources/views/emails/html" folder by running all of the above tasks
|
2016-12-26 01:53:16 +01:00
|
|
|
gulp.task('email-build', function(callback){
|
|
|
|
runSequence("email-clean", "email-pages", "email-sass", "email-images", "email-inline", callback);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Build emails, run the server, and watch for file changes
|
|
|
|
gulp.task('email-default', function(callback) {
|
|
|
|
runSequence('email-build', "email-watch");
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
|
|
|
|
//=============== END Zurb Foundation Email stack =================//
|
|
|
|
|
2015-09-06 19:21:11 +02:00
|
|
|
gulp.task('build', [
|
2016-02-14 18:27:57 +01:00
|
|
|
'webpack-build',
|
|
|
|
'copy:templates',
|
2015-10-25 03:43:37 +01:00
|
|
|
'styles-app',
|
2016-12-26 01:53:16 +01:00
|
|
|
'styles-embed',
|
|
|
|
'email-build'
|
2015-09-06 19:21:11 +02:00
|
|
|
]);
|
|
|
|
|
2016-02-14 18:27:57 +01:00
|
|
|
gulp.task("watch-legacy", ["build"], function () {
|
2015-10-25 03:43:37 +01:00
|
|
|
gulp.watch("resources/assets/styles/**/*.{css,less}", ["styles-app"]);
|
2015-09-06 19:21:11 +02:00
|
|
|
});
|
|
|
|
|
2016-12-26 01:53:16 +01:00
|
|
|
gulp.task("watch", ["webpack-dev-server", "email-default", "watch-legacy"], function () {});
|
2016-02-14 17:14:30 +01:00
|
|
|
|
|
|
|
|
2015-09-06 19:21:11 +02:00
|
|
|
function endsWith(str, suffix) {
|
2015-10-25 03:43:37 +01:00
|
|
|
return str.indexOf(suffix, str.length - suffix.length) !== -1;
|
|
|
|
}
|