@nordicsemiconductor/nrf-jlink-js 0.0.3 → 0.0.4
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/scripts/upload-jlink.d.ts +2 -0
- package/dist/scripts/upload-jlink.js +295 -0
- package/dist/src/common.d.ts +10 -0
- package/dist/{common.js → src/common.js} +7 -3
- package/dist/src/index.d.ts +2 -0
- package/dist/{index.js → src/index.js} +2 -1
- package/dist/{jlink.d.ts → src/jlink.d.ts} +1 -0
- package/dist/{jlink.js → src/jlink.js} +59 -44
- package/package.json +2 -2
- package/dist/common.d.ts +0 -15
- package/dist/index.d.ts +0 -2
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
#!/usr/bin/env ts-node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __assign = (this && this.__assign) || function () {
|
|
4
|
+
__assign = Object.assign || function(t) {
|
|
5
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
6
|
+
s = arguments[i];
|
|
7
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
8
|
+
t[p] = s[p];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
return __assign.apply(this, arguments);
|
|
13
|
+
};
|
|
14
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
24
|
+
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);
|
|
25
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
26
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
27
|
+
function step(op) {
|
|
28
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
29
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
30
|
+
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;
|
|
31
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
32
|
+
switch (op[0]) {
|
|
33
|
+
case 0: case 1: t = op; break;
|
|
34
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
35
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
36
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
37
|
+
default:
|
|
38
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
39
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
40
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
41
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
42
|
+
if (t[2]) _.ops.pop();
|
|
43
|
+
_.trys.pop(); continue;
|
|
44
|
+
}
|
|
45
|
+
op = body.call(thisArg, _);
|
|
46
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
47
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
51
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
var path_1 = __importDefault(require("path"));
|
|
55
|
+
var axios_1 = __importDefault(require("axios"));
|
|
56
|
+
var os_1 = __importDefault(require("os"));
|
|
57
|
+
var fs_1 = __importDefault(require("fs"));
|
|
58
|
+
var common_1 = require("../src/common");
|
|
59
|
+
var SEGGER_DOWNLOAD_BASE_URL = 'https://www.segger.com/downloads/jlink';
|
|
60
|
+
var ARTIFACTORY_UPLOAD_BASE_URL = "https://files.nordicsemi.com/artifactory/swtools/external/ncd/jlink";
|
|
61
|
+
var platformToJlinkPlatform = function (variant) {
|
|
62
|
+
switch (variant) {
|
|
63
|
+
case 'win32':
|
|
64
|
+
return 'Windows';
|
|
65
|
+
case 'linux':
|
|
66
|
+
return 'Linux';
|
|
67
|
+
case 'darwin':
|
|
68
|
+
return 'MacOSX';
|
|
69
|
+
default:
|
|
70
|
+
throw new Error("Unknown variant ".concat(variant));
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
var doPerVariant = function (variants, action) { return __awaiter(void 0, void 0, void 0, function () {
|
|
74
|
+
var ret, _loop_1, _i, platforms_1, platform;
|
|
75
|
+
return __generator(this, function (_a) {
|
|
76
|
+
switch (_a.label) {
|
|
77
|
+
case 0:
|
|
78
|
+
ret = {};
|
|
79
|
+
_loop_1 = function (platform) {
|
|
80
|
+
var _b, _c, _d, _e;
|
|
81
|
+
return __generator(this, function (_f) {
|
|
82
|
+
switch (_f.label) {
|
|
83
|
+
case 0:
|
|
84
|
+
_b = ret;
|
|
85
|
+
_c = platform;
|
|
86
|
+
_e = (_d = Object).fromEntries;
|
|
87
|
+
return [4 /*yield*/, Promise.all(common_1.archs.map(function (arch) { return __awaiter(void 0, void 0, void 0, function () {
|
|
88
|
+
var _a;
|
|
89
|
+
return __generator(this, function (_b) {
|
|
90
|
+
switch (_b.label) {
|
|
91
|
+
case 0:
|
|
92
|
+
_a = [arch];
|
|
93
|
+
return [4 /*yield*/, action(variants[platform][arch])];
|
|
94
|
+
case 1: return [2 /*return*/, _a.concat([
|
|
95
|
+
(_b.sent()) ||
|
|
96
|
+
variants[platform][arch]
|
|
97
|
+
])];
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}); }))];
|
|
101
|
+
case 1:
|
|
102
|
+
_b[_c] = _e.apply(_d, [_f.sent()]);
|
|
103
|
+
return [2 /*return*/];
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
_i = 0, platforms_1 = common_1.platforms;
|
|
108
|
+
_a.label = 1;
|
|
109
|
+
case 1:
|
|
110
|
+
if (!(_i < platforms_1.length)) return [3 /*break*/, 4];
|
|
111
|
+
platform = platforms_1[_i];
|
|
112
|
+
return [5 /*yield**/, _loop_1(platform)];
|
|
113
|
+
case 2:
|
|
114
|
+
_a.sent();
|
|
115
|
+
_a.label = 3;
|
|
116
|
+
case 3:
|
|
117
|
+
_i++;
|
|
118
|
+
return [3 /*break*/, 1];
|
|
119
|
+
case 4: return [2 /*return*/, ret];
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}); };
|
|
123
|
+
var downloadInstallers = function (fileNames) { return __awaiter(void 0, void 0, void 0, function () {
|
|
124
|
+
var incorrectFiles, ret;
|
|
125
|
+
return __generator(this, function (_a) {
|
|
126
|
+
switch (_a.label) {
|
|
127
|
+
case 0:
|
|
128
|
+
console.log('Started downloading all JLink variants.');
|
|
129
|
+
incorrectFiles = [];
|
|
130
|
+
return [4 /*yield*/, doPerVariant(fileNames, function (fileName) { return __awaiter(void 0, void 0, void 0, function () {
|
|
131
|
+
var url, _a, status, stream;
|
|
132
|
+
return __generator(this, function (_b) {
|
|
133
|
+
switch (_b.label) {
|
|
134
|
+
case 0:
|
|
135
|
+
url = "".concat(SEGGER_DOWNLOAD_BASE_URL, "/").concat(fileName);
|
|
136
|
+
console.log('Started download:', url);
|
|
137
|
+
return [4 /*yield*/, axios_1.default.postForm(url, { accept_license_agreement: 'accepted' }, {
|
|
138
|
+
responseType: 'stream',
|
|
139
|
+
headers: {
|
|
140
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
141
|
+
},
|
|
142
|
+
})];
|
|
143
|
+
case 1:
|
|
144
|
+
_a = _b.sent(), status = _a.status, stream = _a.data;
|
|
145
|
+
if (status !== 200) {
|
|
146
|
+
throw new Error("Unable to download ".concat(url, ". Got status code ").concat(status, "."));
|
|
147
|
+
}
|
|
148
|
+
if (!(stream.statusMessage === 'OK')) return [3 /*break*/, 3];
|
|
149
|
+
console.log('Finished download:', url);
|
|
150
|
+
return [4 /*yield*/, (0, common_1.saveToFile)(stream, path_1.default.join(os_1.default.tmpdir(), fileName))];
|
|
151
|
+
case 2: return [2 /*return*/, _b.sent()];
|
|
152
|
+
case 3:
|
|
153
|
+
incorrectFiles.push(fileName);
|
|
154
|
+
console.log('Failed to download (check if file exists):', url);
|
|
155
|
+
return [2 /*return*/, 'Incorrect'];
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}); })];
|
|
159
|
+
case 1:
|
|
160
|
+
ret = _a.sent();
|
|
161
|
+
if (incorrectFiles.length > 0) {
|
|
162
|
+
throw new Error("Failed to download: ".concat(incorrectFiles.join(', ')));
|
|
163
|
+
}
|
|
164
|
+
console.log('Finished downloading all JLink variants.');
|
|
165
|
+
return [2 /*return*/, ret];
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}); };
|
|
169
|
+
var getStandardisedVersion = function (rawVersion) {
|
|
170
|
+
var _a;
|
|
171
|
+
var regex = /[vV]?(\d+)\.(\d\d)(.{0,1})/;
|
|
172
|
+
var _b = (_a = rawVersion.match(regex)) !== null && _a !== void 0 ? _a : [], parsedVersion = _b[0], major = _b[1], minor = _b[2], patch = _b[3];
|
|
173
|
+
if (!parsedVersion || !major || !minor) {
|
|
174
|
+
throw new Error("Unable to parse version ".concat(rawVersion, ". Valid formats: v12.34, v1.23a, V1.23a, 12.34, 1.23a"));
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
major: major,
|
|
178
|
+
minor: minor,
|
|
179
|
+
patch: patch === null || patch === void 0 ? void 0 : patch.toLowerCase(),
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
var getFileFormat = function (platform) {
|
|
183
|
+
switch (platform) {
|
|
184
|
+
case 'win32':
|
|
185
|
+
return 'exe';
|
|
186
|
+
case 'darwin':
|
|
187
|
+
return 'pkg';
|
|
188
|
+
case 'linux':
|
|
189
|
+
return 'deb';
|
|
190
|
+
default:
|
|
191
|
+
throw new Error("Unknown platform ".concat(process.platform));
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
var getFileNames = function (rawVersion) {
|
|
195
|
+
var version = getStandardisedVersion(rawVersion);
|
|
196
|
+
var fileNames = {};
|
|
197
|
+
var _loop_2 = function (platform) {
|
|
198
|
+
fileNames[platform] = Object.fromEntries(common_1.archs.map(function (arch) {
|
|
199
|
+
var _a;
|
|
200
|
+
return [
|
|
201
|
+
arch,
|
|
202
|
+
"JLink_".concat(platformToJlinkPlatform(platform), "_V").concat(version.major).concat(version.minor).concat((_a = version.patch) !== null && _a !== void 0 ? _a : '', "_").concat(arch == 'x64' ? 'x86_64' : arch, ".").concat(getFileFormat(platform)),
|
|
203
|
+
];
|
|
204
|
+
}));
|
|
205
|
+
};
|
|
206
|
+
for (var _i = 0, platforms_2 = common_1.platforms; _i < platforms_2.length; _i++) {
|
|
207
|
+
var platform = platforms_2[_i];
|
|
208
|
+
_loop_2(platform);
|
|
209
|
+
}
|
|
210
|
+
return fileNames;
|
|
211
|
+
};
|
|
212
|
+
var getUpdatedSourceJson = function (version, jlinkUrls) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
213
|
+
return [2 /*return*/, (0, common_1.fetchIndex)().then(function (index) { return (__assign(__assign({}, index), { version: version, jlinkUrls: jlinkUrls })); })];
|
|
214
|
+
}); }); };
|
|
215
|
+
var uploadFile = function (url, data) { return __awaiter(void 0, void 0, void 0, function () {
|
|
216
|
+
var res, _a, _b, _c;
|
|
217
|
+
return __generator(this, function (_d) {
|
|
218
|
+
switch (_d.label) {
|
|
219
|
+
case 0: return [4 /*yield*/, fetch(url, {
|
|
220
|
+
method: 'PUT',
|
|
221
|
+
body: data,
|
|
222
|
+
headers: {
|
|
223
|
+
Authorization: "Bearer ".concat(process.env.ARTIFACTORY_TOKEN),
|
|
224
|
+
},
|
|
225
|
+
})];
|
|
226
|
+
case 1:
|
|
227
|
+
res = _d.sent();
|
|
228
|
+
if (!!res.ok) return [3 /*break*/, 3];
|
|
229
|
+
_a = Error.bind;
|
|
230
|
+
_c = (_b = "Unable to upload to ".concat(url, ". Status code: ").concat(res.status, ". Body: ")).concat;
|
|
231
|
+
return [4 /*yield*/, res.text()];
|
|
232
|
+
case 2: throw new (_a.apply(Error, [void 0, _c.apply(_b, [_d.sent()])]))();
|
|
233
|
+
case 3: return [2 /*return*/];
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}); };
|
|
237
|
+
var upload = function (version, files) {
|
|
238
|
+
if (!process.env.ARTIFACTORY_TOKEN) {
|
|
239
|
+
throw new Error('ARTIFACTORY_TOKEN environment variable not set');
|
|
240
|
+
}
|
|
241
|
+
console.log('Started uploading all JLink variants.');
|
|
242
|
+
return new Promise(function (resolve) { return __awaiter(void 0, void 0, void 0, function () {
|
|
243
|
+
var jlinkUrls, targetUrl, versionObject, updatedIndexJSON;
|
|
244
|
+
return __generator(this, function (_a) {
|
|
245
|
+
switch (_a.label) {
|
|
246
|
+
case 0: return [4 /*yield*/, doPerVariant(files, function (filePath) { return __awaiter(void 0, void 0, void 0, function () {
|
|
247
|
+
var fileName, targetUrl;
|
|
248
|
+
return __generator(this, function (_a) {
|
|
249
|
+
switch (_a.label) {
|
|
250
|
+
case 0:
|
|
251
|
+
fileName = path_1.default.basename(filePath);
|
|
252
|
+
console.log('Started upload:', fileName);
|
|
253
|
+
targetUrl = "".concat(ARTIFACTORY_UPLOAD_BASE_URL, "/").concat(fileName);
|
|
254
|
+
return [4 /*yield*/, uploadFile(targetUrl, fs_1.default.readFileSync(filePath))];
|
|
255
|
+
case 1:
|
|
256
|
+
_a.sent();
|
|
257
|
+
fs_1.default.rmSync(filePath);
|
|
258
|
+
console.log('Finished upload:', fileName);
|
|
259
|
+
return [2 /*return*/, targetUrl];
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
}); })];
|
|
263
|
+
case 1:
|
|
264
|
+
jlinkUrls = _a.sent();
|
|
265
|
+
// Index
|
|
266
|
+
console.log('Started uploading Index');
|
|
267
|
+
targetUrl = "".concat(ARTIFACTORY_UPLOAD_BASE_URL, "/index.json");
|
|
268
|
+
versionObject = getStandardisedVersion(version);
|
|
269
|
+
return [4 /*yield*/, getUpdatedSourceJson("v".concat(versionObject.major, ".").concat(versionObject.minor).concat(versionObject.patch || ''), jlinkUrls)];
|
|
270
|
+
case 2:
|
|
271
|
+
updatedIndexJSON = _a.sent();
|
|
272
|
+
return [4 /*yield*/, uploadFile(targetUrl, Buffer.from(JSON.stringify(updatedIndexJSON, null, 2)))];
|
|
273
|
+
case 3:
|
|
274
|
+
_a.sent();
|
|
275
|
+
console.log('Finished uploading Index');
|
|
276
|
+
return [2 /*return*/, resolve(targetUrl)];
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
}); });
|
|
280
|
+
};
|
|
281
|
+
var main = function (version) {
|
|
282
|
+
return downloadInstallers(getFileNames(version)).then(function (files) {
|
|
283
|
+
return upload(version, files);
|
|
284
|
+
});
|
|
285
|
+
};
|
|
286
|
+
var runAsScript = require.main === module;
|
|
287
|
+
if (runAsScript) {
|
|
288
|
+
var versionIndex = process.argv.findIndex(function (arg) { return arg === '--version' || arg === '-v'; }) + 1;
|
|
289
|
+
var version = versionIndex > 0 ? process.argv[versionIndex] : undefined;
|
|
290
|
+
if (!version) {
|
|
291
|
+
console.error('No version passed with --version or -v');
|
|
292
|
+
process.exit(1);
|
|
293
|
+
}
|
|
294
|
+
main(version);
|
|
295
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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>;
|
|
5
|
+
export interface JLinkIndex {
|
|
6
|
+
version: string;
|
|
7
|
+
jlinkUrls: JLinkVariant;
|
|
8
|
+
}
|
|
9
|
+
export declare const fetchIndex: () => Promise<JLinkIndex>;
|
|
10
|
+
export declare const saveToFile: (stream: NodeJS.ReadableStream, destinationFile: string) => Promise<string>;
|
|
@@ -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 () {
|
|
@@ -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; } });
|
|
@@ -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 {};
|
|
@@ -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.4",
|
|
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",
|
package/dist/common.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
jlinkUrls: JLinkVariant;
|
|
13
|
-
}
|
|
14
|
-
export declare const fetchIndex: () => Promise<JLinkIndex>;
|
|
15
|
-
export declare const saveToFile: (stream: NodeJS.ReadableStream, destinationFile: string) => Promise<string>;
|
package/dist/index.d.ts
DELETED