node-hue-api
Version:
Philips Hue API Library for Node.js
50 lines (39 loc) • 1.09 kB
JavaScript
;
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');
} else if (platform === 'linux') {
testDataFile = path.join(process.env.HOME, '.node-hue-api');
}
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;
}