hereya-cli 0.2.1

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 (85) hide show
  1. package/README.md +392 -0
  2. package/bin/dev.cmd +3 -0
  3. package/bin/dev.js +6 -0
  4. package/bin/run.cmd +3 -0
  5. package/bin/run.js +5 -0
  6. package/dist/backend/common.d.ts +126 -0
  7. package/dist/backend/common.js +1 -0
  8. package/dist/backend/index.d.ts +4 -0
  9. package/dist/backend/index.js +5 -0
  10. package/dist/backend/local.d.ts +16 -0
  11. package/dist/backend/local.js +231 -0
  12. package/dist/commands/add/index.d.ts +13 -0
  13. package/dist/commands/add/index.js +96 -0
  14. package/dist/commands/bootstrap/index.d.ts +12 -0
  15. package/dist/commands/bootstrap/index.js +28 -0
  16. package/dist/commands/down/index.d.ts +10 -0
  17. package/dist/commands/down/index.js +78 -0
  18. package/dist/commands/env/index.d.ts +10 -0
  19. package/dist/commands/env/index.js +46 -0
  20. package/dist/commands/init/index.d.ts +13 -0
  21. package/dist/commands/init/index.js +46 -0
  22. package/dist/commands/remote/exec/index.d.ts +12 -0
  23. package/dist/commands/remote/exec/index.js +65 -0
  24. package/dist/commands/remove/index.d.ts +12 -0
  25. package/dist/commands/remove/index.js +80 -0
  26. package/dist/commands/run/index.d.ts +14 -0
  27. package/dist/commands/run/index.js +60 -0
  28. package/dist/commands/up/index.d.ts +10 -0
  29. package/dist/commands/up/index.js +121 -0
  30. package/dist/commands/workspace/create/index.d.ts +9 -0
  31. package/dist/commands/workspace/create/index.js +25 -0
  32. package/dist/commands/workspace/delete/index.d.ts +9 -0
  33. package/dist/commands/workspace/delete/index.js +24 -0
  34. package/dist/commands/workspace/env/index.d.ts +9 -0
  35. package/dist/commands/workspace/env/index.js +28 -0
  36. package/dist/commands/workspace/install/index.d.ts +14 -0
  37. package/dist/commands/workspace/install/index.js +74 -0
  38. package/dist/commands/workspace/uninstall/index.d.ts +14 -0
  39. package/dist/commands/workspace/uninstall/index.js +85 -0
  40. package/dist/iac/cdk.d.ts +8 -0
  41. package/dist/iac/cdk.js +83 -0
  42. package/dist/iac/common.d.ts +29 -0
  43. package/dist/iac/common.js +5 -0
  44. package/dist/iac/index.d.ts +16 -0
  45. package/dist/iac/index.js +18 -0
  46. package/dist/iac/terraform.d.ts +6 -0
  47. package/dist/iac/terraform.js +67 -0
  48. package/dist/index.d.ts +1 -0
  49. package/dist/index.js +1 -0
  50. package/dist/infrastructure/aws.d.ts +8 -0
  51. package/dist/infrastructure/aws.js +28 -0
  52. package/dist/infrastructure/common.d.ts +59 -0
  53. package/dist/infrastructure/common.js +7 -0
  54. package/dist/infrastructure/index.d.ts +43 -0
  55. package/dist/infrastructure/index.js +82 -0
  56. package/dist/infrastructure/local.d.ts +14 -0
  57. package/dist/infrastructure/local.js +81 -0
  58. package/dist/lib/config/common.d.ts +34 -0
  59. package/dist/lib/config/common.js +1 -0
  60. package/dist/lib/config/index.d.ts +3 -0
  61. package/dist/lib/config/index.js +5 -0
  62. package/dist/lib/config/simple.d.ts +8 -0
  63. package/dist/lib/config/simple.js +41 -0
  64. package/dist/lib/env/index.d.ts +27 -0
  65. package/dist/lib/env/index.js +42 -0
  66. package/dist/lib/env-utils.d.ts +8 -0
  67. package/dist/lib/env-utils.js +20 -0
  68. package/dist/lib/filesystem.d.ts +1 -0
  69. package/dist/lib/filesystem.js +15 -0
  70. package/dist/lib/object-utils.d.ts +4 -0
  71. package/dist/lib/object-utils.js +9 -0
  72. package/dist/lib/package/common.d.ts +15 -0
  73. package/dist/lib/package/common.js +1 -0
  74. package/dist/lib/package/github.d.ts +4 -0
  75. package/dist/lib/package/github.js +32 -0
  76. package/dist/lib/package/index.d.ts +30 -0
  77. package/dist/lib/package/index.js +45 -0
  78. package/dist/lib/parameter/index.d.ts +34 -0
  79. package/dist/lib/parameter/index.js +47 -0
  80. package/dist/lib/shell.d.ts +9 -0
  81. package/dist/lib/shell.js +16 -0
  82. package/dist/lib/yaml-utils.d.ts +5 -0
  83. package/dist/lib/yaml-utils.js +27 -0
  84. package/oclif.manifest.json +610 -0
  85. package/package.json +86 -0
@@ -0,0 +1,12 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class Remove extends Command {
3
+ static args: {
4
+ package: import("@oclif/core/lib/interfaces/parser.js").Arg<string, Record<string, unknown>>;
5
+ };
6
+ static description: string;
7
+ static examples: string[];
8
+ static flags: {
9
+ chdir: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
10
+ };
11
+ run(): Promise<void>;
12
+ }
@@ -0,0 +1,80 @@
1
+ import { Args, Command, Flags } from '@oclif/core';
2
+ import { getBackend } from '../../backend/index.js';
3
+ import { destroyPackage } from '../../infrastructure/index.js';
4
+ import { getConfigManager } from '../../lib/config/index.js';
5
+ import { getEnvManager } from '../../lib/env/index.js';
6
+ import { getParameterManager } from '../../lib/parameter/index.js';
7
+ export default class Remove extends Command {
8
+ static args = {
9
+ package: Args.string({
10
+ description: 'The package to remove. Packages are gitHub repositories. Use the format owner/repository',
11
+ required: true
12
+ }),
13
+ };
14
+ static description = 'Remove a package from the project.';
15
+ static examples = [
16
+ '<%= config.bin %> <%= command.id %> cloudy/docker_postgres',
17
+ ];
18
+ static flags = {
19
+ chdir: Flags.string({
20
+ description: 'directory to run command in',
21
+ required: false,
22
+ }),
23
+ };
24
+ async run() {
25
+ const { args, flags } = await this.parse(Remove);
26
+ const projectRootDir = flags.chdir || process.env.HEREYA_PROJECT_ROOT_DIR;
27
+ const configManager = getConfigManager();
28
+ const loadConfigOutput = await configManager.loadConfig({ projectRootDir });
29
+ if (!loadConfigOutput.found) {
30
+ this.warn(`Project not initialized. Run 'hereya init' first.`);
31
+ return;
32
+ }
33
+ const { config } = loadConfigOutput;
34
+ if (!(args.package in (config.packages ?? {}))) {
35
+ this.warn(`Package ${args.package} not found in project.`);
36
+ return;
37
+ }
38
+ const backend = await getBackend();
39
+ const getWorkspaceEnvOutput = await backend.getWorkspaceEnv({
40
+ project: config.project,
41
+ workspace: config.workspace,
42
+ });
43
+ if (!getWorkspaceEnvOutput.success) {
44
+ this.error(getWorkspaceEnvOutput.reason);
45
+ }
46
+ const { env: workspaceEnv } = getWorkspaceEnvOutput;
47
+ const parameterManager = getParameterManager();
48
+ const { parameters } = await parameterManager.getPackageParameters({
49
+ package: args.package,
50
+ projectRootDir,
51
+ workspace: config.workspace,
52
+ });
53
+ const destroyOutput = await destroyPackage({
54
+ env: workspaceEnv,
55
+ package: args.package,
56
+ parameters,
57
+ project: config.project,
58
+ workspace: config.workspace,
59
+ });
60
+ if (!destroyOutput.success) {
61
+ this.error(destroyOutput.reason);
62
+ }
63
+ const { env, metadata } = destroyOutput;
64
+ this.log(`Infrastructure resources for ${args.package} have been destroyed`);
65
+ this.log('removing package env vars from project');
66
+ const envManager = getEnvManager();
67
+ await envManager.removeProjectEnv({
68
+ env,
69
+ infra: metadata.infra,
70
+ projectRootDir,
71
+ workspace: config.workspace
72
+ });
73
+ await configManager.removePackage({
74
+ package: args.package,
75
+ projectRootDir
76
+ });
77
+ const { config: newConfig } = await configManager.loadConfig({ projectRootDir });
78
+ await backend.saveState(newConfig);
79
+ }
80
+ }
@@ -0,0 +1,14 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class Run extends Command {
3
+ static args: {
4
+ cmd: import("@oclif/core/lib/interfaces/parser.js").Arg<string, Record<string, unknown>>;
5
+ };
6
+ static description: string;
7
+ static examples: string[];
8
+ static flags: {
9
+ chdir: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
10
+ workspace: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
11
+ };
12
+ static strict: boolean;
13
+ run(): Promise<void>;
14
+ }
@@ -0,0 +1,60 @@
1
+ import { Args, Command, Flags } from '@oclif/core';
2
+ import { getConfigManager } from '../../lib/config/index.js';
3
+ import { getEnvManager } from '../../lib/env/index.js';
4
+ import { runShell } from '../../lib/shell.js';
5
+ export default class Run extends Command {
6
+ static args = {
7
+ cmd: Args.string({ description: 'command to run', required: true }),
8
+ };
9
+ static description = 'Run a command with hereya env vars.';
10
+ static examples = [
11
+ '<%= config.bin %> <%= command.id %> -- npm run dev',
12
+ '<%= config.bin %> <%= command.id %> -w uat -- node index.js',
13
+ ];
14
+ static flags = {
15
+ chdir: Flags.string({
16
+ description: 'directory to run command in',
17
+ required: false,
18
+ }),
19
+ workspace: Flags.string({
20
+ char: 'w',
21
+ description: 'name of the workspace to run the command in',
22
+ required: false,
23
+ }),
24
+ };
25
+ static strict = false;
26
+ async run() {
27
+ const { args, argv, flags } = await this.parse(Run);
28
+ const projectRootDir = flags.chdir || process.env.HEREYA_PROJECT_ROOT_DIR;
29
+ const configManager = getConfigManager();
30
+ const loadConfigOutput = await configManager.loadConfig({ projectRootDir });
31
+ if (!loadConfigOutput.found) {
32
+ this.warn(`Project not initialized. Run 'hereya init' first.`);
33
+ return;
34
+ }
35
+ const { config } = loadConfigOutput;
36
+ let { workspace } = flags;
37
+ if (!workspace) {
38
+ workspace = config.workspace;
39
+ }
40
+ if (!workspace) {
41
+ this.error('you must specify a workspace to run the command in');
42
+ }
43
+ const envManager = getEnvManager();
44
+ const { env } = await envManager.getProjectEnv({
45
+ projectRootDir,
46
+ workspace,
47
+ });
48
+ const { cmd } = args;
49
+ const cmdArgs = argv.slice(1);
50
+ this.log(`Running command "${cmd} ${cmdArgs.join(' ')}" ...`);
51
+ const res = runShell(cmd, cmdArgs, {
52
+ directory: projectRootDir,
53
+ env: { ...process.env, ...env },
54
+ stdio: 'inherit',
55
+ });
56
+ if (res.status !== 0) {
57
+ this.error(res.error?.message || 'Command failed');
58
+ }
59
+ }
60
+ }
@@ -0,0 +1,10 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class Up extends Command {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ chdir: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
7
+ workspace: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
8
+ };
9
+ run(): Promise<void>;
10
+ }
@@ -0,0 +1,121 @@
1
+ import { Command, Flags } from '@oclif/core';
2
+ import { getBackend } from '../../backend/index.js';
3
+ import { destroyPackage, provisionPackage } from '../../infrastructure/index.js';
4
+ import { getConfigManager } from '../../lib/config/index.js';
5
+ import { getEnvManager } from '../../lib/env/index.js';
6
+ import { getParameterManager } from '../../lib/parameter/index.js';
7
+ export default class Up extends Command {
8
+ static description = 'Provision all packages in the project.';
9
+ static examples = [
10
+ '<%= config.bin %> <%= command.id %>',
11
+ ];
12
+ static flags = {
13
+ chdir: Flags.string({
14
+ description: 'directory to run command in',
15
+ required: false,
16
+ }),
17
+ workspace: Flags.string({
18
+ char: 'w',
19
+ description: 'name of the workspace to install the packages for',
20
+ required: false,
21
+ }),
22
+ };
23
+ async run() {
24
+ const { flags } = await this.parse(Up);
25
+ const projectRootDir = flags.chdir || process.env.HEREYA_PROJECT_ROOT_DIR;
26
+ const configManager = getConfigManager();
27
+ const loadConfigOutput = await configManager.loadConfig({ projectRootDir });
28
+ if (!loadConfigOutput.found) {
29
+ this.warn(`Project not initialized. Run 'hereya init' first.`);
30
+ return;
31
+ }
32
+ const { config } = loadConfigOutput;
33
+ const packages = Object.keys(config.packages ?? {});
34
+ const backend = await getBackend();
35
+ const savedStateOutput = await backend.getState({
36
+ project: config.project,
37
+ });
38
+ let savedPackages = [];
39
+ if (savedStateOutput.found) {
40
+ savedPackages = Object.keys(savedStateOutput.config.packages ?? {});
41
+ }
42
+ const removedPackages = savedPackages.filter((packageName) => !packages.includes(packageName));
43
+ const workspace = flags.workspace || config.workspace;
44
+ const getWorkspaceEnvOutput = await backend.getWorkspaceEnv({
45
+ project: config.project,
46
+ workspace,
47
+ });
48
+ if (!getWorkspaceEnvOutput.success) {
49
+ this.error(getWorkspaceEnvOutput.reason);
50
+ }
51
+ const { env: workspaceEnv } = getWorkspaceEnvOutput;
52
+ const parameterManager = getParameterManager();
53
+ const removed = await Promise.all(removedPackages.map(async (packageName) => {
54
+ const { parameters } = await parameterManager.getPackageParameters({
55
+ package: packageName,
56
+ projectRootDir,
57
+ workspace,
58
+ });
59
+ const destroyOutput = await destroyPackage({
60
+ env: workspaceEnv,
61
+ package: packageName,
62
+ parameters,
63
+ project: config.project,
64
+ workspace,
65
+ });
66
+ if (!destroyOutput.success) {
67
+ this.error(destroyOutput.reason);
68
+ }
69
+ this.log(`Package ${packageName} destroyed successfully`);
70
+ const { env, metadata } = destroyOutput;
71
+ return { env, metadata, packageName };
72
+ }));
73
+ const added = await Promise.all(packages.map(async (packageName) => {
74
+ const { parameters } = await parameterManager.getPackageParameters({
75
+ package: packageName,
76
+ projectRootDir,
77
+ workspace,
78
+ });
79
+ const provisionOutput = await provisionPackage({
80
+ env: workspaceEnv,
81
+ package: packageName,
82
+ parameters,
83
+ project: config.project,
84
+ workspace,
85
+ });
86
+ if (!provisionOutput.success) {
87
+ this.error(provisionOutput.reason);
88
+ }
89
+ const { env, metadata } = provisionOutput;
90
+ this.log(`Package ${packageName} provisioned successfully`);
91
+ return { env, metadata, packageName };
92
+ }));
93
+ const envManager = getEnvManager();
94
+ for (const { env, metadata, packageName } of removed) {
95
+ // eslint-disable-next-line no-await-in-loop
96
+ await Promise.all([
97
+ envManager.removeProjectEnv({
98
+ env,
99
+ infra: metadata.infra,
100
+ projectRootDir,
101
+ workspace,
102
+ }),
103
+ configManager.removePackage({
104
+ package: packageName,
105
+ projectRootDir,
106
+ })
107
+ ]);
108
+ }
109
+ for (const { env, metadata } of added) {
110
+ // eslint-disable-next-line no-await-in-loop
111
+ await envManager.addProjectEnv({
112
+ env,
113
+ infra: metadata.infra,
114
+ projectRootDir,
115
+ workspace,
116
+ });
117
+ }
118
+ const { config: newConfig } = await configManager.loadConfig({ projectRootDir });
119
+ await backend.saveState(newConfig);
120
+ }
121
+ }
@@ -0,0 +1,9 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class WorkspaceCreate extends Command {
3
+ static args: {
4
+ name: import("@oclif/core/lib/interfaces/parser.js").Arg<string, Record<string, unknown>>;
5
+ };
6
+ static description: string;
7
+ static examples: string[];
8
+ run(): Promise<void>;
9
+ }
@@ -0,0 +1,25 @@
1
+ import { Args, Command } from '@oclif/core';
2
+ import { getBackend } from '../../../backend/index.js';
3
+ export default class WorkspaceCreate extends Command {
4
+ static args = {
5
+ name: Args.string({ description: 'name of the workspace to create', required: true }),
6
+ };
7
+ static description = 'Create a new workspace if it does not exist.';
8
+ static examples = [
9
+ '<%= config.bin %> <%= command.id %> dev',
10
+ ];
11
+ async run() {
12
+ const { args } = await this.parse(WorkspaceCreate);
13
+ const backend = await getBackend();
14
+ const createWorkspaceOutput = await backend.createWorkspace({ name: args.name });
15
+ if (!createWorkspaceOutput.success) {
16
+ this.error(`Failed to create workspace: ${createWorkspaceOutput.reason}`);
17
+ }
18
+ if (createWorkspaceOutput.isNew) {
19
+ this.log(`Workspace ${createWorkspaceOutput.workspace.name} created successfully!`);
20
+ }
21
+ else {
22
+ this.warn(`Workspace ${createWorkspaceOutput.workspace.name} already exists.`);
23
+ }
24
+ }
25
+ }
@@ -0,0 +1,9 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class WorkspaceDelete extends Command {
3
+ static args: {
4
+ name: import("@oclif/core/lib/interfaces/parser.js").Arg<string, Record<string, unknown>>;
5
+ };
6
+ static description: string;
7
+ static examples: string[];
8
+ run(): Promise<void>;
9
+ }
@@ -0,0 +1,24 @@
1
+ import { Args, Command } from '@oclif/core';
2
+ import { getBackend } from '../../../backend/index.js';
3
+ export default class WorkspaceDelete extends Command {
4
+ static args = {
5
+ name: Args.string({ description: 'name of the workspace to delete', required: true }),
6
+ };
7
+ static description = 'Delete a workspace if it exists.';
8
+ static examples = [
9
+ '<%= config.bin %> <%= command.id %> dev',
10
+ ];
11
+ async run() {
12
+ const { args } = await this.parse(WorkspaceDelete);
13
+ const backend = await getBackend();
14
+ const output = await backend.deleteWorkspace({ name: args.name });
15
+ if (!output.success) {
16
+ this.error(`Failed to delete workspace: ${output.reason}`);
17
+ }
18
+ if (output.message) {
19
+ this.log(output.message);
20
+ return;
21
+ }
22
+ this.log(`Workspace ${args.name} deleted successfully!`);
23
+ }
24
+ }
@@ -0,0 +1,9 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class WorkspaceEnv extends Command {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ workspace: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
7
+ };
8
+ run(): Promise<void>;
9
+ }
@@ -0,0 +1,28 @@
1
+ import { Command, Flags } from '@oclif/core';
2
+ import { getBackend } from '../../../backend/index.js';
3
+ import { logEnv } from '../../../lib/env-utils.js';
4
+ export default class WorkspaceEnv extends Command {
5
+ static description = 'Print workspace env vars.';
6
+ static examples = [
7
+ '<%= config.bin %> <%= command.id %> -w dev',
8
+ ];
9
+ static flags = {
10
+ workspace: Flags.string({
11
+ char: 'w',
12
+ description: 'name of the workspace to print env vars for',
13
+ required: true,
14
+ }),
15
+ };
16
+ async run() {
17
+ const { flags } = await this.parse(WorkspaceEnv);
18
+ const backend = await getBackend();
19
+ const getWorkspaceEnvOutput = await backend.getWorkspaceEnv({
20
+ workspace: flags.workspace,
21
+ });
22
+ if (!getWorkspaceEnvOutput.success) {
23
+ this.error(getWorkspaceEnvOutput.reason);
24
+ }
25
+ const { env } = getWorkspaceEnvOutput;
26
+ logEnv(env);
27
+ }
28
+ }
@@ -0,0 +1,14 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class WorkspaceInstall extends Command {
3
+ static args: {
4
+ package: import("@oclif/core/lib/interfaces/parser.js").Arg<string, Record<string, unknown>>;
5
+ };
6
+ static description: string;
7
+ static examples: string[];
8
+ static flags: {
9
+ parameter: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string[], import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
10
+ 'parameter-file': import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
11
+ workspace: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
12
+ };
13
+ run(): Promise<void>;
14
+ }
@@ -0,0 +1,74 @@
1
+ import { Args, Command, Flags } from '@oclif/core';
2
+ import { getBackend } from '../../../backend/index.js';
3
+ import { provisionPackage } from '../../../infrastructure/index.js';
4
+ import { arrayOfStringToObject } from '../../../lib/object-utils.js';
5
+ import { load } from '../../../lib/yaml-utils.js';
6
+ export default class WorkspaceInstall extends Command {
7
+ static args = {
8
+ package: Args.string({
9
+ description: 'The package to add. Packages are gitHub repositories. Use the format owner/repository',
10
+ required: true
11
+ }),
12
+ };
13
+ static description = 'Add a package to the workspace.';
14
+ static examples = [
15
+ '<%= config.bin %> <%= command.id %> hereya/aws-cognito',
16
+ ];
17
+ static flags = {
18
+ parameter: Flags.string({
19
+ char: 'p',
20
+ default: [],
21
+ description: 'parameter for the package, in the form of \'key=value\'. Can be specified multiple times.',
22
+ multiple: true,
23
+ }),
24
+ 'parameter-file': Flags.string({
25
+ char: 'f',
26
+ description: 'path to a file containing parameters for the package',
27
+ }),
28
+ workspace: Flags.string({
29
+ char: 'w',
30
+ description: 'name of the workspace to add the package to',
31
+ required: true,
32
+ }),
33
+ };
34
+ async run() {
35
+ const { args, flags } = await this.parse(WorkspaceInstall);
36
+ const backend = await getBackend();
37
+ const loadWorkspaceOutput = await backend.getWorkspace(flags.workspace);
38
+ if (!loadWorkspaceOutput.found || loadWorkspaceOutput.hasError) {
39
+ this.error(`Workspace ${flags.workspace} not found`);
40
+ }
41
+ const parametersInCmdline = arrayOfStringToObject(flags.parameter);
42
+ let parametersFromFile = {};
43
+ if (flags['parameter-file']) {
44
+ const { data, found } = await load(flags['parameter-file']);
45
+ if (!found) {
46
+ this.error(`Parameter file ${flags['parameter-file']} not found`);
47
+ }
48
+ parametersFromFile = data;
49
+ }
50
+ const parameters = { ...parametersFromFile, ...parametersInCmdline };
51
+ const provisionOutput = await provisionPackage({
52
+ package: args.package,
53
+ parameters,
54
+ workspace: flags.workspace,
55
+ });
56
+ if (!provisionOutput.success) {
57
+ this.error(provisionOutput.reason);
58
+ }
59
+ const { env, metadata } = provisionOutput;
60
+ this.log(`Package ${args.package} provisioned successfully`);
61
+ this.log(`Saving exported environment variables to workspace ${flags.workspace}...`);
62
+ const output = await backend.addPackageToWorkspace({
63
+ env,
64
+ infra: metadata.infra,
65
+ package: args.package,
66
+ parameters,
67
+ workspace: flags.workspace,
68
+ });
69
+ if (!output.success) {
70
+ this.error(output.reason);
71
+ }
72
+ this.log(`Package ${args.package} added to workspace ${flags.workspace}`);
73
+ }
74
+ }
@@ -0,0 +1,14 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class WorkspaceUninstall extends Command {
3
+ static args: {
4
+ package: import("@oclif/core/lib/interfaces/parser.js").Arg<string, Record<string, unknown>>;
5
+ };
6
+ static description: string;
7
+ static examples: string[];
8
+ static flags: {
9
+ parameter: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string[], import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
10
+ 'parameter-file': import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
11
+ workspace: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
12
+ };
13
+ run(): Promise<void>;
14
+ }
@@ -0,0 +1,85 @@
1
+ import { Args, Command, Flags } from '@oclif/core';
2
+ import { getBackend } from '../../../backend/index.js';
3
+ import { destroyPackage } from '../../../infrastructure/index.js';
4
+ import { arrayOfStringToObject } from '../../../lib/object-utils.js';
5
+ import { load } from '../../../lib/yaml-utils.js';
6
+ export default class WorkspaceUninstall extends Command {
7
+ static args = {
8
+ package: Args.string({
9
+ description: 'The package to remove. Packages are gitHub repositories. Use the format owner/repository',
10
+ required: true
11
+ }),
12
+ };
13
+ static description = 'Remove a package from a workspace.';
14
+ static examples = [
15
+ '<%= config.bin %> <%= command.id %> hereya/aws-cognito',
16
+ ];
17
+ static flags = {
18
+ parameter: Flags.string({
19
+ char: 'p',
20
+ default: [],
21
+ description: 'parameter for the package, in the form of \'key=value\'. Can be specified multiple times.',
22
+ multiple: true,
23
+ }),
24
+ 'parameter-file': Flags.string({
25
+ char: 'f',
26
+ description: 'path to a file containing parameters for the package',
27
+ }),
28
+ workspace: Flags.string({
29
+ char: 'w',
30
+ description: 'name of the workspace to remove the package from',
31
+ required: true,
32
+ }),
33
+ };
34
+ async run() {
35
+ const { args, flags } = await this.parse(WorkspaceUninstall);
36
+ const backend = await getBackend();
37
+ const loadWorkspaceOutput = await backend.getWorkspace(flags.workspace);
38
+ if (!loadWorkspaceOutput.found) {
39
+ this.error(`Workspace ${flags.workspace} not found`);
40
+ }
41
+ if (loadWorkspaceOutput.hasError) {
42
+ this.error(`Error loading workspace ${flags.workspace}: ${loadWorkspaceOutput.error}`);
43
+ }
44
+ const { workspace } = loadWorkspaceOutput;
45
+ if (!(args.package in (workspace.packages ?? {}))) {
46
+ this.log(`Package ${args.package} not found in workspace ${flags.workspace}`);
47
+ return;
48
+ }
49
+ const parametersInCmdline = arrayOfStringToObject(flags.parameter);
50
+ let parametersFromFile = {};
51
+ if (flags['parameter-file']) {
52
+ const { data, found } = await load(flags['parameter-file']);
53
+ if (!found) {
54
+ this.error(`Parameter file ${flags['parameter-file']} not found`);
55
+ }
56
+ parametersFromFile = data;
57
+ }
58
+ const parameters = {
59
+ ...workspace.packages?.[args.package].parameters,
60
+ ...parametersFromFile,
61
+ ...parametersInCmdline
62
+ };
63
+ const destroyOutput = await destroyPackage({
64
+ package: args.package,
65
+ parameters,
66
+ workspace: flags.workspace,
67
+ });
68
+ if (!destroyOutput.success) {
69
+ this.error(destroyOutput.reason);
70
+ }
71
+ const { env, metadata } = destroyOutput;
72
+ this.log(`Package ${args.package} removed successfully`);
73
+ this.log(`removing exported environment variables from workspace ${flags.workspace}...`);
74
+ const output = await backend.removePackageFromWorkspace({
75
+ env,
76
+ infra: metadata.infra,
77
+ package: args.package,
78
+ workspace: flags.workspace,
79
+ });
80
+ if (!output.success) {
81
+ this.error(output.reason);
82
+ }
83
+ this.log(`Package ${args.package} removed from workspace ${flags.workspace}`);
84
+ }
85
+ }
@@ -0,0 +1,8 @@
1
+ import { ApplyInput, ApplyOutput, DestroyInput, DestroyOutput, Iac } from './common.js';
2
+ export declare class Cdk implements Iac {
3
+ apply(input: ApplyInput): Promise<ApplyOutput>;
4
+ destroy(input: DestroyInput): Promise<DestroyOutput>;
5
+ private getEnv;
6
+ private getParameterNames;
7
+ private getStack;
8
+ }