@nordicsemiconductor/nrf-jlink-js 0.0.0-alpha1
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 +35 -0
- package/README.md +19 -0
- package/dist/common.d.ts +15 -0
- package/dist/common.js +87 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +6 -0
- package/dist/jlink.d.ts +13 -0
- package/dist/jlink.js +206 -0
- package/package.json +29 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Copyright (c) 2025 Nordic Semiconductor ASA
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
SPDX-License-Identifier: Nordic-4-Clause
|
|
5
|
+
|
|
6
|
+
Use in source and binary forms, redistribution in binary form only, with
|
|
7
|
+
or without modification, are permitted provided that the following conditions
|
|
8
|
+
are met:
|
|
9
|
+
|
|
10
|
+
1. Redistributions in binary form, except as embedded into a Nordic
|
|
11
|
+
Semiconductor ASA integrated circuit in a product or a software update for
|
|
12
|
+
such product, must reproduce the above copyright notice, this list of
|
|
13
|
+
conditions and the following disclaimer in the documentation and/or other
|
|
14
|
+
materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
2. Neither the name of Nordic Semiconductor ASA nor the names of its
|
|
17
|
+
contributors may be used to endorse or promote products derived from this
|
|
18
|
+
software without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
3. This software, with or without modification, must only be used with a Nordic
|
|
21
|
+
Semiconductor ASA integrated circuit.
|
|
22
|
+
|
|
23
|
+
4. Any software provided in binary form under this license must not be reverse
|
|
24
|
+
engineered, decompiled, modified and/or disassembled.
|
|
25
|
+
|
|
26
|
+
THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR
|
|
27
|
+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
28
|
+
MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
29
|
+
DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE
|
|
30
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
31
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
32
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
33
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
|
34
|
+
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# nrf-jlink-js
|
|
2
|
+
|
|
3
|
+
`nrf-jlink-js` is a Node.js module to handle jlink installer and bundle by Nordic Semiconductor ASA.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install nrf-jlink-js
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
const jlink = new Jlink();
|
|
15
|
+
const remoteJlinkList = await jlink.listRemote();
|
|
16
|
+
const localJlinkList = await jlink.listLocalInstalled();
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
For more usage, see [`examples`](./examples)
|
package/dist/common.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface ArchUrl {
|
|
2
|
+
arm64: string;
|
|
3
|
+
x64: string;
|
|
4
|
+
}
|
|
5
|
+
export interface JLinkVariant {
|
|
6
|
+
linux: ArchUrl;
|
|
7
|
+
darwin: ArchUrl;
|
|
8
|
+
win32: ArchUrl;
|
|
9
|
+
}
|
|
10
|
+
export interface JLinkIndex {
|
|
11
|
+
version: string;
|
|
12
|
+
jlinkUrl: JLinkVariant;
|
|
13
|
+
}
|
|
14
|
+
export declare const fetchIndex: () => Promise<JLinkIndex>;
|
|
15
|
+
export declare const saveToFile: (stream: NodeJS.ReadableStream, destinationFile: string) => Promise<string>;
|
package/dist/common.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.saveToFile = exports.fetchIndex = void 0;
|
|
43
|
+
var axios_1 = __importDefault(require("axios"));
|
|
44
|
+
var fs_1 = __importDefault(require("fs"));
|
|
45
|
+
var fetchJSON = function (url) { return __awaiter(void 0, void 0, void 0, function () {
|
|
46
|
+
var _a, status, data;
|
|
47
|
+
return __generator(this, function (_b) {
|
|
48
|
+
switch (_b.label) {
|
|
49
|
+
case 0: return [4 /*yield*/, axios_1.default.get(url, { responseType: 'json' })];
|
|
50
|
+
case 1:
|
|
51
|
+
_a = _b.sent(), status = _a.status, data = _a.data;
|
|
52
|
+
if (status !== 200) {
|
|
53
|
+
throw new Error("Unable to fetch file from ".concat(indexUrl, ". Got status code ").concat(status, "."));
|
|
54
|
+
}
|
|
55
|
+
return [2 /*return*/, data];
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}); };
|
|
59
|
+
var indexUrl = "https://files.nordicsemi.com/artifactory/swtools/external/jlink/index.json";
|
|
60
|
+
var fetchIndex = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
61
|
+
var res;
|
|
62
|
+
return __generator(this, function (_a) {
|
|
63
|
+
switch (_a.label) {
|
|
64
|
+
case 0: return [4 /*yield*/, fetchJSON(indexUrl)];
|
|
65
|
+
case 1:
|
|
66
|
+
res = _a.sent();
|
|
67
|
+
if (res == null || typeof res !== 'object' || res.version !== undefined || res.jlinkUrl !== undefined) {
|
|
68
|
+
throw new Error('`source.json` does not have the expected content.');
|
|
69
|
+
}
|
|
70
|
+
return [2 /*return*/, res];
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}); };
|
|
74
|
+
exports.fetchIndex = fetchIndex;
|
|
75
|
+
var saveToFile = function (stream, destinationFile) {
|
|
76
|
+
return new Promise(function (resolve, reject) {
|
|
77
|
+
var file = fs_1.default.createWriteStream(destinationFile);
|
|
78
|
+
stream.pipe(file);
|
|
79
|
+
stream.on("error", reject);
|
|
80
|
+
stream.on("end", function () {
|
|
81
|
+
file.end(function () {
|
|
82
|
+
return resolve(destinationFile);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
exports.saveToFile = saveToFile;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getVersionToInstall = exports.downloadAndInstallJLink = void 0;
|
|
4
|
+
var jlink_1 = require("./jlink");
|
|
5
|
+
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; } });
|
package/dist/jlink.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
interface Update {
|
|
2
|
+
step: "install" | "download";
|
|
3
|
+
percentage: number;
|
|
4
|
+
}
|
|
5
|
+
interface JLinkState {
|
|
6
|
+
outdated: boolean;
|
|
7
|
+
installed: boolean;
|
|
8
|
+
versionToBeInstalled?: string;
|
|
9
|
+
installedVersion?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const getVersionToInstall: (fallbackVersion?: string) => Promise<JLinkState>;
|
|
12
|
+
export declare const downloadAndInstallJLink: (onUpdate?: (update: Update) => void) => Promise<void>;
|
|
13
|
+
export {};
|
package/dist/jlink.js
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.downloadAndInstallJLink = exports.getVersionToInstall = void 0;
|
|
43
|
+
var child_process_1 = require("child_process");
|
|
44
|
+
var promises_1 = require("fs/promises");
|
|
45
|
+
var os_1 = __importDefault(require("os"));
|
|
46
|
+
var path_1 = __importDefault(require("path"));
|
|
47
|
+
var semver_1 = __importDefault(require("semver"));
|
|
48
|
+
var axios_1 = __importDefault(require("axios"));
|
|
49
|
+
var common_1 = require("./common");
|
|
50
|
+
var getJLinkExePath = function () {
|
|
51
|
+
switch (os_1.default.platform()) {
|
|
52
|
+
case "win32":
|
|
53
|
+
var path_2 = (0, child_process_1.execSync)("reg query HKEY_CURRENT_USER\\Software\\SEGGER\\J-Link /v InstallPath").toString();
|
|
54
|
+
var pathAlternative = (0, child_process_1.execSync)("reg query HKEY_LOCAL_MACHINE\\Software\\SEGGER\\J-Link /v InstallPath").toString();
|
|
55
|
+
if (!path_2 && !pathAlternative) {
|
|
56
|
+
throw new Error('JLink not installed');
|
|
57
|
+
}
|
|
58
|
+
else if ((path_2 && typeof path_2 !== 'string') || (pathAlternative && typeof pathAlternative !== 'string')) {
|
|
59
|
+
throw new Error('Unable to read JLink install path');
|
|
60
|
+
}
|
|
61
|
+
return (path_2 || pathAlternative);
|
|
62
|
+
case "linux":
|
|
63
|
+
case "darwin":
|
|
64
|
+
return 'JLinkExe';
|
|
65
|
+
default:
|
|
66
|
+
throw new Error("Invalid platform");
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
var getInstalledJLinkVersion = function () {
|
|
70
|
+
return new Promise(function (resolve, reject) {
|
|
71
|
+
var jlinkExeCmd = (0, child_process_1.spawn)(getJLinkExePath(), ["-NoGUI", "1"], { shell: true });
|
|
72
|
+
jlinkExeCmd.stdout.on("data", function (data) {
|
|
73
|
+
var output = data.toString();
|
|
74
|
+
var versionRegExp = /DLL version (V\d+\.\d+\w*),.*/;
|
|
75
|
+
var versionMatch = output.match(versionRegExp);
|
|
76
|
+
if (versionMatch) {
|
|
77
|
+
jlinkExeCmd.kill(9);
|
|
78
|
+
// resolve(versionMatch[1])
|
|
79
|
+
}
|
|
80
|
+
else if (data.toString().includes("Connecting to")) {
|
|
81
|
+
jlinkExeCmd.kill(9);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
jlinkExeCmd.stderr.on("data", function () {
|
|
86
|
+
reject('Failed to read Jlink Version');
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
var downloadJLink = function (_a, onUpdate_1) { return __awaiter(void 0, [_a, onUpdate_1], void 0, function (_b, onUpdate) {
|
|
91
|
+
var url, _c, status, stream, destinationFile;
|
|
92
|
+
var jlinkUrls = _b.jlinkUrl;
|
|
93
|
+
return __generator(this, function (_d) {
|
|
94
|
+
switch (_d.label) {
|
|
95
|
+
case 0:
|
|
96
|
+
url = "";
|
|
97
|
+
return [4 /*yield*/, axios_1.default.get(url, {
|
|
98
|
+
responseType: "stream",
|
|
99
|
+
onDownloadProgress: function (_a) {
|
|
100
|
+
var loaded = _a.loaded, total = _a.total;
|
|
101
|
+
return onUpdate && loaded && total &&
|
|
102
|
+
onUpdate({ step: "download", percentage: Number(((loaded / total) * 100).toFixed(2)) });
|
|
103
|
+
},
|
|
104
|
+
})];
|
|
105
|
+
case 1:
|
|
106
|
+
_c = _d.sent(), status = _c.status, stream = _c.data;
|
|
107
|
+
if (status !== 200) {
|
|
108
|
+
throw new Error("Unable to download ".concat(jlinkUrls, ". Got status code ").concat(status, "."));
|
|
109
|
+
}
|
|
110
|
+
destinationFile = path_1.default.join(os_1.default.tmpdir(), path_1.default.basename(url));
|
|
111
|
+
return [4 /*yield*/, (0, promises_1.mkdir)(path_1.default.dirname(destinationFile), { recursive: true })];
|
|
112
|
+
case 2:
|
|
113
|
+
_d.sent();
|
|
114
|
+
return [4 /*yield*/, (0, common_1.saveToFile)(stream, destinationFile)];
|
|
115
|
+
case 3: return [2 /*return*/, _d.sent()];
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}); };
|
|
119
|
+
var installJLink = function (installerPath, onUpdate) {
|
|
120
|
+
;
|
|
121
|
+
var command;
|
|
122
|
+
var args;
|
|
123
|
+
switch (os_1.default.platform()) {
|
|
124
|
+
case 'darwin':
|
|
125
|
+
command = 'open';
|
|
126
|
+
args = ['-W', installerPath];
|
|
127
|
+
break;
|
|
128
|
+
case 'linux':
|
|
129
|
+
command = 'pkexec';
|
|
130
|
+
args = ['sh', '-c', "dpkg -i \"".concat(installerPath, "\"")];
|
|
131
|
+
break;
|
|
132
|
+
case 'win32':
|
|
133
|
+
command = "\"".concat(installerPath, "\"");
|
|
134
|
+
break;
|
|
135
|
+
default:
|
|
136
|
+
throw new Error("Invalid platform");
|
|
137
|
+
}
|
|
138
|
+
onUpdate && onUpdate({ step: "install", percentage: 0 });
|
|
139
|
+
return new Promise(function (resolve, reject) {
|
|
140
|
+
(0, child_process_1.execFile)(command, args, function (error, stdout, stderr) {
|
|
141
|
+
if (error) {
|
|
142
|
+
reject(error);
|
|
143
|
+
}
|
|
144
|
+
if (stderr) {
|
|
145
|
+
reject(stderr);
|
|
146
|
+
}
|
|
147
|
+
if (stdout && stdout.includes("successful")) {
|
|
148
|
+
onUpdate && onUpdate({ step: "install", percentage: 100 });
|
|
149
|
+
return resolve();
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
var convertToSemverVersion = function (version) {
|
|
155
|
+
var _a;
|
|
156
|
+
var _b = (_a = version.match(/V?(\d+\.\d+)(.)?/)) !== null && _a !== void 0 ? _a : [], majorMinor = _b[1], patchLetter = _b[2];
|
|
157
|
+
var patch = patchLetter
|
|
158
|
+
? patchLetter.charCodeAt(0) - 'a'.charCodeAt(0) + 1
|
|
159
|
+
: 0;
|
|
160
|
+
return "".concat(majorMinor, ".").concat(patch);
|
|
161
|
+
};
|
|
162
|
+
var isValidVersion = function (installedVersion, expectedVersion) {
|
|
163
|
+
return semver_1.default.gte(convertToSemverVersion(installedVersion), convertToSemverVersion(expectedVersion));
|
|
164
|
+
};
|
|
165
|
+
var getVersionToInstall = function (fallbackVersion) { return __awaiter(void 0, void 0, void 0, function () {
|
|
166
|
+
var state, _a, e_1, _b;
|
|
167
|
+
return __generator(this, function (_c) {
|
|
168
|
+
switch (_c.label) {
|
|
169
|
+
case 0:
|
|
170
|
+
state = {
|
|
171
|
+
outdated: true,
|
|
172
|
+
installed: false,
|
|
173
|
+
versionToBeInstalled: fallbackVersion,
|
|
174
|
+
};
|
|
175
|
+
_c.label = 1;
|
|
176
|
+
case 1:
|
|
177
|
+
_c.trys.push([1, 3, , 4]);
|
|
178
|
+
state.installed = true;
|
|
179
|
+
_a = state;
|
|
180
|
+
return [4 /*yield*/, getInstalledJLinkVersion()];
|
|
181
|
+
case 2:
|
|
182
|
+
_a.installedVersion = _c.sent();
|
|
183
|
+
return [3 /*break*/, 4];
|
|
184
|
+
case 3:
|
|
185
|
+
e_1 = _c.sent();
|
|
186
|
+
return [3 /*break*/, 4];
|
|
187
|
+
case 4:
|
|
188
|
+
_b = state;
|
|
189
|
+
return [4 /*yield*/, (0, common_1.fetchIndex)()];
|
|
190
|
+
case 5:
|
|
191
|
+
_b.versionToBeInstalled = (_c.sent()).version;
|
|
192
|
+
if (!state.installed || !state.installedVersion) {
|
|
193
|
+
return [2 /*return*/, state];
|
|
194
|
+
}
|
|
195
|
+
state.outdated = !isValidVersion(state.installedVersion, state.versionToBeInstalled);
|
|
196
|
+
return [2 /*return*/, state];
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
}); };
|
|
200
|
+
exports.getVersionToInstall = getVersionToInstall;
|
|
201
|
+
var downloadAndInstallJLink = function (onUpdate) {
|
|
202
|
+
return (0, common_1.fetchIndex)()
|
|
203
|
+
.then(function (v) { return downloadJLink(v, onUpdate); })
|
|
204
|
+
.then(function (v) { return installJLink(v, onUpdate); });
|
|
205
|
+
};
|
|
206
|
+
exports.downloadAndInstallJLink = downloadAndInstallJLink;
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nordicsemiconductor/nrf-jlink-js",
|
|
3
|
+
"version": "0.0.0-alpha1",
|
|
4
|
+
"main": "dist",
|
|
5
|
+
"types": "dist",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"axios": "^1.7.9",
|
|
11
|
+
"semver": "^7.7.2"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc",
|
|
15
|
+
"release-jlink": "ts-node scripts/release-jlink.ts"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/semver": "^7.7.0",
|
|
19
|
+
"ts-node": "^10.9.2",
|
|
20
|
+
"typescript": "^5.7.2"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/NordicSemiconductor/nrf-jlink-js.git"
|
|
25
|
+
},
|
|
26
|
+
"author": "Nordic Semiconductor ASA",
|
|
27
|
+
"license": "Proprietary",
|
|
28
|
+
"description": "Shared library to handle J-Link versions"
|
|
29
|
+
}
|