@signageos/cli 2.3.1 → 2.4.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.
Files changed (146) hide show
  1. package/README.md +54 -19
  2. package/dist/Applet/Build/appletBuildCommand.js +28 -72
  3. package/dist/Applet/Generate/Templates/CHANGELOG.md.template +7 -0
  4. package/dist/Applet/Generate/Templates/README.md.template +3 -0
  5. package/dist/Applet/Generate/Templates/rspack.config.mjs.template +12 -12
  6. package/dist/Applet/Generate/appletGenerateCommand.d.ts +23 -62
  7. package/dist/Applet/Generate/appletGenerateCommand.js +432 -365
  8. package/dist/Applet/Start/appletStartCommand.js +70 -132
  9. package/dist/Applet/Test/Upload/appletTestRunCommand.js +90 -178
  10. package/dist/Applet/Test/Upload/appletTestRunFacade.js +5 -29
  11. package/dist/Applet/Test/Upload/appletTestUploadCommand.js +99 -224
  12. package/dist/Applet/Test/Upload/appletTestUploadFacade.js +51 -105
  13. package/dist/Applet/Test/appletTestCommand.js +6 -36
  14. package/dist/Applet/Upload/appletUploadCommand.js +199 -305
  15. package/dist/Applet/Upload/appletUploadCommandHelper.js +129 -144
  16. package/dist/Applet/Upload/appletUploadFacade.d.ts +2 -2
  17. package/dist/Applet/Upload/appletUploadFacade.js +184 -265
  18. package/dist/Applet/Upload/appletUploadFacadeHelper.js +51 -55
  19. package/dist/Applet/appletCommand.d.ts +25 -157
  20. package/dist/Applet/appletCommand.js +9 -39
  21. package/dist/Applet/appletErrors.js +5 -24
  22. package/dist/Applet/appletFacade.js +122 -147
  23. package/dist/Applet/appletServerHelper.js +18 -55
  24. package/dist/Auth/loginCommand.d.ts +2 -2
  25. package/dist/Auth/loginCommand.js +105 -136
  26. package/dist/Cache/tmpCache.js +47 -16
  27. package/dist/Cli/helper.js +3 -5
  28. package/dist/Cli/packageVersion.js +99 -131
  29. package/dist/Command/Autocomplete/Install/installAutocompleteCommand.d.ts +10 -0
  30. package/dist/Command/Autocomplete/Install/installAutocompleteCommand.js +39 -0
  31. package/dist/Command/Autocomplete/Install/installAutocompleteCommand.ts +30 -0
  32. package/dist/Command/Autocomplete/Install/sos-completion.sh +63 -0
  33. package/dist/Command/Autocomplete/Uninstall/uninstallAutocompleteCommand.d.ts +8 -0
  34. package/dist/Command/Autocomplete/Uninstall/uninstallAutocompleteCommand.js +120 -0
  35. package/dist/Command/Autocomplete/autocompleteCommand.d.ts +22 -0
  36. package/dist/Command/Autocomplete/autocompleteCommand.js +32 -0
  37. package/dist/Command/autoComplete.d.ts +4 -0
  38. package/dist/Command/autoComplete.js +184 -0
  39. package/dist/Command/commandDefinition.d.ts +9 -9
  40. package/dist/Command/commandDefinition.js +1 -3
  41. package/dist/Command/commandProcessor.js +41 -131
  42. package/dist/Command/globalArgs.js +9 -8
  43. package/dist/CommandLine/IProgressBar.js +0 -1
  44. package/dist/CommandLine/progressBarFactory.d.ts +1 -1
  45. package/dist/CommandLine/progressBarFactory.js +42 -13
  46. package/dist/CustomScript/Generate/customScriptGenerateCommand.js +17 -56
  47. package/dist/CustomScript/Generate/customScriptGenerateFacade.js +94 -109
  48. package/dist/CustomScript/Upload/customScriptUploadCommand.js +44 -120
  49. package/dist/CustomScript/customScriptCommand.d.ts +1 -9
  50. package/dist/CustomScript/customScriptCommand.js +6 -36
  51. package/dist/CustomScript/customScriptFacade.d.ts +2 -2
  52. package/dist/CustomScript/customScriptFacade.js +187 -297
  53. package/dist/Device/Connect/connectCommand.js +73 -137
  54. package/dist/Device/Content/setContentCommand.js +33 -78
  55. package/dist/Device/PowerAction/powerActionCommand.js +22 -65
  56. package/dist/Device/deviceCommand.js +7 -37
  57. package/dist/Device/deviceFacade.js +71 -127
  58. package/dist/Emulator/IEmulator.js +0 -1
  59. package/dist/Emulator/createDomain.d.ts +0 -1
  60. package/dist/Emulator/createDomain.js +44 -14
  61. package/dist/Emulator/emulatorFacade.js +75 -133
  62. package/dist/Emulator/emulatorFactory.js +123 -126
  63. package/dist/Firmware/Upload/firmwareUploadCommand.js +133 -221
  64. package/dist/Firmware/Upload/firmwareUploadFacade.js +75 -112
  65. package/dist/Firmware/Upload/firmwareUploadHelper.js +38 -6
  66. package/dist/Firmware/firmwareCommand.js +5 -35
  67. package/dist/Lib/archive.js +56 -62
  68. package/dist/Lib/childProcess.js +37 -5
  69. package/dist/Lib/fileSystem.js +76 -87
  70. package/dist/Lib/git.d.ts +1 -1
  71. package/dist/Lib/git.js +58 -87
  72. package/dist/Organization/Get/organizationGetCommand.js +14 -50
  73. package/dist/Organization/List/organizationListCommand.js +12 -46
  74. package/dist/Organization/SetDefault/organizationSetDefaultCommand.js +18 -56
  75. package/dist/Organization/organizationCommand.js +7 -37
  76. package/dist/Organization/organizationFacade.js +102 -177
  77. package/dist/RunControl/runControlHelper.js +14 -64
  78. package/dist/Timer/wait.js +2 -3
  79. package/dist/Timing/List/timingListCommand.js +20 -62
  80. package/dist/Timing/timingCommand.js +5 -35
  81. package/dist/generalCommand.js +1 -2
  82. package/dist/helper.d.ts +4 -4
  83. package/dist/helper.js +61 -122
  84. package/dist/index.js +19 -46
  85. package/dist/parameters.js +17 -40
  86. package/package.json +52 -57
  87. package/dist/Applet/Build/appletBuildCommand.js.map +0 -1
  88. package/dist/Applet/Generate/appletGenerateCommand.js.map +0 -1
  89. package/dist/Applet/Start/appletStartCommand.js.map +0 -1
  90. package/dist/Applet/Test/Upload/appletTestRunCommand.js.map +0 -1
  91. package/dist/Applet/Test/Upload/appletTestRunFacade.js.map +0 -1
  92. package/dist/Applet/Test/Upload/appletTestUploadCommand.js.map +0 -1
  93. package/dist/Applet/Test/Upload/appletTestUploadFacade.js.map +0 -1
  94. package/dist/Applet/Test/appletTestCommand.js.map +0 -1
  95. package/dist/Applet/Upload/appletUploadCommand.js.map +0 -1
  96. package/dist/Applet/Upload/appletUploadCommandHelper.js.map +0 -1
  97. package/dist/Applet/Upload/appletUploadFacade.js.map +0 -1
  98. package/dist/Applet/Upload/appletUploadFacadeHelper.js.map +0 -1
  99. package/dist/Applet/appletCommand.js.map +0 -1
  100. package/dist/Applet/appletErrors.js.map +0 -1
  101. package/dist/Applet/appletFacade.js.map +0 -1
  102. package/dist/Applet/appletServerHelper.js.map +0 -1
  103. package/dist/Auth/loginCommand.js.map +0 -1
  104. package/dist/Cache/tmpCache.js.map +0 -1
  105. package/dist/Cli/helper.js.map +0 -1
  106. package/dist/Cli/packageVersion.js.map +0 -1
  107. package/dist/Command/commandDefinition.js.map +0 -1
  108. package/dist/Command/commandProcessor.js.map +0 -1
  109. package/dist/Command/globalArgs.js.map +0 -1
  110. package/dist/CommandLine/IProgressBar.js.map +0 -1
  111. package/dist/CommandLine/progressBarFactory.js.map +0 -1
  112. package/dist/CustomScript/Generate/customScriptGenerateCommand.js.map +0 -1
  113. package/dist/CustomScript/Generate/customScriptGenerateFacade.js.map +0 -1
  114. package/dist/CustomScript/Upload/customScriptUploadCommand.js.map +0 -1
  115. package/dist/CustomScript/customScriptCommand.js.map +0 -1
  116. package/dist/CustomScript/customScriptFacade.js.map +0 -1
  117. package/dist/Device/Connect/connectCommand.js.map +0 -1
  118. package/dist/Device/Content/setContentCommand.js.map +0 -1
  119. package/dist/Device/PowerAction/powerActionCommand.js.map +0 -1
  120. package/dist/Device/deviceCommand.js.map +0 -1
  121. package/dist/Device/deviceFacade.js.map +0 -1
  122. package/dist/Emulator/IEmulator.js.map +0 -1
  123. package/dist/Emulator/createDomain.js.map +0 -1
  124. package/dist/Emulator/emulatorFacade.js.map +0 -1
  125. package/dist/Emulator/emulatorFactory.js.map +0 -1
  126. package/dist/Firmware/Upload/firmwareUploadCommand.js.map +0 -1
  127. package/dist/Firmware/Upload/firmwareUploadFacade.js.map +0 -1
  128. package/dist/Firmware/Upload/firmwareUploadHelper.js.map +0 -1
  129. package/dist/Firmware/firmwareCommand.js.map +0 -1
  130. package/dist/Lib/archive.js.map +0 -1
  131. package/dist/Lib/childProcess.js.map +0 -1
  132. package/dist/Lib/fileSystem.js.map +0 -1
  133. package/dist/Lib/git.js.map +0 -1
  134. package/dist/Organization/Get/organizationGetCommand.js.map +0 -1
  135. package/dist/Organization/List/organizationListCommand.js.map +0 -1
  136. package/dist/Organization/SetDefault/organizationSetDefaultCommand.js.map +0 -1
  137. package/dist/Organization/organizationCommand.js.map +0 -1
  138. package/dist/Organization/organizationFacade.js.map +0 -1
  139. package/dist/RunControl/runControlHelper.js.map +0 -1
  140. package/dist/Timer/wait.js.map +0 -1
  141. package/dist/Timing/List/timingListCommand.js.map +0 -1
  142. package/dist/Timing/timingCommand.js.map +0 -1
  143. package/dist/generalCommand.js.map +0 -1
  144. package/dist/helper.js.map +0 -1
  145. package/dist/index.js.map +0 -1
  146. package/dist/parameters.js.map +0 -1
@@ -8,42 +8,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
13
  };
38
14
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.disconnectDevice = exports.getActionType = exports.getDeviceUid = exports.POWER_ACTION_TYPE_OPTION = exports.DEVICE_UID_OPTION = exports.typeMap = void 0;
40
- var Debug = require("debug");
41
- var prompts = require("prompts");
42
- var helper_1 = require("../helper");
43
- var IPowerAction_1 = require("@signageos/sdk/dist/RestApi/Device/PowerAction/IPowerAction");
44
- var apiVersions_1 = require("@signageos/sdk/dist/RestApi/apiVersions");
45
- var runControlHelper_1 = require("../RunControl/runControlHelper");
46
- var debug = Debug('@signageos/cli:Device:facade');
15
+ exports.POWER_ACTION_TYPE_OPTION = exports.DEVICE_UID_OPTION = exports.typeMap = void 0;
16
+ exports.getDeviceUid = getDeviceUid;
17
+ exports.getActionType = getActionType;
18
+ exports.disconnectDevice = disconnectDevice;
19
+ const debug_1 = __importDefault(require("debug"));
20
+ const prompts_1 = __importDefault(require("prompts"));
21
+ const helper_1 = require("../helper");
22
+ const IPowerAction_1 = require("@signageos/sdk/dist/RestApi/Device/PowerAction/IPowerAction");
23
+ const apiVersions_1 = require("@signageos/sdk/dist/RestApi/apiVersions");
24
+ const runControlHelper_1 = require("../RunControl/runControlHelper");
25
+ const Debug = (0, debug_1.default)('@signageos/cli:Device:facade');
47
26
  exports.typeMap = new Map([
48
27
  ['reboot', { name: 'Reboot Device', action: IPowerAction_1.DevicePowerAction.SystemReboot }],
49
28
  ['displayOn', { name: 'Display ON', action: IPowerAction_1.DevicePowerAction.DisplayPowerOn }],
@@ -55,105 +34,70 @@ exports.typeMap = new Map([
55
34
  ['refresh', { name: 'Applet Refresh', action: IPowerAction_1.DevicePowerAction.AppletRefresh }],
56
35
  ]);
57
36
  exports.DEVICE_UID_OPTION = { name: 'device-uid', type: String, description: 'Device UID' };
58
- exports.POWER_ACTION_TYPE_OPTION = { name: 'type', type: String, description: "Type of device power action" };
37
+ exports.POWER_ACTION_TYPE_OPTION = { name: 'type', type: String, description: `Type of device power action` };
59
38
  function getDeviceUid(restApi, options) {
60
- return __awaiter(this, void 0, void 0, function () {
61
- var deviceUid, devices, response;
62
- return __generator(this, function (_a) {
63
- switch (_a.label) {
64
- case 0:
65
- deviceUid = options['device-uid'];
66
- if (!!deviceUid) return [3 /*break*/, 3];
67
- return [4 /*yield*/, restApi.device.list()];
68
- case 1:
69
- devices = _a.sent();
70
- return [4 /*yield*/, prompts({
71
- type: 'autocomplete',
72
- name: 'deviceUid',
73
- message: "Select device to use",
74
- choices: devices.map(function (dev) {
75
- var _a;
76
- return ({
77
- title: "".concat((_a = dev.name) !== null && _a !== void 0 ? _a : "Unnamed device, created ".concat(dev.createdAt.toString()), " (").concat(dev.uid, ")"),
78
- value: dev.uid,
79
- });
80
- }),
81
- })];
82
- case 2:
83
- response = _a.sent();
84
- debug('Device selected', response.deviceUid);
85
- deviceUid = response.deviceUid;
86
- _a.label = 3;
87
- case 3:
88
- if (!deviceUid) {
89
- throw new Error('Missing argument --device-uid <string>');
90
- }
91
- return [2 /*return*/, deviceUid];
92
- }
93
- });
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ let deviceUid = options['device-uid'];
41
+ if (!deviceUid) {
42
+ const devices = yield restApi.device.list();
43
+ const response = yield (0, prompts_1.default)({
44
+ type: 'autocomplete',
45
+ name: 'deviceUid',
46
+ message: `Select device to use`,
47
+ choices: devices.map((dev) => {
48
+ var _a;
49
+ return ({
50
+ title: `${(_a = dev.name) !== null && _a !== void 0 ? _a : `Unnamed device, created ${dev.createdAt.toString()}`} (${dev.uid})`,
51
+ value: dev.uid,
52
+ });
53
+ }),
54
+ });
55
+ Debug('Device selected', response.deviceUid);
56
+ deviceUid = response.deviceUid;
57
+ }
58
+ if (!deviceUid) {
59
+ throw new Error('Missing argument --device-uid <string>');
60
+ }
61
+ return deviceUid;
94
62
  });
95
63
  }
96
- exports.getDeviceUid = getDeviceUid;
97
64
  function getActionType(options) {
98
- return __awaiter(this, void 0, void 0, function () {
99
- var action, response;
100
- return __generator(this, function (_a) {
101
- switch (_a.label) {
102
- case 0:
103
- action = options.type;
104
- if (!!action) return [3 /*break*/, 2];
105
- return [4 /*yield*/, prompts({
106
- type: 'autocomplete',
107
- name: 'type',
108
- message: "Select device power action",
109
- choices: Array.from(exports.typeMap).map(function (item) { return ({
110
- title: item[1].name,
111
- value: item[0],
112
- }); }),
113
- })];
114
- case 1:
115
- response = _a.sent();
116
- action = response.type;
117
- _a.label = 2;
118
- case 2:
119
- if (!action) {
120
- throw new Error('Missing argument --type <string>');
121
- }
122
- if (!exports.typeMap.get(action)) {
123
- throw new Error("Wrong power action type argument --type. Action ".concat(options.type, " is not defined"));
124
- }
125
- return [2 /*return*/, action];
126
- }
127
- });
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ let action = options.type;
67
+ if (!action) {
68
+ const response = yield (0, prompts_1.default)({
69
+ type: 'autocomplete',
70
+ name: 'type',
71
+ message: `Select device power action`,
72
+ choices: Array.from(exports.typeMap).map((item) => ({
73
+ title: item[1].name,
74
+ value: item[0],
75
+ })),
76
+ });
77
+ action = response.type;
78
+ }
79
+ if (!action) {
80
+ throw new Error('Missing argument --type <string>');
81
+ }
82
+ if (!exports.typeMap.get(action)) {
83
+ throw new Error(`Wrong power action type argument --type. Action ${options.type} is not defined`);
84
+ }
85
+ return action;
128
86
  });
129
87
  }
130
- exports.getActionType = getActionType;
131
88
  function disconnectDevice(organization, deviceUid) {
132
- return __awaiter(this, void 0, void 0, function () {
133
- var config, DEVICE_RESOURCE, options, responseOfPost, _a, _b;
134
- return __generator(this, function (_c) {
135
- switch (_c.label) {
136
- case 0: return [4 /*yield*/, (0, runControlHelper_1.loadConfig)()];
137
- case 1:
138
- config = _c.sent();
139
- DEVICE_RESOURCE = "/device/".concat(deviceUid, "/disconnect");
140
- options = {
141
- url: (0, helper_1.getApiUrl)(config),
142
- auth: {
143
- clientId: organization.oauthClientId,
144
- secret: organization.oauthClientSecret,
145
- },
146
- version: apiVersions_1.ApiVersions.V1,
147
- };
148
- return [4 /*yield*/, (0, helper_1.postResource)(options, DEVICE_RESOURCE, null, { deviceUid: "".concat(deviceUid) })];
149
- case 2:
150
- responseOfPost = _c.sent();
151
- _b = (_a = JSON).parse;
152
- return [4 /*yield*/, responseOfPost.text()];
153
- case 3: return [2 /*return*/, _b.apply(_a, [_c.sent(), helper_1.deserializeJSON])];
154
- }
155
- });
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ const config = yield (0, runControlHelper_1.loadConfig)();
91
+ const DEVICE_RESOURCE = `/device/${deviceUid}/disconnect`;
92
+ const options = {
93
+ url: (0, helper_1.getApiUrl)(config),
94
+ auth: {
95
+ clientId: organization.oauthClientId,
96
+ secret: organization.oauthClientSecret,
97
+ },
98
+ version: apiVersions_1.ApiVersions.V1,
99
+ };
100
+ const responseOfPost = yield (0, helper_1.postResource)(options, DEVICE_RESOURCE, null, { deviceUid: `${deviceUid}` });
101
+ return JSON.parse(yield responseOfPost.text(), helper_1.deserializeJSON);
156
102
  });
157
103
  }
158
- exports.disconnectDevice = disconnectDevice;
159
- //# sourceMappingURL=deviceFacade.js.map
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=IEmulator.js.map
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import * as http from 'http';
3
2
  interface IOptions {
4
3
  useLocalIp?: boolean;
@@ -1,25 +1,55 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createDomain = void 0;
4
- var url = require("url");
5
- var ip = require("internal-ip");
36
+ exports.createDomain = createDomain;
37
+ const url = __importStar(require("url"));
38
+ const ip = __importStar(require("internal-ip"));
6
39
  function createDomain(options, server) {
7
- var protocol = options.https ? 'https' : 'http';
8
- var hostname = options.useLocalIp ? ip.v4.sync() || 'localhost' : options.host || 'localhost';
9
- var serverAddress = server === null || server === void 0 ? void 0 : server.address();
10
- // eslint-disable-next-line no-nested-ternary
11
- var port = options.socket ? 0 : server ? (typeof serverAddress === 'object' ? (serverAddress === null || serverAddress === void 0 ? void 0 : serverAddress.port) || 0 : 0) : 0;
40
+ const protocol = options.https ? 'https' : 'http';
41
+ const hostname = options.useLocalIp ? ip.v4.sync() || 'localhost' : options.host || 'localhost';
42
+ const serverAddress = server === null || server === void 0 ? void 0 : server.address();
43
+ const port = options.socket ? 0 : server ? (typeof serverAddress === 'object' ? (serverAddress === null || serverAddress === void 0 ? void 0 : serverAddress.port) || 0 : 0) : 0;
12
44
  // use explicitly defined public url
13
45
  // (prefix with protocol if not explicitly given)
14
46
  if (options.public) {
15
- return /^[a-zA-Z]+:\/\//.test(options.public) ? "".concat(options.public) : "".concat(protocol, "://").concat(options.public);
47
+ return /^[a-zA-Z]+:\/\//.test(options.public) ? `${options.public}` : `${protocol}://${options.public}`;
16
48
  }
17
49
  // the formatted domain (url without path) of the webpack server
18
50
  return url.format({
19
- protocol: protocol,
20
- hostname: hostname,
21
- port: port,
51
+ protocol,
52
+ hostname,
53
+ port,
22
54
  });
23
55
  }
24
- exports.createDomain = createDomain;
25
- //# sourceMappingURL=createDomain.js.map
@@ -8,46 +8,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
13
  };
38
14
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.loadEmulatorOrCreateNewAndReturnUid = void 0;
40
- var chalk_1 = require("chalk");
41
- var prompts = require("prompts");
42
- var runControlHelper_1 = require("../RunControl/runControlHelper");
43
- var RestApi_1 = require("@signageos/sdk/dist/RestApi/RestApi");
44
- var AuthenticationError_1 = require("@signageos/sdk/dist/RestApi/Error/AuthenticationError");
45
- var apiVersions_1 = require("@signageos/sdk/dist/RestApi/apiVersions");
46
- var helper_1 = require("../helper");
47
- var log_1 = require("@signageos/sdk/dist/Console/log");
48
- var createRestApi = function (config) {
15
+ exports.loadEmulatorOrCreateNewAndReturnUid = loadEmulatorOrCreateNewAndReturnUid;
16
+ const chalk_1 = __importDefault(require("chalk"));
17
+ const prompts_1 = __importDefault(require("prompts"));
18
+ const runControlHelper_1 = require("../RunControl/runControlHelper");
19
+ const RestApi_1 = __importDefault(require("@signageos/sdk/dist/RestApi/RestApi"));
20
+ const AuthenticationError_1 = __importDefault(require("@signageos/sdk/dist/RestApi/Error/AuthenticationError"));
21
+ const apiVersions_1 = require("@signageos/sdk/dist/RestApi/apiVersions");
22
+ const helper_1 = require("../helper");
23
+ const log_1 = require("@signageos/sdk/dist/Console/log");
24
+ const createRestApi = (config) => {
49
25
  var _a, _b;
50
- var options = {
26
+ const options = {
51
27
  url: (0, helper_1.getApiUrl)(config),
52
28
  auth: {
53
29
  clientId: (_a = config.identification) !== null && _a !== void 0 ? _a : '',
@@ -59,108 +35,74 @@ var createRestApi = function (config) {
59
35
  return new RestApi_1.default(options, options);
60
36
  };
61
37
  function getListOfEmulators(restApi, organizationUid) {
62
- return __awaiter(this, void 0, void 0, function () {
63
- var e_1;
64
- return __generator(this, function (_a) {
65
- switch (_a.label) {
66
- case 0:
67
- _a.trys.push([0, 2, , 3]);
68
- return [4 /*yield*/, restApi.emulator.list({ organizationUid: organizationUid })];
69
- case 1: return [2 /*return*/, _a.sent()];
70
- case 2:
71
- e_1 = _a.sent();
72
- if (e_1 instanceof AuthenticationError_1.default) {
73
- throw new Error("Authentication error. Try to login using ".concat(chalk_1.default.green('sos login')));
74
- }
75
- else {
76
- throw new Error('Unknown error: ' + e_1.message);
77
- }
78
- return [3 /*break*/, 3];
79
- case 3: return [2 /*return*/];
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ try {
40
+ return yield restApi.emulator.list({ organizationUid });
41
+ }
42
+ catch (e) {
43
+ if (e instanceof AuthenticationError_1.default) {
44
+ throw new Error(`Authentication error. Try to login using ${chalk_1.default.green('sos login')}`);
45
+ }
46
+ else {
47
+ throw new Error('Unknown error: ' + e.message);
80
48
  }
81
- });
49
+ }
82
50
  });
83
51
  }
84
52
  function createNewEmulator(restApi, organizationUid) {
85
- return __awaiter(this, void 0, void 0, function () {
86
- var e_2;
87
- return __generator(this, function (_a) {
88
- switch (_a.label) {
89
- case 0:
90
- _a.trys.push([0, 2, , 3]);
91
- return [4 /*yield*/, restApi.emulator.create({ organizationUid: organizationUid })];
92
- case 1: return [2 /*return*/, _a.sent()];
93
- case 2:
94
- e_2 = _a.sent();
95
- throw new Error('Unknown error: ' + e_2.message);
96
- case 3: return [2 /*return*/];
97
- }
98
- });
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ try {
55
+ return yield restApi.emulator.create({ organizationUid });
56
+ }
57
+ catch (e) {
58
+ throw new Error('Unknown error: ' + e.message);
59
+ }
99
60
  });
100
61
  }
101
62
  function loadEmulatorOrCreateNewAndReturnUid(organizationUid) {
102
- return __awaiter(this, void 0, void 0, function () {
103
- var config, restApi, listOfEmulatorsResponse, isSavedValidEmulator, emulatorUid, emulatorName, selectedEmulator, newEmulatorList, emulatorName;
104
- return __generator(this, function (_a) {
105
- switch (_a.label) {
106
- case 0: return [4 /*yield*/, (0, runControlHelper_1.loadConfig)()];
107
- case 1:
108
- config = _a.sent();
109
- if (!config.identification || !config.apiSecurityToken) {
110
- throw new Error("No authenticized account found. Try to login using ".concat(chalk_1.default.green('sos login')));
111
- }
112
- restApi = createRestApi(config);
113
- return [4 /*yield*/, getListOfEmulators(restApi, organizationUid)];
114
- case 2:
115
- listOfEmulatorsResponse = _a.sent();
116
- isSavedValidEmulator = config.emulatorUid && listOfEmulatorsResponse.some(function (emu) { return emu.duid === config.emulatorUid; });
117
- if (isSavedValidEmulator) {
118
- return [2 /*return*/, config.emulatorUid];
119
- }
120
- else if (config.emulatorUid) {
121
- (0, log_1.log)('warning', chalk_1.default.yellow('Field emulatorUid in sos config links to non existent emulator'));
122
- }
123
- emulatorUid = '';
124
- (0, log_1.log)('info', 'Looking for valid emulator assigned to your account via API...');
125
- if (!(listOfEmulatorsResponse.length === 1)) return [3 /*break*/, 3];
126
- emulatorName = listOfEmulatorsResponse[0].name;
127
- emulatorUid = listOfEmulatorsResponse[0].duid;
128
- (0, log_1.log)('info', "One valid emulator ".concat(chalk_1.default.green(emulatorName), " fetched and saved into .sosrc"));
129
- return [3 /*break*/, 8];
130
- case 3:
131
- if (!(listOfEmulatorsResponse.length > 1)) return [3 /*break*/, 5];
132
- return [4 /*yield*/, prompts({
133
- type: 'select',
134
- name: 'duid',
135
- message: 'Select emulator to use',
136
- choices: listOfEmulatorsResponse.map(function (emu) { return ({
137
- title: "".concat(emu.name, " (").concat(emu.duid, ")"),
138
- value: emu.duid,
139
- }); }),
140
- })];
141
- case 4:
142
- selectedEmulator = _a.sent();
143
- emulatorUid = selectedEmulator.duid;
144
- return [3 /*break*/, 8];
145
- case 5:
146
- (0, log_1.log)('warning', 'No valid emulator assigned to your account found via API thus newone will be created');
147
- return [4 /*yield*/, createNewEmulator(restApi, organizationUid)];
148
- case 6:
149
- _a.sent();
150
- return [4 /*yield*/, getListOfEmulators(restApi, organizationUid)];
151
- case 7:
152
- newEmulatorList = _a.sent();
153
- emulatorName = newEmulatorList[0].name;
154
- emulatorUid = newEmulatorList[0].duid;
155
- (0, log_1.log)('info', "New emulator ".concat(chalk_1.default.green(emulatorName), " created and saved into .sosrc"));
156
- _a.label = 8;
157
- case 8: return [4 /*yield*/, (0, runControlHelper_1.updateConfig)({ emulatorUid: emulatorUid })];
158
- case 9:
159
- _a.sent();
160
- return [2 /*return*/, emulatorUid];
161
- }
162
- });
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ var _a, _b, _c, _d, _e, _f, _g, _h;
65
+ const config = yield (0, runControlHelper_1.loadConfig)();
66
+ if (!config.identification || !config.apiSecurityToken) {
67
+ throw new Error(`No authenticized account found. Try to login using ${chalk_1.default.green('sos login')}`);
68
+ }
69
+ const restApi = createRestApi(config);
70
+ const listOfEmulatorsResponse = yield getListOfEmulators(restApi, organizationUid);
71
+ const isSavedValidEmulator = config.emulatorUid && listOfEmulatorsResponse.some((emu) => emu.duid === config.emulatorUid);
72
+ if (isSavedValidEmulator) {
73
+ return config.emulatorUid;
74
+ }
75
+ else if (config.emulatorUid) {
76
+ (0, log_1.log)('warning', chalk_1.default.yellow('Field emulatorUid in sos config links to non existent emulator'));
77
+ }
78
+ let emulatorUid = '';
79
+ (0, log_1.log)('info', 'Looking for valid emulator assigned to your account via API...');
80
+ if (listOfEmulatorsResponse.length === 1) {
81
+ const emulatorName = (_b = (_a = listOfEmulatorsResponse[0]) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : 'Unknown';
82
+ emulatorUid = (_d = (_c = listOfEmulatorsResponse[0]) === null || _c === void 0 ? void 0 : _c.duid) !== null && _d !== void 0 ? _d : '';
83
+ (0, log_1.log)('info', `One valid emulator ${chalk_1.default.green(emulatorName)} fetched and saved into .sosrc`);
84
+ }
85
+ else if (listOfEmulatorsResponse.length > 1) {
86
+ const selectedEmulator = yield (0, prompts_1.default)({
87
+ type: 'select',
88
+ name: 'duid',
89
+ message: 'Select emulator to use',
90
+ choices: listOfEmulatorsResponse.map((emu) => ({
91
+ title: `${emu.name} (${emu.duid})`,
92
+ value: emu.duid,
93
+ })),
94
+ });
95
+ emulatorUid = selectedEmulator.duid;
96
+ }
97
+ else {
98
+ (0, log_1.log)('warning', 'No valid emulator assigned to your account found via API thus newone will be created');
99
+ yield createNewEmulator(restApi, organizationUid);
100
+ const newEmulatorList = yield getListOfEmulators(restApi, organizationUid);
101
+ const emulatorName = (_f = (_e = newEmulatorList[0]) === null || _e === void 0 ? void 0 : _e.name) !== null && _f !== void 0 ? _f : 'Unknown';
102
+ emulatorUid = (_h = (_g = newEmulatorList[0]) === null || _g === void 0 ? void 0 : _g.duid) !== null && _h !== void 0 ? _h : '';
103
+ (0, log_1.log)('info', `New emulator ${chalk_1.default.green(emulatorName)} created and saved into .sosrc`);
104
+ }
105
+ yield (0, runControlHelper_1.updateConfig)({ emulatorUid });
106
+ return emulatorUid;
163
107
  });
164
108
  }
165
- exports.loadEmulatorOrCreateNewAndReturnUid = loadEmulatorOrCreateNewAndReturnUid;
166
- //# sourceMappingURL=emulatorFacade.js.map