-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
196 lines (165 loc) · 4.24 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
'use strict'
// Load gulp
var gulp = require('gulp');
// Modules container
var $ = {};
// Modules declaration
var modules = {
concat : 'gulp-concat',
del : 'del',
sass : 'gulp-ruby-sass',
rename : 'gulp-rename',
annotate : 'gulp-ng-annotate',
minify_css : 'gulp-minify-css',
version : 'gulp-rev',
uglify : 'gulp-uglify',
autoprefix : 'gulp-autoprefixer',
jshint : 'gulp-jshint',
size : 'gulp-size',
browserSync: 'browser-sync'
};
// Load all modules into modules container
for(var key in modules) {
if (modules.hasOwnProperty(key)) {
$[key] = require(modules[key]);
}
}
///////////////
// Constants //
///////////////
var PATH = {};
// Temporary folder
PATH.temp = 'temp';
// Source
PATH.src = {
css: 'src/content/css',
img: 'src/content/img',
js: 'src/content/js',
sass: 'src/content/sass',
content: 'src/content',
views: 'src/app/views',
appRoot: 'src/app',
root: 'src'
};
// Public
PATH['public'] = {
css: 'public/content/css',
img: 'public/content/img',
js: 'public/content/js',
sass: 'public/content/sass',
content: 'public/content',
root: 'public'
};
///////////////////////
// DEVELOPMENT TASKS //
///////////////////////
/////////////
// Scripts //
/////////////
/**
* Concatenates all bower dependencies in components folder
*/
gulp.task('vendor', function(){
// List of all dependencies
var dependencies = [
'bower_components/jquery/dist/jquery.js',
'bower_components/angular/angular.js',
'bower_components/angular-animate/angular-animate.js',
'bower_components/angular-cookies/angular-cookies.js',
'bower_components/angular-resource/angular-resource.js',
'bower_components/angular-route/angular-route.js',
'bower_components/angular-bootstrap/ui-bootstrap.js',
'bower_components/angular-bootstrap/ui-bootstrap-tpls.js'
];
return gulp.src(dependencies)
.pipe($.concat('vendor.js'))
.pipe(gulp.dest(PATH['public'].root));
});
/**
* Concatenates all application scripts in assets/js folder
*/
gulp.task('script', function(){
return gulp.src([
'src/app/app.js',
'src/app/**/*.js'
])
.pipe($.annotate({'single_quotes': true}))
.pipe($.jshint())
.pipe($.concat('all.js'))
.pipe(gulp.dest(PATH['public'].root));
});
////////////
// Styles //
////////////
/**
* Compile style
*/
gulp.task('style', function() {
return gulp.src(PATH.src.sass + '/main.sass')
.pipe($.sass({
'style': 'expanded',
'sourcemap=none': true,
'container':'gulp-ruby-sass'
}))
.pipe($.autoprefix('last 2 versions', '> 1%', 'ie 8'))
.pipe($.size({title: 'CSS: '}))
.pipe(gulp.dest(PATH['public'].root));
});
///////////
// VIEWS //
///////////
/**
* Move views files from src to public
*/
gulp.task('views', function(){
return gulp.src('src/app/views/**/*.html')
.pipe(gulp.dest('public/views'));
});
///////////
// INDEX //
///////////
/**
* Injects dependencies and save file into public
*/
gulp.task('index', ['vendor', 'script', 'style'], function () {
// Move index to puvlic location
return gulp.src(PATH.src.appRoot + '/index.html')
.pipe(gulp.dest(PATH['public'].root));
});
//////////////
// Cleaners //
//////////////
/*
* not in use at the moment, useful with Inject
*/
gulp.task('clean:index', function(cb){
return $.del([PATH['public'].root + '/index.html'], cb);
});
//////////////////
// Browser Sync //
//////////////////
gulp.task('serve', function (cb) {
$.browserSync({
files: ['public/**/*.{js,css,html}'],
port: 8001,
notify: true,
server: {
baseDir: './public',
index: 'index.html'
}
}, cb)
});
///////////////
// MAIN TASK //
///////////////
/**
* Sets watchers and triggers appropriate tasks
*/
gulp.task('default', ['index', 'serve'], function() {
// Watch for scripts changes
gulp.watch('src/app/views/**/*.html', ['views']);
// Watch for scripts changes
gulp.watch('src/app/**/*.js', ['script']);
// Watch for SASS changes
gulp.watch([PATH.src.sass + '**/*.sass'], ['style']);
});