@nordicsemiconductor/nrf-jlink-js 0.0.2 → 0.0.3

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.js CHANGED
@@ -56,7 +56,7 @@ var fetchJSON = function (url) { return __awaiter(void 0, void 0, void 0, functi
56
56
  }
57
57
  });
58
58
  }); };
59
- var indexUrl = "https://files.nordicsemi.com/artifactory/swtools/external/ncd/jlink/index.json";
59
+ var indexUrl = 'https://files.nordicsemi.com/artifactory/swtools/external/ncd/jlink/index.json';
60
60
  var fetchIndex = function () { return __awaiter(void 0, void 0, void 0, function () {
61
61
  var res;
62
62
  return __generator(this, function (_a) {
@@ -64,7 +64,10 @@ var fetchIndex = function () { return __awaiter(void 0, void 0, void 0, function
64
64
  case 0: return [4 /*yield*/, fetchJSON(indexUrl)];
65
65
  case 1:
66
66
  res = _a.sent();
67
- if (res == null || typeof res !== 'object' || res.version === undefined || res.jlinkUrls === undefined) {
67
+ if (res == null ||
68
+ typeof res !== 'object' ||
69
+ res.version === undefined ||
70
+ res.jlinkUrls === undefined) {
68
71
  throw new Error('`index.json` does not have the expected content.');
69
72
  }
70
73
  return [2 /*return*/, res];
@@ -76,8 +79,8 @@ var saveToFile = function (stream, destinationFile) {
76
79
  return new Promise(function (resolve, reject) {
77
80
  var file = fs_1.default.createWriteStream(destinationFile);
78
81
  stream.pipe(file);
79
- stream.on("error", reject);
80
- stream.on("end", function () {
82
+ stream.on('error', reject);
83
+ stream.on('end', function () {
81
84
  file.end(function () {
82
85
  return resolve(destinationFile);
83
86
  });
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { downloadAndInstallJLink, getVersionToInstall } from "./jlink";
1
+ import { downloadAndInstallJLink, getVersionToInstall } from './jlink';
2
2
  export { downloadAndInstallJLink, getVersionToInstall };
package/dist/jlink.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  interface Update {
2
- step: "install" | "download";
2
+ step: 'install' | 'download';
3
3
  percentage: number;
4
4
  }
5
5
  interface JLinkState {
package/dist/jlink.js CHANGED
@@ -49,26 +49,29 @@ var axios_1 = __importDefault(require("axios"));
49
49
  var common_1 = require("./common");
50
50
  var getJLinkExePath = function () {
51
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();
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
55
  if (!path_2 && !pathAlternative) {
56
56
  throw new Error('JLink not installed');
57
57
  }
58
- else if ((path_2 && typeof path_2 !== 'string') || (pathAlternative && typeof pathAlternative !== 'string')) {
58
+ else if ((path_2 && typeof path_2 !== 'string') ||
59
+ (pathAlternative && typeof pathAlternative !== 'string')) {
59
60
  throw new Error('Unable to read JLink install path');
60
61
  }
61
62
  return (path_2 || pathAlternative);
62
- case "linux":
63
- case "darwin":
63
+ case 'linux':
64
+ case 'darwin':
64
65
  return 'JLinkExe';
65
66
  default:
66
- throw new Error("Invalid platform");
67
+ throw new Error('Invalid platform');
67
68
  }
68
69
  };
69
70
  var getInstalledJLinkVersion = function () {
70
71
  return new Promise(function (resolve, reject) {
71
- var jlinkExeCmd = (0, child_process_1.spawn)(getJLinkExePath(), ["-NoGUI", "1"], { shell: true });
72
+ var jlinkExeCmd = (0, child_process_1.spawn)(getJLinkExePath(), ['-NoGUI', '1'], {
73
+ shell: true,
74
+ });
72
75
  var timeout = setTimeout(function () {
73
76
  var pid = jlinkExeCmd === null || jlinkExeCmd === void 0 ? void 0 : jlinkExeCmd.pid;
74
77
  if (pid) {
@@ -81,19 +84,19 @@ var getInstalledJLinkVersion = function () {
81
84
  }
82
85
  reject('Failed to read Jlink Version');
83
86
  }, 5000);
84
- jlinkExeCmd.stdout.on("data", function (data) {
87
+ jlinkExeCmd.stdout.on('data', function (data) {
85
88
  var versionRegExp = /DLL version (V\d+\.\d+\w*),.*/;
86
89
  var versionMatch = data.toString().match(versionRegExp);
87
90
  if (versionMatch === null || versionMatch === void 0 ? void 0 : versionMatch[1]) {
88
91
  jlinkExeCmd.stdin.write(' exit\n');
89
92
  resolve(versionMatch[1].toLowerCase());
90
93
  }
91
- else if (data.toString().includes("Connecting to")) {
94
+ else if (data.toString().includes('Connecting to')) {
92
95
  jlinkExeCmd.stdin.write(' exit\n');
93
96
  reject('Failed to read Jlink Version');
94
97
  }
95
98
  });
96
- jlinkExeCmd.stderr.on("data", function () {
99
+ jlinkExeCmd.stderr.on('data', function () {
97
100
  reject('Failed to read Jlink Version');
98
101
  });
99
102
  jlinkExeCmd.on('close', function () {
@@ -119,11 +122,15 @@ var downloadJLink = function (_a, onUpdate_1) { return __awaiter(void 0, [_a, on
119
122
  throw new Error("JLink not available for ".concat(platform, "/").concat(arch));
120
123
  }
121
124
  return [4 /*yield*/, axios_1.default.get(url, {
122
- responseType: "stream",
125
+ responseType: 'stream',
123
126
  onDownloadProgress: function (_a) {
124
127
  var loaded = _a.loaded, total = _a.total;
125
- return loaded && total &&
126
- (onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate({ step: "download", percentage: Number(((loaded / total) * 100).toFixed(2)) }));
128
+ return loaded &&
129
+ total &&
130
+ (onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate({
131
+ step: 'download',
132
+ percentage: Number(((loaded / total) * 100).toFixed(2)),
133
+ }));
127
134
  },
128
135
  })];
129
136
  case 1:
@@ -141,7 +148,6 @@ var downloadJLink = function (_a, onUpdate_1) { return __awaiter(void 0, [_a, on
141
148
  });
142
149
  }); };
143
150
  var installJLink = function (installerPath, onUpdate) {
144
- ;
145
151
  var command;
146
152
  var args;
147
153
  switch (os_1.default.platform()) {
@@ -157,21 +163,19 @@ var installJLink = function (installerPath, onUpdate) {
157
163
  command = "\"".concat(installerPath, "\"");
158
164
  break;
159
165
  default:
160
- throw new Error("Invalid platform");
166
+ throw new Error('Invalid platform');
161
167
  }
162
- onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate({ step: "install", percentage: 0 });
168
+ onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate({ step: 'install', percentage: 0 });
163
169
  return new Promise(function (resolve, reject) {
164
- (0, child_process_1.execFile)(command, args, function (error, stdout, stderr) {
170
+ (0, child_process_1.execFile)(command, args, function (error, _, stderr) {
165
171
  if (error) {
166
- reject(error);
172
+ return reject(error);
167
173
  }
168
174
  if (stderr) {
169
- reject(stderr);
170
- }
171
- if (stdout.includes("successful")) {
172
- onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate({ step: "install", percentage: 100 });
173
- return resolve();
175
+ return reject(stderr);
174
176
  }
177
+ onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate({ step: 'install', percentage: 100 });
178
+ return resolve();
175
179
  });
176
180
  });
177
181
  };
@@ -198,7 +202,9 @@ var getVersionToInstall = function (fallbackVersion) { return __awaiter(void 0,
198
202
  case 2:
199
203
  installedVersion = _c.sent();
200
204
  installed = !!installedVersion;
201
- outdated = !installed || !versionToBeInstalled || !isValidVersion(installedVersion, versionToBeInstalled);
205
+ outdated = !installed ||
206
+ !versionToBeInstalled ||
207
+ !isValidVersion(installedVersion, versionToBeInstalled);
202
208
  return [2 /*return*/, {
203
209
  outdated: outdated,
204
210
  installedVersion: installedVersion,
package/package.json CHANGED
@@ -1,29 +1,29 @@
1
1
  {
2
- "name": "@nordicsemiconductor/nrf-jlink-js",
3
- "version": "0.0.2",
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": "git+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"
2
+ "name": "@nordicsemiconductor/nrf-jlink-js",
3
+ "version": "0.0.3",
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": "git+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
29
  }