@cloud-cli/dc 1.1.1 → 1.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.
package/dist/index.d.ts CHANGED
@@ -13,7 +13,7 @@ declare function show(options: CliOptions): Promise<{
13
13
  content: string;
14
14
  }>;
15
15
  declare const _default: {
16
- [init](): void;
16
+ [init](): Promise<void>;
17
17
  start: typeof start;
18
18
  stop: typeof stop;
19
19
  update: typeof update;
package/dist/index.js CHANGED
@@ -6,6 +6,10 @@ import { join } from "node:path";
6
6
  const config = getConfig("dc", { storagePath: "docker-compose" });
7
7
  const storagePath = join(process.cwd(), config.storagePath);
8
8
  const notFoundError = new Error("Service not found");
9
+ const binaryAndArgs = {
10
+ binary: "",
11
+ args: [],
12
+ };
9
13
  const getPath = (name) => join(storagePath, name + ".yml");
10
14
  const checkName = (name) => {
11
15
  if (!name) {
@@ -20,7 +24,7 @@ async function stop(options) {
20
24
  if (!existsSync(path)) {
21
25
  throw notFoundError;
22
26
  }
23
- const out = await exec("docker", ["compose", "down", "-f", path]);
27
+ const out = await exec(binaryAndArgs.binary, [...binaryAndArgs.args, "-f", path, "down"].filter(Boolean));
24
28
  if (out.ok) {
25
29
  return true;
26
30
  }
@@ -32,7 +36,7 @@ async function start(options) {
32
36
  if (!existsSync(path)) {
33
37
  throw notFoundError;
34
38
  }
35
- const out = await exec("docker", ["compose", "up", "-f", path]);
39
+ const out = await exec(binaryAndArgs.binary, [...binaryAndArgs.args, "-f", path, "up", "-d"].filter(Boolean));
36
40
  if (out.ok) {
37
41
  return true;
38
42
  }
@@ -70,8 +74,21 @@ async function show(options) {
70
74
  throw notFoundError;
71
75
  }
72
76
  export default {
73
- [init]() {
77
+ async [init]() {
74
78
  mkdirSync(storagePath, { recursive: true });
79
+ const docker = await exec("docker", ["compose", "--help"]);
80
+ if (docker.ok) {
81
+ binaryAndArgs.binary = "docker";
82
+ binaryAndArgs.args.push("compose");
83
+ return;
84
+ }
85
+ const dockerCompose = await exec("docker-compose", ["--help"]);
86
+ if (dockerCompose.ok) {
87
+ binaryAndArgs.binary = "docker-compose";
88
+ return;
89
+ }
90
+ binaryAndArgs.binary = "exit";
91
+ binaryAndArgs.args.push("1");
75
92
  },
76
93
  start,
77
94
  stop,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud-cli/dc",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "main": "./dist/index.js",
5
5
  "description": "Run services with docker compose",
6
6
  "type": "module",
package/src/index.ts CHANGED
@@ -7,6 +7,10 @@ import { join } from "node:path";
7
7
  const config = getConfig("dc", { storagePath: "docker-compose" });
8
8
  const storagePath = join(process.cwd(), config.storagePath);
9
9
  const notFoundError = new Error("Service not found");
10
+ const binaryAndArgs = {
11
+ binary: "",
12
+ args: [],
13
+ };
10
14
 
11
15
  interface CliOptions {
12
16
  name: string;
@@ -31,7 +35,10 @@ async function stop(options: CliOptions) {
31
35
  throw notFoundError;
32
36
  }
33
37
 
34
- const out = await exec("docker", ["compose", "down", "-f", path]);
38
+ const out = await exec(
39
+ binaryAndArgs.binary,
40
+ [...binaryAndArgs.args, "-f", path, "down"].filter(Boolean)
41
+ );
35
42
 
36
43
  if (out.ok) {
37
44
  return true;
@@ -48,7 +55,10 @@ async function start(options: CliOptions) {
48
55
  throw notFoundError;
49
56
  }
50
57
 
51
- const out = await exec("docker", ["compose", "up", "-f", path]);
58
+ const out = await exec(
59
+ binaryAndArgs.binary,
60
+ [...binaryAndArgs.args, "-f", path, "up", "-d"].filter(Boolean)
61
+ );
52
62
 
53
63
  if (out.ok) {
54
64
  return true;
@@ -99,8 +109,24 @@ async function show(options: CliOptions) {
99
109
  }
100
110
 
101
111
  export default {
102
- [init]() {
112
+ async [init]() {
103
113
  mkdirSync(storagePath, { recursive: true });
114
+
115
+ const docker = await exec("docker", ["compose", "--help"]);
116
+ if (docker.ok) {
117
+ binaryAndArgs.binary = "docker";
118
+ binaryAndArgs.args.push("compose");
119
+ return;
120
+ }
121
+
122
+ const dockerCompose = await exec("docker-compose", ["--help"]);
123
+ if (dockerCompose.ok) {
124
+ binaryAndArgs.binary = "docker-compose";
125
+ return;
126
+ }
127
+
128
+ binaryAndArgs.binary = "exit";
129
+ binaryAndArgs.args.push("1");
104
130
  },
105
131
  start,
106
132
  stop,