@nordicsemiconductor/nrf-jlink-js 0.0.3 → 0.0.5
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/common.d.ts +4 -9
- package/dist/common.js +7 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -1
- package/dist/jlink.d.ts +1 -0
- package/dist/jlink.js +59 -44
- package/package.json +2 -2
package/dist/common.d.ts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export interface JLinkVariant {
|
|
6
|
-
linux: ArchUrl;
|
|
7
|
-
darwin: ArchUrl;
|
|
8
|
-
win32: ArchUrl;
|
|
9
|
-
}
|
|
1
|
+
export declare const platforms: readonly ["darwin", "linux", "win32"];
|
|
2
|
+
export declare const archs: readonly ["arm64", "x64"];
|
|
3
|
+
export type ArchUrl = Record<(typeof archs)[number], string>;
|
|
4
|
+
export type JLinkVariant = Record<(typeof platforms)[number], ArchUrl>;
|
|
10
5
|
export interface JLinkIndex {
|
|
11
6
|
version: string;
|
|
12
7
|
jlinkUrls: JLinkVariant;
|
package/dist/common.js
CHANGED
|
@@ -39,9 +39,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.saveToFile = exports.fetchIndex = void 0;
|
|
42
|
+
exports.saveToFile = exports.fetchIndex = exports.archs = exports.platforms = void 0;
|
|
43
43
|
var axios_1 = __importDefault(require("axios"));
|
|
44
|
-
var fs_1 =
|
|
44
|
+
var fs_1 = require("fs");
|
|
45
|
+
var path_1 = __importDefault(require("path"));
|
|
46
|
+
exports.platforms = ['darwin', 'linux', 'win32'];
|
|
47
|
+
exports.archs = ['arm64', 'x64'];
|
|
45
48
|
var fetchJSON = function (url) { return __awaiter(void 0, void 0, void 0, function () {
|
|
46
49
|
var _a, status, data;
|
|
47
50
|
return __generator(this, function (_b) {
|
|
@@ -76,8 +79,9 @@ var fetchIndex = function () { return __awaiter(void 0, void 0, void 0, function
|
|
|
76
79
|
}); };
|
|
77
80
|
exports.fetchIndex = fetchIndex;
|
|
78
81
|
var saveToFile = function (stream, destinationFile) {
|
|
82
|
+
(0, fs_1.mkdirSync)(path_1.default.dirname(destinationFile), { recursive: true });
|
|
79
83
|
return new Promise(function (resolve, reject) {
|
|
80
|
-
var file = fs_1.
|
|
84
|
+
var file = (0, fs_1.createWriteStream)(destinationFile);
|
|
81
85
|
stream.pipe(file);
|
|
82
86
|
stream.on('error', reject);
|
|
83
87
|
stream.on('end', function () {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { downloadAndInstallJLink, getVersionToInstall } from './jlink';
|
|
2
|
-
export { downloadAndInstallJLink, getVersionToInstall };
|
|
1
|
+
import { downloadAndInstallJLink, getVersionToInstall, downloadAndSaveJLink } from './jlink';
|
|
2
|
+
export { downloadAndInstallJLink, getVersionToInstall, downloadAndSaveJLink };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getVersionToInstall = exports.downloadAndInstallJLink = void 0;
|
|
3
|
+
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
|
+
Object.defineProperty(exports, "downloadAndSaveJLink", { enumerable: true, get: function () { return jlink_1.downloadAndSaveJLink; } });
|
package/dist/jlink.d.ts
CHANGED
|
@@ -9,5 +9,6 @@ interface JLinkState {
|
|
|
9
9
|
installedVersion?: string;
|
|
10
10
|
}
|
|
11
11
|
export declare const getVersionToInstall: (fallbackVersion?: string) => Promise<JLinkState>;
|
|
12
|
+
export declare const downloadAndSaveJLink: (destination: string, onUpdate?: (percentage: number) => void) => Promise<string>;
|
|
12
13
|
export declare const downloadAndInstallJLink: (onUpdate?: (update: Update) => void) => Promise<void>;
|
|
13
14
|
export {};
|
package/dist/jlink.js
CHANGED
|
@@ -35,13 +35,21 @@ 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
|
+
};
|
|
38
47
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
48
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
49
|
};
|
|
41
50
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.downloadAndInstallJLink = exports.getVersionToInstall = void 0;
|
|
51
|
+
exports.downloadAndInstallJLink = exports.downloadAndSaveJLink = exports.getVersionToInstall = void 0;
|
|
43
52
|
var child_process_1 = require("child_process");
|
|
44
|
-
var promises_1 = require("fs/promises");
|
|
45
53
|
var os_1 = __importDefault(require("os"));
|
|
46
54
|
var path_1 = __importDefault(require("path"));
|
|
47
55
|
var semver_1 = __importDefault(require("semver"));
|
|
@@ -104,49 +112,52 @@ var getInstalledJLinkVersion = function () {
|
|
|
104
112
|
});
|
|
105
113
|
});
|
|
106
114
|
};
|
|
107
|
-
var downloadJLink = function (_a, onUpdate_1) {
|
|
108
|
-
var
|
|
109
|
-
var
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
+
});
|
|
148
159
|
});
|
|
149
|
-
}
|
|
160
|
+
};
|
|
150
161
|
var installJLink = function (installerPath, onUpdate) {
|
|
151
162
|
var command;
|
|
152
163
|
var args;
|
|
@@ -215,6 +226,10 @@ var getVersionToInstall = function (fallbackVersion) { return __awaiter(void 0,
|
|
|
215
226
|
});
|
|
216
227
|
}); };
|
|
217
228
|
exports.getVersionToInstall = getVersionToInstall;
|
|
229
|
+
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); });
|
|
231
|
+
};
|
|
232
|
+
exports.downloadAndSaveJLink = downloadAndSaveJLink;
|
|
218
233
|
var downloadAndInstallJLink = function (onUpdate) {
|
|
219
234
|
return (0, common_1.fetchIndex)()
|
|
220
235
|
.then(function (v) { return downloadJLink(v, onUpdate); })
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nordicsemiconductor/nrf-jlink-js",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"main": "dist",
|
|
5
5
|
"types": "dist",
|
|
6
6
|
"files": [
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
14
|
"build": "tsc",
|
|
15
|
-
"
|
|
15
|
+
"upload-jlink": "ts-node scripts/upload-jlink.ts"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@types/semver": "^7.7.0",
|