Skip to content

Commit 8b0077c

Browse files
committed
Update README to show use of NPM package
1 parent 4fc792a commit 8b0077c

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

README.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -220,25 +220,32 @@ Embedded entries (built-in default ones) are demoted to the end of the list, or
220220

221221
## Information for VS Code Extension Developers - How To Leverage Server Manager
222222

223-
An extension XYZ needing to connect to InterSystems servers can define Server Manager as a dependency in its `package.json` like this:
223+
The NPM package [`@intersystems-community/intersystems-servermanager`](https://www.npmjs.com/package/@intersystems-community/intersystems-servermanager) defines the types used by the API which this extension exports. It also declares some constants.
224+
225+
An extension XYZ needing to connect to InterSystems servers should include `"@intersystems-community/intersystems-servermanager": "latest"` in the `"devDependencies"` object in its `package.json`.
226+
227+
It might also define Server Manager as a dependency in its `package.json` like this:
224228

225229
```json
226230
"extensionDependencies": [
227231
"intersystems-community.servermanager"
228232
],
229233
```
230234

231-
Alternatively the `activate` method of XYZ can detect whether the extension is already available, then offer to install it if necessary:
235+
Alternatively the `activate` method of XYZ can detect whether the extension is already available, then offer to install it if not:
232236

233237
```ts
234-
const extId = 'intersystems-community.servermanager';
235-
let extension = vscode.extensions.getExtension(extId);
238+
import * as serverManager from '@intersystems-community/intersystems-servermanager';
239+
```
240+
...
241+
```ts
242+
let extension = vscode.extensions.getExtension(serverManager.EXTENSION_ID);
236243
if (!extension) {
237244
// Optionally ask user for permission
238245
// ...
239246

240-
await vscode.commands.executeCommand('workbench.extensions.installExtension', extId);
241-
extension = vscode.extensions.getExtension(extId);
247+
await vscode.commands.executeCommand('workbench.extensions.installExtension', serverManager.EXTENSION_ID);
248+
extension = vscode.extensions.getExtension(serverManager.EXTENSION_ID);
242249
}
243250
if (!extension.isActive) {
244251
await extension.activate();
@@ -250,7 +257,7 @@ XYZ can then use the extension's API to obtain the properties of a named server
250257
```ts
251258
const serverManagerApi = extension.exports;
252259
if (serverManagerApi && serverManagerApi.getServerSpec) { // defensive coding
253-
const serverSpec = await serverManagerApi.getServerSpec(serverName);
260+
const serverSpec: serverManager.IServerSpec | undefined = await serverManagerApi.getServerSpec(serverName);
254261
}
255262
```
256263

@@ -259,12 +266,11 @@ The `username` and `password` properties will only be present if defined in the
259266
To obtain the password with which to connect, use code like this which will also prompt for a username if absent:
260267

261268
```ts
262-
const AUTHENTICATION_PROVIDER = 'intersystems-server-credentials';
263269
if (typeof serverSpec.password === 'undefined') {
264270
const scopes = [serverSpec.name, serverSpec.username || ''];
265-
let session = await vscode.authentication.getSession(AUTHENTICATION_PROVIDER, scopes, { silent: true });
271+
let session = await vscode.authentication.getSession(serverManager.AUTHENTICATION_PROVIDER, scopes, { silent: true });
266272
if (!session) {
267-
session = await vscode.authentication.getSession(AUTHENTICATION_PROVIDER, scopes, { createIfNone: true });
273+
session = await vscode.authentication.getSession(serverManager.AUTHENTICATION_PROVIDER, scopes, { createIfNone: true });
268274
}
269275
if (session) {
270276
serverSpec.username = session.scopes[1];
@@ -276,13 +282,13 @@ To obtain the password with which to connect, use code like this which will also
276282
To offer the user a quickpick of servers:
277283

278284
```ts
279-
const serverName = await serverManagerApi.pickServer();
285+
const serverName: string = await serverManagerApi.pickServer();
280286
```
281287

282288
To obtain an array of server names:
283289

284290
```ts
285-
const allServerNames = await serverManagerApi.getServerNames();
291+
const allServerNames: serverManager.IServerName[] = await serverManagerApi.getServerNames();
286292
```
287293
For up-to-date details of the API, including result types and available parameters, review the source code of the extension's `activate` method [here](https://github.com/intersystems-community/intersystems-servermanager/blob/master/src/extension.ts).
288294

0 commit comments

Comments
 (0)