@enspirit/emb 0.1.1 → 0.1.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 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.1.1 darwin-x64 node-v22.12.0
17
+ @enspirit/emb/0.1.2 darwin-x64 node-v22.12.0
18
18
  $ emb --help [COMMAND]
19
19
  USAGE
20
20
  $ emb COMMAND
@@ -225,10 +225,11 @@ List docker images.
225
225
 
226
226
  ```
227
227
  USAGE
228
- $ emb images [--json] [-a]
228
+ $ emb images [--json] [--flavor <value>] [-a]
229
229
 
230
230
  FLAGS
231
- -a, --all Show all images. Only images from a final layer (no children) are shown by default.
231
+ -a, --all Show all images. Only images from a final layer (no children) are shown by default.
232
+ --flavor=<value> Specify the flavor to use.
232
233
 
233
234
  GLOBAL FLAGS
234
235
  --json Format output as json.
@@ -9,5 +9,8 @@ export declare abstract class FlavoredCommand<T extends typeof Command> extends
9
9
  static enableJsonFlag: boolean;
10
10
  protected args: Args<T>;
11
11
  protected flags: Flags<T>;
12
+ protected catch(err: Error & {
13
+ exitCode?: number;
14
+ }): Promise<void>;
12
15
  init(): Promise<void>;
13
16
  }
@@ -1,5 +1,6 @@
1
1
  import { getContext, setContext } from '../../index.js';
2
2
  import { Flags } from '@oclif/core';
3
+ import { JsonPatchError } from 'fast-json-patch';
3
4
  import { BaseCommand } from './BaseCommand.js';
4
5
  export class FlavoredCommand extends BaseCommand {
5
6
  // define flags that can be inherited by any command that extends FlavoredCommand
@@ -14,6 +15,19 @@ export class FlavoredCommand extends BaseCommand {
14
15
  static enableJsonFlag = true;
15
16
  args;
16
17
  flags;
18
+ async catch(err) {
19
+ if (err instanceof JsonPatchError) {
20
+ this.log('INVALID', err.operation);
21
+ this.error('Invalid patch detected while applying flavor', {
22
+ code: err.name,
23
+ message: `Path \`${err.operation?.path}\``,
24
+ });
25
+ return;
26
+ }
27
+ // add any custom logic to handle errors from the command
28
+ // or simply return the parent class error handling
29
+ return super.catch(err);
30
+ }
17
31
  async init() {
18
32
  await super.init();
19
33
  const { args, flags } = await this.parse({
@@ -1,4 +1,4 @@
1
- import { BaseCommand } from '../../index.js';
1
+ import { FlavoredCommand } from '../../index.js';
2
2
  export type ImageInfo = {
3
3
  created: Date;
4
4
  imageId: string;
@@ -6,7 +6,7 @@ export type ImageInfo = {
6
6
  size: number;
7
7
  tag: string;
8
8
  };
9
- export default class ImagesIndex extends BaseCommand {
9
+ export default class ImagesIndex extends FlavoredCommand<typeof ImagesIndex> {
10
10
  static description: string;
11
11
  static enableJsonFlag: boolean;
12
12
  static examples: string[];
@@ -1,10 +1,10 @@
1
1
  import { getContext } from '../../../index.js';
2
2
  import { Flags } from '@oclif/core';
3
3
  import { printTable } from '@oclif/table';
4
- import { BaseCommand, TABLE_DEFAULTS } from '../../index.js';
4
+ import { FlavoredCommand, TABLE_DEFAULTS } from '../../index.js';
5
5
  import { listImages, shortId } from '../../../docker/index.js';
6
6
  import { timeAgo } from '../../../utils/index.js';
7
- export default class ImagesIndex extends BaseCommand {
7
+ export default class ImagesIndex extends FlavoredCommand {
8
8
  static description = 'List docker images.';
9
9
  static enableJsonFlag = true;
10
10
  static examples = ['<%= config.bin %> <%= command.id %>'];
@@ -20,6 +20,9 @@ export default class UpCommand extends FlavoredCommand {
20
20
  if (flags.force) {
21
21
  buildFlags.push('--force');
22
22
  }
23
+ if (flags.flavor) {
24
+ buildFlags.push('--flavor', flags.flavor);
25
+ }
23
26
  await this.config.runCommand('resources:build', buildFlags);
24
27
  await monorepo.run(new ComposeUpOperation(), {
25
28
  forceRecreate: flags.force,
@@ -129,6 +129,5 @@ export interface JsonPatchCopyOperation {
129
129
  from: string;
130
130
  }
131
131
  export interface ProjectFlavorConfig {
132
- defaults?: DefaultsConfig;
133
132
  patches?: JsonPatchOperation[];
134
133
  }
@@ -200,9 +200,6 @@
200
200
  "additionalProperties": false,
201
201
  "required": [],
202
202
  "properties": {
203
- "defaults": {
204
- "$ref": "#/$defs/DefaultsConfig"
205
- },
206
203
  "patches": {
207
204
  "type": "array",
208
205
  "items": {
@@ -15,12 +15,14 @@ const DockerImageOpFactory = async ({ config, component, monorepo }) => {
15
15
  await statfs(context);
16
16
  const plugin = new GitPrerequisitePlugin();
17
17
  const sources = await plugin.collect(context);
18
+ const imageName = [monorepo.name, fromConfig.tag || component.name].join('/');
19
+ const tagName = fromConfig.tag || monorepo.defaults.docker?.tag || 'latest';
18
20
  const buildParams = {
19
21
  context,
20
22
  dockerfile: fromConfig.dockerfile || 'Dockerfile',
21
23
  src: sources.map((s) => s.path),
22
24
  buildArgs: fromConfig.buildArgs || {},
23
- tag: [monorepo.name, fromConfig.tag || component.name].join('/'),
25
+ tag: `${imageName}:${tagName}`,
24
26
  labels: {
25
27
  ...fromConfig.labels,
26
28
  'emb/project': monorepo.name,
@@ -41,7 +41,7 @@ export class Component {
41
41
  const patches = this.flavor(name).patches || [];
42
42
  const errors = jsonpatch.validate(patches, original);
43
43
  if (errors) {
44
- throw new Error('Invalid patch(es) detected');
44
+ throw errors;
45
45
  }
46
46
  const patched = patches.reduce((doc, patch, index) => {
47
47
  return jsonpatch.applyReducer(doc, patch, index);
@@ -167,13 +167,13 @@ export class Monorepo {
167
167
  const original = this._config.toJSON();
168
168
  const errors = jsonpatch.validate(patches || [], original);
169
169
  if (errors) {
170
- throw new Error('Invalid patch(es) detected');
170
+ throw errors;
171
171
  }
172
172
  const withComponentPatches = this.components.reduce((config, cmp) => {
173
173
  const componentPatches = cmp.flavor(flavorName, false)?.patches || [];
174
174
  const errors = jsonpatch.validate(componentPatches || [], config.components[cmp.name]);
175
175
  if (errors) {
176
- throw new Error('Invalid patch(es) detected');
176
+ throw errors;
177
177
  }
178
178
  config.components[cmp.name] = componentPatches.reduce((doc, patch, index) => {
179
179
  return jsonpatch.applyReducer(doc, patch, index);
@@ -344,6 +344,14 @@
344
344
  "allowNo": false,
345
345
  "type": "boolean"
346
346
  },
347
+ "flavor": {
348
+ "description": "Specify the flavor to use.",
349
+ "name": "flavor",
350
+ "required": false,
351
+ "hasDynamicHelp": false,
352
+ "multiple": false,
353
+ "type": "option"
354
+ },
347
355
  "all": {
348
356
  "char": "a",
349
357
  "description": "Show all images. Only images from a final layer (no children) are shown by default.",
@@ -359,7 +367,6 @@
359
367
  "pluginAlias": "@enspirit/emb",
360
368
  "pluginName": "@enspirit/emb",
361
369
  "pluginType": "core",
362
- "strict": true,
363
370
  "enableJsonFlag": true,
364
371
  "isESM": true,
365
372
  "relativePath": [
@@ -611,5 +618,5 @@
611
618
  ]
612
619
  }
613
620
  },
614
- "version": "0.1.1"
621
+ "version": "0.1.2"
615
622
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@enspirit/emb",
3
3
  "type": "module",
4
- "version": "0.1.1",
4
+ "version": "0.1.2",
5
5
  "keywords": ["monorepo", "docker", "taskrunner", "ci", "docker compose", "sentinel", "makefile"],
6
6
  "author": "Louis Lambeau <louis.lambeau@enspirit.be>",
7
7
  "license": "ISC",