@nordicsemiconductor/nrf-jlink-js 0.0.10 → 0.9.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/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: Buffer) => Promise<string>;
10
+ export declare const saveToFile: (destinationFile: string, data: string | NodeJS.ArrayBufferView) => Promise<string>;
package/dist/jlink.js CHANGED
@@ -53,20 +53,33 @@ 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
+ 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
+ }
57
70
  var getJLinkExePath = function () {
71
+ var _a;
58
72
  switch (os_1.default.platform()) {
59
73
  case 'win32':
60
- var path_2 = (0, child_process_1.execSync)('reg query HKEY_CURRENT_USER\\Software\\SEGGER\\J-Link /v InstallPath').toString();
61
- var pathAlternative = (0, child_process_1.execSync)('reg query HKEY_LOCAL_MACHINE\\Software\\SEGGER\\J-Link /v InstallPath').toString();
62
- if (!path_2 && !pathAlternative) {
63
- throw new Error('JLink not installed');
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');
64
77
  }
65
- else if ((path_2 && typeof path_2 !== 'string') ||
66
- (pathAlternative && typeof pathAlternative !== 'string')) {
67
- throw new Error('Unable to read JLink install path');
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');
68
81
  }
69
- return (path_2 || pathAlternative);
82
+ return "\"".concat(path_1.default.join(cwd, 'JLink.exe'), "\"");
70
83
  case 'linux':
71
84
  case 'darwin':
72
85
  return 'JLinkExe';
@@ -74,43 +87,23 @@ var getJLinkExePath = function () {
74
87
  throw new Error('Invalid platform');
75
88
  }
76
89
  };
77
- var getInstalledJLinkVersion = function () {
78
- return new Promise(function (resolve, reject) {
79
- var jlinkExeCmd = (0, child_process_1.spawn)(getJLinkExePath(), ['-NoGUI', '1'], {
80
- shell: true,
81
- });
82
- var timeout = setTimeout(function () {
83
- var pid = jlinkExeCmd === null || jlinkExeCmd === void 0 ? void 0 : jlinkExeCmd.pid;
84
- if (pid) {
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
+ 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.");
90
102
  }
91
- }
92
- reject('Failed to read Jlink Version');
93
- }, 5000);
94
- jlinkExeCmd.stdout.on('data', function (data) {
95
- var versionRegExp = /DLL version (V\d+\.\d+\w*),.*/;
96
- var versionMatch = data.toString().match(versionRegExp);
97
- if (versionMatch === null || versionMatch === void 0 ? void 0 : versionMatch[1]) {
98
- jlinkExeCmd.stdin.write(' exit\n');
99
- resolve(versionMatch[1].toLowerCase());
100
- }
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
- });
103
+ return [2 /*return*/, "v".concat(match)];
104
+ }
112
105
  });
113
- };
106
+ }); };
114
107
  var downloadJLink = function (_a, onUpdate_1) {
115
108
  var args_1 = [];
116
109
  for (var _i = 2; _i < arguments.length; _i++) {
@@ -251,7 +244,11 @@ var getVersionToInstall = function (fallbackVersion) { return __awaiter(void 0,
251
244
  });
252
245
  }); };
253
246
  exports.getVersionToInstall = getVersionToInstall;
254
- var downloadAndSaveJLink = function (destinationDir, destinationFileName, onUpdate) { return (0, common_1.fetchIndex)().then(function (v) { return downloadJLink(v, onUpdate, destinationDir, destinationFileName); }); };
247
+ var downloadAndSaveJLink = function (destinationDir, destinationFileName, onUpdate) {
248
+ return (0, common_1.fetchIndex)().then(function (v) {
249
+ return downloadJLink(v, onUpdate, destinationDir, destinationFileName);
250
+ });
251
+ };
255
252
  exports.downloadAndSaveJLink = downloadAndSaveJLink;
256
253
  var downloadAndInstallJLink = function (onUpdate) {
257
254
  return (0, common_1.fetchIndex)()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nordicsemiconductor/nrf-jlink-js",
3
- "version": "0.0.10",
3
+ "version": "0.9.0",
4
4
  "main": "dist",
5
5
  "types": "dist",
6
6
  "files": [