@medplum/cli 2.0.4 → 2.0.6
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/package.json +1 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -119
package/package.json
CHANGED
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.main = void 0;
|
|
8
|
-
const core_1 = require("@medplum/core");
|
|
9
|
-
const dotenv_1 = __importDefault(require("dotenv"));
|
|
10
|
-
const fs_1 = require("fs");
|
|
11
|
-
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
12
|
-
const path_1 = require("path");
|
|
13
|
-
async function main(medplum, argv) {
|
|
14
|
-
if (argv.length < 3) {
|
|
15
|
-
console.log('Usage: medplum <command>');
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
const command = argv[2];
|
|
19
|
-
if (command === 'save-bot') {
|
|
20
|
-
await runBotCommands(medplum, argv, ['save']);
|
|
21
|
-
}
|
|
22
|
-
else if (command === 'deploy-bot') {
|
|
23
|
-
await runBotCommands(medplum, argv, ['save', 'deploy']);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
console.log(`Unknown command: ${command}`);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
exports.main = main;
|
|
30
|
-
async function runBotCommands(medplum, argv, commands) {
|
|
31
|
-
if (argv.length < 4) {
|
|
32
|
-
console.log(`Usage: medplum ${argv[2]} <bot-name>`);
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const botName = argv[3];
|
|
36
|
-
const botConfig = readBotConfig(botName);
|
|
37
|
-
if (!botConfig) {
|
|
38
|
-
console.log(`Error: ${botName} not found`);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
let bot;
|
|
42
|
-
try {
|
|
43
|
-
bot = await medplum.readResource('Bot', botConfig.id);
|
|
44
|
-
}
|
|
45
|
-
catch (err) {
|
|
46
|
-
console.log('Error: ' + (0, core_1.normalizeErrorString)(err));
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
if (commands.includes('save')) {
|
|
50
|
-
await saveBot(medplum, botConfig, bot);
|
|
51
|
-
}
|
|
52
|
-
if (commands.includes('deploy')) {
|
|
53
|
-
await deployBot(medplum, botConfig, bot);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
async function saveBot(medplum, botConfig, bot) {
|
|
57
|
-
const code = readFileContents(botConfig.source);
|
|
58
|
-
if (!code) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
try {
|
|
62
|
-
console.log('Update bot code.....');
|
|
63
|
-
const updateResult = await medplum.updateResource({
|
|
64
|
-
...bot,
|
|
65
|
-
code,
|
|
66
|
-
});
|
|
67
|
-
if (!updateResult) {
|
|
68
|
-
console.log('Bot not modified');
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
console.log('Success! New bot version: ' + updateResult.meta?.versionId);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
catch (err) {
|
|
75
|
-
console.log('Update error: ', err);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
async function deployBot(medplum, botConfig, bot) {
|
|
79
|
-
const code = readFileContents(botConfig.dist ?? botConfig.source);
|
|
80
|
-
if (!code) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
try {
|
|
84
|
-
console.log('Deploying bot...');
|
|
85
|
-
const deployResult = (await medplum.post(medplum.fhirUrl('Bot', bot.id, '$deploy'), {
|
|
86
|
-
code,
|
|
87
|
-
}));
|
|
88
|
-
console.log('Deploy result: ' + deployResult.issue?.[0]?.details?.text);
|
|
89
|
-
}
|
|
90
|
-
catch (err) {
|
|
91
|
-
console.log('Deploy error: ', err);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
function readBotConfig(botName) {
|
|
95
|
-
return readConfig()?.bots?.find((b) => b.name === botName);
|
|
96
|
-
}
|
|
97
|
-
function readConfig() {
|
|
98
|
-
const content = readFileContents('medplum.config.json');
|
|
99
|
-
if (!content) {
|
|
100
|
-
return undefined;
|
|
101
|
-
}
|
|
102
|
-
return JSON.parse(content);
|
|
103
|
-
}
|
|
104
|
-
function readFileContents(fileName) {
|
|
105
|
-
const path = (0, path_1.resolve)(process.cwd(), fileName);
|
|
106
|
-
if (!(0, fs_1.existsSync)(path)) {
|
|
107
|
-
console.log('Error: File does not exist: ' + path);
|
|
108
|
-
return '';
|
|
109
|
-
}
|
|
110
|
-
return (0, fs_1.readFileSync)(path, 'utf8');
|
|
111
|
-
}
|
|
112
|
-
if (require.main === module) {
|
|
113
|
-
dotenv_1.default.config();
|
|
114
|
-
const medplum = new core_1.MedplumClient({ fetch: node_fetch_1.default, baseUrl: process.env['MEDPLUM_BASE_URL'] });
|
|
115
|
-
medplum
|
|
116
|
-
.startClientLogin(process.env['MEDPLUM_CLIENT_ID'], process.env['MEDPLUM_CLIENT_SECRET'])
|
|
117
|
-
.then(() => main(medplum, process.argv))
|
|
118
|
-
.catch((err) => console.error('Unhandled error:', err));
|
|
119
|
-
}
|