@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
@@ -1,4 +1,37 @@
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
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,291 +41,177 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
41
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
42
  });
10
43
  };
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
- }
44
+ var __importDefault = (this && this.__importDefault) || function (mod) {
45
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
46
  };
38
47
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.createMultiFileFileApplet = exports.createSingleFileApplet = exports.updateMultiFileApplet = exports.updateSingleFileApplet = void 0;
40
- var path = require("path");
41
- var fs = require("fs-extra");
42
- var chalk_1 = require("chalk");
43
- var Debug = require("debug");
44
- var NotFoundError_1 = require("@signageos/sdk/dist/RestApi/Error/NotFoundError");
45
- var appletUploadFacadeHelper_1 = require("./appletUploadFacadeHelper");
46
- var fileSystem_1 = require("../../Lib/fileSystem");
47
- var log_1 = require("@signageos/sdk/dist/Console/log");
48
- var debug = Debug('@signageos/cli:Applet:Upload:appletUploadFacade');
48
+ exports.createMultiFileFileApplet = exports.createSingleFileApplet = exports.updateMultiFileApplet = void 0;
49
+ exports.updateSingleFileApplet = updateSingleFileApplet;
50
+ const path = __importStar(require("path"));
51
+ const fs = __importStar(require("fs-extra"));
52
+ const chalk_1 = __importDefault(require("chalk"));
53
+ const debug_1 = __importDefault(require("debug"));
54
+ const NotFoundError_1 = __importDefault(require("@signageos/sdk/dist/RestApi/Error/NotFoundError"));
55
+ const appletUploadFacadeHelper_1 = require("./appletUploadFacadeHelper");
56
+ const fileSystem_1 = require("../../Lib/fileSystem");
57
+ const log_1 = require("@signageos/sdk/dist/Console/log");
58
+ const Debug = (0, debug_1.default)('@signageos/cli:Applet:Upload:appletUploadFacade');
49
59
  function updateSingleFileApplet(parameters) {
50
- return __awaiter(this, void 0, void 0, function () {
51
- var restApi, applet, appletBinary;
52
- return __generator(this, function (_a) {
53
- switch (_a.label) {
54
- case 0:
55
- restApi = parameters.restApi, applet = parameters.applet;
56
- appletBinary = fs.createReadStream(applet.binaryFilePath, { encoding: 'utf8' });
57
- return [4 /*yield*/, restApi.applet.version.update(applet.uid, applet.version, {
58
- binary: appletBinary,
59
- frontAppletVersion: applet.frontAppletVersion,
60
- })];
61
- case 1:
62
- _a.sent();
63
- return [2 /*return*/];
64
- }
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ const { restApi, applet } = parameters;
62
+ const appletBinary = fs.createReadStream(applet.binaryFilePath, { encoding: 'utf8' });
63
+ yield restApi.applet.version.update(applet.uid, applet.version, {
64
+ binary: appletBinary,
65
+ frontAppletVersion: applet.frontAppletVersion,
65
66
  });
66
67
  });
67
68
  }
68
- exports.updateSingleFileApplet = updateSingleFileApplet;
69
- var updateMultiFileApplet = function (parameters) { return __awaiter(void 0, void 0, void 0, function () {
70
- var restApi, applet, progressBar, currentAppletFiles, changedFilesCounter, index, fileAbsolutePath, fileRelativePath, fileRelativePosixPath, fileSize, fileHash, fileType, currentFileHash, currentFileType, fileStream, error_1, _a, _b, _i, fileRelativePath, error_2, appletVersion, appletEntryFilePosixPath;
71
- return __generator(this, function (_c) {
72
- switch (_c.label) {
73
- case 0:
74
- restApi = parameters.restApi, applet = parameters.applet, progressBar = parameters.progressBar;
75
- return [4 /*yield*/, (0, appletUploadFacadeHelper_1.getAppletFilesDictionary)(restApi, applet.uid, applet.version)];
76
- case 1:
77
- currentAppletFiles = _c.sent();
78
- changedFilesCounter = 0;
79
- index = 0;
80
- _c.label = 2;
81
- case 2:
82
- if (!(index < applet.files.length)) return [3 /*break*/, 10];
83
- fileAbsolutePath = applet.files[index];
84
- fileRelativePath = (0, appletUploadFacadeHelper_1.getAppletFileRelativePath)(fileAbsolutePath, applet.directoryPath);
85
- fileRelativePosixPath = path.posix.normalize(fileRelativePath.replace(/\\/g, '/'));
86
- return [4 /*yield*/, fs.stat(fileAbsolutePath)];
87
- case 3:
88
- fileSize = (_c.sent()).size;
89
- return [4 /*yield*/, (0, fileSystem_1.getFileMD5Checksum)(fileAbsolutePath)];
90
- case 4:
91
- fileHash = _c.sent();
92
- return [4 /*yield*/, (0, fileSystem_1.getFileType)(fileAbsolutePath)];
93
- case 5:
94
- fileType = _c.sent();
95
- currentFileHash = currentAppletFiles[fileRelativePosixPath] ? currentAppletFiles[fileRelativePosixPath].hash : undefined;
96
- currentFileType = currentAppletFiles[fileRelativePosixPath] ? currentAppletFiles[fileRelativePosixPath].type : undefined;
97
- delete currentAppletFiles[fileRelativePosixPath];
98
- debug('check file changed', fileHash, currentFileHash, fileType, currentFileType);
99
- if (fileHash === currentFileHash && fileType === currentFileType) {
100
- return [3 /*break*/, 9];
101
- }
102
- else {
103
- changedFilesCounter++;
104
- (0, log_1.log)('info', chalk_1.default.yellow(" Uploading ".concat(fileAbsolutePath)));
105
- }
106
- if (progressBar) {
107
- progressBar.init({ size: fileSize, name: fileRelativePath });
108
- }
109
- fileStream = fs.createReadStream(fileAbsolutePath);
110
- fileStream.pause();
111
- fileStream.on('data', function (chunk) {
112
- if (progressBar) {
113
- progressBar.update({ add: chunk.length });
114
- }
115
- });
116
- _c.label = 6;
117
- case 6:
118
- _c.trys.push([6, 8, , 9]);
119
- // update file is just alias to create file (both are idempotent)
120
- return [4 /*yield*/, restApi.applet.version.file.update(applet.uid, applet.version, fileRelativePosixPath, {
121
- content: fileStream,
122
- hash: fileHash,
123
- size: fileSize,
124
- type: fileType,
125
- }, { build: false })];
126
- case 7:
127
- // update file is just alias to create file (both are idempotent)
128
- _c.sent();
129
- return [3 /*break*/, 9];
130
- case 8:
131
- error_1 = _c.sent();
132
- if (fileSize === 0) {
133
- throw new Error("Empty files are temporarily disallowed ".concat(fileAbsolutePath));
134
- }
135
- throw error_1;
136
- case 9:
137
- index++;
138
- return [3 /*break*/, 2];
139
- case 10:
140
- _a = [];
141
- for (_b in currentAppletFiles)
142
- _a.push(_b);
143
- _i = 0;
144
- _c.label = 11;
145
- case 11:
146
- if (!(_i < _a.length)) return [3 /*break*/, 17];
147
- fileRelativePath = _a[_i];
148
- if (!currentAppletFiles.hasOwnProperty(fileRelativePath)) return [3 /*break*/, 16];
149
- _c.label = 12;
150
- case 12:
151
- _c.trys.push([12, 14, , 15]);
152
- return [4 /*yield*/, restApi.applet.version.file.remove(applet.uid, applet.version, fileRelativePath, { build: false })];
153
- case 13:
154
- _c.sent();
155
- return [3 /*break*/, 15];
156
- case 14:
157
- error_2 = _c.sent();
158
- if (error_2 instanceof NotFoundError_1.default) {
69
+ const updateMultiFileApplet = (parameters) => __awaiter(void 0, void 0, void 0, function* () {
70
+ var _a, _b;
71
+ const { restApi, applet, progressBar } = parameters;
72
+ const currentAppletFiles = yield (0, appletUploadFacadeHelper_1.getAppletFilesDictionary)(restApi, applet.uid, applet.version);
73
+ let changedFilesCounter = 0;
74
+ for (let index = 0; index < applet.files.length; index++) {
75
+ const fileAbsolutePath = applet.files[index];
76
+ if (!fileAbsolutePath) {
77
+ continue;
78
+ }
79
+ const fileRelativePath = (0, appletUploadFacadeHelper_1.getAppletFileRelativePath)(fileAbsolutePath, applet.directoryPath);
80
+ const fileRelativePosixPath = path.posix.normalize(fileRelativePath.replace(/\\/g, '/'));
81
+ const fileStats = yield fs.stat(fileAbsolutePath);
82
+ const fileSize = fileStats.size;
83
+ const fileHash = yield (0, fileSystem_1.getFileMD5Checksum)(fileAbsolutePath);
84
+ const fileType = yield (0, fileSystem_1.getFileType)(fileAbsolutePath);
85
+ const currentFileHash = (_a = currentAppletFiles[fileRelativePosixPath]) === null || _a === void 0 ? void 0 : _a.hash;
86
+ const currentFileType = (_b = currentAppletFiles[fileRelativePosixPath]) === null || _b === void 0 ? void 0 : _b.type;
87
+ delete currentAppletFiles[fileRelativePosixPath];
88
+ Debug('check file changed', fileHash, currentFileHash, fileType, currentFileType);
89
+ if (fileHash === currentFileHash && fileType === currentFileType) {
90
+ continue;
91
+ }
92
+ else {
93
+ changedFilesCounter++;
94
+ (0, log_1.log)('info', chalk_1.default.yellow(` Uploading ${fileAbsolutePath}`));
95
+ }
96
+ if (progressBar) {
97
+ progressBar.init({ size: fileSize, name: fileRelativePath });
98
+ }
99
+ const fileStream = fs.createReadStream(fileAbsolutePath);
100
+ fileStream.pause();
101
+ fileStream.on('data', (chunk) => {
102
+ if (progressBar) {
103
+ progressBar.update({ add: chunk.length });
104
+ }
105
+ });
106
+ try {
107
+ // update file is just alias to create file (both are idempotent)
108
+ yield restApi.applet.version.file.update(applet.uid, applet.version, fileRelativePosixPath, {
109
+ content: fileStream,
110
+ hash: fileHash,
111
+ size: fileSize,
112
+ type: fileType,
113
+ }, { build: false });
114
+ }
115
+ catch (error) {
116
+ if (fileSize === 0) {
117
+ throw new Error(`Empty files are temporarily disallowed ${fileAbsolutePath}`);
118
+ }
119
+ throw error;
120
+ }
121
+ }
122
+ for (const fileRelativePath in currentAppletFiles) {
123
+ if (currentAppletFiles.hasOwnProperty(fileRelativePath)) {
124
+ try {
125
+ yield restApi.applet.version.file.remove(applet.uid, applet.version, fileRelativePath, { build: false });
126
+ }
127
+ catch (error) {
128
+ if (error instanceof NotFoundError_1.default) {
159
129
  /*
160
130
  * This means that the file we are trying to remove somehow already got removed.
161
131
  * It's not expected behavior but the running CLI command shouldn't fail because of it.
162
132
  * Probably it's caused by some other process interfering.
163
133
  */
164
- debug("remove old file ".concat(fileRelativePath, " failed"));
134
+ Debug(`remove old file ${fileRelativePath} failed`);
165
135
  }
166
136
  else {
167
- throw error_2;
168
- }
169
- return [3 /*break*/, 15];
170
- case 15:
171
- changedFilesCounter++;
172
- _c.label = 16;
173
- case 16:
174
- _i++;
175
- return [3 /*break*/, 11];
176
- case 17: return [4 /*yield*/, restApi.applet.version.get(applet.uid, applet.version)];
177
- case 18:
178
- appletVersion = _c.sent();
179
- appletEntryFilePosixPath = path.posix.normalize(applet.entryFilePath.replace(/\\/g, '/'));
180
- if (!(changedFilesCounter > 0 || appletVersion.entryFile !== appletEntryFilePosixPath)) return [3 /*break*/, 20];
181
- // The update applet version has to be the last after upload all files to trigger applet version build
182
- return [4 /*yield*/, restApi.applet.version.update(applet.uid, applet.version, {
183
- entryFile: appletEntryFilePosixPath,
184
- })];
185
- case 19:
186
- // The update applet version has to be the last after upload all files to trigger applet version build
187
- _c.sent();
188
- _c.label = 20;
189
- case 20:
190
- if (progressBar) {
191
- progressBar.end();
137
+ throw error;
192
138
  }
193
- if (changedFilesCounter === 0) {
194
- (0, log_1.log)('info', "No files changed in ".concat(chalk_1.default.yellow.bold(applet.directoryPath)));
195
- }
196
- return [2 /*return*/];
139
+ }
140
+ changedFilesCounter++;
197
141
  }
198
- });
199
- }); };
142
+ }
143
+ const appletVersion = yield restApi.applet.version.get(applet.uid, applet.version);
144
+ const appletEntryFilePosixPath = path.posix.normalize(applet.entryFilePath.replace(/\\/g, '/'));
145
+ if (changedFilesCounter > 0 || appletVersion.entryFile !== appletEntryFilePosixPath) {
146
+ // The update applet version has to be the last after upload all files to trigger applet version build
147
+ yield restApi.applet.version.update(applet.uid, applet.version, {
148
+ entryFile: appletEntryFilePosixPath,
149
+ });
150
+ }
151
+ if (progressBar) {
152
+ progressBar.end();
153
+ }
154
+ if (changedFilesCounter === 0) {
155
+ (0, log_1.log)('info', `No files changed in ${chalk_1.default.yellow.bold(applet.directoryPath)}`);
156
+ }
157
+ });
200
158
  exports.updateMultiFileApplet = updateMultiFileApplet;
201
- var createSingleFileApplet = function (parameters) { return __awaiter(void 0, void 0, void 0, function () {
202
- var restApi, applet, appletBinary;
203
- return __generator(this, function (_a) {
204
- switch (_a.label) {
205
- case 0:
206
- restApi = parameters.restApi, applet = parameters.applet;
207
- appletBinary = fs.createReadStream(applet.binaryFilePath, { encoding: 'utf8' });
208
- return [4 /*yield*/, restApi.applet.version.create(applet.uid, {
209
- binary: appletBinary,
210
- version: applet.version,
211
- frontAppletVersion: applet.frontAppletVersion,
212
- })];
213
- case 1:
214
- _a.sent();
215
- return [2 /*return*/];
216
- }
159
+ const createSingleFileApplet = (parameters) => __awaiter(void 0, void 0, void 0, function* () {
160
+ const { restApi, applet } = parameters;
161
+ const appletBinary = fs.createReadStream(applet.binaryFilePath, { encoding: 'utf8' });
162
+ yield restApi.applet.version.create(applet.uid, {
163
+ binary: appletBinary,
164
+ version: applet.version,
165
+ frontAppletVersion: applet.frontAppletVersion,
217
166
  });
218
- }); };
167
+ });
219
168
  exports.createSingleFileApplet = createSingleFileApplet;
220
- var createMultiFileFileApplet = function (parameters) { return __awaiter(void 0, void 0, void 0, function () {
221
- var restApi, applet, progressBar, appletEntryFilePosixPath;
222
- return __generator(this, function (_a) {
223
- switch (_a.label) {
224
- case 0:
225
- restApi = parameters.restApi, applet = parameters.applet, progressBar = parameters.progressBar;
226
- appletEntryFilePosixPath = path.posix.normalize(applet.entryFilePath.replace(/\\/g, '/'));
227
- _a.label = 1;
228
- case 1:
229
- _a.trys.push([1, , 4, 5]);
230
- return [4 /*yield*/, restApi.applet.version.create(applet.uid, {
231
- version: applet.version,
232
- entryFile: appletEntryFilePosixPath,
233
- })];
234
- case 2:
235
- _a.sent();
236
- return [4 /*yield*/, Promise.all(applet.files.map(function (fileAbsolutePath) { return __awaiter(void 0, void 0, void 0, function () {
237
- var fileRelativePath, fileHash, fileType, fileSize, fileStream, filePosixPath;
238
- return __generator(this, function (_a) {
239
- switch (_a.label) {
240
- case 0:
241
- fileRelativePath = (0, appletUploadFacadeHelper_1.getAppletFileRelativePath)(fileAbsolutePath, applet.directoryPath);
242
- return [4 /*yield*/, (0, fileSystem_1.getFileMD5Checksum)(fileAbsolutePath)];
243
- case 1:
244
- fileHash = _a.sent();
245
- return [4 /*yield*/, (0, fileSystem_1.getFileType)(fileAbsolutePath)];
246
- case 2:
247
- fileType = _a.sent();
248
- return [4 /*yield*/, fs.stat(fileAbsolutePath)];
249
- case 3:
250
- fileSize = (_a.sent()).size;
251
- if (fileSize === 0) {
252
- throw new Error("Empty files are temporarily disallowed ".concat(fileAbsolutePath));
253
- }
254
- if (progressBar) {
255
- progressBar.init({ size: fileSize, name: fileRelativePath });
256
- }
257
- fileStream = fs.createReadStream(fileAbsolutePath);
258
- fileStream.pause();
259
- fileStream.on('data', function (chunk) {
260
- if (progressBar) {
261
- progressBar.update({ add: chunk.length });
262
- }
263
- });
264
- filePosixPath = path.posix.normalize(fileRelativePath.replace(/\\/g, '/'));
265
- (0, log_1.log)('info', chalk_1.default.yellow(" Uploading ".concat(fileAbsolutePath)));
266
- return [2 /*return*/, restApi.applet.version.file.create(applet.uid, applet.version, {
267
- name: path.basename(filePosixPath),
268
- path: filePosixPath,
269
- type: fileType,
270
- hash: fileHash,
271
- content: fileStream,
272
- size: fileSize,
273
- }, { build: false })];
274
- }
275
- });
276
- }); }))];
277
- case 3:
278
- _a.sent();
279
- return [3 /*break*/, 5];
280
- case 4:
169
+ const createMultiFileFileApplet = (parameters) => __awaiter(void 0, void 0, void 0, function* () {
170
+ const { restApi, applet, progressBar } = parameters;
171
+ const appletEntryFilePosixPath = path.posix.normalize(applet.entryFilePath.replace(/\\/g, '/'));
172
+ try {
173
+ yield restApi.applet.version.create(applet.uid, {
174
+ version: applet.version,
175
+ entryFile: appletEntryFilePosixPath,
176
+ });
177
+ yield Promise.all(applet.files.map((fileAbsolutePath) => __awaiter(void 0, void 0, void 0, function* () {
178
+ const fileRelativePath = (0, appletUploadFacadeHelper_1.getAppletFileRelativePath)(fileAbsolutePath, applet.directoryPath);
179
+ const fileHash = yield (0, fileSystem_1.getFileMD5Checksum)(fileAbsolutePath);
180
+ const fileType = yield (0, fileSystem_1.getFileType)(fileAbsolutePath);
181
+ const fileSize = (yield fs.stat(fileAbsolutePath)).size;
182
+ if (fileSize === 0) {
183
+ throw new Error(`Empty files are temporarily disallowed ${fileAbsolutePath}`);
184
+ }
185
+ if (progressBar) {
186
+ progressBar.init({ size: fileSize, name: fileRelativePath });
187
+ }
188
+ const fileStream = fs.createReadStream(fileAbsolutePath);
189
+ fileStream.pause();
190
+ fileStream.on('data', (chunk) => {
281
191
  if (progressBar) {
282
- progressBar.end();
192
+ progressBar.update({ add: chunk.length });
283
193
  }
284
- return [7 /*endfinally*/];
285
- case 5:
286
- // The extra update applet version which has to be after upload all files to trigger applet version build
287
- return [4 /*yield*/, restApi.applet.version.update(applet.uid, applet.version, {
288
- entryFile: appletEntryFilePosixPath,
289
- })];
290
- case 6:
291
- // The extra update applet version which has to be after upload all files to trigger applet version build
292
- _a.sent();
293
- return [2 /*return*/];
194
+ });
195
+ const filePosixPath = path.posix.normalize(fileRelativePath.replace(/\\/g, '/'));
196
+ (0, log_1.log)('info', chalk_1.default.yellow(` Uploading ${fileAbsolutePath}`));
197
+ return restApi.applet.version.file.create(applet.uid, applet.version, {
198
+ name: path.basename(filePosixPath),
199
+ path: filePosixPath,
200
+ type: fileType,
201
+ hash: fileHash,
202
+ content: fileStream,
203
+ size: fileSize,
204
+ }, { build: false });
205
+ })));
206
+ }
207
+ finally {
208
+ if (progressBar) {
209
+ progressBar.end();
294
210
  }
211
+ }
212
+ // The extra update applet version which has to be after upload all files to trigger applet version build
213
+ yield restApi.applet.version.update(applet.uid, applet.version, {
214
+ entryFile: appletEntryFilePosixPath,
295
215
  });
296
- }); };
216
+ });
297
217
  exports.createMultiFileFileApplet = createMultiFileFileApplet;
298
- //# sourceMappingURL=appletUploadFacade.js.map
@@ -1,4 +1,37 @@
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
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,72 +41,35 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
41
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
42
  });
10
43
  };
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
- }
37
- };
38
44
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.getAppletFilesDictionary = exports.getAppletFileRelativePath = void 0;
40
- var path = require("path");
45
+ exports.getAppletFileRelativePath = getAppletFileRelativePath;
46
+ exports.getAppletFilesDictionary = getAppletFilesDictionary;
47
+ const path = __importStar(require("path"));
41
48
  function getAppletFileRelativePath(fileAbsolutePath, directoryAbsolutePath) {
42
- var directoryAbsolutePathNormalized = path.normalize(directoryAbsolutePath);
43
- var fileAbsolutePathNormalized = path.normalize(fileAbsolutePath);
49
+ const directoryAbsolutePathNormalized = path.normalize(directoryAbsolutePath);
50
+ const fileAbsolutePathNormalized = path.normalize(fileAbsolutePath);
44
51
  if (!path.isAbsolute(fileAbsolutePathNormalized)) {
45
- throw new Error("Internal Error: Got relative file path, but need absolute to continue. Current path: ".concat(fileAbsolutePathNormalized));
52
+ throw new Error(`Internal Error: Got relative file path, but need absolute to continue. Current path: ${fileAbsolutePathNormalized}`);
46
53
  }
47
54
  if (!path.isAbsolute(directoryAbsolutePathNormalized)) {
48
- throw new Error("Internal Error: Try input absolute applet directory path. Current path: ".concat(directoryAbsolutePathNormalized));
55
+ throw new Error(`Internal Error: Try input absolute applet directory path. Current path: ${directoryAbsolutePathNormalized}`);
49
56
  }
50
- var isFileInAppletDir = fileAbsolutePathNormalized.startsWith(directoryAbsolutePathNormalized);
57
+ const isFileInAppletDir = fileAbsolutePathNormalized.startsWith(directoryAbsolutePathNormalized);
51
58
  if (!isFileInAppletDir) {
52
- throw new Error("All project files must be in the project directory." +
53
- "\nFile path: ".concat(fileAbsolutePathNormalized) +
54
- "\nApplet directory path: ".concat(directoryAbsolutePathNormalized));
59
+ throw new Error(`All project files must be in the project directory.` +
60
+ `\nFile path: ${fileAbsolutePathNormalized}` +
61
+ `\nApplet directory path: ${directoryAbsolutePathNormalized}`);
55
62
  }
56
- var fileRelativePath = fileAbsolutePathNormalized.substring(directoryAbsolutePathNormalized.length + 1);
63
+ const fileRelativePath = fileAbsolutePathNormalized.substring(directoryAbsolutePathNormalized.length + 1);
57
64
  return fileRelativePath;
58
65
  }
59
- exports.getAppletFileRelativePath = getAppletFileRelativePath;
60
66
  function getAppletFilesDictionary(restApi, appletUid, appletVersion) {
61
- return __awaiter(this, void 0, void 0, function () {
62
- var filesDictionary, currentAppletFiles;
63
- return __generator(this, function (_a) {
64
- switch (_a.label) {
65
- case 0:
66
- filesDictionary = {};
67
- return [4 /*yield*/, restApi.applet.version.file.list(appletUid, appletVersion)];
68
- case 1:
69
- currentAppletFiles = _a.sent();
70
- currentAppletFiles.forEach(function (file) {
71
- filesDictionary[file.path] = file;
72
- });
73
- return [2 /*return*/, filesDictionary];
74
- }
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ const filesDictionary = {};
69
+ const currentAppletFiles = yield restApi.applet.version.file.list(appletUid, appletVersion);
70
+ currentAppletFiles.forEach((file) => {
71
+ filesDictionary[file.path] = file;
75
72
  });
73
+ return filesDictionary;
76
74
  });
77
75
  }
78
- exports.getAppletFilesDictionary = getAppletFilesDictionary;
79
- //# sourceMappingURL=appletUploadFacadeHelper.js.map