Skip to content

Commit

Permalink
Include a static getter for the element version
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur- committed Nov 15, 2017
1 parent a327e66 commit 9770d4e
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 13,077 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
bower_components
node_modules
package-lock.json
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ install:
- polymer install

before_script:
- gulp lint
- gulp lint version:check
- polymer lint --rules polymer-2 --input *.html
- xvfb-run -s '-screen 0 1024x768x24' polymer test

Expand Down
34 changes: 34 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ 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']);

Expand Down Expand Up @@ -47,3 +53,31 @@ gulp.task('lint:css', function() {
]
}));
});

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', ['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(['*.html'])
.pipe(replace(oldversion, newversion))
.pipe(gulp.dest('.'))
.pipe(git.add());
});
Loading

0 comments on commit 9770d4e

Please sign in to comment.