forked from allenhwkim/angularjs-google-maps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
232 lines (215 loc) · 7.74 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/* jshint node: true */
'use strict';
var pjson = require('./package.json');
var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var stripDebug = require('gulp-strip-debug');
var gutil = require('gulp-util');
var clean = require('gulp-clean');
var runSequence = require('run-sequence');
var gutil = require('gulp-util');
var tap = require('gulp-tap');
var bump = require('gulp-bump');
var shell = require('gulp-shell');
var karma = require('karma').Server;
var connect = require('gulp-connect');
var gulpProtractor = require("gulp-protractor").protractor;
var File = require('vinyl');
var through = require('through2');
var path = require('path');
var cheerio = require('cheerio');
var argv = require('yargs').argv;
var replace = require('gulp-replace');
var umd = require('gulp-umd');
var bumpVersion = function(type) {
type = type || 'patch';
var version = '';
gulp.src(['./bower.json', './package.json'])
.pipe(bump({type: type}))
.pipe(gulp.dest('./'))
.pipe(tap(function(file) {
version = JSON.parse(file.contents.toString()).version;
})).on('end', function() {
var color = gutil.colors;
gulp.src('')
.pipe(shell([
'git commit --all --message "Version ' + version + '"',
(type != 'patch' ?
'git tag --annotate "v' + version +
'" --message "Version ' + version + '"' : 'true')
], {ignoreErrors: false}))
.pipe(tap(function() {
gutil.log(color.green("Version bumped to ") +
color.yellow(version) + color.green(", don't forget to push!"));
}));
});
};
gulp.task('clean', function() {
return gulp.src('build')
.pipe(clean({force: true}));
});
var license = require('uglify-save-license');
gulp.task('build-js:debug', function() {
return gulp.src([
'app.js',
'controllers/*.js',
'directives/*.js',
'filters/*.js',
'services/*.js'
])
.pipe(concat('ng-map.debug.js'))
.pipe(replace(/(AngularJS Google Maps)/, '$1 Ver. ' + pjson.version))
.pipe(gulp.dest('build/scripts'))
.on('error', gutil.log);
});
gulp.task('build-js:angular', function() {
return gulp.src(['build/scripts/ng-map.debug.js'])
.pipe(stripDebug())
.pipe(concat('ng-map.js'))
.pipe(umd({
dependencies: function (file) {
return [{
name: 'angular',
amd: 'angular',
cjs: 'angular',
global: 'angular',
param: 'angular'
}];
},
exports: function (file) {
return "'ngMap'";
},
//template: umdTemplates.returnExportsNoNamespace.path,
templateSource: '(function(root, factory) {\r\n' +
'if (typeof exports === "object") {\r\n' +
'module.exports = factory(<%= cjs %>);\r\n' +
'} else if (typeof define === "function" && define.amd) {\r\n' +
'define(<%= amd %>, factory);\r\n' +
'} else{\r\n' +
'factory(<%= global %>);\r\n' +
'}\r\n' +
'}(this, function(<%= param %>) {\r\n' +
'<%= contents %>\r\n' +
'return <%= exports %>;\r\n' +
'}));'
}))
.pipe(gulp.dest('build/scripts'))
.on('error', gutil.log);
});
gulp.task('build-js:angular-min', function() {
return gulp.src(['build/scripts/ng-map.js'])
.pipe(concat('ng-map.min.js'))
.pipe(uglify({preserveComments: license}))
.pipe(gulp.dest('build/scripts'))
.on('error', gutil.log);
})
gulp.task('build-js:no-dependency', function() {
return gulp.src(['build/scripts/ng-map.debug.js'])
.pipe(stripDebug())
.pipe(concat('ng-map.no-dependency.js'))
.pipe(umd({
dependencies: function (file) {
return [];
},
exports: function (file) {
return "'ngMap'";
},
//template: umdTemplates.returnExportsNoNamespace.path,
templateSource: '(function(root, factory) {\r\n' +
'if (typeof exports === "object") {\r\n' +
'module.exports = factory();\r\n' +
'} else if (typeof define === "function" && define.amd) {\r\n' +
'define([], factory);\r\n' +
'} else{\r\n' +
'factory();\r\n' +
'}\r\n' +
'}(this, function() {\r\n' +
'<%= contents %>\r\n' +
'return <%= exports %>;\r\n' +
'}));'
}))
.pipe(gulp.dest('build/scripts'))
.on('error', gutil.log);
});
gulp.task('build-js', function(callback) {
return runSequence('build-js:debug', ['build-js:no-dependency', 'build-js:angular'], 'build-js:angular-min', callback);
});
gulp.task('docs', function() {
gulp.task('docs', shell.task([
'node_modules/jsdoc/jsdoc.js '+
'-c node_modules/angular-jsdoc/common/conf.json '+ // config file
'-t node_modules/angular-jsdoc/angular-template '+ // template file
'-d build/docs '+ // output directory
'./README.md ' + // to include README.md as index contents
'-r directives services' // source code directory
]));
});
gulp.task('bump', function() { bumpVersion('patch'); });
gulp.task('bump:patch', function() { bumpVersion('patch'); });
gulp.task('bump:minor', function() { bumpVersion('minor'); });
gulp.task('bump:major', function() { bumpVersion('major'); });
gulp.task('build', function(callback) {
runSequence('clean', 'build-js', 'test', 'docs', 'examples:json', callback);
});
gulp.task('test', function (done) {
new karma({
configFile: __dirname + '/config/karma.conf.js',
singleRun: true
}, done).start();
});
gulp.task('test:server', function() {
connect.server({
root: __dirname,
port: 8888
});
});
gulp.task('test:e2e', ['test:server'], function() {
gulp.src([__dirname + "/spec/e2e/*_spec.js"])
.pipe(gulpProtractor({
configFile: __dirname + "/config/protractor.conf.js",
args: [
'--baseUrl', 'http://localhost:8888',
'--files', argv.files
]
}))
.on('error', function(e) {
console.log([
'------------------------------------------------------------------------------------',
'For first-time user, we need to update webdrivers',
'$ node_modules/gulp-protractor/node_modules/protractor/bin/webdriver-manager update',
'------------------------------------------------------------------------------------'
].join('\n'));
throw e;
})
.on('end', function() { // when process exits:
connect.serverClose();
});
});
gulp.task('examples:json', function() {
var allExamples = {};
gulp.src([__dirname + "/testapp/*.html"])
.pipe(through.obj(
function(file, encoding, callback) {
var $ = cheerio.load(file.contents);
allExamples[path.basename(file.path)] = {
path: path.relative(path.dirname(path.dirname(file.path)), file.path),
title: $('title').html(),
description: $('meta[name=description]').attr('content'),
keywords: $('meta[name=keywords]').attr('content')
};
callback();
},
function(callback) {
this.push( new File({
cwd: ".",
base: "./",
path: "./all-examples.json",
contents: new Buffer(JSON.stringify(allExamples, null,' '))
}));
callback();
}
))
.pipe(gulp.dest('testapp'));
});