forked from vaadin/vaadin-combo-box
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
88 lines (81 loc) · 2.42 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
'use strict';
const gulp = require('gulp');
const eslint = require('gulp-eslint');
const htmlExtract = require('gulp-html-extract');
const lec = require('gulp-line-ending-corrector');
const stylelint = require('gulp-stylelint');
const find = require('gulp-find');
const replace = require('gulp-replace');
const expect = require('gulp-expect-file');
const grepContents = require('gulp-grep-contents');
const clip = require('gulp-clip-empty-files');
const git = require('gulp-git');
gulp.task('lint', ['lint:js', 'lint:html', 'lint:css']);
gulp.task('lint:js', function() {
return gulp.src([
'*.js',
'test/**/*.js'
])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('lint:html', function() {
return gulp.src([
'*.html',
'src/**/*.html',
'demo/**/*.html',
'test/**/*.html'
])
.pipe(htmlExtract({
sel: 'script, code-example code',
strip: true
}))
.pipe(lec())
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('lint:css', function() {
return gulp.src([
'*.html',
'src/**/*.html',
'demo/**/*.html',
'theme/**/*.html',
'test/**/*.html'
])
.pipe(htmlExtract({
sel: 'style'
}))
.pipe(stylelint({
reporters: [
{formatter: 'string', console: true}
]
}));
});
gulp.task('version:check', function() {
const expectedVersion = new RegExp('^' + require('./package.json').version + '$');
return gulp.src(['src/*.html'])
.pipe(htmlExtract({sel: 'script'}))
.pipe(find(/static get version.*\n.*/))
.pipe(clip()) // Remove non-matching files
.pipe(replace(/.*\n.*return '(.*)'.*/, '$1'))
.pipe(grepContents(expectedVersion, {invert: true}))
.pipe(expect({reportUnexpected: true}, []));
});
gulp.task('version:update', ['version:check'], function() {
// Should be run from 'preversion'
// Assumes that the old version is in package.json and the new version in the `npm_package_version` environment variable
const oldversion = require('./package.json').version;
const newversion = process.env.npm_package_version;
if (!oldversion) {
throw new 'No old version found in package.json';
}
if (!newversion) {
throw new 'New version must be given as a npm_package_version environment variable.';
}
return gulp.src(['src/*.html'])
.pipe(replace(oldversion, newversion))
.pipe(gulp.dest('src/.'))
.pipe(git.add());
});