@nordicsemiconductor/nrf-jlink-js 0.10.0 → 0.12.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.
- package/LICENSE +8 -7
- package/LICENSE.2 +38 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +10 -3
- package/dist/jlink.d.ts +3 -18
- package/dist/jlink.js +14 -265
- package/dist/operations/downloadJLink.d.ts +3 -0
- package/dist/operations/downloadJLink.js +97 -0
- package/dist/{common.d.ts → operations/fetchIndex.d.ts} +1 -1
- package/dist/{common.js → operations/fetchIndex.js} +9 -39
- package/dist/operations/getJLinkState.d.ts +23 -0
- package/dist/operations/getJLinkState.js +106 -0
- package/dist/operations/installJLink.d.ts +2 -0
- package/dist/operations/installJLink.js +47 -0
- package/dist/shared/fs.d.ts +5 -0
- package/dist/shared/fs.js +39 -0
- package/dist/shared/jLinkVersion.d.ts +2 -0
- package/dist/shared/jLinkVersion.js +182 -0
- package/dist/shared/net.d.ts +3 -0
- package/dist/shared/net.js +109 -0
- package/dist/shared/update.d.ts +5 -0
- package/dist/shared/update.js +7 -0
- package/package.json +2 -2
package/LICENSE
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
All rights reserved.
|
|
1
|
+
LicenseID: LicenseRef-Nordic-4-Clause
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
ExtractedText: <text>
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
Copyright (c) 2025 Nordic Semiconductor ASA All rights reserved.
|
|
6
|
+
|
|
7
|
+
Use in source and binary forms, redistribution in binary form only, with or
|
|
8
|
+
without modification, are permitted provided that the following conditions are
|
|
9
|
+
met:
|
|
9
10
|
|
|
10
11
|
1. Redistributions in binary form, except as embedded into a Nordic
|
|
11
12
|
Semiconductor ASA integrated circuit in a product or a software update for
|
|
@@ -32,4 +33,4 @@ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
32
33
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
33
34
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
|
34
35
|
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
35
|
-
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
36
|
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. </text>
|
package/LICENSE.2
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
LicenseID: LicenseRef-Nordic-4-Clause
|
|
2
|
+
|
|
3
|
+
ExtractedText: <text>
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2025 Nordic Semiconductor ASA
|
|
6
|
+
All rights reserved.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
Use in source and binary forms, redistribution in binary form only, with
|
|
10
|
+
or without modification, are permitted provided that the following conditions
|
|
11
|
+
are met:
|
|
12
|
+
|
|
13
|
+
1. Redistributions in binary form, except as embedded into a Nordic
|
|
14
|
+
Semiconductor ASA integrated circuit in a product or a software update for
|
|
15
|
+
such product, must reproduce the above copyright notice, this list of
|
|
16
|
+
conditions and the following disclaimer in the documentation and/or other
|
|
17
|
+
materials provided with the distribution.
|
|
18
|
+
|
|
19
|
+
2. Neither the name of Nordic Semiconductor ASA nor the names of its
|
|
20
|
+
contributors may be used to endorse or promote products derived from this
|
|
21
|
+
software without specific prior written permission.
|
|
22
|
+
|
|
23
|
+
3. This software, with or without modification, must only be used with a Nordic
|
|
24
|
+
Semiconductor ASA integrated circuit.
|
|
25
|
+
|
|
26
|
+
4. Any software provided in binary form under this license must not be reverse
|
|
27
|
+
engineered, decompiled, modified and/or disassembled.
|
|
28
|
+
|
|
29
|
+
THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR
|
|
30
|
+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
31
|
+
MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
32
|
+
DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE
|
|
33
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
34
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
35
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
36
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
|
37
|
+
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
38
|
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export { downloadAndInstallJLink,
|
|
1
|
+
export type { Update as JLinkUpdate } from './shared/update';
|
|
2
|
+
export { downloadAndInstallJLink, downloadAndSaveJLink } from './jlink';
|
|
3
|
+
export { getJLinkState, type JLinkState } from './operations/getJLinkState';
|
|
4
|
+
export { installJLink } from './operations/installJLink';
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Nordic Semiconductor ASA
|
|
4
|
+
*
|
|
5
|
+
* SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
|
|
6
|
+
*/
|
|
2
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.installJLink = exports.
|
|
8
|
+
exports.installJLink = exports.getJLinkState = exports.downloadAndSaveJLink = exports.downloadAndInstallJLink = void 0;
|
|
4
9
|
var jlink_1 = require("./jlink");
|
|
5
10
|
Object.defineProperty(exports, "downloadAndInstallJLink", { enumerable: true, get: function () { return jlink_1.downloadAndInstallJLink; } });
|
|
6
|
-
Object.defineProperty(exports, "getVersionToInstall", { enumerable: true, get: function () { return jlink_1.getVersionToInstall; } });
|
|
7
11
|
Object.defineProperty(exports, "downloadAndSaveJLink", { enumerable: true, get: function () { return jlink_1.downloadAndSaveJLink; } });
|
|
8
|
-
|
|
12
|
+
var getJLinkState_1 = require("./operations/getJLinkState");
|
|
13
|
+
Object.defineProperty(exports, "getJLinkState", { enumerable: true, get: function () { return getJLinkState_1.getJLinkState; } });
|
|
14
|
+
var installJLink_1 = require("./operations/installJLink");
|
|
15
|
+
Object.defineProperty(exports, "installJLink", { enumerable: true, get: function () { return installJLink_1.installJLink; } });
|
package/dist/jlink.d.ts
CHANGED
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
export declare const installJLink: (installerPath: string, onUpdate?: (update: Update) => void) => Promise<void>;
|
|
6
|
-
interface JLinkState {
|
|
7
|
-
outdated: boolean;
|
|
8
|
-
installed: boolean;
|
|
9
|
-
versionToBeInstalled?: string;
|
|
10
|
-
installedVersion?: string;
|
|
11
|
-
}
|
|
12
|
-
export declare const getVersionToInstall: ({ fallbackVersion, checkOnline, }?: {
|
|
13
|
-
fallbackVersion?: string;
|
|
14
|
-
checkOnline?: boolean;
|
|
15
|
-
}) => Promise<JLinkState>;
|
|
16
|
-
export declare const downloadAndSaveJLink: (destinationDir: string, destinationFileName?: string, onUpdate?: (update: Update) => void) => Promise<string>;
|
|
17
|
-
export declare const downloadAndInstallJLink: (onUpdate?: (update: Update) => void) => Promise<void>;
|
|
18
|
-
export {};
|
|
1
|
+
import type { OnUpdate } from './shared/update';
|
|
2
|
+
export declare const downloadAndSaveJLink: (destinationDir: string, destinationFileName?: string, onUpdate?: OnUpdate) => Promise<string>;
|
|
3
|
+
export declare const downloadAndInstallJLink: (onUpdate?: OnUpdate) => Promise<void>;
|
package/dist/jlink.js
CHANGED
|
@@ -1,274 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
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 = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["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 (g && (g = 0, op[0] && (_ = 0)), _) 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
|
-
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
48
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
49
|
-
};
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Nordic Semiconductor ASA
|
|
4
|
+
*
|
|
5
|
+
* SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
|
|
6
|
+
*/
|
|
50
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
-
exports.downloadAndInstallJLink = exports.downloadAndSaveJLink =
|
|
52
|
-
var
|
|
53
|
-
var
|
|
54
|
-
var
|
|
55
|
-
var semver_1 = __importDefault(require("semver"));
|
|
56
|
-
var fs_1 = require("fs");
|
|
57
|
-
var common_1 = require("./common");
|
|
58
|
-
var util_1 = require("util");
|
|
59
|
-
function winRegQuery(key) {
|
|
60
|
-
var _a;
|
|
61
|
-
if (process.platform !== 'win32') {
|
|
62
|
-
throw new Error('Unsupported platform');
|
|
63
|
-
}
|
|
64
|
-
var reg = path_1.default.resolve((_a = process.env.SystemRoot) !== null && _a !== void 0 ? _a : 'C:\\Windows', 'System32', 'reg.exe');
|
|
65
|
-
if (!(0, fs_1.existsSync)(reg)) {
|
|
66
|
-
reg = 'reg.exe';
|
|
67
|
-
}
|
|
68
|
-
return (0, child_process_1.execSync)("".concat(reg, " query ").concat(key)).toString().trim();
|
|
69
|
-
}
|
|
70
|
-
var getJLinkExePath = function () {
|
|
71
|
-
var _a;
|
|
72
|
-
switch (os_1.default.platform()) {
|
|
73
|
-
case 'win32':
|
|
74
|
-
var cwd = winRegQuery('HKEY_CURRENT_USER\\Software\\SEGGER\\J-Link /v InstallPath');
|
|
75
|
-
if (!cwd) {
|
|
76
|
-
cwd = winRegQuery('HKEY_LOCAL_MACHINE\\Software\\SEGGER\\J-Link /v InstallPath');
|
|
77
|
-
}
|
|
78
|
-
cwd = ((_a = /InstallPath\s+\w+\s+(.*)/.exec(cwd)) !== null && _a !== void 0 ? _a : [])[1];
|
|
79
|
-
if (!cwd) {
|
|
80
|
-
throw new Error('JLink not installed');
|
|
81
|
-
}
|
|
82
|
-
return "\"".concat(path_1.default.join(cwd, 'JLink.exe'), "\"");
|
|
83
|
-
case 'linux':
|
|
84
|
-
case 'darwin':
|
|
85
|
-
return 'JLinkExe';
|
|
86
|
-
default:
|
|
87
|
-
throw new Error('Invalid platform');
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
var getInstalledJLinkVersion = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
91
|
-
var output, versionRegExp, match;
|
|
92
|
-
var _a;
|
|
93
|
-
return __generator(this, function (_b) {
|
|
94
|
-
switch (_b.label) {
|
|
95
|
-
case 0: return [4 /*yield*/, (0, util_1.promisify)(child_process_1.exec)("".concat(getJLinkExePath(), " -CommandFile foo")).catch(function (e) { return e; })];
|
|
96
|
-
case 1:
|
|
97
|
-
output = _b.sent();
|
|
98
|
-
versionRegExp = /^SEGGER J-Link Commander V([0-9a-z.]+) .*$/m;
|
|
99
|
-
match = (_a = output.stdout.match(versionRegExp)) === null || _a === void 0 ? void 0 : _a[1];
|
|
100
|
-
if (!match) {
|
|
101
|
-
throw new Error("Couldn't get jlink version.");
|
|
102
|
-
}
|
|
103
|
-
return [2 /*return*/, "v".concat(match)];
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
}); };
|
|
107
|
-
var downloadJLink = function (_a, onUpdate_1) {
|
|
108
|
-
var args_1 = [];
|
|
109
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
110
|
-
args_1[_i - 2] = arguments[_i];
|
|
111
|
-
}
|
|
112
|
-
return __awaiter(void 0, __spreadArray([_a, onUpdate_1], args_1, true), void 0, function (_b, onUpdate, destinationDir, destinationFileName) {
|
|
113
|
-
var platform, arch, url, response, hasContentLength, contentLength, reader, chunks, receivedLength, _c, done, value, chunksAll, position;
|
|
114
|
-
var _d, _e;
|
|
115
|
-
var jlinkUrls = _b.jlinkUrls;
|
|
116
|
-
if (destinationDir === void 0) { destinationDir = os_1.default.tmpdir(); }
|
|
117
|
-
return __generator(this, function (_f) {
|
|
118
|
-
switch (_f.label) {
|
|
119
|
-
case 0:
|
|
120
|
-
platform = os_1.default.platform();
|
|
121
|
-
arch = os_1.default.arch();
|
|
122
|
-
// @ts-expect-error It is quite literally checked right before
|
|
123
|
-
if (!(platform in jlinkUrls) || !(arch in jlinkUrls[platform])) {
|
|
124
|
-
throw new Error("JLink not available for ".concat(platform, "/").concat(arch));
|
|
125
|
-
}
|
|
126
|
-
url = (_d = jlinkUrls[platform]) === null || _d === void 0 ? void 0 : _d[arch];
|
|
127
|
-
if (!url) {
|
|
128
|
-
throw new Error("JLink not available for ".concat(platform, "/").concat(arch));
|
|
129
|
-
}
|
|
130
|
-
return [4 /*yield*/, fetch(url, {
|
|
131
|
-
headers: {
|
|
132
|
-
Range: 'bytes=0-',
|
|
133
|
-
},
|
|
134
|
-
})];
|
|
135
|
-
case 1:
|
|
136
|
-
response = _f.sent();
|
|
137
|
-
if (!response.ok) {
|
|
138
|
-
throw new Error("Unable to download ".concat(url, ". Got status code ").concat(status, "."));
|
|
139
|
-
}
|
|
140
|
-
hasContentLength = response.headers.has('content-length');
|
|
141
|
-
contentLength = hasContentLength
|
|
142
|
-
? Number(response.headers.get('content-length'))
|
|
143
|
-
: 1;
|
|
144
|
-
reader = (_e = response.body) === null || _e === void 0 ? void 0 : _e.getReader();
|
|
145
|
-
chunks = [];
|
|
146
|
-
receivedLength = 0;
|
|
147
|
-
_f.label = 2;
|
|
148
|
-
case 2:
|
|
149
|
-
if (!reader) return [3 /*break*/, 4];
|
|
150
|
-
return [4 /*yield*/, reader.read()];
|
|
151
|
-
case 3:
|
|
152
|
-
_c = _f.sent(), done = _c.done, value = _c.value;
|
|
153
|
-
if (done) {
|
|
154
|
-
return [3 /*break*/, 4];
|
|
155
|
-
}
|
|
156
|
-
chunks.push(value);
|
|
157
|
-
receivedLength += value.length;
|
|
158
|
-
onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate({
|
|
159
|
-
step: 'download',
|
|
160
|
-
percentage: hasContentLength
|
|
161
|
-
? Number(((receivedLength / contentLength) * 100).toFixed(2))
|
|
162
|
-
: 0,
|
|
163
|
-
});
|
|
164
|
-
return [3 /*break*/, 2];
|
|
165
|
-
case 4:
|
|
166
|
-
chunksAll = new Uint8Array(receivedLength);
|
|
167
|
-
position = 0;
|
|
168
|
-
chunks.forEach(function (chunk) {
|
|
169
|
-
chunksAll.set(chunk, position);
|
|
170
|
-
position += chunk.length;
|
|
171
|
-
});
|
|
172
|
-
return [4 /*yield*/, (0, common_1.saveToFile)(path_1.default.join(destinationDir, destinationFileName || path_1.default.basename(url)), Buffer.from(chunksAll))];
|
|
173
|
-
case 5: return [2 /*return*/, _f.sent()];
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
};
|
|
178
|
-
var installJLink = function (installerPath, onUpdate) {
|
|
179
|
-
var command;
|
|
180
|
-
var args;
|
|
181
|
-
switch (os_1.default.platform()) {
|
|
182
|
-
case 'darwin':
|
|
183
|
-
command = 'open';
|
|
184
|
-
args = ['-W', installerPath];
|
|
185
|
-
break;
|
|
186
|
-
case 'linux':
|
|
187
|
-
command = 'pkexec';
|
|
188
|
-
args = ['sh', '-c', "dpkg -i \"".concat(installerPath, "\"")];
|
|
189
|
-
break;
|
|
190
|
-
case 'win32':
|
|
191
|
-
command = installerPath;
|
|
192
|
-
break;
|
|
193
|
-
default:
|
|
194
|
-
throw new Error('Invalid platform');
|
|
195
|
-
}
|
|
196
|
-
onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate({ step: 'install', percentage: 0 });
|
|
197
|
-
return new Promise(function (resolve, reject) {
|
|
198
|
-
(0, child_process_1.execFile)(command, args, function (error, _, stderr) {
|
|
199
|
-
if (error) {
|
|
200
|
-
return reject(error);
|
|
201
|
-
}
|
|
202
|
-
if (stderr) {
|
|
203
|
-
return reject(stderr);
|
|
204
|
-
}
|
|
205
|
-
onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate({ step: 'install', percentage: 100 });
|
|
206
|
-
return resolve();
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
};
|
|
210
|
-
exports.installJLink = installJLink;
|
|
211
|
-
var convertToSemverVersion = function (version) {
|
|
212
|
-
var _a;
|
|
213
|
-
var _b = (_a = version.match(/V?(\d+\.\d+)(.)?/)) !== null && _a !== void 0 ? _a : [], majorMinor = _b[1], patchLetter = _b[2];
|
|
214
|
-
var patch = patchLetter
|
|
215
|
-
? patchLetter.charCodeAt(0) - 'a'.charCodeAt(0) + 1
|
|
216
|
-
: 0;
|
|
217
|
-
return "".concat(majorMinor, ".").concat(patch);
|
|
218
|
-
};
|
|
219
|
-
var isValidVersion = function (installedVersion, expectedVersion) {
|
|
220
|
-
return semver_1.default.gte(convertToSemverVersion(installedVersion), convertToSemverVersion(expectedVersion));
|
|
221
|
-
};
|
|
222
|
-
var getVersionToInstall = function () {
|
|
223
|
-
var args_1 = [];
|
|
224
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
225
|
-
args_1[_i] = arguments[_i];
|
|
226
|
-
}
|
|
227
|
-
return __awaiter(void 0, __spreadArray([], args_1, true), void 0, function (_a) {
|
|
228
|
-
var onlineRecommendedVersion, _b, versionToBeInstalled, installedVersion, installed, outdated;
|
|
229
|
-
var _c;
|
|
230
|
-
var _d = _a === void 0 ? {} : _a, fallbackVersion = _d.fallbackVersion, _e = _d.checkOnline, checkOnline = _e === void 0 ? true : _e;
|
|
231
|
-
return __generator(this, function (_f) {
|
|
232
|
-
switch (_f.label) {
|
|
233
|
-
case 0:
|
|
234
|
-
if (!checkOnline) return [3 /*break*/, 2];
|
|
235
|
-
return [4 /*yield*/, (0, common_1.fetchIndex)().catch(function () { return undefined; })];
|
|
236
|
-
case 1:
|
|
237
|
-
_b = (_c = (_f.sent())) === null || _c === void 0 ? void 0 : _c.version;
|
|
238
|
-
return [3 /*break*/, 3];
|
|
239
|
-
case 2:
|
|
240
|
-
_b = undefined;
|
|
241
|
-
_f.label = 3;
|
|
242
|
-
case 3:
|
|
243
|
-
onlineRecommendedVersion = _b;
|
|
244
|
-
versionToBeInstalled = onlineRecommendedVersion !== null && onlineRecommendedVersion !== void 0 ? onlineRecommendedVersion : fallbackVersion;
|
|
245
|
-
return [4 /*yield*/, getInstalledJLinkVersion().catch(function () { return undefined; })];
|
|
246
|
-
case 4:
|
|
247
|
-
installedVersion = _f.sent();
|
|
248
|
-
installed = !!installedVersion;
|
|
249
|
-
outdated = !installed ||
|
|
250
|
-
!versionToBeInstalled ||
|
|
251
|
-
!isValidVersion(installedVersion, versionToBeInstalled);
|
|
252
|
-
return [2 /*return*/, {
|
|
253
|
-
outdated: outdated,
|
|
254
|
-
installedVersion: installedVersion,
|
|
255
|
-
installed: installed,
|
|
256
|
-
versionToBeInstalled: versionToBeInstalled,
|
|
257
|
-
}];
|
|
258
|
-
}
|
|
259
|
-
});
|
|
260
|
-
});
|
|
261
|
-
};
|
|
262
|
-
exports.getVersionToInstall = getVersionToInstall;
|
|
8
|
+
exports.downloadAndInstallJLink = exports.downloadAndSaveJLink = void 0;
|
|
9
|
+
var fetchIndex_1 = require("./operations/fetchIndex");
|
|
10
|
+
var downloadJLink_1 = require("./operations/downloadJLink");
|
|
11
|
+
var installJLink_1 = require("./operations/installJLink");
|
|
263
12
|
var downloadAndSaveJLink = function (destinationDir, destinationFileName, onUpdate) {
|
|
264
|
-
return (0,
|
|
265
|
-
return downloadJLink(v, onUpdate, destinationDir, destinationFileName);
|
|
13
|
+
return (0, fetchIndex_1.fetchIndex)().then(function (v) {
|
|
14
|
+
return (0, downloadJLink_1.downloadJLink)(v, onUpdate, destinationDir, destinationFileName);
|
|
266
15
|
});
|
|
267
16
|
};
|
|
268
17
|
exports.downloadAndSaveJLink = downloadAndSaveJLink;
|
|
269
18
|
var downloadAndInstallJLink = function (onUpdate) {
|
|
270
|
-
return (0,
|
|
271
|
-
.then(function (v) { return downloadJLink(v, onUpdate); })
|
|
272
|
-
.then(function (v) { return (0,
|
|
19
|
+
return (0, fetchIndex_1.fetchIndex)()
|
|
20
|
+
.then(function (v) { return (0, downloadJLink_1.downloadJLink)(v, onUpdate); })
|
|
21
|
+
.then(function (v) { return (0, installJLink_1.installJLink)(v, onUpdate); });
|
|
273
22
|
};
|
|
274
23
|
exports.downloadAndInstallJLink = downloadAndInstallJLink;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Nordic Semiconductor ASA
|
|
4
|
+
*
|
|
5
|
+
* SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
|
|
6
|
+
*/
|
|
7
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
9
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
12
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
13
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
17
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
18
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
19
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
20
|
+
function step(op) {
|
|
21
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
22
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
23
|
+
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;
|
|
24
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
25
|
+
switch (op[0]) {
|
|
26
|
+
case 0: case 1: t = op; break;
|
|
27
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
28
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
29
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
30
|
+
default:
|
|
31
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
32
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
33
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
34
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
35
|
+
if (t[2]) _.ops.pop();
|
|
36
|
+
_.trys.pop(); continue;
|
|
37
|
+
}
|
|
38
|
+
op = body.call(thisArg, _);
|
|
39
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
40
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
44
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
45
|
+
if (ar || !(i in from)) {
|
|
46
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
47
|
+
ar[i] = from[i];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
51
|
+
};
|
|
52
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
53
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
54
|
+
};
|
|
55
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
56
|
+
exports.downloadJLink = void 0;
|
|
57
|
+
var os_1 = __importDefault(require("os"));
|
|
58
|
+
var path_1 = __importDefault(require("path"));
|
|
59
|
+
var fs_1 = require("../shared/fs");
|
|
60
|
+
var net_1 = require("../shared/net");
|
|
61
|
+
var getDownloadJLinkUrl = function (jlinkUrls) {
|
|
62
|
+
var _a;
|
|
63
|
+
var platform = os_1.default.platform();
|
|
64
|
+
var arch = os_1.default.arch();
|
|
65
|
+
// @ts-expect-error It is quite literally checked right before
|
|
66
|
+
if (!(platform in jlinkUrls) || !(arch in jlinkUrls[platform])) {
|
|
67
|
+
throw new Error("JLink not available for ".concat(platform, "/").concat(arch));
|
|
68
|
+
}
|
|
69
|
+
// @ts-expect-error We know it exists but it is also handled if undefined
|
|
70
|
+
var url = (_a = jlinkUrls[platform]) === null || _a === void 0 ? void 0 : _a[arch];
|
|
71
|
+
if (!url) {
|
|
72
|
+
throw new Error("JLink not available for ".concat(platform, "/").concat(arch));
|
|
73
|
+
}
|
|
74
|
+
return url;
|
|
75
|
+
};
|
|
76
|
+
var downloadJLink = function (_a, onUpdate_1) {
|
|
77
|
+
var args_1 = [];
|
|
78
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
79
|
+
args_1[_i - 2] = arguments[_i];
|
|
80
|
+
}
|
|
81
|
+
return __awaiter(void 0, __spreadArray([_a, onUpdate_1], args_1, true), void 0, function (_b, onUpdate, destinationDir, destinationFileName) {
|
|
82
|
+
var url, jlink;
|
|
83
|
+
var jlinkUrls = _b.jlinkUrls;
|
|
84
|
+
if (destinationDir === void 0) { destinationDir = os_1.default.tmpdir(); }
|
|
85
|
+
return __generator(this, function (_c) {
|
|
86
|
+
switch (_c.label) {
|
|
87
|
+
case 0:
|
|
88
|
+
url = getDownloadJLinkUrl(jlinkUrls);
|
|
89
|
+
return [4 /*yield*/, (0, net_1.download)(url, onUpdate)];
|
|
90
|
+
case 1:
|
|
91
|
+
jlink = _c.sent();
|
|
92
|
+
return [2 /*return*/, (0, fs_1.saveToFile)(path_1.default.join(destinationDir, destinationFileName || path_1.default.basename(url)), jlink)];
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
exports.downloadJLink = downloadJLink;
|
|
@@ -6,5 +6,5 @@ export interface JLinkIndex {
|
|
|
6
6
|
version: string;
|
|
7
7
|
jlinkUrls: JLinkVariant;
|
|
8
8
|
}
|
|
9
|
+
export declare const indexUrl = "https://files.nordicsemi.com/ui/api/v1/download?isNativeBrowsing=true&repoKey=swtools&path=external/ncd/jlink/index.json";
|
|
9
10
|
export declare const fetchIndex: () => Promise<JLinkIndex>;
|
|
10
|
-
export declare const saveToFile: (destinationFile: string, data: string | NodeJS.ArrayBufferView) => Promise<string>;
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Nordic Semiconductor ASA
|
|
4
|
+
*
|
|
5
|
+
* SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
|
|
6
|
+
*/
|
|
2
7
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
8
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
9
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -35,39 +40,17 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
40
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
41
|
}
|
|
37
42
|
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
43
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.
|
|
43
|
-
var
|
|
44
|
-
var path_1 = __importDefault(require("path"));
|
|
44
|
+
exports.fetchIndex = exports.indexUrl = exports.archs = exports.platforms = void 0;
|
|
45
|
+
var net_1 = require("../shared/net");
|
|
45
46
|
exports.platforms = ['darwin', 'linux', 'win32'];
|
|
46
47
|
exports.archs = ['arm64', 'x64'];
|
|
47
|
-
|
|
48
|
-
var response;
|
|
49
|
-
return __generator(this, function (_a) {
|
|
50
|
-
switch (_a.label) {
|
|
51
|
-
case 0: return [4 /*yield*/, fetch(url, {
|
|
52
|
-
headers: {
|
|
53
|
-
Range: 'bytes=0-',
|
|
54
|
-
},
|
|
55
|
-
})];
|
|
56
|
-
case 1:
|
|
57
|
-
response = _a.sent();
|
|
58
|
-
if (!response.ok) {
|
|
59
|
-
throw new Error("Unable to fetch file from ".concat(indexUrl, ". Got status code ").concat(status, "."));
|
|
60
|
-
}
|
|
61
|
-
return [2 /*return*/, response.json()];
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}); };
|
|
65
|
-
var indexUrl = 'https://files.nordicsemi.com/ui/api/v1/download?isNativeBrowsing=true&repoKey=swtools&path=external/ncd/jlink/index.json';
|
|
48
|
+
exports.indexUrl = 'https://files.nordicsemi.com/ui/api/v1/download?isNativeBrowsing=true&repoKey=swtools&path=external/ncd/jlink/index.json';
|
|
66
49
|
var fetchIndex = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
67
50
|
var res;
|
|
68
51
|
return __generator(this, function (_a) {
|
|
69
52
|
switch (_a.label) {
|
|
70
|
-
case 0: return [4 /*yield*/, fetchJSON(indexUrl)];
|
|
53
|
+
case 0: return [4 /*yield*/, (0, net_1.fetchJSON)(exports.indexUrl)];
|
|
71
54
|
case 1:
|
|
72
55
|
res = _a.sent();
|
|
73
56
|
if (res == null ||
|
|
@@ -81,16 +64,3 @@ var fetchIndex = function () { return __awaiter(void 0, void 0, void 0, function
|
|
|
81
64
|
});
|
|
82
65
|
}); };
|
|
83
66
|
exports.fetchIndex = fetchIndex;
|
|
84
|
-
var saveToFile = function (destinationFile, data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
85
|
-
return __generator(this, function (_a) {
|
|
86
|
-
(0, fs_1.mkdirSync)(path_1.default.dirname(destinationFile), { recursive: true });
|
|
87
|
-
try {
|
|
88
|
-
(0, fs_1.writeFileSync)(destinationFile, data);
|
|
89
|
-
}
|
|
90
|
-
catch (e) {
|
|
91
|
-
throw new Error("Unable to write file to ".concat(destinationFile, ". Error: ").concat(e));
|
|
92
|
-
}
|
|
93
|
-
return [2 /*return*/, destinationFile];
|
|
94
|
-
});
|
|
95
|
-
}); };
|
|
96
|
-
exports.saveToFile = saveToFile;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
type JLinkNotInstalled = {
|
|
2
|
+
status: 'not installed';
|
|
3
|
+
versionToBeInstalled: string;
|
|
4
|
+
};
|
|
5
|
+
type JLinkNotInstalledNonAvailable = {
|
|
6
|
+
status: 'not installed but none available';
|
|
7
|
+
};
|
|
8
|
+
type JLinkUpToDate = {
|
|
9
|
+
status: 'up to date';
|
|
10
|
+
installedVersion: string;
|
|
11
|
+
versionToBeInstalled?: string;
|
|
12
|
+
};
|
|
13
|
+
type JLinkShouldBeUpdated = {
|
|
14
|
+
status: 'should be updated';
|
|
15
|
+
installedVersion?: string;
|
|
16
|
+
versionToBeInstalled: string;
|
|
17
|
+
};
|
|
18
|
+
export type JLinkState = JLinkNotInstalled | JLinkNotInstalledNonAvailable | JLinkUpToDate | JLinkShouldBeUpdated;
|
|
19
|
+
export declare const getJLinkState: ({ fallbackVersion, checkOnline, }?: {
|
|
20
|
+
fallbackVersion?: string;
|
|
21
|
+
checkOnline?: boolean;
|
|
22
|
+
}) => Promise<JLinkState>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Nordic Semiconductor ASA
|
|
4
|
+
*
|
|
5
|
+
* SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
|
|
6
|
+
*/
|
|
7
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
9
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
12
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
13
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
17
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
18
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
19
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
20
|
+
function step(op) {
|
|
21
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
22
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
23
|
+
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;
|
|
24
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
25
|
+
switch (op[0]) {
|
|
26
|
+
case 0: case 1: t = op; break;
|
|
27
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
28
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
29
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
30
|
+
default:
|
|
31
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
32
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
33
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
34
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
35
|
+
if (t[2]) _.ops.pop();
|
|
36
|
+
_.trys.pop(); continue;
|
|
37
|
+
}
|
|
38
|
+
op = body.call(thisArg, _);
|
|
39
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
40
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
44
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
45
|
+
if (ar || !(i in from)) {
|
|
46
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
47
|
+
ar[i] = from[i];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
51
|
+
};
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
exports.getJLinkState = void 0;
|
|
54
|
+
var fetchIndex_1 = require("./fetchIndex");
|
|
55
|
+
var jLinkVersion_1 = require("../shared/jLinkVersion");
|
|
56
|
+
var getJLinkState = function () {
|
|
57
|
+
var args_1 = [];
|
|
58
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
59
|
+
args_1[_i] = arguments[_i];
|
|
60
|
+
}
|
|
61
|
+
return __awaiter(void 0, __spreadArray([], args_1, true), void 0, function (_a) {
|
|
62
|
+
var onlineRecommendedVersion, _b, versionToBeInstalled, installedVersion;
|
|
63
|
+
var _c;
|
|
64
|
+
var _d = _a === void 0 ? {} : _a, fallbackVersion = _d.fallbackVersion, _e = _d.checkOnline, checkOnline = _e === void 0 ? true : _e;
|
|
65
|
+
return __generator(this, function (_f) {
|
|
66
|
+
switch (_f.label) {
|
|
67
|
+
case 0:
|
|
68
|
+
if (!checkOnline) return [3 /*break*/, 2];
|
|
69
|
+
return [4 /*yield*/, (0, fetchIndex_1.fetchIndex)().catch(function () { return undefined; })];
|
|
70
|
+
case 1:
|
|
71
|
+
_b = (_c = (_f.sent())) === null || _c === void 0 ? void 0 : _c.version;
|
|
72
|
+
return [3 /*break*/, 3];
|
|
73
|
+
case 2:
|
|
74
|
+
_b = undefined;
|
|
75
|
+
_f.label = 3;
|
|
76
|
+
case 3:
|
|
77
|
+
onlineRecommendedVersion = _b;
|
|
78
|
+
versionToBeInstalled = onlineRecommendedVersion !== null && onlineRecommendedVersion !== void 0 ? onlineRecommendedVersion : fallbackVersion;
|
|
79
|
+
return [4 /*yield*/, (0, jLinkVersion_1.getInstalledJLinkVersion)().catch(function () { return undefined; })];
|
|
80
|
+
case 4:
|
|
81
|
+
installedVersion = _f.sent();
|
|
82
|
+
if (installedVersion == null) {
|
|
83
|
+
if (versionToBeInstalled == null) {
|
|
84
|
+
return [2 /*return*/, { status: 'not installed but none available' }];
|
|
85
|
+
}
|
|
86
|
+
return [2 /*return*/, { status: 'not installed', versionToBeInstalled: versionToBeInstalled }];
|
|
87
|
+
}
|
|
88
|
+
/* If `versionToBeInstalled` is undefined we do not really know but at
|
|
89
|
+
least there is some J-Link installed and we do not know that it is
|
|
90
|
+
outdated. So, we return 'up to date', but this may be changed to a
|
|
91
|
+
fifth state "installed, unknown if up-to-date" if we see the need for
|
|
92
|
+
this in the future. */
|
|
93
|
+
if (versionToBeInstalled == null ||
|
|
94
|
+
(0, jLinkVersion_1.isValidVersion)(installedVersion, versionToBeInstalled)) {
|
|
95
|
+
return [2 /*return*/, { status: 'up to date', installedVersion: installedVersion, versionToBeInstalled: versionToBeInstalled }];
|
|
96
|
+
}
|
|
97
|
+
return [2 /*return*/, {
|
|
98
|
+
status: 'should be updated',
|
|
99
|
+
installedVersion: installedVersion,
|
|
100
|
+
versionToBeInstalled: versionToBeInstalled,
|
|
101
|
+
}];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
exports.getJLinkState = getJLinkState;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Nordic Semiconductor ASA
|
|
4
|
+
*
|
|
5
|
+
* SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
|
|
6
|
+
*/
|
|
7
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.installJLink = void 0;
|
|
12
|
+
var child_process_1 = require("child_process");
|
|
13
|
+
var os_1 = __importDefault(require("os"));
|
|
14
|
+
var installJLink = function (installerPath, onUpdate) {
|
|
15
|
+
var command;
|
|
16
|
+
var args;
|
|
17
|
+
switch (os_1.default.platform()) {
|
|
18
|
+
case 'darwin':
|
|
19
|
+
command = 'open';
|
|
20
|
+
args = ['-W', installerPath];
|
|
21
|
+
break;
|
|
22
|
+
case 'linux':
|
|
23
|
+
command = 'pkexec';
|
|
24
|
+
args = ['sh', '-c', "dpkg -i \"".concat(installerPath, "\"")];
|
|
25
|
+
break;
|
|
26
|
+
case 'win32':
|
|
27
|
+
command = installerPath;
|
|
28
|
+
args = ['-InstUSBDriver=1'];
|
|
29
|
+
break;
|
|
30
|
+
default:
|
|
31
|
+
throw new Error('Invalid platform');
|
|
32
|
+
}
|
|
33
|
+
onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate({ step: 'install', percentage: 0 });
|
|
34
|
+
return new Promise(function (resolve, reject) {
|
|
35
|
+
(0, child_process_1.execFile)(command, args, function (error, _, stderr) {
|
|
36
|
+
if (error) {
|
|
37
|
+
return reject(error);
|
|
38
|
+
}
|
|
39
|
+
if (stderr) {
|
|
40
|
+
return reject(stderr);
|
|
41
|
+
}
|
|
42
|
+
onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate({ step: 'install', percentage: 100 });
|
|
43
|
+
return resolve();
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
exports.installJLink = installJLink;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Nordic Semiconductor ASA
|
|
4
|
+
*
|
|
5
|
+
* SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
|
|
6
|
+
*/
|
|
7
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.createTemporaryScriptFile = exports.saveToFile = void 0;
|
|
12
|
+
var fs_1 = require("fs");
|
|
13
|
+
var os_1 = require("os");
|
|
14
|
+
var path_1 = __importDefault(require("path"));
|
|
15
|
+
var saveToFile = function (destinationFile, data) {
|
|
16
|
+
try {
|
|
17
|
+
(0, fs_1.mkdirSync)(path_1.default.dirname(destinationFile), { recursive: true });
|
|
18
|
+
(0, fs_1.writeFileSync)(destinationFile, data);
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
throw new Error("Unable to write file to ".concat(destinationFile, ". Error: ").concat(e));
|
|
22
|
+
}
|
|
23
|
+
return destinationFile;
|
|
24
|
+
};
|
|
25
|
+
exports.saveToFile = saveToFile;
|
|
26
|
+
var createTemporaryScriptFile = function (content) {
|
|
27
|
+
var _a;
|
|
28
|
+
var tmpDir = (0, fs_1.mkdtempSync)(path_1.default.join((0, os_1.tmpdir)(), 'jlink-'));
|
|
29
|
+
var filePath = path_1.default.join(tmpDir, 'script');
|
|
30
|
+
(0, fs_1.writeFileSync)(filePath, content);
|
|
31
|
+
return _a = {
|
|
32
|
+
filePath: filePath
|
|
33
|
+
},
|
|
34
|
+
_a[Symbol.dispose] = function () {
|
|
35
|
+
(0, fs_1.rmSync)(tmpDir, { recursive: true, force: true });
|
|
36
|
+
},
|
|
37
|
+
_a;
|
|
38
|
+
};
|
|
39
|
+
exports.createTemporaryScriptFile = createTemporaryScriptFile;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Nordic Semiconductor ASA
|
|
4
|
+
*
|
|
5
|
+
* SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
|
|
6
|
+
*/
|
|
7
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
9
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
12
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
13
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
17
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
18
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
19
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
20
|
+
function step(op) {
|
|
21
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
22
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
23
|
+
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;
|
|
24
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
25
|
+
switch (op[0]) {
|
|
26
|
+
case 0: case 1: t = op; break;
|
|
27
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
28
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
29
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
30
|
+
default:
|
|
31
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
32
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
33
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
34
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
35
|
+
if (t[2]) _.ops.pop();
|
|
36
|
+
_.trys.pop(); continue;
|
|
37
|
+
}
|
|
38
|
+
op = body.call(thisArg, _);
|
|
39
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
40
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
44
|
+
if (value !== null && value !== void 0) {
|
|
45
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
46
|
+
var dispose, inner;
|
|
47
|
+
if (async) {
|
|
48
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
49
|
+
dispose = value[Symbol.asyncDispose];
|
|
50
|
+
}
|
|
51
|
+
if (dispose === void 0) {
|
|
52
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
53
|
+
dispose = value[Symbol.dispose];
|
|
54
|
+
if (async) inner = dispose;
|
|
55
|
+
}
|
|
56
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
57
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
58
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
59
|
+
}
|
|
60
|
+
else if (async) {
|
|
61
|
+
env.stack.push({ async: true });
|
|
62
|
+
}
|
|
63
|
+
return value;
|
|
64
|
+
};
|
|
65
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
66
|
+
return function (env) {
|
|
67
|
+
function fail(e) {
|
|
68
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
69
|
+
env.hasError = true;
|
|
70
|
+
}
|
|
71
|
+
var r, s = 0;
|
|
72
|
+
function next() {
|
|
73
|
+
while (r = env.stack.pop()) {
|
|
74
|
+
try {
|
|
75
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
76
|
+
if (r.dispose) {
|
|
77
|
+
var result = r.dispose.call(r.value);
|
|
78
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
79
|
+
}
|
|
80
|
+
else s |= 1;
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
fail(e);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
87
|
+
if (env.hasError) throw env.error;
|
|
88
|
+
}
|
|
89
|
+
return next();
|
|
90
|
+
};
|
|
91
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
92
|
+
var e = new Error(message);
|
|
93
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
94
|
+
});
|
|
95
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
96
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
97
|
+
};
|
|
98
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
99
|
+
exports.getInstalledJLinkVersion = exports.isValidVersion = void 0;
|
|
100
|
+
var child_process_1 = require("child_process");
|
|
101
|
+
var fs_1 = require("fs");
|
|
102
|
+
var os_1 = __importDefault(require("os"));
|
|
103
|
+
var path_1 = __importDefault(require("path"));
|
|
104
|
+
var semver_1 = __importDefault(require("semver"));
|
|
105
|
+
var util_1 = require("util");
|
|
106
|
+
var fs_2 = require("./fs");
|
|
107
|
+
var reg = function () {
|
|
108
|
+
var _a;
|
|
109
|
+
var defaultRegLocation = path_1.default.resolve((_a = process.env.SystemRoot) !== null && _a !== void 0 ? _a : 'C:\\Windows', 'System32', 'reg.exe');
|
|
110
|
+
return (0, fs_1.existsSync)(defaultRegLocation) ? defaultRegLocation : 'reg.exe';
|
|
111
|
+
};
|
|
112
|
+
var winRegQuery = function (key) {
|
|
113
|
+
if (process.platform !== 'win32') {
|
|
114
|
+
throw new Error('Unsupported platform');
|
|
115
|
+
}
|
|
116
|
+
return (0, child_process_1.execSync)("".concat(reg(), " query ").concat(key)).toString().trim();
|
|
117
|
+
};
|
|
118
|
+
var getJLinkExePath = function () {
|
|
119
|
+
var _a;
|
|
120
|
+
switch (os_1.default.platform()) {
|
|
121
|
+
case 'win32':
|
|
122
|
+
var cwd = winRegQuery('HKEY_CURRENT_USER\\Software\\SEGGER\\J-Link /v InstallPath');
|
|
123
|
+
if (!cwd) {
|
|
124
|
+
cwd = winRegQuery('HKEY_LOCAL_MACHINE\\Software\\SEGGER\\J-Link /v InstallPath');
|
|
125
|
+
}
|
|
126
|
+
cwd = ((_a = /InstallPath\s+\w+\s+(.*)/.exec(cwd)) !== null && _a !== void 0 ? _a : [])[1];
|
|
127
|
+
if (!cwd) {
|
|
128
|
+
throw new Error('JLink not installed');
|
|
129
|
+
}
|
|
130
|
+
return "\"".concat(path_1.default.join(cwd, 'JLink.exe'), "\"");
|
|
131
|
+
case 'linux':
|
|
132
|
+
case 'darwin':
|
|
133
|
+
return 'JLinkExe';
|
|
134
|
+
default:
|
|
135
|
+
throw new Error('Invalid platform');
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
var convertToSemverVersion = function (version) {
|
|
139
|
+
var _a;
|
|
140
|
+
var _b = (_a = version.match(/V?(\d+\.\d+)(.)?/)) !== null && _a !== void 0 ? _a : [], majorMinor = _b[1], patchLetter = _b[2];
|
|
141
|
+
var patch = patchLetter
|
|
142
|
+
? patchLetter.charCodeAt(0) - 'a'.charCodeAt(0) + 1
|
|
143
|
+
: 0;
|
|
144
|
+
return "".concat(majorMinor, ".").concat(patch);
|
|
145
|
+
};
|
|
146
|
+
var isValidVersion = function (installedVersion, expectedVersion) {
|
|
147
|
+
return semver_1.default.gte(convertToSemverVersion(installedVersion), convertToSemverVersion(expectedVersion));
|
|
148
|
+
};
|
|
149
|
+
exports.isValidVersion = isValidVersion;
|
|
150
|
+
var getInstalledJLinkVersion = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
151
|
+
var env_1, scriptFile, output, versionRegExp, match, e_1;
|
|
152
|
+
var _a;
|
|
153
|
+
return __generator(this, function (_b) {
|
|
154
|
+
switch (_b.label) {
|
|
155
|
+
case 0:
|
|
156
|
+
env_1 = { stack: [], error: void 0, hasError: false };
|
|
157
|
+
_b.label = 1;
|
|
158
|
+
case 1:
|
|
159
|
+
_b.trys.push([1, 3, 4, 5]);
|
|
160
|
+
scriptFile = __addDisposableResource(env_1, (0, fs_2.createTemporaryScriptFile)('Exit'), false);
|
|
161
|
+
return [4 /*yield*/, (0, util_1.promisify)(child_process_1.exec)("".concat(getJLinkExePath(), " -CommandFile ").concat(scriptFile.filePath)).catch(function (e) { return e; })];
|
|
162
|
+
case 2:
|
|
163
|
+
output = _b.sent();
|
|
164
|
+
versionRegExp = /^SEGGER J-Link Commander V([0-9a-z.]+) .*$/m;
|
|
165
|
+
match = (_a = output.stdout.match(versionRegExp)) === null || _a === void 0 ? void 0 : _a[1];
|
|
166
|
+
if (!match) {
|
|
167
|
+
throw new Error("Couldn't get jlink version.");
|
|
168
|
+
}
|
|
169
|
+
return [2 /*return*/, "v".concat(match)];
|
|
170
|
+
case 3:
|
|
171
|
+
e_1 = _b.sent();
|
|
172
|
+
env_1.error = e_1;
|
|
173
|
+
env_1.hasError = true;
|
|
174
|
+
return [3 /*break*/, 5];
|
|
175
|
+
case 4:
|
|
176
|
+
__disposeResources(env_1);
|
|
177
|
+
return [7 /*endfinally*/];
|
|
178
|
+
case 5: return [2 /*return*/];
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}); };
|
|
182
|
+
exports.getInstalledJLinkVersion = getInstalledJLinkVersion;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Nordic Semiconductor ASA
|
|
4
|
+
*
|
|
5
|
+
* SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
|
|
6
|
+
*/
|
|
7
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
9
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
12
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
13
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
17
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
18
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
19
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
20
|
+
function step(op) {
|
|
21
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
22
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
23
|
+
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;
|
|
24
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
25
|
+
switch (op[0]) {
|
|
26
|
+
case 0: case 1: t = op; break;
|
|
27
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
28
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
29
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
30
|
+
default:
|
|
31
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
32
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
33
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
34
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
35
|
+
if (t[2]) _.ops.pop();
|
|
36
|
+
_.trys.pop(); continue;
|
|
37
|
+
}
|
|
38
|
+
op = body.call(thisArg, _);
|
|
39
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
40
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
exports.fetchJSON = exports.download = void 0;
|
|
45
|
+
var handleFailedRequest = function (response, url) {
|
|
46
|
+
if (!response.ok) {
|
|
47
|
+
throw new Error("Unable to fetch file from ".concat(url, ". Got status code ").concat(response.status, "."));
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var download = function (url, onUpdate) { return __awaiter(void 0, void 0, void 0, function () {
|
|
51
|
+
var response, hasContentLength, contentLength, reader, chunks, receivedLength, _a, done, value;
|
|
52
|
+
var _b;
|
|
53
|
+
return __generator(this, function (_c) {
|
|
54
|
+
switch (_c.label) {
|
|
55
|
+
case 0: return [4 /*yield*/, fetch(url, {
|
|
56
|
+
headers: {
|
|
57
|
+
Range: 'bytes=0-',
|
|
58
|
+
},
|
|
59
|
+
})];
|
|
60
|
+
case 1:
|
|
61
|
+
response = _c.sent();
|
|
62
|
+
handleFailedRequest(response, url);
|
|
63
|
+
hasContentLength = response.headers.has('content-length');
|
|
64
|
+
contentLength = hasContentLength
|
|
65
|
+
? Number(response.headers.get('content-length'))
|
|
66
|
+
: 1;
|
|
67
|
+
reader = (_b = response.body) === null || _b === void 0 ? void 0 : _b.getReader();
|
|
68
|
+
chunks = [];
|
|
69
|
+
receivedLength = 0;
|
|
70
|
+
_c.label = 2;
|
|
71
|
+
case 2:
|
|
72
|
+
if (!reader) return [3 /*break*/, 4];
|
|
73
|
+
return [4 /*yield*/, reader.read()];
|
|
74
|
+
case 3:
|
|
75
|
+
_a = _c.sent(), done = _a.done, value = _a.value;
|
|
76
|
+
if (done) {
|
|
77
|
+
return [3 /*break*/, 4];
|
|
78
|
+
}
|
|
79
|
+
chunks.push(value);
|
|
80
|
+
receivedLength += value.length;
|
|
81
|
+
onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate({
|
|
82
|
+
step: 'download',
|
|
83
|
+
percentage: hasContentLength
|
|
84
|
+
? Number(((receivedLength / contentLength) * 100).toFixed(2))
|
|
85
|
+
: 0,
|
|
86
|
+
});
|
|
87
|
+
return [3 /*break*/, 2];
|
|
88
|
+
case 4: return [2 /*return*/, Buffer.concat(chunks)];
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}); };
|
|
92
|
+
exports.download = download;
|
|
93
|
+
var fetchJSON = function (url) { return __awaiter(void 0, void 0, void 0, function () {
|
|
94
|
+
var response;
|
|
95
|
+
return __generator(this, function (_a) {
|
|
96
|
+
switch (_a.label) {
|
|
97
|
+
case 0: return [4 /*yield*/, fetch(url, {
|
|
98
|
+
headers: {
|
|
99
|
+
Range: 'bytes=0-',
|
|
100
|
+
},
|
|
101
|
+
})];
|
|
102
|
+
case 1:
|
|
103
|
+
response = _a.sent();
|
|
104
|
+
handleFailedRequest(response, url);
|
|
105
|
+
return [2 /*return*/, response.json()];
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}); };
|
|
109
|
+
exports.fetchJSON = fetchJSON;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nordicsemiconductor/nrf-jlink-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"main": "dist",
|
|
5
5
|
"types": "dist",
|
|
6
6
|
"files": [
|
|
@@ -23,6 +23,6 @@
|
|
|
23
23
|
"url": "git+https://github.com/NordicSemiconductor/nrf-jlink-js.git"
|
|
24
24
|
},
|
|
25
25
|
"author": "Nordic Semiconductor ASA",
|
|
26
|
-
"license": "
|
|
26
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
27
27
|
"description": "Shared library to handle J-Link versions"
|
|
28
28
|
}
|