@webos-tools/cli 3.0.6 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +1 -1
- package/.eslintrc.js +52 -52
- package/APIs.js +79 -79
- package/CHANGELOG.md +152 -138
- package/LICENSE +201 -201
- package/README.md +218 -218
- package/bin/ares-config.js +199 -199
- package/bin/ares-device-info.js +30 -30
- package/bin/ares-device.js +219 -219
- package/bin/ares-generate.js +274 -270
- package/bin/ares-inspect.js +179 -179
- package/bin/ares-install.js +223 -223
- package/bin/ares-launch.js +318 -318
- package/bin/ares-log.js +255 -255
- package/bin/ares-novacom.js +220 -223
- package/bin/ares-package.js +336 -336
- package/bin/ares-pull.js +156 -156
- package/bin/ares-push.js +155 -155
- package/bin/ares-server.js +174 -174
- package/bin/ares-setup-device.js +528 -520
- package/bin/ares-shell.js +132 -132
- package/bin/ares.js +166 -166
- package/files/conf/ares.json +49 -49
- package/files/conf/command-service.json +73 -73
- package/files/conf/config.json +31 -22
- package/files/conf/ipk.json +30 -30
- package/files/conf/novacom-devices.json +35 -35
- package/files/conf/query/query-app.json +14 -14
- package/files/conf/query/query-hosted.json +18 -18
- package/files/conf/query/query-package.json +10 -10
- package/files/conf/query/query-service.json +6 -6
- package/files/conf/sdk.json +8 -8
- package/files/conf/template.json +57 -57
- package/files/conf/webos_emul +27 -27
- package/files/conf-base/env/sdk-ose.json +8 -8
- package/files/conf-base/env/sdk-tv.json +8 -8
- package/files/conf-base/profile/config-ose.json +29 -21
- package/files/conf-base/profile/config-tv.json +31 -22
- package/files/conf-base/query/query-app.json +14 -14
- package/files/conf-base/query/query-hosted.json +18 -18
- package/files/conf-base/query/query-package.json +10 -10
- package/files/conf-base/query/query-service.json +6 -6
- package/files/conf-base/template-conf/ose-templates.json +67 -67
- package/files/conf-base/template-conf/tv-sdk-templates.json +57 -57
- package/files/help/ares-config.help +43 -43
- package/files/help/ares-device.help +94 -94
- package/files/help/ares-generate.help +65 -65
- package/files/help/ares-inspect.help +70 -70
- package/files/help/ares-install.help +90 -90
- package/files/help/ares-launch.help +100 -100
- package/files/help/ares-log-pmlogd.help +84 -84
- package/files/help/ares-log.help +101 -101
- package/files/help/ares-novacom.help +68 -68
- package/files/help/ares-package.help +101 -101
- package/files/help/ares-pull.help +38 -38
- package/files/help/ares-push.help +38 -38
- package/files/help/ares-server.help +39 -39
- package/files/help/ares-setup-device.help +116 -75
- package/files/help/ares-shell.help +42 -42
- package/files/help/ares.help +47 -47
- package/files/help/readme.help +23 -23
- package/files/schema/ApplicationDescription.schema +319 -319
- package/files/schema/NovacomDevices.schema +61 -61
- package/files/templates/ose-sdk-templates/appinfo/appinfo.json +10 -10
- package/files/templates/ose-sdk-templates/bootplate-web/index.html +88 -88
- package/files/templates/ose-sdk-templates/hosted-webapp/index.html +13 -13
- package/files/templates/ose-sdk-templates/icon/icon.png +0 -0
- package/files/templates/ose-sdk-templates/js-service/helloclient.js +31 -31
- package/files/templates/ose-sdk-templates/js-service/helloworld_webos_service.js +188 -188
- package/files/templates/ose-sdk-templates/qml-app/main.qml +68 -68
- package/files/templates/ose-sdk-templates/qmlappinfo/appinfo.json +10 -10
- package/files/templates/ose-sdk-templates/serviceinfo/package.json +11 -11
- package/files/templates/ose-sdk-templates/serviceinfo/services.json +8 -8
- package/files/templates/tv-sdk-templates/appinfo/appinfo.json +10 -10
- package/files/templates/tv-sdk-templates/bootplate-web/index.html +58 -58
- package/files/templates/tv-sdk-templates/bootplate-web/webOSTVjs-1.2.10/LICENSE-2.0.txt +202 -202
- package/files/templates/tv-sdk-templates/hosted-webapp/index.html +14 -14
- package/files/templates/tv-sdk-templates/js-service/helloworld_service.js +39 -39
- package/files/templates/tv-sdk-templates/packageinfo/packageinfo.json +3 -3
- package/files/templates/tv-sdk-templates/serviceinfo/package.json +11 -11
- package/files/templates/tv-sdk-templates/serviceinfo/services.json +8 -8
- package/files/templates/tv-sdk-templates/webicon/icon.png +0 -0
- package/files/templates/tv-sdk-templates/webicon/largeIcon.png +0 -0
- package/lib/base/ares.html +40 -40
- package/lib/base/cli-appdata.js +290 -290
- package/lib/base/cli-control.js +44 -44
- package/lib/base/common-tools.js +29 -29
- package/lib/base/error-handler.js +265 -265
- package/lib/base/file-watcher.js +155 -155
- package/lib/base/help-format.js +147 -147
- package/lib/base/luna.js +178 -178
- package/lib/base/novacom.js +1191 -1191
- package/lib/base/sdkenv.js +59 -59
- package/lib/base/server.js +137 -137
- package/lib/base/setup-device.js +335 -328
- package/lib/base/version-tools.js +79 -79
- package/lib/device.js +1419 -1419
- package/lib/generator.js +377 -377
- package/lib/inspect.js +494 -494
- package/lib/install.js +463 -463
- package/lib/launch.js +605 -605
- package/lib/log.js +584 -584
- package/lib/package.js +2147 -2129
- package/lib/pull.js +231 -231
- package/lib/pusher.js +210 -210
- package/lib/session.js +74 -74
- package/lib/shell.js +193 -193
- package/lib/tar-filter-pack.js +62 -62
- package/lib/util/copy.js +31 -31
- package/lib/util/createFileName.js +40 -40
- package/lib/util/eof.js +30 -30
- package/lib/util/json.js +63 -63
- package/lib/util/merge.js +14 -14
- package/lib/util/objclone.js +40 -40
- package/lib/util/spinner.js +37 -37
- package/npm-shrinkwrap.json +9242 -9116
- package/package.json +100 -100
- package/scripts/postinstall.js +24 -24
- package/spec/helpers/reporter.js +65 -65
- package/spec/jsSpecs/apiTest/generator.spec.js +372 -372
- package/spec/jsSpecs/apiTest/inspector.spec.js +89 -89
- package/spec/jsSpecs/apiTest/installer.spec.js +67 -67
- package/spec/jsSpecs/apiTest/launcher.spec.js +150 -150
- package/spec/jsSpecs/apiTest/packager.spec.js +194 -194
- package/spec/jsSpecs/apiTest/puller.spec.js +101 -101
- package/spec/jsSpecs/apiTest/pusher.spec.js +103 -103
- package/spec/jsSpecs/apiTest/server.spec.js +115 -115
- package/spec/jsSpecs/apiTest/setupDevice.spec.js +93 -93
- package/spec/jsSpecs/apiTest/shell.spec.js +49 -49
- package/spec/jsSpecs/ares-config.spec.js +78 -78
- package/spec/jsSpecs/ares-device.spec.js +443 -443
- package/spec/jsSpecs/ares-generate.spec.js +397 -397
- package/spec/jsSpecs/ares-inspect.spec.js +252 -252
- package/spec/jsSpecs/ares-install.spec.js +150 -150
- package/spec/jsSpecs/ares-launch.spec.js +301 -301
- package/spec/jsSpecs/ares-log.spec.js +824 -824
- package/spec/jsSpecs/ares-novacom.spec.js +149 -149
- package/spec/jsSpecs/ares-package.spec.js +1211 -1211
- package/spec/jsSpecs/ares-pull.spec.js +157 -157
- package/spec/jsSpecs/ares-push.spec.js +146 -146
- package/spec/jsSpecs/ares-server.spec.js +160 -160
- package/spec/jsSpecs/ares-setup-device.spec.js +300 -281
- package/spec/jsSpecs/ares-shell.spec.js +220 -220
- package/spec/jsSpecs/ares.spec.js +83 -83
- package/spec/jsSpecs/common-spec.js +169 -169
- package/spec/support/jasmine.json +22 -22
- package/spec/tempFiles/nativeApp/auto/pkg_arm64/GLES2 +0 -0
- package/spec/tempFiles/nativeApp/auto/pkg_arm64/appinfo.json +9 -9
- package/spec/tempFiles/nativeApp/ose/pkg_arm/Hello +0 -0
- package/spec/tempFiles/nativeApp/ose/pkg_arm/appinfo.json +8 -8
- package/spec/tempFiles/nativeApp/ose/pkg_arm/package.properties +2 -2
- package/spec/tempFiles/nativeApp/oseEmul/pkg_x86/Hello +0 -0
- package/spec/tempFiles/nativeApp/oseEmul/pkg_x86/appinfo.json +9 -9
- package/spec/tempFiles/nativeApp/rsi/pkg_x86/GLES2 +0 -0
- package/spec/tempFiles/nativeApp/rsi/pkg_x86/appinfo.json +9 -9
- package/spec/tempFiles/sign/sign.crt +32 -32
- package/spec/tempFiles/sign/signPriv.key +52 -52
- package/spec/test_data/ares-generate.json +41 -41
- package/spec/test_data/ares.json +33 -33
package/lib/base/cli-appdata.js
CHANGED
|
@@ -1,290 +1,290 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2020-2024 LG Electronics Inc.
|
|
3
|
-
*
|
|
4
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const fs = require('fs'),
|
|
8
|
-
Validator = require('jsonschema').Validator,
|
|
9
|
-
mkdirp = require('mkdirp'),
|
|
10
|
-
log = require('npmlog'),
|
|
11
|
-
path = require('path'),
|
|
12
|
-
shelljs = require('shelljs'),
|
|
13
|
-
errHndl = require('./error-handler.js'),
|
|
14
|
-
clone = require('./../util/objclone').deepCopy;
|
|
15
|
-
|
|
16
|
-
const Cli = (function() {
|
|
17
|
-
let instance;
|
|
18
|
-
|
|
19
|
-
function finish(err, returnValue, next) {
|
|
20
|
-
if (next && typeof next === 'function') {
|
|
21
|
-
if (!returnValue) {
|
|
22
|
-
return setImmediate(next, err);
|
|
23
|
-
}
|
|
24
|
-
return setImmediate(next, err, returnValue);
|
|
25
|
-
}
|
|
26
|
-
return err || returnValue;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function init() {
|
|
30
|
-
const
|
|
31
|
-
workParentDir = path.resolve(process.env.APPDATA || process.env.HOME || process.env.USERPROFILE),
|
|
32
|
-
builtinFiles = {
|
|
33
|
-
"config": {
|
|
34
|
-
"dir": path.join(__dirname, "../../files", "conf"),
|
|
35
|
-
"file": "config.json"
|
|
36
|
-
},
|
|
37
|
-
"commands": {
|
|
38
|
-
"dir": path.join(__dirname, "../../files", "conf"),
|
|
39
|
-
"file": "command-service.json"
|
|
40
|
-
},
|
|
41
|
-
"deviceList": {
|
|
42
|
-
"dir": path.join(__dirname, "../../files", "conf"),
|
|
43
|
-
"file": "novacom-devices.json"
|
|
44
|
-
},
|
|
45
|
-
"deviceListSchema": {
|
|
46
|
-
"dir": path.join(__dirname, "../../files", "schema"),
|
|
47
|
-
"file": "NovacomDevices.schema"
|
|
48
|
-
},
|
|
49
|
-
"template": {
|
|
50
|
-
"dir": path.join(__dirname, "../../files", "conf"),
|
|
51
|
-
"file": "template.json"
|
|
52
|
-
},
|
|
53
|
-
"env": {
|
|
54
|
-
"dir": path.join(__dirname, "../../files", "conf"),
|
|
55
|
-
"file": "sdk.json"
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
queryPath = path.join(__dirname, "../../files/conf/query");
|
|
59
|
-
|
|
60
|
-
function _store(store, n, file) {
|
|
61
|
-
store[n] = JSON.parse(fs.readFileSync(file));
|
|
62
|
-
store[n + 'File'] = file;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
for (const key in builtinFiles) {
|
|
66
|
-
const filePath = path.join(builtinFiles[key].dir, builtinFiles[key].file);
|
|
67
|
-
_store(this, key, filePath);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
workDir = (this.config.dataDir) ? path.join(workParentDir, this.config.dataDir) : path.join(workParentDir, '.webos'),
|
|
72
|
-
builtinDeviceListFile = path.join(builtinFiles.deviceList.dir, builtinFiles.deviceList.file),
|
|
73
|
-
userDeviceListFile = path.join(workDir, builtinFiles.deviceList.file);
|
|
74
|
-
|
|
75
|
-
if (!fs.existsSync(workDir)) {
|
|
76
|
-
mkdirp.sync(workDir);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
const userDeviceList = JSON.parse(fs.readFileSync(userDeviceListFile)),
|
|
81
|
-
result = validateDevice(this.deviceListSchema, userDeviceList);
|
|
82
|
-
|
|
83
|
-
if (result && result.resultValue) {
|
|
84
|
-
this.deviceList = userDeviceList;
|
|
85
|
-
} else {
|
|
86
|
-
log.verbose("cli-appdata#init()", "schema check failure:", userDeviceListFile);
|
|
87
|
-
log.verbose("cli-appdata#init()", "result:", result);
|
|
88
|
-
log.verbose("cli-appdata#init()", "copy " + builtinDeviceListFile + " to " + userDeviceListFile);
|
|
89
|
-
shelljs.cp('-f', builtinDeviceListFile, userDeviceListFile);
|
|
90
|
-
}
|
|
91
|
-
} catch (err) {
|
|
92
|
-
log.verbose("cli-appdata#init()", "err:", err);
|
|
93
|
-
log.verbose("cli-appdata#init()", "copy " + builtinDeviceListFile + " to " + userDeviceListFile);
|
|
94
|
-
shelljs.cp('-f', builtinDeviceListFile, userDeviceListFile);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
this.builtinDeviceListFile = builtinDeviceListFile;
|
|
98
|
-
this.deviceListFile = userDeviceListFile;
|
|
99
|
-
this.workDir = workDir;
|
|
100
|
-
this.queryPath = queryPath;
|
|
101
|
-
if (this.config.simulatorConfig) {
|
|
102
|
-
this.simulatorConfigPath = path.join(workDir, this.config.simulatorConfig);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function validateDevice(schema, data) {
|
|
109
|
-
let result = {
|
|
110
|
-
resultValue: false,
|
|
111
|
-
err: null
|
|
112
|
-
};
|
|
113
|
-
const schemaArray = {
|
|
114
|
-
"id": "test",
|
|
115
|
-
"type": "array",
|
|
116
|
-
"items": {
|
|
117
|
-
"$ref": "/deviceSchema"
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
const v = new Validator();
|
|
121
|
-
|
|
122
|
-
try {
|
|
123
|
-
v.addSchema(schema, "/deviceSchema");
|
|
124
|
-
result = v.validate(data, schemaArray);
|
|
125
|
-
if (result && result.errors.length > 0) {
|
|
126
|
-
let errMsg = "Invalid device info.";
|
|
127
|
-
for (const idx in result.errors) {
|
|
128
|
-
errMsg = errMsg.concat("\n");
|
|
129
|
-
let res,
|
|
130
|
-
errMsgLine = result.errors[idx].property + " " + result.errors[idx].message;
|
|
131
|
-
const regex = /instance\[*.*\]*\./g;
|
|
132
|
-
if ((res = regex.exec(errMsgLine)) !== null) {
|
|
133
|
-
errMsgLine = errMsgLine.substring(res[0].length);
|
|
134
|
-
}
|
|
135
|
-
errMsg = errMsg.concat(errMsgLine);
|
|
136
|
-
}
|
|
137
|
-
result.err = new Error(errMsg);
|
|
138
|
-
} else {
|
|
139
|
-
result.resultValue = true;
|
|
140
|
-
}
|
|
141
|
-
} catch (err) {
|
|
142
|
-
// ignore exception
|
|
143
|
-
result.err = err;
|
|
144
|
-
}
|
|
145
|
-
return result;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function CliAppData() {
|
|
149
|
-
if (instance) {
|
|
150
|
-
return instance;
|
|
151
|
-
}
|
|
152
|
-
instance = this;
|
|
153
|
-
if (!this.inialized) {
|
|
154
|
-
this.inialized = init.call(this);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
CliAppData.prototype = {
|
|
159
|
-
getSimulatorConfigPath: function(next) {
|
|
160
|
-
return finish(null, this.simulatorConfigPath, next);
|
|
161
|
-
},
|
|
162
|
-
|
|
163
|
-
getPath: function(next) {
|
|
164
|
-
return finish(null, this.workDir, next);
|
|
165
|
-
},
|
|
166
|
-
|
|
167
|
-
getAppDir: function(next) {
|
|
168
|
-
return finish(null, path.join(__dirname, '..'), next);
|
|
169
|
-
},
|
|
170
|
-
|
|
171
|
-
getConfig: function(next) {
|
|
172
|
-
return finish(null, clone(this.config), next);
|
|
173
|
-
},
|
|
174
|
-
|
|
175
|
-
compareProfile: function(query, next) {
|
|
176
|
-
next(null, query.toLowerCase() === this.config.profile.toLowerCase());
|
|
177
|
-
},
|
|
178
|
-
|
|
179
|
-
compareProfileSync: function(query) {
|
|
180
|
-
return query.toLowerCase() === this.config.profile.toLowerCase();
|
|
181
|
-
},
|
|
182
|
-
|
|
183
|
-
getDeviceList: function(renewal, next) {
|
|
184
|
-
return finish(null, clone(this.deviceList), next);
|
|
185
|
-
},
|
|
186
|
-
|
|
187
|
-
getCommandService: function(next) {
|
|
188
|
-
return finish(null, clone(this.commands), next);
|
|
189
|
-
},
|
|
190
|
-
|
|
191
|
-
setDeviceList: function(deviceListData, next) {
|
|
192
|
-
log.info("cli-appdata#CliAppData#setDeviceList()");
|
|
193
|
-
try {
|
|
194
|
-
const result = validateDevice(this.deviceListSchema, deviceListData);
|
|
195
|
-
if (result && !result.resultValue) {
|
|
196
|
-
const err = result.err || "invalid data";
|
|
197
|
-
return finish(err, this.deviceList, next);
|
|
198
|
-
}
|
|
199
|
-
this.deviceList = deviceListData;
|
|
200
|
-
fs.writeFileSync(this.deviceListFile, JSON.stringify(this.deviceList, null, Number(4)));
|
|
201
|
-
} catch (err) {
|
|
202
|
-
return finish(err, this.deviceList, next);
|
|
203
|
-
}
|
|
204
|
-
return finish(null, this.deviceList, next);
|
|
205
|
-
},
|
|
206
|
-
|
|
207
|
-
setConfig: function(configData, next) {
|
|
208
|
-
try {
|
|
209
|
-
this.config = configData;
|
|
210
|
-
fs.writeFileSync(this.configFile, JSON.stringify(this.config, null, Number(4)) + "\n");
|
|
211
|
-
} catch (err) {
|
|
212
|
-
return finish(err, this.config, next);
|
|
213
|
-
}
|
|
214
|
-
return finish(null, this.config, next);
|
|
215
|
-
},
|
|
216
|
-
|
|
217
|
-
setTemplate: function(templateData, next) {
|
|
218
|
-
try {
|
|
219
|
-
this.template = templateData;
|
|
220
|
-
fs.writeFileSync(this.templateFile, JSON.stringify(this.template, null, Number(4)) + "\n");
|
|
221
|
-
} catch (err) {
|
|
222
|
-
return finish(err, this.template, next);
|
|
223
|
-
}
|
|
224
|
-
},
|
|
225
|
-
|
|
226
|
-
setEnv: function(envData, next) {
|
|
227
|
-
try {
|
|
228
|
-
this.env = envData;
|
|
229
|
-
fs.writeFileSync(this.envFile, JSON.stringify(this.env, null, Number(4)) + "\n");
|
|
230
|
-
} catch (err) {
|
|
231
|
-
return finish(err, this.env, next);
|
|
232
|
-
}
|
|
233
|
-
},
|
|
234
|
-
|
|
235
|
-
setKey: function(keyPath, next) {
|
|
236
|
-
try {
|
|
237
|
-
const dstPubkey = path.join(__dirname, "../../files/conf", "pubkey.pem");
|
|
238
|
-
if (fs.existsSync(dstPubkey)) {
|
|
239
|
-
shelljs.rm(dstPubkey);
|
|
240
|
-
}
|
|
241
|
-
if (keyPath) {
|
|
242
|
-
shelljs.cp(keyPath, dstPubkey);
|
|
243
|
-
}
|
|
244
|
-
} catch (err) {
|
|
245
|
-
return finish(errHndl.getErrMsg(err), keyPath, next);
|
|
246
|
-
}
|
|
247
|
-
return finish(null, keyPath, next);
|
|
248
|
-
},
|
|
249
|
-
|
|
250
|
-
setQuery: function(queryBasePath, next) {
|
|
251
|
-
try {
|
|
252
|
-
if (fs.existsSync(this.queryPath)) {
|
|
253
|
-
shelljs.ls(this.queryPath).forEach(function(file) {
|
|
254
|
-
shelljs.rm(path.join(__dirname, "../../files/conf/query",file));
|
|
255
|
-
});
|
|
256
|
-
} else {
|
|
257
|
-
fs.mkdirSync(this.queryPath);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
shelljs.ls(queryBasePath+'/*.json').forEach(function(file) {
|
|
261
|
-
shelljs.cp(file, path.join(__dirname, "../../files/conf", "query"));
|
|
262
|
-
});
|
|
263
|
-
} catch (err) {
|
|
264
|
-
return finish(err, this.queryPath, next);
|
|
265
|
-
}
|
|
266
|
-
return finish(null, this.queryPath, next);
|
|
267
|
-
},
|
|
268
|
-
|
|
269
|
-
resetDeviceList: function(next) {
|
|
270
|
-
log.info("cli-appdata#CliAppData#resetDeviceList()");
|
|
271
|
-
try {
|
|
272
|
-
if (fs.existsSync(this.deviceListFile)) {
|
|
273
|
-
shelljs.rm(this.deviceListFile);
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
shelljs.cp(this.builtinDeviceListFile, this.deviceListFile);
|
|
277
|
-
this.deviceList = JSON.parse(fs.readFileSync(this.deviceListFile));
|
|
278
|
-
} catch (err) {
|
|
279
|
-
log.verbose("cli-appdata#CliAppData#resetDeviceList()", "err:", err);
|
|
280
|
-
return finish(err, clone(this.deviceList), next);
|
|
281
|
-
}
|
|
282
|
-
return finish(null, clone(this.deviceList), next);
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
return CliAppData;
|
|
286
|
-
}());
|
|
287
|
-
|
|
288
|
-
if (typeof module !== 'undefined' && module.exports) {
|
|
289
|
-
module.exports = Cli;
|
|
290
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2020-2024 LG Electronics Inc.
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const fs = require('fs'),
|
|
8
|
+
Validator = require('jsonschema').Validator,
|
|
9
|
+
mkdirp = require('mkdirp'),
|
|
10
|
+
log = require('npmlog'),
|
|
11
|
+
path = require('path'),
|
|
12
|
+
shelljs = require('shelljs'),
|
|
13
|
+
errHndl = require('./error-handler.js'),
|
|
14
|
+
clone = require('./../util/objclone').deepCopy;
|
|
15
|
+
|
|
16
|
+
const Cli = (function() {
|
|
17
|
+
let instance;
|
|
18
|
+
|
|
19
|
+
function finish(err, returnValue, next) {
|
|
20
|
+
if (next && typeof next === 'function') {
|
|
21
|
+
if (!returnValue) {
|
|
22
|
+
return setImmediate(next, err);
|
|
23
|
+
}
|
|
24
|
+
return setImmediate(next, err, returnValue);
|
|
25
|
+
}
|
|
26
|
+
return err || returnValue;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function init() {
|
|
30
|
+
const
|
|
31
|
+
workParentDir = path.resolve(process.env.APPDATA || process.env.HOME || process.env.USERPROFILE),
|
|
32
|
+
builtinFiles = {
|
|
33
|
+
"config": {
|
|
34
|
+
"dir": path.join(__dirname, "../../files", "conf"),
|
|
35
|
+
"file": "config.json"
|
|
36
|
+
},
|
|
37
|
+
"commands": {
|
|
38
|
+
"dir": path.join(__dirname, "../../files", "conf"),
|
|
39
|
+
"file": "command-service.json"
|
|
40
|
+
},
|
|
41
|
+
"deviceList": {
|
|
42
|
+
"dir": path.join(__dirname, "../../files", "conf"),
|
|
43
|
+
"file": "novacom-devices.json"
|
|
44
|
+
},
|
|
45
|
+
"deviceListSchema": {
|
|
46
|
+
"dir": path.join(__dirname, "../../files", "schema"),
|
|
47
|
+
"file": "NovacomDevices.schema"
|
|
48
|
+
},
|
|
49
|
+
"template": {
|
|
50
|
+
"dir": path.join(__dirname, "../../files", "conf"),
|
|
51
|
+
"file": "template.json"
|
|
52
|
+
},
|
|
53
|
+
"env": {
|
|
54
|
+
"dir": path.join(__dirname, "../../files", "conf"),
|
|
55
|
+
"file": "sdk.json"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
queryPath = path.join(__dirname, "../../files/conf/query");
|
|
59
|
+
|
|
60
|
+
function _store(store, n, file) {
|
|
61
|
+
store[n] = JSON.parse(fs.readFileSync(file));
|
|
62
|
+
store[n + 'File'] = file;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
for (const key in builtinFiles) {
|
|
66
|
+
const filePath = path.join(builtinFiles[key].dir, builtinFiles[key].file);
|
|
67
|
+
_store(this, key, filePath);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const
|
|
71
|
+
workDir = (this.config.dataDir) ? path.join(workParentDir, this.config.dataDir) : path.join(workParentDir, '.webos'),
|
|
72
|
+
builtinDeviceListFile = path.join(builtinFiles.deviceList.dir, builtinFiles.deviceList.file),
|
|
73
|
+
userDeviceListFile = path.join(workDir, builtinFiles.deviceList.file);
|
|
74
|
+
|
|
75
|
+
if (!fs.existsSync(workDir)) {
|
|
76
|
+
mkdirp.sync(workDir);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
const userDeviceList = JSON.parse(fs.readFileSync(userDeviceListFile)),
|
|
81
|
+
result = validateDevice(this.deviceListSchema, userDeviceList);
|
|
82
|
+
|
|
83
|
+
if (result && result.resultValue) {
|
|
84
|
+
this.deviceList = userDeviceList;
|
|
85
|
+
} else {
|
|
86
|
+
log.verbose("cli-appdata#init()", "schema check failure:", userDeviceListFile);
|
|
87
|
+
log.verbose("cli-appdata#init()", "result:", result);
|
|
88
|
+
log.verbose("cli-appdata#init()", "copy " + builtinDeviceListFile + " to " + userDeviceListFile);
|
|
89
|
+
shelljs.cp('-f', builtinDeviceListFile, userDeviceListFile);
|
|
90
|
+
}
|
|
91
|
+
} catch (err) {
|
|
92
|
+
log.verbose("cli-appdata#init()", "err:", err);
|
|
93
|
+
log.verbose("cli-appdata#init()", "copy " + builtinDeviceListFile + " to " + userDeviceListFile);
|
|
94
|
+
shelljs.cp('-f', builtinDeviceListFile, userDeviceListFile);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
this.builtinDeviceListFile = builtinDeviceListFile;
|
|
98
|
+
this.deviceListFile = userDeviceListFile;
|
|
99
|
+
this.workDir = workDir;
|
|
100
|
+
this.queryPath = queryPath;
|
|
101
|
+
if (this.config.simulatorConfig) {
|
|
102
|
+
this.simulatorConfigPath = path.join(workDir, this.config.simulatorConfig);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function validateDevice(schema, data) {
|
|
109
|
+
let result = {
|
|
110
|
+
resultValue: false,
|
|
111
|
+
err: null
|
|
112
|
+
};
|
|
113
|
+
const schemaArray = {
|
|
114
|
+
"id": "test",
|
|
115
|
+
"type": "array",
|
|
116
|
+
"items": {
|
|
117
|
+
"$ref": "/deviceSchema"
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
const v = new Validator();
|
|
121
|
+
|
|
122
|
+
try {
|
|
123
|
+
v.addSchema(schema, "/deviceSchema");
|
|
124
|
+
result = v.validate(data, schemaArray);
|
|
125
|
+
if (result && result.errors.length > 0) {
|
|
126
|
+
let errMsg = "Invalid device info.";
|
|
127
|
+
for (const idx in result.errors) {
|
|
128
|
+
errMsg = errMsg.concat("\n");
|
|
129
|
+
let res,
|
|
130
|
+
errMsgLine = result.errors[idx].property + " " + result.errors[idx].message;
|
|
131
|
+
const regex = /instance\[*.*\]*\./g;
|
|
132
|
+
if ((res = regex.exec(errMsgLine)) !== null) {
|
|
133
|
+
errMsgLine = errMsgLine.substring(res[0].length);
|
|
134
|
+
}
|
|
135
|
+
errMsg = errMsg.concat(errMsgLine);
|
|
136
|
+
}
|
|
137
|
+
result.err = new Error(errMsg);
|
|
138
|
+
} else {
|
|
139
|
+
result.resultValue = true;
|
|
140
|
+
}
|
|
141
|
+
} catch (err) {
|
|
142
|
+
// ignore exception
|
|
143
|
+
result.err = err;
|
|
144
|
+
}
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function CliAppData() {
|
|
149
|
+
if (instance) {
|
|
150
|
+
return instance;
|
|
151
|
+
}
|
|
152
|
+
instance = this;
|
|
153
|
+
if (!this.inialized) {
|
|
154
|
+
this.inialized = init.call(this);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
CliAppData.prototype = {
|
|
159
|
+
getSimulatorConfigPath: function(next) {
|
|
160
|
+
return finish(null, this.simulatorConfigPath, next);
|
|
161
|
+
},
|
|
162
|
+
|
|
163
|
+
getPath: function(next) {
|
|
164
|
+
return finish(null, this.workDir, next);
|
|
165
|
+
},
|
|
166
|
+
|
|
167
|
+
getAppDir: function(next) {
|
|
168
|
+
return finish(null, path.join(__dirname, '..'), next);
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
getConfig: function(next) {
|
|
172
|
+
return finish(null, clone(this.config), next);
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
compareProfile: function(query, next) {
|
|
176
|
+
next(null, query.toLowerCase() === this.config.profile.toLowerCase());
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
compareProfileSync: function(query) {
|
|
180
|
+
return query.toLowerCase() === this.config.profile.toLowerCase();
|
|
181
|
+
},
|
|
182
|
+
|
|
183
|
+
getDeviceList: function(renewal, next) {
|
|
184
|
+
return finish(null, clone(this.deviceList), next);
|
|
185
|
+
},
|
|
186
|
+
|
|
187
|
+
getCommandService: function(next) {
|
|
188
|
+
return finish(null, clone(this.commands), next);
|
|
189
|
+
},
|
|
190
|
+
|
|
191
|
+
setDeviceList: function(deviceListData, next) {
|
|
192
|
+
log.info("cli-appdata#CliAppData#setDeviceList()");
|
|
193
|
+
try {
|
|
194
|
+
const result = validateDevice(this.deviceListSchema, deviceListData);
|
|
195
|
+
if (result && !result.resultValue) {
|
|
196
|
+
const err = result.err || "invalid data";
|
|
197
|
+
return finish(err, this.deviceList, next);
|
|
198
|
+
}
|
|
199
|
+
this.deviceList = deviceListData;
|
|
200
|
+
fs.writeFileSync(this.deviceListFile, JSON.stringify(this.deviceList, null, Number(4)));
|
|
201
|
+
} catch (err) {
|
|
202
|
+
return finish(err, this.deviceList, next);
|
|
203
|
+
}
|
|
204
|
+
return finish(null, this.deviceList, next);
|
|
205
|
+
},
|
|
206
|
+
|
|
207
|
+
setConfig: function(configData, next) {
|
|
208
|
+
try {
|
|
209
|
+
this.config = configData;
|
|
210
|
+
fs.writeFileSync(this.configFile, JSON.stringify(this.config, null, Number(4)) + "\n");
|
|
211
|
+
} catch (err) {
|
|
212
|
+
return finish(err, this.config, next);
|
|
213
|
+
}
|
|
214
|
+
return finish(null, this.config, next);
|
|
215
|
+
},
|
|
216
|
+
|
|
217
|
+
setTemplate: function(templateData, next) {
|
|
218
|
+
try {
|
|
219
|
+
this.template = templateData;
|
|
220
|
+
fs.writeFileSync(this.templateFile, JSON.stringify(this.template, null, Number(4)) + "\n");
|
|
221
|
+
} catch (err) {
|
|
222
|
+
return finish(err, this.template, next);
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
|
|
226
|
+
setEnv: function(envData, next) {
|
|
227
|
+
try {
|
|
228
|
+
this.env = envData;
|
|
229
|
+
fs.writeFileSync(this.envFile, JSON.stringify(this.env, null, Number(4)) + "\n");
|
|
230
|
+
} catch (err) {
|
|
231
|
+
return finish(err, this.env, next);
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
|
|
235
|
+
setKey: function(keyPath, next) {
|
|
236
|
+
try {
|
|
237
|
+
const dstPubkey = path.join(__dirname, "../../files/conf", "pubkey.pem");
|
|
238
|
+
if (fs.existsSync(dstPubkey)) {
|
|
239
|
+
shelljs.rm(dstPubkey);
|
|
240
|
+
}
|
|
241
|
+
if (keyPath) {
|
|
242
|
+
shelljs.cp(keyPath, dstPubkey);
|
|
243
|
+
}
|
|
244
|
+
} catch (err) {
|
|
245
|
+
return finish(errHndl.getErrMsg(err), keyPath, next);
|
|
246
|
+
}
|
|
247
|
+
return finish(null, keyPath, next);
|
|
248
|
+
},
|
|
249
|
+
|
|
250
|
+
setQuery: function(queryBasePath, next) {
|
|
251
|
+
try {
|
|
252
|
+
if (fs.existsSync(this.queryPath)) {
|
|
253
|
+
shelljs.ls(this.queryPath).forEach(function(file) {
|
|
254
|
+
shelljs.rm(path.join(__dirname, "../../files/conf/query",file));
|
|
255
|
+
});
|
|
256
|
+
} else {
|
|
257
|
+
fs.mkdirSync(this.queryPath);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
shelljs.ls(queryBasePath+'/*.json').forEach(function(file) {
|
|
261
|
+
shelljs.cp(file, path.join(__dirname, "../../files/conf", "query"));
|
|
262
|
+
});
|
|
263
|
+
} catch (err) {
|
|
264
|
+
return finish(err, this.queryPath, next);
|
|
265
|
+
}
|
|
266
|
+
return finish(null, this.queryPath, next);
|
|
267
|
+
},
|
|
268
|
+
|
|
269
|
+
resetDeviceList: function(next) {
|
|
270
|
+
log.info("cli-appdata#CliAppData#resetDeviceList()");
|
|
271
|
+
try {
|
|
272
|
+
if (fs.existsSync(this.deviceListFile)) {
|
|
273
|
+
shelljs.rm(this.deviceListFile);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
shelljs.cp(this.builtinDeviceListFile, this.deviceListFile);
|
|
277
|
+
this.deviceList = JSON.parse(fs.readFileSync(this.deviceListFile));
|
|
278
|
+
} catch (err) {
|
|
279
|
+
log.verbose("cli-appdata#CliAppData#resetDeviceList()", "err:", err);
|
|
280
|
+
return finish(err, clone(this.deviceList), next);
|
|
281
|
+
}
|
|
282
|
+
return finish(null, clone(this.deviceList), next);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
return CliAppData;
|
|
286
|
+
}());
|
|
287
|
+
|
|
288
|
+
if (typeof module !== 'undefined' && module.exports) {
|
|
289
|
+
module.exports = Cli;
|
|
290
|
+
}
|
package/lib/base/cli-control.js
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2020-2024 LG Electronics Inc.
|
|
3
|
-
*
|
|
4
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
(function() {
|
|
8
|
-
const cliControl = {};
|
|
9
|
-
|
|
10
|
-
cliControl.end = function(exitCode) {
|
|
11
|
-
let draining = 0;
|
|
12
|
-
const streams = [process.stdout, process.stderr],
|
|
13
|
-
exit = function() {
|
|
14
|
-
if (!(draining--)) {
|
|
15
|
-
process.exit(exitCode || 0);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
streams.forEach(function(stream) {
|
|
20
|
-
draining += 1;
|
|
21
|
-
stream.write('', exit);
|
|
22
|
-
});
|
|
23
|
-
exit();
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
if (process.stdin) {
|
|
27
|
-
const reqExit = "@ARES-CLOSE@";
|
|
28
|
-
process.stdin.on("data", function(data) {
|
|
29
|
-
let str;
|
|
30
|
-
if (Buffer.isBuffer(data)) {
|
|
31
|
-
str = data.toString();
|
|
32
|
-
} else {
|
|
33
|
-
str = data;
|
|
34
|
-
}
|
|
35
|
-
if (str.trim() === reqExit) {
|
|
36
|
-
cliControl.end(0);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (typeof module !== 'undefined' && module.exports) {
|
|
42
|
-
module.exports = cliControl;
|
|
43
|
-
}
|
|
44
|
-
}());
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2020-2024 LG Electronics Inc.
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
(function() {
|
|
8
|
+
const cliControl = {};
|
|
9
|
+
|
|
10
|
+
cliControl.end = function(exitCode) {
|
|
11
|
+
let draining = 0;
|
|
12
|
+
const streams = [process.stdout, process.stderr],
|
|
13
|
+
exit = function() {
|
|
14
|
+
if (!(draining--)) {
|
|
15
|
+
process.exit(exitCode || 0);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
streams.forEach(function(stream) {
|
|
20
|
+
draining += 1;
|
|
21
|
+
stream.write('', exit);
|
|
22
|
+
});
|
|
23
|
+
exit();
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
if (process.stdin) {
|
|
27
|
+
const reqExit = "@ARES-CLOSE@";
|
|
28
|
+
process.stdin.on("data", function(data) {
|
|
29
|
+
let str;
|
|
30
|
+
if (Buffer.isBuffer(data)) {
|
|
31
|
+
str = data.toString();
|
|
32
|
+
} else {
|
|
33
|
+
str = data;
|
|
34
|
+
}
|
|
35
|
+
if (str.trim() === reqExit) {
|
|
36
|
+
cliControl.end(0);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (typeof module !== 'undefined' && module.exports) {
|
|
42
|
+
module.exports = cliControl;
|
|
43
|
+
}
|
|
44
|
+
}());
|