@aneuhold/core-ts-lib 1.0.6 → 1.0.8
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/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -1
- package/lib/services/CLIService.d.ts +5 -2
- package/lib/services/CLIService.d.ts.map +1 -1
- package/lib/services/CLIService.js +24 -14
- package/lib/services/applications/DockerService.d.ts +21 -0
- package/lib/services/applications/DockerService.d.ts.map +1 -0
- package/lib/services/applications/DockerService.js +88 -0
- package/lib/services/applications/FileSystemService.d.ts.map +1 -1
- package/lib/services/applications/FileSystemService.js +1 -0
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -2,10 +2,11 @@ import datesAreOnSameDay from './helperFunctions/dateFunctions';
|
|
|
2
2
|
import sleep from './helperFunctions/sleep';
|
|
3
3
|
import getFileNameExtension from './helperFunctions/stringFunctions';
|
|
4
4
|
import ChromeService from './services/applications/ChromeService';
|
|
5
|
+
import DockerService from './services/applications/DockerService';
|
|
5
6
|
import FileSystemService from './services/applications/FileSystemService';
|
|
6
7
|
import CLIService from './services/CLIService';
|
|
7
8
|
import StringService from './services/StringService';
|
|
8
9
|
import CurrentEnv, { OperatingSystemType, ShellType, TerminalType } from './utils/CurrentEnv';
|
|
9
10
|
import Logger from './utils/Logger';
|
|
10
|
-
export { CLIService, StringService, CurrentEnv, ChromeService, FileSystemService, sleep, OperatingSystemType, ShellType, Logger, TerminalType, datesAreOnSameDay, getFileNameExtension };
|
|
11
|
+
export { CLIService, StringService, CurrentEnv, ChromeService, DockerService, FileSystemService, sleep, OperatingSystemType, ShellType, Logger, TerminalType, datesAreOnSameDay, getFileNameExtension };
|
|
11
12
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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AY,EACZ,iBAAiB,EACjB,oBAAoB,EACrB,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.getFileNameExtension = exports.datesAreOnSameDay = exports.TerminalType = exports.Logger = exports.ShellType = exports.OperatingSystemType = exports.sleep = exports.FileSystemService = exports.ChromeService = exports.CurrentEnv = exports.StringService = exports.CLIService = void 0;
|
|
29
|
+
exports.getFileNameExtension = exports.datesAreOnSameDay = exports.TerminalType = exports.Logger = exports.ShellType = exports.OperatingSystemType = exports.sleep = exports.FileSystemService = exports.DockerService = exports.ChromeService = exports.CurrentEnv = exports.StringService = exports.CLIService = void 0;
|
|
30
30
|
const dateFunctions_1 = __importDefault(require("./helperFunctions/dateFunctions"));
|
|
31
31
|
exports.datesAreOnSameDay = dateFunctions_1.default;
|
|
32
32
|
const sleep_1 = __importDefault(require("./helperFunctions/sleep"));
|
|
@@ -35,6 +35,8 @@ const stringFunctions_1 = __importDefault(require("./helperFunctions/stringFunct
|
|
|
35
35
|
exports.getFileNameExtension = stringFunctions_1.default;
|
|
36
36
|
const ChromeService_1 = __importDefault(require("./services/applications/ChromeService"));
|
|
37
37
|
exports.ChromeService = ChromeService_1.default;
|
|
38
|
+
const DockerService_1 = __importDefault(require("./services/applications/DockerService"));
|
|
39
|
+
exports.DockerService = DockerService_1.default;
|
|
38
40
|
const FileSystemService_1 = __importDefault(require("./services/applications/FileSystemService"));
|
|
39
41
|
exports.FileSystemService = FileSystemService_1.default;
|
|
40
42
|
const CLIService_1 = __importDefault(require("./services/CLIService"));
|
|
@@ -17,7 +17,7 @@ export default class CLIService {
|
|
|
17
17
|
*
|
|
18
18
|
* @param cmd the command to run. This is ran as a normal execution where the
|
|
19
19
|
* output is all returned at once after completion. For example this could be
|
|
20
|
-
* `ls -a
|
|
20
|
+
* `ls -a`.
|
|
21
21
|
*
|
|
22
22
|
* @param logError if set to false, it will not output a log if an error
|
|
23
23
|
* occurs in `stderr` when executing the function. This can be useful if
|
|
@@ -27,10 +27,13 @@ export default class CLIService {
|
|
|
27
27
|
* @param cwd the current working directory to run the command in. If not
|
|
28
28
|
* provided, it will use the current working directory of the process.
|
|
29
29
|
*
|
|
30
|
+
* @param useProfile if set to true will use the current profile or zshrc of
|
|
31
|
+
* the shell environment. By default this is false.
|
|
32
|
+
*
|
|
30
33
|
* @returns an object that holds the output and true if the command completed
|
|
31
34
|
* successfully or false if it did not.
|
|
32
35
|
*/
|
|
33
|
-
static execCmd(cmd: string, logError?: boolean, cwd?: string): Promise<ExecCmdReturnType>;
|
|
36
|
+
static execCmd(cmd: string, logError?: boolean, cwd?: string, useProfile?: boolean): Promise<ExecCmdReturnType>;
|
|
34
37
|
/**
|
|
35
38
|
* Executes the given command but fulfills the
|
|
36
39
|
* promise when either the command completes, or the given number of ms have
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CLIService.d.ts","sourceRoot":"","sources":["../../src/services/CLIService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CLIService.d.ts","sourceRoot":"","sources":["../../src/services/CLIService.ts"],"names":[],"mappings":"AAYA,KAAK,iBAAiB,GAAG;IAAE,WAAW,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAElE;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAA+B;IAE/D;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;WACU,OAAO,CAClB,GAAG,EAAE,MAAM,EACX,QAAQ,UAAQ,EAChB,GAAG,CAAC,EAAE,MAAM,EACZ,UAAU,UAAQ,GACjB,OAAO,CAAC,iBAAiB,CAAC;IA6C7B;;;;;;;OAOG;WACU,kBAAkB,CAC7B,OAAO,EAAE,MAAM,EACf,EAAE,SAAO,GACR,OAAO,CAAC,iBAAiB,CAAC;IAU7B;;;;;;;;;;;;OAYG;WACU,QAAQ,CACnB,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,MAAM,EAAE,EACf,uBAAuB,CAAC,EAAE,MAAM,GAC/B,OAAO,CAAC,iBAAiB,CAAC;IAkC7B;;;;;OAKG;WACU,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAYjE"}
|
|
@@ -36,10 +36,6 @@ const Logger_1 = __importDefault(require("../utils/Logger"));
|
|
|
36
36
|
* The promisified version of the {@link normalExec} function.
|
|
37
37
|
*/
|
|
38
38
|
const execute = util_1.default.promisify(child_process_1.exec);
|
|
39
|
-
const readline = rl.createInterface({
|
|
40
|
-
input: process.stdin,
|
|
41
|
-
output: process.stdout
|
|
42
|
-
});
|
|
43
39
|
/**
|
|
44
40
|
* A service which can be used to interact with the command line on the current
|
|
45
41
|
* system.
|
|
@@ -55,7 +51,7 @@ class CLIService {
|
|
|
55
51
|
*
|
|
56
52
|
* @param cmd the command to run. This is ran as a normal execution where the
|
|
57
53
|
* output is all returned at once after completion. For example this could be
|
|
58
|
-
* `ls -a
|
|
54
|
+
* `ls -a`.
|
|
59
55
|
*
|
|
60
56
|
* @param logError if set to false, it will not output a log if an error
|
|
61
57
|
* occurs in `stderr` when executing the function. This can be useful if
|
|
@@ -65,18 +61,27 @@ class CLIService {
|
|
|
65
61
|
* @param cwd the current working directory to run the command in. If not
|
|
66
62
|
* provided, it will use the current working directory of the process.
|
|
67
63
|
*
|
|
64
|
+
* @param useProfile if set to true will use the current profile or zshrc of
|
|
65
|
+
* the shell environment. By default this is false.
|
|
66
|
+
*
|
|
68
67
|
* @returns an object that holds the output and true if the command completed
|
|
69
68
|
* successfully or false if it did not.
|
|
70
69
|
*/
|
|
71
|
-
static async execCmd(cmd, logError = false, cwd) {
|
|
72
|
-
const execOptions = {
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
static async execCmd(cmd, logError = false, cwd, useProfile = false) {
|
|
71
|
+
const execOptions = {};
|
|
72
|
+
if (cwd) {
|
|
73
|
+
execOptions.cwd = cwd;
|
|
74
|
+
}
|
|
75
75
|
let commandToExecute = cmd;
|
|
76
|
-
// Set the powershell prefix if the current OS is Windows
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
// Set the powershell prefix if the current OS is Windows so that
|
|
77
|
+
// the profile is not ran before the command.
|
|
78
|
+
if (CurrentEnv_1.default.os === CurrentEnv_1.OperatingSystemType.Windows && !useProfile) {
|
|
79
|
+
commandToExecute = `${CLIService.POWERSHELL_PREFIX}${cmd}`;
|
|
79
80
|
}
|
|
81
|
+
else if (CurrentEnv_1.default.os === CurrentEnv_1.OperatingSystemType.Windows && useProfile) {
|
|
82
|
+
execOptions.shell = 'pwsh';
|
|
83
|
+
}
|
|
84
|
+
Logger_1.default.verbose.info(`Executing command: ${commandToExecute}`);
|
|
80
85
|
try {
|
|
81
86
|
const { stdout, stderr } = await execute(commandToExecute, execOptions);
|
|
82
87
|
if (stderr) {
|
|
@@ -89,14 +94,15 @@ class CLIService {
|
|
|
89
94
|
output: stderr
|
|
90
95
|
};
|
|
91
96
|
}
|
|
92
|
-
Logger_1.default.verbose.info(stdout);
|
|
97
|
+
Logger_1.default.verbose.info(`Output from stdout is: ${stdout}`);
|
|
93
98
|
return {
|
|
94
99
|
didComplete: true,
|
|
95
100
|
output: stdout
|
|
96
101
|
};
|
|
97
102
|
}
|
|
98
103
|
catch (err) {
|
|
99
|
-
Logger_1.default.
|
|
104
|
+
Logger_1.default.verbose
|
|
105
|
+
.error(`There was an error executing the "exec" function. Details are printed below:
|
|
100
106
|
${err}`);
|
|
101
107
|
return {
|
|
102
108
|
didComplete: false,
|
|
@@ -173,6 +179,10 @@ class CLIService {
|
|
|
173
179
|
* a newline at the end if you want there to be one.
|
|
174
180
|
*/
|
|
175
181
|
static async getUserInput(promptToUser) {
|
|
182
|
+
const readline = rl.createInterface({
|
|
183
|
+
input: process.stdin,
|
|
184
|
+
output: process.stdout
|
|
185
|
+
});
|
|
176
186
|
return new Promise((resolve) => {
|
|
177
187
|
readline.question(promptToUser, (input) => {
|
|
178
188
|
readline.close();
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { OperatingSystemType } from '../../utils/CurrentEnv';
|
|
2
|
+
/**
|
|
3
|
+
* A service that provides functionality for interacting with the Docker
|
|
4
|
+
* application.
|
|
5
|
+
*/
|
|
6
|
+
export default class DockerService {
|
|
7
|
+
/**
|
|
8
|
+
* Starts the Docker Desktop application. If it is already running, it doesn't
|
|
9
|
+
* do anything.
|
|
10
|
+
*/
|
|
11
|
+
static startDockerDesktop(): Promise<void>;
|
|
12
|
+
static checkIfDockerDesktopIsRunning(): Promise<boolean>;
|
|
13
|
+
/**
|
|
14
|
+
* Gets the path to the docker application for the current system given the
|
|
15
|
+
* operating system type.
|
|
16
|
+
*
|
|
17
|
+
* This does include the quotes
|
|
18
|
+
*/
|
|
19
|
+
static getDockerPath(os: OperatingSystemType): string | null;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=DockerService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DockerService.d.ts","sourceRoot":"","sources":["../../../src/services/applications/DockerService.ts"],"names":[],"mappings":"AAEA,OAAmB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAIzE;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC;;;OAGG;WACU,kBAAkB;WAgBlB,6BAA6B,IAAI,OAAO,CAAC,OAAO,CAAC;IAe9D;;;;;OAKG;IACH,MAAM,CAAC,aAAa,CAAC,EAAE,EAAE,mBAAmB,GAAG,MAAM,GAAG,IAAI;CAS7D"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
/* eslint-disable no-await-in-loop */
|
|
30
|
+
const sleep_1 = __importDefault(require("../../helperFunctions/sleep"));
|
|
31
|
+
const CurrentEnv_1 = __importStar(require("../../utils/CurrentEnv"));
|
|
32
|
+
const Logger_1 = __importDefault(require("../../utils/Logger"));
|
|
33
|
+
const CLIService_1 = __importDefault(require("../CLIService"));
|
|
34
|
+
/**
|
|
35
|
+
* A service that provides functionality for interacting with the Docker
|
|
36
|
+
* application.
|
|
37
|
+
*/
|
|
38
|
+
class DockerService {
|
|
39
|
+
/**
|
|
40
|
+
* Starts the Docker Desktop application. If it is already running, it doesn't
|
|
41
|
+
* do anything.
|
|
42
|
+
*/
|
|
43
|
+
static async startDockerDesktop() {
|
|
44
|
+
const currentOS = CurrentEnv_1.default.os;
|
|
45
|
+
const dockerPath = DockerService.getDockerPath(currentOS);
|
|
46
|
+
let dockerRunning = await DockerService.checkIfDockerDesktopIsRunning();
|
|
47
|
+
if (!dockerRunning && dockerPath) {
|
|
48
|
+
Logger_1.default.info('Docker desktop is not running. Starting it now...');
|
|
49
|
+
await CLIService_1.default.execCmdWithTimeout(dockerPath, 4000);
|
|
50
|
+
while (!dockerRunning) {
|
|
51
|
+
Logger_1.default.info('Waiting for Docker to start...');
|
|
52
|
+
await (0, sleep_1.default)(2000);
|
|
53
|
+
dockerRunning = await DockerService.checkIfDockerDesktopIsRunning();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
Logger_1.default.info('Docker desktop is running.');
|
|
57
|
+
}
|
|
58
|
+
static async checkIfDockerDesktopIsRunning() {
|
|
59
|
+
const currentOS = CurrentEnv_1.default.os;
|
|
60
|
+
if (currentOS === CurrentEnv_1.OperatingSystemType.Windows) {
|
|
61
|
+
const { didComplete } = await CLIService_1.default.execCmd('Get-Process docker');
|
|
62
|
+
if (didComplete) {
|
|
63
|
+
Logger_1.default.verbose.info('Docker is running.');
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
Logger_1.default.verbose.info('Docker is not running.');
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
Logger_1.default.error('Docker command not defined for this OS yet.');
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Gets the path to the docker application for the current system given the
|
|
74
|
+
* operating system type.
|
|
75
|
+
*
|
|
76
|
+
* This does include the quotes
|
|
77
|
+
*/
|
|
78
|
+
static getDockerPath(os) {
|
|
79
|
+
switch (os) {
|
|
80
|
+
case CurrentEnv_1.OperatingSystemType.Windows:
|
|
81
|
+
return `& "C:\\Program Files\\Docker\\Docker\\Docker Desktop.exe"`;
|
|
82
|
+
default:
|
|
83
|
+
Logger_1.default.error('Docker path not defined for this OS yet.');
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.default = DockerService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileSystemService.d.ts","sourceRoot":"","sources":["../../../src/services/applications/FileSystemService.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAiB;WACvB,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"FileSystemService.d.ts","sourceRoot":"","sources":["../../../src/services/applications/FileSystemService.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAiB;WACvB,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ5C;;;;;;;OAOG;WACU,iBAAiB,CAC5B,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,IAAI,CAAC;mBA8BK,qBAAqB;CAM3C"}
|
|
@@ -39,6 +39,7 @@ class FileSystemService {
|
|
|
39
39
|
static async openNugetCache() {
|
|
40
40
|
if (CurrentEnv_1.default.os === CurrentEnv_1.OperatingSystemType.Windows) {
|
|
41
41
|
await FileSystemService.openWindowsNugetCache();
|
|
42
|
+
return;
|
|
42
43
|
}
|
|
43
44
|
Logger_1.default.error('Not implemented for this OS yet.');
|
|
44
45
|
}
|