@enspirit/emb 0.0.4 → 0.0.6
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 +2 -19
- package/dist/src/cli/commands/config/print.js +1 -1
- package/dist/src/cli/commands/tasks/run.d.ts +0 -2
- package/dist/src/cli/commands/tasks/run.js +10 -59
- package/dist/src/config/convert.d.ts +2 -3
- package/dist/src/config/convert.js +2 -7
- package/dist/src/config/schema.d.ts +28 -28
- package/dist/src/config/schema.json +45 -50
- package/dist/src/config/types.d.ts +2 -2
- package/dist/src/config/validation.d.ts +2 -0
- package/dist/src/config/validation.js +26 -1
- package/dist/src/docker/operations/containers/ExecContainerOperation.d.ts +22 -0
- package/dist/src/docker/operations/containers/ExecContainerOperation.js +78 -0
- package/dist/src/docker/operations/containers/index.d.ts +1 -0
- package/dist/src/docker/operations/containers/index.js +1 -0
- package/dist/src/monorepo/config.d.ts +2 -1
- package/dist/src/monorepo/config.js +8 -2
- package/dist/src/monorepo/operations/components/GetComponentContainerOperation.d.ts +6 -0
- package/dist/src/monorepo/operations/components/GetComponentContainerOperation.js +21 -0
- package/dist/src/monorepo/operations/components/index.d.ts +1 -0
- package/dist/src/monorepo/operations/components/index.js +1 -0
- package/dist/src/monorepo/operations/index.d.ts +2 -0
- package/dist/src/monorepo/operations/index.js +2 -0
- package/dist/src/monorepo/operations/shell/ExecuteLocalCommandOperation.d.ts +18 -0
- package/dist/src/monorepo/operations/shell/ExecuteLocalCommandOperation.js +35 -0
- package/dist/src/monorepo/operations/shell/index.d.ts +1 -0
- package/dist/src/monorepo/operations/shell/index.js +1 -0
- package/dist/src/monorepo/operations/tasks/RunTaskOperation.d.ts +18 -0
- package/dist/src/monorepo/operations/tasks/RunTaskOperation.js +50 -0
- package/dist/src/monorepo/operations/tasks/index.d.ts +1 -0
- package/dist/src/monorepo/operations/tasks/index.js +1 -0
- package/dist/src/monorepo/plugins/ComponentDiscoverPlugin.d.ts +15 -0
- package/dist/src/monorepo/plugins/{ComponentsDiscover.js → ComponentDiscoverPlugin.js} +13 -1
- package/dist/src/monorepo/plugins/EmbfileLoaderPlugin.d.ts +14 -0
- package/dist/src/monorepo/plugins/EmbfileLoaderPlugin.js +33 -0
- package/dist/src/monorepo/plugins/index.d.ts +3 -2
- package/dist/src/monorepo/plugins/index.js +5 -2
- package/dist/src/operations/abstract/AbstractOperation.d.ts +1 -1
- package/dist/src/utils/deepMergeArray.d.ts +3 -0
- package/dist/src/utils/deepMergeArray.js +1 -0
- package/oclif.manifest.json +33 -67
- package/package.json +2 -2
- package/dist/src/cli/commands/run/index.d.ts +0 -10
- package/dist/src/cli/commands/run/index.js +0 -49
- package/dist/src/executors/docker.d.ts +0 -6
- package/dist/src/executors/docker.js +0 -14
- package/dist/src/executors/index.d.ts +0 -6
- package/dist/src/executors/index.js +0 -7
- package/dist/src/executors/shell.d.ts +0 -2
- package/dist/src/executors/shell.js +0 -14
- package/dist/src/executors/types.d.ts +0 -8
- package/dist/src/executors/types.js +0 -1
- package/dist/src/monorepo/plugins/ComponentsDiscover.d.ts +0 -6
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ResultPromise } from 'execa';
|
|
2
|
+
import { Writable } from 'node:stream';
|
|
3
|
+
import * as z from 'zod';
|
|
4
|
+
import { AbstractOperation } from '../../../operations/index.js';
|
|
5
|
+
/**
|
|
6
|
+
* https://docs.docker.com/reference/api/engine/version/v1.37/#tag/Exec/operation/ContainerExec
|
|
7
|
+
*/
|
|
8
|
+
declare const schema: z.ZodObject<{
|
|
9
|
+
env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
10
|
+
script: z.ZodString;
|
|
11
|
+
workingDir: z.ZodOptional<z.ZodString>;
|
|
12
|
+
}, z.core.$strip>;
|
|
13
|
+
export declare class ExecuteLocalCommandOperation extends AbstractOperation<typeof schema, ResultPromise> {
|
|
14
|
+
protected out?: Writable | undefined;
|
|
15
|
+
constructor(out?: Writable | undefined);
|
|
16
|
+
protected _run(input: z.input<typeof schema>): Promise<ResultPromise>;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { execa } from 'execa';
|
|
2
|
+
import * as z from 'zod';
|
|
3
|
+
import { AbstractOperation } from '../../../operations/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* https://docs.docker.com/reference/api/engine/version/v1.37/#tag/Exec/operation/ContainerExec
|
|
6
|
+
*/
|
|
7
|
+
const schema = z.object({
|
|
8
|
+
env: z
|
|
9
|
+
.record(z.string(), z.string())
|
|
10
|
+
.optional()
|
|
11
|
+
.describe('A list of environment variables in the form'),
|
|
12
|
+
script: z.string().describe('Command to run, as a string'),
|
|
13
|
+
workingDir: z
|
|
14
|
+
.string()
|
|
15
|
+
.optional()
|
|
16
|
+
.describe('The working directory for the exec process inside the container'),
|
|
17
|
+
});
|
|
18
|
+
export class ExecuteLocalCommandOperation extends AbstractOperation {
|
|
19
|
+
out;
|
|
20
|
+
constructor(out) {
|
|
21
|
+
super(schema);
|
|
22
|
+
this.out = out;
|
|
23
|
+
}
|
|
24
|
+
async _run(input) {
|
|
25
|
+
const process = execa(input.script, {
|
|
26
|
+
all: true,
|
|
27
|
+
cwd: input.workingDir,
|
|
28
|
+
shell: true,
|
|
29
|
+
});
|
|
30
|
+
if (this.out) {
|
|
31
|
+
process.all?.pipe(this.out);
|
|
32
|
+
}
|
|
33
|
+
return process;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ExecuteLocalCommandOperation.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ExecuteLocalCommandOperation.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Writable } from 'node:stream';
|
|
2
|
+
import { TaskInfo } from '../../types.js';
|
|
3
|
+
import { IOperation } from '../../../operations/types.js';
|
|
4
|
+
export declare enum ExecutorType {
|
|
5
|
+
container = "container",
|
|
6
|
+
local = "local"
|
|
7
|
+
}
|
|
8
|
+
export type RunTaskOperationParams = {
|
|
9
|
+
executor: ExecutorType;
|
|
10
|
+
task: TaskInfo;
|
|
11
|
+
};
|
|
12
|
+
export declare class RunTaskOperation implements IOperation<RunTaskOperationParams, void> {
|
|
13
|
+
protected out?: Writable | undefined;
|
|
14
|
+
constructor(out?: Writable | undefined);
|
|
15
|
+
run(params: RunTaskOperationParams): Promise<void>;
|
|
16
|
+
private runDocker;
|
|
17
|
+
private runLocal;
|
|
18
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { getContext } from '../../../index.js';
|
|
2
|
+
import { ContainerExecOperation } from '../../../docker/index.js';
|
|
3
|
+
import { ExecuteLocalCommandOperation, GetComponentContainerOperation, } from '../index.js';
|
|
4
|
+
export var ExecutorType;
|
|
5
|
+
(function (ExecutorType) {
|
|
6
|
+
ExecutorType["container"] = "container";
|
|
7
|
+
ExecutorType["local"] = "local";
|
|
8
|
+
})(ExecutorType || (ExecutorType = {}));
|
|
9
|
+
export class RunTaskOperation {
|
|
10
|
+
out;
|
|
11
|
+
constructor(out) {
|
|
12
|
+
this.out = out;
|
|
13
|
+
}
|
|
14
|
+
async run(params) {
|
|
15
|
+
switch (params.executor) {
|
|
16
|
+
case ExecutorType.container: {
|
|
17
|
+
return this.runDocker(params);
|
|
18
|
+
}
|
|
19
|
+
case ExecutorType.local: {
|
|
20
|
+
return this.runLocal(params);
|
|
21
|
+
}
|
|
22
|
+
default: {
|
|
23
|
+
throw new Error(`Unsupported executor type: ${params.executor}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async runDocker(params) {
|
|
28
|
+
const { monorepo } = getContext();
|
|
29
|
+
if (!params.task.component) {
|
|
30
|
+
throw new Error(`Support for non-component tasks not implemented`);
|
|
31
|
+
}
|
|
32
|
+
const containerInfo = await monorepo.run(new GetComponentContainerOperation(), params.task.component);
|
|
33
|
+
await monorepo.run(new ContainerExecOperation(this.out), {
|
|
34
|
+
attachStderr: true,
|
|
35
|
+
attachStdout: true,
|
|
36
|
+
container: containerInfo.Id,
|
|
37
|
+
script: params.task.script,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
async runLocal(params) {
|
|
41
|
+
const { monorepo } = getContext();
|
|
42
|
+
const cwd = params.task.component
|
|
43
|
+
? monorepo.component(params.task.component).rootdir
|
|
44
|
+
: monorepo.rootDir;
|
|
45
|
+
await monorepo.run(new ExecuteLocalCommandOperation(this.out), {
|
|
46
|
+
script: params.task.script,
|
|
47
|
+
workingDir: cwd,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './RunTaskOperation.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './RunTaskOperation.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Monorepo, MonorepoConfig } from '../index.js';
|
|
2
|
+
import { AbstractPlugin } from './plugin.js';
|
|
3
|
+
export type ComponentDiscoverPluginOptions = {
|
|
4
|
+
glob?: string;
|
|
5
|
+
ignore?: string | string[];
|
|
6
|
+
};
|
|
7
|
+
export declare const ComponentDiscoverPluginDefaultOptions: {
|
|
8
|
+
glob: string;
|
|
9
|
+
};
|
|
10
|
+
export declare class ComponentDiscoverPlugin extends AbstractPlugin<ComponentDiscoverPluginOptions> {
|
|
11
|
+
protected monorepo: Monorepo;
|
|
12
|
+
static name: string;
|
|
13
|
+
constructor(config: Partial<ComponentDiscoverPluginOptions>, monorepo: Monorepo);
|
|
14
|
+
extendConfig(config: MonorepoConfig): Promise<MonorepoConfig>;
|
|
15
|
+
}
|
|
@@ -3,10 +3,22 @@ import { glob } from 'glob';
|
|
|
3
3
|
import { dirname } from 'node:path';
|
|
4
4
|
import { MonorepoConfig } from '../index.js';
|
|
5
5
|
import { AbstractPlugin } from './plugin.js';
|
|
6
|
+
export const ComponentDiscoverPluginDefaultOptions = {
|
|
7
|
+
glob: '*/Dockerfile',
|
|
8
|
+
};
|
|
6
9
|
export class ComponentDiscoverPlugin extends AbstractPlugin {
|
|
10
|
+
monorepo;
|
|
7
11
|
static name = 'autodiscover';
|
|
12
|
+
constructor(config, monorepo) {
|
|
13
|
+
super({
|
|
14
|
+
...ComponentDiscoverPluginDefaultOptions,
|
|
15
|
+
...config,
|
|
16
|
+
}, monorepo);
|
|
17
|
+
this.monorepo = monorepo;
|
|
18
|
+
}
|
|
8
19
|
async extendConfig(config) {
|
|
9
|
-
const files = await glob(
|
|
20
|
+
const files = await glob(this.config.glob || ComponentDiscoverPluginDefaultOptions.glob, {
|
|
21
|
+
...this.config,
|
|
10
22
|
cwd: config.project.rootDir,
|
|
11
23
|
});
|
|
12
24
|
const overrides = files.map((path) => {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Monorepo, MonorepoConfig } from '../index.js';
|
|
2
|
+
import { AbstractPlugin } from './plugin.js';
|
|
3
|
+
export type EmbfileLoaderPluginOptions = {
|
|
4
|
+
glob?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const EmbfileLoaderPluginDefaultOptions: {
|
|
7
|
+
glob: string;
|
|
8
|
+
};
|
|
9
|
+
export declare class EmbfileLoaderPlugin extends AbstractPlugin<EmbfileLoaderPluginOptions> {
|
|
10
|
+
protected monorepo: Monorepo;
|
|
11
|
+
static name: string;
|
|
12
|
+
constructor(config: Partial<EmbfileLoaderPluginOptions>, monorepo: Monorepo);
|
|
13
|
+
extendConfig(config: MonorepoConfig): Promise<MonorepoConfig>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { glob } from 'glob';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { validateEmbfile } from '../../config/index.js';
|
|
4
|
+
import { AbstractPlugin } from './plugin.js';
|
|
5
|
+
export const EmbfileLoaderPluginDefaultOptions = {
|
|
6
|
+
glob: '*/Embfile.{yaml,yml}',
|
|
7
|
+
};
|
|
8
|
+
export class EmbfileLoaderPlugin extends AbstractPlugin {
|
|
9
|
+
monorepo;
|
|
10
|
+
static name = 'embfiles';
|
|
11
|
+
constructor(config, monorepo) {
|
|
12
|
+
super({
|
|
13
|
+
...EmbfileLoaderPluginDefaultOptions,
|
|
14
|
+
...config,
|
|
15
|
+
}, monorepo);
|
|
16
|
+
this.monorepo = monorepo;
|
|
17
|
+
}
|
|
18
|
+
async extendConfig(config) {
|
|
19
|
+
const files = await glob(this.config.glob || EmbfileLoaderPluginDefaultOptions.glob, {
|
|
20
|
+
...this.config,
|
|
21
|
+
cwd: config.project.rootDir,
|
|
22
|
+
});
|
|
23
|
+
const newConfig = await files.reduce(async (pConfig, path) => {
|
|
24
|
+
const config = await pConfig;
|
|
25
|
+
const embfile = await join(config.project.rootDir, path);
|
|
26
|
+
const component = await validateEmbfile(embfile);
|
|
27
|
+
return config.with({
|
|
28
|
+
components: [component],
|
|
29
|
+
});
|
|
30
|
+
}, Promise.resolve(config));
|
|
31
|
+
return newConfig;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { AbstractPlugin } from './plugin.js';
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './ComponentDiscoverPlugin.js';
|
|
3
3
|
export * from './DotEnvPlugin.js';
|
|
4
|
-
|
|
4
|
+
export * from './EmbfileLoaderPlugin.js';
|
|
5
|
+
import { Monorepo } from '../index.js';
|
|
5
6
|
export type AbstractPluginConstructor = new <C, P extends AbstractPlugin<C>>(config: C, monorepo: Monorepo) => P;
|
|
6
7
|
export declare const registerPlugin: (plugin: AbstractPluginConstructor) => void;
|
|
7
8
|
export declare const getPlugin: (name: string) => AbstractPluginConstructor;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './ComponentDiscoverPlugin.js';
|
|
2
2
|
export * from './DotEnvPlugin.js';
|
|
3
|
-
|
|
3
|
+
export * from './EmbfileLoaderPlugin.js';
|
|
4
|
+
import { ComponentDiscoverPlugin } from './ComponentDiscoverPlugin.js';
|
|
4
5
|
import { DotEnvPlugin } from './DotEnvPlugin.js';
|
|
6
|
+
import { EmbfileLoaderPlugin } from './EmbfileLoaderPlugin.js';
|
|
5
7
|
const PluginRegistry = new Map();
|
|
6
8
|
export const registerPlugin = (plugin) => {
|
|
7
9
|
if (PluginRegistry.has(plugin.name)) {
|
|
@@ -18,3 +20,4 @@ export const getPlugin = (name) => {
|
|
|
18
20
|
/** Not sure why we need casting */
|
|
19
21
|
registerPlugin(ComponentDiscoverPlugin);
|
|
20
22
|
registerPlugin(DotEnvPlugin);
|
|
23
|
+
registerPlugin(EmbfileLoaderPlugin);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EmbContext } from '../../index.js';
|
|
2
2
|
import * as z from 'zod';
|
|
3
|
-
import { IOperation } from '../
|
|
3
|
+
import { IOperation } from '../index.js';
|
|
4
4
|
export declare abstract class AbstractOperation<S extends z.Schema, O = unknown> implements IOperation<z.infer<S>, O> {
|
|
5
5
|
protected inputSchema: S;
|
|
6
6
|
protected context: EmbContext;
|
package/oclif.manifest.json
CHANGED
|
@@ -204,12 +204,10 @@
|
|
|
204
204
|
"index.js"
|
|
205
205
|
]
|
|
206
206
|
},
|
|
207
|
-
"
|
|
208
|
-
"aliases": [
|
|
209
|
-
"ps"
|
|
210
|
-
],
|
|
207
|
+
"config:print": {
|
|
208
|
+
"aliases": [],
|
|
211
209
|
"args": {},
|
|
212
|
-
"description": "
|
|
210
|
+
"description": "Print the current config.",
|
|
213
211
|
"examples": [
|
|
214
212
|
"<%= config.bin %> <%= command.id %>"
|
|
215
213
|
],
|
|
@@ -221,18 +219,18 @@
|
|
|
221
219
|
"allowNo": false,
|
|
222
220
|
"type": "boolean"
|
|
223
221
|
},
|
|
224
|
-
"
|
|
225
|
-
"
|
|
226
|
-
"
|
|
227
|
-
"name": "all",
|
|
222
|
+
"flavor": {
|
|
223
|
+
"description": "Specify the flavor to use.",
|
|
224
|
+
"name": "flavor",
|
|
228
225
|
"required": false,
|
|
229
|
-
"
|
|
230
|
-
"
|
|
226
|
+
"hasDynamicHelp": false,
|
|
227
|
+
"multiple": false,
|
|
228
|
+
"type": "option"
|
|
231
229
|
}
|
|
232
230
|
},
|
|
233
231
|
"hasDynamicHelp": false,
|
|
234
232
|
"hiddenAliases": [],
|
|
235
|
-
"id": "
|
|
233
|
+
"id": "config:print",
|
|
236
234
|
"pluginAlias": "@enspirit/emb",
|
|
237
235
|
"pluginName": "@enspirit/emb",
|
|
238
236
|
"pluginType": "core",
|
|
@@ -244,14 +242,16 @@
|
|
|
244
242
|
"src",
|
|
245
243
|
"cli",
|
|
246
244
|
"commands",
|
|
247
|
-
"
|
|
248
|
-
"
|
|
245
|
+
"config",
|
|
246
|
+
"print.js"
|
|
249
247
|
]
|
|
250
248
|
},
|
|
251
|
-
"containers
|
|
252
|
-
"aliases": [
|
|
249
|
+
"containers": {
|
|
250
|
+
"aliases": [
|
|
251
|
+
"ps"
|
|
252
|
+
],
|
|
253
253
|
"args": {},
|
|
254
|
-
"description": "
|
|
254
|
+
"description": "List docker containers.",
|
|
255
255
|
"examples": [
|
|
256
256
|
"<%= config.bin %> <%= command.id %>"
|
|
257
257
|
],
|
|
@@ -262,11 +262,19 @@
|
|
|
262
262
|
"name": "json",
|
|
263
263
|
"allowNo": false,
|
|
264
264
|
"type": "boolean"
|
|
265
|
+
},
|
|
266
|
+
"all": {
|
|
267
|
+
"char": "a",
|
|
268
|
+
"description": "Retun all containers. By default, only running containers are shown",
|
|
269
|
+
"name": "all",
|
|
270
|
+
"required": false,
|
|
271
|
+
"allowNo": false,
|
|
272
|
+
"type": "boolean"
|
|
265
273
|
}
|
|
266
274
|
},
|
|
267
275
|
"hasDynamicHelp": false,
|
|
268
276
|
"hiddenAliases": [],
|
|
269
|
-
"id": "containers
|
|
277
|
+
"id": "containers",
|
|
270
278
|
"pluginAlias": "@enspirit/emb",
|
|
271
279
|
"pluginName": "@enspirit/emb",
|
|
272
280
|
"pluginType": "core",
|
|
@@ -279,13 +287,13 @@
|
|
|
279
287
|
"cli",
|
|
280
288
|
"commands",
|
|
281
289
|
"containers",
|
|
282
|
-
"
|
|
290
|
+
"index.js"
|
|
283
291
|
]
|
|
284
292
|
},
|
|
285
|
-
"
|
|
293
|
+
"containers:prune": {
|
|
286
294
|
"aliases": [],
|
|
287
295
|
"args": {},
|
|
288
|
-
"description": "
|
|
296
|
+
"description": "Prune containers.",
|
|
289
297
|
"examples": [
|
|
290
298
|
"<%= config.bin %> <%= command.id %>"
|
|
291
299
|
],
|
|
@@ -296,19 +304,11 @@
|
|
|
296
304
|
"name": "json",
|
|
297
305
|
"allowNo": false,
|
|
298
306
|
"type": "boolean"
|
|
299
|
-
},
|
|
300
|
-
"flavor": {
|
|
301
|
-
"description": "Specify the flavor to use.",
|
|
302
|
-
"name": "flavor",
|
|
303
|
-
"required": false,
|
|
304
|
-
"hasDynamicHelp": false,
|
|
305
|
-
"multiple": false,
|
|
306
|
-
"type": "option"
|
|
307
307
|
}
|
|
308
308
|
},
|
|
309
309
|
"hasDynamicHelp": false,
|
|
310
310
|
"hiddenAliases": [],
|
|
311
|
-
"id": "
|
|
311
|
+
"id": "containers:prune",
|
|
312
312
|
"pluginAlias": "@enspirit/emb",
|
|
313
313
|
"pluginName": "@enspirit/emb",
|
|
314
314
|
"pluginType": "core",
|
|
@@ -320,42 +320,8 @@
|
|
|
320
320
|
"src",
|
|
321
321
|
"cli",
|
|
322
322
|
"commands",
|
|
323
|
-
"
|
|
324
|
-
"
|
|
325
|
-
]
|
|
326
|
-
},
|
|
327
|
-
"run": {
|
|
328
|
-
"aliases": [],
|
|
329
|
-
"args": {
|
|
330
|
-
"component": {
|
|
331
|
-
"description": "Component name",
|
|
332
|
-
"name": "component",
|
|
333
|
-
"required": true
|
|
334
|
-
},
|
|
335
|
-
"script": {
|
|
336
|
-
"description": "NPM script to run",
|
|
337
|
-
"name": "script",
|
|
338
|
-
"required": true
|
|
339
|
-
}
|
|
340
|
-
},
|
|
341
|
-
"description": "Run an npm script from a component's package.json",
|
|
342
|
-
"flags": {},
|
|
343
|
-
"hasDynamicHelp": false,
|
|
344
|
-
"hiddenAliases": [],
|
|
345
|
-
"id": "run",
|
|
346
|
-
"pluginAlias": "@enspirit/emb",
|
|
347
|
-
"pluginName": "@enspirit/emb",
|
|
348
|
-
"pluginType": "core",
|
|
349
|
-
"strict": true,
|
|
350
|
-
"enableJsonFlag": false,
|
|
351
|
-
"isESM": true,
|
|
352
|
-
"relativePath": [
|
|
353
|
-
"dist",
|
|
354
|
-
"src",
|
|
355
|
-
"cli",
|
|
356
|
-
"commands",
|
|
357
|
-
"run",
|
|
358
|
-
"index.js"
|
|
323
|
+
"containers",
|
|
324
|
+
"prune.js"
|
|
359
325
|
]
|
|
360
326
|
},
|
|
361
327
|
"images:delete": {
|
|
@@ -570,5 +536,5 @@
|
|
|
570
536
|
]
|
|
571
537
|
}
|
|
572
538
|
},
|
|
573
|
-
"version": "0.0.
|
|
539
|
+
"version": "0.0.6"
|
|
574
540
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enspirit/emb",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.6",
|
|
5
5
|
"keywords": ["monorepo", "docker", "taskrunner", "ci", "docker compose", "sentinel", "makefile"],
|
|
6
6
|
"author": "Louis Lambeau <louis.lambeau@enspirit.be>",
|
|
7
7
|
"license": "ISC",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"version": "oclif readme && git add README.md"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
+
"@fastify/deepmerge": "^3.1.0",
|
|
32
33
|
"@listr2/manager": "^3.0.1",
|
|
33
34
|
"@oclif/core": "^4.5.2",
|
|
34
35
|
"@oclif/plugin-autocomplete": "^3.2.34",
|
|
@@ -55,7 +56,6 @@
|
|
|
55
56
|
"devDependencies": {
|
|
56
57
|
"@eslint/eslintrc": "^3.3.1",
|
|
57
58
|
"@eslint/js": "^9.32.0",
|
|
58
|
-
"@fastify/deepmerge": "^3.1.0",
|
|
59
59
|
"@oclif/prettier-config": "^0.2.1",
|
|
60
60
|
"@oclif/test": "^4",
|
|
61
61
|
"@tsconfig/node20": "^20.1.6",
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Command } from '@oclif/core';
|
|
2
|
-
export default class RunComponentScript extends Command {
|
|
3
|
-
static args: {
|
|
4
|
-
component: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
5
|
-
script: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
6
|
-
};
|
|
7
|
-
static description: string;
|
|
8
|
-
static strict: boolean;
|
|
9
|
-
run(): Promise<void>;
|
|
10
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { getContext } from '../../../index.js';
|
|
2
|
-
import { Args, Command } from '@oclif/core';
|
|
3
|
-
import { Listr } from 'listr2';
|
|
4
|
-
import { spawn } from 'node:child_process';
|
|
5
|
-
import fs from 'node:fs/promises';
|
|
6
|
-
export default class RunComponentScript extends Command {
|
|
7
|
-
static args = {
|
|
8
|
-
component: Args.string({
|
|
9
|
-
description: 'Component name',
|
|
10
|
-
required: true,
|
|
11
|
-
}),
|
|
12
|
-
script: Args.string({ description: 'NPM script to run', required: true }),
|
|
13
|
-
};
|
|
14
|
-
static description = "Run an npm script from a component's package.json";
|
|
15
|
-
static strict = true;
|
|
16
|
-
async run() {
|
|
17
|
-
const { args } = await this.parse(RunComponentScript);
|
|
18
|
-
const { monorepo } = getContext();
|
|
19
|
-
const component = monorepo.component(args.component);
|
|
20
|
-
const pkgPath = component.join('package.json');
|
|
21
|
-
const tasks = new Listr([
|
|
22
|
-
{
|
|
23
|
-
rendererOptions: {
|
|
24
|
-
persistentOutput: true,
|
|
25
|
-
},
|
|
26
|
-
async task(_ctx, _task) {
|
|
27
|
-
try {
|
|
28
|
-
const pkgRaw = await fs.readFile(pkgPath, 'utf8');
|
|
29
|
-
const pkg = JSON.parse(pkgRaw);
|
|
30
|
-
if (!pkg.scripts?.[args.script]) {
|
|
31
|
-
throw new Error(`Script "${args.script}" not found in ${component.name}/package.json`);
|
|
32
|
-
}
|
|
33
|
-
return spawn('npm', ['run', args.script], {
|
|
34
|
-
cwd: component.rootdir,
|
|
35
|
-
}).stdout;
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
const error_ = error instanceof Error
|
|
39
|
-
? new TypeError(`Failed to run ${component.name}:${args.script}\n${error.message}`)
|
|
40
|
-
: new Error(`Failed to run ${component.name}:${args.script}\n${error}`);
|
|
41
|
-
throw error_;
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
title: `Running npm script '${args.script}' on ${args.component}`,
|
|
45
|
-
},
|
|
46
|
-
], { concurrent: false });
|
|
47
|
-
await tasks.run();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export const dockerExecutor = {
|
|
2
|
-
async run(script, options) {
|
|
3
|
-
const exec = await options.container.exec({
|
|
4
|
-
AttachStderr: true,
|
|
5
|
-
AttachStdout: true,
|
|
6
|
-
Cmd: ['bash', '-c', script],
|
|
7
|
-
});
|
|
8
|
-
const stream = await exec.start({});
|
|
9
|
-
if (options.out) {
|
|
10
|
-
options.container.modem.demuxStream(stream, options.out, options.out);
|
|
11
|
-
}
|
|
12
|
-
return stream;
|
|
13
|
-
},
|
|
14
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { execa } from 'execa';
|
|
2
|
-
export const shellExecutor = {
|
|
3
|
-
async run(script, options) {
|
|
4
|
-
const process = execa(script, {
|
|
5
|
-
all: true,
|
|
6
|
-
cwd: options.cwd,
|
|
7
|
-
shell: true,
|
|
8
|
-
});
|
|
9
|
-
if (options.out) {
|
|
10
|
-
process.all?.pipe(options.out);
|
|
11
|
-
}
|
|
12
|
-
return process;
|
|
13
|
-
},
|
|
14
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|