Add version to JS (#839)

* Add version to JS

* Throw if version wasn't found
pull/842/head
Andrey 2018-01-27 09:27:11 +02:00 committed by Paulus Schoutsen
parent c11a525a2d
commit 13f8fa7e11
3 changed files with 9 additions and 0 deletions

View File

@ -15,6 +15,7 @@
"__DEV__": false,
"__DEMO__": false,
"__BUILD__": false,
"__VERSION__": false,
"Polymer": true,
"webkitSpeechRecognition": false,
"ResizeObserver": false

View File

@ -1,3 +1,4 @@
const fs = require('fs');
const gulp = require('gulp');
const rollupEach = require('gulp-rollup-each');
const commonjs = require('rollup-plugin-commonjs');
@ -8,6 +9,11 @@ const uglify = require('../common/gulp-uglify.js');
const DEV = !!JSON.parse(process.env.BUILD_DEV || 'true');
const DEMO = !!JSON.parse(process.env.BUILD_DEMO || 'false');
const version = fs.readFileSync('setup.py', 'utf8').match(/\d{8}[^']*/);
if (!version) {
throw Error('Version not found');
}
const VERSION = version[0];
function getRollupInputOptions(es6) {
const babelOpts = {
@ -51,6 +57,7 @@ function getRollupInputOptions(es6) {
__DEV__: JSON.stringify(DEV),
__DEMO__: JSON.stringify(DEMO),
__BUILD__: JSON.stringify(es6 ? 'latest' : 'es5'),
__VERSION__: JSON.stringify(VERSION),
},
}),
],

View File

@ -4,6 +4,7 @@ window.HAWS = HAWS;
window.HASS_DEMO = __DEMO__;
window.HASS_DEV = __DEV__;
window.HASS_BUILD = __BUILD__;
window.HASS_VERSION = __VERSION__;
const init = window.createHassConnection = function (password) {
const proto = window.location.protocol === 'https:' ? 'wss' : 'ws';