Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9770d4e

Browse files
committedNov 15, 2017
Include a static getter for the element version
1 parent a327e66 commit 9770d4e

6 files changed

+48
-13077
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
bower_components
22
node_modules
3+
package-lock.json

‎.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ install:
1616
- polymer install
1717

1818
before_script:
19-
- gulp lint
19+
- gulp lint version:check
2020
- polymer lint --rules polymer-2 --input *.html
2121
- xvfb-run -s '-screen 0 1024x768x24' polymer test
2222

‎gulpfile.js

+34
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ var gulp = require('gulp');
44
var eslint = require('gulp-eslint');
55
var htmlExtract = require('gulp-html-extract');
66
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');
713

814
gulp.task('lint', ['lint:js', 'lint:html', 'lint:css']);
915

@@ -47,3 +53,31 @@ gulp.task('lint:css', function() {
4753
]
4854
}));
4955
});
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(/static get version.*\n.*/))
62+
.pipe(clip()) // Remove non-matching files
63+
.pipe(replace(/.*\n.*return '(.*)'.*/, '$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

Comments
 (0)
Please sign in to comment.