hereya-cli 0.4.2 → 0.4.4

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
@@ -20,7 +20,7 @@ $ npm install -g hereya-cli
20
20
  $ hereya COMMAND
21
21
  running command...
22
22
  $ hereya (--version)
23
- hereya-cli/0.4.2 linux-x64 node-v20.13.1
23
+ hereya-cli/0.4.4 linux-x64 node-v20.13.1
24
24
  $ hereya --help [COMMAND]
25
25
  USAGE
26
26
  $ hereya COMMAND
@@ -70,7 +70,7 @@ EXAMPLES
70
70
  $ hereya add cloudy/docker_postgres
71
71
  ```
72
72
 
73
- _See code: [src/commands/add/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.2/src/commands/add/index.ts)_
73
+ _See code: [src/commands/add/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.4/src/commands/add/index.ts)_
74
74
 
75
75
  ## `hereya bootstrap INFRASTRUCTURETYPE`
76
76
 
@@ -95,7 +95,7 @@ EXAMPLES
95
95
  $ hereya bootstrap local
96
96
  ```
97
97
 
98
- _See code: [src/commands/bootstrap/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.2/src/commands/bootstrap/index.ts)_
98
+ _See code: [src/commands/bootstrap/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.4/src/commands/bootstrap/index.ts)_
99
99
 
100
100
  ## `hereya deploy`
101
101
 
@@ -116,7 +116,7 @@ EXAMPLES
116
116
  $ hereya deploy
117
117
  ```
118
118
 
119
- _See code: [src/commands/deploy/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.2/src/commands/deploy/index.ts)_
119
+ _See code: [src/commands/deploy/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.4/src/commands/deploy/index.ts)_
120
120
 
121
121
  ## `hereya down`
122
122
 
@@ -137,7 +137,7 @@ EXAMPLES
137
137
  $ hereya down
138
138
  ```
139
139
 
140
- _See code: [src/commands/down/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.2/src/commands/down/index.ts)_
140
+ _See code: [src/commands/down/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.4/src/commands/down/index.ts)_
141
141
 
142
142
  ## `hereya env`
143
143
 
@@ -160,7 +160,7 @@ EXAMPLES
160
160
  $ hereya env -w dev
161
161
  ```
162
162
 
163
- _See code: [src/commands/env/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.2/src/commands/env/index.ts)_
163
+ _See code: [src/commands/env/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.4/src/commands/env/index.ts)_
164
164
 
165
165
  ## `hereya help [COMMAND]`
166
166
 
@@ -206,7 +206,7 @@ EXAMPLES
206
206
  $ hereya init myProject -w=defaultWorkspace --chdir=./myProject
207
207
  ```
208
208
 
209
- _See code: [src/commands/init/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.2/src/commands/init/index.ts)_
209
+ _See code: [src/commands/init/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.4/src/commands/init/index.ts)_
210
210
 
211
211
  ## `hereya remote exec [PKGPATH]`
212
212
 
@@ -230,7 +230,7 @@ EXAMPLES
230
230
  $ hereya remote exec
231
231
  ```
232
232
 
233
- _See code: [src/commands/remote/exec/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.2/src/commands/remote/exec/index.ts)_
233
+ _See code: [src/commands/remote/exec/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.4/src/commands/remote/exec/index.ts)_
234
234
 
235
235
  ## `hereya remove PACKAGE`
236
236
 
@@ -253,7 +253,7 @@ EXAMPLES
253
253
  $ hereya remove cloudy/docker_postgres
254
254
  ```
255
255
 
256
- _See code: [src/commands/remove/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.2/src/commands/remove/index.ts)_
256
+ _See code: [src/commands/remove/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.4/src/commands/remove/index.ts)_
257
257
 
258
258
  ## `hereya run CMD`
259
259
 
@@ -279,7 +279,7 @@ EXAMPLES
279
279
  $ hereya run -w uat -- node index.js
280
280
  ```
281
281
 
282
- _See code: [src/commands/run/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.2/src/commands/run/index.ts)_
282
+ _See code: [src/commands/run/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.4/src/commands/run/index.ts)_
283
283
 
284
284
  ## `hereya undeploy`
285
285
 
@@ -300,7 +300,7 @@ EXAMPLES
300
300
  $ hereya undeploy
301
301
  ```
302
302
 
303
- _See code: [src/commands/undeploy/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.2/src/commands/undeploy/index.ts)_
303
+ _See code: [src/commands/undeploy/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.4/src/commands/undeploy/index.ts)_
304
304
 
305
305
  ## `hereya up`
306
306
 
@@ -321,7 +321,7 @@ EXAMPLES
321
321
  $ hereya up
322
322
  ```
323
323
 
324
- _See code: [src/commands/up/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.2/src/commands/up/index.ts)_
324
+ _See code: [src/commands/up/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.4/src/commands/up/index.ts)_
325
325
 
326
326
  ## `hereya workspace create NAME`
327
327
 
@@ -341,7 +341,7 @@ EXAMPLES
341
341
  $ hereya workspace create dev
342
342
  ```
343
343
 
344
- _See code: [src/commands/workspace/create/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.2/src/commands/workspace/create/index.ts)_
344
+ _See code: [src/commands/workspace/create/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.4/src/commands/workspace/create/index.ts)_
345
345
 
346
346
  ## `hereya workspace delete NAME`
347
347
 
@@ -361,7 +361,7 @@ EXAMPLES
361
361
  $ hereya workspace delete dev
362
362
  ```
363
363
 
364
- _See code: [src/commands/workspace/delete/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.2/src/commands/workspace/delete/index.ts)_
364
+ _See code: [src/commands/workspace/delete/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.4/src/commands/workspace/delete/index.ts)_
365
365
 
366
366
  ## `hereya workspace env`
367
367
 
@@ -381,7 +381,7 @@ EXAMPLES
381
381
  $ hereya workspace env -w dev
382
382
  ```
383
383
 
384
- _See code: [src/commands/workspace/env/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.2/src/commands/workspace/env/index.ts)_
384
+ _See code: [src/commands/workspace/env/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.4/src/commands/workspace/env/index.ts)_
385
385
 
386
386
  ## `hereya workspace install PACKAGE`
387
387
 
@@ -407,7 +407,7 @@ EXAMPLES
407
407
  $ hereya workspace install hereya/aws-cognito
408
408
  ```
409
409
 
410
- _See code: [src/commands/workspace/install/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.2/src/commands/workspace/install/index.ts)_
410
+ _See code: [src/commands/workspace/install/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.4/src/commands/workspace/install/index.ts)_
411
411
 
412
412
  ## `hereya workspace uninstall PACKAGE`
413
413
 
@@ -433,5 +433,5 @@ EXAMPLES
433
433
  $ hereya workspace uninstall hereya/aws-cognito
434
434
  ```
435
435
 
436
- _See code: [src/commands/workspace/uninstall/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.2/src/commands/workspace/uninstall/index.ts)_
436
+ _See code: [src/commands/workspace/uninstall/index.ts](https://github.com/hereya/hereya-cli/blob/v0.4.4/src/commands/workspace/uninstall/index.ts)_
437
437
  <!-- commandsstop -->
package/dist/iac/cdk.d.ts CHANGED
@@ -5,4 +5,5 @@ export declare class Cdk implements Iac {
5
5
  private getEnv;
6
6
  private getParameterNames;
7
7
  private getStack;
8
+ private serializedParametersAndContext;
8
9
  }
package/dist/iac/cdk.js CHANGED
@@ -6,15 +6,9 @@ import { load } from '../lib/yaml-utils.js';
6
6
  export class Cdk {
7
7
  async apply(input) {
8
8
  try {
9
- const parameterNames = await this.getParameterNames(input.pkgPath);
10
- const serializedWorkspaceEnv = Object.entries(input.env)
11
- .filter(([key]) => parameterNames.includes(key))
12
- .flatMap(([key, value]) => ['--parameters', `${key}=${value}`]);
13
- const serializedParameters = Object.entries(input.parameters ?? {})
14
- .filter(([key]) => parameterNames.includes(key))
15
- .flatMap(([key, value]) => ['--parameters', `${key}=${value}`]);
9
+ const { serializedContext, serializedParameters, serializedWorkspaceEnv } = await this.serializedParametersAndContext(input);
16
10
  runShell('npx', [
17
- 'cdk', 'deploy', '--require-approval', 'never', ...serializedWorkspaceEnv, ...serializedParameters,
11
+ 'cdk', 'deploy', '--require-approval', 'never', ...serializedWorkspaceEnv, ...serializedParameters, ...serializedContext,
18
12
  ], {
19
13
  directory: input.pkgPath,
20
14
  env: { STACK_NAME: input.id },
@@ -29,15 +23,9 @@ export class Cdk {
29
23
  async destroy(input) {
30
24
  try {
31
25
  const env = await this.getEnv(input.id);
32
- const parameterNames = await this.getParameterNames(input.pkgPath);
33
- const serializedWorkspaceEnv = Object.entries(input.env)
34
- .filter(([key]) => parameterNames.includes(key))
35
- .flatMap(([key, value]) => ['--parameters', `${key}=${value}`]);
36
- const serializedParameters = Object.entries(input.parameters ?? {})
37
- .filter(([key]) => parameterNames.includes(key))
38
- .flatMap(([key, value]) => ['--parameters', `${key}=${value}`]);
26
+ const { serializedContext, serializedParameters, serializedWorkspaceEnv } = await this.serializedParametersAndContext(input);
39
27
  runShell('npx', [
40
- 'cdk', 'destroy', '--force', ...serializedWorkspaceEnv, ...serializedParameters,
28
+ 'cdk', 'destroy', '--force', ...serializedWorkspaceEnv, ...serializedParameters, ...serializedContext
41
29
  ], {
42
30
  directory: input.pkgPath,
43
31
  env: { STACK_NAME: input.id }
@@ -56,10 +44,15 @@ export class Cdk {
56
44
  }
57
45
  return env;
58
46
  }
59
- async getParameterNames(workDir) {
47
+ async getParameterNames(input) {
48
+ const workDir = input.pkgPath;
49
+ const serializedContext = Object.entries({
50
+ ...input.env,
51
+ ...input.parameters,
52
+ }).flatMap(([key, value]) => ['--context', `${key}=${value}`]);
60
53
  runShell('npm', ['install'], { directory: workDir });
61
54
  const result = runShell('npx', [
62
- 'cdk', 'synth',
55
+ 'cdk', 'synth', ...serializedContext,
63
56
  ], {
64
57
  directory: workDir,
65
58
  stdio: 'pipe'
@@ -71,13 +64,37 @@ export class Cdk {
71
64
  }
72
65
  async getStack(stackName) {
73
66
  const cfnClient = new CloudFormationClient({});
74
- const response = await cfnClient.send(new DescribeStacksCommand({
75
- StackName: stackName,
76
- }));
77
- const stack = response.Stacks?.[0];
67
+ let stack;
68
+ try {
69
+ const response = await cfnClient.send(new DescribeStacksCommand({
70
+ StackName: stackName,
71
+ }));
72
+ stack = response.Stacks?.[0];
73
+ }
74
+ catch (error) {
75
+ if (error.name === 'ValidationError') {
76
+ return null;
77
+ }
78
+ throw error;
79
+ }
78
80
  if (!stack) {
79
- throw new Error(`Stack ${stackName} not found`);
81
+ return null;
80
82
  }
81
83
  return stack;
82
84
  }
85
+ async serializedParametersAndContext(input) {
86
+ const parameterNames = await this.getParameterNames(input);
87
+ const serializedParameters = Object.entries(input.parameters ?? {})
88
+ .filter(([key]) => parameterNames.includes(key))
89
+ .flatMap(([key, value]) => ['--parameters', `${key}=${value}`]);
90
+ const serializedWorkspaceEnv = Object.entries(input.env)
91
+ .filter(([key]) => parameterNames.includes(key))
92
+ .flatMap(([key, value]) => ['--parameters', `${key}=${value}`]);
93
+ const serializedContext = Object.entries({
94
+ ...input.env,
95
+ ...input.parameters,
96
+ }).filter(([key]) => !parameterNames.includes(key))
97
+ .flatMap(([key, value]) => ['--context', `${key}=${value}`]);
98
+ return { serializedContext, serializedParameters, serializedWorkspaceEnv };
99
+ }
83
100
  }
@@ -149,10 +149,19 @@ export class AwsInfrastructure {
149
149
  async getEnv(id) {
150
150
  const ssmClient = new SSMClient({});
151
151
  const ssmParameterName = `/hereya/${id}`;
152
- const ssmParameter = await ssmClient.send(new GetParameterCommand({
153
- Name: ssmParameterName,
154
- }));
155
- return JSON.parse(ssmParameter.Parameter?.Value ?? '{}');
152
+ try {
153
+ const ssmParameter = await ssmClient.send(new GetParameterCommand({
154
+ Name: ssmParameterName,
155
+ }));
156
+ return JSON.parse(ssmParameter.Parameter?.Value ?? '{}');
157
+ }
158
+ catch (error) {
159
+ if (error.name === "ParameterNotFound") {
160
+ console.debug(`Parameter "${ssmParameterName}" does not exist.`);
161
+ return {};
162
+ }
163
+ throw error;
164
+ }
156
165
  }
157
166
  async getFilesToUpload(rootDir) {
158
167
  const ig = ignore.default();
@@ -699,5 +699,5 @@
699
699
  ]
700
700
  }
701
701
  },
702
- "version": "0.4.2"
702
+ "version": "0.4.4"
703
703
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hereya-cli",
3
3
  "description": "Developer's Package Manager for Seamless Infrastructure Integration.",
4
- "version": "0.4.2",
4
+ "version": "0.4.4",
5
5
  "author": "Hereya Developers",
6
6
  "bin": {
7
7
  "hereya": "./bin/run.js"