From 13f8fa7e1134cdf241d70aba682af06af8b21fd8 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sat, 27 Jan 2018 09:27:11 +0200 Subject: [PATCH] Add version to JS (#839) * Add version to JS * Throw if version wasn't found --- .eslintrc-hound.json | 1 + gulp/tasks/rollup.js | 7 +++++++ js/core.js | 1 + 3 files changed, 9 insertions(+) diff --git a/.eslintrc-hound.json b/.eslintrc-hound.json index b5ede0d746..dc053e517d 100644 --- a/.eslintrc-hound.json +++ b/.eslintrc-hound.json @@ -15,6 +15,7 @@ "__DEV__": false, "__DEMO__": false, "__BUILD__": false, + "__VERSION__": false, "Polymer": true, "webkitSpeechRecognition": false, "ResizeObserver": false diff --git a/gulp/tasks/rollup.js b/gulp/tasks/rollup.js index e5ba9a39f1..3354737f40 100644 --- a/gulp/tasks/rollup.js +++ b/gulp/tasks/rollup.js @@ -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), }, }), ], diff --git a/js/core.js b/js/core.js index 2553bc51f8..a227e8535f 100644 --- a/js/core.js +++ b/js/core.js @@ -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';