@@ -4,6 +4,12 @@ var gulp = require('gulp');
4
4
var eslint = require ( 'gulp-eslint' ) ;
5
5
var htmlExtract = require ( 'gulp-html-extract' ) ;
6
6
var stylelint = require ( 'gulp-stylelint' ) ;
7
+ var find = require ( 'gulp-find' ) ;
8
+ var replace = require ( 'gulp-replace' ) ;
9
+ var expect = require ( 'gulp-expect-file' ) ;
10
+ var grepContents = require ( 'gulp-grep-contents' ) ;
11
+ var clip = require ( 'gulp-clip-empty-files' ) ;
12
+ var git = require ( 'gulp-git' ) ;
7
13
8
14
gulp . task ( 'lint' , [ 'lint:js' , 'lint:html' , 'lint:css' ] ) ;
9
15
@@ -47,3 +53,31 @@ gulp.task('lint:css', function() {
47
53
]
48
54
} ) ) ;
49
55
} ) ;
56
+
57
+ gulp . task ( 'version:check' , function ( ) {
58
+ const expectedVersion = new RegExp ( '^' + require ( './package.json' ) . version + '$' ) ;
59
+ return gulp . src ( [ '*.html' ] )
60
+ . pipe ( htmlExtract ( { sel : 'script' } ) )
61
+ . pipe ( find ( / s t a t i c g e t v e r s i o n .* \n .* / ) )
62
+ . pipe ( clip ( ) ) // Remove non-matching files
63
+ . pipe ( replace ( / .* \n .* r e t u r n ' ( .* ) ' .* / , '$1' ) )
64
+ . pipe ( grepContents ( expectedVersion , { invert : true } ) )
65
+ . pipe ( expect ( { reportUnexpected : true } , [ ] ) ) ;
66
+ } ) ;
67
+
68
+ gulp . task ( 'version:update' , [ 'version:check' ] , function ( ) {
69
+ // Should be run from 'preversion'
70
+ // Assumes that the old version is in package.json and the new version in the `npm_package_version` environment variable
71
+ const oldversion = require ( './package.json' ) . version ;
72
+ const newversion = process . env . npm_package_version ;
73
+ if ( ! oldversion ) {
74
+ throw new 'No old version found in package.json' ;
75
+ }
76
+ if ( ! newversion ) {
77
+ throw new 'New version must be given as a npm_package_version environment variable.' ;
78
+ }
79
+ return gulp . src ( [ '*.html' ] )
80
+ . pipe ( replace ( oldversion , newversion ) )
81
+ . pipe ( gulp . dest ( '.' ) )
82
+ . pipe ( git . add ( ) ) ;
83
+ } ) ;
0 commit comments