-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
82 lines (76 loc) · 2.29 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
'use strict';
var gulp = require('gulp');
var minimist = require('minimist');
var requireDir = require('require-dir');
var chalk = require('chalk');
var fs = require('fs');
// config
gulp.paths = {
bowerComponents: 'app/bower_components',
dist: 'www',
jsFiles: ['app/**/*.js', '!app/bower_components/**/*.js'],
jsonFiles: ['app/**/*.json', '!app/bower_components/**/*.json'],
templates: ['app/*/templates/**/*'],
contrib: ['gulpfile.js', 'gulp/**/*.js', 'hooks/**/*.js'],
karma: ['test/karma/**/*.js'],
protractor: ['test/protractor/**/*.js']
};
// OPTIONS
var options = gulp.options = minimist(process.argv.slice(2));
// load .gulp_settings.json
var task = options._[0]; // only for first task
var gulpSettings;
if (fs.existsSync('./gulp/.gulp_settings.json')) {
gulpSettings = require('./gulp/.gulp_settings.json');
var defaults = gulpSettings.defaults;
if (defaults) {
// defaults present for said task?
if (task && task.length && defaults[task]) {
var taskDefaults = defaults[task];
// copy defaults to options object
for (var key in taskDefaults) {
// only if they haven't been explicitly set
if (options[key] === undefined) {
options[key] = taskDefaults[key];
}
}
}
}
}
// environment
options.env = options.env || 'dev';
// print options
if (defaults && defaults[task]) {
console.log(chalk.green('defaults for task \'' + task + '\': '), defaults[task]);
}
// cordova command one of cordova's build commands?
if (options.cordova) {
var cmds = ['build', 'run', 'emulate', 'prepare', 'serve'];
for (var i = 0, cmd; ((cmd = cmds[i])); i++) {
if (options.cordova.indexOf(cmd) >= 0) {
options.cordovaBuild = true;
break;
}
}
}
// load tasks
requireDir('./gulp');
// default task
gulp.task('default', function () {
// cordova build command & gulp build
if (options.cordovaBuild && options.build !== false) {
return gulp.start('cordova-with-build');
}
// cordova build command & no gulp build
else if (options.cordovaBuild && options.build === false) {
return gulp.start('cordova-only-resources');
}
// cordova non-build command
else if (options.cordova) {
return gulp.start('cordova');
}
// just watch when cordova option not present
else {
return gulp.start('watch');
}
});