@augment-vir/node 30.0.0 → 30.0.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 (61) hide show
  1. package/README.md +7 -10
  2. package/dist/augments/docker.d.ts +49 -2
  3. package/dist/augments/docker.js +48 -2
  4. package/dist/augments/fs/download.d.ts +11 -0
  5. package/dist/augments/{download.js → fs/download.js} +7 -0
  6. package/dist/augments/fs/json.d.ts +42 -0
  7. package/dist/augments/fs/json.js +34 -0
  8. package/dist/augments/fs/read-dir.d.ts +11 -3
  9. package/dist/augments/fs/read-dir.js +11 -3
  10. package/dist/augments/fs/read-file.d.ts +8 -0
  11. package/dist/augments/fs/read-file.js +8 -0
  12. package/dist/augments/fs/symlink.d.ts +7 -0
  13. package/dist/augments/fs/symlink.js +7 -0
  14. package/dist/augments/fs/write.d.ts +4 -0
  15. package/dist/augments/fs/write.js +4 -0
  16. package/dist/augments/npm/query-workspace.d.ts +14 -0
  17. package/dist/augments/npm/query-workspace.js +8 -1
  18. package/dist/augments/npm/read-package-json.d.ts +9 -0
  19. package/dist/augments/npm/read-package-json.js +9 -0
  20. package/dist/augments/os/operating-system.d.ts +15 -0
  21. package/dist/augments/os/operating-system.js +15 -0
  22. package/dist/augments/path/ancestor.d.ts +19 -0
  23. package/dist/augments/path/ancestor.js +28 -0
  24. package/dist/augments/path/os-path.d.ts +19 -3
  25. package/dist/augments/path/os-path.js +19 -3
  26. package/dist/augments/path/root.d.ts +7 -0
  27. package/dist/augments/path/root.js +7 -0
  28. package/dist/augments/prisma.d.ts +75 -1
  29. package/dist/augments/prisma.js +74 -1
  30. package/dist/augments/terminal/question.d.ts +50 -0
  31. package/dist/augments/{console → terminal}/question.js +23 -2
  32. package/dist/augments/{shell.d.ts → terminal/shell.d.ts} +87 -4
  33. package/dist/augments/{shell.js → terminal/shell.js} +63 -3
  34. package/dist/docker/containers/container-info.d.ts +35 -6
  35. package/dist/docker/containers/container-info.js +1 -7
  36. package/dist/docker/containers/container-status.d.ts +15 -0
  37. package/dist/docker/containers/container-status.js +16 -1
  38. package/dist/docker/containers/copy-to-container.d.ts +7 -0
  39. package/dist/docker/containers/copy-to-container.js +1 -1
  40. package/dist/docker/containers/docker-command-inputs.d.ts +54 -0
  41. package/dist/docker/containers/docker-command-inputs.js +9 -0
  42. package/dist/docker/containers/kill-container.js +1 -1
  43. package/dist/docker/containers/run-command.d.ts +8 -2
  44. package/dist/docker/containers/run-command.js +1 -2
  45. package/dist/docker/containers/run-container.d.ts +7 -0
  46. package/dist/docker/containers/run-container.js +1 -1
  47. package/dist/docker/docker-image.js +1 -1
  48. package/dist/docker/docker-startup.js +1 -2
  49. package/dist/index.d.ts +3 -3
  50. package/dist/index.js +3 -3
  51. package/dist/prisma/prisma-client.d.ts +0 -4
  52. package/dist/prisma/prisma-client.js +0 -4
  53. package/dist/prisma/prisma-errors.d.ts +25 -0
  54. package/dist/prisma/prisma-errors.js +25 -0
  55. package/dist/prisma/prisma-migrations.d.ts +12 -6
  56. package/dist/prisma/prisma-migrations.js +1 -7
  57. package/dist/prisma/run-prisma-command.d.ts +1 -1
  58. package/dist/prisma/run-prisma-command.js +1 -1
  59. package/package.json +16 -6
  60. package/dist/augments/console/question.d.ts +0 -14
  61. package/dist/augments/download.d.ts +0 -4
@@ -1,9 +1,25 @@
1
- /** Convert a given path to a windows path if the current system doesn't use `/`. */
1
+ /**
2
+ * Convert a given path to a windows path if the current system doesn't use `/`.
3
+ *
4
+ * @category Path : Node
5
+ * @category Package : @augment-vir/node
6
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
7
+ */
2
8
  export declare function replaceWithWindowsPathIfNeeded(input: string): string;
3
- /** Convert a Windows path to a posix path. */
9
+ /**
10
+ * Convert a Windows path to a posix path.
11
+ *
12
+ * @category Path : Node
13
+ * @category Package : @augment-vir/node
14
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
15
+ */
4
16
  export declare function toPosixPath(maybeWindowsPath: string): string;
5
17
  /**
6
- * Use this to interpolate paths into bash commands. If the given path is not a window path, the
18
+ * Use this to interpolate paths into bash commands. If the given path is not a Windows path, the
7
19
  * path structure will not be modified.
20
+ *
21
+ * @category Path : Node
22
+ * @category Package : @augment-vir/node
23
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
8
24
  */
9
25
  export declare function interpolationSafeWindowsPath(input: string): string;
@@ -1,5 +1,11 @@
1
1
  import { sep } from 'node:path';
2
- /** Convert a given path to a windows path if the current system doesn't use `/`. */
2
+ /**
3
+ * Convert a given path to a windows path if the current system doesn't use `/`.
4
+ *
5
+ * @category Path : Node
6
+ * @category Package : @augment-vir/node
7
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
8
+ */
3
9
  export function replaceWithWindowsPathIfNeeded(input) {
4
10
  if (sep === '/') {
5
11
  return input;
@@ -10,7 +16,13 @@ export function replaceWithWindowsPathIfNeeded(input) {
10
16
  return input.replace(/\//g, sep);
11
17
  }
12
18
  }
13
- /** Convert a Windows path to a posix path. */
19
+ /**
20
+ * Convert a Windows path to a posix path.
21
+ *
22
+ * @category Path : Node
23
+ * @category Package : @augment-vir/node
24
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
25
+ */
14
26
  export function toPosixPath(maybeWindowsPath) {
15
27
  return maybeWindowsPath
16
28
  .replace(/^(.+?):\\+/, (match, captureGroup) => {
@@ -19,8 +31,12 @@ export function toPosixPath(maybeWindowsPath) {
19
31
  .replace(/\\+/g, '/');
20
32
  }
21
33
  /**
22
- * Use this to interpolate paths into bash commands. If the given path is not a window path, the
34
+ * Use this to interpolate paths into bash commands. If the given path is not a Windows path, the
23
35
  * path structure will not be modified.
36
+ *
37
+ * @category Path : Node
38
+ * @category Package : @augment-vir/node
39
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
24
40
  */
25
41
  export function interpolationSafeWindowsPath(input) {
26
42
  return input.replace(/\\/g, '\\\\\\\\');
@@ -1 +1,8 @@
1
+ /**
2
+ * The root path of the system containing the cwd.
3
+ *
4
+ * @category Path : Node
5
+ * @category Package : @augment-vir/node
6
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
7
+ */
1
8
  export declare const systemRootPath: string;
@@ -2,4 +2,11 @@ import { parse } from 'node:path';
2
2
  function getSystemRootPath() {
3
3
  return parse(process.cwd()).root;
4
4
  }
5
+ /**
6
+ * The root path of the system containing the cwd.
7
+ *
8
+ * @category Path : Node
9
+ * @category Package : @augment-vir/node
10
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
11
+ */
5
12
  export const systemRootPath = getSystemRootPath();
@@ -1,21 +1,95 @@
1
1
  import { generatePrismaClient, isGeneratedPrismaClientCurrent } from '../prisma/prisma-client.js';
2
2
  import { doesPrismaDiffExist, getPrismaDiff, resetDevPrismaDatabase } from '../prisma/prisma-database.js';
3
3
  import { applyPrismaMigrationsToDev, applyPrismaMigrationsToProd, createPrismaMigration, getMigrationStatus } from '../prisma/prisma-migrations.js';
4
- /** Centralized Prisma API from `@augment-vir/node`. */
4
+ export * from '../prisma/prisma-errors.js';
5
+ export type { PrismaMigrationStatus } from '../prisma/prisma-migrations.js';
6
+ /**
7
+ * Centralized Prisma API from `@augment-vir/node`.
8
+ *
9
+ * ## Prisma flows
10
+ *
11
+ * - Deploy to production
12
+ *
13
+ * - {@link prisma.migration.applyProd}
14
+ * - Update dev environment
15
+ *
16
+ * - Apply migrations: {@link prisma.migration.applyDev}
17
+ *
18
+ * - If throws {@link PrismaMigrationNeededError}, prompt user for a new migration name and pass it to
19
+ * {@link prisma.migration.create}
20
+ * - If throws {@link PrismaResetNeededError}, reset the database with {@link prisma.database.resetDev}
21
+ * - Generate client: `prisma.client.isCurrent`
22
+ *
23
+ * - If `false`, run {@link prisma.client.generate}
24
+ *
25
+ * @category Prisma : Node
26
+ * @category Package : @augment-vir/node
27
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
28
+ */
5
29
  export declare const prisma: {
6
30
  migration: {
31
+ /**
32
+ * Get current migration status.
33
+ *
34
+ * @see https://www.prisma.io/docs/orm/reference/prisma-cli-reference#migrate-status
35
+ */
7
36
  status: typeof getMigrationStatus;
37
+ /**
38
+ * Creates a new migration.
39
+ *
40
+ * @see https://www.prisma.io/docs/orm/reference/prisma-cli-reference#migrate-dev
41
+ */
8
42
  create: typeof createPrismaMigration;
43
+ /**
44
+ * Apply all migrations. Meant for a production environment.
45
+ *
46
+ * @see https://www.prisma.io/docs/orm/reference/prisma-cli-reference#migrate-deploy
47
+ */
9
48
  applyProd: typeof applyPrismaMigrationsToProd;
49
+ /**
50
+ * Apply all migrations. Meant for a development environment, with less protections than
51
+ * {@link prisma.migration.applyProd}.
52
+ *
53
+ * @throws `PrismaMigrationNeededError` when a new migration is required so the user needs
54
+ * to input a name.
55
+ * @throws `PrismaResetNeededError` when there's a migration mismatch with the database and
56
+ * it needs to be reset.
57
+ * @see https://www.prisma.io/docs/orm/reference/prisma-cli-reference#migrate-dev
58
+ */
10
59
  applyDev: typeof applyPrismaMigrationsToDev;
11
60
  };
12
61
  database: {
62
+ /**
63
+ * Force resets a dev database to match the current Prisma schema and migrations.
64
+ *
65
+ * **This will destroy all data. Do not use in production.**
66
+ *
67
+ * @see https://www.prisma.io/docs/orm/reference/prisma-cli-reference#migrate-reset
68
+ */
13
69
  resetDev: typeof resetDevPrismaDatabase;
70
+ /**
71
+ * Uses {@link prisma.database.diff} to detect if there are any differences between the
72
+ * current database and the Prisma schema that should control it.
73
+ */
14
74
  hasDiff: typeof doesPrismaDiffExist;
75
+ /**
76
+ * Gets a string list of all differences between the current database and the Prisma schema
77
+ * that should control it.
78
+ *
79
+ * @see https://www.prisma.io/docs/orm/reference/prisma-cli-reference#migrate-diff
80
+ */
15
81
  diff: typeof getPrismaDiff;
16
82
  };
17
83
  client: {
84
+ /**
85
+ * Runs Prisma generators included in the given Prisma schema (which usually includes the
86
+ * Prisma JS client). This will work even if the database doesn't exist yet.
87
+ */
18
88
  generate: typeof generatePrismaClient;
89
+ /**
90
+ * Detects if the current generated Prisma JS Client was generated from the current Prisma
91
+ * schema.
92
+ */
19
93
  isCurrent: typeof isGeneratedPrismaClientCurrent;
20
94
  };
21
95
  };
@@ -1,21 +1,94 @@
1
1
  import { generatePrismaClient, isGeneratedPrismaClientCurrent } from '../prisma/prisma-client.js';
2
2
  import { doesPrismaDiffExist, getPrismaDiff, resetDevPrismaDatabase, } from '../prisma/prisma-database.js';
3
3
  import { applyPrismaMigrationsToDev, applyPrismaMigrationsToProd, createPrismaMigration, getMigrationStatus, } from '../prisma/prisma-migrations.js';
4
- /** Centralized Prisma API from `@augment-vir/node`. */
4
+ export * from '../prisma/prisma-errors.js';
5
+ /**
6
+ * Centralized Prisma API from `@augment-vir/node`.
7
+ *
8
+ * ## Prisma flows
9
+ *
10
+ * - Deploy to production
11
+ *
12
+ * - {@link prisma.migration.applyProd}
13
+ * - Update dev environment
14
+ *
15
+ * - Apply migrations: {@link prisma.migration.applyDev}
16
+ *
17
+ * - If throws {@link PrismaMigrationNeededError}, prompt user for a new migration name and pass it to
18
+ * {@link prisma.migration.create}
19
+ * - If throws {@link PrismaResetNeededError}, reset the database with {@link prisma.database.resetDev}
20
+ * - Generate client: `prisma.client.isCurrent`
21
+ *
22
+ * - If `false`, run {@link prisma.client.generate}
23
+ *
24
+ * @category Prisma : Node
25
+ * @category Package : @augment-vir/node
26
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
27
+ */
5
28
  export const prisma = {
6
29
  migration: {
30
+ /**
31
+ * Get current migration status.
32
+ *
33
+ * @see https://www.prisma.io/docs/orm/reference/prisma-cli-reference#migrate-status
34
+ */
7
35
  status: getMigrationStatus,
36
+ /**
37
+ * Creates a new migration.
38
+ *
39
+ * @see https://www.prisma.io/docs/orm/reference/prisma-cli-reference#migrate-dev
40
+ */
8
41
  create: createPrismaMigration,
42
+ /**
43
+ * Apply all migrations. Meant for a production environment.
44
+ *
45
+ * @see https://www.prisma.io/docs/orm/reference/prisma-cli-reference#migrate-deploy
46
+ */
9
47
  applyProd: applyPrismaMigrationsToProd,
48
+ /**
49
+ * Apply all migrations. Meant for a development environment, with less protections than
50
+ * {@link prisma.migration.applyProd}.
51
+ *
52
+ * @throws `PrismaMigrationNeededError` when a new migration is required so the user needs
53
+ * to input a name.
54
+ * @throws `PrismaResetNeededError` when there's a migration mismatch with the database and
55
+ * it needs to be reset.
56
+ * @see https://www.prisma.io/docs/orm/reference/prisma-cli-reference#migrate-dev
57
+ */
10
58
  applyDev: applyPrismaMigrationsToDev,
11
59
  },
12
60
  database: {
61
+ /**
62
+ * Force resets a dev database to match the current Prisma schema and migrations.
63
+ *
64
+ * **This will destroy all data. Do not use in production.**
65
+ *
66
+ * @see https://www.prisma.io/docs/orm/reference/prisma-cli-reference#migrate-reset
67
+ */
13
68
  resetDev: resetDevPrismaDatabase,
69
+ /**
70
+ * Uses {@link prisma.database.diff} to detect if there are any differences between the
71
+ * current database and the Prisma schema that should control it.
72
+ */
14
73
  hasDiff: doesPrismaDiffExist,
74
+ /**
75
+ * Gets a string list of all differences between the current database and the Prisma schema
76
+ * that should control it.
77
+ *
78
+ * @see https://www.prisma.io/docs/orm/reference/prisma-cli-reference#migrate-diff
79
+ */
15
80
  diff: getPrismaDiff,
16
81
  },
17
82
  client: {
83
+ /**
84
+ * Runs Prisma generators included in the given Prisma schema (which usually includes the
85
+ * Prisma JS client). This will work even if the database doesn't exist yet.
86
+ */
18
87
  generate: generatePrismaClient,
88
+ /**
89
+ * Detects if the current generated Prisma JS Client was generated from the current Prisma
90
+ * schema.
91
+ */
19
92
  isCurrent: isGeneratedPrismaClientCurrent,
20
93
  },
21
94
  };
@@ -0,0 +1,50 @@
1
+ import { type AnyDuration } from '@date-vir/duration';
2
+ /** Can't test requiring user input. */
3
+ /**
4
+ * Options for {@link askQuestion}.
5
+ *
6
+ * @category Node : Terminal : Util
7
+ * @category Package : @augment-vir/node
8
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
9
+ */
10
+ export type AskQuestionOptions = {
11
+ timeout: AnyDuration;
12
+ hideUserInput: boolean;
13
+ };
14
+ /**
15
+ * Asks the user a question in their terminal and then waits for them to type something in response.
16
+ * The response is accepted once the user inputs a new line.
17
+ *
18
+ * @category Node : Terminal
19
+ * @category Package : @augment-vir/node
20
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
21
+ * @see
22
+ * - {@link askQuestionUntilConditionMet}: ask a question on loop until the user provides a valid response.
23
+ */
24
+ export declare function askQuestion(questionToAsk: string, { hideUserInput, timeout, }?: Partial<AskQuestionOptions>): Promise<string>;
25
+ /**
26
+ * Options for {@link askQuestionUntilConditionMet}.
27
+ *
28
+ * @category Node : Terminal : Util
29
+ * @category Package : @augment-vir/node
30
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
31
+ */
32
+ export type QuestionUntilConditionMetOptions = {
33
+ questionToAsk: string;
34
+ /** Callback to call with the user's response to verify if their response is valid. */
35
+ verifyResponseCallback: (response: string) => boolean | Promise<boolean>;
36
+ invalidInputMessage: string;
37
+ tryCountMax?: number;
38
+ } & Partial<AskQuestionOptions>;
39
+ /**
40
+ * Asks the user a question in their terminal and then waits for them to type something in response.
41
+ * The response is submitted once the user inputs a new line. If the response fails validation, the
42
+ * question is presented again.
43
+ *
44
+ * @category Node : Terminal
45
+ * @category Package : @augment-vir/node
46
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
47
+ * @see
48
+ * - {@link askQuestion}: ask a question and accept any response.
49
+ */
50
+ export declare function askQuestionUntilConditionMet({ questionToAsk, verifyResponseCallback, invalidInputMessage, tryCountMax, ...options }: QuestionUntilConditionMetOptions): Promise<string>;
@@ -5,6 +5,16 @@ const defaultAskQuestionOptions = {
5
5
  timeout: { seconds: 60 },
6
6
  hideUserInput: false,
7
7
  };
8
+ /**
9
+ * Asks the user a question in their terminal and then waits for them to type something in response.
10
+ * The response is accepted once the user inputs a new line.
11
+ *
12
+ * @category Node : Terminal
13
+ * @category Package : @augment-vir/node
14
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
15
+ * @see
16
+ * - {@link askQuestionUntilConditionMet}: ask a question on loop until the user provides a valid response.
17
+ */
8
18
  export async function askQuestion(questionToAsk, { hideUserInput = defaultAskQuestionOptions.hideUserInput, timeout = defaultAskQuestionOptions.timeout, } = defaultAskQuestionOptions) {
9
19
  const cliInterface = createInterface({
10
20
  input: process.stdin,
@@ -44,13 +54,24 @@ export async function askQuestion(questionToAsk, { hideUserInput = defaultAskQue
44
54
  });
45
55
  });
46
56
  }
47
- export async function askQuestionUntilConditionMet({ questionToAsk, conditionCallback, invalidInputMessage, tryCountMax = 5, ...options }) {
57
+ /**
58
+ * Asks the user a question in their terminal and then waits for them to type something in response.
59
+ * The response is submitted once the user inputs a new line. If the response fails validation, the
60
+ * question is presented again.
61
+ *
62
+ * @category Node : Terminal
63
+ * @category Package : @augment-vir/node
64
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
65
+ * @see
66
+ * - {@link askQuestion}: ask a question and accept any response.
67
+ */
68
+ export async function askQuestionUntilConditionMet({ questionToAsk, verifyResponseCallback, invalidInputMessage, tryCountMax = 5, ...options }) {
48
69
  let wasConditionMet = false;
49
70
  let retryCount = 0;
50
71
  let response = '';
51
72
  while (!wasConditionMet && retryCount <= tryCountMax) {
52
73
  response = (await askQuestion(questionToAsk, options)).trim();
53
- wasConditionMet = await conditionCallback(response);
74
+ wasConditionMet = await verifyResponseCallback(response);
54
75
  if (!wasConditionMet) {
55
76
  log.error(invalidInputMessage);
56
77
  }
@@ -2,6 +2,13 @@ import { type Logger } from '@augment-vir/common';
2
2
  import type { MaybePromise, PartialWithUndefined } from '@augment-vir/core';
3
3
  import { ChildProcess } from 'node:child_process';
4
4
  import { ListenTarget } from 'typed-event-target';
5
+ /**
6
+ * All output from {@link runShellCommand}.
7
+ *
8
+ * @category Node : Terminal : Util
9
+ * @category Package : @augment-vir/node
10
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
11
+ */
5
12
  export type ShellOutput = {
6
13
  error: undefined | Error;
7
14
  stderr: string;
@@ -17,6 +24,13 @@ declare const ShellStdoutEvent_base: (new (eventInitDict: import("typed-event-ta
17
24
  readonly AT_TARGET: 2;
18
25
  readonly BUBBLING_PHASE: 3;
19
26
  }, "NONE" | "CAPTURING_PHASE" | "AT_TARGET" | "BUBBLING_PHASE" | "prototype"> & Pick<import("typed-event-target").TypedCustomEvent<string | Buffer, "shell-stdout">, "type">;
27
+ /**
28
+ * An event that indicates that the shell command just wrote to stdout.
29
+ *
30
+ * @category Node : Terminal : Util
31
+ * @category Package : @augment-vir/node
32
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
33
+ */
20
34
  export declare class ShellStdoutEvent extends ShellStdoutEvent_base {
21
35
  }
22
36
  declare const ShellStderrEvent_base: (new (eventInitDict: import("typed-event-target").TypedCustomEventInit<string | Buffer>) => import("typed-event-target").TypedCustomEvent<string | Buffer, "shell-stderr">) & Pick<{
@@ -27,6 +41,13 @@ declare const ShellStderrEvent_base: (new (eventInitDict: import("typed-event-ta
27
41
  readonly AT_TARGET: 2;
28
42
  readonly BUBBLING_PHASE: 3;
29
43
  }, "NONE" | "CAPTURING_PHASE" | "AT_TARGET" | "BUBBLING_PHASE" | "prototype"> & Pick<import("typed-event-target").TypedCustomEvent<string | Buffer, "shell-stderr">, "type">;
44
+ /**
45
+ * An event that indicates that the shell command just wrote to stderr.
46
+ *
47
+ * @category Node : Terminal : Util
48
+ * @category Package : @augment-vir/node
49
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
50
+ */
30
51
  export declare class ShellStderrEvent extends ShellStderrEvent_base {
31
52
  }
32
53
  declare const ShellDoneEvent_base: (new (eventInitDict: import("typed-event-target").TypedCustomEventInit<{
@@ -47,8 +68,13 @@ declare const ShellDoneEvent_base: (new (eventInitDict: import("typed-event-targ
47
68
  exitSignal: NodeJS.Signals | undefined;
48
69
  }, "shell-done">, "type">;
49
70
  /**
50
- * Contains an exit code or an exit signal. Based on the Node.js documentation, either one or the
51
- * other is defined, never both at the same time.
71
+ * An event that indicates that the shell command is finished. This contains an exit code or an exit
72
+ * signal. Based on the Node.js documentation, either one or the other is defined, never both at the
73
+ * same time.
74
+ *
75
+ * @category Node : Terminal : Util
76
+ * @category Package : @augment-vir/node
77
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
52
78
  */
53
79
  export declare class ShellDoneEvent extends ShellDoneEvent_base {
54
80
  }
@@ -60,28 +86,85 @@ declare const ShellErrorEvent_base: (new (eventInitDict: import("typed-event-tar
60
86
  readonly AT_TARGET: 2;
61
87
  readonly BUBBLING_PHASE: 3;
62
88
  }, "NONE" | "CAPTURING_PHASE" | "AT_TARGET" | "BUBBLING_PHASE" | "prototype"> & Pick<import("typed-event-target").TypedCustomEvent<Error, "shell-error">, "type">;
89
+ /**
90
+ * An event that indicates that the shell command errored.
91
+ *
92
+ * @category Node : Terminal : Util
93
+ * @category Package : @augment-vir/node
94
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
95
+ */
63
96
  export declare class ShellErrorEvent extends ShellErrorEvent_base {
64
97
  }
98
+ /**
99
+ * A shell command listen target that emits events.
100
+ *
101
+ * @category Node : Terminal : Util
102
+ * @category Package : @augment-vir/node
103
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
104
+ */
65
105
  export declare class ShellTarget extends ListenTarget<ShellStdoutEvent | ShellStderrEvent | ShellDoneEvent | ShellErrorEvent> {
66
106
  readonly childProcess: ChildProcess;
67
107
  constructor(childProcess: ChildProcess);
68
108
  }
109
+ /**
110
+ * Runs a shell command and returns a {@link ShellTarget} instance for directly hooking into shell
111
+ * events. This allows instant reactions to shell events but in a less convenient API compared to
112
+ * {@link runShellCommand}.
113
+ *
114
+ * @category Node : Terminal
115
+ * @category Package : @augment-vir/node
116
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
117
+ * @see
118
+ * - {@link runShellCommand}: a higher level and more succinct way of running a shell command.
119
+ */
69
120
  export declare function streamShellCommand(command: string, cwd?: string, shell?: string, env?: NodeJS.ProcessEnv, hookUpToConsole?: boolean): ShellTarget;
70
- export type RunShellCommandParams = {
121
+ /**
122
+ * Options for {@link runShellCommand}.
123
+ *
124
+ * @category Node : Terminal : Util
125
+ * @category Package : @augment-vir/node
126
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
127
+ */
128
+ export type RunShellCommandOptions = {
71
129
  cwd?: string | undefined;
72
130
  env?: NodeJS.ProcessEnv | undefined;
73
131
  shell?: string | undefined;
74
132
  /** Automatically hook up stdout and stderr printing to the caller's console methods. */
75
133
  hookUpToConsole?: boolean | undefined;
76
134
  rejectOnError?: boolean | undefined;
135
+ /** Callback to call whenever the shell logs to stdout. */
77
136
  stdoutCallback?: (stdout: string, childProcess: ChildProcess) => MaybePromise<void> | undefined;
137
+ /** Callback to call whenever the shell logs to stderr. */
78
138
  stderrCallback?: (stderr: string, childProcess: ChildProcess) => MaybePromise<void> | undefined;
79
139
  };
80
- export declare function runShellCommand(command: string, options?: RunShellCommandParams): Promise<ShellOutput>;
140
+ /**
141
+ * Runs a shell command and returns its output.
142
+ *
143
+ * @category Node : Terminal
144
+ * @category Package : @augment-vir/node
145
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
146
+ * @see
147
+ * - {@link streamShellCommand}: a lower level way of running a shell command that allows instant reactions to shell events.
148
+ */
149
+ export declare function runShellCommand(command: string, options?: RunShellCommandOptions): Promise<ShellOutput>;
150
+ /**
151
+ * Options for {@link logShellOutput}.
152
+ *
153
+ * @category Node : Terminal : Util
154
+ * @category Package : @augment-vir/node
155
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
156
+ */
81
157
  export type LogShellOutputOptions = PartialWithUndefined<{
82
158
  logger: Logger;
83
159
  withLabels: boolean;
84
160
  ignoreError: boolean;
85
161
  }>;
162
+ /**
163
+ * Log the output of running a shell command. This is useful for quick debugging of shell commands.
164
+ *
165
+ * @category Node : Terminal : Util
166
+ * @category Package : @augment-vir/node
167
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
168
+ */
86
169
  export declare function logShellOutput(shellOutput: PartialWithUndefined<Omit<ShellOutput, 'exitSignal'>>, { ignoreError, logger, withLabels, }?: LogShellOutputOptions): void;
87
170
  export {};
@@ -1,18 +1,51 @@
1
1
  import { combineErrors, log } from '@augment-vir/common';
2
2
  import { spawn } from 'node:child_process';
3
3
  import { defineTypedCustomEvent, ListenTarget } from 'typed-event-target';
4
+ /**
5
+ * An event that indicates that the shell command just wrote to stdout.
6
+ *
7
+ * @category Node : Terminal : Util
8
+ * @category Package : @augment-vir/node
9
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
10
+ */
4
11
  export class ShellStdoutEvent extends defineTypedCustomEvent()('shell-stdout') {
5
12
  }
13
+ /**
14
+ * An event that indicates that the shell command just wrote to stderr.
15
+ *
16
+ * @category Node : Terminal : Util
17
+ * @category Package : @augment-vir/node
18
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
19
+ */
6
20
  export class ShellStderrEvent extends defineTypedCustomEvent()('shell-stderr') {
7
21
  }
8
22
  /**
9
- * Contains an exit code or an exit signal. Based on the Node.js documentation, either one or the
10
- * other is defined, never both at the same time.
23
+ * An event that indicates that the shell command is finished. This contains an exit code or an exit
24
+ * signal. Based on the Node.js documentation, either one or the other is defined, never both at the
25
+ * same time.
26
+ *
27
+ * @category Node : Terminal : Util
28
+ * @category Package : @augment-vir/node
29
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
11
30
  */
12
31
  export class ShellDoneEvent extends defineTypedCustomEvent()('shell-done') {
13
32
  }
33
+ /**
34
+ * An event that indicates that the shell command errored.
35
+ *
36
+ * @category Node : Terminal : Util
37
+ * @category Package : @augment-vir/node
38
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
39
+ */
14
40
  export class ShellErrorEvent extends defineTypedCustomEvent()('shell-error') {
15
41
  }
42
+ /**
43
+ * A shell command listen target that emits events.
44
+ *
45
+ * @category Node : Terminal : Util
46
+ * @category Package : @augment-vir/node
47
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
48
+ */
16
49
  export class ShellTarget extends ListenTarget {
17
50
  childProcess;
18
51
  constructor(childProcess) {
@@ -20,6 +53,17 @@ export class ShellTarget extends ListenTarget {
20
53
  this.childProcess = childProcess;
21
54
  }
22
55
  }
56
+ /**
57
+ * Runs a shell command and returns a {@link ShellTarget} instance for directly hooking into shell
58
+ * events. This allows instant reactions to shell events but in a less convenient API compared to
59
+ * {@link runShellCommand}.
60
+ *
61
+ * @category Node : Terminal
62
+ * @category Package : @augment-vir/node
63
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
64
+ * @see
65
+ * - {@link runShellCommand}: a higher level and more succinct way of running a shell command.
66
+ */
23
67
  export function streamShellCommand(command, cwd, shell = 'bash', env = process.env, hookUpToConsole = false) {
24
68
  const stdio = hookUpToConsole ? [process.stdin] : undefined;
25
69
  const childProcess = spawn(command, { shell, cwd, env, stdio });
@@ -75,6 +119,15 @@ function prepareChunkForLogging(chunk, trimEndingLine) {
75
119
  const stringified = chunk.toString();
76
120
  return trimEndingLine ? stringified.replace(/\n$/, '') : stringified;
77
121
  }
122
+ /**
123
+ * Runs a shell command and returns its output.
124
+ *
125
+ * @category Node : Terminal
126
+ * @category Package : @augment-vir/node
127
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
128
+ * @see
129
+ * - {@link streamShellCommand}: a lower level way of running a shell command that allows instant reactions to shell events.
130
+ */
78
131
  export async function runShellCommand(command, options = {}) {
79
132
  return new Promise((resolve, reject) => {
80
133
  let stdout = '';
@@ -126,7 +179,7 @@ export async function runShellCommand(command, options = {}) {
126
179
  shellTarget.listen(ShellDoneEvent, ({ detail: { exitCode, exitSignal } }) => {
127
180
  shellTarget.destroy();
128
181
  resolve({
129
- error: combineErrors(errors),
182
+ error: errors.length ? combineErrors(errors) : undefined,
130
183
  stdout,
131
184
  stderr,
132
185
  exitCode,
@@ -140,6 +193,13 @@ const defaultLogShellOutputOptions = {
140
193
  logger: log,
141
194
  withLabels: false,
142
195
  };
196
+ /**
197
+ * Log the output of running a shell command. This is useful for quick debugging of shell commands.
198
+ *
199
+ * @category Node : Terminal : Util
200
+ * @category Package : @augment-vir/node
201
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
202
+ */
143
203
  export function logShellOutput(shellOutput, { ignoreError = defaultLogShellOutputOptions.ignoreError, logger = defaultLogShellOutputOptions.logger, withLabels = defaultLogShellOutputOptions.withLabels, } = defaultLogShellOutputOptions) {
144
204
  logger.if(withLabels).info('exit code');
145
205
  logger.if(shellOutput.exitCode != undefined || withLabels).plain(shellOutput.exitCode || 0);