-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
164 lines (131 loc) · 4.79 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
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var es = require('event-stream');
var bowerFiles = require('main-bower-files');
var minify = require('gulp-minify-css');
// == SETTINGS ========
var moduleName = 'ps';
// == PATH STRINGS ========
var paths = {
scripts: './public/js/**/*.js',
styles: './public/scss/*.scss',
index: './public/index.html',
partials: ['./public/views/**/*.html', '!public/index.html'],
dist: './public.build',
scriptsServer: './app/**/*.js',
bowerDir: './public/libs/bootstrap-sass/assets/fonts'
};
// == PIPE SEGMENTS ========
var pipes = {};
pipes.orderedVendorScripts = function() {
return plugins.order(['jquery.js', 'angular.js']);
};
pipes.orderedAppScripts = function() {
return plugins.angularFilesort();
};
pipes.validatedAppScripts = function() {
return gulp.src(paths.scripts)
//.pipe(plugins.jshint())
//.pipe(plugins.jshint.reporter('jshint-stylish'))
.pipe(plugins.angularFilesort());
};
pipes.builtAppScripts = function() {
var scriptedPartials = pipes.scriptedPartials();
var validatedAppScripts = pipes.validatedAppScripts();
return es.merge(scriptedPartials, validatedAppScripts)
.pipe(pipes.orderedAppScripts())
.pipe(plugins.sourcemaps.init())
.pipe(plugins.concat('app.js'))
.pipe(plugins.sourcemaps.write())
.pipe(gulp.dest(paths.dist + '/js/'));
};
pipes.builtVendorStyles = function() {
return gulp.src(bowerFiles('**/*.css', {includeDev:true}))
.pipe(plugins.concat('vendor-styles.min.css'))
.pipe(minify())
.pipe(gulp.dest(paths.dist + '/css/'));
};
pipes.builtVendorScripts = function() {
return gulp.src(bowerFiles('**/*.js', {includeDev:true}))
.pipe(pipes.orderedVendorScripts())
.pipe(plugins.concat('vendor.min.js'))
.pipe(plugins.uglify())
.pipe(gulp.dest(paths.dist + '/js/'));
};
pipes.validatedServerScripts = function() {
return gulp.src(paths.scriptsServer)
.pipe(plugins.jshint())
.pipe(plugins.jshint.reporter('jshint-stylish'));
};
pipes.validatedPartials = function() {
return gulp.src(paths.partials)
.pipe(plugins.htmlhint({'doctype-first': false}))
.pipe(plugins.htmlhint.reporter());
};
pipes.scriptedPartials = function() {
return pipes.validatedPartials()
.pipe(plugins.htmlhint.failReporter())
.pipe(plugins.ngHtml2js({
moduleName: moduleName,
prefix: 'views/'
}));
};
pipes.builtStyles = function() {
return gulp.src(paths.styles)
.pipe(plugins.sass())
.pipe(gulp.dest(paths.dist + '/css/'));
};
pipes.validatedIndex = function() {
return gulp.src(paths.index)
.pipe(plugins.htmlhint())
.pipe(plugins.htmlhint.reporter());
};
pipes.builtIndex = function() {
var vendorScripts = pipes.builtVendorScripts();
var vendorStyles = pipes.builtVendorStyles();
var appScripts = pipes.builtAppScripts();
var appStyles = pipes.builtStyles();
return pipes.validatedIndex()
.pipe(gulp.dest(paths.dist)) // write first to get relative path for inject
.pipe(plugins.inject(vendorScripts, {relative: true, name: 'bower'}))
.pipe(plugins.inject(vendorStyles, {ignorePath: 'public.build/', name: 'bower'}))
.pipe(plugins.inject(appScripts, {relative: true}))
.pipe(plugins.inject(appStyles, {ignorePath: 'public.build/'}))
.pipe(gulp.dest(paths.dist));
};
pipes.builtApp = function() {
return es.merge(pipes.builtIndex());
};
// == TASKS ========
gulp.task('fonts', function() {
gulp.src(paths.bowerDir + '/**/*.*')
.pipe(gulp.dest(paths.dist + '/fonts/'));
});
gulp.task('validate-server-scripts', pipes.validatedServerScripts);
gulp.task('build-app', ['fonts'], pipes.builtApp);
gulp.task('watch', ['validate-server-scripts'], function() {
// start nodemon to auto-reload the dev server
plugins.nodemon({ script: 'server.js', ext: 'js', watch: ['server.js', 'app/routes.js'], env: {NODE_ENV : 'production'} })
.on('change', ['validate-server-scripts'])
.on('restart', function () {
console.log('[nodemon] restarted dev server');
});
plugins.livereload.listen({start: true});
gulp.watch(paths.index, function() {
return pipes.builtIndex()
.pipe(plugins.livereload());
});
gulp.watch(paths.scripts, function() {
return pipes.builtAppScripts()
.pipe(plugins.livereload());
});
gulp.watch(paths.partials, function() {
return pipes.builtAppScripts()
.pipe(plugins.livereload());
});
gulp.watch(paths.styles, function() {
return pipes.builtStyles()
.pipe(plugins.livereload());
});
});
gulp.task('default', ['build-app', 'watch']);