1
0
mirror of https://github.com/kremalicious/blog.git synced 2025-01-03 18:35:07 +01:00
This commit is contained in:
Matthias Kretschmann 2017-03-25 22:05:01 +01:00
parent 35c40b7d88
commit 5e735b1a1e
Signed by: m
GPG Key ID: BD3C1F3EDD7831FC
4 changed files with 130 additions and 90 deletions

13
.editorconfig Normal file
View File

@ -0,0 +1,13 @@
# EditorConfig is awesome: http://EditorConfig.org
[*]
indent_style = space
indent_size = 4
end_of_line = lf
insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true
[*.json]
indent_size = 2

View File

@ -3,7 +3,7 @@ dist: trusty
language: ruby language: ruby
rvm: rvm:
- 2.3.0 - 2.4.0
cache: cache:
bundler: true bundler: true
@ -22,7 +22,7 @@ addons:
- libgsl0-dev - libgsl0-dev
before_install: before_install:
- nvm install 6 - nvm install 7
before_script: "_ci/setup.sh" before_script: "_ci/setup.sh"
script: "_ci/build.sh" script: "_ci/build.sh"

View File

@ -12,10 +12,6 @@ import browser from 'browser-sync'
import autoprefixer from 'autoprefixer' import autoprefixer from 'autoprefixer'
import cssnano from 'cssnano' import cssnano from 'cssnano'
// Temporary solution until gulp 4
// https://github.com/gulpjs/gulp/issues/355
import runSequence from 'run-sequence'
// handle errors // handle errors
const onError = (error) => { const onError = (error) => {
$.util.log('') $.util.log('')
@ -110,46 +106,82 @@ const BANNER = [
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// Tasks // gulp tasks
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//
// Full build
//
// `gulp build` is the development build
// `gulp build --production` is the production build
//
gulp.task('build', gulp.series(
buildBanner, clean, jekyll,
gulp.parallel(html, css, js, images, icons, fonts, media),
rev, revReplace
))
function buildBanner(done) {
console.log($.util.colors.gray(" ------------------------------------------"))
console.log($.util.colors.green(' Building ' + ($.util.env.production ? 'production' : 'dev') + ' version...'))
console.log($.util.colors.gray(" ------------------------------------------"))
done()
}
//
// Build site, run server, and watch for file changes
//
gulp.task('default', gulp.series('build', server, watch))
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// Functions
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// //
// Delete build artifacts // Delete build artifacts
// //
gulp.task('clean', (done) => { function clean(done) {
return del([ return del([
DIST + '/**/*', DIST + '**/*',
DIST + '/.*', // delete all hidden files DIST + '.*', // delete all hidden files
'!' + DIST + '/media/**' '!' + DIST + '/media/**'
], done) ])
})
done()
}
// //
// Jekyll // Jekyll
// //
gulp.task('jekyll', (cb) => { function jekyll(done) {
browser.notify('Compiling Jekyll')
var spawn = require('child_process').spawn browser.notify('Compiling Jekyll')
if (isProduction) { if (isProduction) {
process.env.JEKYLL_ENV = 'production' process.env.JEKYLL_ENV = 'production'
var jekyll = spawn('bundle', ['exec', 'jekyll', 'build', '--lsi'], { stdio: 'inherit' }) var jekyll_options = 'jekyll build --lsi'
} else { } else {
var jekyll = spawn('bundle', ['exec', 'jekyll', 'build', '--config', '_config.yml,_config.dev.yml', '--drafts', '--future', '--incremental'], { stdio: 'inherit' }) var jekyll_options = 'jekyll build --config _config.yml,_config.dev.yml --incremental --drafts --future'
} }
jekyll.on('exit', function(code) { var spawn = require('child_process').spawn,
cb(code === 0 ? null : 'ERROR: Jekyll process exited with code: ' + code) jekyll = spawn('bundle', ['exec', jekyll_options], { stdio: 'inherit' })
})
}) return jekyll
.on('error', (error) => onError() )
.on('close', done)
}
// //
// HTML // HTML
// //
gulp.task('html', () => { function html() {
return gulp.src(DIST + '/**/*.html') return gulp.src(DIST + '/**/*.html')
.pipe($.if(isProduction, $.htmlmin({ .pipe($.if(isProduction, $.htmlmin({
collapseWhitespace: true, collapseWhitespace: true,
@ -163,13 +195,13 @@ gulp.task('html', () => {
minifyCSS: true minifyCSS: true
}))) })))
.pipe(gulp.dest(DIST)) .pipe(gulp.dest(DIST))
}) }
// //
// Styles // Styles
// //
gulp.task('css', () => { function css() {
var processors = [ var processors = [
autoprefixer({ browsers: COMPATIBILITY }), autoprefixer({ browsers: COMPATIBILITY }),
@ -188,7 +220,7 @@ gulp.task('css', () => {
.pipe($.rename({ suffix: '.min' })) .pipe($.rename({ suffix: '.min' }))
.pipe(gulp.dest(DIST + '/assets/css/')) .pipe(gulp.dest(DIST + '/assets/css/'))
.pipe(browser.stream()) .pipe(browser.stream())
}) }
// //
@ -196,17 +228,17 @@ gulp.task('css', () => {
// //
// Libraries // Libraries
gulp.task('js:libraries', () => { function jsLibraries() {
return gulp.src([ return gulp.src([
'node_modules/picturefill/dist/picturefill.js' 'node_modules/picturefill/dist/picturefill.js'
]) ])
.pipe($.if(isProduction, $.uglify())).on('error', onError) .pipe($.if(isProduction, $.uglify())).on('error', onError)
.pipe($.rename({ suffix: '.min'})) .pipe($.rename({ suffix: '.min'}))
.pipe(gulp.dest(DIST + '/assets/js/')) .pipe(gulp.dest(DIST + '/assets/js/'))
}) }
// Project js // Project js
gulp.task('js:project', () => { function jsProject() {
return gulp.src(SRC + '/_assets/js/kremalicious3.js') return gulp.src(SRC + '/_assets/js/kremalicious3.js')
.pipe($.sourcemaps.init()) .pipe($.sourcemaps.init())
.pipe($.include()).on('error', onError) .pipe($.include()).on('error', onError)
@ -215,10 +247,10 @@ gulp.task('js:project', () => {
.pipe($.if(isProduction, $.header(BANNER, { pkg: pkg }))) .pipe($.if(isProduction, $.header(BANNER, { pkg: pkg })))
.pipe($.rename({suffix: '.min'})) .pipe($.rename({suffix: '.min'}))
.pipe(gulp.dest(DIST + '/assets/js/')) .pipe(gulp.dest(DIST + '/assets/js/'))
}) }
// Service Worker js // Service Worker js
gulp.task('js:sw', () => { function jsSW() {
return gulp.src(DIST + '/service-worker.js') return gulp.src(DIST + '/service-worker.js')
.pipe($.if(isProduction, $.uglify({ .pipe($.if(isProduction, $.uglify({
compress: { compress: {
@ -226,16 +258,18 @@ gulp.task('js:sw', () => {
} }
}))).on('error', onError) }))).on('error', onError)
.pipe(gulp.dest(DIST + '/')) .pipe(gulp.dest(DIST + '/'))
}) }
// Collect all script tasks // Collect all script tasks
gulp.task('js', ['js:libraries', 'js:project', 'js:sw']) function js() {
return jsLibraries(), jsProject(), jsSW()
}
// //
// Icons // Icons
// //
gulp.task('icons', () => { function icons() {
return gulp.src(iconset.icons) return gulp.src(iconset.icons)
.pipe($.rename({ prefix: iconset.prefix })) .pipe($.rename({ prefix: iconset.prefix }))
.pipe(gulp.dest(iconset.dist)) .pipe(gulp.dest(iconset.dist))
@ -243,13 +277,13 @@ gulp.task('icons', () => {
.pipe($.if(isProduction, $.imagemin({ svgoPlugins: [{ removeViewBox: false }] }))) .pipe($.if(isProduction, $.imagemin({ svgoPlugins: [{ removeViewBox: false }] })))
.pipe($.svgSprite(SPRITE)) .pipe($.svgSprite(SPRITE))
.pipe(gulp.dest(iconset.dist)) .pipe(gulp.dest(iconset.dist))
}) }
// //
// Copy images // Copy images
// //
gulp.task('images', () => { function images() {
return gulp.src([ return gulp.src([
SRC + '/_assets/img/**/*', SRC + '/_assets/img/**/*',
'!' + SRC + '/_assets/img/entypo/**/*' '!' + SRC + '/_assets/img/entypo/**/*'
@ -262,48 +296,49 @@ gulp.task('images', () => {
svgoPlugins: [{ removeViewBox: false }] svgoPlugins: [{ removeViewBox: false }]
}))) })))
.pipe(gulp.dest(DIST + '/assets/img/')) .pipe(gulp.dest(DIST + '/assets/img/'))
}) }
// //
// Copy fonts // Copy fonts
// //
gulp.task('fonts', () => { function fonts() {
return gulp.src(SRC + '/_assets/fonts/**/*') return gulp.src(SRC + '/_assets/fonts/**/*')
.pipe(gulp.dest(DIST + '/assets/fonts/')) .pipe(gulp.dest(DIST + '/assets/fonts/'))
}) }
// //
// Copy media // Copy media
// //
gulp.task('media', () => { function media() {
return gulp.src(SRC + '/_media/**/*') return gulp.src(SRC + '/_media/**/*')
.pipe(gulp.dest(DIST + '/media/')) .pipe(gulp.dest(DIST + '/media/'))
}) }
// //
// Revision static assets // Revision static assets
// //
gulp.task('rev', () => { function rev(done) {
// globbing is slow so do everything conditionally for faster dev build // globbing is slow so do everything conditionally for faster dev build
if (isProduction) { if (isProduction) {
return gulp.src(DIST + '/assets/**/*.{css,js,png,jpg,jpeg,svg,eot,ttf,woff}') return gulp.src(DIST + '/assets/**/*.{css,js,png,jpg,jpeg,svg,eot,ttf,woff,woff2}')
.pipe($.if(isProduction, $.rev())) .pipe($.if(isProduction, $.rev()))
.pipe(gulp.dest(DIST + '/assets/')) .pipe(gulp.dest(DIST + '/assets/'))
// output rev manifest for next replace task // output rev manifest for next replace task
.pipe($.if(isProduction, $.rev.manifest())) .pipe($.if(isProduction, $.rev.manifest()))
.pipe(gulp.dest(DIST + '/assets/')) .pipe(gulp.dest(DIST + '/assets/'))
} }
}) done()
}
// //
// Replace all links to assets in files // Replace all links to assets in files
// from a manifest file // from a manifest file
// //
gulp.task('rev:replace', () => { function revReplace(done) {
// globbing is slow so do everything conditionally for faster dev build // globbing is slow so do everything conditionally for faster dev build
if (isProduction) { if (isProduction) {
var manifest = gulp.src(DIST + '/assets/rev-manifest.json') var manifest = gulp.src(DIST + '/assets/rev-manifest.json')
@ -311,63 +346,42 @@ gulp.task('rev:replace', () => {
.pipe($.if(isProduction, $.revReplace({ manifest: manifest }))) .pipe($.if(isProduction, $.revReplace({ manifest: manifest })))
.pipe(gulp.dest(DIST)) .pipe(gulp.dest(DIST))
} }
}) done()
}
// //
// Dev Server // Dev Server
// //
gulp.task('server', ['build'], () => { function server(done) {
browser.init({ browser.init({
server: DIST, server: DIST,
port: PORT, port: PORT,
reloadDebounce: 2000 reloadDebounce: 2000
}) })
})
done()
}
//
// Watch for file changes
//
function watch() {
gulp.watch(SRC + '_assets/styl/**/*.styl').on('all', gulp.series(css))
gulp.watch(SRC + '_assets/js/**/*.js').on('all', gulp.series(js, browser.reload))
gulp.watch(SRC + '_assets/img/**/*.{png,jpg,jpeg,gif,webp}').on('all', gulp.series(images, browser.reload))
gulp.watch(SRC + '_assets/img/**/*.{svg}').on('all', gulp.series(icons, browser.reload))
gulp.watch(SRC + '_media/**/*').on('all', gulp.series(media, browser.reload))
gulp.watch([SRC + '/**/*.{html,xml,json,txt,md,yml}', './*.yml', SRC + '_includes/svg/*']).on('all', gulp.series('build', browser.reload))
}
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// Task sequences // Deployment
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
gulp.task('deploy', (done) => {
//
// Build site, run server, and watch for file changes
//
gulp.task('default', ['server'], () => {
gulp.watch([SRC + '/_assets/styl/**/*.styl'], ['css'])
gulp.watch([SRC + '/_assets/js/*.js'], ['js', browser.reload])
gulp.watch([SRC + '/_assets/img/**/*.{png,jpg,jpeg,gif}'], ['images', browser.reload])
gulp.watch([SRC + '/_assets/img/**/*.{svg}'], ['icons', browser.reload])
gulp.watch([SRC + '/_media/**/*'], ['media', browser.reload])
gulp.watch([SRC + '/**/*.{html,xml,json,txt,md,yml}', './*.yml'], ['build', browser.reload])
})
//
// Full build
//
gulp.task('build', (done) => {
console.log($.util.colors.gray(" ------------------------------------------"))
console.log($.util.colors.green(' Building ' + ($.util.env.production ? 'production' : 'dev') + ' version...'))
console.log($.util.colors.gray(" ------------------------------------------"))
runSequence(
'clean',
'jekyll',
['html', 'css', 'js', 'images', 'icons', 'fonts', 'media'],
'rev',
'rev:replace',
done
)
})
//
// Deploy to S3
//
gulp.task('deploy', () => {
// create publisher, define config // create publisher, define config
var publisher = $.awspublish.create({ var publisher = $.awspublish.create({
@ -387,7 +401,7 @@ gulp.task('deploy', () => {
}, },
routes: { routes: {
// all static assets, cached & gzipped // all static assets, cached & gzipped
'^assets/(?:.+)\\.(?:js|css|png|jpg|jpeg|gif|ico|svg|ttf)$': { '^assets/(?:.+)\\.(?:js|css|png|jpg|jpeg|gif|ico|svg|ttf|eot|woff|woff2)$': {
cacheTime: 2592000, // cache for 1 month cacheTime: 2592000, // cache for 1 month
gzip: true gzip: true
}, },
@ -403,6 +417,20 @@ gulp.task('deploy', () => {
gzip: true gzip: true
}, },
// font mime types
'\.ttf$': {
key: '$&',
headers: { 'Content-Type': 'application/x-font-ttf' }
},
'\.woff$': {
key: '$&',
headers: { 'Content-Type': 'application/x-font-woff' }
},
'\.woff2$': {
key: '$&',
headers: { 'Content-Type': 'application/x-font-woff2' }
},
// pass-through for anything that wasn't matched by routes above, to be uploaded with default options // pass-through for anything that wasn't matched by routes above, to be uploaded with default options
"^.+$": "$&" "^.+$": "$&"
} }

View File

@ -32,7 +32,7 @@
"concurrent-transform": ">=1.0.0", "concurrent-transform": ">=1.0.0",
"cssnano": ">=3.6.2", "cssnano": ">=3.6.2",
"del": ">=1.2.0", "del": ">=1.2.0",
"gulp": ">=3.8.0", "gulp": "github:gulpjs/gulp#4.0",
"gulp-awspublish": ">=2.0.2", "gulp-awspublish": ">=2.0.2",
"gulp-awspublish-router": ">=0.1.1", "gulp-awspublish-router": ">=0.1.1",
"gulp-filter": ">=2.0.2", "gulp-filter": ">=2.0.2",
@ -51,8 +51,7 @@
"gulp-stylus": ">=2.3.1", "gulp-stylus": ">=2.3.1",
"gulp-svg-sprite": ">=1.2.2", "gulp-svg-sprite": ">=1.2.2",
"gulp-uglify": ">=1.2.0", "gulp-uglify": ">=1.2.0",
"gulp-util": ">=3.0.6", "gulp-util": ">=3.0.6"
"run-sequence": ">=1.1.0"
}, },
"engines": { "engines": {
"node": ">=5.0.0" "node": ">=5.0.0"