From f6df37ec249b1e12f6f4432ddf02df1929853126 Mon Sep 17 00:00:00 2001 From: Francesco Siddi Date: Thu, 13 Jul 2017 18:26:54 +0200 Subject: [PATCH] Introducing the gulp command From now on we work with .pug files for templates. --- gulp | 19 ++++++++++ gulpfile.js | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 25 +++++++++++++ 3 files changed, 144 insertions(+) create mode 100755 gulp create mode 100644 gulpfile.js create mode 100644 package.json diff --git a/gulp b/gulp new file mode 100755 index 0000000..093ad60 --- /dev/null +++ b/gulp @@ -0,0 +1,19 @@ +#!/bin/bash -ex + +GULP=./node_modules/.bin/gulp + +function install() { + npm install + touch $GULP # installer doesn't always touch this after a build, so we do. +} + +# Rebuild Gulp if missing or outdated. +[ -e $GULP ] || install +[ gulpfile.js -nt $GULP ] && install + +if [ "$1" == "watch" ]; then + # Treat "gulp watch" as "gulp && gulp watch" + $GULP +fi + +exec $GULP "$@" diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..eaf6ebe --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,100 @@ +var argv = require('minimist')(process.argv.slice(2)); +var autoprefixer = require('gulp-autoprefixer'); +var chmod = require('gulp-chmod'); +var concat = require('gulp-concat'); +var gulp = require('gulp'); +var gulpif = require('gulp-if'); +var pug = require('gulp-pug'); +var livereload = require('gulp-livereload'); +var plumber = require('gulp-plumber'); +var rename = require('gulp-rename'); +var sass = require('gulp-sass'); +var sourcemaps = require('gulp-sourcemaps'); +var uglify = require('gulp-uglify'); +var cache = require('gulp-cached'); + +var enabled = { + uglify: argv.production, + maps: argv.production, + failCheck: !argv.production, + prettyPug: !argv.production, + cachify: !argv.production, + liveReload: !argv.production +}; + + +/* CSS */ +gulp.task('styles', function() { + gulp.src('src/styles/**/*.sass') + .pipe(gulpif(enabled.failCheck, plumber())) + .pipe(gulpif(enabled.maps, sourcemaps.init())) + .pipe(sass({ + outputStyle: 'compressed'} + )) + .pipe(autoprefixer("last 3 versions")) + .pipe(gulpif(enabled.maps, sourcemaps.write("."))) + .pipe(gulp.dest('cloud/static/assets/css')) + .pipe(gulpif(enabled.liveReload, livereload())); +}); + + +/* Templates - Pug */ +gulp.task('templates', function() { + gulp.src('src/templates/**/*.pug') + .pipe(gulpif(enabled.failCheck, plumber())) + .pipe(gulpif(enabled.cachify, cache('templating'))) + .pipe(pug({ + pretty: enabled.prettyPug + })) + .pipe(gulp.dest('cloud/templates/')) + .pipe(gulpif(enabled.liveReload, livereload())); +}); + + +/* Individual Uglified Scripts */ +gulp.task('scripts', function() { + gulp.src('src/scripts/*.js') + .pipe(gulpif(enabled.failCheck, plumber())) + .pipe(gulpif(enabled.cachify, cache('scripting'))) + .pipe(gulpif(enabled.maps, sourcemaps.init())) + .pipe(gulpif(enabled.uglify, uglify())) + .pipe(rename({suffix: '.min'})) + .pipe(gulpif(enabled.maps, sourcemaps.write("."))) + .pipe(chmod(644)) + .pipe(gulp.dest('cloud/static/assets/js/')) + .pipe(gulpif(enabled.liveReload, livereload())); +}); + + +/* Collection of scripts in src/scripts/tutti/ to merge into tutti.min.js */ +/* Since it's always loaded, it's only for functions that we want site-wide */ +gulp.task('scripts_concat_tutti', function() { + gulp.src('src/scripts/tutti/**/*.js') + .pipe(gulpif(enabled.failCheck, plumber())) + .pipe(gulpif(enabled.maps, sourcemaps.init())) + .pipe(concat("tutti.min.js")) + .pipe(gulpif(enabled.uglify, uglify())) + .pipe(gulpif(enabled.maps, sourcemaps.write("."))) + .pipe(chmod(644)) + .pipe(gulp.dest('cloud/static/assets/js/')) + .pipe(gulpif(enabled.liveReload, livereload())); +}); + + + +// While developing, run 'gulp watch' +gulp.task('watch',function() { + // Only listen for live reloads if ran with --livereload + if (argv.livereload){ + livereload.listen(); + } + + gulp.watch('src/styles/**/*.sass',['styles']); + gulp.watch('src/templates/**/*.pug',['templates']); + gulp.watch('src/scripts/*.js',['scripts']); + gulp.watch('src/scripts/tutti/**/*.js',['scripts_concat_tutti']); +}); + + +// Run 'gulp' to build everything at once +gulp.task('default', ['styles', 'templates', 'scripts', 'scripts_concat_tutti',]); diff --git a/package.json b/package.json new file mode 100644 index 0000000..84365d1 --- /dev/null +++ b/package.json @@ -0,0 +1,25 @@ +{ + "name": "pillar", + "repository": { + "type": "git", + "url": "https://github.com/armadillica/pillar.git" + }, + "author": "Blender Institute", + "license": "GPL-2.0", + "devDependencies": { + "gulp": "~3.9.1", + "gulp-autoprefixer": "~2.3.1", + "gulp-cached": "~1.1.0", + "gulp-chmod": "~1.3.0", + "gulp-concat": "~2.6.0", + "gulp-if": "^2.0.1", + "gulp-pug": "~3.2.0", + "gulp-livereload": "~3.8.1", + "gulp-plumber": "~1.1.0", + "gulp-rename": "~1.2.2", + "gulp-sass": "~2.3.1", + "gulp-sourcemaps": "~1.6.0", + "gulp-uglify": "~1.5.3", + "minimist": "^1.2.0" + } +}