@cloud-cli/dx 2.6.0 → 2.7.0

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/index.d.ts CHANGED
@@ -1,10 +1,12 @@
1
1
  import { getLogs, refreshContainer, restartContainer, startAll, updateAll, startContainer, stopAll, stopContainer, renameContainer, runContainer } from "./containers.js";
2
2
  import { prune, pull } from "./images.js";
3
- import { addContainer, getContainer, listContainers, removeContainer, updateContainer } from "./store.js";
3
+ import { addContainer, clone, getContainer, listContainers, removeContainer, updateContainer } from "./store.js";
4
+ import { help } from "@cloud-cli/cli";
4
5
  export type { Config } from "./types.js";
5
6
  declare function ps(options?: {
6
7
  status?: boolean;
7
8
  }): Promise<string[]> | Promise<import("./types.js").NameAndStatus[]>;
9
+ export { clone };
8
10
  declare const _default: {
9
11
  pull: typeof pull;
10
12
  prune: typeof prune;
@@ -24,5 +26,7 @@ declare const _default: {
24
26
  restart: typeof restartContainer;
25
27
  ps: typeof ps;
26
28
  logs: typeof getLogs;
29
+ clone: typeof clone;
30
+ [help]: () => string;
27
31
  };
28
32
  export default _default;
package/dist/index.js CHANGED
@@ -1,12 +1,42 @@
1
1
  import { getAllContainers, getLogs, getRunningContainers, refreshContainer, restartContainer, startAll, updateAll, startContainer, stopAll, stopContainer, renameContainer, runContainer, } from "./containers.js";
2
2
  import { prune, pull } from "./images.js";
3
- import { addContainer, getContainer, listContainers, removeContainer, updateContainer, } from "./store.js";
3
+ import { addContainer, clone, getContainer, listContainers, removeContainer, updateContainer } from "./store.js";
4
+ import { help } from "@cloud-cli/cli";
4
5
  function ps(options = {}) {
5
6
  if (options.status) {
6
7
  return getAllContainers();
7
8
  }
8
9
  return getRunningContainers();
9
10
  }
11
+ const helpFunction = () => {
12
+ const commands = {
13
+ pull: "--image <image> - Pull a Docker image",
14
+ prune: "- Remove unused Docker images",
15
+ add: "--name <name> --image <image> [--domain <domain>] [--port <port>] [--volumes <mounts>] [--worker] [--startArgs <json>] - Add a container entry",
16
+ clone: "--name <name> --newName <new-name> - Clone a container entry",
17
+ remove: "--name <name> - Remove a container entry",
18
+ rename: "--name <name> --newName <new-name> - Rename a container entry",
19
+ get: "--name <name> - Get a container entry",
20
+ list: "[--name <name>] [--image <image>] [--domain <domain>] [--port <port>] [--volumes <mounts>] - List/filter entries",
21
+ refresh: "--name <name> - Pull and restart a container",
22
+ update: "--name <name> [--image <image>] [--domain <domain>] [--port <port>] [--volumes <mounts>] [--worker] [--startArgs <json>] - Update container properties",
23
+ updateAll: "[--image <image>] - Refresh all matching containers",
24
+ startAll: "[--image <image>] - Start all matching containers",
25
+ start: "--name <name> [--worker] [--startArgs <json>] - Start a stored container",
26
+ run: "--name <name> [--startArgs <json>] - Start a container in worker mode",
27
+ stop: "--name <name> - Stop a container",
28
+ stopAll: "[--image <image>] - Stop all matching containers",
29
+ restart: "--name <name> - Restart a container",
30
+ ps: "[--status] - List running containers (include stored stopped containers with status)",
31
+ logs: "--name <name> [--lines <count>] - Read container logs",
32
+ };
33
+ const lines = ["Docker container management", "", "Commands:"];
34
+ for (const [name, desc] of Object.entries(commands)) {
35
+ lines.push(` dx.${name} ${desc}`);
36
+ }
37
+ return lines.join("\n");
38
+ };
39
+ export { clone };
10
40
  export default {
11
41
  pull,
12
42
  prune,
@@ -26,4 +56,6 @@ export default {
26
56
  restart: restartContainer,
27
57
  ps: ps,
28
58
  logs: getLogs,
59
+ clone,
60
+ [help]: helpFunction,
29
61
  };
package/dist/store.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type { Container, ExtraOptions } from './types.js';
1
+ import type { Container, ExtraOptions } from "./types.js";
2
+ import { type ServerParams } from "@cloud-cli/cli";
2
3
  interface ContainerName extends ExtraOptions {
3
4
  name: string;
4
5
  }
@@ -17,5 +18,9 @@ export declare function getContainer(options: ContainerName): Container;
17
18
  export declare function updateContainer(options: Partial<ContainerUpdateOptions>): Container;
18
19
  export declare function rename(name: string, newName: string): Container;
19
20
  export declare function listContainers(options?: ContainerListOptions): Container[];
21
+ export declare function clone(options: {
22
+ name: string;
23
+ newName: string;
24
+ }, { run }: ServerParams): Promise<Container>;
20
25
  export declare function findContainer(name: string): Container;
21
26
  export {};
package/dist/store.js CHANGED
@@ -1,16 +1,18 @@
1
- import { readTargetImage, readTargetName } from './utils.js';
2
- import { getStorage } from '@cloud-cli/cli';
3
- const { get, set, has, remove, getAll } = getStorage('dx');
1
+ import { readTargetImage, readTargetName } from "./utils.js";
2
+ import { getStorage } from "@cloud-cli/cli";
3
+ const { get, set, has, remove, getAll } = getStorage("dx");
4
4
  export function addContainer(options) {
5
5
  readTargetName(options);
6
6
  readTargetImage(options);
7
7
  const { name, image } = options;
8
- if (!name)
9
- throw new Error('Name required');
10
- if (!image)
11
- throw new Error('Image required');
12
- const volumes = options.volumes ? sanitiseVolumes(options.volumes) : '';
13
- const { port = '', domain = '', worker = false, startArgs = '' } = options;
8
+ if (!name) {
9
+ throw new Error("Name required");
10
+ }
11
+ if (!image) {
12
+ throw new Error("Image required");
13
+ }
14
+ const volumes = options.volumes ? sanitiseVolumes(options.volumes) : "";
15
+ const { port = "", domain = "", worker = false, startArgs = "" } = options;
14
16
  const container = { name, image, volumes, port, domain, worker, startArgs };
15
17
  set(name, container);
16
18
  return container;
@@ -21,7 +23,7 @@ export function removeContainer(options) {
21
23
  remove(options.name);
22
24
  return true;
23
25
  }
24
- throw new Error('Container not found: ' + options.name);
26
+ throw new Error("Container not found: " + options.name);
25
27
  }
26
28
  export function getContainer(options) {
27
29
  readTargetName(options);
@@ -30,10 +32,10 @@ export function getContainer(options) {
30
32
  const optionSplitter = /,\s*/;
31
33
  export function updateContainer(options) {
32
34
  readTargetName(options);
33
- let { port, volumes, name, image, domain, startArgs, worker } = options;
35
+ const { port, volumes, name, image, domain, startArgs, worker } = options;
34
36
  const container = get(name);
35
37
  if (!container) {
36
- throw new Error('Container not found');
38
+ throw new Error("Container not found");
37
39
  }
38
40
  if (port !== undefined) {
39
41
  container.port = port;
@@ -64,7 +66,7 @@ export function rename(name, newName) {
64
66
  return container;
65
67
  }
66
68
  export function listContainers(options = {}) {
67
- const keys = ['name', 'image', 'domain', 'port', 'volumes'];
69
+ const keys = ["name", "image", "domain", "port", "volumes"];
68
70
  const list = getAll();
69
71
  const filtered = keys.reduce((list, key) => {
70
72
  if (options[key]) {
@@ -74,6 +76,26 @@ export function listContainers(options = {}) {
74
76
  }, list);
75
77
  return filtered.sort((a, b) => Number(a.name > b.name) || -1);
76
78
  }
79
+ export async function clone(options, { run }) {
80
+ const { name, newName } = options;
81
+ if (!name || !newName) {
82
+ throw new Error("Name and new name required");
83
+ }
84
+ const container = get(name);
85
+ if (!container) {
86
+ throw new Error("Container not found: " + name);
87
+ }
88
+ const vars = (await run("env.show", { name }));
89
+ for (const varItem of vars) {
90
+ await run("env.set", { name: newName, key: varItem.key, value: varItem.value });
91
+ }
92
+ const cloned = {
93
+ ...container,
94
+ name: newName,
95
+ };
96
+ set(newName, cloned);
97
+ return cloned;
98
+ }
77
99
  export function findContainer(name) {
78
100
  return get(name);
79
101
  }
@@ -83,5 +105,5 @@ function sanitiseVolumes(volumes) {
83
105
  .split(optionSplitter)
84
106
  .map((s) => s.trim())
85
107
  .filter((s) => volumeTester.test(s))
86
- .join(',');
108
+ .join(",");
87
109
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud-cli/dx",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "description": "Docker container management",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -35,9 +35,9 @@
35
35
  "get-port": "^7.1.0"
36
36
  },
37
37
  "peerDependencies": {
38
- "@cloud-cli/cli": "^2.0.0",
39
- "@cloud-cli/env": "^1.0.0",
38
+ "@cloud-cli/cli": "^2.2.0",
40
39
  "@cloud-cli/dns": "^2.0.0",
40
+ "@cloud-cli/env": "^1.0.0",
41
41
  "@cloud-cli/px": "^4.0.0"
42
42
  }
43
43
  }