-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
138 lines (116 loc) · 5.4 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
var gulp = require('gulp'),
minifycss = require('gulp-minify-css'), // for minifying the css
concat = require('gulp-concat'), // concatinating the resources both js and css
uglify = require('gulp-uglify'), // minifying the js files. triggered only in 'deploy' task below
clean = require('gulp-clean'), // removing files from a directory
jshint = require('gulp-jshint'), // check the validity of js files
stylish = require('jshint-stylish'), // to display the jshint messages in a human readable format with line number and file name
templateCache = require('gulp-angular-templatecache'), // to cache angular.js templates
htmlmin = require('gulp-htmlmin'), // to minify html templates
ngmin = require('gulp-ng-annotate'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer');
rename = require('gulp-rename');
// Setting up the js, css, fonts, templates and images src n destination directories.
// Follows ng-boilerplate directory structure by default.
// Change the variables below to suit for project needs.
var options = new function() {
this.PARTIALS_SRC = 'assets/js/**/*.tpl',
this.ANGULAR_MODULE_NAME = 'app',
this.FONTS_SRC = 'assets/fonts/**/*',
this.IMAGES_SRC = 'assets/images/**/*',
this.JS_SRC_DEV = ['assets/libs/js/**/*.js', 'assets/js/app.js', 'assets/js/**/*.js', 'assets/profiles/dev/**/*.js'],
this.JS_SRC_PROD = ['assets/libs/js/**/*.js', 'assets/js/app.js', 'assets/js/**/*.js', 'assets/profiles/prod/**/*.js'], // ,'assets/profiles/dev/*.js' 0 index must be vendor libs for convention sake
this.CSS_SRC = ['assets/libs/css/**/*.css', 'assets/css/**/*.css'], // 0 index must be vendor libs for convention sake
this.SASS_SRC = ['app/sass/**/*.sass', 'app/sass/**/*.scss'],
//this.DIST_SRC = '.tmp/public/includes/', // specific to sails-starter-project. change to suit your project needs.
this.DIST_SRC = 'assets/includes/',
this.PARTIALS_DEST = 'assets/templates',
this.FONTS_DEST = this.DIST_SRC + '/fonts',
this.IMAGES_DEST = this.DIST_SRC + '/images',
this.JS_DEST = this.DIST_SRC + '/js',
this.CSS_DEST = this.DIST_SRC + '/css',
this.JS_DEST_NAME = 'app.min.js',
this.CSS_DEST_NAME = 'app.min.css',
this.TEMPLATES_DEST_NAME = 'templates.js'
};
gulp.task('template-cache', function () {
return gulp.src(options.PARTIALS_SRC)
.pipe(htmlmin({collapseWhitespace: true, removeComments: true}))
.pipe(templateCache(options.TEMPLATES_DEST_NAME, {standalone: true}))
.pipe(gulp.dest(options.PARTIALS_DEST));
});
gulp.task('fonts', function() {
return gulp.src(options.FONTS_SRC)
.pipe(gulp.dest(options.FONTS_DEST));
});
gulp.task('imgs', function() {
return gulp.src(options.IMAGES_SRC)
.pipe(gulp.dest(options.IMAGES_DEST));
});
gulp.task('jshint', function() {
return gulp.src(options.JS_SRC_DEV.concat( '!' + options.JS_SRC_DEV[0] ) // excluding vendor libs from lint checking
.concat( '!' + options.PARTIALS_DEST + '/**/*.js')) // excluding angular templates from lint checking
.pipe(jshint( {globals:{angular: true}} )) // adding angular to global scope to avoid angular not found errors in lint
.pipe(jshint.reporter(stylish));
});
gulp.task('js', ['jshint', 'template-cache', 'uglify'], function() {
return gulp.src(options.JS_SRC_PROD)
.pipe(ngmin())
.pipe(uglify())
.pipe(concat('app.min.js'))
.pipe(gulp.dest(options.JS_DEST));
});
// not minifying the files for debugging purposes.
gulp.task('js-dev', ['jshint', 'template-cache'], function() {
return gulp.src(options.JS_SRC_DEV)
.pipe(concat(options.JS_DEST_NAME))
.pipe(gulp.dest(options.JS_DEST));
});
gulp.task('compile-sass', function () {
var stream = gulp.src(options.SASS_SRC) // path to your file
.pipe(concat('app.all.scss'))
.pipe(sass())
.pipe(gulp.dest('app/css/sass'));
return stream;
});
gulp.task('css', ['compile-sass'], function() {
return gulp.src(options.CSS_SRC)
.pipe(concat(options.CSS_DEST_NAME))
.pipe(autoprefixer({ browsers: ['last 2 versions'], cascade: false }))
.pipe(minifycss())
.pipe(gulp.dest(options.CSS_DEST));
});
// not minifying the files for debugging purposes.
gulp.task('uglify', function() {
return gulp.src(options.JS_SRC_PROD)
.pipe(concat(options.JS_DEST_NAME))
.pipe(uglify({mangle: false}))
.pipe(gulp.dest(options.JS_DEST));
});
gulp.task('css-dev', ['compile-sass'], function() {
return gulp.src(options.CSS_SRC)
.pipe(concat(options.CSS_DEST_NAME))
.pipe(autoprefixer({ cascade: false }))
.pipe(gulp.dest(options.CSS_DEST));
});
gulp.task('clean', function() {
return gulp.src([options.DIST_SRC + '/*']
.concat(options.PARTIALS_DEST + '/*'), {read: false})
.pipe(clean( {force: true} ));
});
gulp.task('deploy', ['fonts', 'imgs', 'js', 'css']);
gulp.task('default', ['fonts', 'imgs', 'js-dev', 'css-dev'], function() {
gulp.watch(options.FONTS_SRC, ['fonts']);
gulp.watch(options.IMAGES_SRC, ['imgs']);
gulp.watch(options.JS_SRC_DEV, ['js-dev']);
gulp.watch(options.CSS_SRC.concat(options.SASS_SRC), ['css-dev']);
gulp.watch(options.PARTIALS_SRC, ['template-cache']);
});
// gulp.task('prod', ['fonts', 'imgs', 'js', 'css'], function() {
// gulp.watch(options.FONTS_SRC, ['fonts']);
// gulp.watch(options.IMAGES_SRC, ['imgs']);
// gulp.watch(options.JS_SRC_PROD, ['js']);
// gulp.watch(options.CSS_SRC.concat(options.SASS_SRC), ['css']);
// gulp.watch(options.PARTIALS_SRC, ['template-cache']);
// });