Skip to content

Commit 4f14c4f

Browse files
committed
ensure environment variables are present
1 parent d9e8f4a commit 4f14c4f

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
const process = require('node:process');
2+
const { isIP } = require('net');
3+
const env = require('good-env');
24
const Sonos = require('./lib/sonos');
35
const Sensor = require('./lib/sensor');
46
const { hue } = require('./lib/config');
@@ -10,6 +12,14 @@ const {
1012
printNowPlaying,
1113
randomTrack
1214
} = require('./lib/utils');
15+
const ipOk = str => isIP(str) === 4 || isIP(str) === 6;
16+
17+
// Ensure all the required environemnt variables are present
18+
env.assert(
19+
{ 'HUE_BRIDGE_IP': { type: 'string', ok: ipOk }},
20+
'HUE_USERNAME',
21+
'HUE_SENSOR_ID',
22+
);
1323

1424
(async function () {
1525
const trackChoices = await chooseVibe();

src/lib/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ function randomTrack (items) {
7979
return items[Math.floor(Math.random() * items.length)];
8080
}
8181

82-
const camelize = (str) => {
82+
function camelize (str) {
8383
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, (word, index) => {
8484
return index === 0 ? word.toLowerCase() : word.toUpperCase();
8585
})
8686
.replace(/\s+/g, '')
8787
.replace(/'/g, '')
8888
.replace(//g, '');
89-
};
89+
}
9090

9191
module.exports = {
9292
buildPlayQueue,

0 commit comments

Comments
 (0)