@aneuhold/core-ts-lib 1.0.3 → 1.0.6
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/helperFunctions/cmd.d.ts +3 -0
- package/lib/helperFunctions/cmd.d.ts.map +1 -1
- package/lib/helperFunctions/cmd.js +13 -6
- package/lib/helperFunctions/sleep.d.ts +0 -1
- package/lib/helperFunctions/sleep.d.ts.map +1 -1
- package/lib/helperFunctions/sleep.js +1 -1
- package/lib/index.d.ts +6 -19
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +18 -19
- package/lib/services/CLIService.d.ts +66 -0
- package/lib/services/CLIService.d.ts.map +1 -0
- package/lib/services/CLIService.js +184 -0
- package/lib/services/StringService.d.ts +14 -0
- package/lib/services/StringService.d.ts.map +1 -0
- package/lib/services/StringService.js +18 -0
- package/lib/services/applications/ChromeService.d.ts +20 -0
- package/lib/services/applications/ChromeService.d.ts.map +1 -0
- package/lib/services/applications/ChromeService.js +60 -0
- package/lib/services/applications/FileSystemService.d.ts +18 -0
- package/lib/services/applications/FileSystemService.d.ts.map +1 -0
- package/lib/services/applications/FileSystemService.js +86 -0
- package/lib/utils/CurrentEnv.d.ts +1 -4
- package/lib/utils/CurrentEnv.d.ts.map +1 -1
- package/lib/utils/CurrentEnv.js +11 -21
- package/lib/utils/Logger.d.ts +68 -0
- package/lib/utils/Logger.d.ts.map +1 -0
- package/lib/utils/Logger.js +112 -0
- package/package.json +9 -7
|
@@ -34,6 +34,9 @@ export type ExecCmdCommandArgument = string | {
|
|
|
34
34
|
* a command regularly outputs an error even when it succeeds. This only
|
|
35
35
|
* applies to commands ran with normal execution.
|
|
36
36
|
*
|
|
37
|
+
* @param cwd the current working directory to run the command in. If not
|
|
38
|
+
* provided, it will use the current working directory of the process.
|
|
39
|
+
*
|
|
37
40
|
* @returns an object that holds the output and the true if the command comlpleted
|
|
38
41
|
* successfully or false if it did not
|
|
39
42
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cmd.d.ts","sourceRoot":"","sources":["../../src/helperFunctions/cmd.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,eAAe;;CAG3B,CAAC;
|
|
1
|
+
{"version":3,"file":"cmd.d.ts","sourceRoot":"","sources":["../../src/helperFunctions/cmd.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,eAAe;;CAG3B,CAAC;AAIF,KAAK,iBAAiB,GAAG;IAAE,WAAW,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAClE,MAAM,MAAM,sBAAsB,GAC9B,MAAM,GACN;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AA6EzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAA8B,OAAO,CACnC,GAAG,EAAE,sBAAsB,EAC3B,QAAQ,UAAQ,EAChB,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC,iBAAiB,CAAC,CAwB5B;AAED;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,MAAM,EACf,EAAE,SAAO,GACR,OAAO,CAAC,iBAAiB,CAAC,CAQ5B"}
|
|
@@ -41,6 +41,7 @@ const exec = util_1.default.promisify(child_process_1.exec);
|
|
|
41
41
|
exports.variousCommands = {
|
|
42
42
|
pwshExectuablePath: 'Get-Command pwsh | Select-Object -ExpandProperty Definition'
|
|
43
43
|
};
|
|
44
|
+
const POWERSHELL_PREFIX = `pwsh -NoProfile -Command `;
|
|
44
45
|
async function helperExec(cmd, execOptions, logError) {
|
|
45
46
|
try {
|
|
46
47
|
const { stdout, stderr } = await exec(cmd, execOptions);
|
|
@@ -131,6 +132,9 @@ async function helperSpawn(cmd, args, execOptions) {
|
|
|
131
132
|
* a command regularly outputs an error even when it succeeds. This only
|
|
132
133
|
* applies to commands ran with normal execution.
|
|
133
134
|
*
|
|
135
|
+
* @param cwd the current working directory to run the command in. If not
|
|
136
|
+
* provided, it will use the current working directory of the process.
|
|
137
|
+
*
|
|
134
138
|
* @returns an object that holds the output and the true if the command comlpleted
|
|
135
139
|
* successfully or false if it did not
|
|
136
140
|
*/
|
|
@@ -138,16 +142,19 @@ async function execCmd(cmd, logError = false, cwd) {
|
|
|
138
142
|
const execOptions = {
|
|
139
143
|
cwd
|
|
140
144
|
};
|
|
141
|
-
|
|
142
|
-
if (CurrentEnv_1.default.os === CurrentEnv_1.OperatingSystemType.Windows) {
|
|
143
|
-
execOptions.shell = 'pwsh';
|
|
144
|
-
}
|
|
145
|
+
let modifiedCmd = null;
|
|
145
146
|
if (typeof cmd === 'string') {
|
|
146
147
|
Log_1.default.verbose.info('Command type provided to "execCmd" was a string, so executing "exec" promise...');
|
|
147
|
-
|
|
148
|
+
if (CurrentEnv_1.default.os === CurrentEnv_1.OperatingSystemType.Windows) {
|
|
149
|
+
modifiedCmd = POWERSHELL_PREFIX + cmd;
|
|
150
|
+
}
|
|
151
|
+
return helperExec(modifiedCmd || cmd, execOptions, logError);
|
|
148
152
|
}
|
|
149
153
|
Log_1.default.verbose.info('Command type provided to "execCmd" was an object, so executing "spawn" promise...');
|
|
150
|
-
|
|
154
|
+
if (CurrentEnv_1.default.os === CurrentEnv_1.OperatingSystemType.Windows) {
|
|
155
|
+
modifiedCmd = POWERSHELL_PREFIX + cmd.command;
|
|
156
|
+
}
|
|
157
|
+
return helperSpawn(modifiedCmd || cmd.command, cmd.args, execOptions);
|
|
151
158
|
}
|
|
152
159
|
exports.default = execCmd;
|
|
153
160
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sleep.d.ts","sourceRoot":"","sources":["../../src/helperFunctions/sleep.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"sleep.d.ts","sourceRoot":"","sources":["../../src/helperFunctions/sleep.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGvD"}
|
|
@@ -4,9 +4,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
* Sleeps for the given amount of milliseconds, and resolves once finished.
|
|
5
5
|
*
|
|
6
6
|
* @param ms the number of milliseconds to sleep
|
|
7
|
-
* @returns
|
|
8
7
|
*/
|
|
9
8
|
function sleep(ms) {
|
|
9
|
+
// eslint-disable-next-line no-promise-executor-return
|
|
10
10
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
11
11
|
}
|
|
12
12
|
exports.default = sleep;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,24 +1,11 @@
|
|
|
1
|
-
import execCmd, { execCmdWithTimeout } from './helperFunctions/cmd';
|
|
2
1
|
import datesAreOnSameDay from './helperFunctions/dateFunctions';
|
|
3
|
-
import findAndInsertText from './helperFunctions/fileFunctions';
|
|
4
|
-
import getUserInput from './helperFunctions/input';
|
|
5
2
|
import sleep from './helperFunctions/sleep';
|
|
6
3
|
import getFileNameExtension from './helperFunctions/stringFunctions';
|
|
4
|
+
import ChromeService from './services/applications/ChromeService';
|
|
5
|
+
import FileSystemService from './services/applications/FileSystemService';
|
|
6
|
+
import CLIService from './services/CLIService';
|
|
7
|
+
import StringService from './services/StringService';
|
|
7
8
|
import CurrentEnv, { OperatingSystemType, ShellType, TerminalType } from './utils/CurrentEnv';
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
execCmd: typeof execCmd;
|
|
11
|
-
execCmdWithTimeout: typeof execCmdWithTimeout;
|
|
12
|
-
CurrentEnv: typeof CurrentEnv;
|
|
13
|
-
Log: typeof Log;
|
|
14
|
-
sleep: typeof sleep;
|
|
15
|
-
getUserInput: typeof getUserInput;
|
|
16
|
-
findAndInsertText: typeof findAndInsertText;
|
|
17
|
-
OperatingSystemType: typeof OperatingSystemType;
|
|
18
|
-
ShellType: typeof ShellType;
|
|
19
|
-
TerminalType: typeof TerminalType;
|
|
20
|
-
datesAreOnSameDay: typeof datesAreOnSameDay;
|
|
21
|
-
getFileNameExtension: typeof getFileNameExtension;
|
|
22
|
-
};
|
|
23
|
-
export default _default;
|
|
9
|
+
import Logger from './utils/Logger';
|
|
10
|
+
export { CLIService, StringService, CurrentEnv, ChromeService, FileSystemService, sleep, OperatingSystemType, ShellType, Logger, TerminalType, datesAreOnSameDay, getFileNameExtension };
|
|
24
11
|
//# 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":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,iCAAiC,CAAC;AAChE,OAAO,KAAK,MAAM,yBAAyB,CAAC;AAC5C,OAAO,oBAAoB,MAAM,mCAAmC,CAAC;AACrE,OAAO,aAAa,MAAM,uCAAuC,CAAC;AAClE,OAAO,iBAAiB,MAAM,2CAA2C,CAAC;AAC1E,OAAO,UAAU,MAAM,uBAAuB,CAAC;AAC/C,OAAO,aAAa,MAAM,0BAA0B,CAAC;AACrD,OAAO,UAAU,EAAE,EACjB,mBAAmB,EACnB,SAAS,EACT,YAAY,EACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,MAAM,MAAM,gBAAgB,CAAC;AAGpC,OAAO,EACL,UAAU,EACV,aAAa,EACb,UAAU,EACV,aAAa,EACb,iBAAiB,EACjB,KAAK,EACL,mBAAmB,EACnB,SAAS,EACT,MAAM,EACN,YAAY,EACZ,iBAAiB,EACjB,oBAAoB,EACrB,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -26,26 +26,25 @@ 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
|
-
|
|
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;
|
|
30
30
|
const dateFunctions_1 = __importDefault(require("./helperFunctions/dateFunctions"));
|
|
31
|
-
|
|
32
|
-
const input_1 = __importDefault(require("./helperFunctions/input"));
|
|
31
|
+
exports.datesAreOnSameDay = dateFunctions_1.default;
|
|
33
32
|
const sleep_1 = __importDefault(require("./helperFunctions/sleep"));
|
|
33
|
+
exports.sleep = sleep_1.default;
|
|
34
34
|
const stringFunctions_1 = __importDefault(require("./helperFunctions/stringFunctions"));
|
|
35
|
+
exports.getFileNameExtension = stringFunctions_1.default;
|
|
36
|
+
const ChromeService_1 = __importDefault(require("./services/applications/ChromeService"));
|
|
37
|
+
exports.ChromeService = ChromeService_1.default;
|
|
38
|
+
const FileSystemService_1 = __importDefault(require("./services/applications/FileSystemService"));
|
|
39
|
+
exports.FileSystemService = FileSystemService_1.default;
|
|
40
|
+
const CLIService_1 = __importDefault(require("./services/CLIService"));
|
|
41
|
+
exports.CLIService = CLIService_1.default;
|
|
42
|
+
const StringService_1 = __importDefault(require("./services/StringService"));
|
|
43
|
+
exports.StringService = StringService_1.default;
|
|
35
44
|
const CurrentEnv_1 = __importStar(require("./utils/CurrentEnv"));
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
exports.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
Log: Log_1.default,
|
|
43
|
-
sleep: sleep_1.default,
|
|
44
|
-
getUserInput: input_1.default,
|
|
45
|
-
findAndInsertText: fileFunctions_1.default,
|
|
46
|
-
OperatingSystemType: CurrentEnv_1.OperatingSystemType,
|
|
47
|
-
ShellType: CurrentEnv_1.ShellType,
|
|
48
|
-
TerminalType: CurrentEnv_1.TerminalType,
|
|
49
|
-
datesAreOnSameDay: dateFunctions_1.default,
|
|
50
|
-
getFileNameExtension: stringFunctions_1.default
|
|
51
|
-
};
|
|
45
|
+
exports.CurrentEnv = CurrentEnv_1.default;
|
|
46
|
+
Object.defineProperty(exports, "OperatingSystemType", { enumerable: true, get: function () { return CurrentEnv_1.OperatingSystemType; } });
|
|
47
|
+
Object.defineProperty(exports, "ShellType", { enumerable: true, get: function () { return CurrentEnv_1.ShellType; } });
|
|
48
|
+
Object.defineProperty(exports, "TerminalType", { enumerable: true, get: function () { return CurrentEnv_1.TerminalType; } });
|
|
49
|
+
const Logger_1 = __importDefault(require("./utils/Logger"));
|
|
50
|
+
exports.Logger = Logger_1.default;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
type ExecCmdReturnType = {
|
|
2
|
+
didComplete: boolean;
|
|
3
|
+
output: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* A service which can be used to interact with the command line on the current
|
|
7
|
+
* system.
|
|
8
|
+
*/
|
|
9
|
+
export default class CLIService {
|
|
10
|
+
private static POWERSHELL_PREFIX;
|
|
11
|
+
/**
|
|
12
|
+
* Executes the given command in a shell environment. Spins up a separate
|
|
13
|
+
* process to execute the command and returns a promise once it is completely
|
|
14
|
+
* finished.
|
|
15
|
+
*
|
|
16
|
+
* The shell environment chosen is determined by the `CurrentEnv` class.
|
|
17
|
+
*
|
|
18
|
+
* @param cmd the command to run. This is ran as a normal execution where the
|
|
19
|
+
* output is all returned at once after completion. For example this could be
|
|
20
|
+
* `ls -a`
|
|
21
|
+
*
|
|
22
|
+
* @param logError if set to false, it will not output a log if an error
|
|
23
|
+
* occurs in `stderr` when executing the function. This can be useful if
|
|
24
|
+
* a command regularly outputs an error even when it succeeds. This only
|
|
25
|
+
* applies to commands ran with normal execution.
|
|
26
|
+
*
|
|
27
|
+
* @param cwd the current working directory to run the command in. If not
|
|
28
|
+
* provided, it will use the current working directory of the process.
|
|
29
|
+
*
|
|
30
|
+
* @returns an object that holds the output and true if the command completed
|
|
31
|
+
* successfully or false if it did not.
|
|
32
|
+
*/
|
|
33
|
+
static execCmd(cmd: string, logError?: boolean, cwd?: string): Promise<ExecCmdReturnType>;
|
|
34
|
+
/**
|
|
35
|
+
* Executes the given command but fulfills the
|
|
36
|
+
* promise when either the command completes, or the given number of ms have
|
|
37
|
+
* passed. Whichever comes first.
|
|
38
|
+
*
|
|
39
|
+
* @param command the command to execute
|
|
40
|
+
* @param ms the number of milliseconds to wait. This is 5 seconds by default.
|
|
41
|
+
*/
|
|
42
|
+
static execCmdWithTimeout(command: string, ms?: number): Promise<ExecCmdReturnType>;
|
|
43
|
+
/**
|
|
44
|
+
* Spawns a new process where the command is ran as a stream where all
|
|
45
|
+
* output is streamed to the console.
|
|
46
|
+
* This is helpful for long-running commands or commands
|
|
47
|
+
* that output a lot of data. For example `yarn` or `npm install`.
|
|
48
|
+
* All of the output from this is logged by default because of the listeners
|
|
49
|
+
* involved. This could be changed in the future though.
|
|
50
|
+
*
|
|
51
|
+
* @param cmd the command to run. This is the the first argument passed to the
|
|
52
|
+
* `spawn` function. For example this could be `npm`.
|
|
53
|
+
* @param args the arguments to pass to the command. For example this could be
|
|
54
|
+
* `['install', 'react']`.
|
|
55
|
+
*/
|
|
56
|
+
static spawnCmd(cmd: string, args?: string[], currentWorkingDirectory?: string): Promise<ExecCmdReturnType>;
|
|
57
|
+
/**
|
|
58
|
+
* Gets input from the user on command line.
|
|
59
|
+
*
|
|
60
|
+
* @param promptToUser the prompt that should be provided to the user. Include
|
|
61
|
+
* a newline at the end if you want there to be one.
|
|
62
|
+
*/
|
|
63
|
+
static getUserInput(promptToUser: string): Promise<string>;
|
|
64
|
+
}
|
|
65
|
+
export {};
|
|
66
|
+
//# sourceMappingURL=CLIService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CLIService.d.ts","sourceRoot":"","sources":["../../src/services/CLIService.ts"],"names":[],"mappings":"AAgBA,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;;;;;;;;;;;;;;;;;;;;;OAqBG;WACU,OAAO,CAClB,GAAG,EAAE,MAAM,EACX,QAAQ,UAAQ,EAChB,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC,iBAAiB,CAAC;IAsC7B;;;;;;;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;CAQjE"}
|
|
@@ -0,0 +1,184 @@
|
|
|
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
|
+
const child_process_1 = require("child_process");
|
|
30
|
+
const rl = __importStar(require("readline"));
|
|
31
|
+
const util_1 = __importDefault(require("util"));
|
|
32
|
+
const sleep_1 = __importDefault(require("../helperFunctions/sleep"));
|
|
33
|
+
const CurrentEnv_1 = __importStar(require("../utils/CurrentEnv"));
|
|
34
|
+
const Logger_1 = __importDefault(require("../utils/Logger"));
|
|
35
|
+
/**
|
|
36
|
+
* The promisified version of the {@link normalExec} function.
|
|
37
|
+
*/
|
|
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
|
+
/**
|
|
44
|
+
* A service which can be used to interact with the command line on the current
|
|
45
|
+
* system.
|
|
46
|
+
*/
|
|
47
|
+
class CLIService {
|
|
48
|
+
static POWERSHELL_PREFIX = `pwsh -NoProfile -Command `;
|
|
49
|
+
/**
|
|
50
|
+
* Executes the given command in a shell environment. Spins up a separate
|
|
51
|
+
* process to execute the command and returns a promise once it is completely
|
|
52
|
+
* finished.
|
|
53
|
+
*
|
|
54
|
+
* The shell environment chosen is determined by the `CurrentEnv` class.
|
|
55
|
+
*
|
|
56
|
+
* @param cmd the command to run. This is ran as a normal execution where the
|
|
57
|
+
* output is all returned at once after completion. For example this could be
|
|
58
|
+
* `ls -a`
|
|
59
|
+
*
|
|
60
|
+
* @param logError if set to false, it will not output a log if an error
|
|
61
|
+
* occurs in `stderr` when executing the function. This can be useful if
|
|
62
|
+
* a command regularly outputs an error even when it succeeds. This only
|
|
63
|
+
* applies to commands ran with normal execution.
|
|
64
|
+
*
|
|
65
|
+
* @param cwd the current working directory to run the command in. If not
|
|
66
|
+
* provided, it will use the current working directory of the process.
|
|
67
|
+
*
|
|
68
|
+
* @returns an object that holds the output and true if the command completed
|
|
69
|
+
* successfully or false if it did not.
|
|
70
|
+
*/
|
|
71
|
+
static async execCmd(cmd, logError = false, cwd) {
|
|
72
|
+
const execOptions = {
|
|
73
|
+
cwd
|
|
74
|
+
};
|
|
75
|
+
let commandToExecute = cmd;
|
|
76
|
+
// Set the powershell prefix if the current OS is Windows
|
|
77
|
+
if (CurrentEnv_1.default.os === CurrentEnv_1.OperatingSystemType.Windows) {
|
|
78
|
+
commandToExecute = CLIService.POWERSHELL_PREFIX + cmd;
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
const { stdout, stderr } = await execute(commandToExecute, execOptions);
|
|
82
|
+
if (stderr) {
|
|
83
|
+
if (logError) {
|
|
84
|
+
Logger_1.default.error(`There was an error executing ${cmd}. Details are printed below:
|
|
85
|
+
${stderr}`);
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
didComplete: false,
|
|
89
|
+
output: stderr
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
Logger_1.default.verbose.info(stdout);
|
|
93
|
+
return {
|
|
94
|
+
didComplete: true,
|
|
95
|
+
output: stdout
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
Logger_1.default.error(`There was an error executing the "exec" function. Details are printed below:
|
|
100
|
+
${err}`);
|
|
101
|
+
return {
|
|
102
|
+
didComplete: false,
|
|
103
|
+
output: err
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Executes the given command but fulfills the
|
|
109
|
+
* promise when either the command completes, or the given number of ms have
|
|
110
|
+
* passed. Whichever comes first.
|
|
111
|
+
*
|
|
112
|
+
* @param command the command to execute
|
|
113
|
+
* @param ms the number of milliseconds to wait. This is 5 seconds by default.
|
|
114
|
+
*/
|
|
115
|
+
static async execCmdWithTimeout(command, ms = 5000) {
|
|
116
|
+
const sleepPromise = (0, sleep_1.default)(ms).then(() => {
|
|
117
|
+
return {
|
|
118
|
+
didComplete: false,
|
|
119
|
+
output: `Command ended after ${ms} ms.`
|
|
120
|
+
};
|
|
121
|
+
});
|
|
122
|
+
return Promise.any([sleepPromise, CLIService.execCmd(command)]);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Spawns a new process where the command is ran as a stream where all
|
|
126
|
+
* output is streamed to the console.
|
|
127
|
+
* This is helpful for long-running commands or commands
|
|
128
|
+
* that output a lot of data. For example `yarn` or `npm install`.
|
|
129
|
+
* All of the output from this is logged by default because of the listeners
|
|
130
|
+
* involved. This could be changed in the future though.
|
|
131
|
+
*
|
|
132
|
+
* @param cmd the command to run. This is the the first argument passed to the
|
|
133
|
+
* `spawn` function. For example this could be `npm`.
|
|
134
|
+
* @param args the arguments to pass to the command. For example this could be
|
|
135
|
+
* `['install', 'react']`.
|
|
136
|
+
*/
|
|
137
|
+
static async spawnCmd(cmd, args, currentWorkingDirectory) {
|
|
138
|
+
return new Promise((resolve) => {
|
|
139
|
+
let output = '';
|
|
140
|
+
const execOptions = {
|
|
141
|
+
cwd: currentWorkingDirectory
|
|
142
|
+
};
|
|
143
|
+
const spawnedCmd = (0, child_process_1.spawn)(cmd, args, execOptions);
|
|
144
|
+
spawnedCmd.on('error', (err) => {
|
|
145
|
+
Logger_1.default.error(`There was an error executing the "spawn" function. Details are printed below:
|
|
146
|
+
${err}`);
|
|
147
|
+
resolve({
|
|
148
|
+
didComplete: false,
|
|
149
|
+
output: err.toString()
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
spawnedCmd.stdout.on('data', (data) => {
|
|
153
|
+
output += data;
|
|
154
|
+
Logger_1.default.info(data, true);
|
|
155
|
+
});
|
|
156
|
+
spawnedCmd.stderr.on('data', (data) => {
|
|
157
|
+
output += data;
|
|
158
|
+
Logger_1.default.info(data, true);
|
|
159
|
+
});
|
|
160
|
+
spawnedCmd.on('close', (exitCode) => {
|
|
161
|
+
Logger_1.default.info(`Command "${cmd}" exited with code ${exitCode}`);
|
|
162
|
+
resolve({
|
|
163
|
+
didComplete: true,
|
|
164
|
+
output
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Gets input from the user on command line.
|
|
171
|
+
*
|
|
172
|
+
* @param promptToUser the prompt that should be provided to the user. Include
|
|
173
|
+
* a newline at the end if you want there to be one.
|
|
174
|
+
*/
|
|
175
|
+
static async getUserInput(promptToUser) {
|
|
176
|
+
return new Promise((resolve) => {
|
|
177
|
+
readline.question(promptToUser, (input) => {
|
|
178
|
+
readline.close();
|
|
179
|
+
resolve(input);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
exports.default = CLIService;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A service which can be used to interact with strings.
|
|
3
|
+
*/
|
|
4
|
+
export default class StringService {
|
|
5
|
+
/**
|
|
6
|
+
* Gets the file extension of the provided file name.
|
|
7
|
+
*
|
|
8
|
+
* @param fileName the full name of the file or the entire file path
|
|
9
|
+
* @returns a string containing the extension of the file name or undefined
|
|
10
|
+
* if there is no extension
|
|
11
|
+
*/
|
|
12
|
+
static getFileNameExtension(fileName: string): string | undefined;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=StringService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StringService.d.ts","sourceRoot":"","sources":["../../src/services/StringService.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC;;;;;;OAMG;IACH,MAAM,CAAC,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;CAGlE"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* A service which can be used to interact with strings.
|
|
5
|
+
*/
|
|
6
|
+
class StringService {
|
|
7
|
+
/**
|
|
8
|
+
* Gets the file extension of the provided file name.
|
|
9
|
+
*
|
|
10
|
+
* @param fileName the full name of the file or the entire file path
|
|
11
|
+
* @returns a string containing the extension of the file name or undefined
|
|
12
|
+
* if there is no extension
|
|
13
|
+
*/
|
|
14
|
+
static getFileNameExtension(fileName) {
|
|
15
|
+
return fileName.split('.').pop();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.default = StringService;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { OperatingSystemType } from '../../utils/CurrentEnv';
|
|
2
|
+
/**
|
|
3
|
+
* A service that provides functionality for interacting with the Chrome
|
|
4
|
+
* browser.
|
|
5
|
+
*/
|
|
6
|
+
export default class ChromeService {
|
|
7
|
+
/**
|
|
8
|
+
* Gets the path to the chrome application for the current system given the
|
|
9
|
+
* operating system type.
|
|
10
|
+
*
|
|
11
|
+
* This does include the quotes
|
|
12
|
+
*/
|
|
13
|
+
static getChromePath(os: OperatingSystemType): string | null;
|
|
14
|
+
/**
|
|
15
|
+
* Opens and sets pinned tabs in chrome. Still trying to figure out
|
|
16
|
+
* how to get this to work.
|
|
17
|
+
*/
|
|
18
|
+
static openAndSetPinnedTabs(): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=ChromeService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChromeService.d.ts","sourceRoot":"","sources":["../../../src/services/applications/ChromeService.ts"],"names":[],"mappings":"AAAA,OAAmB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAGzE;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC;;;;;OAKG;IACH,MAAM,CAAC,aAAa,CAAC,EAAE,EAAE,mBAAmB,GAAG,MAAM,GAAG,IAAI;IAW5D;;;OAGG;WACU,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;CAOnD"}
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
const CurrentEnv_1 = __importStar(require("../../utils/CurrentEnv"));
|
|
30
|
+
const CLIService_1 = __importDefault(require("../CLIService"));
|
|
31
|
+
/**
|
|
32
|
+
* A service that provides functionality for interacting with the Chrome
|
|
33
|
+
* browser.
|
|
34
|
+
*/
|
|
35
|
+
class ChromeService {
|
|
36
|
+
/**
|
|
37
|
+
* Gets the path to the chrome application for the current system given the
|
|
38
|
+
* operating system type.
|
|
39
|
+
*
|
|
40
|
+
* This does include the quotes
|
|
41
|
+
*/
|
|
42
|
+
static getChromePath(os) {
|
|
43
|
+
switch (os) {
|
|
44
|
+
case CurrentEnv_1.OperatingSystemType.MacOSX:
|
|
45
|
+
return `"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"`;
|
|
46
|
+
case CurrentEnv_1.OperatingSystemType.Windows:
|
|
47
|
+
return `& "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"`;
|
|
48
|
+
default:
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Opens and sets pinned tabs in chrome. Still trying to figure out
|
|
54
|
+
* how to get this to work.
|
|
55
|
+
*/
|
|
56
|
+
static async openAndSetPinnedTabs() {
|
|
57
|
+
await CLIService_1.default.execCmd(`${ChromeService.getChromePath(CurrentEnv_1.default.os)} --pinned-tab-count=2 https://google.com https://tonyneuhold.com`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.default = ChromeService;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A service which can be used to interact with the file system on the current
|
|
3
|
+
* system.
|
|
4
|
+
*/
|
|
5
|
+
export default class FileSystemService {
|
|
6
|
+
static openNugetCache(): Promise<void>;
|
|
7
|
+
/**
|
|
8
|
+
* Tries to add the provided snippet of text to the path provided. If the file
|
|
9
|
+
* doesn't exist, it creates it. If the folders to the file don't exist, it
|
|
10
|
+
* creates those. If the text already exists in the file, it does nothing.
|
|
11
|
+
*
|
|
12
|
+
* @param folderPath the path to the folder which contains the file that should
|
|
13
|
+
* be updated
|
|
14
|
+
*/
|
|
15
|
+
static findAndInsertText(folderPath: string, fileName: string, textToInsert: string): Promise<void>;
|
|
16
|
+
private static openWindowsNugetCache;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=FileSystemService.d.ts.map
|
|
@@ -0,0 +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;IAO5C;;;;;;;OAOG;WACU,iBAAiB,CAC5B,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,IAAI,CAAC;mBA8BK,qBAAqB;CAM3C"}
|
|
@@ -0,0 +1,86 @@
|
|
|
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
|
+
const promises_1 = require("fs/promises");
|
|
30
|
+
const path_1 = __importDefault(require("path"));
|
|
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 which can be used to interact with the file system on the current
|
|
36
|
+
* system.
|
|
37
|
+
*/
|
|
38
|
+
class FileSystemService {
|
|
39
|
+
static async openNugetCache() {
|
|
40
|
+
if (CurrentEnv_1.default.os === CurrentEnv_1.OperatingSystemType.Windows) {
|
|
41
|
+
await FileSystemService.openWindowsNugetCache();
|
|
42
|
+
}
|
|
43
|
+
Logger_1.default.error('Not implemented for this OS yet.');
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Tries to add the provided snippet of text to the path provided. If the file
|
|
47
|
+
* doesn't exist, it creates it. If the folders to the file don't exist, it
|
|
48
|
+
* creates those. If the text already exists in the file, it does nothing.
|
|
49
|
+
*
|
|
50
|
+
* @param folderPath the path to the folder which contains the file that should
|
|
51
|
+
* be updated
|
|
52
|
+
*/
|
|
53
|
+
static async findAndInsertText(folderPath, fileName, textToInsert) {
|
|
54
|
+
const filePath = path_1.default.join(folderPath, fileName);
|
|
55
|
+
try {
|
|
56
|
+
await (0, promises_1.access)(folderPath);
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
console.log(e);
|
|
60
|
+
Logger_1.default.info(`Directory "${folderPath}" does not exist. Creating it now...`);
|
|
61
|
+
await (0, promises_1.mkdir)(folderPath, { recursive: true });
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
await (0, promises_1.access)(filePath);
|
|
65
|
+
const fileContents = await (0, promises_1.readFile)(filePath);
|
|
66
|
+
if (!fileContents.includes(textToInsert)) {
|
|
67
|
+
await (0, promises_1.appendFile)(filePath, `\n${textToInsert}`);
|
|
68
|
+
Logger_1.default.info(`Added "${textToInsert}" to "${filePath}"`);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
Logger_1.default.info(`"${textToInsert}" already exists in "${filePath}"`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
Logger_1.default.info(`File at "${filePath}" didn't exist. Creating it now and adding "${textToInsert}" to it.`);
|
|
76
|
+
await (0, promises_1.writeFile)(filePath, textToInsert);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
static async openWindowsNugetCache() {
|
|
80
|
+
await Promise.all([
|
|
81
|
+
CLIService_1.default.execCmd(`ii $HOME/localNuget`),
|
|
82
|
+
CLIService_1.default.execCmd(`ii $HOME/.nuget/packages`)
|
|
83
|
+
]);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.default = FileSystemService;
|
|
@@ -49,11 +49,8 @@ export default class CurrentEnv {
|
|
|
49
49
|
*
|
|
50
50
|
* The startup scripts are defined in the
|
|
51
51
|
* [dotfiles repo](https://github.com/aneuhold/dotfiles).
|
|
52
|
-
*
|
|
53
|
-
* @param args are the arguements that should be provided to the startup
|
|
54
|
-
* script as a string[]. This can be empty.
|
|
55
52
|
*/
|
|
56
|
-
static runStartupScript(
|
|
53
|
+
static runStartupScript(): Promise<void>;
|
|
57
54
|
/**
|
|
58
55
|
* Determines the type of operating system in the current environment.
|
|
59
56
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CurrentEnv.d.ts","sourceRoot":"","sources":["../../src/utils/CurrentEnv.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,oBAAY,SAAS;IACnB,cAAc,IAAA;IACd,iBAAiB,IAAA;IACjB,IAAI,IAAA;IACJ,GAAG,IAAA;IACH,aAAa,IAAA;IACb,OAAO,IAAA;CACR;AAED,oBAAY,mBAAmB;IAC7B,OAAO,IAAA;IACP,MAAM,IAAA;IACN,KAAK,IAAA;IACL,OAAO,IAAA;CACR;AAED;;GAEG;AACH,oBAAY,YAAY;IACtB,eAAe,IAAA;IACf,OAAO,IAAA;CACR;AAED;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B;;OAEG;WACW,QAAQ,IAAI,YAAY;IAStC;;;;;;OAMG;WACiB,KAAK,IAAI,OAAO,CAAC,SAAS,CAAC;IAyB/C;;OAEG;WACiB,cAAc,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAIvD
|
|
1
|
+
{"version":3,"file":"CurrentEnv.d.ts","sourceRoot":"","sources":["../../src/utils/CurrentEnv.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,oBAAY,SAAS;IACnB,cAAc,IAAA;IACd,iBAAiB,IAAA;IACjB,IAAI,IAAA;IACJ,GAAG,IAAA;IACH,aAAa,IAAA;IACb,OAAO,IAAA;CACR;AAED,oBAAY,mBAAmB;IAC7B,OAAO,IAAA;IACP,MAAM,IAAA;IACN,KAAK,IAAA;IACL,OAAO,IAAA;CACR;AAED;;GAEG;AACH,oBAAY,YAAY;IACtB,eAAe,IAAA;IACf,OAAO,IAAA;CACR;AAED;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B;;OAEG;WACW,QAAQ,IAAI,YAAY;IAStC;;;;;;OAMG;WACiB,KAAK,IAAI,OAAO,CAAC,SAAS,CAAC;IAyB/C;;OAEG;WACiB,cAAc,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAIvD;;;;;;OAMG;WACiB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAsBrD;;;;OAIG;IACH,WAAkB,EAAE,IAAI,mBAAmB,CAQ1C;WAEa,UAAU,IAAI,MAAM;CAGnC"}
|
package/lib/utils/CurrentEnv.js
CHANGED
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.TerminalType = exports.OperatingSystemType = exports.ShellType = void 0;
|
|
7
7
|
const promises_1 = require("fs/promises");
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const
|
|
10
|
-
const
|
|
9
|
+
const CLIService_1 = __importDefault(require("../services/CLIService"));
|
|
10
|
+
const Logger_1 = __importDefault(require("./Logger"));
|
|
11
11
|
/**
|
|
12
12
|
* The type of shell that the current environment is running.
|
|
13
13
|
*/
|
|
@@ -62,7 +62,7 @@ class CurrentEnv {
|
|
|
62
62
|
const currentOs = CurrentEnv.os;
|
|
63
63
|
if (currentOs === OperatingSystemType.Windows) {
|
|
64
64
|
// Command comes from: https://stackoverflow.com/questions/34471956/how-to-determine-if-im-in-powershell-or-cmd
|
|
65
|
-
const { output } = await
|
|
65
|
+
const { output } = await CLIService_1.default.execCmd('(dir 2>&1 *`|echo CMD);&<# rem #>echo ($PSVersionTable).PSEdition');
|
|
66
66
|
switch (output) {
|
|
67
67
|
case 'CMD':
|
|
68
68
|
return ShellType.CommandPrompt;
|
|
@@ -71,7 +71,7 @@ class CurrentEnv {
|
|
|
71
71
|
case 'Core':
|
|
72
72
|
return ShellType.PowerShellCore;
|
|
73
73
|
default:
|
|
74
|
-
|
|
74
|
+
Logger_1.default.verbose.failure(`No recognizable shell returned for Windows environment.`);
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
else if (currentOs === OperatingSystemType.MacOSX) {
|
|
@@ -91,11 +91,8 @@ class CurrentEnv {
|
|
|
91
91
|
*
|
|
92
92
|
* The startup scripts are defined in the
|
|
93
93
|
* [dotfiles repo](https://github.com/aneuhold/dotfiles).
|
|
94
|
-
*
|
|
95
|
-
* @param args are the arguements that should be provided to the startup
|
|
96
|
-
* script as a string[]. This can be empty.
|
|
97
94
|
*/
|
|
98
|
-
static async runStartupScript(
|
|
95
|
+
static async runStartupScript() {
|
|
99
96
|
let cmd = '';
|
|
100
97
|
if (CurrentEnv.os === OperatingSystemType.Windows) {
|
|
101
98
|
// & says to powershell that you actually want to run the script in the
|
|
@@ -105,21 +102,14 @@ class CurrentEnv {
|
|
|
105
102
|
cmd = `& "$Home\\startup.ps1"`;
|
|
106
103
|
}
|
|
107
104
|
else {
|
|
108
|
-
cmd =
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
if (args) {
|
|
112
|
-
args.forEach((arg) => {
|
|
113
|
-
tmpArgs.push(arg);
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
cmd.args = tmpArgs;
|
|
117
|
-
await (0, cmd_1.default)(cmd, true, process.env.HOME);
|
|
105
|
+
cmd = 'zsh';
|
|
106
|
+
const args = ['startup.sh'];
|
|
107
|
+
await CLIService_1.default.spawnCmd(cmd, args, process.env.HOME);
|
|
118
108
|
return;
|
|
119
109
|
}
|
|
120
|
-
|
|
121
|
-
const { output } = await
|
|
122
|
-
|
|
110
|
+
Logger_1.default.info(`Executing the following command: "${cmd}"`);
|
|
111
|
+
const { output } = await CLIService_1.default.execCmd(cmd);
|
|
112
|
+
Logger_1.default.info(output);
|
|
123
113
|
process.exit();
|
|
124
114
|
}
|
|
125
115
|
/**
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export default class Logger {
|
|
2
|
+
static verboseLoggingEnabled: boolean;
|
|
3
|
+
/**
|
|
4
|
+
* Private variable that sets if any logging on this instance of the Log
|
|
5
|
+
* should only log if the `verboseLoggingEnabled` is set to true.
|
|
6
|
+
*/
|
|
7
|
+
private logOnlyIfVerbose;
|
|
8
|
+
constructor(logOnlyIfVerbose?: boolean);
|
|
9
|
+
/**
|
|
10
|
+
* Sets the logging of the next chained function to only be activated
|
|
11
|
+
* if verbose logging is turned on.
|
|
12
|
+
*/
|
|
13
|
+
static get verbose(): Logger;
|
|
14
|
+
/**
|
|
15
|
+
* Logs info to the console. Prepends `ℹ️` to each message.
|
|
16
|
+
*/
|
|
17
|
+
info(msg: string, skipNewline?: boolean): void;
|
|
18
|
+
/**
|
|
19
|
+
* Static version of {@link Logger.prototype.info}.
|
|
20
|
+
*
|
|
21
|
+
* @see Logger.prototype.info
|
|
22
|
+
*/
|
|
23
|
+
static info(msg: string, skipNewline?: boolean): void;
|
|
24
|
+
/**
|
|
25
|
+
* Logs a success message to the console. Prepends `✅` to each message.
|
|
26
|
+
*
|
|
27
|
+
* @param msg
|
|
28
|
+
*/
|
|
29
|
+
success(msg: string): void;
|
|
30
|
+
/**
|
|
31
|
+
* Static version of {@link Logger.prototype.success}.
|
|
32
|
+
*
|
|
33
|
+
* @see Logger.prototype.success
|
|
34
|
+
*/
|
|
35
|
+
static success(msg: string): void;
|
|
36
|
+
/**
|
|
37
|
+
* Logs a failure message to the console. Prepends `🔴` to each message.
|
|
38
|
+
*
|
|
39
|
+
* See {@link error} for logging errors.
|
|
40
|
+
*
|
|
41
|
+
* This doesn't use a `console.error` entry. Just a `console.log` entry.
|
|
42
|
+
* @param msg
|
|
43
|
+
*/
|
|
44
|
+
failure(msg: string): void;
|
|
45
|
+
/**
|
|
46
|
+
* Static version of {@link Logger.prototype.failure}.
|
|
47
|
+
*
|
|
48
|
+
* @see Logger.prototype.failure
|
|
49
|
+
*/
|
|
50
|
+
static failure(msg: string): void;
|
|
51
|
+
/**
|
|
52
|
+
* Logs an error message to the console. Only use this for errors that will
|
|
53
|
+
* likely stop execution. Prepends `💀` to each message and uses `console.error`.
|
|
54
|
+
*
|
|
55
|
+
* See {@link failure} for logging simple failures.
|
|
56
|
+
*
|
|
57
|
+
* @param msg
|
|
58
|
+
*/
|
|
59
|
+
error(msg: string): void;
|
|
60
|
+
/**
|
|
61
|
+
* Static version of {@link Logger.prototype.error}.
|
|
62
|
+
*
|
|
63
|
+
* @see Logger.prototype.error
|
|
64
|
+
*/
|
|
65
|
+
static error(msg: string): void;
|
|
66
|
+
private shouldLog;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=Logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/utils/Logger.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,MAAM;IACzB,OAAc,qBAAqB,UAAS;IAE5C;;;OAGG;IACH,OAAO,CAAC,gBAAgB,CAAS;gBAErB,gBAAgB,CAAC,EAAE,OAAO;IAMtC;;;OAGG;IACH,MAAM,KAAK,OAAO,IAAI,MAAM,CAE3B;IAED;;OAEG;IACH,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,OAAO,GAAG,IAAI;IAW9C;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,OAAO,GAAG,IAAI;IAIrD;;;;OAIG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAM1B;;;;OAIG;IACH,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAIjC;;;;;;;OAOG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAM1B;;;;OAIG;IACH,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAIjC;;;;;;;OAOG;IACH,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAMxB;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAI/B,OAAO,CAAC,SAAS;CASlB"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class Logger {
|
|
4
|
+
static verboseLoggingEnabled = false;
|
|
5
|
+
/**
|
|
6
|
+
* Private variable that sets if any logging on this instance of the Log
|
|
7
|
+
* should only log if the `verboseLoggingEnabled` is set to true.
|
|
8
|
+
*/
|
|
9
|
+
logOnlyIfVerbose = false;
|
|
10
|
+
constructor(logOnlyIfVerbose) {
|
|
11
|
+
if (logOnlyIfVerbose) {
|
|
12
|
+
this.logOnlyIfVerbose = logOnlyIfVerbose;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Sets the logging of the next chained function to only be activated
|
|
17
|
+
* if verbose logging is turned on.
|
|
18
|
+
*/
|
|
19
|
+
static get verbose() {
|
|
20
|
+
return new Logger(true);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Logs info to the console. Prepends `ℹ️` to each message.
|
|
24
|
+
*/
|
|
25
|
+
info(msg, skipNewline) {
|
|
26
|
+
if (this.shouldLog()) {
|
|
27
|
+
const printMessage = `ℹ️ ${msg}`;
|
|
28
|
+
if (skipNewline) {
|
|
29
|
+
process.stdout.write(printMessage);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
console.log(printMessage);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Static version of {@link Logger.prototype.info}.
|
|
38
|
+
*
|
|
39
|
+
* @see Logger.prototype.info
|
|
40
|
+
*/
|
|
41
|
+
static info(msg, skipNewline) {
|
|
42
|
+
new Logger().info(msg, skipNewline);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Logs a success message to the console. Prepends `✅` to each message.
|
|
46
|
+
*
|
|
47
|
+
* @param msg
|
|
48
|
+
*/
|
|
49
|
+
success(msg) {
|
|
50
|
+
if (this.shouldLog()) {
|
|
51
|
+
console.log(`✅ ${msg}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Static version of {@link Logger.prototype.success}.
|
|
56
|
+
*
|
|
57
|
+
* @see Logger.prototype.success
|
|
58
|
+
*/
|
|
59
|
+
static success(msg) {
|
|
60
|
+
new Logger().success(msg);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Logs a failure message to the console. Prepends `🔴` to each message.
|
|
64
|
+
*
|
|
65
|
+
* See {@link error} for logging errors.
|
|
66
|
+
*
|
|
67
|
+
* This doesn't use a `console.error` entry. Just a `console.log` entry.
|
|
68
|
+
* @param msg
|
|
69
|
+
*/
|
|
70
|
+
failure(msg) {
|
|
71
|
+
if (this.shouldLog()) {
|
|
72
|
+
console.log(`🔴 ${msg}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Static version of {@link Logger.prototype.failure}.
|
|
77
|
+
*
|
|
78
|
+
* @see Logger.prototype.failure
|
|
79
|
+
*/
|
|
80
|
+
static failure(msg) {
|
|
81
|
+
new Logger().failure(msg);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Logs an error message to the console. Only use this for errors that will
|
|
85
|
+
* likely stop execution. Prepends `💀` to each message and uses `console.error`.
|
|
86
|
+
*
|
|
87
|
+
* See {@link failure} for logging simple failures.
|
|
88
|
+
*
|
|
89
|
+
* @param msg
|
|
90
|
+
*/
|
|
91
|
+
error(msg) {
|
|
92
|
+
if (this.shouldLog()) {
|
|
93
|
+
console.error(`💀 ${msg}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Static version of {@link Logger.prototype.error}.
|
|
98
|
+
*
|
|
99
|
+
* @see Logger.prototype.error
|
|
100
|
+
*/
|
|
101
|
+
static error(msg) {
|
|
102
|
+
new Logger().error(msg);
|
|
103
|
+
}
|
|
104
|
+
shouldLog() {
|
|
105
|
+
if (!this.logOnlyIfVerbose ||
|
|
106
|
+
(this.logOnlyIfVerbose && Logger.verboseLoggingEnabled)) {
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.default = Logger;
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aneuhold/core-ts-lib",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "A core library for all of my TypeScript projects",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"pushpub": "npm run build && npm version patch && git push && npm publish --access public",
|
|
9
|
-
"build": "tsc"
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"watch": "tsc -w",
|
|
11
|
+
"upgrade:all": "yarn upgrade --latest"
|
|
10
12
|
},
|
|
11
13
|
"type": "commonjs",
|
|
12
14
|
"repository": {
|
|
@@ -28,11 +30,11 @@
|
|
|
28
30
|
],
|
|
29
31
|
"dependencies": {},
|
|
30
32
|
"devDependencies": {
|
|
31
|
-
"@types/node": "^
|
|
32
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
33
|
-
"@typescript-eslint/parser": "^
|
|
34
|
-
"eslint": "^
|
|
35
|
-
"eslint-config-airbnb-base": "^
|
|
33
|
+
"@types/node": "^18.15.0",
|
|
34
|
+
"@typescript-eslint/eslint-plugin": "^5.54.1",
|
|
35
|
+
"@typescript-eslint/parser": "^5.54.1",
|
|
36
|
+
"eslint": "^8.35.0",
|
|
37
|
+
"eslint-config-airbnb-base": "^15.0.0",
|
|
36
38
|
"eslint-config-prettier": "^8.3.0",
|
|
37
39
|
"eslint-plugin-import": "^2.22.1",
|
|
38
40
|
"eslint-plugin-prettier": "^4.0.0",
|