@cloud-cli/dx 2.1.1 → 2.1.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.
@@ -2,6 +2,7 @@ import { exec } from '@cloud-cli/exec';
2
2
  import { getConfig } from '@cloud-cli/cli';
3
3
  import { findContainer, listContainers } from './store.js';
4
4
  import { addExecFlag, getEnvVars, getListFromString, readTargetName } from './utils.js';
5
+ import getPort from 'get-port';
5
6
  export async function getRunningContainers() {
6
7
  const ps = await exec('docker', ['ps', '--format', '{{.Names}}']);
7
8
  if (!ps.ok) {
@@ -67,11 +68,16 @@ export async function startContainer(options, { run }) {
67
68
  if (!name) {
68
69
  throw new Error('Name is required');
69
70
  }
71
+ const container = findContainer(name);
72
+ if (!container) {
73
+ throw new Error('Container not found: ' + name);
74
+ }
70
75
  const vars = (await run('env.show', { name }));
76
+ const port = String(container.port || (await getPort()));
77
+ vars.push({ key: 'PORT', value: port });
71
78
  const { env, envKeys } = await getEnvVars(vars);
72
- const container = findContainer(name);
73
- const volumes = addExecFlag(container.volumes, 'v');
74
- const ports = ['-p' + env.PORT + ':' + (container.port || env.PORT)];
79
+ const volumes = addExecFlag(container.volumes.split(','), 'v');
80
+ const ports = addExecFlag([`${port}:${port}`], 'p');
75
81
  if (container.domain) {
76
82
  const [domain] = container.domain.split('/');
77
83
  await run('px.update', { domain, target: 'http://localhost:' + env.PORT });
@@ -95,7 +101,7 @@ export async function startContainer(options, { run }) {
95
101
  ...extraArgs,
96
102
  ...volumes,
97
103
  ...ports,
98
- ...envKeys.map((e) => '-e' + e),
104
+ ...addExecFlag(envKeys, 'e'),
99
105
  container.image,
100
106
  ];
101
107
  const output = await exec('docker', execArgs.filter(Boolean), { env });
package/dist/utils.d.ts CHANGED
@@ -10,6 +10,6 @@ export declare function getEnvVars(vars: EnvList): Promise<{
10
10
  envKeys: string[];
11
11
  }>;
12
12
  export declare function getListFromString(string: string): string[];
13
- export declare function addExecFlag(string: string, flag: string): string[];
13
+ export declare function addExecFlag(list: string[], flag: string): string[];
14
14
  export declare function readTargetName(args: any): void;
15
15
  export declare function readTargetImage(args: any): void;
package/dist/utils.js CHANGED
@@ -1,9 +1,7 @@
1
- import getPort from 'get-port';
2
1
  export async function getEnvVars(vars) {
3
- const port = await getPort();
4
2
  const envKeys = [];
5
3
  const env = { ...process.env };
6
- vars.concat({ key: 'PORT', value: String(port) }).forEach(({ key, value }) => {
4
+ vars.forEach(({ key, value }) => {
7
5
  envKeys.push(key);
8
6
  env[key] = String(value);
9
7
  });
@@ -12,9 +10,8 @@ export async function getEnvVars(vars) {
12
10
  export function getListFromString(string) {
13
11
  return String(string).trim().split('\n').filter(Boolean);
14
12
  }
15
- export function addExecFlag(string, flag) {
16
- return string
17
- .split(',')
13
+ export function addExecFlag(list, flag) {
14
+ return list
18
15
  .filter(Boolean)
19
16
  .map((p) => `-${flag}${p}`);
20
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud-cli/dx",
3
- "version": "2.1.1",
3
+ "version": "2.1.3",
4
4
  "description": "Docker container management",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -19,6 +19,7 @@
19
19
  "@cloud-cli/prettier-config": "^1.0.0",
20
20
  "@cloud-cli/typescript-config": "^1.0.1",
21
21
  "@types/node": "^20.12.8",
22
+ "@vitest/coverage-v8": "^1.6.0",
22
23
  "typescript": "^5.4.5",
23
24
  "vitest": "^1.6.0"
24
25
  },
@@ -30,8 +31,10 @@
30
31
  "access": "public"
31
32
  },
32
33
  "dependencies": {
33
- "@cloud-cli/cli": "^1.9.0",
34
34
  "@cloud-cli/exec": "^1.0.4",
35
35
  "get-port": "^7.1.0"
36
+ },
37
+ "peerDependencies": {
38
+ "@cloud-cli/cli": "^2.0.0"
36
39
  }
37
40
  }