Last active
April 12, 2016 05:38
-
-
Save leongaban/7991924581eb3e35b86f to your computer and use it in GitHub Desktop.
gulpfile.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////////////////////////////////////////////////////////////// | |
/** | |
* @name Gulp taskrunner | |
* @desc Gulp taskrunner for TickerTags.dashboard | |
*/ | |
var gulp = require('gulp'), | |
gutil = require('gulp-util'), | |
gulpif = require('gulp-if'), | |
uglify = require('gulp-uglify'), | |
concat = require('gulp-concat'), | |
sass = require('gulp-ruby-sass'), | |
streamqueue = require('streamqueue'), | |
sourcemaps = require('gulp-sourcemaps'), | |
templateCache = require('gulp-angular-templatecache'), | |
htmlReplace = require('gulp-html-replace'), | |
runSequence = require('run-sequence'), | |
del = require('del'), | |
es = require('event-stream'); | |
var config = { | |
srcPartials:[ | |
'app/beta/*.html', | |
'app/header/**/*.html', | |
'app/help/*.html', | |
'app/login/*.html', | |
'app/notificaitons/*.html', | |
'app/panels/**/*.html', | |
'app/popovers/**/*.html', | |
'app/popovers/*.html', | |
'app/user/*.html', | |
'app/dashboard.html' | |
], | |
srcPaths:[ | |
'beta/', | |
'header/', | |
'help/', | |
'login/', | |
'notificaitons/', | |
'panels/', | |
'popovers/', | |
'popovers/', | |
'user/', | |
'dashboard.html' | |
], | |
destPartials: 'app/templates/' | |
}; | |
var paths = { | |
scripts: [ | |
'app/templates/*.js', | |
'app/authentication/*js', | |
'app/header/**/*.js', | |
'app/help/*js', | |
'app/helpers/*js', | |
'app/beta/*.js', | |
'app/login/*.js', | |
'app/notifications/*.js', | |
'app/panels/**/*.js', | |
'app/popovers/*.js', | |
'app/popovers/**/*.js', | |
'app/popovers/**/**/*.js', | |
'app/user/*.js', | |
'app/*.js'] | |
}; | |
var stxPaths = { | |
scripts: ['chartiq/js/stx.js', | |
'chartiq/js/stxThirdParty.js', | |
'chartiq/js/stxTimeZoneData.js', | |
'chartiq/js/stxKernelOs.js', | |
'chartiq/js/stxLibrary.js', | |
'chartiq/js/stxAdvanced.js'] | |
}; | |
// //////////////////////////////////////////////// | |
// Log Errors | |
// // ///////////////////////////////////////////// | |
function errorlog(err){ | |
console.log(err.message); | |
this.emit('end'); | |
} | |
/** Build Tasks */ | |
/** ------------------------------------------------------------------------- */ | |
//////////////////////////////////////////////////////////////////////////////// | |
// Clear out all files and folders from build folder: | |
gulp.task('build:cleanfolder', function(cb) { | |
del([ | |
'build/**' | |
], cb); | |
}); | |
// Task to create build directory for all files: | |
gulp.task('build:copy', ['build:cleanfolder'], function() { | |
return gulp.src('app/**') | |
.pipe(gulp.dest('build/')); | |
}); | |
// Task to remove unwated build files | |
// list all files and directories here that you don't want to include | |
gulp.task('build:remove', ['build:copy'], function(cb) { | |
del([ | |
'build/gus.html', | |
'build/authentication/', | |
'build/beta/*.js', | |
'build/header/**/*.js', | |
'build/help/*.js', | |
'build/helpers/', | |
'build/login/*.js', | |
'build/notifications/*.js', | |
'build/panels/**/*.js', | |
'build/popovers/**/*.js', | |
'build/popovers/*.js', | |
'build/user/*.js', | |
'build/app.js' | |
], cb); | |
}); | |
// 'build/js/!(*.min.js)' | |
// Task to make the index file production ready | |
gulp.task('build:index', function() { | |
gulp.src('app/index.html') | |
.pipe(htmlReplace({ | |
'stx-js': 'assets/js/libs/chartiq/stx.min.js', | |
'app-js': 'assets/js/app.min.js' | |
})) | |
.pipe(gulp.dest('build/')); | |
}); | |
gulp.task('build', function(cb) { | |
runSequence('build:copy', 'build:remove', 'build:index', cb); | |
}); | |
/** Main Gulp Tasks */ | |
/** ------------------------------------------------------------------------- */ | |
//////////////////////////////////////////////////////////////////////////////// | |
// App modules | |
gulp.task('app-js', function() { | |
return gulp.src(paths.scripts) | |
.pipe(uglify()) | |
.pipe(concat('app.min.js')) | |
.pipe(gulp.dest('app/assets/js')); | |
}); | |
// Chart IQ | |
gulp.task('stx-js', function() { | |
return gulp.src(stxPaths.scripts) | |
.pipe(uglify()) | |
.pipe(concat('stx.min.js')) | |
.pipe(gulp.dest('app/assets/js/libs/chartiq/')); | |
}); | |
/** HTML Template caching */ | |
/** ------------------------------------------------------------------------- */ | |
// gulp.src(["beta/*.html", "!beta/beta.html"], {base: "beta"}) | |
// return gulp.src(["app/*.html", "app/**/*.html", "app/**/**/*.html"], {base: "app"}) | |
// return gulp.src(config.srcPartials, {base: 'app'}) | |
gulp.task('html-templates', function() { | |
return gulp.src(config.srcPartials) | |
.pipe(templateCache('templateCache.js', { | |
root: updateRoot(config.srcPaths) | |
}, | |
{ module:'templateCache', standalone:true }) | |
).pipe(gulp.dest(config.destPartials)); | |
}); | |
function updateRoot(paths) { | |
for (var i = 0; i < paths.length; i++) { | |
// console.log(paths); | |
console.log(paths[i]); | |
return paths[i]; | |
} | |
} | |
/** Main Styles */ | |
/** ------------------------------------------------------------------------- */ | |
gulp.task('css', function() { | |
return sass('bower_components/sass-smacss/sass/dashboard.scss', { | |
// noCache: true, | |
style: 'compressed' | |
}) | |
.pipe(sourcemaps.init()) | |
.on('error', errorlog) | |
.pipe(sourcemaps.write('./maps')) | |
.pipe(gulp.dest('app/assets/css/')) | |
}); | |
/** ChartIQ Styles */ | |
/** ------------------------------------------------------------------------- */ | |
gulp.task('stx-css', function() { | |
return sass('chartiq/sass/stx.scss', { | |
// noCache: true, | |
style: 'compressed' | |
}) | |
.pipe(sourcemaps.init()) | |
.on('error', errorlog) | |
.pipe(sourcemaps.write('./maps')) | |
.pipe(gulp.dest('app/assets/css/chartiq/')) | |
}); | |
/** Development watch */ | |
/** ------------------------------------------------------------------------- */ | |
gulp.task('watch', function() { | |
gulp.watch('app/**/**/*.html', ['html-templates']).on('change', function(file) { | |
gutil.log(gutil.colors.yellow.bold('HTML updated' + ' (' + file.path + ')')); | |
}); | |
gulp.watch('app/assets/imgs/*.svg').on('change', function(file) { | |
gutil.log(gutil.colors.magenta('SVG updated' + ' (' + file.path + ')')); | |
}); | |
gulp.watch('chartiq/sass/*.scss', ['stx-css']).on('change', function(file) { | |
gutil.log(gutil.colors.cyan.bold('CSS updated' + ' (' + file.path + ')')); | |
}); | |
gulp.watch('bower_components/sass-smacss/sass/**/*.scss', ['css']).on('change', function(file) { | |
gutil.log(gutil.colors.cyan.bold('CSS updated' + ' (' + file.path + ')')); | |
}); | |
gulp.watch('chartiq/js/*.js', ['stx-js']).on('change', function(file) { | |
gutil.log(gutil.colors.red.bold('JavaScript updated' + ' (' + file.path + ')')); | |
}); | |
gulp.watch(paths.scripts, ['app-js']).on('change', function(file) { | |
gutil.log(gutil.colors.red.bold('JavaScript updated' + ' (' + file.path + ')')); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment