@mikeyt23/node-cli-utils 1.4.1 → 2.0.0-beta.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.
- package/README.md +45 -87
- package/dist/cjs/GitUtility.d.ts +7 -0
- package/dist/cjs/GitUtility.d.ts.map +1 -0
- package/dist/cjs/GitUtility.js +49 -0
- package/dist/cjs/NodeCliUtilsConfig.d.ts +21 -0
- package/dist/cjs/NodeCliUtilsConfig.d.ts.map +1 -0
- package/dist/cjs/NodeCliUtilsConfig.js +41 -0
- package/dist/cjs/TarballUtility.d.ts +63 -0
- package/dist/cjs/TarballUtility.d.ts.map +1 -0
- package/dist/cjs/TarballUtility.js +143 -0
- package/dist/cjs/certUtils.d.ts +66 -0
- package/dist/cjs/certUtils.d.ts.map +1 -0
- package/dist/cjs/certUtils.js +283 -0
- package/dist/cjs/dbMigrationUtils.d.ts +39 -0
- package/dist/cjs/dbMigrationUtils.d.ts.map +1 -0
- package/dist/cjs/dbMigrationUtils.js +195 -0
- package/dist/cjs/dotnetUtils.d.ts +25 -0
- package/dist/cjs/dotnetUtils.d.ts.map +1 -0
- package/dist/cjs/dotnetUtils.js +61 -0
- package/dist/cjs/esmSpecific.d.mts +7 -0
- package/dist/cjs/esmSpecific.d.mts.map +1 -0
- package/dist/cjs/esmSpecific.mjs +15 -0
- package/dist/cjs/generalUtils.d.ts +565 -0
- package/dist/cjs/generalUtils.d.ts.map +1 -0
- package/dist/cjs/generalUtils.js +1068 -0
- package/dist/cjs/generalUtilsInternal.d.ts +15 -0
- package/dist/cjs/generalUtilsInternal.d.ts.map +1 -0
- package/dist/cjs/generalUtilsInternal.js +317 -0
- package/dist/cjs/hostsUtils.d.ts +16 -0
- package/dist/cjs/hostsUtils.d.ts.map +1 -0
- package/dist/cjs/hostsUtils.js +82 -0
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +25 -0
- package/dist/cjs/package.json +5 -0
- package/dist/cjs/runWhileParentAlive.d.ts +2 -0
- package/dist/cjs/runWhileParentAlive.d.ts.map +1 -0
- package/dist/cjs/runWhileParentAlive.js +159 -0
- package/dist/esm/GitUtility.d.ts +7 -0
- package/dist/esm/GitUtility.d.ts.map +1 -0
- package/dist/esm/GitUtility.js +43 -0
- package/dist/esm/NodeCliUtilsConfig.d.ts +21 -0
- package/dist/esm/NodeCliUtilsConfig.d.ts.map +1 -0
- package/dist/esm/NodeCliUtilsConfig.js +35 -0
- package/dist/esm/TarballUtility.d.ts +63 -0
- package/dist/esm/TarballUtility.d.ts.map +1 -0
- package/dist/esm/TarballUtility.js +139 -0
- package/dist/esm/certUtils.d.ts +66 -0
- package/dist/esm/certUtils.d.ts.map +1 -0
- package/dist/esm/certUtils.js +271 -0
- package/dist/esm/dbMigrationUtils.d.ts +39 -0
- package/dist/esm/dbMigrationUtils.d.ts.map +1 -0
- package/dist/esm/dbMigrationUtils.js +184 -0
- package/dist/esm/dotnetUtils.d.ts +25 -0
- package/dist/esm/dotnetUtils.d.ts.map +1 -0
- package/dist/esm/dotnetUtils.js +54 -0
- package/dist/esm/esmSpecific.d.mts +7 -0
- package/dist/esm/esmSpecific.d.mts.map +1 -0
- package/dist/esm/esmSpecific.mjs +11 -0
- package/dist/esm/generalUtils.d.ts +565 -0
- package/dist/esm/generalUtils.d.ts.map +1 -0
- package/dist/esm/generalUtils.js +976 -0
- package/dist/esm/generalUtilsInternal.d.ts +15 -0
- package/dist/esm/generalUtilsInternal.d.ts.map +1 -0
- package/dist/esm/generalUtilsInternal.js +278 -0
- package/dist/esm/hostsUtils.d.ts +16 -0
- package/dist/esm/hostsUtils.d.ts.map +1 -0
- package/dist/esm/hostsUtils.js +69 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/runWhileParentAlive.d.ts +2 -0
- package/dist/esm/runWhileParentAlive.d.ts.map +1 -0
- package/dist/esm/runWhileParentAlive.js +151 -0
- package/package.json +69 -10
- package/index.js +0 -627
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.configureDotnetDevCerts = exports.installOrUpdateDotnetEfTool = exports.dotnetPublish = exports.dotnetBuild = void 0;
|
|
4
|
+
const generalUtils_js_1 = require("./generalUtils.js");
|
|
5
|
+
/**
|
|
6
|
+
* Runs dotnet build on the specified project.
|
|
7
|
+
* @param projectPath Path to project file (like .csproj) or directory of project to build
|
|
8
|
+
* @throws A {@link SpawnError} if the spawned process exits with a non-zero exit code
|
|
9
|
+
*/
|
|
10
|
+
async function dotnetBuild(projectPath) {
|
|
11
|
+
(0, generalUtils_js_1.requireValidPath)('projectPath', projectPath);
|
|
12
|
+
await (0, generalUtils_js_1.spawnAsync)('dotnet', ['build', projectPath], { throwOnNonZero: true });
|
|
13
|
+
}
|
|
14
|
+
exports.dotnetBuild = dotnetBuild;
|
|
15
|
+
/**
|
|
16
|
+
* Helper method to spawn a process and run 'dotnet publish'.
|
|
17
|
+
* @param projectPath Path to project file (like .csproj) or directory of project to build
|
|
18
|
+
* @param configuration Build configuration, such as 'Release'
|
|
19
|
+
* @param outputDir The relative or absolute path for the build output
|
|
20
|
+
* @param cwd Optionally run the command from another current working directory
|
|
21
|
+
*/
|
|
22
|
+
async function dotnetPublish(projectPath = './', configuration = 'Release', outputDir = 'publish', cwd) {
|
|
23
|
+
(0, generalUtils_js_1.requireValidPath)('projectPath', projectPath);
|
|
24
|
+
(0, generalUtils_js_1.requireString)('outputDir', outputDir);
|
|
25
|
+
(0, generalUtils_js_1.requireString)('configuration', configuration);
|
|
26
|
+
if (cwd) {
|
|
27
|
+
(0, generalUtils_js_1.requireValidPath)('cwd', cwd);
|
|
28
|
+
}
|
|
29
|
+
const args = ['publish', projectPath, '-c', configuration, '-o', outputDir];
|
|
30
|
+
const traceMessage = `running dotnet ${args.join(' ')}`;
|
|
31
|
+
const traceAdditional = cwd ? ` in cwd ${cwd}` : '';
|
|
32
|
+
(0, generalUtils_js_1.trace)(`${traceMessage}${traceAdditional}`);
|
|
33
|
+
await (0, generalUtils_js_1.spawnAsync)('dotnet', args, { cwd: cwd });
|
|
34
|
+
}
|
|
35
|
+
exports.dotnetPublish = dotnetPublish;
|
|
36
|
+
/**
|
|
37
|
+
* Spawns a process that runs the necessary commands to install or update the dotnet-ef tool globally on the system.
|
|
38
|
+
*/
|
|
39
|
+
async function installOrUpdateDotnetEfTool() {
|
|
40
|
+
const installed = (0, generalUtils_js_1.whichSync)('dotnet-ef').location;
|
|
41
|
+
if (installed) {
|
|
42
|
+
(0, generalUtils_js_1.log)('dotnet-ef tool already installed, updating...');
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
(0, generalUtils_js_1.log)('dotnet-ef tool not installed, installing...');
|
|
46
|
+
}
|
|
47
|
+
const args = ['tool', installed ? 'update' : 'install', '--global', 'dotnet-ef'];
|
|
48
|
+
await (0, generalUtils_js_1.spawnAsync)('dotnet', args);
|
|
49
|
+
}
|
|
50
|
+
exports.installOrUpdateDotnetEfTool = installOrUpdateDotnetEfTool;
|
|
51
|
+
/**
|
|
52
|
+
* Spawns a process that runs the following commands to clean and re-install the dotnet dev certs:
|
|
53
|
+
* - dotnet dev-certs https --clean
|
|
54
|
+
* - dotnet dev-certs https -t
|
|
55
|
+
*/
|
|
56
|
+
async function configureDotnetDevCerts() {
|
|
57
|
+
await (0, generalUtils_js_1.spawnAsync)('dotnet', ['dev-certs', 'https', '--clean']);
|
|
58
|
+
await (0, generalUtils_js_1.spawnAsync)('dotnet', ['dev-certs', 'https', '-t']);
|
|
59
|
+
}
|
|
60
|
+
exports.configureDotnetDevCerts = configureDotnetDevCerts;
|
|
61
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZG90bmV0VXRpbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvZG90bmV0VXRpbHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUEsdURBQXNHO0FBTXRHOzs7O0dBSUc7QUFDSSxLQUFLLFVBQVUsV0FBVyxDQUFDLFdBQW1CO0lBQ25ELElBQUEsa0NBQWdCLEVBQUMsYUFBYSxFQUFFLFdBQVcsQ0FBQyxDQUFBO0lBQzVDLE1BQU0sSUFBQSw0QkFBVSxFQUFDLFFBQVEsRUFBRSxDQUFDLE9BQU8sRUFBRSxXQUFXLENBQUMsRUFBRSxFQUFFLGNBQWMsRUFBRSxJQUFJLEVBQUUsQ0FBQyxDQUFBO0FBQzlFLENBQUM7QUFIRCxrQ0FHQztBQUVEOzs7Ozs7R0FNRztBQUNJLEtBQUssVUFBVSxhQUFhLENBQUMsY0FBc0IsSUFBSSxFQUFFLGdCQUF3QixTQUFTLEVBQUUsWUFBb0IsU0FBUyxFQUFFLEdBQVk7SUFDNUksSUFBQSxrQ0FBZ0IsRUFBQyxhQUFhLEVBQUUsV0FBVyxDQUFDLENBQUE7SUFDNUMsSUFBQSwrQkFBYSxFQUFDLFdBQVcsRUFBRSxTQUFTLENBQUMsQ0FBQTtJQUNyQyxJQUFBLCtCQUFhLEVBQUMsZUFBZSxFQUFFLGFBQWEsQ0FBQyxDQUFBO0lBQzdDLElBQUksR0FBRyxFQUFFO1FBQ1AsSUFBQSxrQ0FBZ0IsRUFBQyxLQUFLLEVBQUUsR0FBRyxDQUFDLENBQUE7S0FDN0I7SUFDRCxNQUFNLElBQUksR0FBRyxDQUFDLFNBQVMsRUFBRSxXQUFXLEVBQUUsSUFBSSxFQUFFLGFBQWEsRUFBRSxJQUFJLEVBQUUsU0FBUyxDQUFDLENBQUE7SUFDM0UsTUFBTSxZQUFZLEdBQUcsa0JBQWtCLElBQUksQ0FBQyxJQUFJLENBQUMsR0FBRyxDQUFDLEVBQUUsQ0FBQTtJQUN2RCxNQUFNLGVBQWUsR0FBRyxHQUFHLENBQUMsQ0FBQyxDQUFDLFdBQVcsR0FBRyxFQUFFLENBQUMsQ0FBQyxDQUFDLEVBQUUsQ0FBQTtJQUNuRCxJQUFBLHVCQUFLLEVBQUMsR0FBRyxZQUFZLEdBQUcsZUFBZSxFQUFFLENBQUMsQ0FBQTtJQUMxQyxNQUFNLElBQUEsNEJBQVUsRUFBQyxRQUFRLEVBQUUsSUFBSSxFQUFFLEVBQUUsR0FBRyxFQUFFLEdBQUcsRUFBRSxDQUFDLENBQUE7QUFDaEQsQ0FBQztBQVpELHNDQVlDO0FBRUQ7O0dBRUc7QUFDSSxLQUFLLFVBQVUsMkJBQTJCO0lBQy9DLE1BQU0sU0FBUyxHQUFHLElBQUEsMkJBQVMsRUFBQyxXQUFXLENBQUMsQ0FBQyxRQUFRLENBQUE7SUFDakQsSUFBSSxTQUFTLEVBQUU7UUFDYixJQUFBLHFCQUFHLEVBQUMsK0NBQStDLENBQUMsQ0FBQTtLQUNyRDtTQUFNO1FBQ0wsSUFBQSxxQkFBRyxFQUFDLDZDQUE2QyxDQUFDLENBQUE7S0FDbkQ7SUFDRCxNQUFNLElBQUksR0FBRyxDQUFDLE1BQU0sRUFBRSxTQUFTLENBQUMsQ0FBQyxDQUFDLFFBQVEsQ0FBQyxDQUFDLENBQUMsU0FBUyxFQUFFLFVBQVUsRUFBRSxXQUFXLENBQUMsQ0FBQTtJQUNoRixNQUFNLElBQUEsNEJBQVUsRUFBQyxRQUFRLEVBQUUsSUFBSSxDQUFDLENBQUE7QUFDbEMsQ0FBQztBQVRELGtFQVNDO0FBRUQ7Ozs7R0FJRztBQUNJLEtBQUssVUFBVSx1QkFBdUI7SUFDM0MsTUFBTSxJQUFBLDRCQUFVLEVBQUMsUUFBUSxFQUFFLENBQUMsV0FBVyxFQUFFLE9BQU8sRUFBRSxTQUFTLENBQUMsQ0FBQyxDQUFBO0lBQzdELE1BQU0sSUFBQSw0QkFBVSxFQUFDLFFBQVEsRUFBRSxDQUFDLFdBQVcsRUFBRSxPQUFPLEVBQUUsSUFBSSxDQUFDLENBQUMsQ0FBQTtBQUMxRCxDQUFDO0FBSEQsMERBR0MifQ==
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Only dynamically import this if ESM is detected. This allows a CJS-specific build to avoid
|
|
3
|
+
* an error it would otherwise encounter when parsing import.meta.url.
|
|
4
|
+
* @returns the file path of the currently executing script
|
|
5
|
+
*/
|
|
6
|
+
export declare const getImportMetaUrlFilePath: () => string;
|
|
7
|
+
//# sourceMappingURL=esmSpecific.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"esmSpecific.d.mts","sourceRoot":"","sources":["../../src/esmSpecific.mts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,cAGpC,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getImportMetaUrlFilePath = void 0;
|
|
4
|
+
const node_url_1 = require("node:url");
|
|
5
|
+
/**
|
|
6
|
+
* Only dynamically import this if ESM is detected. This allows a CJS-specific build to avoid
|
|
7
|
+
* an error it would otherwise encounter when parsing import.meta.url.
|
|
8
|
+
* @returns the file path of the currently executing script
|
|
9
|
+
*/
|
|
10
|
+
const getImportMetaUrlFilePath = () => {
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
return (0, node_url_1.fileURLToPath)(import.meta.url);
|
|
13
|
+
};
|
|
14
|
+
exports.getImportMetaUrlFilePath = getImportMetaUrlFilePath;
|
|
15
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXNtU3BlY2lmaWMubWpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2VzbVNwZWNpZmljLm10cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSx1Q0FBd0M7QUFFeEM7Ozs7R0FJRztBQUNJLE1BQU0sd0JBQXdCLEdBQUcsR0FBRyxFQUFFO0lBQzNDLGFBQWE7SUFDYixPQUFPLElBQUEsd0JBQWEsRUFBQyxNQUFNLENBQUMsSUFBSSxDQUFDLEdBQUcsQ0FBQyxDQUFBO0FBQ3ZDLENBQUMsQ0FBQTtBQUhZLFFBQUEsd0JBQXdCLDRCQUdwQyJ9
|
|
@@ -0,0 +1,565 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { SpawnOptions } from 'node:child_process';
|
|
3
|
+
/**
|
|
4
|
+
* Just a wrapper for console.log() to type less.
|
|
5
|
+
* @param data The data to log
|
|
6
|
+
* @param moreData More data to log
|
|
7
|
+
*/
|
|
8
|
+
export declare function log(data: unknown, ...moreData: unknown[]): void;
|
|
9
|
+
/**
|
|
10
|
+
* Log conditionally. Useful for methods that have an option to either suppress output or to show it when it normally isn't.
|
|
11
|
+
* @param data The data to log
|
|
12
|
+
* @param moreData More data to log
|
|
13
|
+
*/
|
|
14
|
+
export declare function logIf(shouldLog: boolean, data: unknown, ...moreData: unknown[]): void;
|
|
15
|
+
/**
|
|
16
|
+
* Wrapper for console.log() that is suppressed if NodeCliUtilsConfig.logEnabled is false.
|
|
17
|
+
* @param data The data to log
|
|
18
|
+
* @param moreData More data to log
|
|
19
|
+
*/
|
|
20
|
+
export declare function trace(data?: unknown, ...moreData: unknown[]): void;
|
|
21
|
+
/**
|
|
22
|
+
* Type guard for a string keyed dictionary.
|
|
23
|
+
*/
|
|
24
|
+
export type StringKeyedDictionary = {
|
|
25
|
+
[name: string]: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Options for the {@link spawnAsync} wrapper function for NodeJS spawn.
|
|
29
|
+
*/
|
|
30
|
+
export interface SpawnResult {
|
|
31
|
+
/**
|
|
32
|
+
* The exit code of the spawned process. Rather than allowing null, this will be set to 1 if the process exits with null, or 0 if user cancels with ctrl+c.
|
|
33
|
+
*/
|
|
34
|
+
code: number;
|
|
35
|
+
/**
|
|
36
|
+
* The stdout of the spawned process. **Warning:** this will be empty by default without changing SpawnOptions stdio (see {@link spawnAsync}).
|
|
37
|
+
*/
|
|
38
|
+
stdout: string;
|
|
39
|
+
/**
|
|
40
|
+
* The stderr of the spawned process. **Warning:** this will be empty by default without changing SpawnOptions stdio (see {@link spawnAsync}).
|
|
41
|
+
*/
|
|
42
|
+
stderr: string;
|
|
43
|
+
/**
|
|
44
|
+
* Not an error from the child process stderr, but rather an error thrown when attempting to spawn the child process.
|
|
45
|
+
*/
|
|
46
|
+
error?: Error;
|
|
47
|
+
/**
|
|
48
|
+
* The current working directory of the spawned process. Not changed by method, so just repeating your SpawnOptions.cwd back to you, but helpful for debugging.
|
|
49
|
+
*/
|
|
50
|
+
cwd?: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Error throw by {@link spawnAsync} when the spawned process exits with a non-zero exit code and options.throwOnNonZero is true.
|
|
54
|
+
*
|
|
55
|
+
* Contains a {@link SpawnResult} with the exit code, stdout, stderr, and error (if any).
|
|
56
|
+
*/
|
|
57
|
+
export declare class SpawnError extends Error {
|
|
58
|
+
result: SpawnResult;
|
|
59
|
+
constructor(message: string, result: SpawnResult);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Spawn result for calls to {@link simpleSpawnSync} and {@link simpleCmdSync}.
|
|
63
|
+
*
|
|
64
|
+
* Contains the same properties as {@link SpawnResult} plus stdoutLines, which is stdout split into lines from stdout that weren't empty.
|
|
65
|
+
*/
|
|
66
|
+
export interface SimpleSpawnResult extends SpawnResult {
|
|
67
|
+
stdoutLines: string[];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Error throw by {@link simpleSpawnSync} and {@link simpleCmdSync} when the spawned process exits with a non-zero exit code and throwOnNonZero param is true (the default).
|
|
71
|
+
*
|
|
72
|
+
* Contains a {@link SimpleSpawnResult} with the exit code, stdout, stderr, and error (if any) in addition to stdoutLines, which is stdout split into lines from stdout that weren't empty.
|
|
73
|
+
*/
|
|
74
|
+
export declare class SimpleSpawnError extends Error {
|
|
75
|
+
result: SimpleSpawnResult;
|
|
76
|
+
constructor(message: string, result: SimpleSpawnResult);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The result type for {@link whichSync}. Contains the location of the command, any additional locations, and an error if one occurred.
|
|
80
|
+
*/
|
|
81
|
+
export interface WhichResult {
|
|
82
|
+
location: string | undefined;
|
|
83
|
+
additionalLocations: string[] | undefined;
|
|
84
|
+
error: Error | undefined;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Type guard for command passed to {@link spawnDockerCompose}.
|
|
88
|
+
*/
|
|
89
|
+
export type DockerComposeCommand = 'build' | 'config' | 'cp' | 'create' | 'down' | 'events' | 'exec' | 'images' | 'kill' | 'logs' | 'ls' | 'pause' | 'port' | 'ps' | 'pull' | 'push' | 'restart' | 'rm' | 'run' | 'start' | 'stop' | 'top' | 'unpause' | 'up' | 'version';
|
|
90
|
+
/**
|
|
91
|
+
* Sleeps for the specified number of milliseconds.
|
|
92
|
+
* @param ms The number of milliseconds to sleep
|
|
93
|
+
* @returns A Promise that resolves after the specified number of milliseconds
|
|
94
|
+
*/
|
|
95
|
+
export declare function sleep(ms: number): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* An extension of the built-in SpawnOptions with an extra option to specify whether a non-zero exit code should throw an error.
|
|
98
|
+
*/
|
|
99
|
+
export interface SpawnOptionsWithThrow extends SpawnOptions {
|
|
100
|
+
throwOnNonZero: boolean;
|
|
101
|
+
simpleErrorMsg?: string;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* This is a wrapper function for NodeJS spawn. Defaults stdio to inherit so that output is visible in the console,
|
|
105
|
+
* but note that this means stdout and stderr will not be available in the returned SpawnResult. To hide the output
|
|
106
|
+
* from the console but collect the stdout and stderr in the SpawnResult, use stdio: 'pipe'.
|
|
107
|
+
*
|
|
108
|
+
* When spawning long-running processes, use {@link spawnAsyncLongRunning} instead so that unexpected
|
|
109
|
+
* termination of the parent process will not orphan the child process tree on windows.
|
|
110
|
+
*
|
|
111
|
+
* **Warning:** Do NOT use this for generating commands dynamically from user input as it could be used to execute arbitrary code.
|
|
112
|
+
* This is meant solely for building up known commands that are not made up of unsanitized user input, and only at compile time.
|
|
113
|
+
* See {@link winInstallCert} and {@link winUninstallCert} for examples of taking user input and inserting it safely into known commands.
|
|
114
|
+
* @param command The command to spawn
|
|
115
|
+
* @param args The arguments to pass to the command
|
|
116
|
+
* @param options The options to pass to the command
|
|
117
|
+
* @returns A Promise that resolves to a {@link SpawnResult}
|
|
118
|
+
*/
|
|
119
|
+
export declare function spawnAsync(command: string, args?: string[], options?: Partial<SpawnOptionsWithThrow>): Promise<SpawnResult>;
|
|
120
|
+
/**
|
|
121
|
+
* Use this alternate spawn wrapper instead of {@link spawnAsync} when spawning long-running processes to
|
|
122
|
+
* avoid orphaned child process trees on Windows.
|
|
123
|
+
*
|
|
124
|
+
* **Warning:** Do NOT use this for generating commands dynamically from user input as it could be used to execute arbitrary code.
|
|
125
|
+
* This is meant solely for building up known commands that are not made up of unsanitized user input, and only at compile time.
|
|
126
|
+
* See {@link winInstallCert} and {@link winUninstallCert} for examples of taking user input and inserting it safely into known commands.
|
|
127
|
+
* @param command The command to spawn
|
|
128
|
+
* @param args The arguments to pass to the command
|
|
129
|
+
* @param cwd The current working directory to run the command from - defaults to process.cwd()
|
|
130
|
+
* @returns A Promise that resolves to a {@link SpawnResult}
|
|
131
|
+
*/
|
|
132
|
+
export declare function spawnAsyncLongRunning(command: string, args?: string[], cwd?: string): Promise<SpawnResult>;
|
|
133
|
+
/**
|
|
134
|
+
* Ensure the directory exists. Similar to `mkdir -p` (creates parent directories if they don't exist).
|
|
135
|
+
* @param dir The directory to ensure exists. If it does not exist, it will be created.
|
|
136
|
+
*/
|
|
137
|
+
export declare function ensureDirectory(dir: string): Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* Create a directory. Will create parent directory structure if it don't exist. Similar to `mkdir -p`.
|
|
140
|
+
* @param dir The directory to create.
|
|
141
|
+
*/
|
|
142
|
+
export declare function mkdirp(dir: string): Promise<void>;
|
|
143
|
+
/**
|
|
144
|
+
* Create a directory. Will create parent directory structure if it don't exist. Similar to `mkdir -p`.
|
|
145
|
+
* @param dir The directory to create.
|
|
146
|
+
*/
|
|
147
|
+
export declare function mkdirpSync(dir: string): Promise<void>;
|
|
148
|
+
/**
|
|
149
|
+
* Empties a directory of all files and subdirectories.
|
|
150
|
+
*
|
|
151
|
+
* Optionally skips files and directories at the top level.
|
|
152
|
+
* @param directoryToEmpty The directory to empty.
|
|
153
|
+
* @param fileAndDirectoryNamesToSkip An optional array of file and directory names to skip, but only at the top level of the directoryToEmpty.
|
|
154
|
+
*/
|
|
155
|
+
export declare function emptyDirectory(directoryToEmpty: string, fileAndDirectoryNamesToSkip?: string[]): Promise<void>;
|
|
156
|
+
/**
|
|
157
|
+
* Copies the contents of a directory to another directory (not including the top-level directory itself).
|
|
158
|
+
*
|
|
159
|
+
* If the destination directory does not exist, it will be created.
|
|
160
|
+
* @param sourceDirectory Directory to copy from
|
|
161
|
+
* @param destinationDirectory Directory to copy to
|
|
162
|
+
*/
|
|
163
|
+
export declare function copyDirectoryContents(sourceDirectory: string, destinationDirectory: string): Promise<void>;
|
|
164
|
+
/**
|
|
165
|
+
* Helper method to validate that a non-falsy and non-empty value is provided for a parameter that should be a string.
|
|
166
|
+
* @param paramName The name of the parameter to be used in the error message
|
|
167
|
+
* @param paramValue The value of the parameter
|
|
168
|
+
*/
|
|
169
|
+
export declare function requireString(paramName: string, paramValue: string): void;
|
|
170
|
+
/**
|
|
171
|
+
* Helper method to validate that the path actually exists for the provided value.
|
|
172
|
+
* @param paramName The name of the parameter, for logging purposes
|
|
173
|
+
* @param paramValue The value of the parameter
|
|
174
|
+
*/
|
|
175
|
+
export declare function requireValidPath(paramName: string, paramValue: string): void;
|
|
176
|
+
/**
|
|
177
|
+
* Project names must contain only lowercase letters, decimal digits, dashes, and underscores, and must begin with a lowercase letter or decimal digit.
|
|
178
|
+
*
|
|
179
|
+
* See https://docs.docker.com/compose/environment-variables/envvars/#compose_project_name.
|
|
180
|
+
* @param projectName The string to validate
|
|
181
|
+
* @returns `true` if it's a valid docker compose project name and `false` otherwise
|
|
182
|
+
*/
|
|
183
|
+
export declare function isDockerComposeProjectNameValid(projectName: string): boolean;
|
|
184
|
+
/**
|
|
185
|
+
* Options for {@link spawnDockerCompose}.
|
|
186
|
+
* @param projectName
|
|
187
|
+
* Note that there are other better options such as using the environment variable `COMPOSE_PROJECT_NAME`. See https://docs.docker.com/compose/environment-variables/envvars/#compose_project_name.
|
|
188
|
+
* @param attached Default: false. All commands that support the detached option wil use it unless attached is specified as true (-d support: exec, logs, ps, restart, run, start, stop, up)
|
|
189
|
+
* @param useDockerComposeFileDirectoryAsCwd Default: false. If true, the docker compose command will be run in the directory containing the docker compose file.
|
|
190
|
+
*/
|
|
191
|
+
export interface DockerComposeOptions {
|
|
192
|
+
/** Additional arguments to pass to the docker-compose command. */
|
|
193
|
+
args: string[];
|
|
194
|
+
/**
|
|
195
|
+
* Defaults to `false`. Controls whether or not the `--detach` option is passed. Note that this only applies to
|
|
196
|
+
* some commands (exec, logs, ps, restart, run, start, stop, up).
|
|
197
|
+
*/
|
|
198
|
+
attached: boolean;
|
|
199
|
+
/**
|
|
200
|
+
* If not provided, it will default to using the directory that the docker-compose.yml is located in.
|
|
201
|
+
* Specifies what current working directory to use with the spawn command.
|
|
202
|
+
*/
|
|
203
|
+
cwd?: string;
|
|
204
|
+
/**
|
|
205
|
+
* Optional. If provided, projectName will be passed as the `--project-name` param to `docker compose` so that generated containers will use it as a prefix
|
|
206
|
+
* instead of the default, which is the directory name where the docker-compose.yml is located.
|
|
207
|
+
*
|
|
208
|
+
* Alternate approaches for setting the docker compose project name:
|
|
209
|
+
*
|
|
210
|
+
* - Locate your docker-compose.yml file in the root of your project so that docker will use that directory name for prefixing generated containers
|
|
211
|
+
* - OR, locate your docker-compose.yml in a sub-directory named appropriately for use as a prefix for generated containers
|
|
212
|
+
* - OR, put a `.env` file in the same directory as your docker-compose.yml
|
|
213
|
+
* with the entry `COMPOSE_PROJECT_NAME=your-project-name`
|
|
214
|
+
*
|
|
215
|
+
* Additional note on docker compose project names form the official docker compose docs: "Project names must contain only lowercase letters, decimal digits,
|
|
216
|
+
* dashes, and underscores, and must begin with a lowercase letter or decimal digit". See https://docs.docker.com/compose/environment-variables/envvars/#compose_project_name.
|
|
217
|
+
*
|
|
218
|
+
*/
|
|
219
|
+
projectName?: string;
|
|
220
|
+
/**
|
|
221
|
+
* Optional. If provided, profile is passed to docker compose along with `--profile` param. Must match this regex: `[a-zA-Z0-9][a-zA-Z0-9_.-]+`.
|
|
222
|
+
*
|
|
223
|
+
* See https://docs.docker.com/compose/profiles/.
|
|
224
|
+
*/
|
|
225
|
+
profile?: string;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* For docker compose commands, see https://docs.docker.com/compose/reference/. For available options for this wrapper function, see {@link DockerComposeOptions}.
|
|
229
|
+
*
|
|
230
|
+
* The current working directory will be the directory of the {@link dockerComposePath} unless specified in the options. This ensures relative paths in the
|
|
231
|
+
* docker compose file will be relative to itself by default.
|
|
232
|
+
*
|
|
233
|
+
* See {@link DockerComposeOptions.projectName} for info on where to locate your docker compose file and how to specify the docker project name.
|
|
234
|
+
* @param dockerComposePath Path to docker-compose.yml
|
|
235
|
+
* @param dockerComposeCommand The docker-compose command to run
|
|
236
|
+
* @param options {@link DockerComposeOptions} to use, including additional arguments to pass to the docker compose command and the project name
|
|
237
|
+
*/
|
|
238
|
+
export declare function spawnDockerCompose(dockerComposePath: string, dockerComposeCommand: DockerComposeCommand, options?: Partial<DockerComposeOptions>): Promise<void>;
|
|
239
|
+
/**
|
|
240
|
+
* Splits a string into lines, removing `\n` and `\r` characters. Does not return empty lines. Also see {@link stringToLines}.
|
|
241
|
+
* @param str String to split into lines
|
|
242
|
+
* @returns An array of lines from the string, with empty lines removed
|
|
243
|
+
*/
|
|
244
|
+
export declare function stringToNonEmptyLines(str: string): string[];
|
|
245
|
+
/**
|
|
246
|
+
* Splits a string into lines, removing `\n` and `\r` characters. Returns empty lines. Also see {@link stringToNonEmptyLines}.
|
|
247
|
+
* @param str String to split into lines
|
|
248
|
+
* @returns An array of lines from the string, with empty lines removed
|
|
249
|
+
*/
|
|
250
|
+
export declare function stringToLines(str: string): string[];
|
|
251
|
+
/**
|
|
252
|
+
* Runs the requested command using NodeJS spawnSync wrapped in an outer Windows CMD.exe command and returns the result with stdout split into lines.
|
|
253
|
+
*
|
|
254
|
+
* Use this for simple quick commands that don't require a lot of control.
|
|
255
|
+
*
|
|
256
|
+
* For commands that aren't Windows and CMD specific, use {@link simpleSpawnSync}.
|
|
257
|
+
*
|
|
258
|
+
* **Warning:** Do NOT use this for generating commands dynamically from user input as it could be used to execute arbitrary code.
|
|
259
|
+
* This is meant solely for building up known commands that are not made up of unsanitized user input, and only at compile time.
|
|
260
|
+
* See {@link winInstallCert} and {@link winUninstallCert} for examples of taking user input and inserting it safely into known commands.
|
|
261
|
+
* @param command Command to run
|
|
262
|
+
* @param args Arguments to pass to the command
|
|
263
|
+
* @returns An object with the status code, stdout, stderr, and error (if any)
|
|
264
|
+
* @throws {@link SimpleSpawnError} if the command fails and throwOnNonZero is true
|
|
265
|
+
*/
|
|
266
|
+
export declare function simpleCmdSync(command: string, args?: string[], throwOnNonZero?: boolean): SimpleSpawnResult;
|
|
267
|
+
/**
|
|
268
|
+
* Runs the requested command using {@link spawnAsync} wrapped in an outer Windows CMD.exe command and returns the result with stdout split into lines.
|
|
269
|
+
*
|
|
270
|
+
* Use this for simple quick commands that don't require a lot of control.
|
|
271
|
+
*
|
|
272
|
+
* For commands that aren't Windows and CMD specific, use {@link simpleSpawnAsync}.
|
|
273
|
+
*
|
|
274
|
+
* **Warning:** Do NOT use this for generating commands dynamically from user input as it could be used to execute arbitrary code.
|
|
275
|
+
* This is meant solely for building up known commands that are not made up of unsanitized user input, and only at compile time.
|
|
276
|
+
* See {@link winInstallCert} and {@link winUninstallCert} for examples of taking user input and inserting it safely into known commands.
|
|
277
|
+
* @param command Command to run
|
|
278
|
+
* @param args Arguments to pass to the command
|
|
279
|
+
* @returns An object with the status code, stdout, stderr, and error (if any)
|
|
280
|
+
* @throws {@link SimpleSpawnError} if the command fails and throwOnNonZero is true
|
|
281
|
+
*/
|
|
282
|
+
export declare function simpleCmdAsync(command: string, args?: string[], throwOnNonZero?: boolean): Promise<SimpleSpawnResult>;
|
|
283
|
+
/**
|
|
284
|
+
* Runs the requested command using NodeJS spawnSync and returns the result with stdout split into lines.
|
|
285
|
+
*
|
|
286
|
+
* Use this for simple quick commands that don't require a lot of control.
|
|
287
|
+
*
|
|
288
|
+
* For commands that are Windows and CMD specific, use {@link simpleCmdSync}.
|
|
289
|
+
*
|
|
290
|
+
* **Warning:** Do NOT use this for generating commands dynamically from user input as it could be used to execute arbitrary code.
|
|
291
|
+
* This is meant solely for building up known commands that are not made up of unsanitized user input, and only at compile time.
|
|
292
|
+
* See {@link winInstallCert} and {@link winUninstallCert} for examples of taking user input and inserting it safely into known commands.
|
|
293
|
+
* @param command Command to run
|
|
294
|
+
* @param args Arguments to pass to the command
|
|
295
|
+
* @returns An object with the status code, stdout, stderr, and error (if any)
|
|
296
|
+
* @throws {@link SimpleSpawnError} if the command fails and throwOnNonZero is true
|
|
297
|
+
*/
|
|
298
|
+
export declare function simpleSpawnSync(command: string, args?: string[], throwOnNonZero?: boolean): SimpleSpawnResult;
|
|
299
|
+
/**
|
|
300
|
+
* Runs the requested command using {@link spawnAsync} and returns the result with stdout split into lines.
|
|
301
|
+
*
|
|
302
|
+
* Use this for simple quick commands that don't require a lot of control.
|
|
303
|
+
*
|
|
304
|
+
* For commands that are Windows and CMD specific, use {@link simpleCmdSync}.
|
|
305
|
+
*
|
|
306
|
+
* **Warning:** Do NOT use this for generating commands dynamically from user input as it could be used to execute arbitrary code.
|
|
307
|
+
* This is meant solely for building up known commands that are not made up of unsanitized user input, and only at compile time.
|
|
308
|
+
* See {@link winInstallCert} and {@link winUninstallCert} for examples of taking user input and inserting it safely into known commands.
|
|
309
|
+
* @param command Command to run
|
|
310
|
+
* @param args Arguments to pass to the command
|
|
311
|
+
* @returns An object with the status code, stdout, stderr, and error (if any)
|
|
312
|
+
* @throws {@link SimpleSpawnError} if the command fails and throwOnNonZero is true
|
|
313
|
+
*/
|
|
314
|
+
export declare function simpleSpawnAsync(command: string, args?: string[], throwOnNonZero?: boolean): Promise<SimpleSpawnResult>;
|
|
315
|
+
/**
|
|
316
|
+
* @returns `true` if platform() is 'win32', `false` otherwise
|
|
317
|
+
*/
|
|
318
|
+
export declare function isPlatformWindows(): boolean;
|
|
319
|
+
/**
|
|
320
|
+
*
|
|
321
|
+
* @returns `true` if platform() is 'darwin', `false` otherwise
|
|
322
|
+
*/
|
|
323
|
+
export declare function isPlatformMac(): boolean;
|
|
324
|
+
/**
|
|
325
|
+
*
|
|
326
|
+
* @returns `true` if {@link isPlatformWindows} and {@link isPlatformMac} are both `false, otherwise returns `true`
|
|
327
|
+
*/
|
|
328
|
+
export declare function isPlatformLinux(): boolean;
|
|
329
|
+
/**
|
|
330
|
+
* This is a cross-platform method to get the location of a system command. Useful for checking if software
|
|
331
|
+
* is installed, where it's installed and whether there are multiple locations.
|
|
332
|
+
* @param commandName The name of the command to find
|
|
333
|
+
* @returns The location of the command, any additional locations, and an error if one occurred
|
|
334
|
+
*/
|
|
335
|
+
export declare function which(commandName: string): Promise<WhichResult>;
|
|
336
|
+
/**
|
|
337
|
+
* This is a cross-platform method to get the location of a system command. Useful for checking if software
|
|
338
|
+
* is installed, where it's installed and whether there are multiple locations.
|
|
339
|
+
* @param commandName The name of the command to find
|
|
340
|
+
* @returns The location of the command, any additional locations, and an error if one occurred
|
|
341
|
+
*/
|
|
342
|
+
export declare function whichSync(commandName: string): WhichResult;
|
|
343
|
+
/**
|
|
344
|
+
* First checks if docker is installed and if not immediately returns false. Then runs the `docker info`
|
|
345
|
+
* command and looks for "error during connect" in the output to determine if docker is running.
|
|
346
|
+
* @returns `true` if docker is installed and running, `false` otherwise
|
|
347
|
+
*/
|
|
348
|
+
export declare function isDockerRunning(): Promise<boolean>;
|
|
349
|
+
/**
|
|
350
|
+
* Uses built-in NodeJS readline to ask a question and return the user's answer.
|
|
351
|
+
* @param query The question to ask
|
|
352
|
+
* @returns A Promise that resolves to the user's answer
|
|
353
|
+
*/
|
|
354
|
+
export declare function askQuestion(query: string): Promise<string>;
|
|
355
|
+
/**
|
|
356
|
+
* A simple CLI prompt using the built-in NodeJS readline functionality to ask for confirmation.
|
|
357
|
+
* @param question The question to ask
|
|
358
|
+
* @returns A Promise that resolves to true if the user answers 'y' or 'yes', false otherwise
|
|
359
|
+
*/
|
|
360
|
+
export declare function getConfirmation(question: string): Promise<boolean>;
|
|
361
|
+
/**
|
|
362
|
+
* Example of using {@link getConfirmation}.
|
|
363
|
+
*/
|
|
364
|
+
export declare function getConfirmationExample(): Promise<void>;
|
|
365
|
+
/**
|
|
366
|
+
* Copy entries from a source .env file to a destination .env file for which the destination .env file does not already have entries.
|
|
367
|
+
* If the destination .env file does not exist, it will be created and populated with the source .env file's values.
|
|
368
|
+
*
|
|
369
|
+
* This is useful for copying values from a .env.template file to a root .env file.
|
|
370
|
+
*
|
|
371
|
+
* For copying root .env files to other locations, use {@link overwriteEnvFile}.
|
|
372
|
+
* @param sourcePath The path to the source .env file such as a `.env.template` file (use {@link overwriteEnvFile} for copying root .env files to other locations)
|
|
373
|
+
* @param destinationPath The path to the destination .env file, such as the root .env file
|
|
374
|
+
*/
|
|
375
|
+
export declare function copyNewEnvValues(sourcePath: string, destinationPath: string): Promise<void>;
|
|
376
|
+
/**
|
|
377
|
+
* Copy entries from a source .env file to a destination .env file, overwriting any existing entries in the destination .env file.
|
|
378
|
+
* If the destination .env file does not exist, it will be created and populated with the source .env file's values.
|
|
379
|
+
*
|
|
380
|
+
* This is useful for copying values from a root .env file to additional locations (server, client, docker-compose directory, etc.)
|
|
381
|
+
* throughout your solution so you only have to manage one .env file.
|
|
382
|
+
*
|
|
383
|
+
* Note that this does not delete any existing entries in the destination .env file, which is useful if you have additional entries in
|
|
384
|
+
* the destination .env file that you don't want to overwrite.
|
|
385
|
+
*
|
|
386
|
+
* For copying .env.template files to root .env files, use {@link copyNewEnvValues}.
|
|
387
|
+
* @param sourcePath The path to the source .env file such as a root .env file (use {@link copyNewEnvValues} for .env.template files)
|
|
388
|
+
* @param destinationPath The path to the destination .env file
|
|
389
|
+
* @param suppressAddKeysMessages If true, messages about adding missing keys will not be logged (useful if you're always calling {@link copyModifiedEnv} after this call)
|
|
390
|
+
*/
|
|
391
|
+
export declare function overwriteEnvFile(sourcePath: string, destinationPath: string, suppressAddKeysMessages?: boolean): Promise<void>;
|
|
392
|
+
/**
|
|
393
|
+
* Copy entries from a source .env file to a destination .env file, but only for the keys specified in keepKeys.
|
|
394
|
+
* Will also modify entries in the destination .env file as specified in modifyEntries.
|
|
395
|
+
* @param sourcePath The path to the source .env file
|
|
396
|
+
* @param destinationPath The path to the destination .env file
|
|
397
|
+
* @param keepKeys The keys to keep from the source .env file
|
|
398
|
+
* @param modifyEntries The entries to modify in the destination .env file
|
|
399
|
+
*/
|
|
400
|
+
export declare function copyModifiedEnv(sourcePath: string, destinationPath: string, keepKeys: string[], modifyEntries?: StringKeyedDictionary): Promise<void>;
|
|
401
|
+
/**
|
|
402
|
+
* Filters a dictionary by key.
|
|
403
|
+
* @param dict The dictionary to filter
|
|
404
|
+
* @param predicate A function that returns true if the key should be included in the filtered dictionary
|
|
405
|
+
* @returns A new dictionary with only the keys that passed the predicate
|
|
406
|
+
*/
|
|
407
|
+
export declare function filterDictionary(dict: StringKeyedDictionary, predicate: (key: string) => boolean): StringKeyedDictionary;
|
|
408
|
+
/**
|
|
409
|
+
* Sorts a dictionary by key in ascending order.
|
|
410
|
+
* @param dict The dictionary to sort
|
|
411
|
+
* @returns A new dictionary sorted by key in ascending order
|
|
412
|
+
*/
|
|
413
|
+
export declare function sortDictionaryByKeyAsc(dict: StringKeyedDictionary): StringKeyedDictionary;
|
|
414
|
+
/**
|
|
415
|
+
* Helper method to delete a .env file if it exists.
|
|
416
|
+
* @param envPath The path to the .env file to delete
|
|
417
|
+
*/
|
|
418
|
+
export declare function deleteEnvIfExists(envPath: string): Promise<void>;
|
|
419
|
+
export interface FindFilesOptions {
|
|
420
|
+
maxDepth: number;
|
|
421
|
+
excludeDirectoryNames: string[];
|
|
422
|
+
returnForwardSlashRelativePaths: boolean;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Searches a directory recursively for files that match the specified pattern.
|
|
426
|
+
* The filenamePattern is a simple text string with asterisks (*) for wildcards.
|
|
427
|
+
* @param dir The directory to find files in
|
|
428
|
+
* @param filenamePattern The pattern to match files against
|
|
429
|
+
* @param options Specify a max depth to search, defaults to 5
|
|
430
|
+
* @returns A Promise that resolves to an array of file paths that match the pattern
|
|
431
|
+
*/
|
|
432
|
+
export declare function findFilesRecursively(dir: string, filenamePattern: string, options?: Partial<FindFilesOptions>): Promise<string[]>;
|
|
433
|
+
/** Utility function to escape a string for use within regex */
|
|
434
|
+
export declare function escapeStringForRegex(str: string): string;
|
|
435
|
+
/**
|
|
436
|
+
* Logs the provided 2-dimensional string array as a formatted table.
|
|
437
|
+
*
|
|
438
|
+
* @param data 2-dimensional string array where the first row is the column headers
|
|
439
|
+
* @example
|
|
440
|
+
*
|
|
441
|
+
* logTable([
|
|
442
|
+
* ['Name', 'Age', 'Country'],
|
|
443
|
+
* ['Alice', '28', 'USA'],
|
|
444
|
+
* ['Bob', '22', 'Canada']
|
|
445
|
+
* ])
|
|
446
|
+
*/
|
|
447
|
+
export declare function logTable(data: string[][]): void;
|
|
448
|
+
/**
|
|
449
|
+
* See {@link getPowershellHackArgs}.
|
|
450
|
+
*/
|
|
451
|
+
export declare const powershellHackPrefix = "$env:PSModulePath = [Environment]::GetEnvironmentVariable('PSModulePath', 'Machine'); ";
|
|
452
|
+
/**
|
|
453
|
+
* Powershell doesn't load the system PSModulePath when running in a non-interactive shell.
|
|
454
|
+
* This is a workaround to set the PSModulePath environment variable to the system value before running a powershell command.
|
|
455
|
+
*
|
|
456
|
+
* **Warning:** Do NOT use this for generating commands dynamically from user input as it could be used to execute arbitrary code.
|
|
457
|
+
* This is meant solely for building up known commands that are not made up of unsanitized user input, and only at compile time.
|
|
458
|
+
* See {@link winInstallCert} and {@link winUninstallCert} for examples of taking user input and inserting it safely into known commands.
|
|
459
|
+
* @param command The powershell command to run
|
|
460
|
+
* @returns An array of arguments to pass to {@link spawnAsync} with the "powershell" command as the first argument
|
|
461
|
+
*/
|
|
462
|
+
export declare function getPowershellHackArgs(command: string): string[];
|
|
463
|
+
/**
|
|
464
|
+
* Returns a humanized string representation of the number of milliseconds using ms, seconds, minutes, or hours.
|
|
465
|
+
* @param milliseconds The number of milliseconds to humanize
|
|
466
|
+
* @returns A humanized string representation of the number
|
|
467
|
+
*/
|
|
468
|
+
export declare function humanizeTime(milliseconds: number): string;
|
|
469
|
+
export declare class ExtendedError extends Error {
|
|
470
|
+
innerError: Error | null;
|
|
471
|
+
constructor(message: string, innerError?: Error);
|
|
472
|
+
}
|
|
473
|
+
export declare function getHostname(url: string): string;
|
|
474
|
+
export declare function isDirectory(path: string): Promise<boolean>;
|
|
475
|
+
export declare function isDirectorySync(path: string): boolean;
|
|
476
|
+
export type PlatformCode = 'win' | 'linux' | 'mac';
|
|
477
|
+
/**
|
|
478
|
+
* This is a somewhat naive method but is useful if you rarely or never deal with unusual operating systems.
|
|
479
|
+
* @returns `win`, `mac` or `linux`
|
|
480
|
+
*/
|
|
481
|
+
export declare function getPlatformCode(): PlatformCode;
|
|
482
|
+
/**
|
|
483
|
+
* Tries connecting to a port to see if it's being listened on or not. It's likely that this won't work in a lot of scenarios, so use it at your own risk.
|
|
484
|
+
* @param port The port to check
|
|
485
|
+
* @returns `true` if the port is available, `false` otherwise
|
|
486
|
+
*/
|
|
487
|
+
export declare function isPortAvailable(port: number): Promise<boolean>;
|
|
488
|
+
/**
|
|
489
|
+
* Returns the value for an environment variable or throws if it's undefined or null. Pass optional {@param throwOnEmpty} to throw when the key exists but has an empty value.
|
|
490
|
+
* @param varName The name of the environment variable to get.
|
|
491
|
+
* @param throwOnEmpty Throw an error if key exists (not undefined or null) but is empty.
|
|
492
|
+
* @returns
|
|
493
|
+
*/
|
|
494
|
+
export declare function getRequiredEnvVar(varName: string, throwOnEmpty?: boolean): string;
|
|
495
|
+
/** Options for {@link withRetryAsync}. */
|
|
496
|
+
export interface WithRetryOptions {
|
|
497
|
+
/**
|
|
498
|
+
* Number of milliseconds to wait before the first attempt.
|
|
499
|
+
*/
|
|
500
|
+
initialDelayMilliseconds: number;
|
|
501
|
+
/**
|
|
502
|
+
* Use this in log messages instead of the function name (useful for passing lambdas which would otherwise display as "anonymous").
|
|
503
|
+
*/
|
|
504
|
+
functionLabel?: string;
|
|
505
|
+
/**
|
|
506
|
+
* If NodeCliUtilsConfig.traceEnabled is `true` then messages will be logged even if this option is `false`.
|
|
507
|
+
* Set to `true` to log messages even if Node ]
|
|
508
|
+
*/
|
|
509
|
+
traceEnabled: boolean;
|
|
510
|
+
}
|
|
511
|
+
export declare function getNormalizedError(err: unknown): Error;
|
|
512
|
+
/**
|
|
513
|
+
* Call a function until it succeeds. Will stop after the number of calls specified by {@param maxCalls}, or forever if -1 is passed.
|
|
514
|
+
* @param func The function to call
|
|
515
|
+
* @param maxCalls The maximum number of times to call the function before giving up. Pass -1 to retry forever.
|
|
516
|
+
* @param delayMilliseconds The number of milliseconds to wait between calls
|
|
517
|
+
* @param options Options for controlling the behavior of the retry. See {@link WithRetryOptions}.
|
|
518
|
+
*/
|
|
519
|
+
export declare function withRetryAsync(func: () => Promise<void>, maxCalls: number, delayMilliseconds: number, options?: Partial<WithRetryOptions>): Promise<void>;
|
|
520
|
+
/**
|
|
521
|
+
* Collapses each instance of consecutive whitespace characters into a single space.
|
|
522
|
+
*/
|
|
523
|
+
export declare function collapseWhitespace(str: string): string;
|
|
524
|
+
/**
|
|
525
|
+
* Check if a string is a valid directory name. This is a very simple check that just makes sure the string doesn't contain any invalid characters.
|
|
526
|
+
* @param dirName The directory name to check
|
|
527
|
+
* @returns `true` if the directory name is valid, `false` otherwise
|
|
528
|
+
*/
|
|
529
|
+
export declare function isValidDirName(dirName: string): boolean;
|
|
530
|
+
export declare function hasWhitespace(str: string): boolean;
|
|
531
|
+
export declare function stripShellMetaCharacters(input: string): string;
|
|
532
|
+
export declare enum AnsiColor {
|
|
533
|
+
RESET = "\u001B[0m",
|
|
534
|
+
RED = "\u001B[31m",
|
|
535
|
+
GREEN = "\u001B[32m",
|
|
536
|
+
YELLOW = "\u001B[33m",
|
|
537
|
+
CYAN = "\u001B[96m",
|
|
538
|
+
GRAY = "\u001B[90m",
|
|
539
|
+
PURPLE = "\u001B[35m"
|
|
540
|
+
}
|
|
541
|
+
export declare const color: (str: string, colorAnsiCode: AnsiColor) => string;
|
|
542
|
+
export declare const red: (str: string) => string;
|
|
543
|
+
export declare const green: (str: string) => string;
|
|
544
|
+
export declare const cyan: (str: string) => string;
|
|
545
|
+
export declare const gray: (str: string) => string;
|
|
546
|
+
export declare const purple: (str: string) => string;
|
|
547
|
+
export declare const yellow: (str: string) => string;
|
|
548
|
+
export declare enum Emoji {
|
|
549
|
+
RightArrow = "\u27A1\uFE0F",
|
|
550
|
+
LeftArrow = "\u2B05\uFE0F",
|
|
551
|
+
GreenCheck = "\u2705",
|
|
552
|
+
Warning = "\u26A0\uFE0F",
|
|
553
|
+
Lightning = "\u26A1",
|
|
554
|
+
Exclamation = "\u2757",
|
|
555
|
+
RedQuestion = "\u2753",
|
|
556
|
+
RedX = "\u274C",
|
|
557
|
+
Info = "\u2139\uFE0F",
|
|
558
|
+
SadFace = "\uD83D\uDE22",
|
|
559
|
+
Tools = "\uD83D\uDEE0\uFE0F",
|
|
560
|
+
NoEntry = "\u26D4",
|
|
561
|
+
Stop = "\uD83D\uDED1",
|
|
562
|
+
Certificate = "\uD83D\uDCDC",
|
|
563
|
+
Key = "\uD83D\uDD11"
|
|
564
|
+
}
|
|
565
|
+
//# sourceMappingURL=generalUtils.d.ts.map
|