forked from vaadin/vaadin-lumo-styles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
82 lines (75 loc) · 2.2 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
'use strict';
var gulp = require('gulp');
var eslint = require('gulp-eslint');
var htmlExtract = require('gulp-html-extract');
var stylelint = require('gulp-stylelint');
var find = require('gulp-find');
var replace = require('gulp-replace');
var expect = require('gulp-expect-file');
var grepContents = require('gulp-grep-contents');
var clip = require('gulp-clip-empty-files');
var 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('fail'));
});
gulp.task('lint:html', function() {
return gulp.src([
'*.html',
'demo/**/*.html',
'test/**/*.html'
])
.pipe(htmlExtract({
sel: 'script, code-example code'
}))
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError('fail'));
});
gulp.task('lint:css', function() {
return gulp.src([
'*.html',
'demo/**/*.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(['*.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', 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(['*.html'])
.pipe(replace(oldversion, newversion))
.pipe(gulp.dest('.'))
.pipe(git.add());
});