var
/** Modules */
gulp = require('gulp'),
gutil = require('gulp-util'),
include = require('gulp-include'),
connect = require('gulp-connect'),
coffee = require('gulp-coffee'),
rename = require('gulp-rename'),
htmlify = require('gulp-angular-htmlify'),
templateCache = require('gulp-angular-templatecache'),
/** Constants */
mainModule = 'app',
/** Paths */
appDir = './app/',
distDir = './dist/',
appScriptsDir = appDir + 'scripts/',
appScriptsFiles = appScriptsDir + '**/*js',
coffeeDir = appDir + 'coffee/modules/**/',
viewsGlob = [appDir + 'views/**/*.html'];
gulp.task('coffee', function () {
return gulp.src(coffeeDir + 'main.coffee')
.pipe(include())
.pipe(coffee({bare: true}).on('error', gutil.log))
.pipe(rename(function (path) {
path.basename = '../' + path.dirname;
}))
.pipe(gulp.dest(appScriptsDir + 'modules/'));
});
gulp.task('views', function () {
return gulp.src(viewsGlob)
.pipe(htmlify())
.pipe(templateCache({
module: mainModule,
root: 'views'
}))
.pipe(gulp.dest(appScriptsDir));
});
gulp.task('build', ['views', 'coffee']);
gulp.task('connect', function () {
return connect.server({
root: appDir,
livereload: true
});
});
gulp.task('reload', function () {
gulp.src(appScriptsFiles)
.pipe(connect.reload());
});
gulp.task('watch', function () {
gulp.watch(viewsGlob, ['views']);
gulp.watch(coffeeDir + '*.coffee', ['coffee']);
gulp.watch(appScriptsFiles, ['reload']);
});
/** For dist */
gulp.task('usemin', function () {
var
usemin = require('gulp-usemin'),
uglify = require('gulp-uglify'),
replace = require('gulp-replace'),
minifyCss = require('gulp-minify-css'),
minifyHtml = require('gulp-minify-html');
gulp.src(appDir + '*.html')
.pipe(usemin({
css: [minifyCss(), 'concat'],
html: [minifyHtml({empty: true})],
js: [uglify({mangle: false}), replace('api.pms.dev', 'terrapms.cloudapp.net')]
}))
.pipe(gulp.dest(distDir));
});
gulp.task('copy-to-dist', function () {
gulp.src([appDir + 'fonts/*', appDir + 'img/*'], {base: appDir}).pipe(gulp.dest(distDir));
gulp.src(appDir + '/vendors/ckeditor/**/*', {base: appDir}).pipe(gulp.dest(distDir));
});
gulp.task('build-dist', ['usemin', 'copy-to-dist']);
gulp.task('connect-dist', function () {
return connect.server({
port: 8080,
root: distDir
});
});
gulp.task('test', function () {
var casperJs = require('gulp-casperjs');
//var s = gulp.src('test/specs/**/*')
//var s = gulp.src('test/specs/accounts/*')
var s = gulp.src('test/specs/users/*')
.pipe(casperJs());
s.on('error', console.error.bind(console));
return s;
});
gulp.task('default', ['build', 'connect', 'watch']);