mirror of
https://github.com/koodiklinikka/koodiklinikka.fi.git
synced 2026-02-09 09:50:53 +00:00
convert gulpfile.coffee to gulpfile.js
It actually makes a lot of sense to not use coffeescript because its not used elsewhere in the project. There was also Windows bug that prevented users from running the gulpfile https://github.com/gulpjs/gulp/issues/717
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@ node_modules
|
||||
bower_components
|
||||
public
|
||||
.DS_Store
|
||||
npm-debug.log
|
||||
139
gulpfile.coffee
139
gulpfile.coffee
@@ -1,139 +0,0 @@
|
||||
browserify = require 'browserify'
|
||||
chalk = require 'chalk'
|
||||
concat = require 'gulp-concat'
|
||||
CSSmin = require 'gulp-minify-css'
|
||||
ecstatic = require 'ecstatic'
|
||||
es = require 'event-stream'
|
||||
gulp = require 'gulp'
|
||||
gutil = require 'gulp-util'
|
||||
jade = require 'gulp-jade'
|
||||
less = require 'gulp-less'
|
||||
livereload = require 'gulp-livereload'
|
||||
path = require 'path'
|
||||
prefix = require 'gulp-autoprefixer'
|
||||
prettyTime = require 'pretty-hrtime'
|
||||
source = require 'vinyl-source-stream'
|
||||
streamify = require 'gulp-streamify'
|
||||
stylus = require 'gulp-stylus'
|
||||
uglify = require 'gulp-uglify'
|
||||
watchify = require 'watchify'
|
||||
|
||||
production = process.env.NODE_ENV is 'production'
|
||||
|
||||
config =
|
||||
scripts:
|
||||
source: './src/js/main.js'
|
||||
destination: './public/js/'
|
||||
filename: 'bundle.js'
|
||||
templates:
|
||||
source: './src/jade/*.jade'
|
||||
watch: './src/jade/*.jade'
|
||||
destination: './public/'
|
||||
styles:
|
||||
source: './src/styles/style.styl'
|
||||
icons: './src/styles/icons.less'
|
||||
filename: 'style.css'
|
||||
watch: './src/styles/*.*'
|
||||
destination: './public/css/'
|
||||
assets:
|
||||
source: ['./src/assets/**/*.*', './bower_components/font-awesome/fonts*/*.*']
|
||||
watch: './src/assets/**/*.*'
|
||||
destination: './public/'
|
||||
|
||||
handleError = (err) ->
|
||||
gutil.log err
|
||||
gutil.beep()
|
||||
this.emit 'end'
|
||||
|
||||
gulp.task 'scripts', ->
|
||||
|
||||
bundle = browserify
|
||||
entries: [config.scripts.source]
|
||||
extensions: config.scripts.extensions
|
||||
debug: not production
|
||||
|
||||
build = bundle.bundle()
|
||||
.on 'error', handleError
|
||||
.pipe source config.scripts.filename
|
||||
|
||||
build.pipe(streamify(uglify())) if production
|
||||
|
||||
build
|
||||
.pipe gulp.dest config.scripts.destination
|
||||
|
||||
gulp.task 'templates', ->
|
||||
pipeline = gulp
|
||||
.src config.templates.source
|
||||
.pipe(jade(pretty: not production))
|
||||
.on 'error', handleError
|
||||
.pipe gulp.dest config.templates.destination
|
||||
|
||||
pipeline = pipeline.pipe livereload(auto: false) unless production
|
||||
|
||||
pipeline
|
||||
|
||||
gulp.task 'styles', ->
|
||||
|
||||
styles = gulp
|
||||
.src config.styles.source
|
||||
.pipe stylus
|
||||
'include css': true
|
||||
|
||||
icons = gulp.src(config.styles.icons)
|
||||
.pipe less()
|
||||
|
||||
styles = es.merge(styles, icons)
|
||||
.pipe concat config.styles.filename
|
||||
.on 'error', handleError
|
||||
.pipe prefix 'last 2 versions', 'Chrome 34', 'Firefox 28', 'iOS 7'
|
||||
|
||||
styles = styles.pipe(CSSmin()) if production
|
||||
styles = styles.pipe gulp.dest config.styles.destination
|
||||
styles = styles.pipe livereload(auto: false) unless production
|
||||
styles
|
||||
|
||||
gulp.task 'assets', ->
|
||||
gulp
|
||||
.src config.assets.source
|
||||
.pipe gulp.dest config.assets.destination
|
||||
|
||||
gulp.task 'server', ->
|
||||
require('http')
|
||||
.createServer ecstatic root: path.join(__dirname, 'public')
|
||||
.listen 9001
|
||||
|
||||
gulp.task 'watch', ->
|
||||
livereload.listen()
|
||||
|
||||
gulp.watch config.templates.watch, ['templates']
|
||||
gulp.watch config.styles.watch, ['styles']
|
||||
gulp.watch config.assets.watch, ['assets']
|
||||
|
||||
bundle = watchify browserify
|
||||
entries: [config.scripts.source]
|
||||
extensions: config.scripts.extensions
|
||||
debug: not production
|
||||
cache: {}
|
||||
packageCache: {}
|
||||
fullPaths: true
|
||||
|
||||
bundle.on 'update', ->
|
||||
gutil.log "Starting '#{chalk.cyan 'rebundle'}'..."
|
||||
start = process.hrtime()
|
||||
build = bundle.bundle()
|
||||
.on 'error', handleError
|
||||
|
||||
.pipe source config.scripts.filename
|
||||
|
||||
build
|
||||
.pipe gulp.dest config.scripts.destination
|
||||
.pipe(livereload())
|
||||
gutil.log "Finished '#{chalk.cyan 'rebundle'}' after #{chalk.magenta prettyTime process.hrtime start}"
|
||||
|
||||
.emit 'update'
|
||||
|
||||
gulp.task 'no-js', ['templates', 'styles', 'assets']
|
||||
gulp.task 'build', ['scripts', 'no-js']
|
||||
# scripts and watch conflict and will produce invalid js upon first run
|
||||
# which is why the no-js task exists.
|
||||
gulp.task 'default', ['watch', 'no-js', 'server']
|
||||
140
gulpfile.js
Normal file
140
gulpfile.js
Normal file
@@ -0,0 +1,140 @@
|
||||
'use strict';
|
||||
|
||||
var browserify = require('browserify'),
|
||||
chalk = require('chalk'),
|
||||
concat = require('gulp-concat'),
|
||||
CSSmin = require('gulp-minify-css'),
|
||||
ecstatic = require('ecstatic'),
|
||||
es = require('event-stream'),
|
||||
gulp = require('gulp'),
|
||||
gutil = require('gulp-util'),
|
||||
jade = require('gulp-jade'),
|
||||
less = require('gulp-less'),
|
||||
livereload = require('gulp-livereload'),
|
||||
path = require('path'),
|
||||
prefix = require('gulp-autoprefixer'),
|
||||
prettyTime = require('pretty-hrtime'),
|
||||
source = require('vinyl-source-stream'),
|
||||
streamify = require('gulp-streamify'),
|
||||
stylus = require('gulp-stylus'),
|
||||
uglify = require('gulp-uglify'),
|
||||
watchify = require('watchify');
|
||||
|
||||
var production = process.env.NODE_ENV === 'production';
|
||||
|
||||
var config = {
|
||||
scripts: {
|
||||
source: './src/js/main.js',
|
||||
destination: './public/js/',
|
||||
filename: 'bundle.js'
|
||||
},
|
||||
templates: {
|
||||
source: './src/jade/*.jade',
|
||||
watch: './src/jade/*.jade',
|
||||
destination: './public/'
|
||||
},
|
||||
styles: {
|
||||
source: './src/styles/style.styl',
|
||||
icons: './src/styles/icons.less',
|
||||
filename: 'style.css',
|
||||
watch: './src/styles/*.*',
|
||||
destination: './public/css/'
|
||||
},
|
||||
assets: {
|
||||
source: ['./src/assets/**/*.*', './bower_components/font-awesome/fonts*/*.*'],
|
||||
watch: './src/assets/**/*.*',
|
||||
destination: './public/'
|
||||
}
|
||||
};
|
||||
|
||||
function handleError(err) {
|
||||
gutil.log(err);
|
||||
gutil.beep();
|
||||
return this.emit('end');
|
||||
};
|
||||
|
||||
gulp.task('scripts', function() {
|
||||
var build, bundle;
|
||||
bundle = browserify({
|
||||
entries: [config.scripts.source],
|
||||
extensions: config.scripts.extensions,
|
||||
debug: !production
|
||||
});
|
||||
build = bundle.bundle().on('error', handleError).pipe(source(config.scripts.filename));
|
||||
if (production) {
|
||||
build.pipe(streamify(uglify()));
|
||||
}
|
||||
return build.pipe(gulp.dest(config.scripts.destination));
|
||||
});
|
||||
|
||||
gulp.task('templates', function() {
|
||||
var pipeline;
|
||||
pipeline = gulp.src(config.templates.source).pipe(jade({
|
||||
pretty: !production
|
||||
})).on('error', handleError).pipe(gulp.dest(config.templates.destination));
|
||||
if (!production) {
|
||||
pipeline = pipeline.pipe(livereload({
|
||||
auto: false
|
||||
}));
|
||||
}
|
||||
return pipeline;
|
||||
});
|
||||
|
||||
gulp.task('styles', function() {
|
||||
var icons, styles;
|
||||
styles = gulp.src(config.styles.source).pipe(stylus({
|
||||
'include css': true
|
||||
}));
|
||||
icons = gulp.src(config.styles.icons).pipe(less());
|
||||
styles = es.merge(styles, icons).pipe(concat(config.styles.filename)).on('error', handleError).pipe(prefix('last 2 versions', 'Chrome 34', 'Firefox 28', 'iOS 7'));
|
||||
if (production) {
|
||||
styles = styles.pipe(CSSmin());
|
||||
}
|
||||
styles = styles.pipe(gulp.dest(config.styles.destination));
|
||||
if (!production) {
|
||||
styles = styles.pipe(livereload({
|
||||
auto: false
|
||||
}));
|
||||
}
|
||||
return styles;
|
||||
});
|
||||
|
||||
gulp.task('assets', function() {
|
||||
return gulp.src(config.assets.source).pipe(gulp.dest(config.assets.destination));
|
||||
});
|
||||
|
||||
gulp.task('server', function() {
|
||||
return require('http').createServer(ecstatic({
|
||||
root: path.join(__dirname, 'public')
|
||||
})).listen(9001);
|
||||
});
|
||||
|
||||
gulp.task('watch', function() {
|
||||
var bundle;
|
||||
livereload.listen();
|
||||
gulp.watch(config.templates.watch, ['templates']);
|
||||
gulp.watch(config.styles.watch, ['styles']);
|
||||
gulp.watch(config.assets.watch, ['assets']);
|
||||
bundle = watchify(browserify({
|
||||
entries: [config.scripts.source],
|
||||
extensions: config.scripts.extensions,
|
||||
debug: !production,
|
||||
cache: {},
|
||||
packageCache: {},
|
||||
fullPaths: true
|
||||
}));
|
||||
return bundle.on('update', function() {
|
||||
var build, start;
|
||||
gutil.log("Starting '" + (chalk.cyan('rebundle')) + "'...");
|
||||
start = process.hrtime();
|
||||
build = bundle.bundle().on('error', handleError).pipe(source(config.scripts.filename));
|
||||
build.pipe(gulp.dest(config.scripts.destination)).pipe(livereload());
|
||||
return gutil.log("Finished '" + (chalk.cyan('rebundle')) + "' after " + (chalk.magenta(prettyTime(process.hrtime(start)))));
|
||||
}).emit('update');
|
||||
});
|
||||
|
||||
gulp.task('no-js', ['templates', 'styles', 'assets']);
|
||||
|
||||
gulp.task('build', ['scripts', 'no-js']);
|
||||
|
||||
gulp.task('default', ['watch', 'no-js', 'server']);
|
||||
Reference in New Issue
Block a user