Skip to content

Instantly share code, notes, and snippets.

@hyrmn
Last active August 29, 2015 14:08
Show Gist options
  • Save hyrmn/1c61abc119f21095019b to your computer and use it in GitHub Desktop.
Save hyrmn/1c61abc119f21095019b to your computer and use it in GitHub Desktop.
var gulp = require('gulp'),
gulpif = require('gulp-if'),
less = require('gulp-less'),
autoprefixer = require('gulp-autoprefixer'),
minifycss = require('gulp-minify-css'),
rename = require('gulp-rename'),
clean = require('gulp-clean'),
runSequence = require('run-sequence'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
templateCache = require('gulp-angular-templatecache'),
notify = require('gulp-notify'),
replace = require('gulp-replace'),
insert = require('gulp-insert'),
shell = require('gulp-shell'),
plumber = require('gulp-plumber'),
utf8BOM = String.fromCharCode(65279);
/*
jshint = require('gulp-jshint'),
*/
var paths = {
appScripts: [
'client/common/**/*.js',
'client/app/app.js',
'client/app/**/*.js'
],
libScripts: [
'client/lib/codemirror/*.js',
'client/lib/bootstrap/*.js',
'client/lib/extras/**/*.js',
'client/lib/theme/**/*.js',
'!client/**/*.min.js'
],
templates: 'client/app/**/*.html',
stylesheets: [
'./assets/css/frameworks/*.*',
'assets/css/lib/*.*',
'assets/css/app/*.*'
],
stylesheetImages: 'assets/css/app/img/**/*.*',
stylesheetLibImages: 'assets/css/lib/img/**/*.*',
staticFiles: [
'assets/fonts/**/*.*',
'assets/img/**/*.*',
],
editorFiles: [
'client/lib/ckeditor/dev/builder/release/ckeditor/**/*.js',
'client/lib/ckeditor/dev/builder/release/ckeditor/**/*.css',
'client/lib/ckeditor/dev/builder/release/ckeditor/**/*.png'
]
};
var onError = function(err) {
console.log.bind(console, '\007');
console.log(err);
}
gulp.task('build-styles', [], function() {
return gulp.src(paths.stylesheets)
.pipe(plumber({errorHandler: onError}))
.pipe(replace(utf8BOM, ''))
.pipe(gulpif(/[.]less$/, less({ style: 'expanded' })))
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(concat('all.css'))
.pipe(gulp.dest('dist/assets/css'))
.pipe(minifycss())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('dist/assets/css'));
});
gulp.task('copy-static-files', [], function() {
//copy static files over.
return gulp.src(paths.staticFiles, { base: 'assets/' })
.pipe(plumber({errorHandler: onError}))
.pipe(gulp.dest('dist/assets'));
});
gulp.task('copy-css-image-files', [], function () {
//copy css app img folders in
return gulp.src(paths.stylesheetImages, { base: 'assets/css/app/' })
.pipe(plumber({errorHandler: onError}))
.pipe(gulp.dest('dist/assets/css/'));
});
gulp.task('copy-css-lib-image-files', [], function () {
//copy css lib img folders in
return gulp.src(paths.stylesheetLibImages, { base: 'assets/css/lib/' })
.pipe(plumber({errorHandler: onError}))
.pipe(gulp.dest('dist/assets/css/'));
});
gulp.task('styles', ['build-styles', 'copy-static-files', 'copy-css-image-files', 'copy-css-lib-image-files']);
gulp.task('build-app', [], function () {
//our app js
return gulp.src(paths.appScripts)
.pipe(plumber({errorHandler: onError}))
//.pipe(jshint())
//.pipe(jshint.reporter('default'))
.pipe(replace(utf8BOM, ''))
.pipe(concat('app.js'))
.pipe(insert.wrap('(function () {"use strict";', '})();'))
.pipe(gulp.dest('dist/client'))
.pipe(uglify())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('dist/client'));
});
gulp.task('build-lib', [], function() {
//3rd party library js
return gulp.src(paths.libScripts)
.pipe(plumber({errorHandler: onError}))
//.pipe(jshint())
//.pipe(jshint.reporter('default'))
.pipe(replace(utf8BOM, ''))
.pipe(concat('lib.js'))
.pipe(gulp.dest('dist/client'))
.pipe(uglify())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('dist/client'));
});
gulp.task('build-templates', [], function() {
//angular templates
return gulp.src(paths.templates)
.pipe(plumber({errorHandler: onError}))
.pipe(replace(utf8BOM, ''))
.pipe(templateCache('templates.js', { root: 'client/app/', module: 'rsPms' }))
.pipe(gulp.dest('dist/client'))
.pipe(uglify())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('dist/client'));
});
gulp.task('copy-editor-files', [], function () {
//copy ckeditor over.
return gulp.src(paths.editorFiles, { base: 'client/lib/ckeditor/dev/builder/release/' })
.pipe(plumber({errorHandler: onError}))
.pipe(gulp.dest('dist/client/lib/'));
});
gulp.task('scripts', ['build-app', 'build-lib', 'build-templates', 'copy-editor-files']);
gulp.task('watch', function() {
var styleWatcher = gulp.watch('assets/css/**/*.{css,less}', ['styles']);
styleWatcher.on('change', function (event) {
var time = new Date();
console.log(time.toLocaleTimeString() + ' - Style File ' + event.path + ' was ' + event.type);
});
var appScriptWatcher = gulp.watch(paths.appScripts, ['build-app']);
appScriptWatcher.on('change', function (event) {
var time = new Date();
console.log(time.toLocaleTimeString() + ' - App Script File ' + event.path + ' was ' + event.type);
});
var libScriptWatcher = gulp.watch(paths.libScripts, ['build-lib']);
libScriptWatcher.on('change', function (event) {
var time = new Date();
console.log(time.toLocaleTimeString() + ' - Lib Script File ' + event.path + ' was ' + event.type);
});
var tmplScriptWatcher = gulp.watch(paths.templates, ['build-templates']);
tmplScriptWatcher.on('change', function (event) {
var time = new Date();
console.log(time.toLocaleTimeString() + ' - Template File ' + event.path + ' was ' + event.type);
});
});
gulp.task('clean', function() {
return gulp.src('dist', { read: false })
.pipe(clean());
});
gulp.task('default', function(callback) {
return runSequence('clean',
'scripts',
'styles',
callback);
});
REM Note the "call" is important here for the "npm install" command. see https://github.com/npm/npm/issues/2938
REM Change current directory to the RezStream root
pushd "..\..\.."
call npm install
REM Revert back to original directory
popd
node "%~dp0..\..\..\node_modules\gulp\bin\gulp.js" --gulpfile "%~dp0gulpfile.js"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment