dhti-cli 0.3.0 → 0.3.1

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.
@@ -2,18 +2,26 @@ import { Args, Command, Flags } from '@oclif/core';
2
2
  import yaml from 'js-yaml';
3
3
  import fs from 'node:fs';
4
4
  import os from 'node:os';
5
+ import path from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
5
7
  export default class Compose extends Command {
6
8
  static args = {
7
9
  op: Args.string({ description: 'Operation to perform (add, delete, read or reset)' }),
8
10
  };
9
11
  static description = 'Generates a docker-compose.yml file from a list of modules';
10
- static examples = [
11
- '<%= config.bin %> <%= command.id %>',
12
- ];
12
+ static examples = ['<%= config.bin %> <%= command.id %>'];
13
13
  static flags = {
14
- file: Flags.string({ char: 'f', default: `${os.homedir()}/dhti/docker-compose.yml`, description: 'Full path to the docker compose file to read from. Creates if it does not exist' }),
14
+ file: Flags.string({
15
+ char: 'f',
16
+ default: `${os.homedir()}/dhti/docker-compose.yml`,
17
+ description: 'Full path to the docker compose file to read from. Creates if it does not exist',
18
+ }),
15
19
  // flag with a value (-n, --name=VALUE)
16
- module: Flags.string({ char: 'm', description: 'Modules to add from ( langserve, openmrs, ollama, langfuse, cqlFhir, redis, neo4j and mcpFhir)', multiple: true }),
20
+ module: Flags.string({
21
+ char: 'm',
22
+ description: 'Modules to add from ( langserve, openmrs, ollama, langfuse, cqlFhir, redis, neo4j and mcpFhir)',
23
+ multiple: true,
24
+ }),
17
25
  };
18
26
  static init = () => {
19
27
  // Create ${os.homedir()}/dhti if it does not exist
@@ -27,6 +35,10 @@ export default class Compose extends Command {
27
35
  };
28
36
  async run() {
29
37
  const { args, flags } = await this.parse(Compose);
38
+ // Resolve resources directory for both dev (src) and packaged (dist)
39
+ const __filename = fileURLToPath(import.meta.url);
40
+ const __dirname = path.dirname(__filename);
41
+ const RESOURCES_DIR = path.resolve(__dirname, '../resources');
30
42
  // console.log('args', args) //args { op: 'add' }
31
43
  // console.log('flags', flags) //flags { module: [ 'default', 'langserve', 'redis' ] }
32
44
  const openmrs = ['gateway', 'frontend', 'backend', 'openmrs-db'];
@@ -51,10 +63,10 @@ export default class Compose extends Command {
51
63
  ollama,
52
64
  openmrs,
53
65
  redis,
54
- webui
66
+ webui,
55
67
  };
56
68
  try {
57
- const masterData = yaml.load(fs.readFileSync('src/resources/docker-compose-master.yml', 'utf8'));
69
+ const masterData = yaml.load(fs.readFileSync(path.join(RESOURCES_DIR, 'docker-compose-master.yml'), 'utf8'));
58
70
  let existingData = { services: {}, version: '3.8' };
59
71
  if (fs.existsSync(flags.file)) {
60
72
  existingData = yaml.load(fs.readFileSync(flags.file, 'utf8'));
@@ -2,28 +2,44 @@ import { Args, Command, Flags } from '@oclif/core';
2
2
  import { exec } from 'node:child_process';
3
3
  import fs from 'node:fs';
4
4
  import os from 'node:os';
5
+ import path from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
5
7
  export default class Conch extends Command {
6
8
  static args = {
7
9
  op: Args.string({ description: 'Operation to perform (install, uninstall or dev)' }),
8
10
  };
9
11
  static description = 'Install or uninstall conchs to create a Docker image';
10
- static examples = [
11
- '<%= config.bin %> <%= command.id %>',
12
- ];
12
+ static examples = ['<%= config.bin %> <%= command.id %>'];
13
13
  static flags = {
14
- branch: Flags.string({ char: 'b', default: "develop", description: 'Branch to install from' }),
15
- container: Flags.string({ char: 'c', default: "dhti-frontend-1", description: 'Name of the container to copy the conch to while in dev mode' }),
16
- dev: Flags.string({ char: 'd', default: "none", description: 'Dev folder to install' }),
17
- git: Flags.string({ char: 'g', default: "none", description: 'Github repository to install' }),
18
- image: Flags.string({ char: 'i', default: "openmrs/openmrs-reference-application-3-frontend:3.0.0-beta.17", description: 'Base image to use for the conch' }),
14
+ branch: Flags.string({ char: 'b', default: 'develop', description: 'Branch to install from' }),
15
+ container: Flags.string({
16
+ char: 'c',
17
+ default: 'dhti-frontend-1',
18
+ description: 'Name of the container to copy the conch to while in dev mode',
19
+ }),
20
+ dev: Flags.string({ char: 'd', default: 'none', description: 'Dev folder to install' }),
21
+ git: Flags.string({ char: 'g', default: 'none', description: 'Github repository to install' }),
22
+ image: Flags.string({
23
+ char: 'i',
24
+ default: 'openmrs/openmrs-reference-application-3-frontend:3.0.0-beta.17',
25
+ description: 'Base image to use for the conch',
26
+ }),
19
27
  name: Flags.string({ char: 'n', description: 'Name of the elixir' }),
20
- repoVersion: Flags.string({ char: 'v', default: "1.0.0", description: 'Version of the conch' }),
21
- workdir: Flags.string({ char: 'w', default: `${os.homedir()}/dhti`, description: 'Working directory to install the conch' }),
28
+ repoVersion: Flags.string({ char: 'v', default: '1.0.0', description: 'Version of the conch' }),
29
+ workdir: Flags.string({
30
+ char: 'w',
31
+ default: `${os.homedir()}/dhti`,
32
+ description: 'Working directory to install the conch',
33
+ }),
22
34
  };
23
35
  async run() {
24
36
  const { args, flags } = await this.parse(Conch);
37
+ // Resolve resources directory for both dev (src) and packaged (dist)
38
+ const __filename = fileURLToPath(import.meta.url);
39
+ const __dirname = path.dirname(__filename);
40
+ const RESOURCES_DIR = path.resolve(__dirname, '../resources');
25
41
  if (!flags.name) {
26
- console.log("Please provide a name for the conch");
42
+ console.log('Please provide a name for the conch');
27
43
  this.exit(1);
28
44
  }
29
45
  // if arg is dev then copy to docker as below
@@ -50,14 +66,14 @@ export default class Conch extends Command {
50
66
  });
51
67
  }
52
68
  catch (error) {
53
- console.log("Error copying conch to container", error);
69
+ console.log('Error copying conch to container', error);
54
70
  }
55
71
  }
56
72
  // Create a directory to install the elixir
57
73
  if (!fs.existsSync(`${flags.workdir}/conch`)) {
58
74
  fs.mkdirSync(`${flags.workdir}/conch`);
59
75
  }
60
- fs.cpSync('src/resources/spa', `${flags.workdir}/conch`, { recursive: true });
76
+ fs.cpSync(path.join(RESOURCES_DIR, 'spa'), `${flags.workdir}/conch`, { recursive: true });
61
77
  // Rewrite files
62
78
  const rewrite = () => {
63
79
  flags.name = flags.name ?? 'openmrs-esm-genai';
@@ -77,16 +93,19 @@ export default class Conch extends Command {
77
93
  fs.writeFileSync(`${flags.workdir}/conch/def/spa-assemble-config.json`, JSON.stringify(spaAssembleConfig, null, 2));
78
94
  // Read and process Dockerfile
79
95
  let dockerfile = fs.readFileSync(`${flags.workdir}/conch/Dockerfile`, 'utf8');
80
- dockerfile = dockerfile.replaceAll('conch', flags.name).replaceAll('version', flags.repoVersion).replaceAll('server-image', flags.image);
96
+ dockerfile = dockerfile
97
+ .replaceAll('conch', flags.name)
98
+ .replaceAll('version', flags.repoVersion)
99
+ .replaceAll('server-image', flags.image);
81
100
  fs.writeFileSync(`${flags.workdir}/conch/Dockerfile`, dockerfile);
82
101
  // Read routes.json
83
102
  const routes = JSON.parse(fs.readFileSync(`${flags.workdir}/conch/${flags.name}/src/routes.json`, 'utf8'));
84
103
  // Add to routes.registry.json
85
104
  const registry = JSON.parse(fs.readFileSync(`${flags.workdir}/conch/def/routes.registry.json`, 'utf8'));
86
105
  if (args.op === 'install')
87
- registry[(flags.name).replace('openmrs-', '@openmrs/')] = routes;
106
+ registry[flags.name.replace('openmrs-', '@openmrs/')] = routes;
88
107
  if (args.op === 'uninstall')
89
- delete registry[(flags.name).replace('openmrs-', '@openmrs/')];
108
+ delete registry[flags.name.replace('openmrs-', '@openmrs/')];
90
109
  fs.writeFileSync(`${flags.workdir}/conch/def/routes.registry.json`, JSON.stringify(registry, null, 2));
91
110
  };
92
111
  if (flags.git !== 'none') {
@@ -3,6 +3,7 @@ import { exec } from 'node:child_process';
3
3
  import fs from 'node:fs';
4
4
  import os from 'node:os';
5
5
  import path from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
6
7
  export default class Elixir extends Command {
7
8
  static args = {
8
9
  op: Args.string({ description: 'Operation to perform (install, uninstall or dev)' }),
@@ -34,6 +35,10 @@ export default class Elixir extends Command {
34
35
  };
35
36
  async run() {
36
37
  const { args, flags } = await this.parse(Elixir);
38
+ // Resolve resources directory for both dev (src) and packaged (dist)
39
+ const __filename = fileURLToPath(import.meta.url);
40
+ const __dirname = path.dirname(__filename);
41
+ const RESOURCES_DIR = path.resolve(__dirname, '../resources');
37
42
  if (!flags.name) {
38
43
  console.log('Please provide a name for the elixir');
39
44
  this.exit(1);
@@ -69,7 +74,7 @@ export default class Elixir extends Command {
69
74
  if (!fs.existsSync(`${flags.workdir}/elixir`)) {
70
75
  fs.mkdirSync(`${flags.workdir}/elixir`);
71
76
  }
72
- fs.cpSync('src/resources/genai', `${flags.workdir}/elixir`, { recursive: true });
77
+ fs.cpSync(path.join(RESOURCES_DIR, 'genai'), `${flags.workdir}/elixir`, { recursive: true });
73
78
  // if whl is not none, copy the whl file to thee whl directory
74
79
  if (flags.whl !== 'none') {
75
80
  if (!fs.existsSync(`${flags.workdir}/elixir/whl/`)) {
@@ -440,5 +440,5 @@
440
440
  ]
441
441
  }
442
442
  },
443
- "version": "0.3.0"
443
+ "version": "0.3.1"
444
444
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dhti-cli",
3
3
  "description": "DHTI CLI",
4
- "version": "0.3.0",
4
+ "version": "0.3.1",
5
5
  "author": "Bell Eapen",
6
6
  "bin": {
7
7
  "dhti-cli": "bin/run.js"