@augment-vir/node 30.0.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/LICENSE-CC0 +121 -0
- package/LICENSE-MIT +21 -0
- package/README.md +13 -0
- package/dist/augments/console/question.d.ts +14 -0
- package/dist/augments/console/question.js +63 -0
- package/dist/augments/docker.d.ts +44 -0
- package/dist/augments/docker.js +40 -0
- package/dist/augments/download.d.ts +4 -0
- package/dist/augments/download.js +19 -0
- package/dist/augments/fs/json.d.ts +8 -0
- package/dist/augments/fs/json.js +22 -0
- package/dist/augments/fs/read-dir.d.ts +16 -0
- package/dist/augments/fs/read-dir.js +31 -0
- package/dist/augments/fs/read-file.d.ts +1 -0
- package/dist/augments/fs/read-file.js +10 -0
- package/dist/augments/fs/symlink.d.ts +9 -0
- package/dist/augments/fs/symlink.js +16 -0
- package/dist/augments/fs/write.d.ts +5 -0
- package/dist/augments/fs/write.js +10 -0
- package/dist/augments/npm/query-workspace.d.ts +18 -0
- package/dist/augments/npm/query-workspace.js +14 -0
- package/dist/augments/npm/read-package-json.d.ts +2 -0
- package/dist/augments/npm/read-package-json.js +14 -0
- package/dist/augments/os/operating-system.d.ts +6 -0
- package/dist/augments/os/operating-system.js +20 -0
- package/dist/augments/path/ancestor.d.ts +5 -0
- package/dist/augments/path/ancestor.js +29 -0
- package/dist/augments/path/os-path.d.ts +9 -0
- package/dist/augments/path/os-path.js +27 -0
- package/dist/augments/path/root.d.ts +1 -0
- package/dist/augments/path/root.js +5 -0
- package/dist/augments/prisma.d.ts +21 -0
- package/dist/augments/prisma.js +21 -0
- package/dist/augments/shell.d.ts +87 -0
- package/dist/augments/shell.js +152 -0
- package/dist/docker/containers/container-info.d.ts +28 -0
- package/dist/docker/containers/container-info.js +24 -0
- package/dist/docker/containers/container-status.d.ts +17 -0
- package/dist/docker/containers/container-status.js +53 -0
- package/dist/docker/containers/copy-to-container.d.ts +7 -0
- package/dist/docker/containers/copy-to-container.js +10 -0
- package/dist/docker/containers/docker-command-inputs.d.ts +20 -0
- package/dist/docker/containers/docker-command-inputs.js +36 -0
- package/dist/docker/containers/kill-container.d.ts +10 -0
- package/dist/docker/containers/kill-container.js +12 -0
- package/dist/docker/containers/run-command.d.ts +12 -0
- package/dist/docker/containers/run-command.js +25 -0
- package/dist/docker/containers/run-container.d.ts +15 -0
- package/dist/docker/containers/run-container.js +47 -0
- package/dist/docker/containers/run-container.mock.d.ts +2 -0
- package/dist/docker/containers/run-container.mock.js +14 -0
- package/dist/docker/containers/try-or-kill-container.d.ts +6 -0
- package/dist/docker/containers/try-or-kill-container.js +14 -0
- package/dist/docker/docker-image.d.ts +9 -0
- package/dist/docker/docker-image.js +36 -0
- package/dist/docker/docker-startup.d.ts +2 -0
- package/dist/docker/docker-startup.js +40 -0
- package/dist/file-paths.mock.d.ts +17 -0
- package/dist/file-paths.mock.js +19 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +16 -0
- package/dist/prisma/prisma-client.d.ts +9 -0
- package/dist/prisma/prisma-client.js +28 -0
- package/dist/prisma/prisma-database.d.ts +3 -0
- package/dist/prisma/prisma-database.js +22 -0
- package/dist/prisma/prisma-database.mock.d.ts +1 -0
- package/dist/prisma/prisma-database.mock.js +7 -0
- package/dist/prisma/prisma-errors.d.ts +12 -0
- package/dist/prisma/prisma-errors.js +18 -0
- package/dist/prisma/prisma-migrations.d.ts +17 -0
- package/dist/prisma/prisma-migrations.js +105 -0
- package/dist/prisma/run-prisma-command.d.ts +8 -0
- package/dist/prisma/run-prisma-command.js +48 -0
- package/package.json +58 -0
package/LICENSE-CC0
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
CC0 1.0 Universal
|
|
2
|
+
|
|
3
|
+
Creative Commons Legal Code
|
|
4
|
+
|
|
5
|
+
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
|
6
|
+
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
|
7
|
+
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
|
8
|
+
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
|
9
|
+
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
|
10
|
+
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
|
11
|
+
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
|
12
|
+
HEREUNDER.
|
|
13
|
+
|
|
14
|
+
Statement of Purpose
|
|
15
|
+
|
|
16
|
+
The laws of most jurisdictions throughout the world automatically confer
|
|
17
|
+
exclusive Copyright and Related Rights (defined below) upon the creator
|
|
18
|
+
and subsequent owner(s) (each and all, an "owner") of an original work of
|
|
19
|
+
authorship and/or a database (each, a "Work").
|
|
20
|
+
|
|
21
|
+
Certain owners wish to permanently relinquish those rights to a Work for
|
|
22
|
+
the purpose of contributing to a commons of creative, cultural and
|
|
23
|
+
scientific works ("Commons") that the public can reliably and without fear
|
|
24
|
+
of later claims of infringement build upon, modify, incorporate in other
|
|
25
|
+
works, reuse and redistribute as freely as possible in any form whatsoever
|
|
26
|
+
and for any purposes, including without limitation commercial purposes.
|
|
27
|
+
These owners may contribute to the Commons to promote the ideal of a free
|
|
28
|
+
culture and the further production of creative, cultural and scientific
|
|
29
|
+
works, or to gain reputation or greater distribution for their Work in
|
|
30
|
+
part through the use and efforts of others.
|
|
31
|
+
|
|
32
|
+
For these and/or other purposes and motivations, and without any
|
|
33
|
+
expectation of additional consideration or compensation, the person
|
|
34
|
+
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
|
35
|
+
is an owner of Copyright and Related Rights in the Work, voluntarily
|
|
36
|
+
elects to apply CC0 to the Work and publicly distribute the Work under its
|
|
37
|
+
terms, with knowledge of his or her Copyright and Related Rights in the
|
|
38
|
+
Work and the meaning and intended legal effect of CC0 on those rights.
|
|
39
|
+
|
|
40
|
+
1. Copyright and Related Rights. A Work made available under CC0 may be
|
|
41
|
+
protected by copyright and related or neighboring rights ("Copyright and
|
|
42
|
+
Related Rights"). Copyright and Related Rights include, but are not
|
|
43
|
+
limited to, the following:
|
|
44
|
+
|
|
45
|
+
i. the right to reproduce, adapt, distribute, perform, display,
|
|
46
|
+
communicate, and translate a Work;
|
|
47
|
+
ii. moral rights retained by the original author(s) and/or performer(s);
|
|
48
|
+
iii. publicity and privacy rights pertaining to a person's image or
|
|
49
|
+
likeness depicted in a Work;
|
|
50
|
+
iv. rights protecting against unfair competition in regards to a Work,
|
|
51
|
+
subject to the limitations in paragraph 4(a), below;
|
|
52
|
+
v. rights protecting the extraction, dissemination, use and reuse of data
|
|
53
|
+
in a Work;
|
|
54
|
+
vi. database rights (such as those arising under Directive 96/9/EC of the
|
|
55
|
+
European Parliament and of the Council of 11 March 1996 on the legal
|
|
56
|
+
protection of databases, and under any national implementation
|
|
57
|
+
thereof, including any amended or successor version of such
|
|
58
|
+
directive); and
|
|
59
|
+
vii. other similar, equivalent or corresponding rights throughout the
|
|
60
|
+
world based on applicable law or treaty, and any national
|
|
61
|
+
implementations thereof.
|
|
62
|
+
|
|
63
|
+
2. Waiver. To the greatest extent permitted by, but not in contravention
|
|
64
|
+
of, applicable law, Affirmer hereby overtly, fully, permanently,
|
|
65
|
+
irrevocably and unconditionally waives, abandons, and surrenders all of
|
|
66
|
+
Affirmer's Copyright and Related Rights and associated claims and causes
|
|
67
|
+
of action, whether now known or unknown (including existing as well as
|
|
68
|
+
future claims and causes of action), in the Work (i) in all territories
|
|
69
|
+
worldwide, (ii) for the maximum duration provided by applicable law or
|
|
70
|
+
treaty (including future time extensions), (iii) in any current or future
|
|
71
|
+
medium and for any number of copies, and (iv) for any purpose whatsoever,
|
|
72
|
+
including without limitation commercial, advertising or promotional
|
|
73
|
+
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
|
74
|
+
member of the public at large and to the detriment of Affirmer's heirs and
|
|
75
|
+
successors, fully intending that such Waiver shall not be subject to
|
|
76
|
+
revocation, rescission, cancellation, termination, or any other legal or
|
|
77
|
+
equitable action to disrupt the quiet enjoyment of the Work by the public
|
|
78
|
+
as contemplated by Affirmer's express Statement of Purpose.
|
|
79
|
+
|
|
80
|
+
3. Public License Fallback. Should any part of the Waiver for any reason
|
|
81
|
+
be judged legally invalid or ineffective under applicable law, then the
|
|
82
|
+
Waiver shall be preserved to the maximum extent permitted taking into
|
|
83
|
+
account Affirmer's express Statement of Purpose. In addition, to the
|
|
84
|
+
extent the Waiver is so judged Affirmer hereby grants to each affected
|
|
85
|
+
person a royalty-free, non transferable, non sublicensable, non exclusive,
|
|
86
|
+
irrevocable and unconditional license to exercise Affirmer's Copyright and
|
|
87
|
+
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
|
88
|
+
maximum duration provided by applicable law or treaty (including future
|
|
89
|
+
time extensions), (iii) in any current or future medium and for any number
|
|
90
|
+
of copies, and (iv) for any purpose whatsoever, including without
|
|
91
|
+
limitation commercial, advertising or promotional purposes (the
|
|
92
|
+
"License"). The License shall be deemed effective as of the date CC0 was
|
|
93
|
+
applied by Affirmer to the Work. Should any part of the License for any
|
|
94
|
+
reason be judged legally invalid or ineffective under applicable law, such
|
|
95
|
+
partial invalidity or ineffectiveness shall not invalidate the remainder
|
|
96
|
+
of the License, and in such case Affirmer hereby affirms that he or she
|
|
97
|
+
will not (i) exercise any of his or her remaining Copyright and Related
|
|
98
|
+
Rights in the Work or (ii) assert any associated claims and causes of
|
|
99
|
+
action with respect to the Work, in either case contrary to Affirmer's
|
|
100
|
+
express Statement of Purpose.
|
|
101
|
+
|
|
102
|
+
4. Limitations and Disclaimers.
|
|
103
|
+
|
|
104
|
+
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
|
105
|
+
surrendered, licensed or otherwise affected by this document.
|
|
106
|
+
b. Affirmer offers the Work as-is and makes no representations or
|
|
107
|
+
warranties of any kind concerning the Work, express, implied,
|
|
108
|
+
statutory or otherwise, including without limitation warranties of
|
|
109
|
+
title, merchantability, fitness for a particular purpose, non
|
|
110
|
+
infringement, or the absence of latent or other defects, accuracy, or
|
|
111
|
+
the present or absence of errors, whether or not discoverable, all to
|
|
112
|
+
the greatest extent permissible under applicable law.
|
|
113
|
+
c. Affirmer disclaims responsibility for clearing rights of other persons
|
|
114
|
+
that may apply to the Work or any use thereof, including without
|
|
115
|
+
limitation any person's Copyright and Related Rights in the Work.
|
|
116
|
+
Further, Affirmer disclaims responsibility for obtaining any necessary
|
|
117
|
+
consents, permissions or other rights required for any use of the
|
|
118
|
+
Work.
|
|
119
|
+
d. Affirmer understands and acknowledges that Creative Commons is not a
|
|
120
|
+
party to this document and has no duty or obligation with respect to
|
|
121
|
+
this CC0 or use of the Work.
|
package/LICENSE-MIT
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 electrovir
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# @augment-vir/node
|
|
2
|
+
|
|
3
|
+
## Prisma flows
|
|
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`
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type AnyDuration } from '@date-vir/duration';
|
|
2
|
+
/** Can't test requiring user input. */
|
|
3
|
+
export type AskQuestionOptions = {
|
|
4
|
+
timeout: AnyDuration;
|
|
5
|
+
hideUserInput: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare function askQuestion(questionToAsk: string, { hideUserInput, timeout, }?: Partial<AskQuestionOptions>): Promise<string>;
|
|
8
|
+
export type QuestionUntilConditionMetConfig = {
|
|
9
|
+
questionToAsk: string;
|
|
10
|
+
conditionCallback: (response: string) => boolean | Promise<boolean>;
|
|
11
|
+
invalidInputMessage: string;
|
|
12
|
+
tryCountMax?: number;
|
|
13
|
+
} & Partial<AskQuestionOptions>;
|
|
14
|
+
export declare function askQuestionUntilConditionMet({ questionToAsk, conditionCallback, invalidInputMessage, tryCountMax, ...options }: QuestionUntilConditionMetConfig): Promise<string>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { log } from '@augment-vir/common';
|
|
2
|
+
import { convertDuration, DurationUnit } from '@date-vir/duration';
|
|
3
|
+
import { createInterface } from 'node:readline';
|
|
4
|
+
const defaultAskQuestionOptions = {
|
|
5
|
+
timeout: { seconds: 60 },
|
|
6
|
+
hideUserInput: false,
|
|
7
|
+
};
|
|
8
|
+
export async function askQuestion(questionToAsk, { hideUserInput = defaultAskQuestionOptions.hideUserInput, timeout = defaultAskQuestionOptions.timeout, } = defaultAskQuestionOptions) {
|
|
9
|
+
const cliInterface = createInterface({
|
|
10
|
+
input: process.stdin,
|
|
11
|
+
output: process.stdout,
|
|
12
|
+
});
|
|
13
|
+
if (hideUserInput) {
|
|
14
|
+
let promptWritten = false;
|
|
15
|
+
/** _writeToOutput is not in the types OR in the Node.js documentation but is a thing. */
|
|
16
|
+
cliInterface._writeToOutput = (prompt) => {
|
|
17
|
+
if (!promptWritten) {
|
|
18
|
+
cliInterface.output.write(prompt);
|
|
19
|
+
promptWritten = true;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
// handle killing the process
|
|
24
|
+
cliInterface.on('SIGINT', () => {
|
|
25
|
+
cliInterface.close();
|
|
26
|
+
process.stdout.write('\n');
|
|
27
|
+
process.kill(process.pid, 'SIGINT');
|
|
28
|
+
});
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
const timeoutMs = convertDuration(timeout, DurationUnit.Milliseconds).milliseconds;
|
|
31
|
+
const timeoutId = timeoutMs
|
|
32
|
+
? setTimeout(() => {
|
|
33
|
+
cliInterface.close();
|
|
34
|
+
reject(new Error(`Took too long to respond (over "${Math.floor(timeoutMs / 1000)}" seconds)`));
|
|
35
|
+
}, timeoutMs)
|
|
36
|
+
: undefined;
|
|
37
|
+
process.stdout.write(questionToAsk + '\n');
|
|
38
|
+
cliInterface.question('', (response) => {
|
|
39
|
+
if (timeoutId != undefined) {
|
|
40
|
+
clearTimeout(timeoutId);
|
|
41
|
+
}
|
|
42
|
+
cliInterface.close();
|
|
43
|
+
resolve(response);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
export async function askQuestionUntilConditionMet({ questionToAsk, conditionCallback, invalidInputMessage, tryCountMax = 5, ...options }) {
|
|
48
|
+
let wasConditionMet = false;
|
|
49
|
+
let retryCount = 0;
|
|
50
|
+
let response = '';
|
|
51
|
+
while (!wasConditionMet && retryCount <= tryCountMax) {
|
|
52
|
+
response = (await askQuestion(questionToAsk, options)).trim();
|
|
53
|
+
wasConditionMet = await conditionCallback(response);
|
|
54
|
+
if (!wasConditionMet) {
|
|
55
|
+
log.error(invalidInputMessage);
|
|
56
|
+
}
|
|
57
|
+
retryCount++;
|
|
58
|
+
}
|
|
59
|
+
if (retryCount > tryCountMax) {
|
|
60
|
+
throw new Error(`Max input attempts (${tryCountMax}) exceeded.`);
|
|
61
|
+
}
|
|
62
|
+
return response;
|
|
63
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { getContainerInfo } from '../docker/containers/container-info.js';
|
|
2
|
+
import { getContainerLogs, getContainerStatus, waitUntilContainerExited, waitUntilContainerRemoved, waitUntilContainerRunning } from '../docker/containers/container-status.js';
|
|
3
|
+
import { copyToContainer } from '../docker/containers/copy-to-container.js';
|
|
4
|
+
import { makeEnvFlags, makePortMapFlags, makeVolumeFlags } from '../docker/containers/docker-command-inputs.js';
|
|
5
|
+
import { killContainer } from '../docker/containers/kill-container.js';
|
|
6
|
+
import { runContainerCommand } from '../docker/containers/run-command.js';
|
|
7
|
+
import { runContainer } from '../docker/containers/run-container.js';
|
|
8
|
+
import { tryOrKillContainer } from '../docker/containers/try-or-kill-container.js';
|
|
9
|
+
import { isImageInLocalRegistry, removeImageFromLocalRegistry, updateImage } from '../docker/docker-image.js';
|
|
10
|
+
import { isDockerRunning, startDocker } from '../docker/docker-startup.js';
|
|
11
|
+
export { DockerContainerStatusEnum, type DockerContainerInfo, type DockerContainerInfoState, } from '../docker/containers/container-info.js';
|
|
12
|
+
export { DockerContainerStatus, exitedDockerContainerStatuses, } from '../docker/containers/container-status.js';
|
|
13
|
+
export { type CopyToDockerContainerParams } from '../docker/containers/copy-to-container.js';
|
|
14
|
+
export { type DockerEnvMap, type DockerPortMap, type DockerVolumeMap, type DockerVolumeMappingType, } from '../docker/containers/docker-command-inputs.js';
|
|
15
|
+
export { type RunDockerContainerCommandParams } from '../docker/containers/run-command.js';
|
|
16
|
+
export { type RunDockerContainerParams } from '../docker/containers/run-container.js';
|
|
17
|
+
/** Centralized Docker API from `@augment-vir/node`. */
|
|
18
|
+
export declare const docker: {
|
|
19
|
+
isRunning: typeof isDockerRunning;
|
|
20
|
+
start: typeof startDocker;
|
|
21
|
+
image: {
|
|
22
|
+
update: typeof updateImage;
|
|
23
|
+
remove: typeof removeImageFromLocalRegistry;
|
|
24
|
+
exists: typeof isImageInLocalRegistry;
|
|
25
|
+
};
|
|
26
|
+
container: {
|
|
27
|
+
getStatus: typeof getContainerStatus;
|
|
28
|
+
waitUntilRunning: typeof waitUntilContainerRunning;
|
|
29
|
+
waitUntilExited: typeof waitUntilContainerExited;
|
|
30
|
+
waitUntilRemoved: typeof waitUntilContainerRemoved;
|
|
31
|
+
tryOrKill: typeof tryOrKillContainer;
|
|
32
|
+
run: typeof runContainer;
|
|
33
|
+
kill: typeof killContainer;
|
|
34
|
+
copyTo: typeof copyToContainer;
|
|
35
|
+
runCommand: typeof runContainerCommand;
|
|
36
|
+
getInfo: typeof getContainerInfo;
|
|
37
|
+
getLogs: typeof getContainerLogs;
|
|
38
|
+
};
|
|
39
|
+
util: {
|
|
40
|
+
makeVolumeFlags: typeof makeVolumeFlags;
|
|
41
|
+
makePortMapFlags: typeof makePortMapFlags;
|
|
42
|
+
makeEnvFlags: typeof makeEnvFlags;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { getContainerInfo } from '../docker/containers/container-info.js';
|
|
2
|
+
import { getContainerLogs, getContainerStatus, waitUntilContainerExited, waitUntilContainerRemoved, waitUntilContainerRunning, } from '../docker/containers/container-status.js';
|
|
3
|
+
import { copyToContainer } from '../docker/containers/copy-to-container.js';
|
|
4
|
+
import { makeEnvFlags, makePortMapFlags, makeVolumeFlags, } from '../docker/containers/docker-command-inputs.js';
|
|
5
|
+
import { killContainer } from '../docker/containers/kill-container.js';
|
|
6
|
+
import { runContainerCommand } from '../docker/containers/run-command.js';
|
|
7
|
+
import { runContainer } from '../docker/containers/run-container.js';
|
|
8
|
+
import { tryOrKillContainer } from '../docker/containers/try-or-kill-container.js';
|
|
9
|
+
import { isImageInLocalRegistry, removeImageFromLocalRegistry, updateImage, } from '../docker/docker-image.js';
|
|
10
|
+
import { isDockerRunning, startDocker } from '../docker/docker-startup.js';
|
|
11
|
+
export { DockerContainerStatusEnum, } from '../docker/containers/container-info.js';
|
|
12
|
+
export { DockerContainerStatus, exitedDockerContainerStatuses, } from '../docker/containers/container-status.js';
|
|
13
|
+
/** Centralized Docker API from `@augment-vir/node`. */
|
|
14
|
+
export const docker = {
|
|
15
|
+
isRunning: isDockerRunning,
|
|
16
|
+
start: startDocker,
|
|
17
|
+
image: {
|
|
18
|
+
update: updateImage,
|
|
19
|
+
remove: removeImageFromLocalRegistry,
|
|
20
|
+
exists: isImageInLocalRegistry,
|
|
21
|
+
},
|
|
22
|
+
container: {
|
|
23
|
+
getStatus: getContainerStatus,
|
|
24
|
+
waitUntilRunning: waitUntilContainerRunning,
|
|
25
|
+
waitUntilExited: waitUntilContainerExited,
|
|
26
|
+
waitUntilRemoved: waitUntilContainerRemoved,
|
|
27
|
+
tryOrKill: tryOrKillContainer,
|
|
28
|
+
run: runContainer,
|
|
29
|
+
kill: killContainer,
|
|
30
|
+
copyTo: copyToContainer,
|
|
31
|
+
runCommand: runContainerCommand,
|
|
32
|
+
getInfo: getContainerInfo,
|
|
33
|
+
getLogs: getContainerLogs,
|
|
34
|
+
},
|
|
35
|
+
util: {
|
|
36
|
+
makeVolumeFlags,
|
|
37
|
+
makePortMapFlags,
|
|
38
|
+
makeEnvFlags,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createWriteStream } from 'node:fs';
|
|
2
|
+
import { mkdir } from 'node:fs/promises';
|
|
3
|
+
import { dirname } from 'node:path';
|
|
4
|
+
import { Readable } from 'node:stream';
|
|
5
|
+
import { finished } from 'node:stream/promises';
|
|
6
|
+
export async function downloadFile({ url, writePath }) {
|
|
7
|
+
const response = await fetch(url);
|
|
8
|
+
if (!response.ok) {
|
|
9
|
+
throw new Error(`${response.status}: ${response.statusText}`);
|
|
10
|
+
}
|
|
11
|
+
/** Idk how to actually trigger a response with no body. */
|
|
12
|
+
/* node:coverage ignore next 3 */
|
|
13
|
+
if (!response.body) {
|
|
14
|
+
throw new Error(`Response body is missing from '${url}'.`);
|
|
15
|
+
}
|
|
16
|
+
await mkdir(dirname(writePath), { recursive: true });
|
|
17
|
+
const fileStream = createWriteStream(writePath);
|
|
18
|
+
await finished(Readable.fromWeb(response.body).pipe(fileStream));
|
|
19
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { JsonCompatibleArray, JsonCompatibleObject, type JsonCompatibleValue } from '@augment-vir/common';
|
|
2
|
+
import type { PartialWithUndefined } from '@augment-vir/core';
|
|
3
|
+
export declare function readJsonFile(path: string): Promise<JsonCompatibleValue | undefined>;
|
|
4
|
+
export type WriteJsonOptions = PartialWithUndefined<{
|
|
5
|
+
includeTrailingNewLine: boolean;
|
|
6
|
+
}>;
|
|
7
|
+
export declare function writeJsonFile(path: string, data: JsonCompatibleValue, options?: WriteJsonOptions): Promise<void>;
|
|
8
|
+
export declare function appendJsonFile(path: string, newData: JsonCompatibleObject | JsonCompatibleArray, options?: WriteJsonOptions): Promise<void>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { appendJson, } from '@augment-vir/common';
|
|
2
|
+
import { mkdir, readFile } from 'node:fs/promises';
|
|
3
|
+
import { dirname } from 'node:path';
|
|
4
|
+
import { writeFileAndDir } from './write.js';
|
|
5
|
+
export async function readJsonFile(path) {
|
|
6
|
+
try {
|
|
7
|
+
const contents = (await readFile(path)).toString();
|
|
8
|
+
return JSON.parse(contents);
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export async function writeJsonFile(path, data, options = {}) {
|
|
15
|
+
await mkdir(dirname(path), { recursive: true });
|
|
16
|
+
const trailingNewLine = options.includeTrailingNewLine ? '\n' : '';
|
|
17
|
+
await writeFileAndDir(path, JSON.stringify(data, null, 4) + trailingNewLine);
|
|
18
|
+
}
|
|
19
|
+
export async function appendJsonFile(path, newData, options = {}) {
|
|
20
|
+
const fileJson = await readJsonFile(path);
|
|
21
|
+
await writeJsonFile(path, appendJson(fileJson, newData), options);
|
|
22
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { RequireExactlyOne } from 'type-fest';
|
|
2
|
+
/**
|
|
3
|
+
* Gets all files within a directory and its subdirectories, recursively. Returns an array of paths
|
|
4
|
+
* relative to the input directory path.
|
|
5
|
+
*/
|
|
6
|
+
export declare function readDirRecursive(dirPath: string): Promise<string[]>;
|
|
7
|
+
/**
|
|
8
|
+
* Reads all files within a directory and then filters them by the given extension or extensions.
|
|
9
|
+
* Returns that filtered list.
|
|
10
|
+
*/
|
|
11
|
+
export declare function readDirFilesByExtension({ dirPath, extension, extensions, }: {
|
|
12
|
+
dirPath: string;
|
|
13
|
+
} & RequireExactlyOne<{
|
|
14
|
+
extension: string;
|
|
15
|
+
extensions: ReadonlyArray<string>;
|
|
16
|
+
}>): Promise<string[]>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { readdir, stat } from 'node:fs/promises';
|
|
2
|
+
import { join, relative } from 'node:path';
|
|
3
|
+
async function internalReadDirPathsRecursive(dirPath, basePath) {
|
|
4
|
+
const dirContents = await readdir(dirPath);
|
|
5
|
+
const recursiveContents = (await Promise.all(dirContents.map(async (fileName) => {
|
|
6
|
+
const filePath = join(dirPath, fileName);
|
|
7
|
+
if ((await stat(filePath)).isDirectory()) {
|
|
8
|
+
return internalReadDirPathsRecursive(filePath, basePath);
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
return relative(basePath, filePath);
|
|
12
|
+
}
|
|
13
|
+
}))).flat();
|
|
14
|
+
return recursiveContents;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Gets all files within a directory and its subdirectories, recursively. Returns an array of paths
|
|
18
|
+
* relative to the input directory path.
|
|
19
|
+
*/
|
|
20
|
+
export async function readDirRecursive(dirPath) {
|
|
21
|
+
return await internalReadDirPathsRecursive(dirPath, dirPath);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Reads all files within a directory and then filters them by the given extension or extensions.
|
|
25
|
+
* Returns that filtered list.
|
|
26
|
+
*/
|
|
27
|
+
export async function readDirFilesByExtension({ dirPath, extension, extensions, }) {
|
|
28
|
+
const extensionsToCheck = extensions || [extension];
|
|
29
|
+
const fileNames = await readdir(dirPath);
|
|
30
|
+
return fileNames.filter((fileName) => extensionsToCheck.some((extensionToCheck) => fileName.endsWith(extensionToCheck)));
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function readFileIfExists(path: string): Promise<string | undefined>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function createSymlink({ linkTo, symlinkPath, }: {
|
|
2
|
+
/**
|
|
3
|
+
* Path that the symlink will link to. If relative, it will be linked relative to the symlink
|
|
4
|
+
* location.
|
|
5
|
+
*/
|
|
6
|
+
linkTo: string;
|
|
7
|
+
/** The location and name the symlink file to be created. */
|
|
8
|
+
symlinkPath: string;
|
|
9
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { lstat, readlink, stat, symlink } from 'node:fs/promises';
|
|
3
|
+
export async function createSymlink({ linkTo, symlinkPath, }) {
|
|
4
|
+
if (existsSync(symlinkPath)) {
|
|
5
|
+
if (!(await lstat(symlinkPath)).isSymbolicLink()) {
|
|
6
|
+
throw new Error(`Tried to create symlink at '${symlinkPath}' but a non-symlink file already exists in that location.`);
|
|
7
|
+
}
|
|
8
|
+
else if ((await readlink(symlinkPath)) !== linkTo) {
|
|
9
|
+
throw new Error(`Symlink already exists at '${symlinkPath}' but has a differently link path.`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
const isDir = (await stat(linkTo)).isDirectory();
|
|
14
|
+
await symlink(linkTo, symlinkPath, isDir ? 'dir' : 'file');
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* Writes to the given file path and always ensures that the path's parent directories are all
|
|
5
|
+
* created.
|
|
6
|
+
*/
|
|
7
|
+
export async function writeFileAndDir(path, contents) {
|
|
8
|
+
await mkdir(dirname(path), { recursive: true });
|
|
9
|
+
await writeFile(path, contents);
|
|
10
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { UnknownObject } from '@augment-vir/core';
|
|
2
|
+
import type { PackageJson } from 'type-fest';
|
|
3
|
+
export type NpmWorkspace = PackageJson & {
|
|
4
|
+
_id: string;
|
|
5
|
+
deduped: boolean;
|
|
6
|
+
dev: boolean;
|
|
7
|
+
from: string[];
|
|
8
|
+
inBundle: boolean;
|
|
9
|
+
location: string;
|
|
10
|
+
overridden: boolean;
|
|
11
|
+
path: string;
|
|
12
|
+
pkgid: string;
|
|
13
|
+
queryContext: UnknownObject;
|
|
14
|
+
realpath: string;
|
|
15
|
+
resolved: null;
|
|
16
|
+
to: string[];
|
|
17
|
+
};
|
|
18
|
+
export declare function queryNpmWorkspace(cwd: string): Promise<NpmWorkspace[]>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { runShellCommand } from '../shell.js';
|
|
2
|
+
export async function queryNpmWorkspace(cwd) {
|
|
3
|
+
const queryOutput = await runShellCommand('npm query .workspace', {
|
|
4
|
+
cwd,
|
|
5
|
+
rejectOnError: true,
|
|
6
|
+
});
|
|
7
|
+
try {
|
|
8
|
+
return JSON.parse(queryOutput.stdout);
|
|
9
|
+
/* node:coverage ignore next 3 */
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
throw new Error(`Failed to read npm workspace data for '${cwd}'`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { check } from '@augment-vir/assert';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { readJsonFile } from '../fs/json.js';
|
|
4
|
+
export async function readPackageJson(dirPath) {
|
|
5
|
+
const packageJsonPath = join(dirPath, 'package.json');
|
|
6
|
+
const packageJson = (await readJsonFile(packageJsonPath));
|
|
7
|
+
if (!packageJson) {
|
|
8
|
+
throw new TypeError(`package.json file does not exist in '${dirPath}'`);
|
|
9
|
+
}
|
|
10
|
+
if (!check.isObject(packageJson)) {
|
|
11
|
+
throw new TypeError(`Parsing package.json file did not return an object in '${dirPath}'`);
|
|
12
|
+
}
|
|
13
|
+
return packageJson;
|
|
14
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export var OperatingSystem;
|
|
2
|
+
(function (OperatingSystem) {
|
|
3
|
+
OperatingSystem["Linux"] = "linux";
|
|
4
|
+
OperatingSystem["Mac"] = "mac";
|
|
5
|
+
OperatingSystem["Windows"] = "windows";
|
|
6
|
+
})(OperatingSystem || (OperatingSystem = {}));
|
|
7
|
+
export const currentOperatingSystem = getOperatingSystem();
|
|
8
|
+
function getOperatingSystem() {
|
|
9
|
+
/** We can't test all of these on a single system. */
|
|
10
|
+
/* node:coverage ignore next 7 */
|
|
11
|
+
if (process.platform === 'win32') {
|
|
12
|
+
return OperatingSystem.Windows;
|
|
13
|
+
}
|
|
14
|
+
else if (process.platform === 'darwin') {
|
|
15
|
+
return OperatingSystem.Mac;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
return OperatingSystem.Linux;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { MaybePromise } from '@augment-vir/common';
|
|
2
|
+
export declare function findAncestor(currentPath: string, callback: (path: string) => Promise<boolean>): Promise<string | undefined>;
|
|
3
|
+
export declare function findAncestor(currentPath: string, callback: (path: string) => boolean): string | undefined;
|
|
4
|
+
export declare function findAncestor(currentPath: string, callback: (path: string) => MaybePromise<boolean>): MaybePromise<string | undefined>;
|
|
5
|
+
export declare function joinFilesToDir(parentDirPath: string, childNames: ReadonlyArray<string>): Array<string>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { check } from '@augment-vir/assert';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { systemRootPath } from './root.js';
|
|
4
|
+
export function findAncestor(currentPath, callback) {
|
|
5
|
+
if (currentPath === systemRootPath) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
const result = callback(currentPath);
|
|
9
|
+
if (check.isPromise(result)) {
|
|
10
|
+
return new Promise(async (resolve) => {
|
|
11
|
+
const awaitedResult = await result;
|
|
12
|
+
if (awaitedResult) {
|
|
13
|
+
resolve(currentPath);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
resolve(await findAncestor(dirname(currentPath), callback));
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
else if (result) {
|
|
21
|
+
return currentPath;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
return findAncestor(dirname(currentPath), callback);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function joinFilesToDir(parentDirPath, childNames) {
|
|
28
|
+
return childNames.map((childName) => join(parentDirPath, childName));
|
|
29
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Convert a given path to a windows path if the current system doesn't use `/`. */
|
|
2
|
+
export declare function replaceWithWindowsPathIfNeeded(input: string): string;
|
|
3
|
+
/** Convert a Windows path to a posix path. */
|
|
4
|
+
export declare function toPosixPath(maybeWindowsPath: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* Use this to interpolate paths into bash commands. If the given path is not a window path, the
|
|
7
|
+
* path structure will not be modified.
|
|
8
|
+
*/
|
|
9
|
+
export declare function interpolationSafeWindowsPath(input: string): string;
|