@enspirit/emb 0.8.0 → 0.8.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/README.md +1 -1
- package/dist/src/cli/hooks/not-found.d.ts +3 -0
- package/dist/src/cli/hooks/not-found.js +4 -0
- package/dist/src/docker/compose/client.d.ts +2 -1
- package/dist/src/docker/compose/client.js +18 -11
- package/dist/src/monorepo/operations/tasks/RunTasksOperation.js +9 -4
- package/oclif.manifest.json +1 -1
- package/package.json +3 -4
package/README.md
CHANGED
|
@@ -16,9 +16,10 @@ export type GetContainerOptions = {
|
|
|
16
16
|
export declare const DefaultGetContainerOptions: GetContainerOptions;
|
|
17
17
|
export declare class DockerComposeClient {
|
|
18
18
|
protected monorepo: Monorepo;
|
|
19
|
-
protected
|
|
19
|
+
protected services?: ComposeServices;
|
|
20
20
|
constructor(monorepo: Monorepo);
|
|
21
21
|
init(): Promise<void>;
|
|
22
|
+
isService(component: string): boolean | undefined;
|
|
22
23
|
getContainer(serviceName: string, options?: Partial<GetContainerOptions>): Promise<string>;
|
|
23
24
|
private loadContainers;
|
|
24
25
|
}
|
|
@@ -5,17 +5,20 @@ export const DefaultGetContainerOptions = {
|
|
|
5
5
|
};
|
|
6
6
|
export class DockerComposeClient {
|
|
7
7
|
monorepo;
|
|
8
|
-
|
|
8
|
+
services;
|
|
9
9
|
constructor(monorepo) {
|
|
10
10
|
this.monorepo = monorepo;
|
|
11
11
|
}
|
|
12
12
|
async init() {
|
|
13
13
|
await this.loadContainers();
|
|
14
14
|
}
|
|
15
|
+
isService(component) {
|
|
16
|
+
return this.services?.has(component);
|
|
17
|
+
}
|
|
15
18
|
async getContainer(serviceName, options = DefaultGetContainerOptions) {
|
|
16
19
|
const getOptions = { ...DefaultGetContainerOptions, ...options };
|
|
17
20
|
await this.loadContainers();
|
|
18
|
-
const service = this.
|
|
21
|
+
const service = this.services?.get(serviceName);
|
|
19
22
|
if (!service) {
|
|
20
23
|
throw new Error(`No compose service found with name ${serviceName}`);
|
|
21
24
|
}
|
|
@@ -31,25 +34,29 @@ export class DockerComposeClient {
|
|
|
31
34
|
return containers[0].ID;
|
|
32
35
|
}
|
|
33
36
|
async loadContainers(force = false) {
|
|
34
|
-
if (this.
|
|
37
|
+
if (this.services && !force) {
|
|
35
38
|
return;
|
|
36
39
|
}
|
|
40
|
+
const { stdout: servicesOutput } = await execa({
|
|
41
|
+
cwd: this.monorepo.rootDir,
|
|
42
|
+
}) `docker compose config --services`;
|
|
43
|
+
const services = servicesOutput
|
|
44
|
+
.split('\n')
|
|
45
|
+
.map((l) => l.trim())
|
|
46
|
+
.reduce((services, name) => {
|
|
47
|
+
services.set(name, { name, containers: [] });
|
|
48
|
+
return services;
|
|
49
|
+
}, new Map());
|
|
37
50
|
const { stdout } = await execa({
|
|
38
51
|
cwd: this.monorepo.rootDir,
|
|
39
52
|
}) `docker compose ps -a --format json`;
|
|
40
|
-
this.
|
|
53
|
+
this.services = stdout
|
|
41
54
|
.split('\n')
|
|
42
55
|
.map((l) => JSON.parse(l))
|
|
43
56
|
.reduce((services, entry) => {
|
|
44
|
-
if (!services.has(entry.Service)) {
|
|
45
|
-
services.set(entry.Service, {
|
|
46
|
-
name: entry.Service,
|
|
47
|
-
containers: [],
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
57
|
const svc = services.get(entry.Service);
|
|
51
58
|
svc?.containers.push(entry);
|
|
52
59
|
return services;
|
|
53
|
-
},
|
|
60
|
+
}, services);
|
|
54
61
|
}
|
|
55
62
|
}
|
|
@@ -13,7 +13,7 @@ export var ExecutorType;
|
|
|
13
13
|
})(ExecutorType || (ExecutorType = {}));
|
|
14
14
|
export class RunTasksOperation {
|
|
15
15
|
async run(params) {
|
|
16
|
-
const { monorepo } = getContext();
|
|
16
|
+
const { monorepo, compose } = getContext();
|
|
17
17
|
// First ensure the selection is valid (user can use task IDs or names)
|
|
18
18
|
const collection = new EMBCollection(monorepo.tasks, {
|
|
19
19
|
idField: 'id',
|
|
@@ -33,9 +33,14 @@ export class RunTasksOperation {
|
|
|
33
33
|
}
|
|
34
34
|
const vars = await monorepo.expand(task.vars || {});
|
|
35
35
|
const executor = params.executor ??
|
|
36
|
-
(task.component
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
(task.component
|
|
37
|
+
? compose.isService(task.component)
|
|
38
|
+
? ExecutorType.container
|
|
39
|
+
: ExecutorType.local
|
|
40
|
+
: ExecutorType.local);
|
|
41
|
+
if (executor === ExecutorType.container &&
|
|
42
|
+
(!task.component || !compose.isService(task.component))) {
|
|
43
|
+
throw new Error('Cannot use the container executor with this task');
|
|
39
44
|
}
|
|
40
45
|
// Handle tasks that require confirmation
|
|
41
46
|
if (task.confirm) {
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enspirit/emb",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.8.
|
|
4
|
+
"version": "0.8.2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"monorepo",
|
|
7
7
|
"docker",
|
|
@@ -45,7 +45,6 @@
|
|
|
45
45
|
"@oclif/core": "^4.5.2",
|
|
46
46
|
"@oclif/plugin-autocomplete": "^3.2.34",
|
|
47
47
|
"@oclif/plugin-help": "^6.2.32",
|
|
48
|
-
"@oclif/plugin-not-found": "^3.2.63",
|
|
49
48
|
"@oclif/plugin-update": "^4.7.3",
|
|
50
49
|
"@oclif/table": "^0.4.12",
|
|
51
50
|
"ajv": "^8.17.1",
|
|
@@ -111,7 +110,8 @@
|
|
|
111
110
|
"dirname": "emb",
|
|
112
111
|
"commands": "./dist/src/cli/commands",
|
|
113
112
|
"hooks": {
|
|
114
|
-
"init": "./dist/src/cli/hooks/init"
|
|
113
|
+
"init": "./dist/src/cli/hooks/init",
|
|
114
|
+
"command_not_found": "./dist/src/cli/hooks/not-found"
|
|
115
115
|
},
|
|
116
116
|
"macos": {
|
|
117
117
|
"identifier": "dev.enspirit.emb"
|
|
@@ -119,7 +119,6 @@
|
|
|
119
119
|
"plugins": [
|
|
120
120
|
"@oclif/plugin-help",
|
|
121
121
|
"@oclif/plugin-autocomplete",
|
|
122
|
-
"@oclif/plugin-not-found",
|
|
123
122
|
"@oclif/plugin-update"
|
|
124
123
|
],
|
|
125
124
|
"topicSeparator": " ",
|