@enspirit/emb 0.6.0 → 0.7.0

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 CHANGED
@@ -14,7 +14,7 @@ $ npm install -g @enspirit/emb
14
14
  $ emb COMMAND
15
15
  running command...
16
16
  $ emb (--version)
17
- @enspirit/emb/0.6.0 darwin-x64 node-v22.18.0
17
+ @enspirit/emb/0.7.0 darwin-arm64 node-v22.14.0
18
18
  $ emb --help [COMMAND]
19
19
  USAGE
20
20
  $ emb COMMAND
@@ -36,7 +36,7 @@ export default class ContainersIndex extends BaseCommand {
36
36
  id: shortId(c.Id),
37
37
  image: c.Image,
38
38
  name: c.Names[0] || c.Id,
39
- ports: c.Ports.map((p) => {
39
+ ports: c.Ports?.map((p) => {
40
40
  const parts = [];
41
41
  if (p.IP) {
42
42
  parts.push(p.IP, ':', p.PublicPort, '->');
@@ -268,6 +268,9 @@
268
268
  "properties": {
269
269
  "path": {
270
270
  "type": "string"
271
+ },
272
+ "script": {
273
+ "type": "string"
271
274
  }
272
275
  }
273
276
  }
@@ -3,6 +3,8 @@ import * as z from 'zod';
3
3
  import { AbstractOperation } from '../../../operations/index.js';
4
4
  declare const schema: z.ZodObject<{
5
5
  path: z.ZodString;
6
+ script: z.ZodOptional<z.ZodString>;
7
+ cwd: z.ZodOptional<z.ZodString>;
6
8
  force: z.ZodOptional<z.ZodBoolean>;
7
9
  }, z.core.$strip>;
8
10
  export declare class CreateFileOperation extends AbstractOperation<typeof schema, unknown> {
@@ -1,9 +1,12 @@
1
+ import { execa } from 'execa';
1
2
  import { open, statfs, utimes } from 'node:fs/promises';
2
3
  import * as z from 'zod';
3
4
  import { AbstractOperation } from '../../../operations/index.js';
4
5
  const schema = z.object({
5
6
  //
6
7
  path: z.string().describe('Path to the file to create'),
8
+ script: z.string().optional().describe('The script to generate the file'),
9
+ cwd: z.string().optional().describe('Working directory to execute scripts'),
7
10
  force: z
8
11
  .boolean()
9
12
  .optional()
@@ -16,6 +19,7 @@ export class CreateFileOperation extends AbstractOperation {
16
19
  this.out = out;
17
20
  }
18
21
  async _run(input) {
22
+ // Check if the file exists, if so our work is done here
19
23
  try {
20
24
  await statfs(input.path);
21
25
  if (input.force) {
@@ -23,11 +27,21 @@ export class CreateFileOperation extends AbstractOperation {
23
27
  }
24
28
  }
25
29
  catch (error) {
26
- if (error?.code === 'ENOENT') {
27
- const fn = await open(input.path, 'a');
28
- return fn.close();
30
+ // Ignore ENOENT error (file does not exist)
31
+ if (error?.code !== 'ENOENT') {
32
+ throw error;
29
33
  }
30
- throw error;
34
+ }
35
+ if (input.script) {
36
+ await execa(input.script, {
37
+ all: true,
38
+ cwd: input.cwd,
39
+ shell: true,
40
+ });
41
+ }
42
+ else {
43
+ const fn = await open(input.path, 'a');
44
+ fn.close();
31
45
  }
32
46
  }
33
47
  }
@@ -9,6 +9,8 @@ export declare class FileResourceBuilder implements IResourceBuilder<OpInput<Cre
9
9
  build(resource: ResourceInfo<OpInput<CreateFileOperation>>, out?: Writable): Promise<{
10
10
  input: {
11
11
  path: string;
12
+ script?: string | undefined;
13
+ cwd?: string | undefined;
12
14
  force?: boolean | undefined;
13
15
  };
14
16
  operation: CreateFileOperation;
@@ -11,6 +11,8 @@ export class FileResourceBuilder {
11
11
  async build(resource, out) {
12
12
  const input = {
13
13
  path: await this.context.component.join(this.context.config.params?.path || this.context.config.name),
14
+ script: resource.params?.script,
15
+ cwd: this.context.component.join('./'),
14
16
  };
15
17
  return {
16
18
  input,
@@ -853,5 +853,5 @@
853
853
  ]
854
854
  }
855
855
  },
856
- "version": "0.6.0"
856
+ "version": "0.7.0"
857
857
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@enspirit/emb",
3
3
  "type": "module",
4
- "version": "0.6.0",
4
+ "version": "0.7.0",
5
5
  "keywords": [
6
6
  "monorepo",
7
7
  "docker",