@cloud-cli/dx 2.5.1 → 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.
@@ -4,10 +4,12 @@ export declare function getRunningContainers(): Promise<string[]>;
4
4
  export declare function getAllContainers(): Promise<NameAndStatus[]>;
5
5
  export declare function getLogs(options: GetLogsOptions): Promise<string>;
6
6
  export declare function renameContainer(options: RenameOptions): Container;
7
- export declare function startAll(_: any, cli: any): Promise<boolean>;
8
- export declare function updateAll(options: {
9
- image: string;
10
- }, cli: any): Promise<any[]>;
7
+ export interface AllOptions {
8
+ image?: string;
9
+ }
10
+ export declare function updateAll({ image }: AllOptions, cli: any): Promise<any[]>;
11
+ export declare function startAll({ image }: AllOptions, cli: any): Promise<boolean>;
12
+ export declare function stopAll({ image }: AllOptions, cli: any): Promise<any[]>;
11
13
  export declare function refreshContainer(options: ContainerName, { run }: ServerParams): Promise<void>;
12
14
  export declare function restartContainer(options: ContainerName, { run }: ServerParams): Promise<boolean>;
13
15
  export interface StartOptions {
@@ -44,8 +44,20 @@ export function renameContainer(options) {
44
44
  }
45
45
  return rename(name, newName);
46
46
  }
47
- export async function startAll(_, cli) {
48
- const list = listContainers();
47
+ export async function updateAll({ image } = {}, cli) {
48
+ const list = listContainers({ image });
49
+ const affected = [];
50
+ for (const app of list) {
51
+ try {
52
+ await refreshContainer({ name: app.name }, cli);
53
+ affected.push(app.name);
54
+ }
55
+ catch { }
56
+ }
57
+ return affected;
58
+ }
59
+ export async function startAll({ image } = {}, cli) {
60
+ const list = listContainers({ image });
49
61
  const running = (await getRunningContainers());
50
62
  const notRunning = list.filter(({ name }) => !running.includes(name));
51
63
  for (const app of notRunning) {
@@ -56,14 +68,14 @@ export async function startAll(_, cli) {
56
68
  }
57
69
  return true;
58
70
  }
59
- export async function updateAll(options, cli) {
60
- const list = listContainers();
71
+ export async function stopAll({ image } = {}, cli) {
72
+ const list = listContainers({ image });
73
+ const running = await getRunningContainers();
74
+ const runningContainers = list.filter(({ name }) => running.includes(name));
61
75
  const affected = [];
62
- for (const app of list) {
63
- if (app.image !== options.image)
64
- continue;
76
+ for (const app of runningContainers) {
65
77
  try {
66
- await refreshContainer({ name: app.name }, cli);
78
+ await stopContainer({ name: app.name }, cli);
67
79
  affected.push(app.name);
68
80
  }
69
81
  catch { }
package/dist/index.d.ts CHANGED
@@ -1,10 +1,12 @@
1
- import { getLogs, refreshContainer, restartContainer, startAll, updateAll, startContainer, stopContainer, renameContainer, runContainer } from "./containers.js";
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;
@@ -15,13 +17,16 @@ declare const _default: {
15
17
  list: typeof listContainers;
16
18
  refresh: typeof refreshContainer;
17
19
  update: typeof updateContainer;
18
- startAll: typeof startAll;
19
20
  updateAll: typeof updateAll;
21
+ startAll: typeof startAll;
20
22
  start: typeof startContainer;
21
23
  run: typeof runContainer;
24
+ stopAll: typeof stopAll;
22
25
  stop: typeof stopContainer;
23
26
  restart: typeof restartContainer;
24
27
  ps: typeof ps;
25
28
  logs: typeof getLogs;
29
+ clone: typeof clone;
30
+ [help]: () => string;
26
31
  };
27
32
  export default _default;
package/dist/index.js CHANGED
@@ -1,12 +1,42 @@
1
- import { getAllContainers, getLogs, getRunningContainers, refreshContainer, restartContainer, startAll, updateAll, startContainer, stopContainer, renameContainer, runContainer, } from "./containers.js";
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,
@@ -17,12 +47,15 @@ export default {
17
47
  list: listContainers,
18
48
  refresh: refreshContainer,
19
49
  update: updateContainer,
20
- startAll,
21
50
  updateAll,
51
+ startAll,
22
52
  start: startContainer,
23
53
  run: runContainer,
54
+ stopAll,
24
55
  stop: stopContainer,
25
56
  restart: restartContainer,
26
57
  ps: ps,
27
58
  logs: getLogs,
59
+ clone,
60
+ [help]: helpFunction,
28
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.5.1",
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
  }