@signageos/cli 2.3.1 → 2.3.2

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 (127) hide show
  1. package/README.md +1 -0
  2. package/dist/Applet/Build/appletBuildCommand.js +28 -72
  3. package/dist/Applet/Generate/Templates/rspack.config.mjs.template +12 -12
  4. package/dist/Applet/Generate/appletGenerateCommand.d.ts +23 -62
  5. package/dist/Applet/Generate/appletGenerateCommand.js +398 -365
  6. package/dist/Applet/Start/appletStartCommand.js +69 -131
  7. package/dist/Applet/Test/Upload/appletTestRunCommand.js +89 -177
  8. package/dist/Applet/Test/Upload/appletTestRunFacade.js +4 -27
  9. package/dist/Applet/Test/Upload/appletTestUploadCommand.js +98 -223
  10. package/dist/Applet/Test/Upload/appletTestUploadFacade.js +39 -102
  11. package/dist/Applet/Test/appletTestCommand.js +6 -36
  12. package/dist/Applet/Upload/appletUploadCommand.js +199 -305
  13. package/dist/Applet/Upload/appletUploadCommandHelper.js +103 -138
  14. package/dist/Applet/Upload/appletUploadFacade.d.ts +2 -2
  15. package/dist/Applet/Upload/appletUploadFacade.js +172 -263
  16. package/dist/Applet/Upload/appletUploadFacadeHelper.js +39 -52
  17. package/dist/Applet/appletCommand.d.ts +22 -62
  18. package/dist/Applet/appletCommand.js +9 -39
  19. package/dist/Applet/appletErrors.js +5 -24
  20. package/dist/Applet/appletFacade.js +106 -141
  21. package/dist/Applet/appletServerHelper.js +16 -53
  22. package/dist/Auth/loginCommand.js +96 -137
  23. package/dist/Cache/tmpCache.js +35 -13
  24. package/dist/Cli/helper.js +1 -2
  25. package/dist/Cli/packageVersion.js +82 -123
  26. package/dist/Command/commandDefinition.js +0 -1
  27. package/dist/Command/commandProcessor.js +40 -129
  28. package/dist/Command/globalArgs.js +7 -5
  29. package/dist/CommandLine/IProgressBar.js +0 -1
  30. package/dist/CommandLine/progressBarFactory.js +31 -11
  31. package/dist/CustomScript/Generate/customScriptGenerateCommand.js +17 -56
  32. package/dist/CustomScript/Generate/customScriptGenerateFacade.js +82 -106
  33. package/dist/CustomScript/Upload/customScriptUploadCommand.js +44 -120
  34. package/dist/CustomScript/customScriptCommand.js +6 -36
  35. package/dist/CustomScript/customScriptFacade.js +175 -294
  36. package/dist/Device/Connect/connectCommand.js +72 -136
  37. package/dist/Device/Content/setContentCommand.js +33 -78
  38. package/dist/Device/PowerAction/powerActionCommand.js +22 -65
  39. package/dist/Device/deviceCommand.js +7 -37
  40. package/dist/Device/deviceFacade.js +67 -123
  41. package/dist/Emulator/IEmulator.js +0 -1
  42. package/dist/Emulator/createDomain.js +33 -12
  43. package/dist/Emulator/emulatorFacade.js +74 -131
  44. package/dist/Emulator/emulatorFactory.js +112 -124
  45. package/dist/Firmware/Upload/firmwareUploadCommand.js +133 -221
  46. package/dist/Firmware/Upload/firmwareUploadFacade.js +64 -110
  47. package/dist/Firmware/Upload/firmwareUploadHelper.js +27 -5
  48. package/dist/Firmware/firmwareCommand.js +5 -35
  49. package/dist/Lib/archive.js +45 -60
  50. package/dist/Lib/childProcess.js +27 -5
  51. package/dist/Lib/fileSystem.js +62 -82
  52. package/dist/Lib/git.d.ts +1 -1
  53. package/dist/Lib/git.js +44 -82
  54. package/dist/Organization/Get/organizationGetCommand.js +14 -50
  55. package/dist/Organization/List/organizationListCommand.js +12 -46
  56. package/dist/Organization/SetDefault/organizationSetDefaultCommand.js +18 -56
  57. package/dist/Organization/organizationCommand.js +7 -37
  58. package/dist/Organization/organizationFacade.js +97 -172
  59. package/dist/RunControl/runControlHelper.js +11 -60
  60. package/dist/Timer/wait.js +1 -2
  61. package/dist/Timing/List/timingListCommand.js +20 -62
  62. package/dist/Timing/timingCommand.js +5 -35
  63. package/dist/generalCommand.js +1 -2
  64. package/dist/helper.js +48 -109
  65. package/dist/index.js +15 -45
  66. package/dist/parameters.js +17 -40
  67. package/package.json +16 -18
  68. package/dist/Applet/Build/appletBuildCommand.js.map +0 -1
  69. package/dist/Applet/Generate/appletGenerateCommand.js.map +0 -1
  70. package/dist/Applet/Start/appletStartCommand.js.map +0 -1
  71. package/dist/Applet/Test/Upload/appletTestRunCommand.js.map +0 -1
  72. package/dist/Applet/Test/Upload/appletTestRunFacade.js.map +0 -1
  73. package/dist/Applet/Test/Upload/appletTestUploadCommand.js.map +0 -1
  74. package/dist/Applet/Test/Upload/appletTestUploadFacade.js.map +0 -1
  75. package/dist/Applet/Test/appletTestCommand.js.map +0 -1
  76. package/dist/Applet/Upload/appletUploadCommand.js.map +0 -1
  77. package/dist/Applet/Upload/appletUploadCommandHelper.js.map +0 -1
  78. package/dist/Applet/Upload/appletUploadFacade.js.map +0 -1
  79. package/dist/Applet/Upload/appletUploadFacadeHelper.js.map +0 -1
  80. package/dist/Applet/appletCommand.js.map +0 -1
  81. package/dist/Applet/appletErrors.js.map +0 -1
  82. package/dist/Applet/appletFacade.js.map +0 -1
  83. package/dist/Applet/appletServerHelper.js.map +0 -1
  84. package/dist/Auth/loginCommand.js.map +0 -1
  85. package/dist/Cache/tmpCache.js.map +0 -1
  86. package/dist/Cli/helper.js.map +0 -1
  87. package/dist/Cli/packageVersion.js.map +0 -1
  88. package/dist/Command/commandDefinition.js.map +0 -1
  89. package/dist/Command/commandProcessor.js.map +0 -1
  90. package/dist/Command/globalArgs.js.map +0 -1
  91. package/dist/CommandLine/IProgressBar.js.map +0 -1
  92. package/dist/CommandLine/progressBarFactory.js.map +0 -1
  93. package/dist/CustomScript/Generate/customScriptGenerateCommand.js.map +0 -1
  94. package/dist/CustomScript/Generate/customScriptGenerateFacade.js.map +0 -1
  95. package/dist/CustomScript/Upload/customScriptUploadCommand.js.map +0 -1
  96. package/dist/CustomScript/customScriptCommand.js.map +0 -1
  97. package/dist/CustomScript/customScriptFacade.js.map +0 -1
  98. package/dist/Device/Connect/connectCommand.js.map +0 -1
  99. package/dist/Device/Content/setContentCommand.js.map +0 -1
  100. package/dist/Device/PowerAction/powerActionCommand.js.map +0 -1
  101. package/dist/Device/deviceCommand.js.map +0 -1
  102. package/dist/Device/deviceFacade.js.map +0 -1
  103. package/dist/Emulator/IEmulator.js.map +0 -1
  104. package/dist/Emulator/createDomain.js.map +0 -1
  105. package/dist/Emulator/emulatorFacade.js.map +0 -1
  106. package/dist/Emulator/emulatorFactory.js.map +0 -1
  107. package/dist/Firmware/Upload/firmwareUploadCommand.js.map +0 -1
  108. package/dist/Firmware/Upload/firmwareUploadFacade.js.map +0 -1
  109. package/dist/Firmware/Upload/firmwareUploadHelper.js.map +0 -1
  110. package/dist/Firmware/firmwareCommand.js.map +0 -1
  111. package/dist/Lib/archive.js.map +0 -1
  112. package/dist/Lib/childProcess.js.map +0 -1
  113. package/dist/Lib/fileSystem.js.map +0 -1
  114. package/dist/Lib/git.js.map +0 -1
  115. package/dist/Organization/Get/organizationGetCommand.js.map +0 -1
  116. package/dist/Organization/List/organizationListCommand.js.map +0 -1
  117. package/dist/Organization/SetDefault/organizationSetDefaultCommand.js.map +0 -1
  118. package/dist/Organization/organizationCommand.js.map +0 -1
  119. package/dist/Organization/organizationFacade.js.map +0 -1
  120. package/dist/RunControl/runControlHelper.js.map +0 -1
  121. package/dist/Timer/wait.js.map +0 -1
  122. package/dist/Timing/List/timingListCommand.js.map +0 -1
  123. package/dist/Timing/timingCommand.js.map +0 -1
  124. package/dist/generalCommand.js.map +0 -1
  125. package/dist/helper.js.map +0 -1
  126. package/dist/index.js.map +0 -1
  127. package/dist/parameters.js.map +0 -1
@@ -8,42 +8,18 @@ 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
15
  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');
16
+ const debug_1 = __importDefault(require("debug"));
17
+ const prompts_1 = __importDefault(require("prompts"));
18
+ const helper_1 = require("../helper");
19
+ const IPowerAction_1 = require("@signageos/sdk/dist/RestApi/Device/PowerAction/IPowerAction");
20
+ const apiVersions_1 = require("@signageos/sdk/dist/RestApi/apiVersions");
21
+ const runControlHelper_1 = require("../RunControl/runControlHelper");
22
+ const Debug = (0, debug_1.default)('@signageos/cli:Device:facade');
47
23
  exports.typeMap = new Map([
48
24
  ['reboot', { name: 'Reboot Device', action: IPowerAction_1.DevicePowerAction.SystemReboot }],
49
25
  ['displayOn', { name: 'Display ON', action: IPowerAction_1.DevicePowerAction.DisplayPowerOn }],
@@ -55,105 +31,73 @@ exports.typeMap = new Map([
55
31
  ['refresh', { name: 'Applet Refresh', action: IPowerAction_1.DevicePowerAction.AppletRefresh }],
56
32
  ]);
57
33
  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" };
34
+ exports.POWER_ACTION_TYPE_OPTION = { name: 'type', type: String, description: `Type of device power action` };
59
35
  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
- });
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ let deviceUid = options['device-uid'];
38
+ if (!deviceUid) {
39
+ const devices = yield restApi.device.list();
40
+ const response = yield (0, prompts_1.default)({
41
+ type: 'autocomplete',
42
+ name: 'deviceUid',
43
+ message: `Select device to use`,
44
+ choices: devices.map((dev) => {
45
+ var _a;
46
+ return ({
47
+ title: `${(_a = dev.name) !== null && _a !== void 0 ? _a : `Unnamed device, created ${dev.createdAt.toString()}`} (${dev.uid})`,
48
+ value: dev.uid,
49
+ });
50
+ }),
51
+ });
52
+ Debug('Device selected', response.deviceUid);
53
+ deviceUid = response.deviceUid;
54
+ }
55
+ if (!deviceUid) {
56
+ throw new Error('Missing argument --device-uid <string>');
57
+ }
58
+ return deviceUid;
94
59
  });
95
60
  }
96
61
  exports.getDeviceUid = getDeviceUid;
97
62
  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
- });
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ let action = options.type;
65
+ if (!action) {
66
+ const response = yield (0, prompts_1.default)({
67
+ type: 'autocomplete',
68
+ name: 'type',
69
+ message: `Select device power action`,
70
+ choices: Array.from(exports.typeMap).map((item) => ({
71
+ title: item[1].name,
72
+ value: item[0],
73
+ })),
74
+ });
75
+ action = response.type;
76
+ }
77
+ if (!action) {
78
+ throw new Error('Missing argument --type <string>');
79
+ }
80
+ if (!exports.typeMap.get(action)) {
81
+ throw new Error(`Wrong power action type argument --type. Action ${options.type} is not defined`);
82
+ }
83
+ return action;
128
84
  });
129
85
  }
130
86
  exports.getActionType = getActionType;
131
87
  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
- });
88
+ return __awaiter(this, void 0, void 0, function* () {
89
+ const config = yield (0, runControlHelper_1.loadConfig)();
90
+ const DEVICE_RESOURCE = `/device/${deviceUid}/disconnect`;
91
+ const options = {
92
+ url: (0, helper_1.getApiUrl)(config),
93
+ auth: {
94
+ clientId: organization.oauthClientId,
95
+ secret: organization.oauthClientSecret,
96
+ },
97
+ version: apiVersions_1.ApiVersions.V1,
98
+ };
99
+ const responseOfPost = yield (0, helper_1.postResource)(options, DEVICE_RESOURCE, null, { deviceUid: `${deviceUid}` });
100
+ return JSON.parse(yield responseOfPost.text(), helper_1.deserializeJSON);
156
101
  });
157
102
  }
158
103
  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,25 +1,46 @@
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 (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.createDomain = void 0;
4
- var url = require("url");
5
- var ip = require("internal-ip");
27
+ const url = __importStar(require("url"));
28
+ const ip = __importStar(require("internal-ip"));
6
29
  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;
30
+ const protocol = options.https ? 'https' : 'http';
31
+ const hostname = options.useLocalIp ? ip.v4.sync() || 'localhost' : options.host || 'localhost';
32
+ const serverAddress = server === null || server === void 0 ? void 0 : server.address();
33
+ const port = options.socket ? 0 : server ? (typeof serverAddress === 'object' ? (serverAddress === null || serverAddress === void 0 ? void 0 : serverAddress.port) || 0 : 0) : 0;
12
34
  // use explicitly defined public url
13
35
  // (prefix with protocol if not explicitly given)
14
36
  if (options.public) {
15
- return /^[a-zA-Z]+:\/\//.test(options.public) ? "".concat(options.public) : "".concat(protocol, "://").concat(options.public);
37
+ return /^[a-zA-Z]+:\/\//.test(options.public) ? `${options.public}` : `${protocol}://${options.public}`;
16
38
  }
17
39
  // the formatted domain (url without path) of the webpack server
18
40
  return url.format({
19
- protocol: protocol,
20
- hostname: hostname,
21
- port: port,
41
+ protocol,
42
+ hostname,
43
+ port,
22
44
  });
23
45
  }
24
46
  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
15
  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) {
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,75 @@ 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
+ var _a, _b, _c, _d, _e, _f, _g, _h;
64
+ return __awaiter(this, void 0, void 0, function* () {
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
109
  exports.loadEmulatorOrCreateNewAndReturnUid = loadEmulatorOrCreateNewAndReturnUid;
166
- //# sourceMappingURL=emulatorFacade.js.map