forked from allenhwkim/angularjs-google-maps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
190 lines (176 loc) · 6.18 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
/* 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', 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'))
.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'))
.pipe(uglify({preserveComments: license}))
.pipe(rename('ng-map.min.js'))
.pipe(gulp.dest('build/scripts'))
.on('error', gutil.log);
});
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) {
karma.start({
configFile: __dirname + '/config/karma.conf.js',
singleRun: true
}, done);
});
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'));
});