@aneuhold/core-ts-lib 1.0.3

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 (38) hide show
  1. package/lib/helperFunctions/applications/applications.d.ts +21 -0
  2. package/lib/helperFunctions/applications/applications.d.ts.map +1 -0
  3. package/lib/helperFunctions/applications/applications.js +26 -0
  4. package/lib/helperFunctions/applications/chromeApplication.d.ts +8 -0
  5. package/lib/helperFunctions/applications/chromeApplication.d.ts.map +1 -0
  6. package/lib/helperFunctions/applications/chromeApplication.js +63 -0
  7. package/lib/helperFunctions/applications/fileSystemApplication.d.ts +8 -0
  8. package/lib/helperFunctions/applications/fileSystemApplication.d.ts.map +1 -0
  9. package/lib/helperFunctions/applications/fileSystemApplication.js +51 -0
  10. package/lib/helperFunctions/cmd.d.ts +51 -0
  11. package/lib/helperFunctions/cmd.d.ts.map +1 -0
  12. package/lib/helperFunctions/cmd.js +170 -0
  13. package/lib/helperFunctions/dateFunctions.d.ts +10 -0
  14. package/lib/helperFunctions/dateFunctions.d.ts.map +1 -0
  15. package/lib/helperFunctions/dateFunctions.js +15 -0
  16. package/lib/helperFunctions/fileFunctions.d.ts +10 -0
  17. package/lib/helperFunctions/fileFunctions.d.ts.map +1 -0
  18. package/lib/helperFunctions/fileFunctions.js +43 -0
  19. package/lib/helperFunctions/input.d.ts +8 -0
  20. package/lib/helperFunctions/input.d.ts.map +1 -0
  21. package/lib/helperFunctions/input.js +48 -0
  22. package/lib/helperFunctions/sleep.d.ts +8 -0
  23. package/lib/helperFunctions/sleep.d.ts.map +1 -0
  24. package/lib/helperFunctions/sleep.js +12 -0
  25. package/lib/helperFunctions/stringFunctions.d.ts +9 -0
  26. package/lib/helperFunctions/stringFunctions.d.ts.map +1 -0
  27. package/lib/helperFunctions/stringFunctions.js +13 -0
  28. package/lib/index.d.ts +24 -0
  29. package/lib/index.d.ts.map +1 -0
  30. package/lib/index.js +51 -0
  31. package/lib/utils/CurrentEnv.d.ts +65 -0
  32. package/lib/utils/CurrentEnv.d.ts.map +1 -0
  33. package/lib/utils/CurrentEnv.js +143 -0
  34. package/lib/utils/Log.d.ts +69 -0
  35. package/lib/utils/Log.d.ts.map +1 -0
  36. package/lib/utils/Log.js +112 -0
  37. package/package.json +43 -0
  38. package/readme.md +3 -0
@@ -0,0 +1,21 @@
1
+ export type Application = {
2
+ defaultCall: () => Promise<void>;
3
+ [functionName: string]: unknown;
4
+ };
5
+ /**
6
+ * The list of app names that are possible. These can be aliases to specific
7
+ * operations as well. This is the single source of truth.
8
+ */
9
+ export declare enum AppName {
10
+ chrome = "chrome",
11
+ nugetCache = "nugetCache"
12
+ }
13
+ /**
14
+ * Holds logic pertaining to running and using individual applications on the
15
+ * current system.
16
+ */
17
+ declare const applications: {
18
+ [appName in AppName]: Application;
19
+ };
20
+ export default applications;
21
+ //# sourceMappingURL=applications.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"applications.d.ts","sourceRoot":"","sources":["../../../src/helperFunctions/applications/applications.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,WAAW,GAAG;IACxB,WAAW,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC;CACjC,CAAC;AAEF;;;GAGG;AACH,oBAAY,OAAO;IACjB,MAAM,WAAW;IACjB,UAAU,eAAe;CAC1B;AAED;;;GAGG;AACH,QAAA,MAAM,YAAY,EAAE;KAAG,OAAO,IAAI,OAAO,GAAG,WAAW;CAGtD,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -0,0 +1,26 @@
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
+ exports.AppName = void 0;
7
+ const chromeApplication_1 = __importDefault(require("./chromeApplication"));
8
+ const fileSystemApplication_1 = __importDefault(require("./fileSystemApplication"));
9
+ /**
10
+ * The list of app names that are possible. These can be aliases to specific
11
+ * operations as well. This is the single source of truth.
12
+ */
13
+ var AppName;
14
+ (function (AppName) {
15
+ AppName["chrome"] = "chrome";
16
+ AppName["nugetCache"] = "nugetCache";
17
+ })(AppName = exports.AppName || (exports.AppName = {}));
18
+ /**
19
+ * Holds logic pertaining to running and using individual applications on the
20
+ * current system.
21
+ */
22
+ const applications = {
23
+ chrome: chromeApplication_1.default,
24
+ nugetCache: fileSystemApplication_1.default
25
+ };
26
+ exports.default = applications;
@@ -0,0 +1,8 @@
1
+ import { Application } from './applications';
2
+ /**
3
+ * Holds the logic pertaining to interacting with the Chrome application,
4
+ * regardless of which platform it is on.
5
+ */
6
+ declare const chromeApplication: Application;
7
+ export default chromeApplication;
8
+ //# sourceMappingURL=chromeApplication.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chromeApplication.d.ts","sourceRoot":"","sources":["../../../src/helperFunctions/applications/chromeApplication.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AA+B7C;;;GAGG;AACH,QAAA,MAAM,iBAAiB,EAAE,WAIxB,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
@@ -0,0 +1,63 @@
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 cmd_1 = __importDefault(require("../cmd"));
31
+ /**
32
+ * Gets the path to the chrome application for the current system given the
33
+ * operating system type.
34
+ *
35
+ * This does include the quotes
36
+ */
37
+ function getChromePath(os) {
38
+ switch (os) {
39
+ case CurrentEnv_1.OperatingSystemType.MacOSX:
40
+ return `"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"`;
41
+ case CurrentEnv_1.OperatingSystemType.Windows:
42
+ return `& "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"`;
43
+ default:
44
+ return null;
45
+ }
46
+ }
47
+ /**
48
+ * Opens and sets pinned tabs in chrome. Still trying to figure out
49
+ * how to get this to work.
50
+ */
51
+ async function openAndSetPinnedTabs() {
52
+ await (0, cmd_1.default)(`${getChromePath(CurrentEnv_1.default.os)} --pinned-tab-count=2 https://google.com https://tonyneuhold.com`);
53
+ }
54
+ /**
55
+ * Holds the logic pertaining to interacting with the Chrome application,
56
+ * regardless of which platform it is on.
57
+ */
58
+ const chromeApplication = {
59
+ async defaultCall() {
60
+ openAndSetPinnedTabs();
61
+ }
62
+ };
63
+ exports.default = chromeApplication;
@@ -0,0 +1,8 @@
1
+ import { Application } from './applications';
2
+ /**
3
+ * Holds the logic pertaining to interacting with the Chrome application,
4
+ * regardless of which platform it is on.
5
+ */
6
+ declare const fileSystemApplication: Application;
7
+ export default fileSystemApplication;
8
+ //# sourceMappingURL=fileSystemApplication.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fileSystemApplication.d.ts","sourceRoot":"","sources":["../../../src/helperFunctions/applications/fileSystemApplication.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAe7C;;;GAGG;AACH,QAAA,MAAM,qBAAqB,EAAE,WAI5B,CAAC;AAEF,eAAe,qBAAqB,CAAC"}
@@ -0,0 +1,51 @@
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 cmd_1 = __importDefault(require("../cmd"));
31
+ async function openWindowsNugetCache() {
32
+ await Promise.all([
33
+ (0, cmd_1.default)(`ii $HOME/localNuget`),
34
+ (0, cmd_1.default)(`ii $HOME/.nuget/packages`)
35
+ ]);
36
+ }
37
+ async function openNugetCache() {
38
+ if (CurrentEnv_1.default.os === CurrentEnv_1.OperatingSystemType.Windows) {
39
+ await openWindowsNugetCache();
40
+ }
41
+ }
42
+ /**
43
+ * Holds the logic pertaining to interacting with the Chrome application,
44
+ * regardless of which platform it is on.
45
+ */
46
+ const fileSystemApplication = {
47
+ async defaultCall() {
48
+ await openNugetCache();
49
+ }
50
+ };
51
+ exports.default = fileSystemApplication;
@@ -0,0 +1,51 @@
1
+ export declare const variousCommands: {
2
+ pwshExectuablePath: string;
3
+ };
4
+ type ExecCmdReturnType = {
5
+ didComplete: boolean;
6
+ output: string;
7
+ };
8
+ export type ExecCmdCommandArgument = string | {
9
+ command: string;
10
+ args?: string[];
11
+ };
12
+ /**
13
+ * Executes the given command in a shell environment. Spins up a separate
14
+ * process to execute the command and returns a promise once it is completely
15
+ * finished.
16
+ *
17
+ * The shell environment chosen is determined by the `CurrentEnv` class.
18
+ *
19
+ * @param cmd the command to run as either one large string or an object.
20
+ *
21
+ * If just a string is provided, this is ran as a normal execution where the
22
+ * output is all returned at once after completion. For example this could be
23
+ * `ls -a`
24
+ *
25
+ * If an object is provided, this is ran as a stream where all output is streamed
26
+ * to the console. This is helpful for long-running commands or commands
27
+ * that output a lot of data. For example `yarn` or `npm install`.
28
+ * All of the output from this is logged by default because of the listeners
29
+ * involved. This could be changed in the future though. For example the param
30
+ * could be `{command: "npm", args: ["install"]}`
31
+ *
32
+ * @param logError if set to false, it will not output a log if an error
33
+ * occurs in `stderr` when executing the function. This can be useful if
34
+ * a command regularly outputs an error even when it succeeds. This only
35
+ * applies to commands ran with normal execution.
36
+ *
37
+ * @returns an object that holds the output and the true if the command comlpleted
38
+ * successfully or false if it did not
39
+ */
40
+ export default function execCmd(cmd: ExecCmdCommandArgument, logError?: boolean, cwd?: string): Promise<ExecCmdReturnType>;
41
+ /**
42
+ * Executes the given command but fulfills the
43
+ * promise when either the command completes, or the given number of ms have
44
+ * passed. Whichever comes first.
45
+ *
46
+ * @param command the command to execute
47
+ * @param ms the number of milliseconds to wait. This is 5 seconds by default.
48
+ */
49
+ export declare function execCmdWithTimeout(command: string, ms?: number): Promise<ExecCmdReturnType>;
50
+ export {};
51
+ //# sourceMappingURL=cmd.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cmd.d.ts","sourceRoot":"","sources":["../../src/helperFunctions/cmd.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,eAAe;;CAG3B,CAAC;AAEF,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;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAA8B,OAAO,CACnC,GAAG,EAAE,sBAAsB,EAC3B,QAAQ,UAAQ,EAChB,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC,iBAAiB,CAAC,CAoB5B;AAED;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,MAAM,EACf,EAAE,SAAO,GACR,OAAO,CAAC,iBAAiB,CAAC,CAQ5B"}
@@ -0,0 +1,170 @@
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
+ async function helperExec(cmd, execOptions, logError) {
45
+ try {
46
+ const { stdout, stderr } = await exec(cmd, execOptions);
47
+ if (stderr) {
48
+ if (logError) {
49
+ Log_1.default.error(`There was an error executing ${cmd}. Details are printed below:
50
+ ${stderr}`);
51
+ }
52
+ return {
53
+ didComplete: false,
54
+ output: stderr
55
+ };
56
+ }
57
+ Log_1.default.verbose.info(stdout);
58
+ return {
59
+ didComplete: true,
60
+ output: stdout
61
+ };
62
+ }
63
+ catch (err) {
64
+ Log_1.default.error(`There was an error executing the "exec" function. Details are printed below:
65
+ ${err}`);
66
+ return {
67
+ didComplete: false,
68
+ output: err
69
+ };
70
+ }
71
+ }
72
+ /**
73
+ * Code was found from this site: https://stackabuse.com/executing-shell-commands-with-node-js/.
74
+ *
75
+ * This still needs to be hardened it feels like.
76
+ *
77
+ * @param cmd
78
+ * @param execOptions
79
+ */
80
+ async function helperSpawn(cmd, args, execOptions) {
81
+ return new Promise((resolve) => {
82
+ let output = '';
83
+ const spawnedCmd = (0, child_process_1.spawn)(cmd, args, execOptions);
84
+ spawnedCmd.on('error', (err) => {
85
+ Log_1.default.error(`There was an error executing the "spawn" function. Details are printed below:
86
+ ${err}`);
87
+ resolve({
88
+ didComplete: false,
89
+ output: err.toString()
90
+ });
91
+ });
92
+ spawnedCmd.stdout.on('data', (data) => {
93
+ output += data;
94
+ Log_1.default.info(data, true);
95
+ });
96
+ spawnedCmd.stderr.on('data', (data) => {
97
+ output += data;
98
+ Log_1.default.info(data, true);
99
+ });
100
+ spawnedCmd.on('close', (exitCode) => {
101
+ Log_1.default.info(`Command "${cmd}" exited with code ${exitCode}`);
102
+ resolve({
103
+ didComplete: true,
104
+ output
105
+ });
106
+ });
107
+ });
108
+ }
109
+ /**
110
+ * Executes the given command in a shell environment. Spins up a separate
111
+ * process to execute the command and returns a promise once it is completely
112
+ * finished.
113
+ *
114
+ * The shell environment chosen is determined by the `CurrentEnv` class.
115
+ *
116
+ * @param cmd the command to run as either one large string or an object.
117
+ *
118
+ * If just a string is provided, this is ran as a normal execution where the
119
+ * output is all returned at once after completion. For example this could be
120
+ * `ls -a`
121
+ *
122
+ * If an object is provided, this is ran as a stream where all output is streamed
123
+ * to the console. This is helpful for long-running commands or commands
124
+ * that output a lot of data. For example `yarn` or `npm install`.
125
+ * All of the output from this is logged by default because of the listeners
126
+ * involved. This could be changed in the future though. For example the param
127
+ * could be `{command: "npm", args: ["install"]}`
128
+ *
129
+ * @param logError if set to false, it will not output a log if an error
130
+ * occurs in `stderr` when executing the function. This can be useful if
131
+ * a command regularly outputs an error even when it succeeds. This only
132
+ * applies to commands ran with normal execution.
133
+ *
134
+ * @returns an object that holds the output and the true if the command comlpleted
135
+ * successfully or false if it did not
136
+ */
137
+ async function execCmd(cmd, logError = false, cwd) {
138
+ const execOptions = {
139
+ cwd
140
+ };
141
+ // Use powershell core if it is windows
142
+ if (CurrentEnv_1.default.os === CurrentEnv_1.OperatingSystemType.Windows) {
143
+ execOptions.shell = 'pwsh';
144
+ }
145
+ if (typeof cmd === 'string') {
146
+ Log_1.default.verbose.info('Command type provided to "execCmd" was a string, so executing "exec" promise...');
147
+ return helperExec(cmd, execOptions, logError);
148
+ }
149
+ Log_1.default.verbose.info('Command type provided to "execCmd" was an object, so executing "spawn" promise...');
150
+ return helperSpawn(cmd.command, cmd.args, execOptions);
151
+ }
152
+ exports.default = execCmd;
153
+ /**
154
+ * Executes the given command but fulfills the
155
+ * promise when either the command completes, or the given number of ms have
156
+ * passed. Whichever comes first.
157
+ *
158
+ * @param command the command to execute
159
+ * @param ms the number of milliseconds to wait. This is 5 seconds by default.
160
+ */
161
+ async function execCmdWithTimeout(command, ms = 5000) {
162
+ const sleepPromise = (0, sleep_1.default)(ms).then(() => {
163
+ return {
164
+ didComplete: false,
165
+ output: `Command ended after ${ms} ms.`
166
+ };
167
+ });
168
+ return Promise.any([sleepPromise, execCmd(command)]);
169
+ }
170
+ exports.execCmdWithTimeout = execCmdWithTimeout;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Determines if the dates are on the same day.
3
+ *
4
+ * @param first the first date
5
+ * @param second the second date
6
+ * @returns true if they are on the same day
7
+ */
8
+ declare function datesAreOnSameDay(first: Date, second: Date): boolean;
9
+ export default datesAreOnSameDay;
10
+ //# sourceMappingURL=dateFunctions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dateFunctions.d.ts","sourceRoot":"","sources":["../../src/helperFunctions/dateFunctions.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,iBAAS,iBAAiB,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAG,OAAO,CAM7D;AAED,eAAe,iBAAiB,CAAC"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Determines if the dates are on the same day.
5
+ *
6
+ * @param first the first date
7
+ * @param second the second date
8
+ * @returns true if they are on the same day
9
+ */
10
+ function datesAreOnSameDay(first, second) {
11
+ return (first.getFullYear() === second.getFullYear() &&
12
+ first.getMonth() === second.getMonth() &&
13
+ first.getDate() === second.getDate());
14
+ }
15
+ exports.default = datesAreOnSameDay;
@@ -0,0 +1,10 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,43 @@
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;
@@ -0,0 +1,8 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,48 @@
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;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Sleeps for the given amount of milliseconds, and resolves once finished.
3
+ *
4
+ * @param ms the number of milliseconds to sleep
5
+ * @returns
6
+ */
7
+ export default function sleep(ms: number): Promise<void>;
8
+ //# sourceMappingURL=sleep.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Sleeps for the given amount of milliseconds, and resolves once finished.
5
+ *
6
+ * @param ms the number of milliseconds to sleep
7
+ * @returns
8
+ */
9
+ function sleep(ms) {
10
+ return new Promise((resolve) => setTimeout(resolve, ms));
11
+ }
12
+ exports.default = sleep;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Gets the file extension of the provided file name.
3
+ *
4
+ * @param fileName the full name of the file or the entire file path
5
+ * @returns a string containing the extension of the file name or undefined
6
+ * if there is no extension
7
+ */
8
+ export default function getFileNameExtension(fileName: string): string | undefined;
9
+ //# sourceMappingURL=stringFunctions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stringFunctions.d.ts","sourceRoot":"","sources":["../../src/helperFunctions/stringFunctions.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAC1C,QAAQ,EAAE,MAAM,GACf,MAAM,GAAG,SAAS,CAEpB"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Gets the file extension of the provided file name.
5
+ *
6
+ * @param fileName the full name of the file or the entire file path
7
+ * @returns a string containing the extension of the file name or undefined
8
+ * if there is no extension
9
+ */
10
+ function getFileNameExtension(fileName) {
11
+ return fileName.split('.').pop();
12
+ }
13
+ exports.default = getFileNameExtension;
package/lib/index.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ import execCmd, { execCmdWithTimeout } from './helperFunctions/cmd';
2
+ import datesAreOnSameDay from './helperFunctions/dateFunctions';
3
+ import findAndInsertText from './helperFunctions/fileFunctions';
4
+ import getUserInput from './helperFunctions/input';
5
+ import sleep from './helperFunctions/sleep';
6
+ import getFileNameExtension from './helperFunctions/stringFunctions';
7
+ import CurrentEnv, { OperatingSystemType, ShellType, TerminalType } from './utils/CurrentEnv';
8
+ import Log from './utils/Log';
9
+ declare const _default: {
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;
24
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,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,wBAaE"}
package/lib/index.js ADDED
@@ -0,0 +1,51 @@
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 cmd_1 = __importStar(require("./helperFunctions/cmd"));
30
+ const dateFunctions_1 = __importDefault(require("./helperFunctions/dateFunctions"));
31
+ const fileFunctions_1 = __importDefault(require("./helperFunctions/fileFunctions"));
32
+ const input_1 = __importDefault(require("./helperFunctions/input"));
33
+ const sleep_1 = __importDefault(require("./helperFunctions/sleep"));
34
+ const stringFunctions_1 = __importDefault(require("./helperFunctions/stringFunctions"));
35
+ const CurrentEnv_1 = __importStar(require("./utils/CurrentEnv"));
36
+ const Log_1 = __importDefault(require("./utils/Log"));
37
+ // Export all the functions and classes from this library
38
+ exports.default = {
39
+ execCmd: cmd_1.default,
40
+ execCmdWithTimeout: cmd_1.execCmdWithTimeout,
41
+ CurrentEnv: CurrentEnv_1.default,
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
+ };
@@ -0,0 +1,65 @@
1
+ /**
2
+ * The type of shell that the current environment is running.
3
+ */
4
+ export declare enum ShellType {
5
+ PowerShellCore = 0,
6
+ PowerShellDesktop = 1,
7
+ Bash = 2,
8
+ Zsh = 3,
9
+ CommandPrompt = 4,
10
+ Unknown = 5
11
+ }
12
+ export declare enum OperatingSystemType {
13
+ Windows = 0,
14
+ MacOSX = 1,
15
+ Linux = 2,
16
+ Unknown = 3
17
+ }
18
+ /**
19
+ * The type of terminal that the current enviornment is running.
20
+ */
21
+ export declare enum TerminalType {
22
+ WindowsTerminal = 0,
23
+ Unknown = 1
24
+ }
25
+ /**
26
+ * Provides information relevant to the current environment this script is
27
+ * running in.
28
+ */
29
+ export default class CurrentEnv {
30
+ /**
31
+ * Returns the type of terminal the current environment is using.
32
+ */
33
+ static terminal(): TerminalType;
34
+ /**
35
+ * Returns the type of shell the current environment is using.
36
+ *
37
+ * This might be arbitrary because it seems that the exec command will use
38
+ * whatever the default shell is or whatever is specified as the shell
39
+ * option.
40
+ */
41
+ static shell(): Promise<ShellType>;
42
+ /**
43
+ * Gets all file names in the current directory.
44
+ */
45
+ static fileNamesInDir(): Promise<string[]>;
46
+ /**
47
+ * Runs the startup script for the current system. This command exits the
48
+ * package.
49
+ *
50
+ * The startup scripts are defined in the
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
+ */
56
+ static runStartupScript(args?: string[]): Promise<void>;
57
+ /**
58
+ * Determines the type of operating system in the current environment.
59
+ *
60
+ * This looks to be O(1) complexity.
61
+ */
62
+ static get os(): OperatingSystemType;
63
+ static folderName(): string;
64
+ }
65
+ //# sourceMappingURL=CurrentEnv.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,143 @@
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
+ exports.TerminalType = exports.OperatingSystemType = exports.ShellType = void 0;
7
+ const promises_1 = require("fs/promises");
8
+ const path_1 = __importDefault(require("path"));
9
+ const cmd_1 = __importDefault(require("../helperFunctions/cmd"));
10
+ const Log_1 = __importDefault(require("./Log"));
11
+ /**
12
+ * The type of shell that the current environment is running.
13
+ */
14
+ var ShellType;
15
+ (function (ShellType) {
16
+ ShellType[ShellType["PowerShellCore"] = 0] = "PowerShellCore";
17
+ ShellType[ShellType["PowerShellDesktop"] = 1] = "PowerShellDesktop";
18
+ ShellType[ShellType["Bash"] = 2] = "Bash";
19
+ ShellType[ShellType["Zsh"] = 3] = "Zsh";
20
+ ShellType[ShellType["CommandPrompt"] = 4] = "CommandPrompt";
21
+ ShellType[ShellType["Unknown"] = 5] = "Unknown";
22
+ })(ShellType = exports.ShellType || (exports.ShellType = {}));
23
+ var OperatingSystemType;
24
+ (function (OperatingSystemType) {
25
+ OperatingSystemType[OperatingSystemType["Windows"] = 0] = "Windows";
26
+ OperatingSystemType[OperatingSystemType["MacOSX"] = 1] = "MacOSX";
27
+ OperatingSystemType[OperatingSystemType["Linux"] = 2] = "Linux";
28
+ OperatingSystemType[OperatingSystemType["Unknown"] = 3] = "Unknown";
29
+ })(OperatingSystemType = exports.OperatingSystemType || (exports.OperatingSystemType = {}));
30
+ /**
31
+ * The type of terminal that the current enviornment is running.
32
+ */
33
+ var TerminalType;
34
+ (function (TerminalType) {
35
+ TerminalType[TerminalType["WindowsTerminal"] = 0] = "WindowsTerminal";
36
+ TerminalType[TerminalType["Unknown"] = 1] = "Unknown";
37
+ })(TerminalType = exports.TerminalType || (exports.TerminalType = {}));
38
+ /**
39
+ * Provides information relevant to the current environment this script is
40
+ * running in.
41
+ */
42
+ class CurrentEnv {
43
+ /**
44
+ * Returns the type of terminal the current environment is using.
45
+ */
46
+ static terminal() {
47
+ // See https://stackoverflow.com/questions/59733731/how-to-detect-if-running-in-the-new-windows-terminal
48
+ // for information on why this method was chosen.
49
+ if (process.env.WT_SESSION) {
50
+ return TerminalType.WindowsTerminal;
51
+ }
52
+ return TerminalType.Unknown;
53
+ }
54
+ /**
55
+ * Returns the type of shell the current environment is using.
56
+ *
57
+ * This might be arbitrary because it seems that the exec command will use
58
+ * whatever the default shell is or whatever is specified as the shell
59
+ * option.
60
+ */
61
+ static async shell() {
62
+ const currentOs = CurrentEnv.os;
63
+ if (currentOs === OperatingSystemType.Windows) {
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');
66
+ switch (output) {
67
+ case 'CMD':
68
+ return ShellType.CommandPrompt;
69
+ case 'Desktop':
70
+ return ShellType.PowerShellDesktop;
71
+ case 'Core':
72
+ return ShellType.PowerShellCore;
73
+ default:
74
+ Log_1.default.verbose.failure(`No recognizable shell returned for Windows environment.`);
75
+ }
76
+ }
77
+ else if (currentOs === OperatingSystemType.MacOSX) {
78
+ // Mighbt want to use process.env.SHELL for Linux environments
79
+ }
80
+ return ShellType.Unknown;
81
+ }
82
+ /**
83
+ * Gets all file names in the current directory.
84
+ */
85
+ static async fileNamesInDir() {
86
+ return (0, promises_1.readdir)(path_1.default.resolve('.'));
87
+ }
88
+ /**
89
+ * Runs the startup script for the current system. This command exits the
90
+ * package.
91
+ *
92
+ * The startup scripts are defined in the
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
+ */
98
+ static async runStartupScript(args) {
99
+ let cmd = '';
100
+ if (CurrentEnv.os === OperatingSystemType.Windows) {
101
+ // & says to powershell that you actually want to run the script in the
102
+ // quotes afterwards
103
+ // Also just running the startup script for now because of some infinite
104
+ // loop issues with specifying arguments
105
+ cmd = `& "$Home\\startup.ps1"`;
106
+ }
107
+ 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);
118
+ return;
119
+ }
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);
123
+ process.exit();
124
+ }
125
+ /**
126
+ * Determines the type of operating system in the current environment.
127
+ *
128
+ * This looks to be O(1) complexity.
129
+ */
130
+ static get os() {
131
+ if (process.platform === 'win32') {
132
+ return OperatingSystemType.Windows;
133
+ }
134
+ if (process.platform === 'darwin') {
135
+ return OperatingSystemType.MacOSX;
136
+ }
137
+ return OperatingSystemType.Unknown;
138
+ }
139
+ static folderName() {
140
+ return path_1.default.basename(path_1.default.resolve('.'));
141
+ }
142
+ }
143
+ exports.default = CurrentEnv;
@@ -0,0 +1,69 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,112 @@
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;
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@aneuhold/core-ts-lib",
3
+ "version": "1.0.3",
4
+ "description": "A core library for all of my TypeScript projects",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "scripts": {
8
+ "pushpub": "npm run build && npm version patch && git push && npm publish --access public",
9
+ "build": "tsc"
10
+ },
11
+ "type": "commonjs",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/aneuhold/core-ts-lib.git"
15
+ },
16
+ "keywords": [
17
+ "Scripting",
18
+ "Node.js"
19
+ ],
20
+ "author": "Anton G. Neuhold Jr.",
21
+ "license": "MIT",
22
+ "bugs": {
23
+ "url": "https://github.com/aneuhold/core-ts-lib/issues"
24
+ },
25
+ "homepage": "https://github.com/aneuhold/core-ts-lib#readme",
26
+ "files": [
27
+ "lib/**/*"
28
+ ],
29
+ "dependencies": {},
30
+ "devDependencies": {
31
+ "@types/node": "^16.10.2",
32
+ "@typescript-eslint/eslint-plugin": "^4.32.0",
33
+ "@typescript-eslint/parser": "^4.32.0",
34
+ "eslint": "^7.32.0",
35
+ "eslint-config-airbnb-base": "^14.2.1",
36
+ "eslint-config-prettier": "^8.3.0",
37
+ "eslint-plugin-import": "^2.22.1",
38
+ "eslint-plugin-prettier": "^4.0.0",
39
+ "prettier": "^2.4.1",
40
+ "ts-node": "^10.2.1",
41
+ "typescript": "^4.4.3"
42
+ }
43
+ }
package/readme.md ADDED
@@ -0,0 +1,3 @@
1
+ # core-ts-lib
2
+
3
+ This is a library containing TypeScript that I am sharing among a few different projects.