@aneuhold/core-ts-lib 1.0.8 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/helperFunctions/dateFunctions.d.ts +9 -9
- package/lib/helperFunctions/dateFunctions.js +15 -15
- package/lib/helperFunctions/sleep.d.ts +6 -6
- package/lib/helperFunctions/sleep.js +12 -12
- package/lib/helperFunctions/stringFunctions.d.ts +8 -8
- package/lib/helperFunctions/stringFunctions.js +13 -13
- package/lib/index.d.ts +12 -11
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +54 -52
- package/lib/services/CLIService.d.ts +68 -68
- package/lib/services/CLIService.js +194 -194
- package/lib/services/StringService.d.ts +13 -13
- package/lib/services/StringService.js +18 -18
- package/lib/services/applications/ChromeService.d.ts +19 -19
- package/lib/services/applications/ChromeService.js +60 -60
- package/lib/services/applications/DockerService.d.ts +20 -20
- package/lib/services/applications/DockerService.js +88 -88
- package/lib/services/applications/FileSystemService.d.ts +18 -17
- package/lib/services/applications/FileSystemService.d.ts.map +1 -1
- package/lib/services/applications/FileSystemService.js +97 -87
- package/lib/services/applications/ITermService.d.ts +8 -0
- package/lib/services/applications/ITermService.d.ts.map +1 -0
- package/lib/services/applications/ITermService.js +45 -0
- package/lib/services/applications/OsaScriptService.d.ts +4 -0
- package/lib/services/applications/OsaScriptService.d.ts.map +1 -0
- package/lib/services/applications/OsaScriptService.js +31 -0
- package/lib/utils/CurrentEnv.d.ts +62 -61
- package/lib/utils/CurrentEnv.d.ts.map +1 -1
- package/lib/utils/CurrentEnv.js +137 -133
- package/lib/utils/Logger.d.ts +67 -67
- package/lib/utils/Logger.js +112 -112
- package/lib/utils/OsaScriptBuilder.d.ts +45 -0
- package/lib/utils/OsaScriptBuilder.d.ts.map +1 -0
- package/lib/utils/OsaScriptBuilder.js +53 -0
- package/package.json +1 -1
- package/lib/helperFunctions/applications/applications.d.ts +0 -21
- package/lib/helperFunctions/applications/applications.d.ts.map +0 -1
- package/lib/helperFunctions/applications/applications.js +0 -26
- package/lib/helperFunctions/applications/chromeApplication.d.ts +0 -8
- package/lib/helperFunctions/applications/chromeApplication.d.ts.map +0 -1
- package/lib/helperFunctions/applications/chromeApplication.js +0 -63
- package/lib/helperFunctions/applications/fileSystemApplication.d.ts +0 -8
- package/lib/helperFunctions/applications/fileSystemApplication.d.ts.map +0 -1
- package/lib/helperFunctions/applications/fileSystemApplication.js +0 -51
- package/lib/helperFunctions/cmd.d.ts +0 -54
- package/lib/helperFunctions/cmd.d.ts.map +0 -1
- package/lib/helperFunctions/cmd.js +0 -177
- package/lib/helperFunctions/fileFunctions.d.ts +0 -10
- package/lib/helperFunctions/fileFunctions.d.ts.map +0 -1
- package/lib/helperFunctions/fileFunctions.js +0 -43
- package/lib/helperFunctions/input.d.ts +0 -8
- package/lib/helperFunctions/input.d.ts.map +0 -1
- package/lib/helperFunctions/input.js +0 -48
- package/lib/utils/Log.d.ts +0 -69
- package/lib/utils/Log.d.ts.map +0 -1
- package/lib/utils/Log.js +0 -112
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `tell` block that can be executed in an OSA script.
|
|
3
|
+
*/
|
|
4
|
+
export type OsaScriptTellBlock = {
|
|
5
|
+
/**
|
|
6
|
+
* The command that goes after the `tell` keyword in the first line of the
|
|
7
|
+
* block.
|
|
8
|
+
*/
|
|
9
|
+
tellCommand: string;
|
|
10
|
+
sections: OsaScriptSection[];
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* A plain command that can be executed in an OSA script.
|
|
14
|
+
*/
|
|
15
|
+
export type OsaScriptCommand = string;
|
|
16
|
+
export type OsaScriptSection = OsaScriptTellBlock | OsaScriptCommand;
|
|
17
|
+
export default class OsaScriptBuilder {
|
|
18
|
+
private currentScript;
|
|
19
|
+
/**
|
|
20
|
+
* There's no need to escape single quotes with this. That is already done
|
|
21
|
+
* in the class.
|
|
22
|
+
*/
|
|
23
|
+
addCommand(command: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* There's no need to escape single quotes with this. That is already done
|
|
26
|
+
* in the class.
|
|
27
|
+
*/
|
|
28
|
+
addTellBlock(tellBlock: OsaScriptTellBlock): void;
|
|
29
|
+
/**
|
|
30
|
+
* Generates the full command that should be pasted as-is into a terminal.
|
|
31
|
+
*
|
|
32
|
+
* This will automatically escape any single quotes appropriately that were
|
|
33
|
+
* provided.
|
|
34
|
+
*/
|
|
35
|
+
getFullCommand(): string;
|
|
36
|
+
private stringifySection;
|
|
37
|
+
/**
|
|
38
|
+
* Single quotes are escaped by splitting the string in two, then adding a
|
|
39
|
+
* single quote to the end of the first half, and combining the two halves.
|
|
40
|
+
*
|
|
41
|
+
* By putting no space inbetween the two halves, the two halves are combined.
|
|
42
|
+
*/
|
|
43
|
+
private static escapeSingleQuotes;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=OsaScriptBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OsaScriptBuilder.d.ts","sourceRoot":"","sources":["../../src/utils/OsaScriptBuilder.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,gBAAgB,EAAE,CAAC;CAC9B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEtC,MAAM,MAAM,gBAAgB,GAAG,kBAAkB,GAAG,gBAAgB,CAAC;AAErE,MAAM,CAAC,OAAO,OAAO,gBAAgB;IACnC,OAAO,CAAC,aAAa,CAA0B;IAE/C;;;OAGG;IACI,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAIxC;;;OAGG;IACI,YAAY,CAAC,SAAS,EAAE,kBAAkB,GAAG,IAAI;IAIxD;;;;;OAKG;IACH,cAAc,IAAI,MAAM;IAQxB,OAAO,CAAC,gBAAgB;IAcxB;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,kBAAkB;CAGlC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class OsaScriptBuilder {
|
|
4
|
+
currentScript = [];
|
|
5
|
+
/**
|
|
6
|
+
* There's no need to escape single quotes with this. That is already done
|
|
7
|
+
* in the class.
|
|
8
|
+
*/
|
|
9
|
+
addCommand(command) {
|
|
10
|
+
this.currentScript.push(command);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* There's no need to escape single quotes with this. That is already done
|
|
14
|
+
* in the class.
|
|
15
|
+
*/
|
|
16
|
+
addTellBlock(tellBlock) {
|
|
17
|
+
this.currentScript.push(tellBlock);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Generates the full command that should be pasted as-is into a terminal.
|
|
21
|
+
*
|
|
22
|
+
* This will automatically escape any single quotes appropriately that were
|
|
23
|
+
* provided.
|
|
24
|
+
*/
|
|
25
|
+
getFullCommand() {
|
|
26
|
+
let stringifiedScript = `osascript`;
|
|
27
|
+
this.currentScript.forEach((section) => {
|
|
28
|
+
stringifiedScript += this.stringifySection(section);
|
|
29
|
+
});
|
|
30
|
+
return stringifiedScript;
|
|
31
|
+
}
|
|
32
|
+
stringifySection(section) {
|
|
33
|
+
if (typeof section === 'string') {
|
|
34
|
+
return ` -e '${OsaScriptBuilder.escapeSingleQuotes(section)}'`;
|
|
35
|
+
}
|
|
36
|
+
let stringifiedSection = ` -e 'tell ${OsaScriptBuilder.escapeSingleQuotes(section.tellCommand)}'`;
|
|
37
|
+
section.sections.forEach((subSection) => {
|
|
38
|
+
stringifiedSection += this.stringifySection(subSection);
|
|
39
|
+
});
|
|
40
|
+
stringifiedSection += ` -e 'end tell'`;
|
|
41
|
+
return stringifiedSection;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Single quotes are escaped by splitting the string in two, then adding a
|
|
45
|
+
* single quote to the end of the first half, and combining the two halves.
|
|
46
|
+
*
|
|
47
|
+
* By putting no space inbetween the two halves, the two halves are combined.
|
|
48
|
+
*/
|
|
49
|
+
static escapeSingleQuotes(stringToEscape) {
|
|
50
|
+
return stringToEscape.replace(/'/g, `'\\''`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.default = OsaScriptBuilder;
|
package/package.json
CHANGED
|
@@ -1,21 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,26 +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
|
-
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;
|
|
@@ -1,8 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,63 +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
|
-
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;
|
|
@@ -1,8 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,51 +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
|
-
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;
|
|
@@ -1,54 +0,0 @@
|
|
|
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
|
-
* @param cwd the current working directory to run the command in. If not
|
|
38
|
-
* provided, it will use the current working directory of the process.
|
|
39
|
-
*
|
|
40
|
-
* @returns an object that holds the output and the true if the command comlpleted
|
|
41
|
-
* successfully or false if it did not
|
|
42
|
-
*/
|
|
43
|
-
export default function execCmd(cmd: ExecCmdCommandArgument, logError?: boolean, cwd?: string): Promise<ExecCmdReturnType>;
|
|
44
|
-
/**
|
|
45
|
-
* Executes the given command but fulfills the
|
|
46
|
-
* promise when either the command completes, or the given number of ms have
|
|
47
|
-
* passed. Whichever comes first.
|
|
48
|
-
*
|
|
49
|
-
* @param command the command to execute
|
|
50
|
-
* @param ms the number of milliseconds to wait. This is 5 seconds by default.
|
|
51
|
-
*/
|
|
52
|
-
export declare function execCmdWithTimeout(command: string, ms?: number): Promise<ExecCmdReturnType>;
|
|
53
|
-
export {};
|
|
54
|
-
//# sourceMappingURL=cmd.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cmd.d.ts","sourceRoot":"","sources":["../../src/helperFunctions/cmd.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,eAAe;;CAG3B,CAAC;AAIF,KAAK,iBAAiB,GAAG;IAAE,WAAW,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAClE,MAAM,MAAM,sBAAsB,GAC9B,MAAM,GACN;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AA6EzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAA8B,OAAO,CACnC,GAAG,EAAE,sBAAsB,EAC3B,QAAQ,UAAQ,EAChB,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC,iBAAiB,CAAC,CAwB5B;AAED;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,MAAM,EACf,EAAE,SAAO,GACR,OAAO,CAAC,iBAAiB,CAAC,CAQ5B"}
|
|
@@ -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;
|