@cloud-cli/dc 1.0.0 → 1.1.1
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 +5 -0
- package/dist/index.js +16 -5
- package/package.json +1 -1
- package/src/index.ts +19 -5
package/dist/index.d.ts
CHANGED
|
@@ -8,12 +8,17 @@ declare function start(options: CliOptions): Promise<boolean>;
|
|
|
8
8
|
declare function update(options: CliOptions): Promise<boolean>;
|
|
9
9
|
declare function remove(options: CliOptions): Promise<boolean>;
|
|
10
10
|
declare function list(): Promise<string[]>;
|
|
11
|
+
declare function show(options: CliOptions): Promise<{
|
|
12
|
+
name: any;
|
|
13
|
+
content: string;
|
|
14
|
+
}>;
|
|
11
15
|
declare const _default: {
|
|
12
16
|
[init](): void;
|
|
13
17
|
start: typeof start;
|
|
14
18
|
stop: typeof stop;
|
|
15
19
|
update: typeof update;
|
|
16
20
|
remove: typeof remove;
|
|
21
|
+
show: typeof show;
|
|
17
22
|
list: typeof list;
|
|
18
23
|
};
|
|
19
24
|
export default _default;
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { getConfig, init } from "@cloud-cli/cli";
|
|
2
2
|
import { exec } from "@cloud-cli/exec";
|
|
3
3
|
import { existsSync, mkdirSync } from "node:fs";
|
|
4
|
-
import { readdir, rm, writeFile } from "node:fs/promises";
|
|
4
|
+
import { readFile, readdir, rm, writeFile } from "node:fs/promises";
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
const config = getConfig("dc", { storagePath: "docker-compose" });
|
|
7
7
|
const storagePath = join(process.cwd(), config.storagePath);
|
|
8
|
+
const notFoundError = new Error("Service not found");
|
|
8
9
|
const getPath = (name) => join(storagePath, name + ".yml");
|
|
9
10
|
const checkName = (name) => {
|
|
10
11
|
if (!name) {
|
|
@@ -17,9 +18,9 @@ async function stop(options) {
|
|
|
17
18
|
const name = checkName(options.name);
|
|
18
19
|
const path = getPath(name);
|
|
19
20
|
if (!existsSync(path)) {
|
|
20
|
-
throw
|
|
21
|
+
throw notFoundError;
|
|
21
22
|
}
|
|
22
|
-
const out = await exec("docker compose",
|
|
23
|
+
const out = await exec("docker", ["compose", "down", "-f", path]);
|
|
23
24
|
if (out.ok) {
|
|
24
25
|
return true;
|
|
25
26
|
}
|
|
@@ -29,9 +30,9 @@ async function start(options) {
|
|
|
29
30
|
const name = checkName(options.name);
|
|
30
31
|
const path = getPath(name);
|
|
31
32
|
if (!existsSync(path)) {
|
|
32
|
-
throw
|
|
33
|
+
throw notFoundError;
|
|
33
34
|
}
|
|
34
|
-
const out = await exec("docker compose",
|
|
35
|
+
const out = await exec("docker", ["compose", "up", "-f", path]);
|
|
35
36
|
if (out.ok) {
|
|
36
37
|
return true;
|
|
37
38
|
}
|
|
@@ -59,6 +60,15 @@ async function list() {
|
|
|
59
60
|
const files = await readdir(storagePath, { withFileTypes: true });
|
|
60
61
|
return files.filter((f) => f.isFile()).map((f) => f.name.replace(".yml", ""));
|
|
61
62
|
}
|
|
63
|
+
async function show(options) {
|
|
64
|
+
const name = checkName(options.name);
|
|
65
|
+
const path = getPath(name);
|
|
66
|
+
if (existsSync(path)) {
|
|
67
|
+
const content = await readFile(path, "utf-8");
|
|
68
|
+
return { name, content };
|
|
69
|
+
}
|
|
70
|
+
throw notFoundError;
|
|
71
|
+
}
|
|
62
72
|
export default {
|
|
63
73
|
[init]() {
|
|
64
74
|
mkdirSync(storagePath, { recursive: true });
|
|
@@ -67,5 +77,6 @@ export default {
|
|
|
67
77
|
stop,
|
|
68
78
|
update,
|
|
69
79
|
remove,
|
|
80
|
+
show,
|
|
70
81
|
list,
|
|
71
82
|
};
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { getConfig, init } from "@cloud-cli/cli";
|
|
2
2
|
import { exec } from "@cloud-cli/exec";
|
|
3
3
|
import { existsSync, mkdirSync } from "node:fs";
|
|
4
|
-
import { readdir, rm, writeFile } from "node:fs/promises";
|
|
4
|
+
import { readFile, readdir, rm, writeFile } from "node:fs/promises";
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
|
|
7
7
|
const config = getConfig("dc", { storagePath: "docker-compose" });
|
|
8
8
|
const storagePath = join(process.cwd(), config.storagePath);
|
|
9
|
+
const notFoundError = new Error("Service not found");
|
|
9
10
|
|
|
10
11
|
interface CliOptions {
|
|
11
12
|
name: string;
|
|
@@ -27,10 +28,10 @@ async function stop(options: CliOptions) {
|
|
|
27
28
|
const path = getPath(name);
|
|
28
29
|
|
|
29
30
|
if (!existsSync(path)) {
|
|
30
|
-
throw
|
|
31
|
+
throw notFoundError;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
const out = await exec("docker compose",
|
|
34
|
+
const out = await exec("docker", ["compose", "down", "-f", path]);
|
|
34
35
|
|
|
35
36
|
if (out.ok) {
|
|
36
37
|
return true;
|
|
@@ -44,10 +45,10 @@ async function start(options: CliOptions) {
|
|
|
44
45
|
const path = getPath(name);
|
|
45
46
|
|
|
46
47
|
if (!existsSync(path)) {
|
|
47
|
-
throw
|
|
48
|
+
throw notFoundError;
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
const out = await exec("docker compose",
|
|
51
|
+
const out = await exec("docker", ["compose", "up", "-f", path]);
|
|
51
52
|
|
|
52
53
|
if (out.ok) {
|
|
53
54
|
return true;
|
|
@@ -85,6 +86,18 @@ async function list() {
|
|
|
85
86
|
return files.filter((f) => f.isFile()).map((f) => f.name.replace(".yml", ""));
|
|
86
87
|
}
|
|
87
88
|
|
|
89
|
+
async function show(options: CliOptions) {
|
|
90
|
+
const name = checkName(options.name);
|
|
91
|
+
const path = getPath(name);
|
|
92
|
+
|
|
93
|
+
if (existsSync(path)) {
|
|
94
|
+
const content = await readFile(path, "utf-8");
|
|
95
|
+
return { name, content };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
throw notFoundError;
|
|
99
|
+
}
|
|
100
|
+
|
|
88
101
|
export default {
|
|
89
102
|
[init]() {
|
|
90
103
|
mkdirSync(storagePath, { recursive: true });
|
|
@@ -93,5 +106,6 @@ export default {
|
|
|
93
106
|
stop,
|
|
94
107
|
update,
|
|
95
108
|
remove,
|
|
109
|
+
show,
|
|
96
110
|
list,
|
|
97
111
|
};
|