-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
71 lines (55 loc) · 2.21 KB
/
gulpfile.js
File metadata and controls
71 lines (55 loc) · 2.21 KB
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
// modules > native
var p = require('path');
var fs = require('fs');
// modules > 3rd party
var _ = require('lodash');
var chalk = require('chalk');
// modules > gulp
var gulp = require('gulp');
var runSequence = require('run-sequence');
var gutil = require('gulp-util');
global._ = require('lodash');
global.ENV = process.env.NODE_ENV || 'development';
global.PWD = process.env.PWD;
// gulp config
// set up gulp helper functions
gulp.mkdir = require('./util/mkdir');
gulp.timer = require('./util/timer');
gulp.logger = require('./util/logger');
gulp.errorHandler = require('./util/error-handler');
gulp.config = require('./util/config');
// gulp dir, should be the same as PWD
gulp.dir = __dirname;
gulp.userConfig = fs.existsSync(p.join(PWD, 'gulpconfig.js')) ? require(p.join(PWD, 'gulpconfig.js')) : {};
var args = process.argv.slice(4);
var tasks = args.length > 0 ? args : gulp.config({
development: [ 'wipe', [ 'browserify', 'dust', 'fonts','raster', 'sass', 'static', 'svg' ], [ 'nodemon' ], [ 'watch', 'browser-sync' ] ],
production: [ 'wipe', [ 'browserify', 'dust', 'fonts', 'raster', 'sass', 'static', 'svg' ]]
}, gulp.userConfig.tasks);
var taskNames = _.flatten(tasks, true);
// only require non-local tasks
_.difference(taskNames, gulp.userConfig.localTasks).forEach(function(task) {
require('./tasks/' + task);
});
// TCB-Gulp executable calls 'gulp --cwd [ path to tcb-gulp ], which makes gulp
// call `process.cwd()`. Gulp saves the initial CWD in INIT_CWD. In order for
// our node app to function properly, we set the CWD back to the directory in
// which tcb-glp was called
process.env.GULP_CWD = process.cwd();
if(process.env.INIT_CWD) {
process.chdir(process.env.INIT_CWD);
if(gulp.userConfig.localTasks) {
var path = gulp.userConfig.localPath || './gulp-tasks';
if(/\.js/.test(path))
require(/^\//.test(path) ? path : p.join(PWD, path));
else
_.union(tasks, gulp.userConfig.localTasks).forEach(function(task) {
require(p.join(path, task));
});
}
gutil.log('Working directory changed (BACK) to ' + chalk.magenta(process.cwd()));
}
// set up the 'default' task to use runSequence to run all tasks
gulp.task('default', function(callback) {
runSequence.apply(null, tasks.concat(callback));
});