forked from dropbox/nsot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
166 lines (138 loc) · 4.15 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
/**
* Build file for NSoT's Frontend dependencies.
*
* Build tasks are broken up as either top-level tasks, for example `build`,
* or sub-tasks, namespaced with a top-level task name and a color as a prefix,
* for example, `build:js`
*
* You'll likely want to have gulp installed globally if you're using it regularly
* though you'll be able to run it fron `node_modules/.bin/gulp` if you don't
* use it often.
*
* Top Level Tasks
* ---------------
* gulp clean - Remove built assets
* gulp build - Build all static assets for distribution
* gulp lint - Lint JavaScript and CSS files
* gulp bower - Update local cache for web dependencies
*/
var gulp = require('gulp');
// Plugin Imports
var jshint = require('gulp-jshint');
var concat = require('gulp-concat');
var ngAnnotate = require('gulp-ng-annotate');
var templateCache = require('gulp-angular-templatecache');
var addStream = require('add-stream');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var minifyCss = require('gulp-minify-css');
var csslint = require('gulp-csslint');
var mainBowerFiles = require('main-bower-files');
var bower = require('gulp-bower');
var sort = require('gulp-sort');
var del = require('del');
var SRC_ROOT = './nsot/static/src/';
var BUILD_DEST = './nsot/static/build/';
var JS_SRC = SRC_ROOT + 'js/**/*.js';
var STYLE_SRC = SRC_ROOT + 'style/**/*.css';
var TEMPLATE_SRC = SRC_ROOT + 'templates/**/*.html';
var IMAGE_SRC = SRC_ROOT + 'images/**';
/**
* Task to lint JavaScript files.
*/
gulp.task('lint:js', function() {
return gulp.src(JS_SRC)
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});
/**
* Task to lint CSS files.
*/
gulp.task('lint:style', function() {
return gulp.src(STYLE_SRC)
.pipe(csslint())
.pipe(csslint.reporter());
});
/**
* Top level Task to run all lint tasks.
*/
gulp.task('lint', ['lint:js', 'lint:style']);
/**
* Updates the local cache of bower dependencies
*/
gulp.task('bower', function() {
return bower({ cmd: 'update'});
});
/**
* Finds angular templates and compiles them to JavaScript
* To be included in another stream.
*/
function buildTemplateJs() {
return gulp.src(TEMPLATE_SRC)
.pipe(templateCache('compiled-templates.js', {
module: 'nsotTemplates'
}));
}
/**
* Task to build JavaScript files.
*/
gulp.task('build:js', function() {
return gulp.src(JS_SRC)
.pipe(ngAnnotate())
.pipe(addStream.obj(buildTemplateJs()))
.pipe(sort())
.pipe(concat('app.js'))
.pipe(gulp.dest((BUILD_DEST + 'js')))
.pipe(uglify())
.pipe(rename('app.min.js'))
.pipe(gulp.dest((BUILD_DEST + 'js')));
});
/**
* Task to build CSS files.
*/
gulp.task('build:style', function() {
return gulp.src(STYLE_SRC)
.pipe(sort())
.pipe(concat('nsot.css'))
.pipe(gulp.dest((BUILD_DEST + 'style')))
.pipe(minifyCss())
.pipe(rename('nsot.min.css'))
.pipe(gulp.dest((BUILD_DEST + 'style')));
});
/**
* Task to "build" images. While we're not doing anything interesting
* now this opens up the option for building sprites if needed. This
* also keeps our src separate from our build where we'll do things like
* hash built files eventually.
*/
gulp.task('build:images', function() {
return gulp.src(IMAGE_SRC)
.pipe(gulp.dest((BUILD_DEST + 'images')))
});
/**
* Uses bower to install the "main" files into our build. In most cases
* the "main" files are manually specified in the `overrides` section
* of bower.json
*/
gulp.task('build:3rdparty', ['bower'], function() {
return gulp.src(mainBowerFiles(), {base: '_bc'})
.pipe(gulp.dest(BUILD_DEST + 'vendor'))
});
/**
* Create a hashed version of all built files. This is currently
* just a placeholder and hasn't been finished yet.
*/
gulp.task('build:revisions', ['build:js', 'build:style', 'build:images', 'build:3rdparty'], function() {
// TODO(gary): Do.
return gulp.src(BUILD_DEST);
});
/**
* Super task to build everything.
*/
gulp.task('build', ['build:revisions']);
/**
* Remove the build directory
*/
gulp.task('clean', function(cb) {
del([BUILD_DEST], cb);
});