@nordicsemiconductor/nrf-jlink-js 0.0.5 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { downloadAndInstallJLink, getVersionToInstall, downloadAndSaveJLink } from './jlink';
2
- export { downloadAndInstallJLink, getVersionToInstall, downloadAndSaveJLink };
1
+ import { downloadAndInstallJLink, getVersionToInstall, downloadAndSaveJLink, installJLink, Update as JLinkUpdate } from './jlink';
2
+ export { downloadAndInstallJLink, getVersionToInstall, downloadAndSaveJLink, installJLink, JLinkUpdate, };
package/dist/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.downloadAndSaveJLink = exports.getVersionToInstall = exports.downloadAndInstallJLink = void 0;
3
+ exports.installJLink = exports.downloadAndSaveJLink = exports.getVersionToInstall = exports.downloadAndInstallJLink = void 0;
4
4
  var jlink_1 = require("./jlink");
5
5
  Object.defineProperty(exports, "downloadAndInstallJLink", { enumerable: true, get: function () { return jlink_1.downloadAndInstallJLink; } });
6
6
  Object.defineProperty(exports, "getVersionToInstall", { enumerable: true, get: function () { return jlink_1.getVersionToInstall; } });
7
7
  Object.defineProperty(exports, "downloadAndSaveJLink", { enumerable: true, get: function () { return jlink_1.downloadAndSaveJLink; } });
8
+ Object.defineProperty(exports, "installJLink", { enumerable: true, get: function () { return jlink_1.installJLink; } });
package/dist/jlink.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- interface Update {
1
+ export interface Update {
2
2
  step: 'install' | 'download';
3
3
  percentage: number;
4
4
  }
5
+ export declare const installJLink: (installerPath: string, onUpdate?: (update: Update) => void) => Promise<void>;
5
6
  interface JLinkState {
6
7
  outdated: boolean;
7
8
  installed: boolean;
@@ -9,6 +10,6 @@ interface JLinkState {
9
10
  installedVersion?: string;
10
11
  }
11
12
  export declare const getVersionToInstall: (fallbackVersion?: string) => Promise<JLinkState>;
12
- export declare const downloadAndSaveJLink: (destination: string, onUpdate?: (percentage: number) => void) => Promise<string>;
13
+ export declare const downloadAndSaveJLink: (destination: string, onUpdate?: (update: Update) => void) => Promise<string>;
13
14
  export declare const downloadAndInstallJLink: (onUpdate?: (update: Update) => void) => Promise<void>;
14
15
  export {};
package/dist/jlink.js CHANGED
@@ -35,20 +35,11 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
36
  }
37
37
  };
38
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
- if (ar || !(i in from)) {
41
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
- ar[i] = from[i];
43
- }
44
- }
45
- return to.concat(ar || Array.prototype.slice.call(from));
46
- };
47
38
  var __importDefault = (this && this.__importDefault) || function (mod) {
48
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
49
40
  };
50
41
  Object.defineProperty(exports, "__esModule", { value: true });
51
- exports.downloadAndInstallJLink = exports.downloadAndSaveJLink = exports.getVersionToInstall = void 0;
42
+ exports.downloadAndInstallJLink = exports.downloadAndSaveJLink = exports.getVersionToInstall = exports.installJLink = void 0;
52
43
  var child_process_1 = require("child_process");
53
44
  var os_1 = __importDefault(require("os"));
54
45
  var path_1 = __importDefault(require("path"));
@@ -112,52 +103,45 @@ var getInstalledJLinkVersion = function () {
112
103
  });
113
104
  });
114
105
  };
115
- var downloadJLink = function (_a, onUpdate_1) {
116
- var args_1 = [];
117
- for (var _i = 2; _i < arguments.length; _i++) {
118
- args_1[_i - 2] = arguments[_i];
119
- }
120
- return __awaiter(void 0, __spreadArray([_a, onUpdate_1], args_1, true), void 0, function (_b, onUpdate, destinationPath) {
121
- var platform, arch, url, _c, status, stream;
122
- var _d;
123
- var jlinkUrls = _b.jlinkUrls;
124
- if (destinationPath === void 0) { destinationPath = os_1.default.tmpdir(); }
125
- return __generator(this, function (_e) {
126
- switch (_e.label) {
127
- case 0:
128
- platform = os_1.default.platform();
129
- arch = os_1.default.arch();
130
- // @ts-expect-error It is quite literally checked right before
131
- if (!(platform in jlinkUrls) || !(arch in jlinkUrls[platform])) {
132
- throw new Error("JLink not available for ".concat(platform, "/").concat(arch));
133
- }
134
- url = (_d = jlinkUrls[platform]) === null || _d === void 0 ? void 0 : _d[arch];
135
- if (!url) {
136
- throw new Error("JLink not available for ".concat(platform, "/").concat(arch));
137
- }
138
- return [4 /*yield*/, axios_1.default.get(url, {
139
- responseType: 'stream',
140
- onDownloadProgress: function (_a) {
141
- var loaded = _a.loaded, total = _a.total;
142
- return loaded &&
143
- total &&
144
- (onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate({
145
- step: 'download',
146
- percentage: Number(((loaded / total) * 100).toFixed(2)),
147
- }));
148
- },
149
- })];
150
- case 1:
151
- _c = _e.sent(), status = _c.status, stream = _c.data;
152
- if (status !== 200) {
153
- throw new Error("Unable to download ".concat(url, ". Got status code ").concat(status, "."));
154
- }
155
- return [4 /*yield*/, (0, common_1.saveToFile)(stream, path_1.default.join(destinationPath, path_1.default.basename(url)))];
156
- case 2: return [2 /*return*/, _e.sent()];
157
- }
158
- });
106
+ var downloadJLink = function (_a, onUpdate_1, destinationFilePath_1) { return __awaiter(void 0, [_a, onUpdate_1, destinationFilePath_1], void 0, function (_b, onUpdate, destinationFilePath) {
107
+ var platform, arch, url, _c, status, stream;
108
+ var _d;
109
+ var jlinkUrls = _b.jlinkUrls;
110
+ return __generator(this, function (_e) {
111
+ switch (_e.label) {
112
+ case 0:
113
+ platform = os_1.default.platform();
114
+ arch = os_1.default.arch();
115
+ // @ts-expect-error It is quite literally checked right before
116
+ if (!(platform in jlinkUrls) || !(arch in jlinkUrls[platform])) {
117
+ throw new Error("JLink not available for ".concat(platform, "/").concat(arch));
118
+ }
119
+ url = (_d = jlinkUrls[platform]) === null || _d === void 0 ? void 0 : _d[arch];
120
+ if (!url) {
121
+ throw new Error("JLink not available for ".concat(platform, "/").concat(arch));
122
+ }
123
+ return [4 /*yield*/, axios_1.default.get(url, {
124
+ responseType: 'stream',
125
+ onDownloadProgress: function (_a) {
126
+ var loaded = _a.loaded, total = _a.total;
127
+ return loaded &&
128
+ total &&
129
+ (onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate({
130
+ step: 'download',
131
+ percentage: Number(((loaded / total) * 100).toFixed(2)),
132
+ }));
133
+ },
134
+ })];
135
+ case 1:
136
+ _c = _e.sent(), status = _c.status, stream = _c.data;
137
+ if (status !== 200) {
138
+ throw new Error("Unable to download ".concat(url, ". Got status code ").concat(status, "."));
139
+ }
140
+ return [4 /*yield*/, (0, common_1.saveToFile)(stream, destinationFilePath || path_1.default.join(os_1.default.tmpdir(), path_1.default.basename(url)))];
141
+ case 2: return [2 /*return*/, _e.sent()];
142
+ }
159
143
  });
160
- };
144
+ }); };
161
145
  var installJLink = function (installerPath, onUpdate) {
162
146
  var command;
163
147
  var args;
@@ -190,6 +174,7 @@ var installJLink = function (installerPath, onUpdate) {
190
174
  });
191
175
  });
192
176
  };
177
+ exports.installJLink = installJLink;
193
178
  var convertToSemverVersion = function (version) {
194
179
  var _a;
195
180
  var _b = (_a = version.match(/V?(\d+\.\d+)(.)?/)) !== null && _a !== void 0 ? _a : [], majorMinor = _b[1], patchLetter = _b[2];
@@ -227,12 +212,14 @@ var getVersionToInstall = function (fallbackVersion) { return __awaiter(void 0,
227
212
  }); };
228
213
  exports.getVersionToInstall = getVersionToInstall;
229
214
  var downloadAndSaveJLink = function (destination, onUpdate) {
230
- return (0, common_1.fetchIndex)().then(function (v) { return downloadJLink(v, function (update) { return onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate(update.percentage); }, destination); });
215
+ return (0, common_1.fetchIndex)().then(function (v) {
216
+ return downloadJLink(v, onUpdate, destination);
217
+ });
231
218
  };
232
219
  exports.downloadAndSaveJLink = downloadAndSaveJLink;
233
220
  var downloadAndInstallJLink = function (onUpdate) {
234
221
  return (0, common_1.fetchIndex)()
235
222
  .then(function (v) { return downloadJLink(v, onUpdate); })
236
- .then(function (v) { return installJLink(v, onUpdate); });
223
+ .then(function (v) { return (0, exports.installJLink)(v, onUpdate); });
237
224
  };
238
225
  exports.downloadAndInstallJLink = downloadAndInstallJLink;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nordicsemiconductor/nrf-jlink-js",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "main": "dist",
5
5
  "types": "dist",
6
6
  "files": [