0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-25 07:58:49 -05:00
penpot/gulpfile.js

147 lines
3.7 KiB
JavaScript
Raw Normal View History

2016-06-11 21:43:57 +03:00
const gulp = require("gulp");
const runseq = require('run-sequence');
const scss = require("gulp-sass");
const plumber = require("gulp-plumber");
const autoprefixer = require('gulp-autoprefixer');
const watch = require("gulp-watch");
const cssmin = require("gulp-cssmin");
const rimraf = require("rimraf");
const mustache = require("gulp-mustache");
const rename = require("gulp-rename");
const paths = {};
2016-02-21 16:42:35 +02:00
paths.app = "./resources/";
paths.output = "./resources/public/";
2016-02-21 20:42:01 +02:00
paths.dist = "./dist/";
2016-02-21 20:50:26 +02:00
paths.target = "./target/";
2015-06-18 19:35:50 +02:00
paths.scss = paths.app + "styles/**/*.scss";
2016-06-11 21:43:57 +03:00
/***********************************************
* Styles
***********************************************/
2016-04-03 13:19:11 +03:00
function makeAutoprefixer() {
return autoprefixer('last 2 version',
'safari 5',
'ios 6',
'android 4');
}
function scssPipeline(options) {
2016-06-11 21:43:57 +03:00
const input = options.input;
const output = options.output;
2016-04-03 13:19:11 +03:00
return gulp.src(input)
2016-06-11 21:43:57 +03:00
.pipe(plumber())
.pipe(scss({style: "expanded"}))
.pipe(makeAutoprefixer())
.pipe(gulp.dest(output));
2016-04-03 13:19:11 +03:00
}
2016-02-21 16:42:35 +02:00
2016-06-11 21:43:57 +03:00
gulp.task("scss:main", function() {
2016-04-03 13:19:11 +03:00
return scssPipeline({
input: paths.app + "styles/main.scss",
output: paths.output + "css/"
});
2016-02-21 16:42:35 +02:00
});
2016-06-11 21:43:57 +03:00
gulp.task("scss:preview", function() {
return scssPipeline({
input: paths.app + "styles/preview.scss",
output: paths.output + "css/"
});
});
2016-04-03 13:19:11 +03:00
2016-06-11 21:43:57 +03:00
gulp.task("scss", ["scss:main", "scss:preview"]);
2016-04-03 13:19:11 +03:00
2016-06-11 21:43:57 +03:00
/***********************************************
* Templates
***********************************************/
2015-06-18 19:35:50 +02:00
2016-06-11 21:43:57 +03:00
gulp.task("template:main", function() {
const ts = Math.floor(new Date());
const tmpl = mustache({
jsfile: "/js/main.js?v=" + ts,
cssfile: "/css/main.css?v=" + ts
2016-04-03 13:19:11 +03:00
});
return gulp.src(paths.app + "index.mustache")
2016-06-11 21:43:57 +03:00
.pipe(tmpl)
.pipe(rename("index.html"))
.pipe(gulp.dest(paths.output));
});
gulp.task("template:preview", function() {
const ts = Math.floor(new Date());
const tmpl = mustache({
jsfile: "/js/preview.js?v=" + ts,
cssfile: "/css/preview.css?v=" + ts
});
return gulp.src(paths.app + "preview.mustache")
.pipe(tmpl)
.pipe(rename("index.html"))
.pipe(gulp.dest(paths.output + "preview/"));
});
2016-06-11 21:43:57 +03:00
gulp.task("template", ["template:preview",
"template:main"]);
/***********************************************
* Production Build
***********************************************/
gulp.task("dist:cssmin:main", function() {
return gulp.src(paths.output + "css/main.css")
.pipe(cssmin())
.pipe(gulp.dest(paths.output + "css/"));
});
gulp.task("dist:cssmin:preview", function() {
return gulp.src(paths.output + "css/preview.css")
.pipe(cssmin())
.pipe(gulp.dest(paths.output + "css/"));
});
gulp.task("dist:cssmin", ["dist:cssmin:main",
"dist:cssmin:preview"]);
2016-04-03 13:19:11 +03:00
gulp.task("dist:scss", function(next) {
2016-06-11 21:43:57 +03:00
runseq("scss", "dist:cssmin", next);
2016-02-21 16:42:35 +02:00
});
2016-04-03 13:19:11 +03:00
gulp.task("dist:clean", function(next) {
2016-02-21 20:50:26 +02:00
rimraf(paths.dist, next);
2016-02-21 20:42:01 +02:00
});
2016-06-11 21:43:57 +03:00
/***********************************************
* Helper Tasks
***********************************************/
2016-02-21 20:50:26 +02:00
gulp.task("clean", function(next) {
2016-02-21 18:01:27 +02:00
rimraf(paths.output + "css/", function() {
2016-02-21 20:50:26 +02:00
rimraf(paths.output + "js/", function() {
rimraf(paths.target, next);
});
2016-02-21 18:01:27 +02:00
});
});
2016-04-03 13:19:11 +03:00
gulp.task("dist:copy", function() {
2016-02-21 16:42:35 +02:00
return gulp.src(paths.output + "/**/*.*")
2016-06-11 21:43:57 +03:00
.pipe(gulp.dest(paths.dist));
2016-02-21 16:42:35 +02:00
});
2015-06-18 19:35:50 +02:00
2016-06-11 21:43:57 +03:00
/***********************************************
* Entry Points
***********************************************/
2015-06-18 19:35:50 +02:00
// Default
2016-02-21 16:42:35 +02:00
gulp.task("dist", function(next) {
2016-06-11 21:43:57 +03:00
runseq(["template", "dist:scss"], "dist:clean", "dist:copy", next);
2016-02-21 16:42:35 +02:00
});
2015-06-18 19:35:50 +02:00
// Watch
2016-06-11 21:43:57 +03:00
gulp.task("default", ["scss", "template"], function () {
gulp.watch(paths.scss, ["scss"]);
2015-06-18 19:35:50 +02:00
});