-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
129 lines (108 loc) · 3.33 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
'use strict';
/*********************************************************
* Modules
********************************************************/
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var templateCache = require('gulp-angular-templatecache');
var ngConstant = require('gulp-ng-constant');
var ngAnnotate = require('gulp-ng-annotate');
// Non-Gulp dependencies
var browserify = require('browserify');
var babelify = require('babelify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var watchify = require('watchify');
var fs = require('fs');
/*********************************************************
* Vars
********************************************************/
var projectPath = 'app/';
var outputPath = 'public/';
var configPath = 'config/';
/*********************************************************
* Angular Templates
********************************************************/
gulp.task('templates', function() {
return gulp.src(projectPath + '**/*.html')
.pipe(templateCache({
module: 'templateCache',
standalone: true,
transformUrl: function (url) {
return url.replace('custom/', '');
}
}))
.pipe(gulp.dest(outputPath + 'js'));
});
/*********************************************************
* JavaScript
********************************************************/
gulp.task('js:build', function() {
return browserify(projectPath + 'app.js', {
debug: false
})
.transform(babelify)
.bundle()
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe(ngAnnotate())
.pipe(uglify())
.pipe(gulp.dest(outputPath + 'js'));
});
gulp.task('js:dev', function() {
return browserify(projectPath + 'app.js', {
debug: true
})
.bundle()
.pipe(source('bundle.js'))
.pipe(gulp.dest(outputPath + 'js'));
});
gulp.task('js:watch', [], function() {
var bundler = browserify({
entries: [projectPath + 'app.js'],
extensions: ['.js'],
debug: true,
fullPaths: true,
cache: {},
packageCache: {}
})
var rebundle = function() {
var startDate = new Date();
return bundler.bundle(function(err, buf) {
if (err) {
console.log('JS error: ' + err.toString());
} else {
console.log('JS bundle updated in ' + (new Date().getTime() - startDate.getTime()) + ' ms');
}
})
.pipe(source('bundle.js'))
.pipe(gulp.dest(outputPath + 'js'));
};
bundler.plugin(watchify);
bundler.on('update', rebundle);
return rebundle();
});
/*********************************************************
* Environment Config
********************************************************/
var configFunc = function(env) {
var config = './' + configPath + 'config.json';
var localConfig = './' + configPath + 'config.local.json';
var myConfig;
if (fs.existsSync(localConfig)) {
console.log('Using local config file: ' + localConfig);
myConfig = require(localConfig);
} else {
console.log('Using default config file: ' + config);
myConfig = require(config);
}
var envConfig = myConfig[env];
return ngConstant({
constants: envConfig,
stream: true
})
.pipe(gulp.dest(outputPath + 'js'));
};
gulp.task('config:dev', configFunc.bind(this, 'dev'));
gulp.task('config:staging', configFunc.bind(this, 'staging'));
gulp.task('config:build', configFunc.bind(this, 'production'));