forked from ThirstyHead/meaningfuljs2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
202 lines (176 loc) · 5.63 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
201
202
'use strict';
// Load Node Modules/Plugins
let config = require('./gulpfile-config');
let gulp = require('gulp-help')(require('gulp'));
let gulpPlugin = require('gulp-load-plugins')({lazy: true});
let del = require('del');
let browserSync = require('browser-sync');
let merge = require('merge-stream');
//NOTE: this hides tasks from 'gulp help' console output,
// but leaves them runnable as dependent tasks
let hideFromTaskList = false;
/**
* Default task
*/
gulp.task('default',
'*** Default task ***',
['help']);
/**
* Builds runnable app
*/
gulp.task('build',
'Builds runnable app (dev-mode)',
['build-html', 'build-js', 'build-css', 'build-img', 'build-bower'],
() => {
});
/**
* Builds Bower Components
*/
gulp.task('build-bower',
hideFromTaskList,
() => {
return gulp.src(config.src.bower)
.pipe(gulp.dest(`${config.dir.build}/bower_components`));
});
/**
* Builds CSS
*/
gulp.task('build-css',
hideFromTaskList,
() => {
return gulp.src(config.src.css)
.pipe(gulp.dest(config.dir.build));
});
/**
* Builds HTML
*/
gulp.task('build-html',
hideFromTaskList,
() => {
return gulp.src(config.src.html)
.pipe(gulp.dest(config.dir.build));
});
/**
* Builds HTML
*/
gulp.task('build-img',
hideFromTaskList,
() => {
return gulp.src(config.src.img)
.pipe(gulp.dest(config.dir.build));
});
/**
* Builds JavaScript
*/
gulp.task('build-js',
hideFromTaskList,
() => {
// copy all app js, config.js, and jspm_packages
let appjs = gulp.src(config.src.js)
.pipe(gulp.dest(config.dir.build));
let jspm_packages = gulp.src(`${config.dir.jspm}/**/*`)
.pipe(gulp.dest(`${config.dir.build}/jspm_packages`));
let config_js = gulp.src('./config.js')
.pipe(gulp.dest(`${config.dir.build}/components`));
return merge(appjs, jspm_packages, config_js);
});
/**
* Deletes generated artifacts
*/
gulp.task('clean',
'Deletes generated artifacts (build, dist)',
(cb) => {
del.sync([config.dir.build, config.dir.dist]);
return cb();
});
/**
* Builds production app
*/
gulp.task('dist',
'Builds production app (prod-mode)',
() => {
});
/**
* Keeps web server up and running
* Called by 'run' task
*/
gulp.task('nodemon',
hideFromTaskList,
(cb) => {
let started = false;
let nodemonOptions = {
script: config.dir.server + '/server.js',
watch: [config.dir.server + '/server.js',
config.dir.build + '/**/*.*']
};
return gulpPlugin.nodemon(nodemonOptions)
.on('start', () => {
console.log('*** nodemon started');
if(!started){
cb();
}
started = true;
})
.on('restart', () => {
console.log('*** nodemon restarted');
})
.on('crash', () => {
console.log('*** nodemon crashed: script crashed for some reason');
})
.on('exit', () => {
console.log('*** nodemon exited cleanly');
});
});
/**
* Deletes generated and downloaded artifacts (node_modules, jspm_packages, bower_components)
*/
gulp.task('reset',
'Deletes generated (build, dist) ' +
'and downloaded artifacts (node_modules, jspm_packages, bower_components)',
(cb) => {
del.sync([config.dir.build, config.dir.dist, config.dir.jspm, config.dir.npm, config.dir.bower]);
return cb();
});
/**
* Runs website (dev-mode)
*/
gulp.task('run',
`Runs website (dev-mode)\n\t\tUse '--server' to disable browser launch`,
['nodemon'],
() => {
let hostname = process.env.HOSTNAME || config.web.hostname || 'localhost';
let port = process.env.PORT || config.web.port || 8000;
let syncPort = process.env.SYNC_PORT || 4000;
let serverOnly = process.argv.indexOf('--server') !== -1;
if(!serverOnly){
let browserSyncOptions = {
// All of the following files will be watched
files: [config.dir.build + '/**/*.*'],
// Tells BrowserSync on where the express app is running
proxy: `http://${hostname}:${port}`,
// This port should be different from the express app port
port: syncPort,
// Which browser should we launch?
browser: ['google chrome']
};
browserSync.init(browserSyncOptions);
}
// Register a watcher on the src directory for changes,
// which will update the build directory,
// which will trigger browserSync + nodemon
return gulp.watch(config.dir.src + '/**/*.*', ['build']);
});
/**
* Runs website (prod-mode)
*/
gulp.task('run-prod',
'Runs website (prod-mode)',
() => {
});
/**
* Runs tests
*/
gulp.task('test',
'Runs tests',
() => {
});