-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
200 lines (146 loc) · 4.12 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
197
198
199
200
'use strict';
var gulp = require('gulp');
var rename = require('gulp-rename');
var jshint = require('gulp-jshint');
var inject = require('gulp-inject');
var clean = require('gulp-clean');
var series = require('stream-series');
var sass = require('gulp-sass');
var nodemon = require('gulp-nodemon');
var jsdoc = require('gulp-jsdoc3');
// --- Environment ---
var envs = {
dev: 'dev',
prod: 'prod'
};
var environment = process.env.ENVIRONMENT || envs.dev;
// --- Paths ---
var paths = {
jshintPaths: ['public/js/**/*.js'],
jsdocPaths: ['README.md', 'app/**/*.js']
};
var sources = {
appjs: 'public/js/app.js',
angularFiles: ['public/js/**/*'],
configDev: 'config/config.dev.js',
configProd: 'config/config.prod.js',
env: '.env',
files: 'public/files/*',
index: 'public/index.html',
injectedJs: ['public/js/**/*.js', '!public/js/app.js'],
libs: 'public/libs/**/*',
node: ['app/**/*'],
passportConfig: './config/passport.js',
sass: 'public/sass/**/*.scss',
server: 'server.js',
views: 'public/views/**/*'
};
var dest = {
config: 'dist/config',
configName: 'config.js',
css: 'dist/public/css',
dist: 'dist/',
env: 'dist',
files: 'dist/public/files',
angularFiles: 'dist/public/js',
libs: 'dist/public/libs',
node: 'dist/app',
public: 'dist/public',
views: 'dist/public/views'
};
// -------------
// --- Testing, Linting, Etc ---
//Run jshint on our javascript files
gulp.task('jshint', function(){
return gulp.src(paths.jshintPaths)
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
gulp.task('doc', function (cb) {
gulp.src(paths.jsdocPaths, {read: false})
.pipe(jsdoc(cb));
});
// -----------------------------
// --- Move Tasks ---
gulp.task('libs', function(){
return gulp.src(sources.libs)
.pipe(gulp.dest(dest.libs));
});
gulp.task('views', function(){
return gulp.src(sources.views)
.pipe(gulp.dest(dest.views));
});
gulp.task('server', function(){
return gulp.src(sources.server)
.pipe(gulp.dest(dest.dist));
});
gulp.task('node', function(){
return gulp.src(sources.node)
.pipe(gulp.dest(dest.node));
});
gulp.task('angularFiles', function(){
return gulp.src(sources.angularFiles)
.pipe(gulp.dest(dest.angularFiles));
});
gulp.task('files', function(){
return gulp.src(sources.files)
.pipe(gulp.dest(dest.files));
});
//Move env file
gulp.task('env', function(){
return gulp.src(sources.env)
.pipe(gulp.dest(dest.env));
});
gulp.task('config', function(){
var src;
if(environment === envs.dev){
src = sources.configDev;
} else if(environment === envs.prod){
src = sources.configProd;
} else {
console.error('Unknown environment');
}
return gulp.src(src)
.pipe(rename(dest.configName))
.pipe(gulp.dest(dest.config));
});
gulp.task('config-passport', function(){
return gulp.src(sources.passportConfig)
.pipe(gulp.dest(dest.config));
});
gulp.task('move', ['libs', 'views', 'server', 'angularFiles', 'node', 'env',
'files', 'config', 'config-passport']);
// ------------------
// --- Compilation Tasks ---
//Set up index.html, injecting required js files
gulp.task('index', function(){
return gulp.src(sources.index)
.pipe(inject(series(
gulp.src(sources.injectedJs, {read:false}),
gulp.src(sources.appjs, {read:false}) ),
{relative:true}))
.pipe(gulp.dest(dest.public));
});
gulp.task('sass', function(){
return gulp.src(sources.sass)
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest(dest.css));
});
gulp.task('compile', ['index', 'sass']);
// -------------------------
gulp.task('build', ['compile', 'move']);
gulp.task('clean', function(){
return gulp.src(dest.dist)
.pipe(clean());
});
gulp.task('default', ['jshint', 'build']);
gulp.task('watch', function() {
gulp.watch(sources.sass, ['sass']);
gulp.watch(sources.server, ['server']);
gulp.watch(sources.angularFiles, ['angularFiles']);
});
gulp.task('dev', ['watch'], function(){
nodemon({
script: 'dist/server.js'
});
});