-
Notifications
You must be signed in to change notification settings - Fork 66
/
gulpfile.js
247 lines (217 loc) · 8.09 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
const ASSETS = 'assets/';
const BUILD = 'build/';
const CHROME = 'chrome/';
const CHROME_CONFIGS = CHROME + ASSETS + 'configs/';
const CHROME_CSS = CHROME + ASSETS + 'css/';
const CHROME_FONTS = CHROME + ASSETS + 'fonts/';
const CHROME_ICONS = CHROME + ASSETS + 'icons/';
const CHROME_JS = CHROME + ASSETS + 'js/';
const CHROME_MANIFEST = CHROME + 'manifest.json';
const CHROME_TEMPLATES = CHROME + ASSETS + 'templates/';
const COMMON = 'common/';
const CONFIGS = 'configs/';
const FONTS = 'fonts/';
const DIST = 'dist/';
const LIBS = 'libs/';
const SRC = 'src/';
const TEMPLATES = 'templates/';
var packagejson = require('./package.json');
var banner = ['/*',
' Selenium Page Object Generator - to improve agile testing process velocity.',
' Copyright (c) 2015, 2016, 2018 ' + packagejson.author,
'',
' This program is free software: you can redistribute it and/or modify',
' it under the terms of the GNU Affero General Public License as',
' published by the Free Software Foundation, either version 3 of the',
' License, or (at your option) any later version.',
'',
' This program is distributed in the hope that it will be useful,',
' but WITHOUT ANY WARRANTY; without even the implied warranty of',
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the',
' GNU Affero General Public License for more details.',
'',
' You should have received a copy of the GNU Affero General Public License',
' along with this program. If not, see <http://www.gnu.org/licenses/>.',
'*/',
''].join('\n');
console.time('Loading Modules');
var concat = require('gulp-concat');
var concatcss = require('gulp-concat-css');
var cssnano = require('gulp-cssnano');
var del = require('del');
var es = require('event-stream');
var gulp = require('gulp');
var header = require('gulp-header');
var htmlmin = require('gulp-htmlmin');
var istanbul = require('gulp-istanbul');
var jasmine = require('gulp-jasmine');
var jshint = require('gulp-jshint');
var jsonminify = require('gulp-jsonminify');
var replace = require('gulp-replace');
var uglify = require('gulp-uglify');
var zip = require('gulp-zip');
console.timeEnd('Loading Modules');
function css(base, inputs, output) {
return gulp.src(inputs, { base: base }).
pipe(concatcss(output)).
pipe(cssnano({ discardComments: { removeAllButFirst: true } })).
pipe(header(banner)).
pipe(gulp.dest(BUILD));
}
function html(input) {
return gulp.src(SRC + CHROME + input).
pipe(htmlmin({
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true
})).
pipe(gulp.dest(BUILD + CHROME));
}
function js(base, inputs, output) {
return gulp.src(inputs, { base: base }).
//pipe(jshint('.jshintrc')).
//pipe(jshint.reporter('default')).
pipe(concat(output)).
pipe(uglify()).
pipe(header(banner)).
pipe(gulp.dest(BUILD));
}
gulp.task('clean', function() {
return del([ BUILD, DIST ]);
});
gulp.task('chrome:copy', [ 'chrome:copy:configs', 'chrome:copy:folders', 'chrome:copy:manifest' ], function(cb) {
cb();
});
gulp.task('chrome:copy:configs', function() {
return gulp.src(CONFIGS + '**/*').
pipe(jsonminify()).
pipe(gulp.dest(BUILD + CHROME_CONFIGS));
});
gulp.task('chrome:copy:folders', function() {
return es.merge(
gulp.src(FONTS + '**/*').pipe(gulp.dest(BUILD + CHROME_FONTS)),
gulp.src(SRC + CHROME_ICONS + '**/*').pipe(gulp.dest(BUILD + CHROME_ICONS)),
gulp.src(TEMPLATES + '**/*').pipe(gulp.dest(BUILD + CHROME_TEMPLATES))
);
});
gulp.task('chrome:copy:manifest', function() {
var name = packagejson.name.replace(/-/g, ' ').replace(/\w\S*/g, function(word) {
return word.charAt(0).toUpperCase() + word.substr(1).toLowerCase();
});
return gulp.src(SRC + CHROME_MANIFEST).
pipe(replace(/"author": "[^"]*",/g, '"author": "' + packagejson.author + '",')).
pipe(replace(/"description": "[^"]*",/g, '"description": "' + packagejson.description + '",')).
pipe(replace(/"name": "[^"]*",/g, '"name": "' + name + '",')).
pipe(replace(/"version": "[^"]*"/g, '"version": "' + packagejson.version + '"')).
pipe(jsonminify()).
pipe(gulp.dest(BUILD + CHROME));
});
gulp.task('chrome:css', [ 'chrome:css:options', 'chrome:css:popup' ], function(cb) {
cb();
});
gulp.task('chrome:css:options', function() {
return css(SRC, [
SRC + CHROME_CSS + 'options.css',
SRC + CHROME_CSS + 'preloader.css'
], CHROME_CSS + 'options.css');
});
gulp.task('chrome:css:popup', function() {
return css(SRC, [
SRC + CHROME_CSS + 'popup.css',
SRC + CHROME_CSS + 'preloader.css',
SRC + CHROME_CSS + 'notify.css'
], CHROME_CSS + 'popup.css');
});
gulp.task('chrome:dist', function() {
return gulp.src(BUILD + CHROME + '**/*').
pipe(zip(packagejson.name + '-' + packagejson.version + '.zip')).
pipe(gulp.dest(DIST));
});
gulp.task('chrome:html', [ 'chrome:html:options', 'chrome:html:popup' ], function(cb) {
cb();
});
gulp.task('chrome:html:options', function() {
return html('options.html');
});
gulp.task('chrome:html:popup', function() {
return html('popup.html');
});
gulp.task('chrome:js', [ 'chrome:js:generator', 'chrome:js:options', 'chrome:js:popup' ], function(cb) {
cb();
});
gulp.task('chrome:js:generator', function() {
return js(SRC, [
SRC + COMMON + 'common.js',
SRC + COMMON + 'generator.js'
], CHROME_JS + 'generator.js');
});
gulp.task('chrome:js:options', function() {
return js(SRC, [
LIBS + 'jquery-3.3.1.js',
SRC + CHROME_JS + 'preloader.js',
SRC + COMMON + 'common.js',
SRC + CHROME_JS + 'options.js'
], CHROME_JS + 'options.js');
});
gulp.task('chrome:js:popup', function() {
return js(SRC, [
LIBS + 'jquery-3.3.1.js',
LIBS + 'handlebars-v4.0.11.js',
SRC + CHROME_JS + 'preloader.js',
SRC + CHROME_JS + 'notify.js',
SRC + CHROME_JS + 'social.js',
SRC + COMMON + 'common.js',
SRC + COMMON + 'helpers.js',
SRC + CHROME_JS + 'popup.js'
], CHROME_JS + 'popup.js');
});
gulp.task('chrome:js:lint', function() {
return gulp.src(SRC + CHROME_JS + '*.js', { base: SRC }).
pipe(jshint()).
//pipe(jshint('.jshintrc')).
pipe(jshint.reporter('default'));
});
gulp.task('chrome:js:test', function(cb) {
gulp.src(SRC + CHROME_JS + '*.js', { base: SRC }).
pipe(istanbul({ includeUntested: true })).
pipe(istanbul.hookRequire()).
on('finish', function() {
gulp.src('specs/chrome/*-spec.js').
pipe(jasmine({ includeStackTrace: true, verbose: true })).
pipe(istanbul.writeReports({
dir: 'lcov/chrome',
reporters: [ 'lcov' ],
reportOpts: { dir: 'lcov/chrome' }
})).
on('end', cb);
});
});
gulp.task('chrome', [ 'chrome:copy', 'chrome:css', 'chrome:html', 'chrome:js' ], function(cb) {
gulp.start('chrome:dist');
cb();
});
gulp.task('common:test', function(cb) {
gulp.src(SRC + COMMON + '*.js', { base: SRC }).
pipe(istanbul({ includeUntested: true })).
pipe(istanbul.hookRequire()).
on('finish', function() {
gulp.src('specs/common/*-spec.js').
pipe(jasmine({ includeStackTrace: true, verbose: true })).
pipe(istanbul.writeReports({
dir: 'lcov/common',
reporters: [ 'lcov' ],
reportOpts: { dir: 'lcov/common' }
})).
on('end', cb);
});
});
//gulp.task('watch', function() {
//});
gulp.task('default', [ 'clean' ], function(cb) {
// wait until clean task is completed
gulp.start('chrome');
cb();
});