@aneuhold/core-ts-lib 1.0.7 → 1.0.9

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.
Files changed (56) hide show
  1. package/lib/helperFunctions/dateFunctions.d.ts +9 -9
  2. package/lib/helperFunctions/dateFunctions.js +15 -15
  3. package/lib/helperFunctions/sleep.d.ts +6 -6
  4. package/lib/helperFunctions/sleep.js +12 -12
  5. package/lib/helperFunctions/stringFunctions.d.ts +8 -8
  6. package/lib/helperFunctions/stringFunctions.js +13 -13
  7. package/lib/index.d.ts +12 -11
  8. package/lib/index.d.ts.map +1 -1
  9. package/lib/index.js +54 -52
  10. package/lib/services/CLIService.d.ts +68 -65
  11. package/lib/services/CLIService.d.ts.map +1 -1
  12. package/lib/services/CLIService.js +194 -188
  13. package/lib/services/StringService.d.ts +13 -13
  14. package/lib/services/StringService.js +18 -18
  15. package/lib/services/applications/ChromeService.d.ts +19 -19
  16. package/lib/services/applications/ChromeService.js +60 -60
  17. package/lib/services/applications/DockerService.d.ts +20 -20
  18. package/lib/services/applications/DockerService.js +88 -88
  19. package/lib/services/applications/FileSystemService.d.ts +17 -17
  20. package/lib/services/applications/FileSystemService.js +87 -87
  21. package/lib/services/applications/ITermService.d.ts +8 -0
  22. package/lib/services/applications/ITermService.d.ts.map +1 -0
  23. package/lib/services/applications/ITermService.js +45 -0
  24. package/lib/services/applications/OsaScriptService.d.ts +4 -0
  25. package/lib/services/applications/OsaScriptService.d.ts.map +1 -0
  26. package/lib/services/applications/OsaScriptService.js +31 -0
  27. package/lib/utils/CurrentEnv.d.ts +62 -61
  28. package/lib/utils/CurrentEnv.d.ts.map +1 -1
  29. package/lib/utils/CurrentEnv.js +137 -133
  30. package/lib/utils/Logger.d.ts +67 -67
  31. package/lib/utils/Logger.js +112 -112
  32. package/lib/utils/OsaScriptBuilder.d.ts +45 -0
  33. package/lib/utils/OsaScriptBuilder.d.ts.map +1 -0
  34. package/lib/utils/OsaScriptBuilder.js +53 -0
  35. package/package.json +1 -1
  36. package/lib/helperFunctions/applications/applications.d.ts +0 -21
  37. package/lib/helperFunctions/applications/applications.d.ts.map +0 -1
  38. package/lib/helperFunctions/applications/applications.js +0 -26
  39. package/lib/helperFunctions/applications/chromeApplication.d.ts +0 -8
  40. package/lib/helperFunctions/applications/chromeApplication.d.ts.map +0 -1
  41. package/lib/helperFunctions/applications/chromeApplication.js +0 -63
  42. package/lib/helperFunctions/applications/fileSystemApplication.d.ts +0 -8
  43. package/lib/helperFunctions/applications/fileSystemApplication.d.ts.map +0 -1
  44. package/lib/helperFunctions/applications/fileSystemApplication.js +0 -51
  45. package/lib/helperFunctions/cmd.d.ts +0 -54
  46. package/lib/helperFunctions/cmd.d.ts.map +0 -1
  47. package/lib/helperFunctions/cmd.js +0 -177
  48. package/lib/helperFunctions/fileFunctions.d.ts +0 -10
  49. package/lib/helperFunctions/fileFunctions.d.ts.map +0 -1
  50. package/lib/helperFunctions/fileFunctions.js +0 -43
  51. package/lib/helperFunctions/input.d.ts +0 -8
  52. package/lib/helperFunctions/input.d.ts.map +0 -1
  53. package/lib/helperFunctions/input.js +0 -48
  54. package/lib/utils/Log.d.ts +0 -69
  55. package/lib/utils/Log.d.ts.map +0 -1
  56. package/lib/utils/Log.js +0 -112
@@ -1,177 +0,0 @@
1
- "use strict";
2
- /* This file is meant to house helper functions for specifically executing
3
- command line / terminal things. */
4
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
- if (k2 === undefined) k2 = k;
6
- var desc = Object.getOwnPropertyDescriptor(m, k);
7
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
- desc = { enumerable: true, get: function() { return m[k]; } };
9
- }
10
- Object.defineProperty(o, k2, desc);
11
- }) : (function(o, m, k, k2) {
12
- if (k2 === undefined) k2 = k;
13
- o[k2] = m[k];
14
- }));
15
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
16
- Object.defineProperty(o, "default", { enumerable: true, value: v });
17
- }) : function(o, v) {
18
- o["default"] = v;
19
- });
20
- var __importStar = (this && this.__importStar) || function (mod) {
21
- if (mod && mod.__esModule) return mod;
22
- var result = {};
23
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
24
- __setModuleDefault(result, mod);
25
- return result;
26
- };
27
- var __importDefault = (this && this.__importDefault) || function (mod) {
28
- return (mod && mod.__esModule) ? mod : { "default": mod };
29
- };
30
- Object.defineProperty(exports, "__esModule", { value: true });
31
- exports.execCmdWithTimeout = exports.variousCommands = void 0;
32
- const child_process_1 = require("child_process");
33
- const util_1 = __importDefault(require("util"));
34
- const CurrentEnv_1 = __importStar(require("../utils/CurrentEnv"));
35
- const Log_1 = __importDefault(require("../utils/Log"));
36
- const sleep_1 = __importDefault(require("./sleep"));
37
- /**
38
- * The promisified version of the {@link normalExec} function.
39
- */
40
- const exec = util_1.default.promisify(child_process_1.exec);
41
- exports.variousCommands = {
42
- pwshExectuablePath: 'Get-Command pwsh | Select-Object -ExpandProperty Definition'
43
- };
44
- const POWERSHELL_PREFIX = `pwsh -NoProfile -Command `;
45
- async function helperExec(cmd, execOptions, logError) {
46
- try {
47
- const { stdout, stderr } = await exec(cmd, execOptions);
48
- if (stderr) {
49
- if (logError) {
50
- Log_1.default.error(`There was an error executing ${cmd}. Details are printed below:
51
- ${stderr}`);
52
- }
53
- return {
54
- didComplete: false,
55
- output: stderr
56
- };
57
- }
58
- Log_1.default.verbose.info(stdout);
59
- return {
60
- didComplete: true,
61
- output: stdout
62
- };
63
- }
64
- catch (err) {
65
- Log_1.default.error(`There was an error executing the "exec" function. Details are printed below:
66
- ${err}`);
67
- return {
68
- didComplete: false,
69
- output: err
70
- };
71
- }
72
- }
73
- /**
74
- * Code was found from this site: https://stackabuse.com/executing-shell-commands-with-node-js/.
75
- *
76
- * This still needs to be hardened it feels like.
77
- *
78
- * @param cmd
79
- * @param execOptions
80
- */
81
- async function helperSpawn(cmd, args, execOptions) {
82
- return new Promise((resolve) => {
83
- let output = '';
84
- const spawnedCmd = (0, child_process_1.spawn)(cmd, args, execOptions);
85
- spawnedCmd.on('error', (err) => {
86
- Log_1.default.error(`There was an error executing the "spawn" function. Details are printed below:
87
- ${err}`);
88
- resolve({
89
- didComplete: false,
90
- output: err.toString()
91
- });
92
- });
93
- spawnedCmd.stdout.on('data', (data) => {
94
- output += data;
95
- Log_1.default.info(data, true);
96
- });
97
- spawnedCmd.stderr.on('data', (data) => {
98
- output += data;
99
- Log_1.default.info(data, true);
100
- });
101
- spawnedCmd.on('close', (exitCode) => {
102
- Log_1.default.info(`Command "${cmd}" exited with code ${exitCode}`);
103
- resolve({
104
- didComplete: true,
105
- output
106
- });
107
- });
108
- });
109
- }
110
- /**
111
- * Executes the given command in a shell environment. Spins up a separate
112
- * process to execute the command and returns a promise once it is completely
113
- * finished.
114
- *
115
- * The shell environment chosen is determined by the `CurrentEnv` class.
116
- *
117
- * @param cmd the command to run as either one large string or an object.
118
- *
119
- * If just a string is provided, this is ran as a normal execution where the
120
- * output is all returned at once after completion. For example this could be
121
- * `ls -a`
122
- *
123
- * If an object is provided, this is ran as a stream where all output is streamed
124
- * to the console. This is helpful for long-running commands or commands
125
- * that output a lot of data. For example `yarn` or `npm install`.
126
- * All of the output from this is logged by default because of the listeners
127
- * involved. This could be changed in the future though. For example the param
128
- * could be `{command: "npm", args: ["install"]}`
129
- *
130
- * @param logError if set to false, it will not output a log if an error
131
- * occurs in `stderr` when executing the function. This can be useful if
132
- * a command regularly outputs an error even when it succeeds. This only
133
- * applies to commands ran with normal execution.
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
- *
138
- * @returns an object that holds the output and the true if the command comlpleted
139
- * successfully or false if it did not
140
- */
141
- async function execCmd(cmd, logError = false, cwd) {
142
- const execOptions = {
143
- cwd
144
- };
145
- let modifiedCmd = null;
146
- if (typeof cmd === 'string') {
147
- Log_1.default.verbose.info('Command type provided to "execCmd" was a string, so executing "exec" promise...');
148
- if (CurrentEnv_1.default.os === CurrentEnv_1.OperatingSystemType.Windows) {
149
- modifiedCmd = POWERSHELL_PREFIX + cmd;
150
- }
151
- return helperExec(modifiedCmd || cmd, execOptions, logError);
152
- }
153
- Log_1.default.verbose.info('Command type provided to "execCmd" was an object, so executing "spawn" promise...');
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);
158
- }
159
- exports.default = execCmd;
160
- /**
161
- * Executes the given command but fulfills the
162
- * promise when either the command completes, or the given number of ms have
163
- * passed. Whichever comes first.
164
- *
165
- * @param command the command to execute
166
- * @param ms the number of milliseconds to wait. This is 5 seconds by default.
167
- */
168
- async function execCmdWithTimeout(command, ms = 5000) {
169
- const sleepPromise = (0, sleep_1.default)(ms).then(() => {
170
- return {
171
- didComplete: false,
172
- output: `Command ended after ${ms} ms.`
173
- };
174
- });
175
- return Promise.any([sleepPromise, execCmd(command)]);
176
- }
177
- exports.execCmdWithTimeout = execCmdWithTimeout;
@@ -1,10 +0,0 @@
1
- /**
2
- * Tries to add the provided snippet of text to the path provided. If the file
3
- * doesn't exist, it creates it. If the folders to the file don't exist, it
4
- * creates those. If the text already exists in the file, it does nothing.
5
- *
6
- * @param folderPath the path to the folder which contains the file that should
7
- * be updated
8
- */
9
- export default function findAndInsertText(folderPath: string, fileName: string, textToInsert: string): Promise<void>;
10
- //# sourceMappingURL=fileFunctions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fileFunctions.d.ts","sourceRoot":"","sources":["../../src/helperFunctions/fileFunctions.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,wBAA8B,iBAAiB,CAC7C,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,IAAI,CAAC,CA0Bf"}
@@ -1,43 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const promises_1 = require("fs/promises");
7
- const path_1 = __importDefault(require("path"));
8
- const Log_1 = __importDefault(require("../utils/Log"));
9
- /**
10
- * Tries to add the provided snippet of text to the path provided. If the file
11
- * doesn't exist, it creates it. If the folders to the file don't exist, it
12
- * creates those. If the text already exists in the file, it does nothing.
13
- *
14
- * @param folderPath the path to the folder which contains the file that should
15
- * be updated
16
- */
17
- async function findAndInsertText(folderPath, fileName, textToInsert) {
18
- const filePath = path_1.default.join(folderPath, fileName);
19
- try {
20
- await (0, promises_1.access)(folderPath);
21
- }
22
- catch (e) {
23
- console.log(e);
24
- Log_1.default.info(`Directory "${folderPath}" does not exist. Creating it now...`);
25
- await (0, promises_1.mkdir)(folderPath, { recursive: true });
26
- }
27
- try {
28
- await (0, promises_1.access)(filePath);
29
- const fileContents = await (0, promises_1.readFile)(filePath);
30
- if (!fileContents.includes(textToInsert)) {
31
- await (0, promises_1.appendFile)(filePath, `\n${textToInsert}`);
32
- Log_1.default.info(`Added "${textToInsert}" to "${filePath}"`);
33
- }
34
- else {
35
- Log_1.default.info(`"${textToInsert}" already exists in "${filePath}"`);
36
- }
37
- }
38
- catch {
39
- Log_1.default.info(`File at "${filePath}" didn't exist. Creating it now and adding "${textToInsert}" to it.`);
40
- await (0, promises_1.writeFile)(filePath, textToInsert);
41
- }
42
- }
43
- exports.default = findAndInsertText;
@@ -1,8 +0,0 @@
1
- /**
2
- * Gets input from the user on command line.
3
- *
4
- * @param promptToUser the prompt that should be provided to the user. Include
5
- * a newline at the end if you want there to be one.
6
- */
7
- export default function getUserInput(promptToUser: string): Promise<string>;
8
- //# sourceMappingURL=input.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../src/helperFunctions/input.ts"],"names":[],"mappings":"AAgBA;;;;;GAKG;AACH,wBAA8B,YAAY,CACxC,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,MAAM,CAAC,CAEjB"}
@@ -1,48 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const rl = __importStar(require("readline"));
27
- const readline = rl.createInterface({
28
- input: process.stdin,
29
- output: process.stdout
30
- });
31
- function ask(promptToUser) {
32
- return new Promise((resolve) => {
33
- readline.question(promptToUser, (input) => {
34
- readline.close();
35
- resolve(input);
36
- });
37
- });
38
- }
39
- /**
40
- * Gets input from the user on command line.
41
- *
42
- * @param promptToUser the prompt that should be provided to the user. Include
43
- * a newline at the end if you want there to be one.
44
- */
45
- async function getUserInput(promptToUser) {
46
- return ask(promptToUser);
47
- }
48
- exports.default = getUserInput;
@@ -1,69 +0,0 @@
1
- declare class Log {
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(): Log;
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 Log.prototype.info}.
20
- *
21
- * @see Log.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 Log.prototype.success}.
32
- *
33
- * @see Log.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 Log.prototype.failure}.
47
- *
48
- * @see Log.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 Log.prototype.error}.
62
- *
63
- * @see Log.prototype.error
64
- */
65
- static error(msg: string): void;
66
- private shouldLog;
67
- }
68
- export default Log;
69
- //# sourceMappingURL=Log.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Log.d.ts","sourceRoot":"","sources":["../../src/utils/Log.ts"],"names":[],"mappings":"AAAA,cAAM,GAAG;IACP,OAAc,qBAAqB,UAAS;IAE5C;;;OAGG;IACH,OAAO,CAAC,gBAAgB,CAAS;gBAErB,gBAAgB,CAAC,EAAE,OAAO;IAMtC;;;OAGG;IACH,MAAM,KAAK,OAAO,IAAI,GAAG,CAExB;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;AAED,eAAe,GAAG,CAAC"}
package/lib/utils/Log.js DELETED
@@ -1,112 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class Log {
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 Log(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 Log.prototype.info}.
38
- *
39
- * @see Log.prototype.info
40
- */
41
- static info(msg, skipNewline) {
42
- new Log().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 Log.prototype.success}.
56
- *
57
- * @see Log.prototype.success
58
- */
59
- static success(msg) {
60
- new Log().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 Log.prototype.failure}.
77
- *
78
- * @see Log.prototype.failure
79
- */
80
- static failure(msg) {
81
- new Log().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 Log.prototype.error}.
98
- *
99
- * @see Log.prototype.error
100
- */
101
- static error(msg) {
102
- new Log().error(msg);
103
- }
104
- shouldLog() {
105
- if (!this.logOnlyIfVerbose ||
106
- (this.logOnlyIfVerbose && Log.verboseLoggingEnabled)) {
107
- return true;
108
- }
109
- return false;
110
- }
111
- }
112
- exports.default = Log;