Skip to content

Instantly share code, notes, and snippets.

@Kashkovsky
Created June 15, 2016 23:30
Show Gist options
  • Save Kashkovsky/8e22a003a43d0def975108e35d0e000e to your computer and use it in GitHub Desktop.
Save Kashkovsky/8e22a003a43d0def975108e35d0e000e to your computer and use it in GitHub Desktop.
Common gulpfile
var lr = require('tiny-lr'),
gulp = require('gulp'),
nib = require('nib'),
jade = require('gulp-jade'),
stylus = require('gulp-stylus'),
livereload = require('gulp-livereload'),
myth = require('gulp-myth'),
csso = require('gulp-csso'),
imagemin = require('gulp-imagemin'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
sourcemaps = require('gulp-sourcemaps'),
connect = require('gulp-connect'),
insert = require('gulp-insert'),
uglify = require('gulp-uglify'),
resolveDependencies = require('gulp-resolve-dependencies')
server = lr();
var comment = '/*\n' +
'* An Angular module for token based authentication *\n' +
'* @version v0.0.1 - 2016-06-16 *\n' +
'* @link https://github.com/Mr-Zoidberg/ngAuthenticate *\n' +
'* @author Dan Kashkovsky <[email protected]> *\n' +
'* @license MIT License, http://www.opensource.org/licenses/MIT *\n' +
'*/ \n';
//init stylus
gulp.task('stylus', function() {
gulp.src('./assets/stylus/screen.styl')
.pipe(stylus({
use: ['nib']
}))
.on('error', console.log)
.pipe(myth())
.pipe(gulp.dest('./src/css/'))
.pipe(connect.reload());
});
//create local server
gulp.task('http-server', function() {
connect
.server({
port: 89898,
root: './src/',
livereload: true
});
});
gulp.task('http-server-close', function() {
connect.serverClose();
});
gulp.task('jade', function() {
gulp.src(['./assets/template/*.jade', '!./assets/template/_*.jade'])
.pipe(jade({
pretty: true
}))
.on('error', console.log)
.pipe(gulp.dest('./src/'))
.pipe(connect.reload());
});
// compile JS
gulp.task('min-js', function() {
gulp.src(['./src/js/app.js', './src/js/interceptor.js', './src/js/service.js', './src/js/directive.js', './src/js/config.js', '!./assets/js/vendor/*.js', '!./assets/js/vendor/**/*.js'])
.pipe(resolveDependencies({
pattern: /\* @requires [\s-]*(.*\.js)/g
}))
.on('error', function(err) {
console.log(err.message);
})
.pipe(concat('angular-authenticate.min.js'))
.pipe(insert.wrap('(function(){ "use strict", ', '})();'))
.pipe(insert.transform(function (contents) {
return comment + contents;
}))
.pipe(uglify({
preserveComments: 'all'
}))
.pipe(gulp.dest('./build/minified'))
.pipe(connect.reload());
});
gulp.task('js', ['min-js'], function() {
gulp.src(['./src/js/app.js', './src/js/interceptor.js', './src/js/service.js', './src/js/directive.js', './src/js/config.js', '!./assets/js/vendor/*.js', '!./assets/js/vendor/**/*.js'])
.pipe(resolveDependencies({
pattern: /\* @requires [\s-]*(.*\.js)/g
}))
.on('error', function(err) {
console.log(err.message);
})
.pipe(concat('angular-authenticate.js', {newLine: '\r\n'}))
.pipe(insert.wrap('(function(){ "use strict", ', '})();'))
.pipe(insert.transform(function (contents) {
return comment + contents;
}))
.pipe(gulp.dest('./build/unminified'))
.pipe(connect.reload());
});
gulp.task('images', function() {
gulp.src('./assets/img/**/*')
.pipe(imagemin())
.pipe(gulp.dest('./src/img'))
.pipe(connect.reload());
});
gulp.task('watch', ['stylus', 'jade', 'images', 'js', 'http-server'], function() {
gulp.watch('assets/stylus/**/*.styl', function() {
gulp.run('stylus');
});
gulp.watch('assets/template/**/*.jade', function() {
gulp.run('jade');
});
gulp.watch('assets/img/**/*', function() {
gulp.run('images');
});
gulp.watch('./src/js/*', function() {
gulp.run('js');
});
});
gulp.task('build', function() {
// css
gulp.src('./assets/stylus/screen.styl')
.pipe(stylus({
use: ['nib']
}))
.pipe(myth())
.pipe(csso())
.pipe(gulp.dest('./build/css/'));
// jade
gulp.src(['./assets/template/*.jade', '!./assets/template/_*.jade'])
.pipe(jade())
.pipe(gulp.dest('./build/'))
// js
gulp.src(['./assets/js/**/*.js', '!./assets/js/vendor/**/*.js'])
.pipe(concat('angular-authenticate.js'))
.pipe(uglify())
.pipe(gulp.dest('./build/js'));
// image
gulp.src('./assets/img/**/*')
.pipe(imagemin())
.pipe(gulp.dest('./build/img'))
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment