@nordicsemiconductor/nrf-jlink-js 0.0.10 → 0.0.11
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 +1 -1
- package/dist/jlink.js +46 -35
- package/package.json +1 -1
package/dist/common.d.ts
CHANGED
|
@@ -7,4 +7,4 @@ export interface JLinkIndex {
|
|
|
7
7
|
jlinkUrls: JLinkVariant;
|
|
8
8
|
}
|
|
9
9
|
export declare const fetchIndex: () => Promise<JLinkIndex>;
|
|
10
|
-
export declare const saveToFile: (destinationFile: string, data:
|
|
10
|
+
export declare const saveToFile: (destinationFile: string, data: string | NodeJS.ArrayBufferView) => Promise<string>;
|
package/dist/jlink.js
CHANGED
|
@@ -53,20 +53,30 @@ var child_process_1 = require("child_process");
|
|
|
53
53
|
var os_1 = __importDefault(require("os"));
|
|
54
54
|
var path_1 = __importDefault(require("path"));
|
|
55
55
|
var semver_1 = __importDefault(require("semver"));
|
|
56
|
+
var fs_1 = require("fs");
|
|
56
57
|
var common_1 = require("./common");
|
|
58
|
+
function winRegQuery(key) {
|
|
59
|
+
var _a;
|
|
60
|
+
if (process.platform !== 'win32') {
|
|
61
|
+
throw new Error('Unsupported platform');
|
|
62
|
+
}
|
|
63
|
+
var reg = path_1.default.resolve((_a = process.env.SystemRoot) !== null && _a !== void 0 ? _a : 'C:\\Windows', 'System32', 'reg.exe');
|
|
64
|
+
if (!(0, fs_1.existsSync)(reg)) {
|
|
65
|
+
reg = 'reg.exe';
|
|
66
|
+
}
|
|
67
|
+
return (0, child_process_1.execSync)("".concat(reg, " query ").concat(key)).toString().trim();
|
|
68
|
+
}
|
|
57
69
|
var getJLinkExePath = function () {
|
|
58
70
|
switch (os_1.default.platform()) {
|
|
59
71
|
case 'win32':
|
|
60
|
-
var
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
throw new Error('JLink not installed');
|
|
72
|
+
var jlinkDir = winRegQuery('HKEY_CURRENT_USER\\Software\\SEGGER\\J-Link /v InstallPath');
|
|
73
|
+
if (!jlinkDir) {
|
|
74
|
+
jlinkDir = winRegQuery('HKEY_LOCAL_MACHINE\\Software\\SEGGER\\J-Link /v InstallPath');
|
|
64
75
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
throw new Error('Unable to read JLink install path');
|
|
76
|
+
if (!jlinkDir) {
|
|
77
|
+
throw new Error('JLink not installed');
|
|
68
78
|
}
|
|
69
|
-
return (
|
|
79
|
+
return path_1.default.resolve(jlinkDir, 'JLink.exe');
|
|
70
80
|
case 'linux':
|
|
71
81
|
case 'darwin':
|
|
72
82
|
return 'JLinkExe';
|
|
@@ -74,40 +84,37 @@ var getJLinkExePath = function () {
|
|
|
74
84
|
throw new Error('Invalid platform');
|
|
75
85
|
}
|
|
76
86
|
};
|
|
87
|
+
function killProcess(childProcess, signal) {
|
|
88
|
+
var pid = typeof childProcess === 'number' ? childProcess : childProcess === null || childProcess === void 0 ? void 0 : childProcess.pid;
|
|
89
|
+
if (!pid) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (process.platform === 'win32') {
|
|
93
|
+
(0, child_process_1.spawn)('taskkill', ['/pid', "".concat(pid), '/f', '/t']);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
process.kill(pid, signal);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
77
99
|
var getInstalledJLinkVersion = function () {
|
|
78
100
|
return new Promise(function (resolve, reject) {
|
|
79
|
-
var jlinkExeCmd = (0, child_process_1.spawn)(getJLinkExePath(), ['-NoGUI', '1'], {
|
|
101
|
+
var jlinkExeCmd = (0, child_process_1.spawn)(getJLinkExePath(), ['-NoGUI', '1', '-USB', '0'], {
|
|
80
102
|
shell: true,
|
|
81
103
|
});
|
|
104
|
+
var output = '';
|
|
82
105
|
var timeout = setTimeout(function () {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (process.platform === 'win32') {
|
|
86
|
-
(0, child_process_1.spawn)('taskkill', ['/pid', "".concat(pid), '/f', '/t']);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
process.kill(pid);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
reject('Failed to read Jlink Version');
|
|
106
|
+
killProcess(jlinkExeCmd.pid);
|
|
107
|
+
reject(new Error("Timeout while waiting for J-Link version. Output: ".concat(output)));
|
|
93
108
|
}, 5000);
|
|
109
|
+
var versionRegExp = /^SEGGER J-Link Commander V([0-9a-z.]+) .*$/m;
|
|
94
110
|
jlinkExeCmd.stdout.on('data', function (data) {
|
|
95
|
-
|
|
96
|
-
var
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
|
|
111
|
+
output += data.toString();
|
|
112
|
+
var match = output.match(versionRegExp);
|
|
113
|
+
if (match === null || match === void 0 ? void 0 : match[1]) {
|
|
114
|
+
clearTimeout(timeout);
|
|
115
|
+
killProcess(jlinkExeCmd.pid);
|
|
116
|
+
resolve(match[1]);
|
|
100
117
|
}
|
|
101
|
-
else if (data.toString().includes('Connecting to')) {
|
|
102
|
-
jlinkExeCmd.stdin.write(' exit\n');
|
|
103
|
-
reject('Failed to read Jlink Version');
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
jlinkExeCmd.stderr.on('data', function () {
|
|
107
|
-
reject('Failed to read Jlink Version');
|
|
108
|
-
});
|
|
109
|
-
jlinkExeCmd.on('close', function () {
|
|
110
|
-
clearTimeout(timeout);
|
|
111
118
|
});
|
|
112
119
|
});
|
|
113
120
|
};
|
|
@@ -251,7 +258,11 @@ var getVersionToInstall = function (fallbackVersion) { return __awaiter(void 0,
|
|
|
251
258
|
});
|
|
252
259
|
}); };
|
|
253
260
|
exports.getVersionToInstall = getVersionToInstall;
|
|
254
|
-
var downloadAndSaveJLink = function (destinationDir, destinationFileName, onUpdate) {
|
|
261
|
+
var downloadAndSaveJLink = function (destinationDir, destinationFileName, onUpdate) {
|
|
262
|
+
return (0, common_1.fetchIndex)().then(function (v) {
|
|
263
|
+
return downloadJLink(v, onUpdate, destinationDir, destinationFileName);
|
|
264
|
+
});
|
|
265
|
+
};
|
|
255
266
|
exports.downloadAndSaveJLink = downloadAndSaveJLink;
|
|
256
267
|
var downloadAndInstallJLink = function (onUpdate) {
|
|
257
268
|
return (0, common_1.fetchIndex)()
|