@augment-vir/node 30.0.0 → 30.0.2

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 (67) 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 +33 -0
  21. package/dist/augments/os/operating-system.js +35 -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 +137 -1
  29. package/dist/augments/prisma.js +135 -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 +4 -2
  48. package/dist/docker/docker-startup.js +1 -2
  49. package/dist/docker/run-docker-test.mock.d.ts +2 -0
  50. package/dist/docker/run-docker-test.mock.js +16 -0
  51. package/dist/index.d.ts +3 -3
  52. package/dist/index.js +3 -3
  53. package/dist/prisma/disable-ci-env.mock.d.ts +2 -0
  54. package/dist/prisma/disable-ci-env.mock.js +81 -0
  55. package/dist/prisma/model-data.d.ts +73 -0
  56. package/dist/prisma/model-data.js +70 -0
  57. package/dist/prisma/prisma-client.d.ts +0 -4
  58. package/dist/prisma/prisma-client.js +0 -4
  59. package/dist/prisma/prisma-errors.d.ts +25 -0
  60. package/dist/prisma/prisma-errors.js +25 -0
  61. package/dist/prisma/prisma-migrations.d.ts +12 -6
  62. package/dist/prisma/prisma-migrations.js +1 -7
  63. package/dist/prisma/run-prisma-command.d.ts +1 -1
  64. package/dist/prisma/run-prisma-command.js +1 -1
  65. package/package.json +23 -13
  66. package/dist/augments/console/question.d.ts +0 -14
  67. package/dist/augments/download.d.ts +0 -4
package/README.md CHANGED
@@ -1,13 +1,10 @@
1
1
  # @augment-vir/node
2
2
 
3
- ## Prisma flows
3
+ A collection of augments, helpers types, functions, and classes only for Node.js (backend) JavaScript environments.
4
4
 
5
- - deploy to production
6
- - `prisma.migration.applyProd`
7
- - update dev environment
8
- - apply migrations: `prisma.migration.applyDev`
9
- - if throws `PrismaMigrationNeededError`, prompt user for a new migration name
10
- - pass migration name to `prisma.migration.create`
11
- - if throws `PrismaResetNeededError`, reset the database with `prisma.database.resetDev`
12
- - generate client: `prisma.client.isCurrent`
13
- - if `false`, run `prisma.client.generate`
5
+ - Includes a custom Prisma API built on its CLI: [`prisma`](https://electrovir.github.io/augment-vir/variables/prisma.html).
6
+ - Includes a custom Docker API built on its CLI: [`docker`](https://electrovir.github.io/augment-vir/variables/docker.html).
7
+ - Includes an easy to use shell script runner: [`runShellCommand`](https://electrovir.github.io/augment-vir/functions/runShellCommand.html).
8
+ - and much more!
9
+
10
+ See all the docs under `Node : *`, or `* : Node`, or `Package: @augment-vir/node` here: https://electrovir.github.io/augment-vir
@@ -8,37 +8,84 @@ import { runContainer } from '../docker/containers/run-container.js';
8
8
  import { tryOrKillContainer } from '../docker/containers/try-or-kill-container.js';
9
9
  import { isImageInLocalRegistry, removeImageFromLocalRegistry, updateImage } from '../docker/docker-image.js';
10
10
  import { isDockerRunning, startDocker } from '../docker/docker-startup.js';
11
- export { DockerContainerStatusEnum, type DockerContainerInfo, type DockerContainerInfoState, } from '../docker/containers/container-info.js';
11
+ export { type DockerContainerInfo, type DockerContainerInfoState, } from '../docker/containers/container-info.js';
12
12
  export { DockerContainerStatus, exitedDockerContainerStatuses, } from '../docker/containers/container-status.js';
13
13
  export { type CopyToDockerContainerParams } from '../docker/containers/copy-to-container.js';
14
14
  export { type DockerEnvMap, type DockerPortMap, type DockerVolumeMap, type DockerVolumeMappingType, } from '../docker/containers/docker-command-inputs.js';
15
15
  export { type RunDockerContainerCommandParams } from '../docker/containers/run-command.js';
16
16
  export { type RunDockerContainerParams } from '../docker/containers/run-container.js';
17
- /** Centralized Docker API from `@augment-vir/node`. */
17
+ /**
18
+ * Centralized Docker API from `@augment-vir/node`.
19
+ *
20
+ * @category Node : Docker
21
+ * @category Package : @augment-vir/node
22
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
23
+ */
18
24
  export declare const docker: {
25
+ /** Detects if the Docker service is running. */
19
26
  isRunning: typeof isDockerRunning;
27
+ /**
28
+ * Tries to start Docker based ont he current operating system's supported commands. The success
29
+ * of this operation is heavily dependent on how you have Docker setup on your system.
30
+ */
20
31
  start: typeof startDocker;
21
32
  image: {
33
+ /** Downloads an image if it is missing from the local registry. */
22
34
  update: typeof updateImage;
35
+ /** Removes an image from the local registry. */
23
36
  remove: typeof removeImageFromLocalRegistry;
37
+ /** Detects if an image exists in the local registry. */
24
38
  exists: typeof isImageInLocalRegistry;
25
39
  };
26
40
  container: {
41
+ /**
42
+ * Get the current status of a container. If the container does not exist at all, the status
43
+ * will be {@link DockerContainerStatus.Removed}.
44
+ */
27
45
  getStatus: typeof getContainerStatus;
46
+ /** Wait until a container is running and responsive. */
28
47
  waitUntilRunning: typeof waitUntilContainerRunning;
48
+ /**
49
+ * Wait until a container has a status that can be classified as "exited".
50
+ *
51
+ * @see {@link exitedDockerContainerStatuses}
52
+ */
29
53
  waitUntilExited: typeof waitUntilContainerExited;
54
+ /** Wait until a container is completely removed. */
30
55
  waitUntilRemoved: typeof waitUntilContainerRemoved;
56
+ /**
57
+ * Runs a callback (which presumably will run a command within the given `containerName`)
58
+ * and kills the container if the callback fails.
59
+ */
31
60
  tryOrKill: typeof tryOrKillContainer;
61
+ /** Run a container that isn't already running. */
32
62
  run: typeof runContainer;
63
+ /** Kill a container. */
33
64
  kill: typeof killContainer;
65
+ /** Copy a file or directory to a container. */
34
66
  copyTo: typeof copyToContainer;
67
+ /** Run a command on a container that is already running. */
35
68
  runCommand: typeof runContainerCommand;
69
+ /** Run `docker inspect` on a container and return its output. */
36
70
  getInfo: typeof getContainerInfo;
71
+ /** Get a container's logs. */
37
72
  getLogs: typeof getContainerLogs;
38
73
  };
39
74
  util: {
75
+ /**
76
+ * Manually create a string of volume mapping flags. This is automatically done already
77
+ * inside the run container methods.
78
+ */
40
79
  makeVolumeFlags: typeof makeVolumeFlags;
80
+ /**
81
+ * Manually create a string of port mapping flags. This is automatically done already inside
82
+ * the run container methods.
83
+ */
41
84
  makePortMapFlags: typeof makePortMapFlags;
85
+ /**
86
+ * Manually create a string of env mapping flags. This is automatically done already inside
87
+ * the run container methods.
88
+ */
42
89
  makeEnvFlags: typeof makeEnvFlags;
43
90
  };
44
91
  };
@@ -8,33 +8,79 @@ import { runContainer } from '../docker/containers/run-container.js';
8
8
  import { tryOrKillContainer } from '../docker/containers/try-or-kill-container.js';
9
9
  import { isImageInLocalRegistry, removeImageFromLocalRegistry, updateImage, } from '../docker/docker-image.js';
10
10
  import { isDockerRunning, startDocker } from '../docker/docker-startup.js';
11
- export { DockerContainerStatusEnum, } from '../docker/containers/container-info.js';
12
11
  export { DockerContainerStatus, exitedDockerContainerStatuses, } from '../docker/containers/container-status.js';
13
- /** Centralized Docker API from `@augment-vir/node`. */
12
+ /**
13
+ * Centralized Docker API from `@augment-vir/node`.
14
+ *
15
+ * @category Node : Docker
16
+ * @category Package : @augment-vir/node
17
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
18
+ */
14
19
  export const docker = {
20
+ /** Detects if the Docker service is running. */
15
21
  isRunning: isDockerRunning,
22
+ /**
23
+ * Tries to start Docker based ont he current operating system's supported commands. The success
24
+ * of this operation is heavily dependent on how you have Docker setup on your system.
25
+ */
16
26
  start: startDocker,
17
27
  image: {
28
+ /** Downloads an image if it is missing from the local registry. */
18
29
  update: updateImage,
30
+ /** Removes an image from the local registry. */
19
31
  remove: removeImageFromLocalRegistry,
32
+ /** Detects if an image exists in the local registry. */
20
33
  exists: isImageInLocalRegistry,
21
34
  },
22
35
  container: {
36
+ /**
37
+ * Get the current status of a container. If the container does not exist at all, the status
38
+ * will be {@link DockerContainerStatus.Removed}.
39
+ */
23
40
  getStatus: getContainerStatus,
41
+ /** Wait until a container is running and responsive. */
24
42
  waitUntilRunning: waitUntilContainerRunning,
43
+ /**
44
+ * Wait until a container has a status that can be classified as "exited".
45
+ *
46
+ * @see {@link exitedDockerContainerStatuses}
47
+ */
25
48
  waitUntilExited: waitUntilContainerExited,
49
+ /** Wait until a container is completely removed. */
26
50
  waitUntilRemoved: waitUntilContainerRemoved,
51
+ /**
52
+ * Runs a callback (which presumably will run a command within the given `containerName`)
53
+ * and kills the container if the callback fails.
54
+ */
27
55
  tryOrKill: tryOrKillContainer,
56
+ /** Run a container that isn't already running. */
28
57
  run: runContainer,
58
+ /** Kill a container. */
29
59
  kill: killContainer,
60
+ /** Copy a file or directory to a container. */
30
61
  copyTo: copyToContainer,
62
+ /** Run a command on a container that is already running. */
31
63
  runCommand: runContainerCommand,
64
+ /** Run `docker inspect` on a container and return its output. */
32
65
  getInfo: getContainerInfo,
66
+ /** Get a container's logs. */
33
67
  getLogs: getContainerLogs,
34
68
  },
35
69
  util: {
70
+ /**
71
+ * Manually create a string of volume mapping flags. This is automatically done already
72
+ * inside the run container methods.
73
+ */
36
74
  makeVolumeFlags,
75
+ /**
76
+ * Manually create a string of port mapping flags. This is automatically done already inside
77
+ * the run container methods.
78
+ */
37
79
  makePortMapFlags,
80
+ /**
81
+ * Manually create a string of env mapping flags. This is automatically done already inside
82
+ * the run container methods.
83
+ */
38
84
  makeEnvFlags,
39
85
  },
40
86
  };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Download a file.
3
+ *
4
+ * @category Node : File
5
+ * @category Package : @augment-vir/node
6
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
7
+ */
8
+ export declare function downloadFile({ url, writePath }: {
9
+ url: string;
10
+ writePath: string;
11
+ }): Promise<void>;
@@ -3,6 +3,13 @@ import { mkdir } from 'node:fs/promises';
3
3
  import { dirname } from 'node:path';
4
4
  import { Readable } from 'node:stream';
5
5
  import { finished } from 'node:stream/promises';
6
+ /**
7
+ * Download a file.
8
+ *
9
+ * @category Node : File
10
+ * @category Package : @augment-vir/node
11
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
12
+ */
6
13
  export async function downloadFile({ url, writePath }) {
7
14
  const response = await fetch(url);
8
15
  if (!response.ok) {
@@ -1,8 +1,50 @@
1
1
  import { JsonCompatibleArray, JsonCompatibleObject, type JsonCompatibleValue } from '@augment-vir/common';
2
2
  import type { PartialWithUndefined } from '@augment-vir/core';
3
+ /**
4
+ * Read a file and also parse its contents as JSON.
5
+ *
6
+ * @category Node : File
7
+ * @category JSON : Node
8
+ * @category Package : @augment-vir/node
9
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
10
+ * @see
11
+ * - {@link writeJsonFile}
12
+ * - {@link appendJsonFile}
13
+ */
3
14
  export declare function readJsonFile(path: string): Promise<JsonCompatibleValue | undefined>;
15
+ /**
16
+ * Options for {@link writeJsonFile}.
17
+ *
18
+ * @category Node : File
19
+ * @category JSON : Node
20
+ * @category Package : @augment-vir/node
21
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
22
+ */
4
23
  export type WriteJsonOptions = PartialWithUndefined<{
5
24
  includeTrailingNewLine: boolean;
6
25
  }>;
26
+ /**
27
+ * Write to a file and stringify `data` as JSON before doing so.
28
+ *
29
+ * @category Node : File
30
+ * @category JSON : Node
31
+ * @category Package : @augment-vir/node
32
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
33
+ * @see
34
+ * - {@link readJsonFile}
35
+ * - {@link appendJsonFile}
36
+ */
7
37
  export declare function writeJsonFile(path: string, data: JsonCompatibleValue, options?: WriteJsonOptions): Promise<void>;
38
+ /**
39
+ * Append the given `newData` to the contents of the existing JSON file. If the file does not yet
40
+ * exist, `newData` is written as its only JSON contents.
41
+ *
42
+ * @category Node : File
43
+ * @category JSON : Node
44
+ * @category Package : @augment-vir/node
45
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
46
+ * @see
47
+ * - {@link readJsonFile}
48
+ * - {@link writeJsonFile}
49
+ */
8
50
  export declare function appendJsonFile(path: string, newData: JsonCompatibleObject | JsonCompatibleArray, options?: WriteJsonOptions): Promise<void>;
@@ -2,6 +2,17 @@ import { appendJson, } from '@augment-vir/common';
2
2
  import { mkdir, readFile } from 'node:fs/promises';
3
3
  import { dirname } from 'node:path';
4
4
  import { writeFileAndDir } from './write.js';
5
+ /**
6
+ * Read a file and also parse its contents as JSON.
7
+ *
8
+ * @category Node : File
9
+ * @category JSON : Node
10
+ * @category Package : @augment-vir/node
11
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
12
+ * @see
13
+ * - {@link writeJsonFile}
14
+ * - {@link appendJsonFile}
15
+ */
5
16
  export async function readJsonFile(path) {
6
17
  try {
7
18
  const contents = (await readFile(path)).toString();
@@ -11,11 +22,34 @@ export async function readJsonFile(path) {
11
22
  return undefined;
12
23
  }
13
24
  }
25
+ /**
26
+ * Write to a file and stringify `data` as JSON before doing so.
27
+ *
28
+ * @category Node : File
29
+ * @category JSON : Node
30
+ * @category Package : @augment-vir/node
31
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
32
+ * @see
33
+ * - {@link readJsonFile}
34
+ * - {@link appendJsonFile}
35
+ */
14
36
  export async function writeJsonFile(path, data, options = {}) {
15
37
  await mkdir(dirname(path), { recursive: true });
16
38
  const trailingNewLine = options.includeTrailingNewLine ? '\n' : '';
17
39
  await writeFileAndDir(path, JSON.stringify(data, null, 4) + trailingNewLine);
18
40
  }
41
+ /**
42
+ * Append the given `newData` to the contents of the existing JSON file. If the file does not yet
43
+ * exist, `newData` is written as its only JSON contents.
44
+ *
45
+ * @category Node : File
46
+ * @category JSON : Node
47
+ * @category Package : @augment-vir/node
48
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
49
+ * @see
50
+ * - {@link readJsonFile}
51
+ * - {@link writeJsonFile}
52
+ */
19
53
  export async function appendJsonFile(path, newData, options = {}) {
20
54
  const fileJson = await readJsonFile(path);
21
55
  await writeJsonFile(path, appendJson(fileJson, newData), options);
@@ -1,12 +1,20 @@
1
1
  import type { RequireExactlyOne } from 'type-fest';
2
2
  /**
3
3
  * Gets all files within a directory and its subdirectories, recursively. Returns an array of paths
4
- * relative to the input directory path.
4
+ * relative to the given input path.
5
+ *
6
+ * @category Node : File
7
+ * @category Package : @augment-vir/node
8
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
5
9
  */
6
10
  export declare function readDirRecursive(dirPath: string): Promise<string[]>;
7
11
  /**
8
- * Reads all files within a directory and then filters them by the given extension or extensions.
9
- * Returns that filtered list.
12
+ * Reads all files within a single directory and filters them by the given extension or extensions.
13
+ *
14
+ * @category Node : File
15
+ * @category Package : @augment-vir/node
16
+ * @returns That filtered list of paths.
17
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
10
18
  */
11
19
  export declare function readDirFilesByExtension({ dirPath, extension, extensions, }: {
12
20
  dirPath: string;
@@ -15,14 +15,22 @@ async function internalReadDirPathsRecursive(dirPath, basePath) {
15
15
  }
16
16
  /**
17
17
  * Gets all files within a directory and its subdirectories, recursively. Returns an array of paths
18
- * relative to the input directory path.
18
+ * relative to the given input path.
19
+ *
20
+ * @category Node : File
21
+ * @category Package : @augment-vir/node
22
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
19
23
  */
20
24
  export async function readDirRecursive(dirPath) {
21
25
  return await internalReadDirPathsRecursive(dirPath, dirPath);
22
26
  }
23
27
  /**
24
- * Reads all files within a directory and then filters them by the given extension or extensions.
25
- * Returns that filtered list.
28
+ * Reads all files within a single directory and filters them by the given extension or extensions.
29
+ *
30
+ * @category Node : File
31
+ * @category Package : @augment-vir/node
32
+ * @returns That filtered list of paths.
33
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
26
34
  */
27
35
  export async function readDirFilesByExtension({ dirPath, extension, extensions, }) {
28
36
  const extensionsToCheck = extensions || [extension];
@@ -1 +1,9 @@
1
+ /**
2
+ * Reads a file if it exists, or just return `undefined`.
3
+ *
4
+ * @category Node : File
5
+ * @category Package : @augment-vir/node
6
+ * @returns The file contents as a string if the file exists, otherwise `undefined`.
7
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
8
+ */
1
9
  export declare function readFileIfExists(path: string): Promise<string | undefined>;
@@ -1,5 +1,13 @@
1
1
  import { existsSync } from 'node:fs';
2
2
  import { readFile } from 'node:fs/promises';
3
+ /**
4
+ * Reads a file if it exists, or just return `undefined`.
5
+ *
6
+ * @category Node : File
7
+ * @category Package : @augment-vir/node
8
+ * @returns The file contents as a string if the file exists, otherwise `undefined`.
9
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
10
+ */
3
11
  export async function readFileIfExists(path) {
4
12
  if (existsSync(path)) {
5
13
  return (await readFile(path)).toString();
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Creates a symlink.
3
+ *
4
+ * @category Node : File
5
+ * @category Package : @augment-vir/node
6
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
7
+ */
1
8
  export declare function createSymlink({ linkTo, symlinkPath, }: {
2
9
  /**
3
10
  * Path that the symlink will link to. If relative, it will be linked relative to the symlink
@@ -1,5 +1,12 @@
1
1
  import { existsSync } from 'node:fs';
2
2
  import { lstat, readlink, stat, symlink } from 'node:fs/promises';
3
+ /**
4
+ * Creates a symlink.
5
+ *
6
+ * @category Node : File
7
+ * @category Package : @augment-vir/node
8
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
9
+ */
3
10
  export async function createSymlink({ linkTo, symlinkPath, }) {
4
11
  if (existsSync(symlinkPath)) {
5
12
  if (!(await lstat(symlinkPath)).isSymbolicLink()) {
@@ -1,5 +1,9 @@
1
1
  /**
2
2
  * Writes to the given file path and always ensures that the path's parent directories are all
3
3
  * created.
4
+ *
5
+ * @category Node : File
6
+ * @category Package : @augment-vir/node
7
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
4
8
  */
5
9
  export declare function writeFileAndDir(path: string, contents: string | NodeJS.ArrayBufferView): Promise<void>;
@@ -3,6 +3,10 @@ import { dirname } from 'node:path';
3
3
  /**
4
4
  * Writes to the given file path and always ensures that the path's parent directories are all
5
5
  * created.
6
+ *
7
+ * @category Node : File
8
+ * @category Package : @augment-vir/node
9
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
6
10
  */
7
11
  export async function writeFileAndDir(path, contents) {
8
12
  await mkdir(dirname(path), { recursive: true });
@@ -1,5 +1,12 @@
1
1
  import type { UnknownObject } from '@augment-vir/core';
2
2
  import type { PackageJson } from 'type-fest';
3
+ /**
4
+ * An npm workspace object. This is the return type for {@link queryNpmWorkspace}.
5
+ *
6
+ * @category Node : Npm
7
+ * @category Package : @augment-vir/node
8
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
9
+ */
3
10
  export type NpmWorkspace = PackageJson & {
4
11
  _id: string;
5
12
  deduped: boolean;
@@ -15,4 +22,11 @@ export type NpmWorkspace = PackageJson & {
15
22
  resolved: null;
16
23
  to: string[];
17
24
  };
25
+ /**
26
+ * Get a list of all NPM workspaces in the given mono-repo directory using npm's CLI.
27
+ *
28
+ * @category Node : Npm
29
+ * @category Package : @augment-vir/node
30
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
31
+ */
18
32
  export declare function queryNpmWorkspace(cwd: string): Promise<NpmWorkspace[]>;
@@ -1,4 +1,11 @@
1
- import { runShellCommand } from '../shell.js';
1
+ import { runShellCommand } from '../terminal/shell.js';
2
+ /**
3
+ * Get a list of all NPM workspaces in the given mono-repo directory using npm's CLI.
4
+ *
5
+ * @category Node : Npm
6
+ * @category Package : @augment-vir/node
7
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
8
+ */
2
9
  export async function queryNpmWorkspace(cwd) {
3
10
  const queryOutput = await runShellCommand('npm query .workspace', {
4
11
  cwd,
@@ -1,2 +1,11 @@
1
1
  import { PackageJson } from 'type-fest';
2
+ /**
3
+ * Read the `package.json` file contained within the given directory.
4
+ *
5
+ * @category Node : Npm
6
+ * @category Package : @augment-vir/node
7
+ * @throws `TypeError` if the given directory has no `package.json` or the `package.json` is
8
+ * invalid.
9
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
10
+ */
2
11
  export declare function readPackageJson(dirPath: string): Promise<PackageJson>;
@@ -1,6 +1,15 @@
1
1
  import { check } from '@augment-vir/assert';
2
2
  import { join } from 'node:path';
3
3
  import { readJsonFile } from '../fs/json.js';
4
+ /**
5
+ * Read the `package.json` file contained within the given directory.
6
+ *
7
+ * @category Node : Npm
8
+ * @category Package : @augment-vir/node
9
+ * @throws `TypeError` if the given directory has no `package.json` or the `package.json` is
10
+ * invalid.
11
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
12
+ */
4
13
  export async function readPackageJson(dirPath) {
5
14
  const packageJsonPath = join(dirPath, 'package.json');
6
15
  const packageJson = (await readJsonFile(packageJsonPath));
@@ -1,6 +1,39 @@
1
+ /**
2
+ * The three major operating system types.
3
+ *
4
+ * @category Node : OS
5
+ * @category Package : @augment-vir/node
6
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
7
+ */
1
8
  export declare enum OperatingSystem {
2
9
  Linux = "linux",
3
10
  Mac = "mac",
4
11
  Windows = "windows"
5
12
  }
13
+ /**
14
+ * The current operating system type, as deduced from
15
+ * [`process.platform`](https://nodejs.org/api/process.html#processplatform).
16
+ *
17
+ * @category Node : OS
18
+ * @category Package : @augment-vir/node
19
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
20
+ */
6
21
  export declare const currentOperatingSystem: OperatingSystem;
22
+ /**
23
+ * Checks if the current operating system is the requested one.
24
+ *
25
+ * @category Node : OS
26
+ * @category Package : @augment-vir/node
27
+ * @example
28
+ *
29
+ * ```ts
30
+ * import {isOperatingSystem, OperatingSystem} from '@augment-vir/node';
31
+ *
32
+ * if (isOperatingSystem(OperatingSystem.Mac)) {
33
+ * // do something
34
+ * }
35
+ * ```
36
+ *
37
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
38
+ */
39
+ export declare function isOperatingSystem(operatingSystem: OperatingSystem): boolean;
@@ -1,10 +1,45 @@
1
+ /**
2
+ * The three major operating system types.
3
+ *
4
+ * @category Node : OS
5
+ * @category Package : @augment-vir/node
6
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
7
+ */
1
8
  export var OperatingSystem;
2
9
  (function (OperatingSystem) {
3
10
  OperatingSystem["Linux"] = "linux";
4
11
  OperatingSystem["Mac"] = "mac";
5
12
  OperatingSystem["Windows"] = "windows";
6
13
  })(OperatingSystem || (OperatingSystem = {}));
14
+ /**
15
+ * The current operating system type, as deduced from
16
+ * [`process.platform`](https://nodejs.org/api/process.html#processplatform).
17
+ *
18
+ * @category Node : OS
19
+ * @category Package : @augment-vir/node
20
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
21
+ */
7
22
  export const currentOperatingSystem = getOperatingSystem();
23
+ /**
24
+ * Checks if the current operating system is the requested one.
25
+ *
26
+ * @category Node : OS
27
+ * @category Package : @augment-vir/node
28
+ * @example
29
+ *
30
+ * ```ts
31
+ * import {isOperatingSystem, OperatingSystem} from '@augment-vir/node';
32
+ *
33
+ * if (isOperatingSystem(OperatingSystem.Mac)) {
34
+ * // do something
35
+ * }
36
+ * ```
37
+ *
38
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
39
+ */
40
+ export function isOperatingSystem(operatingSystem) {
41
+ return currentOperatingSystem === operatingSystem;
42
+ }
8
43
  function getOperatingSystem() {
9
44
  /** We can't test all of these on a single system. */
10
45
  /* node:coverage ignore next 7 */
@@ -2,4 +2,23 @@ import type { MaybePromise } from '@augment-vir/common';
2
2
  export declare function findAncestor(currentPath: string, callback: (path: string) => Promise<boolean>): Promise<string | undefined>;
3
3
  export declare function findAncestor(currentPath: string, callback: (path: string) => boolean): string | undefined;
4
4
  export declare function findAncestor(currentPath: string, callback: (path: string) => MaybePromise<boolean>): MaybePromise<string | undefined>;
5
+ /**
6
+ * Join a list of paths to the given `parentDirPath`. This is particularly useful for getting full
7
+ * paths from the output of
8
+ * [`readdir`](https://nodejs.org/api/fs.html#fspromisesreaddirpath-options).
9
+ *
10
+ * @category Path : Node
11
+ * @category Package : @augment-vir/node
12
+ * @example
13
+ *
14
+ * ```ts
15
+ * import {readdir} from 'node:fs/promises';
16
+ * import {join} from 'node:path';
17
+ *
18
+ * const parentDir = join('my', 'path');
19
+ * const dirs = joinFilesToDir(parentDir, await readdir(parentDir));
20
+ * ```
21
+ *
22
+ * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
23
+ */
5
24
  export declare function joinFilesToDir(parentDirPath: string, childNames: ReadonlyArray<string>): Array<string>;