@enspirit/emb 0.0.8 → 0.1.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.
Files changed (125) hide show
  1. package/README.md +50 -27
  2. package/dist/src/cli/abstract/BaseCommand.d.ts +6 -0
  3. package/dist/src/cli/abstract/BaseCommand.js +33 -0
  4. package/dist/src/cli/abstract/FlavouredCommand.d.ts +2 -1
  5. package/dist/src/cli/abstract/FlavouredCommand.js +4 -3
  6. package/dist/src/cli/abstract/index.d.ts +1 -0
  7. package/dist/src/cli/abstract/index.js +1 -0
  8. package/dist/src/cli/commands/clean.d.ts +2 -2
  9. package/dist/src/cli/commands/clean.js +7 -6
  10. package/dist/src/cli/commands/components/index.d.ts +5 -4
  11. package/dist/src/cli/commands/components/index.js +13 -15
  12. package/dist/src/cli/commands/config/print.d.ts +2 -2
  13. package/dist/src/cli/commands/containers/index.d.ts +2 -2
  14. package/dist/src/cli/commands/containers/index.js +3 -3
  15. package/dist/src/cli/commands/containers/prune.d.ts +2 -2
  16. package/dist/src/cli/commands/containers/prune.js +2 -2
  17. package/dist/src/cli/commands/images/delete.d.ts +2 -2
  18. package/dist/src/cli/commands/images/delete.js +3 -2
  19. package/dist/src/cli/commands/images/index.d.ts +2 -2
  20. package/dist/src/cli/commands/images/index.js +3 -3
  21. package/dist/src/cli/commands/images/prune.d.ts +2 -2
  22. package/dist/src/cli/commands/images/prune.js +3 -2
  23. package/dist/src/cli/commands/{components → resources}/build.d.ts +4 -3
  24. package/dist/src/cli/commands/resources/build.js +42 -0
  25. package/dist/src/cli/commands/resources/index.d.ts +9 -0
  26. package/dist/src/cli/commands/resources/index.js +28 -0
  27. package/dist/src/cli/commands/tasks/index.d.ts +2 -2
  28. package/dist/src/cli/commands/tasks/index.js +4 -4
  29. package/dist/src/cli/commands/tasks/run.d.ts +2 -2
  30. package/dist/src/cli/commands/tasks/run.js +12 -5
  31. package/dist/src/cli/commands/up.js +5 -4
  32. package/dist/src/cli/hooks/init.js +1 -26
  33. package/dist/src/cli/utils.d.ts +1 -0
  34. package/dist/src/cli/utils.js +26 -0
  35. package/dist/src/config/convert.d.ts +2 -4
  36. package/dist/src/config/convert.js +12 -35
  37. package/dist/src/config/index.d.ts +3 -4
  38. package/dist/src/config/index.js +2 -3
  39. package/dist/src/config/schema.d.ts +69 -48
  40. package/dist/src/config/schema.json +185 -99
  41. package/dist/src/config/types.d.ts +13 -46
  42. package/dist/src/config/types.js +1 -1
  43. package/dist/src/config/validation.d.ts +3 -3
  44. package/dist/src/config/validation.js +9 -9
  45. package/dist/src/context.d.ts +1 -1
  46. package/dist/src/context.js +1 -0
  47. package/dist/src/docker/compose/operations/ComposeUpOperation.js +13 -12
  48. package/dist/src/docker/images/index.d.ts +0 -1
  49. package/dist/src/docker/images/index.js +0 -1
  50. package/dist/src/docker/index.d.ts +1 -1
  51. package/dist/src/docker/index.js +1 -1
  52. package/dist/src/docker/operations/containers/ExecContainerOperation.js +2 -1
  53. package/dist/src/docker/operations/images/BuildImageOperation.d.ts +7 -8
  54. package/dist/src/docker/operations/images/BuildImageOperation.js +17 -11
  55. package/dist/src/docker/resources/DockerImageResource.js +56 -0
  56. package/dist/src/docker/resources/index.d.ts +1 -0
  57. package/dist/src/docker/resources/index.js +1 -0
  58. package/dist/src/docker/utils.d.ts +1 -7
  59. package/dist/src/docker/utils.js +3 -7
  60. package/dist/src/errors.d.ts +9 -6
  61. package/dist/src/errors.js +15 -9
  62. package/dist/src/index.d.ts +2 -0
  63. package/dist/src/index.js +2 -0
  64. package/dist/src/monorepo/component.d.ts +14 -19
  65. package/dist/src/monorepo/component.js +42 -58
  66. package/dist/src/monorepo/config.d.ts +13 -15
  67. package/dist/src/monorepo/config.js +15 -46
  68. package/dist/src/monorepo/index.d.ts +1 -0
  69. package/dist/src/monorepo/index.js +1 -0
  70. package/dist/src/monorepo/monorepo.d.ts +13 -10
  71. package/dist/src/monorepo/monorepo.js +78 -19
  72. package/dist/src/monorepo/operations/components/index.d.ts +0 -1
  73. package/dist/src/monorepo/operations/components/index.js +0 -1
  74. package/dist/src/monorepo/operations/fs/CreateFileOperation.d.ts +11 -0
  75. package/dist/src/monorepo/operations/fs/CreateFileOperation.js +31 -0
  76. package/dist/src/monorepo/operations/fs/index.d.ts +1 -0
  77. package/dist/src/monorepo/operations/fs/index.js +1 -0
  78. package/dist/src/monorepo/operations/index.d.ts +1 -0
  79. package/dist/src/monorepo/operations/index.js +1 -0
  80. package/dist/src/monorepo/operations/resources/BuildResourcesOperation.d.ts +27 -0
  81. package/dist/src/monorepo/operations/resources/BuildResourcesOperation.js +146 -0
  82. package/dist/src/monorepo/operations/tasks/RunTasksOperation.js +5 -13
  83. package/dist/src/monorepo/plugins/{ComponentDiscoverPlugin.d.ts → AutoDockerPlugin.d.ts} +4 -4
  84. package/dist/src/monorepo/plugins/AutoDockerPlugin.js +46 -0
  85. package/dist/src/monorepo/plugins/EmbfileLoaderPlugin.js +9 -2
  86. package/dist/src/monorepo/plugins/index.d.ts +1 -1
  87. package/dist/src/monorepo/plugins/index.js +3 -3
  88. package/dist/src/monorepo/resources/FileResource.d.ts +1 -0
  89. package/dist/src/monorepo/resources/FileResource.js +13 -0
  90. package/dist/src/monorepo/resources/ResourceFactory.d.ts +23 -0
  91. package/dist/src/monorepo/resources/ResourceFactory.js +16 -0
  92. package/dist/src/monorepo/resources/index.d.ts +1 -0
  93. package/dist/src/monorepo/resources/index.js +1 -0
  94. package/dist/src/monorepo/store/index.d.ts +1 -1
  95. package/dist/src/monorepo/store/index.js +10 -2
  96. package/dist/src/monorepo/taskManagerFactory.d.ts +2 -2
  97. package/dist/src/monorepo/taskManagerFactory.js +2 -2
  98. package/dist/src/monorepo/types.d.ts +18 -5
  99. package/dist/src/monorepo/utils/{findRunOrder.d.ts → EMBCollection.d.ts} +3 -9
  100. package/dist/src/monorepo/utils/EMBCollection.js +101 -0
  101. package/dist/src/monorepo/utils/graph.d.ts +15 -0
  102. package/dist/src/monorepo/utils/graph.js +84 -0
  103. package/dist/src/monorepo/utils/index.d.ts +7 -1
  104. package/dist/src/monorepo/utils/index.js +14 -1
  105. package/dist/src/monorepo/utils/types.d.ts +2 -0
  106. package/dist/src/monorepo/utils/types.js +1 -0
  107. package/dist/src/operations/abstract/AbstractOperation.d.ts +3 -1
  108. package/dist/src/operations/abstract/AbstractOperation.js +3 -0
  109. package/dist/src/operations/types.d.ts +1 -1
  110. package/dist/src/prerequisites/GitPrerequisitePlugin.js +2 -2
  111. package/dist/src/utils/TemplateExpander.d.ts +2 -1
  112. package/dist/src/utils/TemplateExpander.js +3 -1
  113. package/oclif.manifest.json +157 -112
  114. package/package.json +7 -2
  115. package/dist/src/cli/commands/components/build.js +0 -34
  116. package/dist/src/docker/images/buildImage.d.ts +0 -19
  117. package/dist/src/docker/images/buildImage.js +0 -64
  118. package/dist/src/docker/types.d.ts +0 -14
  119. package/dist/src/monorepo/operations/components/BuildComponentsOperation.d.ts +0 -21
  120. package/dist/src/monorepo/operations/components/BuildComponentsOperation.js +0 -135
  121. package/dist/src/monorepo/plugins/ComponentDiscoverPlugin.js +0 -44
  122. package/dist/src/monorepo/project.d.ts +0 -6
  123. package/dist/src/monorepo/project.js +0 -8
  124. package/dist/src/monorepo/utils/findRunOrder.js +0 -165
  125. /package/dist/src/docker/{types.js → resources/DockerImageResource.d.ts} +0 -0
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.0.8 darwin-x64 node-v22.12.0
17
+ @enspirit/emb/0.1.0 darwin-x64 node-v22.12.0
18
18
  $ emb --help [COMMAND]
19
19
  USAGE
20
20
  $ emb COMMAND
@@ -26,7 +26,6 @@ USAGE
26
26
  * [`emb autocomplete [SHELL]`](#emb-autocomplete-shell)
27
27
  * [`emb clean`](#emb-clean)
28
28
  * [`emb components`](#emb-components)
29
- * [`emb components build [COMPONENT]`](#emb-components-build-component)
30
29
  * [`emb config print`](#emb-config-print)
31
30
  * [`emb containers`](#emb-containers)
32
31
  * [`emb containers prune`](#emb-containers-prune)
@@ -36,6 +35,8 @@ USAGE
36
35
  * [`emb images delete`](#emb-images-delete)
37
36
  * [`emb images prune`](#emb-images-prune)
38
37
  * [`emb ps`](#emb-ps)
38
+ * [`emb resources`](#emb-resources)
39
+ * [`emb resources build [COMPONENT]`](#emb-resources-build-component)
39
40
  * [`emb tasks`](#emb-tasks)
40
41
  * [`emb tasks run TASK`](#emb-tasks-run-task)
41
42
  * [`emb up`](#emb-up)
@@ -114,31 +115,6 @@ EXAMPLES
114
115
  $ emb components
115
116
  ```
116
117
 
117
- ## `emb components build [COMPONENT]`
118
-
119
- Build the components of the monorepo
120
-
121
- ```
122
- USAGE
123
- $ emb components build [COMPONENT...] [--json] [--flavor <value>] [--dry-run]
124
-
125
- ARGUMENTS
126
- COMPONENT... List of components to build (defaults to all)
127
-
128
- FLAGS
129
- --dry-run Do not build the components but only produce build meta information
130
- --flavor=<value> Specify the flavor to use.
131
-
132
- GLOBAL FLAGS
133
- --json Format output as json.
134
-
135
- DESCRIPTION
136
- Build the components of the monorepo
137
-
138
- EXAMPLES
139
- $ emb components build build --flavor development
140
- ```
141
-
142
118
  ## `emb config print`
143
119
 
144
120
  Print the current config.
@@ -330,6 +306,53 @@ EXAMPLES
330
306
  $ emb ps
331
307
  ```
332
308
 
309
+ ## `emb resources`
310
+
311
+ List resources.
312
+
313
+ ```
314
+ USAGE
315
+ $ emb resources [--json] [--flavor <value>]
316
+
317
+ FLAGS
318
+ --flavor=<value> Specify the flavor to use.
319
+
320
+ GLOBAL FLAGS
321
+ --json Format output as json.
322
+
323
+ DESCRIPTION
324
+ List resources.
325
+
326
+ EXAMPLES
327
+ $ emb resources
328
+ ```
329
+
330
+ ## `emb resources build [COMPONENT]`
331
+
332
+ Build the resources of the monorepo
333
+
334
+ ```
335
+ USAGE
336
+ $ emb resources build [COMPONENT...] [--json] [--flavor <value>] [--dry-run] [-f]
337
+
338
+ ARGUMENTS
339
+ COMPONENT... List of resources to build (defaults to all)
340
+
341
+ FLAGS
342
+ -f, --force Bypass the cache and force the build
343
+ --dry-run Do not build the resources but only produce build meta information
344
+ --flavor=<value> Specify the flavor to use.
345
+
346
+ GLOBAL FLAGS
347
+ --json Format output as json.
348
+
349
+ DESCRIPTION
350
+ Build the resources of the monorepo
351
+
352
+ EXAMPLES
353
+ $ emb resources build build --flavor development
354
+ ```
355
+
333
356
  ## `emb tasks`
334
357
 
335
358
  List tasks.
@@ -0,0 +1,6 @@
1
+ import { EmbContext } from '../../index.js';
2
+ import { Command } from '@oclif/core';
3
+ export declare abstract class BaseCommand extends Command {
4
+ protected context: EmbContext;
5
+ init(): Promise<void>;
6
+ }
@@ -0,0 +1,33 @@
1
+ import { getContext, setContext } from '../../index.js';
2
+ import { Command, Performance } from '@oclif/core';
3
+ import Dockerode from 'dockerode';
4
+ import { loadConfig } from '../../config/index.js';
5
+ import { Monorepo } from '../../monorepo/monorepo.js';
6
+ const withMarker = async (owner, name, cb) => {
7
+ const marker = Performance.mark(owner, name);
8
+ const res = await cb();
9
+ marker?.stop();
10
+ return res;
11
+ };
12
+ export class BaseCommand extends Command {
13
+ context;
14
+ async init() {
15
+ await super.init();
16
+ if (getContext()) {
17
+ return;
18
+ }
19
+ try {
20
+ const config = await withMarker('emb:config', 'load', () => loadConfig());
21
+ const monorepo = await withMarker('emb:monorepo', 'init', () => {
22
+ return new Monorepo(config).init();
23
+ });
24
+ this.context = setContext({
25
+ docker: new Dockerode(),
26
+ monorepo,
27
+ });
28
+ }
29
+ catch (error) {
30
+ this.error(error);
31
+ }
32
+ }
33
+ }
@@ -1,7 +1,8 @@
1
1
  import { Command, Interfaces } from '@oclif/core';
2
+ import { BaseCommand } from './BaseCommand.js';
2
3
  export type Flags<T extends typeof Command> = Interfaces.InferredFlags<(typeof FlavoredCommand)['baseFlags'] & T['flags']>;
3
4
  export type Args<T extends typeof Command> = Interfaces.InferredArgs<T['args']>;
4
- export declare abstract class FlavoredCommand<T extends typeof Command> extends Command {
5
+ export declare abstract class FlavoredCommand<T extends typeof Command> extends BaseCommand {
5
6
  static baseFlags: {
6
7
  flavor: Interfaces.OptionFlag<string | undefined, Interfaces.CustomOptions>;
7
8
  };
@@ -1,6 +1,7 @@
1
1
  import { getContext, setContext } from '../../index.js';
2
- import { Command, Flags } from '@oclif/core';
3
- export class FlavoredCommand extends Command {
2
+ import { Flags } from '@oclif/core';
3
+ import { BaseCommand } from './BaseCommand.js';
4
+ export class FlavoredCommand extends BaseCommand {
4
5
  // define flags that can be inherited by any command that extends FlavoredCommand
5
6
  static baseFlags = {
6
7
  flavor: Flags.string({
@@ -31,7 +32,7 @@ export class FlavoredCommand extends Command {
31
32
  // complain properly if incorrect
32
33
  const { flavor } = this.flags;
33
34
  if (flavor) {
34
- setContext({
35
+ this.context = setContext({
35
36
  ...context,
36
37
  monorepo: await context.monorepo.withFlavor(flavor),
37
38
  });
@@ -1 +1,2 @@
1
+ export * from './BaseCommand.js';
1
2
  export * from './FlavouredCommand.js';
@@ -1 +1,2 @@
1
+ export * from './BaseCommand.js';
1
2
  export * from './FlavouredCommand.js';
@@ -1,4 +1,4 @@
1
- import { Command } from '@oclif/core';
1
+ import { BaseCommand } from '../abstract/BaseCommand.js';
2
2
  /**
3
3
  * For now, only cleans the stores (logs/sentinels)
4
4
  * But this should permit to clean everytning (via flags)
@@ -6,7 +6,7 @@ import { Command } from '@oclif/core';
6
6
  * Eg: --containers --volumes --images --networks
7
7
  * Or: --all
8
8
  */
9
- export default class CleanCommand extends Command {
9
+ export default class CleanCommand extends BaseCommand {
10
10
  static description: string;
11
11
  static enableJsonFlag: boolean;
12
12
  static examples: string[];
@@ -1,6 +1,7 @@
1
1
  import { getContext } from '../../index.js';
2
- import { Command, Flags } from '@oclif/core';
2
+ import { Flags } from '@oclif/core';
3
3
  import { Listr } from 'listr2';
4
+ import { BaseCommand } from '../abstract/BaseCommand.js';
4
5
  /**
5
6
  * For now, only cleans the stores (logs/sentinels)
6
7
  * But this should permit to clean everytning (via flags)
@@ -8,7 +9,7 @@ import { Listr } from 'listr2';
8
9
  * Eg: --containers --volumes --images --networks
9
10
  * Or: --all
10
11
  */
11
- export default class CleanCommand extends Command {
12
+ export default class CleanCommand extends BaseCommand {
12
13
  static description = 'Clean the project.';
13
14
  static enableJsonFlag = true;
14
15
  static examples = ['<%= config.bin %> <%= command.id %>'];
@@ -22,6 +23,10 @@ export default class CleanCommand extends Command {
22
23
  async run() {
23
24
  const { monorepo } = getContext();
24
25
  const { flags } = await this.parse(CleanCommand);
26
+ await this.config.runCommand('down');
27
+ await this.config.runCommand('containers:prune');
28
+ await this.config.runCommand('images:delete', flags.force ? ['--force'] : undefined);
29
+ await this.config.runCommand('images:prune', flags.force ? ['-a'] : undefined);
25
30
  const runner = new Listr([
26
31
  {
27
32
  rendererOptions: { persistentOutput: true },
@@ -32,9 +37,5 @@ export default class CleanCommand extends Command {
32
37
  },
33
38
  ]);
34
39
  await runner.run();
35
- await this.config.runCommand('down');
36
- await this.config.runCommand('containers:prune');
37
- await this.config.runCommand('images:delete', flags.force ? ['--force'] : undefined);
38
- await this.config.runCommand('images:prune', flags.force ? ['-a'] : undefined);
39
40
  }
40
41
  }
@@ -1,9 +1,10 @@
1
1
  import { FlavoredCommand } from '../../index.js';
2
2
  export type ComponentInfo = {
3
- container?: string;
4
- imageName: string;
5
- name: string;
6
- tag: string;
3
+ component: string;
4
+ name?: string;
5
+ id?: string;
6
+ created?: string;
7
+ status?: string;
7
8
  };
8
9
  export default class ComponentsIndex extends FlavoredCommand<typeof ComponentsIndex> {
9
10
  static description: string;
@@ -1,6 +1,8 @@
1
1
  import { printTable } from '@oclif/table';
2
2
  import { FlavoredCommand, getContext, TABLE_DEFAULTS } from '../../index.js';
3
- import { ListContainersOperation, shortId } from '../../../docker/index.js';
3
+ import { getTimeAgo } from '../../utils.js';
4
+ import { ListContainersOperation } from '../../../docker/operations/index.js';
5
+ import { shortId } from '../../../docker/utils.js';
4
6
  export default class ComponentsIndex extends FlavoredCommand {
5
7
  static description = 'List components.';
6
8
  static enableJsonFlag = true;
@@ -9,30 +11,26 @@ export default class ComponentsIndex extends FlavoredCommand {
9
11
  async run() {
10
12
  const { flags } = await this.parse(ComponentsIndex);
11
13
  const { monorepo } = await getContext();
12
- // Get all running containers for this project
13
- // and then try to do a mapping. It's probably better than
14
- // doing N queries to list with specific filters
15
14
  const runningContainers = await monorepo.run(new ListContainersOperation(), {
16
15
  filters: {
17
16
  label: [`emb/project=${monorepo.name}`],
18
17
  },
19
18
  });
20
- const components = await Promise.all(monorepo.components.map(async (cmp) => {
21
- const buildInfos = await cmp.toDockerBuild();
22
- const container = runningContainers.find((cont) => {
23
- return cont.Image === `${buildInfos.name}:${buildInfos.tag}`;
24
- });
19
+ const components = monorepo.components.map((cmp) => {
20
+ const container = runningContainers.find((c) => c.Labels['emb/component'] === cmp.name &&
21
+ c.Labels['emb/flavor'] === monorepo.currentFlavor);
25
22
  return {
26
- container: container?.Id ? shortId(container?.Id) : '',
27
- imageName: buildInfos.name,
28
- name: cmp.name,
29
- tag: buildInfos.tag,
23
+ component: cmp.name,
24
+ id: shortId(container?.Id),
25
+ name: container?.Names?.join(', '),
26
+ created: getTimeAgo(container?.Created),
27
+ status: container?.Status,
30
28
  };
31
- }));
29
+ });
32
30
  if (!flags.json) {
33
31
  printTable({
34
32
  ...TABLE_DEFAULTS,
35
- columns: ['name', 'imageName', 'tag', 'container'],
33
+ columns: ['component', 'name', 'id', 'created', 'status'],
36
34
  data: components,
37
35
  sort: {
38
36
  name: 'asc',
@@ -1,5 +1,5 @@
1
1
  import { FlavoredCommand } from '../../index.js';
2
- import { IMonorepoConfig } from '../../../config/index.js';
2
+ import { EMBConfig } from '../../../config/schema.js';
3
3
  export type TaskInfo = {
4
4
  component?: string;
5
5
  description?: string;
@@ -9,5 +9,5 @@ export default class ConfigPrint extends FlavoredCommand<typeof ConfigPrint> {
9
9
  static description: string;
10
10
  static enableJsonFlag: boolean;
11
11
  static examples: string[];
12
- run(): Promise<IMonorepoConfig>;
12
+ run(): Promise<EMBConfig>;
13
13
  }
@@ -1,6 +1,6 @@
1
- import { Command } from '@oclif/core';
2
1
  import { ContainerInfo } from 'dockerode';
3
- export default class ContainersIndex extends Command {
2
+ import { BaseCommand } from '../../index.js';
3
+ export default class ContainersIndex extends BaseCommand {
4
4
  static aliases: string[];
5
5
  static description: string;
6
6
  static enableJsonFlag: boolean;
@@ -1,10 +1,10 @@
1
1
  import { getContext } from '../../../index.js';
2
- import { Command, Flags } from '@oclif/core';
2
+ import { Flags } from '@oclif/core';
3
3
  import { printTable } from '@oclif/table';
4
- import { TABLE_DEFAULTS } from '../../index.js';
4
+ import { BaseCommand, TABLE_DEFAULTS } from '../../index.js';
5
5
  import { ListContainersOperation, shortId } from '../../../docker/index.js';
6
6
  import { timeAgo } from '../../../utils/index.js';
7
- export default class ContainersIndex extends Command {
7
+ export default class ContainersIndex extends BaseCommand {
8
8
  static aliases = ['ps'];
9
9
  static description = 'List docker containers.';
10
10
  static enableJsonFlag = true;
@@ -1,6 +1,6 @@
1
- import { Command } from '@oclif/core';
2
1
  import { PruneContainersInfo } from 'dockerode';
3
- export default class ContainersPrune extends Command {
2
+ import { BaseCommand } from '../../abstract/BaseCommand.js';
3
+ export default class ContainersPrune extends BaseCommand {
4
4
  static description: string;
5
5
  static enableJsonFlag: boolean;
6
6
  static examples: string[];
@@ -1,7 +1,7 @@
1
1
  import { getContext } from '../../../index.js';
2
- import { Command } from '@oclif/core';
2
+ import { BaseCommand } from '../../abstract/BaseCommand.js';
3
3
  import { PruneContainersOperation } from '../../../docker/index.js';
4
- export default class ContainersPrune extends Command {
4
+ export default class ContainersPrune extends BaseCommand {
5
5
  static description = 'Prune containers.';
6
6
  static enableJsonFlag = true;
7
7
  static examples = ['<%= config.bin %> <%= command.id %>'];
@@ -1,5 +1,5 @@
1
- import { Command } from '@oclif/core';
2
- export default class ImagesDelete extends Command {
1
+ import { BaseCommand } from '../../index.js';
2
+ export default class ImagesDelete extends BaseCommand {
3
3
  static description: string;
4
4
  static enableJsonFlag: boolean;
5
5
  static examples: string[];
@@ -1,8 +1,9 @@
1
1
  import { getContext } from '../../../index.js';
2
- import { Command, Flags } from '@oclif/core';
2
+ import { Flags } from '@oclif/core';
3
3
  import { Listr } from 'listr2';
4
+ import { BaseCommand } from '../../index.js';
4
5
  import { deleteImage, listImages } from '../../../docker/index.js';
5
- export default class ImagesDelete extends Command {
6
+ export default class ImagesDelete extends BaseCommand {
6
7
  static description = 'Delete project images.';
7
8
  static enableJsonFlag = true;
8
9
  static examples = ['<%= config.bin %> <%= command.id %>'];
@@ -1,4 +1,4 @@
1
- import { Command } from '@oclif/core';
1
+ import { BaseCommand } 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 Command {
9
+ export default class ImagesIndex extends BaseCommand {
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
- import { Command, Flags } from '@oclif/core';
2
+ import { Flags } from '@oclif/core';
3
3
  import { printTable } from '@oclif/table';
4
- import { TABLE_DEFAULTS } from '../../index.js';
4
+ import { BaseCommand, 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 Command {
7
+ export default class ImagesIndex extends BaseCommand {
8
8
  static description = 'List docker images.';
9
9
  static enableJsonFlag = true;
10
10
  static examples = ['<%= config.bin %> <%= command.id %>'];
@@ -1,6 +1,6 @@
1
- import { Command } from '@oclif/core';
2
1
  import { PruneImagesInfo } from 'dockerode';
3
- export default class ImagesPrune extends Command {
2
+ import { BaseCommand } from '../../index.js';
3
+ export default class ImagesPrune extends BaseCommand {
4
4
  static description: string;
5
5
  static enableJsonFlag: boolean;
6
6
  static examples: string[];
@@ -1,7 +1,8 @@
1
1
  import { getContext } from '../../../index.js';
2
- import { Command, Flags } from '@oclif/core';
2
+ import { Flags } from '@oclif/core';
3
+ import { BaseCommand } from '../../index.js';
3
4
  import { pruneImages } from '../../../docker/index.js';
4
- export default class ImagesPrune extends Command {
5
+ export default class ImagesPrune extends BaseCommand {
5
6
  static description = 'Prune project images.';
6
7
  static enableJsonFlag = true;
7
8
  static examples = ['<%= config.bin %> <%= command.id %>'];
@@ -1,6 +1,6 @@
1
1
  import { FlavoredCommand } from '../../index.js';
2
- import { BuildComponentMeta } from '../../../monorepo/index.js';
3
- export default class BuildCommand extends FlavoredCommand<typeof BuildCommand> {
2
+ import { BuildResourceMeta } from '../../../monorepo/operations/resources/BuildResourcesOperation.js';
3
+ export default class ResourcesBuildCommand extends FlavoredCommand<typeof ResourcesBuildCommand> {
4
4
  static args: {
5
5
  component: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
6
6
  };
@@ -8,8 +8,9 @@ export default class BuildCommand extends FlavoredCommand<typeof BuildCommand> {
8
8
  static examples: string[];
9
9
  static flags: {
10
10
  'dry-run': import("@oclif/core/interfaces").BooleanFlag<boolean>;
11
+ force: import("@oclif/core/interfaces").BooleanFlag<boolean>;
11
12
  };
12
13
  static enableJsonFlag: boolean;
13
14
  static strict: boolean;
14
- run(): Promise<Record<string, BuildComponentMeta>>;
15
+ run(): Promise<Record<string, BuildResourceMeta>>;
15
16
  }
@@ -0,0 +1,42 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import { FlavoredCommand, getContext } from '../../index.js';
3
+ import { BuildResourcesOperation, } from '../../../monorepo/operations/resources/BuildResourcesOperation.js';
4
+ export default class ResourcesBuildCommand extends FlavoredCommand {
5
+ static args = {
6
+ component: Args.string({
7
+ description: 'List of resources to build (defaults to all)',
8
+ required: false,
9
+ }),
10
+ };
11
+ static description = 'Build the resources of the monorepo';
12
+ static examples = [
13
+ `<%= config.bin %> <%= command.id %> build --flavor development`,
14
+ ];
15
+ static flags = {
16
+ 'dry-run': Flags.boolean({
17
+ required: false,
18
+ description: 'Do not build the resources but only produce build meta information',
19
+ }),
20
+ force: Flags.boolean({
21
+ name: 'force',
22
+ char: 'f',
23
+ required: false,
24
+ description: 'Bypass the cache and force the build',
25
+ }),
26
+ };
27
+ static enableJsonFlag = true;
28
+ static strict = false;
29
+ async run() {
30
+ const { argv, flags } = await this.parse(ResourcesBuildCommand);
31
+ const { monorepo } = getContext();
32
+ const toBuild = argv.length > 0
33
+ ? argv
34
+ : monorepo.resources.map((c) => c.id);
35
+ return monorepo.run(new BuildResourcesOperation(), {
36
+ dryRun: flags['dry-run'],
37
+ force: flags.force,
38
+ silent: flags.json,
39
+ resources: toBuild,
40
+ });
41
+ }
42
+ }
@@ -0,0 +1,9 @@
1
+ import { FlavoredCommand } from '../../index.js';
2
+ import { ResourceConfig } from '../../../config/schema.js';
3
+ export default class ResourcesIndex extends FlavoredCommand<typeof ResourcesIndex> {
4
+ static description: string;
5
+ static enableJsonFlag: boolean;
6
+ static examples: string[];
7
+ static flags: {};
8
+ run(): Promise<Array<ResourceConfig>>;
9
+ }
@@ -0,0 +1,28 @@
1
+ import { printTable } from '@oclif/table';
2
+ import { FlavoredCommand, getContext, TABLE_DEFAULTS } from '../../index.js';
3
+ export default class ResourcesIndex extends FlavoredCommand {
4
+ static description = 'List resources.';
5
+ static enableJsonFlag = true;
6
+ static examples = ['<%= config.bin %> <%= command.id %>'];
7
+ static flags = {};
8
+ async run() {
9
+ const { flags } = await this.parse(ResourcesIndex);
10
+ const { monorepo } = await getContext();
11
+ const resources = await Promise.all(monorepo.resources.map(async (config) => {
12
+ return {
13
+ ...config,
14
+ };
15
+ }));
16
+ if (!flags.json) {
17
+ printTable({
18
+ ...TABLE_DEFAULTS,
19
+ columns: ['name', 'type', 'id'],
20
+ data: resources,
21
+ sort: {
22
+ name: 'asc',
23
+ },
24
+ });
25
+ }
26
+ return resources;
27
+ }
28
+ }
@@ -1,6 +1,6 @@
1
- import { Command } from '@oclif/core';
1
+ import { BaseCommand } from '../../index.js';
2
2
  import { TaskInfo } from '../../../monorepo/index.js';
3
- export default class TasksIndex extends Command {
3
+ export default class TasksIndex extends BaseCommand {
4
4
  static description: string;
5
5
  static enableJsonFlag: boolean;
6
6
  static examples: string[];
@@ -1,8 +1,7 @@
1
1
  import { getContext } from '../../../index.js';
2
- import { Command } from '@oclif/core';
3
2
  import { printTable } from '@oclif/table';
4
- import { TABLE_DEFAULTS } from '../../index.js';
5
- export default class TasksIndex extends Command {
3
+ import { BaseCommand, TABLE_DEFAULTS } from '../../index.js';
4
+ export default class TasksIndex extends BaseCommand {
6
5
  static description = 'List tasks.';
7
6
  static enableJsonFlag = true;
8
7
  static examples = ['<%= config.bin %> <%= command.id %>'];
@@ -10,7 +9,7 @@ export default class TasksIndex extends Command {
10
9
  async run() {
11
10
  const { flags } = await this.parse(TasksIndex);
12
11
  const { monorepo: { tasks }, } = await getContext();
13
- if (!flags.json)
12
+ if (!flags.json) {
14
13
  printTable({
15
14
  ...TABLE_DEFAULTS,
16
15
  columns: ['name', 'component', 'description', 'id'],
@@ -24,6 +23,7 @@ export default class TasksIndex extends Command {
24
23
  return 0;
25
24
  }),
26
25
  });
26
+ }
27
27
  return tasks;
28
28
  }
29
29
  }
@@ -1,5 +1,5 @@
1
- import { Command } from '@oclif/core';
2
- export default class RunTask extends Command {
1
+ import { BaseCommand } from '../../index.js';
2
+ export default class RunTask extends BaseCommand {
3
3
  static args: {
4
4
  task: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
5
5
  };
@@ -1,7 +1,8 @@
1
- import { AmbiguousTaskError, getContext } from '../../../index.js';
2
- import { Args, Command, Flags } from '@oclif/core';
1
+ import { AmbiguousReferenceError, getContext, UnkownReferenceError } from '../../../index.js';
2
+ import { Args, Flags } from '@oclif/core';
3
+ import { BaseCommand } from '../../index.js';
3
4
  import { ExecutorType, RunTasksOperation } from '../../../monorepo/index.js';
4
- export default class RunTask extends Command {
5
+ export default class RunTask extends BaseCommand {
5
6
  static args = {
6
7
  task: Args.string({
7
8
  description: 'List of tasks to run. You can provide either ids or names (eg: component:task or task)',
@@ -37,13 +38,19 @@ export default class RunTask extends Command {
37
38
  });
38
39
  }
39
40
  catch (error) {
40
- if (error instanceof AmbiguousTaskError) {
41
+ if (error instanceof AmbiguousReferenceError) {
41
42
  throw error.toCliError([
42
- `Specify just one. Eg: \`emb tasks run ${error.options[0]}\``,
43
+ `Specify just one. Eg: \`emb tasks run ${error.matches[0]}\``,
43
44
  'Run the same command with --all-matches / -a',
44
45
  'Review the list of tasks by running `emb tasks`',
45
46
  ]);
46
47
  }
48
+ if (error instanceof UnkownReferenceError) {
49
+ throw error.toCliError([
50
+ `Check the list of tasks available by running: \`emb tasks\``,
51
+ ]);
52
+ }
53
+ throw error;
47
54
  }
48
55
  }
49
56
  }