@webos-tools/cli 3.1.1 → 3.1.3

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.
Files changed (53) hide show
  1. package/CHANGELOG.md +173 -157
  2. package/LICENSES/342/200/216/LicenseRef-3rd_party_licenses.txt +1355 -0
  3. package/README.md +21 -19
  4. package/bin/ares-config.js +6 -3
  5. package/bin/ares-device.js +2 -2
  6. package/bin/ares-log.js +6 -2
  7. package/bin/ares-pull.js +1 -1
  8. package/bin/ares-push.js +1 -1
  9. package/bin/ares-setup-device.js +573 -528
  10. package/bin/ares-shell.js +1 -1
  11. package/bin/ares.js +1 -1
  12. package/files/conf/ares.json +5 -5
  13. package/files/conf/novacom-devices.json +18 -1
  14. package/files/conf-base/env/sdk-apollo.json +8 -0
  15. package/files/conf-base/profile/config-apollo.json +29 -0
  16. package/files/conf-base/profile/config-ose.json +1 -1
  17. package/files/conf-base/template-conf/apollo-sdk-templates.json +56 -0
  18. package/files/help/ares-config.help +6 -1
  19. package/files/help/ares-device.help +15 -0
  20. package/files/help/ares-generate.help +27 -1
  21. package/files/help/ares-inspect.help +6 -0
  22. package/files/help/ares-install.help +5 -0
  23. package/files/help/ares-launch.help +5 -0
  24. package/files/help/ares-server.help +5 -0
  25. package/files/help/ares-setup-device.help +40 -0
  26. package/files/help/ares.help +5 -0
  27. package/files/schema/NovacomDevices.schema +2 -1
  28. package/files/templates/apollo-sdk-templates/appinfo/appinfo.json +10 -0
  29. package/files/templates/apollo-sdk-templates/bootplate-web/index.html +88 -0
  30. package/files/templates/apollo-sdk-templates/hosted-webapp/index.html +14 -0
  31. package/files/templates/apollo-sdk-templates/icon/icon.png +0 -0
  32. package/files/templates/apollo-sdk-templates/js-service/helloclient.js +31 -0
  33. package/files/templates/apollo-sdk-templates/js-service/helloworld_webos_service.js +188 -0
  34. package/files/templates/apollo-sdk-templates/native-service/CMakeLists.txt +72 -0
  35. package/files/templates/apollo-sdk-templates/native-service/services.json +11 -0
  36. package/files/templates/apollo-sdk-templates/native-service/src/main.c +144 -0
  37. package/files/templates/apollo-sdk-templates/serviceinfo/package.json +11 -0
  38. package/files/templates/apollo-sdk-templates/serviceinfo/services.json +8 -0
  39. package/lib/base/novacom.js +1 -1
  40. package/lib/base/setup-device.js +338 -335
  41. package/lib/device.js +1 -1
  42. package/lib/generator.js +408 -377
  43. package/lib/package.js +3 -1
  44. package/lib/shell.js +1 -1
  45. package/npm-shrinkwrap.json +9242 -9242
  46. package/package.json +100 -100
  47. package/sbom-info.yaml +1758 -0
  48. package/spec/jsSpecs/ares-config.spec.js +10 -0
  49. package/spec/jsSpecs/ares-generate.spec.js +4 -4
  50. package/spec/jsSpecs/ares-log.spec.js +1 -1
  51. package/spec/test_data/ares-generate.json +18 -1
  52. package/spec/test_data/ares.json +17 -0
  53. package/webos-tools-cli-3.1.3.tgz +0 -0
@@ -0,0 +1,188 @@
1
+ /*
2
+ * Copyright (c) 2020-2024 LG Electronics Inc.
3
+ *
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ // helloworld_webos_service.js
8
+ // is simple service, based on low-level luna-bus API
9
+
10
+ // eslint-disable-next-line import/no-unresolved
11
+ const pkgInfo = require('./package.json');
12
+ const Service = require('webos-service');
13
+
14
+ const service = new Service(pkgInfo.name); // Create service by service name on package.json
15
+ const logHeader = "[" + pkgInfo.name + "]";
16
+ let greeting = "Hello, World!";
17
+
18
+ // a method that always returns the same value
19
+ service.register("hello", function(message) {
20
+ console.log(logHeader, "SERVICE_METHOD_CALLED:/hello");
21
+ console.log("In hello callback");
22
+ const name = message.payload.name ? message.payload.name : "World";
23
+
24
+ message.respond({
25
+ returnValue: true,
26
+ Response: "Hello, " + name + "!"
27
+ });
28
+ });
29
+
30
+ // set some state in the service
31
+ service.register("/config/setGreeting", function(message) {
32
+ console.log(logHeader, "SERVICE_METHOD_CALLED:/config/setGreeting");
33
+ console.log("In setGreeting callback");
34
+ if (message.payload.greeting) {
35
+ greeting = message.payload.greeting;
36
+ } else {
37
+ message.respond({
38
+ returnValue: false,
39
+ errorText: "argument 'greeting' is required",
40
+ errorCode: 1
41
+ });
42
+ }
43
+ message.respond({
44
+ returnValue: true,
45
+ greeting: greeting
46
+ });
47
+ });
48
+
49
+ // call another service
50
+ service.register("time", function(message) {
51
+ console.log(logHeader, "SERVICE_METHOD_CALLED:/time");
52
+ console.log("time callback");
53
+ service.call("luna://com.webos.service.systemservice/clock/getTime", {}, function(m2) {
54
+ console.log(logHeader, "SERVICE_METHOD_CALLED:com.webos.service.systemservice/clock/getTime");
55
+ const response = "You appear to have your UTC set to: " + m2.payload.utc;
56
+ console.log(response);
57
+ message.respond({message: response});
58
+ });
59
+ });
60
+
61
+ // handle subscription requests
62
+ const subscriptions = {};
63
+ let interval;
64
+ let x = 1;
65
+ function createInterval() {
66
+ if (interval) {
67
+ return;
68
+ }
69
+ console.log(logHeader, "create_interval");
70
+ console.log("create new interval");
71
+ interval = setInterval(function() {
72
+ sendResponses();
73
+ }, 1000);
74
+ }
75
+
76
+ // send responses to each subscribed client
77
+ function sendResponses() {
78
+ console.log(logHeader, "send_response");
79
+ console.log("Sending responses, subscription count=" + Object.keys(subscriptions).length);
80
+ for (const i in subscriptions) {
81
+ if (Object.prototype.hasOwnProperty.call(subscriptions, i)) {
82
+ const s = subscriptions[i];
83
+ s.respond({
84
+ returnValue: true,
85
+ event: "beat " + x
86
+ });
87
+ }
88
+ }
89
+ x++;
90
+ }
91
+
92
+ // listen for requests, and handle subscriptions via implicit event handlers in call
93
+ // to register
94
+ service.register("heartbeat", function(message) {
95
+ const uniqueToken = message.uniqueToken;
96
+ console.log(logHeader, "SERVICE_METHOD_CALLED:/heartbeat");
97
+ console.log("heartbeat callback, uniqueToken: " + uniqueToken + ", token: " + message.token);
98
+ message.respond({event: "beat"});
99
+ if (message.isSubscription) {
100
+ subscriptions[uniqueToken] = message;
101
+ if (!interval) {
102
+ createInterval();
103
+ }
104
+ }
105
+ },
106
+ function(message) {
107
+ const uniqueToken = message.uniqueToken;
108
+ console.log("Canceled " + uniqueToken);
109
+ delete subscriptions[uniqueToken];
110
+ const keys = Object.keys(subscriptions);
111
+ if (keys.length === 0) {
112
+ console.log("no more subscriptions, canceling interval");
113
+ clearInterval(interval);
114
+ interval = undefined;
115
+ }
116
+ });
117
+
118
+ // EventEmitter-based API for subscriptions
119
+ // note that the previous examples are actually using this API as well, they're
120
+ // just setting a "request" handler implicitly
121
+ const heartbeat2 = service.register("heartbeat2");
122
+ heartbeat2.on("request", function(message) {
123
+ console.log(logHeader, "SERVICE_METHOD_CALLED:/heartbeat2/request");
124
+ console.log("heartbeat callback");
125
+ message.respond({event: "beat"});
126
+ if (message.isSubscription) {
127
+ subscriptions[message.uniqueToken] = message;
128
+ if (!interval) {
129
+ createInterval();
130
+ }
131
+ }
132
+ });
133
+ heartbeat2.on("cancel", function(message) {
134
+ console.log(logHeader, "SERVICE_METHOD_CALLED:/heartbeat2/cancel");
135
+ console.log("Canceled " + message.uniqueToken);
136
+ delete subscriptions[message.uniqueToken];
137
+ const keys = Object.keys(subscriptions);
138
+ if (keys.length === 0) {
139
+ console.log("no more subscriptions, canceling interval");
140
+ clearInterval(interval);
141
+ interval = undefined;
142
+ }
143
+ });
144
+
145
+ service.register("ping", function(message) {
146
+ console.log(logHeader, "SERVICE_METHOD_CALLED:/ping");
147
+ console.log("Ping! setting up activity");
148
+ const methodName = "luna://" + pkgInfo.name + "/pong";
149
+ const activitySpec = {
150
+ "activity": {
151
+ "name": "My Activity", // this needs to be unique, per service
152
+ "description": "do something", // required
153
+ "background": true, // can use foreground or background, or set individual properties (see Activity Specification below, for details)
154
+ "persist": true, // this activity will be persistent across reboots
155
+ "explicit": true, // this activity *must* be completed or cancelled explicitly, or it will be re-launched until it does
156
+ "callback": { // what service to call when this activity starts
157
+ "method": methodName, // URI to service
158
+ "params": { // parameters/arguments to pass to service
159
+ }
160
+ }
161
+ },
162
+ "start": true, // start the activity immediately when its requirements (if any) are met
163
+ "replace": true, // if an activity with the same name already exists, replace it
164
+ "subscribe": false // if "subscribe" is false, the activity needs to be adopted immediately, or it gets canceled
165
+ };
166
+ service.call("luna://com.webos.service.activitymanager/create", activitySpec, function(reply) {
167
+ console.log(logHeader, "SERVICE_METHOD_CALLED:com.webos.service.activitymanager/create");
168
+ const activityId = reply.payload.activityId;
169
+ console.log("ActivityId = " + activityId);
170
+ message.respond({msg: "Created activity "+ activityId});
171
+ });
172
+ });
173
+
174
+ service.register("pong", function(message) {
175
+ console.log(logHeader, "SERVICE_METHOD_CALLED:/pong");
176
+ console.log("Pong!");
177
+ console.log(message.payload);
178
+ message.respond({message: "Pong"});
179
+ });
180
+
181
+ service.register("/do/re/me", function(message) {
182
+ console.log(logHeader, "SERVICE_METHOD_CALLED://do/re/me");
183
+ message.respond({verses:[
184
+ {doe: "a deer, a female deer"},
185
+ {ray: "a drop of golden sun"},
186
+ {me: "a name I call myself"}
187
+ ]});
188
+ });
@@ -0,0 +1,72 @@
1
+ # Copyright (c) 2020-2024 LG Electronics, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
15
+ # SPDX-License-Identifier: Apache-2.0
16
+
17
+ cmake_minimum_required(VERSION 2.8.7)
18
+ project(nativeService C)
19
+
20
+ # set link directory
21
+ #link_directories(${CMAKE_SOURCE_DIR}/pkg_$ENV{ARCH}/lib)
22
+
23
+ # ---
24
+ # add include files
25
+ include_directories(${CMAKE_SOURCE_DIR})
26
+ include_directories(${CMAKE_SOURCE_DIR}/src)
27
+ include_directories(${CMAKE_SOURCE_DIR}/include)
28
+
29
+ # ---
30
+ # find required packages
31
+ include(FindPkgConfig)
32
+
33
+ pkg_check_modules(GTHREAD2 REQUIRED gthread-2.0)
34
+ include_directories(${GTHREAD2_INCLUDE_DIRS})
35
+
36
+ pkg_check_modules(PBNJSON REQUIRED pbnjson_c)
37
+ include_directories(${PBNJSON_INCLUDE_DIRS})
38
+
39
+ # -- check for glib 2.0
40
+ pkg_check_modules(GLIB2 REQUIRED glib-2.0)
41
+ include_directories(${GLIB2_INCLUDE_DIRS})
42
+
43
+ pkg_check_modules(LS2 REQUIRED luna-service2)
44
+ include_directories(${LS2_INCLUDE_DIRS})
45
+
46
+ pkg_check_modules(PMLOG REQUIRED PmLogLib)
47
+ include_directories(${PMLOG_INCLUDE_DIRS})
48
+
49
+ # ---
50
+ # create executable file
51
+ set(BIN_NAME echo_service)
52
+
53
+ set(SRC_LIST
54
+ ${CMAKE_SOURCE_DIR}/src/main.c
55
+ )
56
+
57
+ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/pkg_$ENV{OECORE_TARGET_ARCH}/")
58
+ add_executable(${BIN_NAME} ${SRC_LIST})
59
+
60
+ # ignore shared library
61
+ set(CMAKE_EXE_LINKER_FLAGS "-Wl,--allow-shlib-undefined")
62
+ set_target_properties(${BIN_NAME} PROPERTIES LINKER_LANGUAGE C)
63
+
64
+ target_link_libraries (${BIN_NAME}
65
+ ${GTHREAD2_LDFLAGS}
66
+ ${PBNJSON_LDFLAGS}
67
+ ${LS2_LDFLAGS}
68
+ ${GLIB2_LDFLAGS}
69
+ ${PMLOG_LDFLAGS}
70
+ )
71
+
72
+ file(COPY ${CMAKE_SOURCE_DIR}/services.json DESTINATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
@@ -0,0 +1,11 @@
1
+ {
2
+ "id": "com.domain.app.service",
3
+ "description": "Native echo service",
4
+ "engine": "native",
5
+ "executable": "echo_service",
6
+ "services": [ {
7
+ "name": "com.domain.app.service",
8
+ "description": "Native echo service"
9
+ }]
10
+ }
11
+
@@ -0,0 +1,144 @@
1
+ // Copyright (c) 2020-2024 LG Electronics, Inc.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ //
15
+ // SPDX-License-Identifier: Apache-2.0
16
+
17
+ #include <stdlib.h>
18
+ #include <string.h>
19
+ #include <glib.h>
20
+ #include <stdio.h>
21
+ #include <glib-object.h>
22
+ #include <luna-service2/lunaservice.h>
23
+ #include <pbnjson.h>
24
+
25
+ // This service name
26
+ #define SERVICE_NAME "SERVICE_ID"
27
+ #define BUF_SIZE 64
28
+
29
+ // Main loop for aliving background service
30
+ GMainLoop *gmainLoop;
31
+
32
+ LSHandle *sh = NULL;
33
+ LSMessage *message;
34
+
35
+ // Declare of each method
36
+ // All method format must be : bool function(LSHandle*, LSMessage*, void*)
37
+ bool echo(LSHandle *sh, LSMessage *message, void *data);
38
+
39
+ LSMethod sampleMethods[] = {
40
+ {"echo", echo}, // luna://SERVICE_ID/echo
41
+ };
42
+
43
+
44
+ /*
45
+ * Define luna://SERVICE_ID/echo
46
+ * - A method that always returns the same value
47
+ *
48
+ * +----------------------------+ +--------------------------------+
49
+ * | APP_ID | | SERVICE_ID |
50
+ * | Foreground Application | | Background Service |
51
+ * +----------------------------+ +--------------------------------+
52
+ * | |
53
+ * | |
54
+ * | 1. Request to luna://SERVICE_ID/echo |
55
+ * | with parameters { input: "Hello, World!" } |
56
+ * | |
57
+ * | ---------------------------------------------------------------------> |
58
+ * | |
59
+ * | |
60
+ * | 2. Response to APP_ID |
61
+ * | with result '{ "echoMessage" : "Hello, World!" }' |
62
+ * | |
63
+ * | <--------------------------------------------------------------------- |
64
+ * | |
65
+ * \|/ \|/
66
+ * ' '
67
+ */
68
+ bool echo(LSHandle *sh, LSMessage *message, void *data)
69
+ {
70
+ LSError lserror;
71
+ JSchemaInfo schemaInfo;
72
+ jvalue_ref parsed = {0}, value = {0};
73
+ jvalue_ref jobj = {0}, jreturnValue = {0};
74
+ const char *input = NULL;
75
+ char buf[BUF_SIZE] = {0, };
76
+
77
+ LSErrorInit(&lserror);
78
+
79
+ // Initialize schema
80
+ jschema_info_init (&schemaInfo, jschema_all(), NULL, NULL);
81
+
82
+ // get message from LS2 and parsing to make object
83
+ parsed = jdom_parse(j_cstr_to_buffer(LSMessageGetPayload(message)), DOMOPT_NOOPT, &schemaInfo);
84
+
85
+ if (jis_null(parsed)) {
86
+ j_release(&parsed);
87
+ return true;
88
+ }
89
+
90
+ // Get value from payload.input
91
+ value = jobject_get(parsed, j_cstr_to_buffer("input"));
92
+
93
+ // JSON Object to string without schema validation check
94
+ input = jvalue_tostring_simple(value);
95
+
96
+ /**
97
+ * JSON create test
98
+ */
99
+ jobj = jobject_create();
100
+ if (jis_null(jobj)) {
101
+ j_release(&jobj);
102
+ return true;
103
+ }
104
+
105
+ jreturnValue = jboolean_create(TRUE);
106
+ jobject_set(jobj, j_cstr_to_buffer("returnValue"), jreturnValue);
107
+ jobject_set(jobj, j_cstr_to_buffer("echoMessage"), value);
108
+
109
+ LSMessageReply(sh, message, jvalue_tostring_simple(jobj), &lserror);
110
+
111
+ j_release(&parsed);
112
+ return true;
113
+ }
114
+
115
+ // Register background service and initialize
116
+ int main(int argc, char* argv[])
117
+ {
118
+ LSError lserror;
119
+ LSHandle *handle = NULL;
120
+ bool bRetVal = FALSE;
121
+
122
+ LSErrorInit(&lserror);
123
+
124
+ // create a GMainLoop
125
+ gmainLoop = g_main_loop_new(NULL, FALSE);
126
+
127
+ bRetVal = LSRegister(SERVICE_NAME, &handle, &lserror);
128
+ if (FALSE== bRetVal) {
129
+ LSErrorFree( &lserror );
130
+ return 0;
131
+ }
132
+ sh = LSMessageGetConnection(message);
133
+
134
+ LSRegisterCategory(handle,"/",sampleMethods, NULL, NULL, &lserror);
135
+
136
+ LSGmainAttach(handle, gmainLoop, &lserror);
137
+
138
+ // run to check continuously for new events from each of the event sources
139
+ g_main_loop_run(gmainLoop);
140
+ // Decreases the reference count on a GMainLoop object by one
141
+ g_main_loop_unref(gmainLoop);
142
+
143
+ return 0;
144
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "com.domain.app.service",
3
+ "version": "1.0.0",
4
+ "description": "Helloworld service",
5
+ "main": "helloworld_webos_service.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "author": "",
10
+ "license": "BSD"
11
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "id": "com.domain.app.service",
3
+ "description": "HelloWorld Service",
4
+ "services": [ {
5
+ "name": "com.domain.app.service",
6
+ "description": "HelloWorld Service"
7
+ } ]
8
+ }
@@ -975,7 +975,7 @@ const async = require('async'),
975
975
  chStream.on('close', function() {
976
976
  log.silly("novacom#Session()#run()", "event close (cmd:" + cmd + ")");
977
977
  if (err === undefined) {
978
- setImmediate(next);
978
+ setImmediate(next);
979
979
  }
980
980
  });
981
981