0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-08 07:50:43 -05:00
penpot/gulpfile.js

187 lines
4.3 KiB
JavaScript
Raw Normal View History

2016-06-11 13:43:57 -05: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 gulpif = require("gulp-if");
2016-06-11 13:43:57 -05:00
const paths = {};
2016-02-21 09:42:35 -05:00
paths.app = "./resources/";
paths.output = "./resources/public/";
2016-02-21 13:42:01 -05:00
paths.dist = "./dist/";
2016-02-21 13:50:26 -05:00
paths.target = "./target/";
2015-06-18 12:35:50 -05:00
paths.scss = paths.app + "styles/**/*.scss";
2016-06-11 13:43:57 -05:00
/***********************************************
* Helper Tasks
2016-06-11 13:43:57 -05:00
***********************************************/
gulp.task("clean", function(next) {
rimraf(paths.output + "css/", function() {
rimraf(paths.output + "js/", function() {
rimraf(paths.target, next);
});
});
});
2016-04-03 05:19:11 -05:00
function makeAutoprefixer() {
return autoprefixer('last 2 version',
'safari 5',
'ios 6',
'android 4');
}
function isProduction() {
return (process.env.NODE_ENV === 'production');
}
/***********************************************
* Development
***********************************************/
// Styles
2016-04-03 05:19:11 -05:00
function scssPipeline(options) {
return function() {
const input = options.input;
const output = options.output;
return gulp.src(input)
.pipe(plumber())
.pipe(scss({style: "expanded"}))
.pipe(makeAutoprefixer())
.pipe(gulpif(isProduction, cssmin()))
.pipe(gulp.dest(output));
};
2016-04-03 05:19:11 -05:00
}
2016-02-21 09:42:35 -05:00
gulp.task("scss:main", scssPipeline({
input: paths.app + "styles/main.scss",
output: paths.output + "css/"
}));
2016-02-21 09:42:35 -05:00
gulp.task("scss:view", scssPipeline({
input: paths.app + "styles/view.scss",
output: paths.output + "view/css/"
}));
2016-04-03 05:19:11 -05:00
gulp.task("scss", ["scss:main", "scss:view"]);
2016-04-03 05:19:11 -05:00
// Templates
2015-06-18 12:35:50 -05:00
function templatePipeline(options) {
return function() {
const input = options.input;
const output = options.output;
const jspath = options.jspath;
const csspath = options.csspath;
const ts = Math.floor(new Date());
2016-06-11 13:43:57 -05:00
const tmpl = mustache({
jsfile: `${jspath}?v=${ts}`,
cssfile: `${csspath}?v=${ts}`
});
2016-06-11 13:43:57 -05:00
return gulp.src(input)
.pipe(tmpl)
.pipe(rename("index.html"))
.pipe(gulp.dest(output));
};
}
gulp.task("template:main", templatePipeline({
input: paths.app + "index.mustache",
output: paths.output,
jspath: "/js/main.js",
csspath: "/css/main.css"
}));
gulp.task("template:view", templatePipeline({
input: paths.app + "view.mustache",
output: paths.output + "view/",
jspath: "/view/js/view.js",
csspath: "/view/css/view.css"
}));
gulp.task("template", ["template:view",
2016-06-11 13:43:57 -05:00
"template:main"]);
// Entry Point
gulp.task("default", ["scss", "template"], function () {
gulp.watch(paths.scss, ["scss"]);
});
2016-06-11 13:43:57 -05:00
/***********************************************
* Production
2016-06-11 13:43:57 -05:00
***********************************************/
gulp.task("dist:clean", function(next) {
rimraf(paths.dist, next);
2016-06-11 13:43:57 -05:00
});
// Templates
2016-06-11 13:43:57 -05:00
gulp.task("dist:template:main", templatePipeline({
input: paths.app + "index.mustache",
output: paths.dist,
jspath: "/js/main.js",
csspath: "/css/main.css"
}));
2016-06-11 13:43:57 -05:00
gulp.task("dist:template:view", templatePipeline({
input: paths.app + "view.mustache",
output: paths.dist + "view/",
jspath: "/view/js/main.js",
csspath: "/view/css/main.css"
}));
2016-02-21 09:42:35 -05:00
gulp.task("dist:template", ["dist:template:view",
"dist:template:main"]);
2016-02-21 13:42:01 -05:00
// Styles
2016-06-11 13:43:57 -05:00
gulp.task("dist:scss:main", scssPipeline({
input: paths.app + "styles/main.scss",
output: paths.dist + "css/"
}));
gulp.task("dist:scss:view", scssPipeline({
input: paths.app + "styles/view.scss",
output: paths.dist + "view/css/"
}));
gulp.task("dist:scss", ["dist:scss:main",
"dist:scss:view"]);
// Copy
gulp.task("dist:copy:fonts", function() {
return gulp.src(paths.output + "/fonts/**/*")
.pipe(gulp.dest(paths.dist + "fonts/"));
2016-02-21 11:01:27 -05:00
});
gulp.task("dist:copy:images", function() {
return gulp.src(paths.output + "/images/**/*")
.pipe(gulp.dest(paths.dist + "images/"));
2016-02-21 09:42:35 -05:00
});
2015-06-18 12:35:50 -05:00
2016-06-11 13:43:57 -05:00
gulp.task("dist:copy", ["dist:copy:fonts",
"dist:copy:images"]);
// Entry Point
2016-02-21 09:42:35 -05:00
gulp.task("dist", function(next) {
runseq("dist:clean", ["dist:template", "dist:scss", "dist:copy"], next);
2016-02-21 09:42:35 -05:00
});
2015-06-18 12:35:50 -05:00