-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkConfig.js
115 lines (104 loc) · 4.15 KB
/
checkConfig.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
"use strict";
let config = require(process.argv[2]);
let err = [];
try {
if (!config) err.push("何も設定されていません(設定必須です)。");
config &&
config.forEach(c => {
Object.keys(c).forEach(
key =>
[
"intervalMillisec",
"omron2jcieBu01Name",
"omron2jcieBu01Address",
"csvFilename",
"machinistApiKey",
"machinistAgent",
"machinistBatchQuantity",
"ambientChannelId",
"ambientWriteKey",
"ambientBatchQuantity",
"webAgent",
"speechAgent"
].indexOf(key) == -1 && err.push(`${key}は誤った設定項目です。`)
);
if (c.omron2jcieBu01Name && c.omron2jcieBu01Address) {
if (!c.intervalMillisec)
err.push("interval_millisecが設定されていません(必須項目です)。");
if (typeof c.intervalMillisec != "number" || c.intervalMillisec < 1000)
err.push("interval_millisecは1000以上の数値である必要があります。");
}
if (c.omron2jcieBu01Address) {
if (!c.omron2jcieBu01Name)
err.push("omron2jcieBu01Nameの設定は必須です。");
//if(c.omron2jcieBu01Name != "Rbt") err.push('');
if (
!(
c.omron2jcieBu01Address.match(
/^[A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9]$/
) ||
c.omron2jcieBu01Address.match(
/^[A-Za-z0-9][A-Za-z0-9]\:?[A-Za-z0-9][A-Za-z0-9]\:?[A-Za-z0-9][A-Za-z0-9]\:?[A-Za-z0-9][A-Za-z0-9]\:?[A-Za-z0-9][A-Za-z0-9]\:?[A-Za-z0-9][A-Za-z0-9]$/
)
)
) {
err.push(
"omron2jcieBu01Addressのフォーマットが間違っています。(アルファベットと数字の12文字(2文字おきに:があってもよい)が正しいフォーマットです)"
);
}
}
//if(c.csvFilename) err.push('csvが設定されていません(必須項目です)。');
if (c.csvFilename) {
c.csvFilename.match(/[\0|\/]/) &&
err.push("csvFilenameに/文字やnull文字は使えません。");
}
if (c.machinistApiKey || c.machinistAgent) {
if (!c.machinistApiKey)
err.push(
"machinistApiKeyが設定されていません(Machinistを使用するなら必須項目です)。"
);
if (typeof c.machinistApiKey != "string")
err.push("MachinistApiKeyは文字列である必要があります。");
if (!c.machinistAgent)
err.push(
"machinistAgentが設定されていません(Machinistを使用するなら必須項目です)。"
);
if (typeof c.machinistAgent != "string")
err.push("MachinistAgentは文字列である必要があります。");
if (!c.machinistBatchQuantity)
err.push(
"machinistBatchQuantityが設定されていません(Machinistを使用するなら必須項目です)。"
);
if (
typeof c.machinistBatchQuantity != "number" ||
c.machinistBatchQuantity < 1
)
err.push("machinistBatchQuantityは1以上の整数である必要があります。");
}
if (c.ambientChannelId || c.ambientWriteKey) {
if (!c.ambientChannelId)
err.push(
"ambientChannelIdが設定されていません(Ambientを使用するなら必須項目です)。"
);
if (!c.ambientWriteKey)
err.push(
"ambientWriteKeyが設定されていません(Ambientを使用するなら必須項目です)。"
);
if (!c.ambientBatchQuantity)
err.push(
"ambientBatchQuantityが設定されていません(Ambientを使用するなら必須項目です)。"
);
}
});
} catch (e) {
console.error(err.join("\n"));
console.error(e);
process.exit(1);
}
if (err.length > 0) {
console.error(err.join("\n"));
process.exit(1);
} else {
console.log("設定項目のチェックは正常に終了しました。");
process.exit(0);
}