-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
room-assistant.js
executable file
·81 lines (74 loc) · 1.9 KB
/
room-assistant.js
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env node
/* eslint-disable @typescript-eslint/no-var-requires */
const pkg = require('../package.json');
require('please-upgrade-node')(pkg);
const updateNotifier = require('update-notifier');
const chalk = require('chalk');
const commandLineUsage = require('command-line-usage');
const commandLineArgs = require('command-line-args');
const isBeta = pkg.version.includes('beta');
let updateCommand = 'npm i -g --unsafe-perm {packageName}';
if (isBeta) {
updateCommand += '@beta';
}
updateNotifier({
pkg,
distTag: isBeta ? 'beta' : 'latest',
}).notify({
message: `Update available ${chalk.dim('{currentVersion}')} ${chalk.reset(
'→'
)} ${chalk.green('{latestVersion}')} \nRun ${chalk.cyan(
updateCommand
)} to update`,
});
const optionDefinitions = [
{
name: 'help',
description: 'Display this usage guide.',
alias: 'h',
type: Boolean,
},
{
name: 'config',
description: 'Path to the config folder the software should load.',
alias: 'c',
type: String,
defaultValue: './config',
},
{
name: 'digResolver',
description:
'Use dig to resolve mdns hostnames instead of the native getaddrinfo.',
type: Boolean,
},
{
name: 'verbose',
description: 'Turn on debugging output.',
alias: 'v',
type: Boolean,
},
];
const usage = commandLineUsage([
{
header: `room-assistant ${pkg.version}`,
content:
'A companion client for Home Assistant to handle presence detection and sensors in multiple rooms.',
},
{
header: 'Options',
optionList: optionDefinitions,
},
]);
const options = commandLineArgs(optionDefinitions);
if (options.help) {
console.log(usage);
return;
}
process.env.NODE_LOG_LEVEL = options.verbose
? 'debug'
: process.env.NODE_LOG_LEVEL || 'info';
process.env.NODE_CONFIG_DIR = options.config;
if (options.digResolver) {
process.env.NODE_DIG_RESOLVER = true;
}
require('../dist/main');