@cloud-cli/dc 1.3.0 → 1.3.2
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/package.json +2 -2
- package/src/index.ts +28 -28
- package/.github/workflows/cicd.yml +0 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloud-cli/dc",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"description": "Run services with docker compose",
|
|
6
6
|
"type": "module",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"@cloud-cli/exec": "latest"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@cloud-cli/cli": "
|
|
28
|
+
"@cloud-cli/cli": "^2.2.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@cloud-cli/prettier-config": "^1.0.0",
|
package/src/index.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { getConfig, init, help } from
|
|
2
|
-
import { exec } from
|
|
3
|
-
import { existsSync, mkdirSync } from
|
|
4
|
-
import { readFile, readdir, rm, writeFile } from
|
|
5
|
-
import { join } from
|
|
1
|
+
import { getConfig, init, help } from "@cloud-cli/cli";
|
|
2
|
+
import { exec } from "@cloud-cli/exec";
|
|
3
|
+
import { existsSync, mkdirSync } from "node:fs";
|
|
4
|
+
import { readFile, readdir, rm, writeFile } from "node:fs/promises";
|
|
5
|
+
import { join } from "node:path";
|
|
6
6
|
|
|
7
|
-
const config = getConfig(
|
|
7
|
+
const config = getConfig("dc", { storagePath: "docker-compose" });
|
|
8
8
|
const storagePath = join(process.cwd(), config.storagePath);
|
|
9
|
-
const notFoundError = new Error(
|
|
9
|
+
const notFoundError = new Error("Service not found");
|
|
10
10
|
const binaryAndArgs = {
|
|
11
|
-
binary:
|
|
11
|
+
binary: "",
|
|
12
12
|
args: [],
|
|
13
13
|
};
|
|
14
14
|
|
|
@@ -17,10 +17,10 @@ interface CliOptions {
|
|
|
17
17
|
content?: string;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
const getPath = (name) => join(storagePath, name +
|
|
20
|
+
const getPath = (name) => join(storagePath, name + ".yml");
|
|
21
21
|
const checkName = (name) => {
|
|
22
22
|
if (!name) {
|
|
23
|
-
throw new Error(
|
|
23
|
+
throw new Error("Name is required");
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
// TODO sanitize file name
|
|
@@ -35,7 +35,7 @@ async function stop(options: CliOptions) {
|
|
|
35
35
|
throw notFoundError;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
const out = await exec(binaryAndArgs.binary, [...binaryAndArgs.args,
|
|
38
|
+
const out = await exec(binaryAndArgs.binary, [...binaryAndArgs.args, "-f", path, "down"].filter(Boolean));
|
|
39
39
|
|
|
40
40
|
if (out.ok) {
|
|
41
41
|
return true;
|
|
@@ -52,7 +52,7 @@ async function start(options: CliOptions) {
|
|
|
52
52
|
throw notFoundError;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
const out = await exec(binaryAndArgs.binary, [...binaryAndArgs.args,
|
|
55
|
+
const out = await exec(binaryAndArgs.binary, [...binaryAndArgs.args, "-f", path, "up", "-d"].filter(Boolean));
|
|
56
56
|
|
|
57
57
|
if (out.ok) {
|
|
58
58
|
return true;
|
|
@@ -66,7 +66,7 @@ async function update(options: CliOptions) {
|
|
|
66
66
|
const { content } = options;
|
|
67
67
|
|
|
68
68
|
if (!content) {
|
|
69
|
-
throw new Error(
|
|
69
|
+
throw new Error("docker compose content is required");
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
const path = getPath(name);
|
|
@@ -87,7 +87,7 @@ async function remove(options: CliOptions) {
|
|
|
87
87
|
|
|
88
88
|
async function list() {
|
|
89
89
|
const files = await readdir(storagePath, { withFileTypes: true });
|
|
90
|
-
return files.filter((f) => f.isFile()).map((f) => f.name.replace(
|
|
90
|
+
return files.filter((f) => f.isFile()).map((f) => f.name.replace(".yml", ""));
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
async function show(options: CliOptions) {
|
|
@@ -95,7 +95,7 @@ async function show(options: CliOptions) {
|
|
|
95
95
|
const path = getPath(name);
|
|
96
96
|
|
|
97
97
|
if (existsSync(path)) {
|
|
98
|
-
const content = await readFile(path,
|
|
98
|
+
const content = await readFile(path, "utf-8");
|
|
99
99
|
return { name, content };
|
|
100
100
|
}
|
|
101
101
|
|
|
@@ -106,31 +106,31 @@ export default {
|
|
|
106
106
|
async [init]() {
|
|
107
107
|
mkdirSync(storagePath, { recursive: true });
|
|
108
108
|
|
|
109
|
-
const docker = await exec(
|
|
109
|
+
const docker = await exec("docker", ["compose"]);
|
|
110
110
|
if (docker.ok) {
|
|
111
|
-
binaryAndArgs.binary =
|
|
112
|
-
binaryAndArgs.args.push(
|
|
111
|
+
binaryAndArgs.binary = "docker";
|
|
112
|
+
binaryAndArgs.args.push("compose");
|
|
113
113
|
return;
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
const dockerCompose = await exec(
|
|
116
|
+
const dockerCompose = await exec("docker-compose", ["--help"]);
|
|
117
117
|
if (dockerCompose.ok) {
|
|
118
|
-
binaryAndArgs.binary =
|
|
118
|
+
binaryAndArgs.binary = "docker-compose";
|
|
119
119
|
return;
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
binaryAndArgs.binary =
|
|
123
|
-
binaryAndArgs.args.push(
|
|
122
|
+
binaryAndArgs.binary = "exit";
|
|
123
|
+
binaryAndArgs.args.push("1");
|
|
124
124
|
},
|
|
125
125
|
[help]: () => `Manage Docker Compose services
|
|
126
126
|
|
|
127
127
|
Available commands:
|
|
128
|
-
start - Start
|
|
129
|
-
stop - Stop
|
|
130
|
-
update -
|
|
131
|
-
remove - Remove a Compose file
|
|
132
|
-
show - Show
|
|
133
|
-
list - List Compose files/services
|
|
128
|
+
dc.start --name <name> - Start a Compose service
|
|
129
|
+
dc.stop --name <name> - Stop a Compose service
|
|
130
|
+
dc.update --name <name> --content <yaml> - Create or update a Compose file
|
|
131
|
+
dc.remove --name <name> - Remove a Compose file
|
|
132
|
+
dc.show --name <name> - Show a Compose file
|
|
133
|
+
dc.list - List Compose files/services
|
|
134
134
|
|
|
135
135
|
Options:
|
|
136
136
|
name - Service/Compose file name
|