@cloud-cli/dc 1.3.1 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud-cli/dc",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "main": "./dist/index.js",
5
5
  "description": "Run services with docker compose",
6
6
  "type": "module",
@@ -1,10 +0,0 @@
1
- name: CICD
2
- on:
3
- push:
4
-
5
- jobs:
6
- release:
7
- uses: cloud-cli/workflows/.github/workflows/npm-build-release.yml@main
8
- secrets:
9
- NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
10
- GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
package/dist/index.d.ts DELETED
@@ -1,25 +0,0 @@
1
- import { init, help } from "@cloud-cli/cli";
2
- interface CliOptions {
3
- name: string;
4
- content?: string;
5
- }
6
- declare function stop(options: CliOptions): Promise<boolean>;
7
- declare function start(options: CliOptions): Promise<boolean>;
8
- declare function update(options: CliOptions): Promise<boolean>;
9
- declare function remove(options: CliOptions): Promise<boolean>;
10
- declare function list(): Promise<string[]>;
11
- declare function show(options: CliOptions): Promise<{
12
- name: any;
13
- content: string;
14
- }>;
15
- declare const _default: {
16
- [init](): Promise<void>;
17
- [help]: () => string;
18
- start: typeof start;
19
- stop: typeof stop;
20
- update: typeof update;
21
- remove: typeof remove;
22
- show: typeof show;
23
- list: typeof list;
24
- };
25
- export default _default;
package/dist/index.js DELETED
@@ -1,112 +0,0 @@
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
- const config = getConfig("dc", { storagePath: "docker-compose" });
7
- const storagePath = join(process.cwd(), config.storagePath);
8
- const notFoundError = new Error("Service not found");
9
- const binaryAndArgs = {
10
- binary: "",
11
- args: [],
12
- };
13
- const getPath = (name) => join(storagePath, name + ".yml");
14
- const checkName = (name) => {
15
- if (!name) {
16
- throw new Error("Name is required");
17
- }
18
- // TODO sanitize file name
19
- return name;
20
- };
21
- async function stop(options) {
22
- const name = checkName(options.name);
23
- const path = getPath(name);
24
- if (!existsSync(path)) {
25
- throw notFoundError;
26
- }
27
- const out = await exec(binaryAndArgs.binary, [...binaryAndArgs.args, "-f", path, "down"].filter(Boolean));
28
- if (out.ok) {
29
- return true;
30
- }
31
- throw new Error(out.stderr);
32
- }
33
- async function start(options) {
34
- const name = checkName(options.name);
35
- const path = getPath(name);
36
- if (!existsSync(path)) {
37
- throw notFoundError;
38
- }
39
- const out = await exec(binaryAndArgs.binary, [...binaryAndArgs.args, "-f", path, "up", "-d"].filter(Boolean));
40
- if (out.ok) {
41
- return true;
42
- }
43
- throw new Error(out.stderr);
44
- }
45
- async function update(options) {
46
- const name = checkName(options.name);
47
- const { content } = options;
48
- if (!content) {
49
- throw new Error("docker compose content is required");
50
- }
51
- const path = getPath(name);
52
- await writeFile(path, String(options.content));
53
- return true;
54
- }
55
- async function remove(options) {
56
- const name = checkName(options.name);
57
- const path = getPath(name);
58
- if (existsSync(path)) {
59
- await rm(path);
60
- }
61
- return true;
62
- }
63
- async function list() {
64
- const files = await readdir(storagePath, { withFileTypes: true });
65
- return files.filter((f) => f.isFile()).map((f) => f.name.replace(".yml", ""));
66
- }
67
- async function show(options) {
68
- const name = checkName(options.name);
69
- const path = getPath(name);
70
- if (existsSync(path)) {
71
- const content = await readFile(path, "utf-8");
72
- return { name, content };
73
- }
74
- throw notFoundError;
75
- }
76
- export default {
77
- async [init]() {
78
- mkdirSync(storagePath, { recursive: true });
79
- const docker = await exec("docker", ["compose"]);
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");
92
- },
93
- [help]: () => `Manage Docker Compose services
94
-
95
- Available commands:
96
- dc.start --name <name> - Start a Compose service
97
- dc.stop --name <name> - Stop a Compose service
98
- dc.update --name <name> --content <yaml> - Create or update a Compose file
99
- dc.remove --name <name> - Remove a Compose file
100
- dc.show --name <name> - Show a Compose file
101
- dc.list - List Compose files/services
102
-
103
- Options:
104
- name - Service/Compose file name
105
- content - Docker Compose YAML content (for update command)`,
106
- start,
107
- stop,
108
- update,
109
- remove,
110
- show,
111
- list,
112
- };