@aneuhold/core-ts-lib 1.0.4 → 1.0.7

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.
@@ -2,7 +2,6 @@
2
2
  * Sleeps for the given amount of milliseconds, and resolves once finished.
3
3
  *
4
4
  * @param ms the number of milliseconds to sleep
5
- * @returns
6
5
  */
7
6
  export default function sleep(ms: number): Promise<void>;
8
7
  //# sourceMappingURL=sleep.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sleep.d.ts","sourceRoot":"","sources":["../../src/helperFunctions/sleep.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEvD"}
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,11 +1,12 @@
1
- import applications, { AppName } from './helperFunctions/applications/applications';
2
- import execCmd, { execCmdWithTimeout } from './helperFunctions/cmd';
3
1
  import datesAreOnSameDay from './helperFunctions/dateFunctions';
4
- import findAndInsertText from './helperFunctions/fileFunctions';
5
- import getUserInput from './helperFunctions/input';
6
2
  import sleep from './helperFunctions/sleep';
7
3
  import getFileNameExtension from './helperFunctions/stringFunctions';
4
+ import ChromeService from './services/applications/ChromeService';
5
+ import DockerService from './services/applications/DockerService';
6
+ import FileSystemService from './services/applications/FileSystemService';
7
+ import CLIService from './services/CLIService';
8
+ import StringService from './services/StringService';
8
9
  import CurrentEnv, { OperatingSystemType, ShellType, TerminalType } from './utils/CurrentEnv';
9
- import Log from './utils/Log';
10
- export { execCmd, execCmdWithTimeout, CurrentEnv, applications, AppName, Log, sleep, getUserInput, findAndInsertText, OperatingSystemType, ShellType, TerminalType, datesAreOnSameDay, getFileNameExtension };
10
+ import Logger from './utils/Logger';
11
+ export { CLIService, StringService, CurrentEnv, ChromeService, DockerService, FileSystemService, sleep, OperatingSystemType, ShellType, Logger, TerminalType, datesAreOnSameDay, getFileNameExtension };
11
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,EAAE,EACnB,OAAO,EACR,MAAM,6CAA6C,CAAC;AACrD,OAAO,OAAO,EAAE,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,iBAAiB,MAAM,iCAAiC,CAAC;AAChE,OAAO,iBAAiB,MAAM,iCAAiC,CAAC;AAChE,OAAO,YAAY,MAAM,yBAAyB,CAAC;AACnD,OAAO,KAAK,MAAM,yBAAyB,CAAC;AAC5C,OAAO,oBAAoB,MAAM,mCAAmC,CAAC;AACrE,OAAO,UAAU,EAAE,EACjB,mBAAmB,EACnB,SAAS,EACT,YAAY,EACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,GAAG,MAAM,aAAa,CAAC;AAG9B,OAAO,EACL,OAAO,EACP,kBAAkB,EAClB,UAAU,EACV,YAAY,EACZ,OAAO,EACP,GAAG,EACH,KAAK,EACL,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,EACnB,SAAS,EACT,YAAY,EACZ,iBAAiB,EACjB,oBAAoB,EACrB,CAAC"}
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,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,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,27 +26,27 @@ 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.ShellType = exports.OperatingSystemType = exports.findAndInsertText = exports.getUserInput = exports.sleep = exports.Log = exports.AppName = exports.applications = exports.CurrentEnv = exports.execCmdWithTimeout = exports.execCmd = void 0;
30
- const applications_1 = __importStar(require("./helperFunctions/applications/applications"));
31
- exports.applications = applications_1.default;
32
- Object.defineProperty(exports, "AppName", { enumerable: true, get: function () { return applications_1.AppName; } });
33
- const cmd_1 = __importStar(require("./helperFunctions/cmd"));
34
- exports.execCmd = cmd_1.default;
35
- Object.defineProperty(exports, "execCmdWithTimeout", { enumerable: true, get: function () { return cmd_1.execCmdWithTimeout; } });
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;
36
30
  const dateFunctions_1 = __importDefault(require("./helperFunctions/dateFunctions"));
37
31
  exports.datesAreOnSameDay = dateFunctions_1.default;
38
- const fileFunctions_1 = __importDefault(require("./helperFunctions/fileFunctions"));
39
- exports.findAndInsertText = fileFunctions_1.default;
40
- const input_1 = __importDefault(require("./helperFunctions/input"));
41
- exports.getUserInput = input_1.default;
42
32
  const sleep_1 = __importDefault(require("./helperFunctions/sleep"));
43
33
  exports.sleep = sleep_1.default;
44
34
  const stringFunctions_1 = __importDefault(require("./helperFunctions/stringFunctions"));
45
35
  exports.getFileNameExtension = stringFunctions_1.default;
36
+ const ChromeService_1 = __importDefault(require("./services/applications/ChromeService"));
37
+ exports.ChromeService = ChromeService_1.default;
38
+ const DockerService_1 = __importDefault(require("./services/applications/DockerService"));
39
+ exports.DockerService = DockerService_1.default;
40
+ const FileSystemService_1 = __importDefault(require("./services/applications/FileSystemService"));
41
+ exports.FileSystemService = FileSystemService_1.default;
42
+ const CLIService_1 = __importDefault(require("./services/CLIService"));
43
+ exports.CLIService = CLIService_1.default;
44
+ const StringService_1 = __importDefault(require("./services/StringService"));
45
+ exports.StringService = StringService_1.default;
46
46
  const CurrentEnv_1 = __importStar(require("./utils/CurrentEnv"));
47
47
  exports.CurrentEnv = CurrentEnv_1.default;
48
48
  Object.defineProperty(exports, "OperatingSystemType", { enumerable: true, get: function () { return CurrentEnv_1.OperatingSystemType; } });
49
49
  Object.defineProperty(exports, "ShellType", { enumerable: true, get: function () { return CurrentEnv_1.ShellType; } });
50
50
  Object.defineProperty(exports, "TerminalType", { enumerable: true, get: function () { return CurrentEnv_1.TerminalType; } });
51
- const Log_1 = __importDefault(require("./utils/Log"));
52
- exports.Log = Log_1.default;
51
+ const Logger_1 = __importDefault(require("./utils/Logger"));
52
+ 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":"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;;;;;;;;;;;;;;;;;;;;;OAqBG;WACU,OAAO,CAClB,GAAG,EAAE,MAAM,EACX,QAAQ,UAAQ,EAChB,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC,iBAAiB,CAAC;IA2C7B;;;;;;;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"}
@@ -0,0 +1,188 @@
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
+ /**
40
+ * A service which can be used to interact with the command line on the current
41
+ * system.
42
+ */
43
+ class CLIService {
44
+ static POWERSHELL_PREFIX = `pwsh -NoProfile -Command `;
45
+ /**
46
+ * Executes the given command in a shell environment. Spins up a separate
47
+ * process to execute the command and returns a promise once it is completely
48
+ * finished.
49
+ *
50
+ * The shell environment chosen is determined by the `CurrentEnv` class.
51
+ *
52
+ * @param cmd the command to run. This is ran as a normal execution where the
53
+ * output is all returned at once after completion. For example this could be
54
+ * `ls -a`.
55
+ *
56
+ * @param logError if set to false, it will not output a log if an error
57
+ * occurs in `stderr` when executing the function. This can be useful if
58
+ * a command regularly outputs an error even when it succeeds. This only
59
+ * applies to commands ran with normal execution.
60
+ *
61
+ * @param cwd the current working directory to run the command in. If not
62
+ * provided, it will use the current working directory of the process.
63
+ *
64
+ * @returns an object that holds the output and true if the command completed
65
+ * successfully or false if it did not.
66
+ */
67
+ static async execCmd(cmd, logError = false, cwd) {
68
+ const execOptions = {};
69
+ if (cwd) {
70
+ execOptions.cwd = cwd;
71
+ }
72
+ let commandToExecute = cmd;
73
+ // Set the powershell prefix if the current OS is Windows so that
74
+ // the profile is not ran before the command.
75
+ if (CurrentEnv_1.default.os === CurrentEnv_1.OperatingSystemType.Windows) {
76
+ commandToExecute = `${CLIService.POWERSHELL_PREFIX}${cmd}`;
77
+ }
78
+ Logger_1.default.verbose.info(`Executing command: ${commandToExecute}`);
79
+ try {
80
+ const { stdout, stderr } = await execute(commandToExecute, execOptions);
81
+ if (stderr) {
82
+ if (logError) {
83
+ Logger_1.default.error(`There was an error executing ${cmd}. Details are printed below:
84
+ ${stderr}`);
85
+ }
86
+ return {
87
+ didComplete: false,
88
+ output: stderr
89
+ };
90
+ }
91
+ Logger_1.default.verbose.info(`Output from stdout is: ${stdout}`);
92
+ return {
93
+ didComplete: true,
94
+ output: stdout
95
+ };
96
+ }
97
+ catch (err) {
98
+ Logger_1.default.verbose
99
+ .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
+ const readline = rl.createInterface({
177
+ input: process.stdin,
178
+ output: process.stdout
179
+ });
180
+ return new Promise((resolve) => {
181
+ readline.question(promptToUser, (input) => {
182
+ readline.close();
183
+ resolve(input);
184
+ });
185
+ });
186
+ }
187
+ }
188
+ 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,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;
@@ -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;IAQ5C;;;;;;;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,87 @@
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
+ return;
43
+ }
44
+ Logger_1.default.error('Not implemented for this OS yet.');
45
+ }
46
+ /**
47
+ * Tries to add the provided snippet of text to the path provided. If the file
48
+ * doesn't exist, it creates it. If the folders to the file don't exist, it
49
+ * creates those. If the text already exists in the file, it does nothing.
50
+ *
51
+ * @param folderPath the path to the folder which contains the file that should
52
+ * be updated
53
+ */
54
+ static async findAndInsertText(folderPath, fileName, textToInsert) {
55
+ const filePath = path_1.default.join(folderPath, fileName);
56
+ try {
57
+ await (0, promises_1.access)(folderPath);
58
+ }
59
+ catch (e) {
60
+ console.log(e);
61
+ Logger_1.default.info(`Directory "${folderPath}" does not exist. Creating it now...`);
62
+ await (0, promises_1.mkdir)(folderPath, { recursive: true });
63
+ }
64
+ try {
65
+ await (0, promises_1.access)(filePath);
66
+ const fileContents = await (0, promises_1.readFile)(filePath);
67
+ if (!fileContents.includes(textToInsert)) {
68
+ await (0, promises_1.appendFile)(filePath, `\n${textToInsert}`);
69
+ Logger_1.default.info(`Added "${textToInsert}" to "${filePath}"`);
70
+ }
71
+ else {
72
+ Logger_1.default.info(`"${textToInsert}" already exists in "${filePath}"`);
73
+ }
74
+ }
75
+ catch {
76
+ Logger_1.default.info(`File at "${filePath}" didn't exist. Creating it now and adding "${textToInsert}" to it.`);
77
+ await (0, promises_1.writeFile)(filePath, textToInsert);
78
+ }
79
+ }
80
+ static async openWindowsNugetCache() {
81
+ await Promise.all([
82
+ CLIService_1.default.execCmd(`ii $HOME/localNuget`),
83
+ CLIService_1.default.execCmd(`ii $HOME/.nuget/packages`)
84
+ ]);
85
+ }
86
+ }
87
+ 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(args?: string[]): Promise<void>;
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;;;;;;;;;OASG;WACiB,gBAAgB,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IA8BpE;;;;OAIG;IACH,WAAkB,EAAE,IAAI,mBAAmB,CAQ1C;WAEa,UAAU,IAAI,MAAM;CAGnC"}
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"}
@@ -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 cmd_1 = __importDefault(require("../helperFunctions/cmd"));
10
- const Log_1 = __importDefault(require("./Log"));
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 (0, cmd_1.default)('(dir 2>&1 *`|echo CMD);&<# rem #>echo ($PSVersionTable).PSEdition');
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
- Log_1.default.verbose.failure(`No recognizable shell returned for Windows environment.`);
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(args) {
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 = { command: 'zsh' };
109
- const tmpArgs = ['startup.sh'];
110
- // Add additional arguments
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
- Log_1.default.info(`Executing the following command: "${cmd}"`);
121
- const { output } = await (0, cmd_1.default)(cmd);
122
- Log_1.default.info(output);
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@aneuhold/core-ts-lib",
3
- "version": "1.0.4",
3
+ "version": "1.0.7",
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",