-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathgulpfile.js
247 lines (219 loc) · 5.89 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/* eslint-env es6, eslint-disable no-var, prefer-arrow-callback */
/*eslint strict: [2, "never"]*/
const fs = require("fs");
const gulp = require("gulp");
const eslint = require("gulp-eslint");
const ui5preload = require("gulp-ui5-preload");
const uglify = require("gulp-uglify");
const concat = require("gulp-concat");
const clean = require("gulp-clean");
const rename = require("gulp-rename");
const header = require("gulp-header");
const streamify = require("gulp-streamify");
const sequence = require("run-sequence");
const shell = require("gulp-shell");
const bump = require("gulp-bump");
const replace = require("gulp-replace");
const imagemin = require("gulp-imagemin");
const semver = require("semver");
const pkg = require("./package.json");
const banner = [
"/**",
" * <%= pkg.name %> - <%= pkg.description %>",
" * @version v<%= pkg.version %>",
" * @link <%= pkg.homepage %>",
" * @license <%= pkg.license %>",
" */",
""
].join("\n");
const filePath = {
src: "./src/*.js",
test: "./test/*.js",
dest: "./dist/openui5/googlemaps"
};
const libNS = "openui5.googlemaps";
const getPackageJson = () =>
JSON.parse(fs.readFileSync("./package.json", "utf8"));
/**
* Start the tests using karma.
* @param {boolean} singleRun - True means run once and end (CI), or keep running (dev)
* @param {Function} done - Callback to fire when karma is done
* @return {undefined}
*/
const startTests = (singleRun, done) => {
const Server = require("karma").Server;
const karmaCompleted = karmaResult => {
console.log("Karma completed");
if (karmaResult === 1) {
done("karma: tests failed with code " + karmaResult);
} else {
done();
}
};
new Server({
configFile: __dirname + "/karma.conf.js",
singleRun: !!singleRun
},
karmaCompleted
).start();
};
/**
* Start Plato inspector and visualizer
* @param {any} done this is done
*/
const startPlatoVisualizer = done => {
console.log("Running Plato");
const excludeFiles = /.*markerclusterer.js/;
const plato = require("plato");
const options = {
title: "Plato Inspections Report",
exclude: excludeFiles
};
const platoCompleted = report => {
let overview = plato.getOverviewReport(report);
console.log(overview.summary);
if (done) {
done();
}
};
plato.inspect(filePath.src, "reports/plato", options, platoCompleted);
};
/**
* Create a visualizer report
*/
gulp.task("plato", done => {
console.log("Analyzing source with Plato");
console.log("Browse to /report/plato/index.html to see Plato results");
startPlatoVisualizer(done);
});
/**
* clean destination folder
*/
gulp.task("clean", () =>
gulp
.src(filePath.dest, {
read: false
})
.pipe(clean())
);
/**
* create script dbg files
*/
gulp.task("scripts-dbg", ["lint", "clean"], () =>
gulp
.src(filePath.src)
.pipe(header(banner, { pkg: pkg }))
.pipe(rename({ suffix: "-dbg" }))
.pipe(gulp.dest(filePath.dest))
.on("error", err => {
console.error("Error in scripts-dbg task", err.toString());
})
);
/**
* create minified scripts
*/
gulp.task("scripts-min", ["lint", "clean"], () => {
const options = {
preserveComments: "license"
};
return gulp
.src(filePath.src)
.pipe(header(banner, { pkg: pkg }))
.pipe(streamify(uglify(options)))
.pipe(gulp.dest(filePath.dest))
.pipe(concat("library-all.js"))
.pipe(gulp.dest(filePath.dest));
});
/**
* lint code
* @return {Stream}
*/
gulp.task("lint", () =>
gulp
.src([filePath.src, "!./src/markerclusterer.js"])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
);
gulp.task("bump", () => {
const oldVer = getPackageJson().version;
const newVer = semver.inc(oldVer, "patch");
gulp
.src("./package.json")
.pipe(
bump({
version: newVer
})
)
.pipe(gulp.dest("./"));
gulp
.src(["src/library.js"])
.pipe(replace(oldVer, newVer))
.pipe(gulp.dest("src"));
});
/**
* add needed images to theme
*/
gulp.task("theme", () =>
gulp
.src("src/themes/base/img/*")
.pipe(imagemin())
.pipe(gulp.dest("dist/openui5/googlemaps/themes/base/img/"))
);
/**
* tag and release to new version to github, merging changes to gh-pages
*/
gulp.task("release", [], () => {
const tag = getPackageJson().version;
return gulp
.src("*.js", {
read: false
})
.pipe(
shell([
"git add -u",
"git commit m 'release' " + newVer + "",
"git tag " + tag,
"git push",
"git push --tags",
"git branch -f gh-pages master",
"git push origin gh-pages", //update branch from master
"git checkout gh-pages",
"git merge master",
"git push",
"git checkout master"
])
);
});
/**
* Run specs once and exit
* To start servers and run midway specs as well:
* @return {Stream}
*/
gulp.task("test", ["lint"], done => startTests(true /*singleRun*/ , done));
/**
* Run specs and wait.
* Watch for file changes and re-run tests on each change
*/
gulp.task("tdd", done => startTests(false /*singleRun*/ , done));
/**
* create ui5 library preload json file
*/
gulp.task("buildlibrary", ["lint", "clean", "scripts-min", "scripts-dbg"], () =>
gulp
.src([filePath.dest + "/**/!(*-dbg.js|*-all.js)"])
.pipe(
ui5preload({
base: "openui5/googlemaps",
namespace: libNS,
isLibrary: true
})
)
.pipe(gulp.dest(filePath.dest))
);
/**
* build task
*/
gulp.task("build", cb =>
sequence(["lint", "test"], "buildlibrary", "theme", cb)
);