testValues.js
1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use strict';
const path = require('path')
, fs = require('fs')
, os = require('os')
;
const TEST_DATA = loadData();
module.exports = {
username: getTestDataValue('username'),
clientkey: getTestDataValue('clientkey'),
testLightId: getTestDataValue('lightid'),
streamingLightId: getTestDataValue('lightid'),
};
function loadData() {
const platform = os.platform();
let testDataFile;
if (platform === 'win32') {
testDataFile = path.join(process.env.LOCALAPPDATA, '.node-hue-api');
} else if (platform === 'darwin') {
testDataFile = path.join(process.env.HOME, '.node-hue-api');
}
//TODO add support for Linux
let data = null;
if (fs.existsSync(testDataFile)) {
try {
data = JSON.parse(fs.readFileSync(testDataFile));
} catch(err) {
console.error(`Failed to parse data file ${testDataFile}: ${err.message}`);
data = null;
}
}
return data;
}
function getTestDataValue(key) {
if (TEST_DATA) {
return TEST_DATA[key];
}
return null;
}