hereya-cli 0.19.0 → 0.20.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
@@ -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.19.0 linux-x64 node-v22.13.1
23
+ hereya-cli/0.20.0 linux-x64 node-v22.13.1
24
24
  $ hereya --help [COMMAND]
25
25
  USAGE
26
26
  $ hereya COMMAND
@@ -74,7 +74,7 @@ EXAMPLES
74
74
  $ hereya add cloudy/docker_postgres
75
75
  ```
76
76
 
77
- _See code: [src/commands/add/index.ts](https://github.com/hereya/hereya-cli/blob/v0.19.0/src/commands/add/index.ts)_
77
+ _See code: [src/commands/add/index.ts](https://github.com/hereya/hereya-cli/blob/v0.20.0/src/commands/add/index.ts)_
78
78
 
79
79
  ## `hereya bootstrap INFRASTRUCTURETYPE`
80
80
 
@@ -99,7 +99,7 @@ EXAMPLES
99
99
  $ hereya bootstrap local
100
100
  ```
101
101
 
102
- _See code: [src/commands/bootstrap/index.ts](https://github.com/hereya/hereya-cli/blob/v0.19.0/src/commands/bootstrap/index.ts)_
102
+ _See code: [src/commands/bootstrap/index.ts](https://github.com/hereya/hereya-cli/blob/v0.20.0/src/commands/bootstrap/index.ts)_
103
103
 
104
104
  ## `hereya deploy`
105
105
 
@@ -121,7 +121,7 @@ EXAMPLES
121
121
  $ hereya deploy
122
122
  ```
123
123
 
124
- _See code: [src/commands/deploy/index.ts](https://github.com/hereya/hereya-cli/blob/v0.19.0/src/commands/deploy/index.ts)_
124
+ _See code: [src/commands/deploy/index.ts](https://github.com/hereya/hereya-cli/blob/v0.20.0/src/commands/deploy/index.ts)_
125
125
 
126
126
  ## `hereya down`
127
127
 
@@ -144,7 +144,7 @@ EXAMPLES
144
144
  $ hereya down
145
145
  ```
146
146
 
147
- _See code: [src/commands/down/index.ts](https://github.com/hereya/hereya-cli/blob/v0.19.0/src/commands/down/index.ts)_
147
+ _See code: [src/commands/down/index.ts](https://github.com/hereya/hereya-cli/blob/v0.20.0/src/commands/down/index.ts)_
148
148
 
149
149
  ## `hereya env [NAME]`
150
150
 
@@ -175,7 +175,7 @@ EXAMPLES
175
175
  $ hereya env -w dev -l
176
176
  ```
177
177
 
178
- _See code: [src/commands/env/index.ts](https://github.com/hereya/hereya-cli/blob/v0.19.0/src/commands/env/index.ts)_
178
+ _See code: [src/commands/env/index.ts](https://github.com/hereya/hereya-cli/blob/v0.20.0/src/commands/env/index.ts)_
179
179
 
180
180
  ## `hereya env set [NAME]`
181
181
 
@@ -202,7 +202,7 @@ EXAMPLES
202
202
  $ hereya env set FOO -v bar -w dev
203
203
  ```
204
204
 
205
- _See code: [src/commands/env/set/index.ts](https://github.com/hereya/hereya-cli/blob/v0.19.0/src/commands/env/set/index.ts)_
205
+ _See code: [src/commands/env/set/index.ts](https://github.com/hereya/hereya-cli/blob/v0.20.0/src/commands/env/set/index.ts)_
206
206
 
207
207
  ## `hereya help [COMMAND]`
208
208
 
@@ -248,7 +248,7 @@ EXAMPLES
248
248
  $ hereya init myProject -w=defaultWorkspace --chdir=./myProject
249
249
  ```
250
250
 
251
- _See code: [src/commands/init/index.ts](https://github.com/hereya/hereya-cli/blob/v0.19.0/src/commands/init/index.ts)_
251
+ _See code: [src/commands/init/index.ts](https://github.com/hereya/hereya-cli/blob/v0.20.0/src/commands/init/index.ts)_
252
252
 
253
253
  ## `hereya remove PACKAGE`
254
254
 
@@ -272,7 +272,7 @@ EXAMPLES
272
272
  $ hereya remove cloudy/docker_postgres
273
273
  ```
274
274
 
275
- _See code: [src/commands/remove/index.ts](https://github.com/hereya/hereya-cli/blob/v0.19.0/src/commands/remove/index.ts)_
275
+ _See code: [src/commands/remove/index.ts](https://github.com/hereya/hereya-cli/blob/v0.20.0/src/commands/remove/index.ts)_
276
276
 
277
277
  ## `hereya run CMD`
278
278
 
@@ -298,7 +298,7 @@ EXAMPLES
298
298
  $ hereya run -w uat -- node index.js
299
299
  ```
300
300
 
301
- _See code: [src/commands/run/index.ts](https://github.com/hereya/hereya-cli/blob/v0.19.0/src/commands/run/index.ts)_
301
+ _See code: [src/commands/run/index.ts](https://github.com/hereya/hereya-cli/blob/v0.20.0/src/commands/run/index.ts)_
302
302
 
303
303
  ## `hereya unbootstrap INFRASTRUCTURETYPE`
304
304
 
@@ -323,7 +323,7 @@ EXAMPLES
323
323
  $ hereya unbootstrap local
324
324
  ```
325
325
 
326
- _See code: [src/commands/unbootstrap/index.ts](https://github.com/hereya/hereya-cli/blob/v0.19.0/src/commands/unbootstrap/index.ts)_
326
+ _See code: [src/commands/unbootstrap/index.ts](https://github.com/hereya/hereya-cli/blob/v0.20.0/src/commands/unbootstrap/index.ts)_
327
327
 
328
328
  ## `hereya undeploy`
329
329
 
@@ -345,7 +345,7 @@ EXAMPLES
345
345
  $ hereya undeploy
346
346
  ```
347
347
 
348
- _See code: [src/commands/undeploy/index.ts](https://github.com/hereya/hereya-cli/blob/v0.19.0/src/commands/undeploy/index.ts)_
348
+ _See code: [src/commands/undeploy/index.ts](https://github.com/hereya/hereya-cli/blob/v0.20.0/src/commands/undeploy/index.ts)_
349
349
 
350
350
  ## `hereya up`
351
351
 
@@ -368,7 +368,7 @@ EXAMPLES
368
368
  $ hereya up
369
369
  ```
370
370
 
371
- _See code: [src/commands/up/index.ts](https://github.com/hereya/hereya-cli/blob/v0.19.0/src/commands/up/index.ts)_
371
+ _See code: [src/commands/up/index.ts](https://github.com/hereya/hereya-cli/blob/v0.20.0/src/commands/up/index.ts)_
372
372
 
373
373
  ## `hereya workspace create NAME`
374
374
 
@@ -388,7 +388,7 @@ EXAMPLES
388
388
  $ hereya workspace create dev
389
389
  ```
390
390
 
391
- _See code: [src/commands/workspace/create/index.ts](https://github.com/hereya/hereya-cli/blob/v0.19.0/src/commands/workspace/create/index.ts)_
391
+ _See code: [src/commands/workspace/create/index.ts](https://github.com/hereya/hereya-cli/blob/v0.20.0/src/commands/workspace/create/index.ts)_
392
392
 
393
393
  ## `hereya workspace delete NAME`
394
394
 
@@ -408,7 +408,7 @@ EXAMPLES
408
408
  $ hereya workspace delete dev
409
409
  ```
410
410
 
411
- _See code: [src/commands/workspace/delete/index.ts](https://github.com/hereya/hereya-cli/blob/v0.19.0/src/commands/workspace/delete/index.ts)_
411
+ _See code: [src/commands/workspace/delete/index.ts](https://github.com/hereya/hereya-cli/blob/v0.20.0/src/commands/workspace/delete/index.ts)_
412
412
 
413
413
  ## `hereya workspace env [NAME]`
414
414
 
@@ -434,7 +434,7 @@ EXAMPLES
434
434
  $ hereya workspace env myEnv -w dev
435
435
  ```
436
436
 
437
- _See code: [src/commands/workspace/env/index.ts](https://github.com/hereya/hereya-cli/blob/v0.19.0/src/commands/workspace/env/index.ts)_
437
+ _See code: [src/commands/workspace/env/index.ts](https://github.com/hereya/hereya-cli/blob/v0.20.0/src/commands/workspace/env/index.ts)_
438
438
 
439
439
  ## `hereya workspace env set`
440
440
 
@@ -458,7 +458,7 @@ EXAMPLES
458
458
  $ hereya workspace env set -w my-workspace -n myVar -v my-value -i aws -s
459
459
  ```
460
460
 
461
- _See code: [src/commands/workspace/env/set/index.ts](https://github.com/hereya/hereya-cli/blob/v0.19.0/src/commands/workspace/env/set/index.ts)_
461
+ _See code: [src/commands/workspace/env/set/index.ts](https://github.com/hereya/hereya-cli/blob/v0.20.0/src/commands/workspace/env/set/index.ts)_
462
462
 
463
463
  ## `hereya workspace env unset`
464
464
 
@@ -479,7 +479,7 @@ EXAMPLES
479
479
  $ hereya workspace env unset -w my-workspace -n myVar
480
480
  ```
481
481
 
482
- _See code: [src/commands/workspace/env/unset/index.ts](https://github.com/hereya/hereya-cli/blob/v0.19.0/src/commands/workspace/env/unset/index.ts)_
482
+ _See code: [src/commands/workspace/env/unset/index.ts](https://github.com/hereya/hereya-cli/blob/v0.20.0/src/commands/workspace/env/unset/index.ts)_
483
483
 
484
484
  ## `hereya workspace install PACKAGE`
485
485
 
@@ -506,7 +506,7 @@ EXAMPLES
506
506
  $ hereya workspace install hereya/aws-cognito
507
507
  ```
508
508
 
509
- _See code: [src/commands/workspace/install/index.ts](https://github.com/hereya/hereya-cli/blob/v0.19.0/src/commands/workspace/install/index.ts)_
509
+ _See code: [src/commands/workspace/install/index.ts](https://github.com/hereya/hereya-cli/blob/v0.20.0/src/commands/workspace/install/index.ts)_
510
510
 
511
511
  ## `hereya workspace uninstall PACKAGE`
512
512
 
@@ -533,5 +533,5 @@ EXAMPLES
533
533
  $ hereya workspace uninstall hereya/aws-cognito
534
534
  ```
535
535
 
536
- _See code: [src/commands/workspace/uninstall/index.ts](https://github.com/hereya/hereya-cli/blob/v0.19.0/src/commands/workspace/uninstall/index.ts)_
536
+ _See code: [src/commands/workspace/uninstall/index.ts](https://github.com/hereya/hereya-cli/blob/v0.20.0/src/commands/workspace/uninstall/index.ts)_
537
537
  <!-- commandsstop -->
@@ -52,13 +52,13 @@ export default class Run extends Command {
52
52
  const { cmd } = args;
53
53
  const cmdArgs = argv.slice(1);
54
54
  this.log(`Running command "${cmd} ${cmdArgs.join(' ')}" ...`);
55
- const res = runShell(cmd, cmdArgs, {
55
+ const res = await runShell(cmd, cmdArgs, {
56
56
  directory: projectRootDir,
57
57
  env: { ...process.env, ...env },
58
58
  stdio: 'inherit',
59
59
  });
60
60
  if (res.status !== 0) {
61
- this.error(res.error?.message || 'Command failed');
61
+ this.error(res.stderr || 'Command failed');
62
62
  }
63
63
  }
64
64
  }
package/dist/iac/cdk.js CHANGED
@@ -7,7 +7,7 @@ export class Cdk {
7
7
  async apply(input) {
8
8
  try {
9
9
  const { remainingEnv, serializedParameters, serializedWorkspaceEnv } = await this.serializedParametersAndContext(input);
10
- runShell('npx', [
10
+ await runShell('npx', [
11
11
  'aws-cdk', 'deploy', '--require-approval', 'never', ...serializedWorkspaceEnv, ...serializedParameters,
12
12
  ], {
13
13
  directory: input.pkgPath,
@@ -27,7 +27,7 @@ export class Cdk {
27
27
  try {
28
28
  const env = await this.getEnv(input.id);
29
29
  const { remainingEnv, serializedParameters, serializedWorkspaceEnv } = await this.serializedParametersAndContext(input);
30
- runShell('npx', [
30
+ await runShell('npx', [
31
31
  'aws-cdk', 'destroy', '--force', ...serializedWorkspaceEnv, ...serializedParameters
32
32
  ], {
33
33
  directory: input.pkgPath,
@@ -52,14 +52,14 @@ export class Cdk {
52
52
  }
53
53
  async getParameterNames(input) {
54
54
  const workDir = input.pkgPath;
55
- runShell('npm', ['install'], { directory: workDir });
56
- runShell('npx', [
55
+ await runShell('npm', ['install'], { directory: workDir });
56
+ await runShell('npx', [
57
57
  'aws-cdk', 'synth',
58
58
  ], {
59
59
  directory: workDir,
60
60
  env: { ...input.env, ...input.parameters },
61
61
  });
62
- const result = runShell('npx', [
62
+ const result = await runShell('npx', [
63
63
  'aws-cdk', 'synth',
64
64
  ], {
65
65
  directory: workDir,
@@ -27,7 +27,7 @@ export class Terraform {
27
27
  }
28
28
  try {
29
29
  const terraform = await this.getTerraformBinary();
30
- runShell(terraform, ['init'], {
30
+ await runShell(terraform, ['init'], {
31
31
  directory: input.pkgPath,
32
32
  env: {
33
33
  ...mapObject(input.env ?? {}, (key, value) => [
@@ -41,7 +41,7 @@ export class Terraform {
41
41
  ]),
42
42
  },
43
43
  });
44
- runShell(terraform, ['apply', '-auto-approve'], {
44
+ await runShell(terraform, ['apply', '-auto-approve'], {
45
45
  directory: input.pkgPath,
46
46
  env: {
47
47
  ...mapObject(input.env ?? {}, (key, value) => [
@@ -71,7 +71,7 @@ export class Terraform {
71
71
  async destroy(input) {
72
72
  const terraform = await this.getTerraformBinary();
73
73
  try {
74
- runShell(terraform, ['init'], {
74
+ await runShell(terraform, ['init'], {
75
75
  directory: input.pkgPath,
76
76
  env: {
77
77
  ...mapObject(input.env ?? {}, (key, value) => [
@@ -86,7 +86,7 @@ export class Terraform {
86
86
  },
87
87
  });
88
88
  const env = await this.getEnv(input.pkgPath);
89
- runShell(terraform, ['destroy', '-auto-approve'], {
89
+ await runShell(terraform, ['destroy', '-auto-approve'], {
90
90
  directory: input.pkgPath,
91
91
  env: {
92
92
  ...mapObject(input.env ?? {}, (key, value) => [
@@ -170,11 +170,11 @@ export class Terraform {
170
170
  }
171
171
  async getEnv(pkgPath) {
172
172
  const terraform = await this.getTerraformBinary();
173
- const resourceOut = runShell(terraform, ['output', '--json'], {
173
+ const resourceOut = await runShell(terraform, ['output', '--json'], {
174
174
  directory: pkgPath,
175
175
  stdio: 'pipe',
176
176
  });
177
- let outStr = resourceOut.output.toString().trim();
177
+ let outStr = resourceOut.stdout.toString().trim();
178
178
  const start = outStr.indexOf('{');
179
179
  const end = outStr.lastIndexOf('}');
180
180
  outStr = outStr.slice(start, end + 1);
@@ -15,7 +15,7 @@ export class AwsInfrastructure {
15
15
  const stsClient = new STSClient({});
16
16
  const { Account: accountId } = await stsClient.send(new GetCallerIdentityCommand({}));
17
17
  const region = process.env.AWS_REGION || process.env.AWS_DEFAULT_REGION;
18
- runShell('npx', ['cdk', 'bootstrap', `aws://${accountId}/${region}`]);
18
+ await runShell('npx', ['cdk', 'bootstrap', `aws://${accountId}/${region}`]);
19
19
  const bootstrapPackage = 'hereya/bootstrap-aws-stack';
20
20
  const output = await provisionPackage({ package: bootstrapPackage });
21
21
  if (!output.success) {
@@ -1,10 +1,22 @@
1
- import { spawnSync, StdioOptions } from 'node:child_process';
1
+ import { SpawnOptions } from 'node:child_process';
2
2
  export declare function setDebug(value: boolean): void;
3
3
  export declare function isDebug(): boolean;
4
- export type RunShellOptions = {
4
+ export interface RunShellOptions {
5
5
  directory?: string;
6
6
  env?: NodeJS.ProcessEnv;
7
- stdio?: StdioOptions;
8
- };
9
- export declare function runShell(cmd: string, args: string[], options?: RunShellOptions): ReturnType<typeof spawnSync>;
7
+ logger?: typeof defaultLogger;
8
+ stdio?: SpawnOptions['stdio'];
9
+ }
10
+ export declare function runShell(cmd: string, args: string[], options?: RunShellOptions): Promise<{
11
+ pid: number;
12
+ signal: NodeJS.Signals | null;
13
+ status: null | number;
14
+ stderr: string;
15
+ stdout: string;
16
+ }>;
10
17
  export declare function delay(ms: number): Promise<unknown> | undefined;
18
+ export declare const defaultLogger: {
19
+ debug(message: string): void;
20
+ error(message: string): void;
21
+ info(message: string): void;
22
+ };
package/dist/lib/shell.js CHANGED
@@ -1,4 +1,4 @@
1
- import { spawnSync } from 'node:child_process';
1
+ import { spawn } from 'node:child_process';
2
2
  let debug = false;
3
3
  export function setDebug(value) {
4
4
  debug = value;
@@ -6,20 +6,62 @@ export function setDebug(value) {
6
6
  export function isDebug() {
7
7
  return debug;
8
8
  }
9
- export function runShell(cmd, args, options = {}) {
10
- // Run the command
11
- const result = spawnSync(cmd, args, {
12
- cwd: options.directory ?? process.cwd(),
13
- encoding: 'utf8',
14
- env: { ...process.env, ...options.env },
15
- shell: true,
16
- stdio: options.stdio ?? (isDebug() ? 'inherit' : 'ignore'),
9
+ // Asynchronous runShell that logs output using the provided logger.
10
+ export async function runShell(cmd, args, options = {}) {
11
+ return new Promise((resolve, reject) => {
12
+ // Use the provided logger or default to console.log
13
+ const logger = options.logger ?? defaultLogger;
14
+ const spawnOptions = {
15
+ cwd: options.directory ?? process.cwd(),
16
+ env: { ...process.env, ...options.env },
17
+ shell: true,
18
+ // If not explicitly set, use 'inherit' when debugging, or 'pipe' otherwise
19
+ stdio: options.stdio ?? (isDebug() ? 'inherit' : 'pipe'),
20
+ };
21
+ logger.debug(`Executing: ${cmd} ${args.join(' ')}`);
22
+ const child = spawn(cmd, args, spawnOptions);
23
+ // Buffers to accumulate output from the process.
24
+ let stdout = '';
25
+ let stderr = '';
26
+ if (child.stdout) {
27
+ child.stdout.on('data', (data) => {
28
+ const chunk = data.toString();
29
+ stdout += chunk;
30
+ logger.info(chunk);
31
+ });
32
+ }
33
+ if (child.stderr) {
34
+ child.stderr.on('data', (data) => {
35
+ const chunk = data.toString();
36
+ stderr += chunk;
37
+ logger.info(chunk);
38
+ });
39
+ }
40
+ child.on('error', (err) => {
41
+ logger.error(`Error: ${err.message}`);
42
+ reject(err);
43
+ });
44
+ let exitCode = null;
45
+ let exitSignal = null;
46
+ child.on('exit', (code, signal) => {
47
+ exitCode = code;
48
+ exitSignal = signal;
49
+ });
50
+ child.on('close', () => {
51
+ if (exitCode !== 0) {
52
+ const errorMsg = `Command "${cmd} ${args.join(' ')}" failed with exit code "${exitCode}"`;
53
+ logger.error(errorMsg);
54
+ return reject(new Error(errorMsg));
55
+ }
56
+ resolve({
57
+ pid: child.pid,
58
+ signal: exitSignal,
59
+ status: exitCode,
60
+ stderr,
61
+ stdout,
62
+ });
63
+ });
17
64
  });
18
- // Throw an error if the command failed
19
- if (result.status !== 0) {
20
- throw new Error(`Command "${cmd} ${args.join(' ')}" failed with exit code "${result.status}"`);
21
- }
22
- return result;
23
65
  }
24
66
  export function delay(ms) {
25
67
  if (process.env.NODE_ENV === 'test') {
@@ -29,3 +71,20 @@ export function delay(ms) {
29
71
  setTimeout(resolve, ms);
30
72
  });
31
73
  }
74
+ export const defaultLogger = {
75
+ debug(message) {
76
+ if (isDebug()) {
77
+ console.debug(message);
78
+ }
79
+ },
80
+ error(message) {
81
+ if (isDebug()) {
82
+ console.error(message);
83
+ }
84
+ },
85
+ info(message) {
86
+ if (isDebug()) {
87
+ console.info(message);
88
+ }
89
+ },
90
+ };
@@ -954,5 +954,5 @@
954
954
  ]
955
955
  }
956
956
  },
957
- "version": "0.19.0"
957
+ "version": "0.20.0"
958
958
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hereya-cli",
3
3
  "description": "Infrastructure as Package",
4
- "version": "0.19.0",
4
+ "version": "0.20.0",
5
5
  "author": "Hereya Developers",
6
6
  "bin": {
7
7
  "hereya": "./bin/run.js"