This repository has been archived by the owner on Oct 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 104
/
gulpfile.js
144 lines (131 loc) · 4.54 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
var gulp = require('gulp');
var gulpConcat = require('gulp-concat');
var del = require('del');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var ngAnnotate = require('gulp-ng-annotate');
var karma = require('karma');
var gulpInject = require('gulp-inject');
var mainBowerFiles = require('main-bower-files');
var angularFilesort = require('gulp-angular-filesort');
var gulpFile = require('gulp-file');
const CDN_FILES = require(__dirname + '/config/CDN.json');
const outputPath = __dirname + '/app/dist/';
var getBundleName = function () {
var name = require(__dirname + '/package.json').name;
return name + '.' + 'min';
};
/**
* Tasks
*/
gulp.task('default', ['dev']);
gulp.task('clean', clean);
gulp.task('concat', ['clean'], concat);
gulp.task('dev', ['clean'], devBuild);
gulp.task('inject-cdn', injectCdn);
gulp.task('prod', ['concat', 'inject-cdn'], productionBuild);
gulp.task('karma', unitTests);
gulp.task('karma-watch', unitTestsWatch);
/**
* Functions
*/
function clean(cb) {
del([outputPath + '**'], cb);
}
/**
* Run test once and exit
*/
function unitTests(done) {
new karma.Server({
configFile: __dirname + '/test/unit/karma.conf.js',
singleRun: true
}, done).start();
}
function unitTestsWatch(done) {
new karma.Server({
configFile: __dirname + '/test/unit/karma.conf.js',
singleRun: false,
autoWatch: true
}, done).start();
}
function concat() {
return gulp.src([
__dirname + '/app/boomerang.module.js',
__dirname + '/app/boomerang.config.js',
__dirname + '/app/services/*.js',
__dirname + '/app/**/**.js',
'!' + outputPath + '**'
])
.pipe(gulpConcat('boomerang.js'))
.pipe(gulp.dest(outputPath));
}
function productionBuild() {
var bundler = browserify({
entries: [outputPath + 'boomerang.js'],
debug: true
});
var bundle = function () {
return bundler.bundle()
.pipe(source(getBundleName() + '.js'))
.pipe(buffer())
.pipe(ngAnnotate())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(outputPath));
};
return bundle();
}
function injectCdn() {
return gulp.src(__dirname + '/index.html')
.pipe(gulpInject(
gulpFile('cdn.css', '', { src: true })
.pipe(gulpFile('cdn.js', '')),
{
name: 'bower',
transform: function (filePath) {
var tags = '', jsIndex, cssIndex;
if (filePath.indexOf('.js') !== -1) {
var jsUrls = CDN_FILES.js;
for (jsIndex = 0; jsIndex < jsUrls.length; jsIndex++) {
tags += '<script src="' + jsUrls[jsIndex] + '"></script>\n';
}
} else {
var cssUrls = CDN_FILES.css;
for (cssIndex = 0; cssIndex < cssUrls.length; cssIndex++) {
tags += '<link rel="stylesheet" href="' + cssUrls[cssIndex] + '">\n';
}
}
return tags.substring(0, tags.length - 1);
}
}))
.pipe(gulpInject(
gulpFile('local.css', '', { src: true })
.pipe(gulpFile('local.js', '')),
{
name: 'inject',
transform: function (filePath) {
var tags = '';
if (filePath.indexOf('.js') !== -1) {
tags += '<script src="' + 'app/dist/' + getBundleName() + '.js' + '"></script>\n';
} else {
tags += '<link rel="stylesheet" href="' + 'app/css/gdg.css' + '">\n';
}
return tags.substring(0, tags.length - 1);
}
}))
.pipe(gulp.dest(__dirname));
}
function devBuild() {
var target = gulp.src(__dirname + '/index.html');
var sources = gulp.src([__dirname + '/app/**/**.js'], {read: true});
var styles = gulp.src([__dirname + '/app/**/**.css'], {read: false});
return target
.pipe(gulpInject(gulp.src(mainBowerFiles(), {read: false}), {name: 'bower'}))
.pipe(gulpInject(sources.pipe(angularFilesort())))
.pipe(gulpInject(styles))
.pipe(gulp.dest(__dirname));
}