@aneuhold/be-ts-lib 1.0.79 → 2.0.0

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/LICENSE +21 -0
  2. package/README.md +44 -1
  3. package/lib/index.d.ts +4 -11
  4. package/lib/index.d.ts.map +1 -1
  5. package/lib/index.js +5 -51
  6. package/lib/index.js.map +1 -0
  7. package/lib/index.ts +11 -0
  8. package/lib/services/ConfigService/ConfigDefinition.d.ts.map +1 -1
  9. package/lib/services/ConfigService/ConfigDefinition.js +2 -2
  10. package/lib/services/ConfigService/ConfigDefinition.js.map +1 -0
  11. package/lib/services/ConfigService/ConfigDefinition.ts +10 -0
  12. package/lib/services/ConfigService/ConfigService.d.ts +25 -4
  13. package/lib/services/ConfigService/ConfigService.d.ts.map +1 -1
  14. package/lib/services/ConfigService/ConfigService.js +33 -17
  15. package/lib/services/ConfigService/ConfigService.js.map +1 -0
  16. package/lib/services/ConfigService/ConfigService.spec.ts +17 -0
  17. package/lib/services/ConfigService/ConfigService.ts +88 -0
  18. package/lib/services/GitHubService.d.ts +10 -0
  19. package/lib/services/GitHubService.d.ts.map +1 -1
  20. package/lib/services/GitHubService.js +17 -9
  21. package/lib/services/GitHubService.js.map +1 -0
  22. package/lib/services/GitHubService.ts +63 -0
  23. package/lib/services/TranslationService/TranslationService.d.ts +7 -1
  24. package/lib/services/TranslationService/TranslationService.d.ts.map +1 -1
  25. package/lib/services/TranslationService/TranslationService.js +17 -17
  26. package/lib/services/TranslationService/TranslationService.js.map +1 -0
  27. package/lib/services/TranslationService/TranslationService.spec.ts +18 -0
  28. package/lib/services/TranslationService/TranslationService.ts +40 -0
  29. package/package.json +37 -28
  30. package/lib/services/CLIService.d.ts +0 -69
  31. package/lib/services/CLIService.d.ts.map +0 -1
  32. package/lib/services/CLIService.js +0 -193
  33. package/lib/services/ConfigService/ConfigService.spec.d.ts +0 -2
  34. package/lib/services/ConfigService/ConfigService.spec.d.ts.map +0 -1
  35. package/lib/services/ConfigService/ConfigService.spec.js +0 -20
  36. package/lib/services/TranslationService/TranslationService.spec.d.ts +0 -2
  37. package/lib/services/TranslationService/TranslationService.spec.d.ts.map +0 -1
  38. package/lib/services/TranslationService/TranslationService.spec.js +0 -39
  39. package/lib/services/applications/ChromeService.d.ts +0 -20
  40. package/lib/services/applications/ChromeService.d.ts.map +0 -1
  41. package/lib/services/applications/ChromeService.js +0 -60
  42. package/lib/services/applications/DockerService.d.ts +0 -21
  43. package/lib/services/applications/DockerService.d.ts.map +0 -1
  44. package/lib/services/applications/DockerService.js +0 -86
  45. package/lib/services/applications/ITermService.d.ts +0 -8
  46. package/lib/services/applications/ITermService.d.ts.map +0 -1
  47. package/lib/services/applications/ITermService.js +0 -45
  48. package/lib/services/applications/OSFileSystemService.d.ts +0 -19
  49. package/lib/services/applications/OSFileSystemService.d.ts.map +0 -1
  50. package/lib/services/applications/OSFileSystemService.js +0 -90
  51. package/lib/utils/CurrentEnv.d.ts +0 -63
  52. package/lib/utils/CurrentEnv.d.ts.map +0 -1
  53. package/lib/utils/CurrentEnv.js +0 -137
  54. package/lib/utils/OsaScriptBuilder.d.ts +0 -45
  55. package/lib/utils/OsaScriptBuilder.d.ts.map +0 -1
  56. package/lib/utils/OsaScriptBuilder.js +0 -53
@@ -1 +0,0 @@
1
- {"version":3,"file":"DockerService.d.ts","sourceRoot":"","sources":["../../../src/services/applications/DockerService.ts"],"names":[],"mappings":"AACA,OAAmB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAGzE;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC;;;OAGG;WACU,kBAAkB;WAgBlB,6BAA6B,IAAI,OAAO,CAAC,OAAO,CAAC;IAe9D;;;;;OAKG;IACH,MAAM,CAAC,aAAa,CAAC,EAAE,EAAE,mBAAmB,GAAG,MAAM,GAAG,IAAI;CAS7D"}
@@ -1,86 +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 core_ts_lib_1 = require("@aneuhold/core-ts-lib");
30
- const CurrentEnv_1 = __importStar(require("../../utils/CurrentEnv"));
31
- const CLIService_1 = __importDefault(require("../CLIService"));
32
- /**
33
- * A service that provides functionality for interacting with the Docker
34
- * application.
35
- */
36
- class DockerService {
37
- /**
38
- * Starts the Docker Desktop application. If it is already running, it doesn't
39
- * do anything.
40
- */
41
- static async startDockerDesktop() {
42
- const currentOS = CurrentEnv_1.default.os;
43
- const dockerPath = DockerService.getDockerPath(currentOS);
44
- let dockerRunning = await DockerService.checkIfDockerDesktopIsRunning();
45
- if (!dockerRunning && dockerPath) {
46
- core_ts_lib_1.Logger.info('Docker desktop is not running. Starting it now...');
47
- await CLIService_1.default.execCmdWithTimeout(dockerPath, 4000);
48
- while (!dockerRunning) {
49
- core_ts_lib_1.Logger.info('Waiting for Docker to start...');
50
- await (0, core_ts_lib_1.sleep)(2000);
51
- dockerRunning = await DockerService.checkIfDockerDesktopIsRunning();
52
- }
53
- }
54
- core_ts_lib_1.Logger.info('Docker desktop is running.');
55
- }
56
- static async checkIfDockerDesktopIsRunning() {
57
- const currentOS = CurrentEnv_1.default.os;
58
- if (currentOS === CurrentEnv_1.OperatingSystemType.Windows) {
59
- const { didComplete } = await CLIService_1.default.execCmd('Get-Process docker');
60
- if (didComplete) {
61
- core_ts_lib_1.Logger.verbose.info('Docker is running.');
62
- return true;
63
- }
64
- core_ts_lib_1.Logger.verbose.info('Docker is not running.');
65
- return false;
66
- }
67
- core_ts_lib_1.Logger.error('Docker command not defined for this OS yet.');
68
- return false;
69
- }
70
- /**
71
- * Gets the path to the docker application for the current system given the
72
- * operating system type.
73
- *
74
- * This does include the quotes
75
- */
76
- static getDockerPath(os) {
77
- switch (os) {
78
- case CurrentEnv_1.OperatingSystemType.Windows:
79
- return `& "C:\\Program Files\\Docker\\Docker\\Docker Desktop.exe"`;
80
- default:
81
- core_ts_lib_1.Logger.error('Docker path not defined for this OS yet.');
82
- return null;
83
- }
84
- }
85
- }
86
- exports.default = DockerService;
@@ -1,8 +0,0 @@
1
- export default class ITermService {
2
- /**
3
- * Splits the iTerm terminal horzontally and runs each command in a separate
4
- * pane.
5
- */
6
- static splitHorizontallyAndRunCommands(commands: string[], cwd?: string): Promise<void>;
7
- }
8
- //# sourceMappingURL=ITermService.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ITermService.d.ts","sourceRoot":"","sources":["../../../src/services/applications/ITermService.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,OAAO,OAAO,YAAY;IAC/B;;;OAGG;WACU,+BAA+B,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,GAAG,SAAK;CAmC1E"}
@@ -1,45 +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 core_ts_lib_1 = require("@aneuhold/core-ts-lib");
7
- const OsaScriptBuilder_1 = __importDefault(require("../../utils/OsaScriptBuilder"));
8
- const CLIService_1 = __importDefault(require("../CLIService"));
9
- class ITermService {
10
- /**
11
- * Splits the iTerm terminal horzontally and runs each command in a separate
12
- * pane.
13
- */
14
- static async splitHorizontallyAndRunCommands(commands, cwd = '') {
15
- const terminalWindowTellBlock = {
16
- tellCommand: `W's current session`,
17
- sections: []
18
- };
19
- // Do the number of splits needed
20
- commands.forEach(() => {
21
- terminalWindowTellBlock.sections.push(`split horizontally with default profile`);
22
- });
23
- const iTermApplicationTellBlock = {
24
- tellCommand: 'application "iTerm"',
25
- sections: [
26
- 'activate',
27
- 'set W to current window',
28
- 'if W = missing value then set W to create window with default profile',
29
- terminalWindowTellBlock,
30
- `set T to W's current tab`
31
- ]
32
- };
33
- // Add in the commands, adding 2 to the session number because the first
34
- // session is 1, and the second is 2.
35
- commands.forEach((command, i) => {
36
- iTermApplicationTellBlock.sections.push(`write T's session ${i + 2} text "cd ${cwd} && ${command}"`);
37
- });
38
- const osaScriptBuilder = new OsaScriptBuilder_1.default();
39
- osaScriptBuilder.addTellBlock(iTermApplicationTellBlock);
40
- const osaScript = osaScriptBuilder.getFullCommand();
41
- core_ts_lib_1.Logger.verbose.info(`OsaScript: ${osaScript}`);
42
- await CLIService_1.default.execCmd(osaScript);
43
- }
44
- }
45
- exports.default = ITermService;
@@ -1,19 +0,0 @@
1
- /**
2
- * A service which can be used to interact with the file system application on
3
- * the current system.
4
- */
5
- export default class OSFileSystemService {
6
- static openNugetCache(): Promise<void>;
7
- /**
8
- * Tries to add the provided snippet of text to the path provided. If the file
9
- * doesn't exist, it creates it. If the folders to the file don't exist, it
10
- * creates those. If the text already exists in the file, it does nothing.
11
- *
12
- * @param folderPath the path to the folder which contains the file that should
13
- * be updated
14
- */
15
- static findAndInsertText(folderPath: string, fileName: string, textToInsert: string): Promise<void>;
16
- private static openWindowsNugetCache;
17
- private static openMacNugetCache;
18
- }
19
- //# sourceMappingURL=OSFileSystemService.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"OSFileSystemService.d.ts","sourceRoot":"","sources":["../../../src/services/applications/OSFileSystemService.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,mBAAmB;WACzB,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAY5C;;;;;;;OAOG;WACU,iBAAiB,CAC5B,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,IAAI,CAAC;mBAsBK,qBAAqB;mBAOrB,iBAAiB;CAMvC"}
@@ -1,90 +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 promises_1 = require("fs/promises");
30
- const path_1 = __importDefault(require("path"));
31
- const core_ts_lib_1 = require("@aneuhold/core-ts-lib");
32
- const CurrentEnv_1 = __importStar(require("../../utils/CurrentEnv"));
33
- const CLIService_1 = __importDefault(require("../CLIService"));
34
- /**
35
- * A service which can be used to interact with the file system application on
36
- * the current system.
37
- */
38
- class OSFileSystemService {
39
- static async openNugetCache() {
40
- if (CurrentEnv_1.default.os === CurrentEnv_1.OperatingSystemType.Windows) {
41
- await OSFileSystemService.openWindowsNugetCache();
42
- return;
43
- }
44
- if (CurrentEnv_1.default.os === CurrentEnv_1.OperatingSystemType.MacOSX) {
45
- await OSFileSystemService.openMacNugetCache();
46
- return;
47
- }
48
- core_ts_lib_1.Logger.error('Not implemented for this OS yet.');
49
- }
50
- /**
51
- * Tries to add the provided snippet of text to the path provided. If the file
52
- * doesn't exist, it creates it. If the folders to the file don't exist, it
53
- * creates those. If the text already exists in the file, it does nothing.
54
- *
55
- * @param folderPath the path to the folder which contains the file that should
56
- * be updated
57
- */
58
- static async findAndInsertText(folderPath, fileName, textToInsert) {
59
- const filePath = path_1.default.join(folderPath, fileName);
60
- await core_ts_lib_1.FileSystemService.checkOrCreateFolder(folderPath);
61
- try {
62
- await (0, promises_1.access)(filePath);
63
- const fileContents = await (0, promises_1.readFile)(filePath);
64
- if (!fileContents.includes(textToInsert)) {
65
- await (0, promises_1.appendFile)(filePath, `\n${textToInsert}`);
66
- core_ts_lib_1.Logger.info(`Added "${textToInsert}" to "${filePath}"`);
67
- }
68
- else {
69
- core_ts_lib_1.Logger.info(`"${textToInsert}" already exists in "${filePath}"`);
70
- }
71
- }
72
- catch {
73
- core_ts_lib_1.Logger.info(`File at "${filePath}" didn't exist. Creating it now and adding "${textToInsert}" to it.`);
74
- await (0, promises_1.writeFile)(filePath, textToInsert);
75
- }
76
- }
77
- static async openWindowsNugetCache() {
78
- await Promise.all([
79
- CLIService_1.default.execCmd(`ii $HOME/localNuget`),
80
- CLIService_1.default.execCmd(`ii $HOME/.nuget/packages`)
81
- ]);
82
- }
83
- static async openMacNugetCache() {
84
- await Promise.all([
85
- CLIService_1.default.execCmd(`open $HOME/localNuget`),
86
- CLIService_1.default.execCmd(`open $HOME/.nuget/packages`)
87
- ]);
88
- }
89
- }
90
- exports.default = OSFileSystemService;
@@ -1,63 +0,0 @@
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
- ITerm2 = 1,
24
- Unknown = 2
25
- }
26
- /**
27
- * Provides information relevant to the current environment this script is
28
- * running in.
29
- */
30
- export default class CurrentEnv {
31
- /**
32
- * Returns the type of terminal the current environment is using.
33
- */
34
- static terminal(): TerminalType;
35
- /**
36
- * Returns the type of shell the current environment is using.
37
- *
38
- * This might be arbitrary because it seems that the exec command will use
39
- * whatever the default shell is or whatever is specified as the shell
40
- * option.
41
- */
42
- static shell(): Promise<ShellType>;
43
- /**
44
- * Gets all file names in the current directory.
45
- */
46
- static fileNamesInDir(): Promise<string[]>;
47
- /**
48
- * Runs the startup script for the current system. This command exits the
49
- * package.
50
- *
51
- * The startup scripts are defined in the
52
- * [dotfiles repo](https://github.com/aneuhold/dotfiles).
53
- */
54
- static runStartupScript(): Promise<void>;
55
- /**
56
- * Determines the type of operating system in the current environment.
57
- *
58
- * This looks to be O(1) complexity.
59
- */
60
- static get os(): OperatingSystemType;
61
- static folderName(): string;
62
- }
63
- //# sourceMappingURL=CurrentEnv.d.ts.map
@@ -1 +0,0 @@
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,MAAM,IAAA;IACN,OAAO,IAAA;CACR;AAED;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B;;OAEG;WACW,QAAQ,IAAI,YAAY;IAYtC;;;;;;OAMG;WACiB,KAAK,IAAI,OAAO,CAAC,SAAS,CAAC;IAyB/C;;OAEG;WACiB,cAAc,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAIvD;;;;;;OAMG;WACiB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAsBrD;;;;OAIG;IACH,WAAkB,EAAE,IAAI,mBAAmB,CAQ1C;WAEa,UAAU,IAAI,MAAM;CAGnC"}
@@ -1,137 +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.TerminalType = exports.OperatingSystemType = exports.ShellType = void 0;
7
- const promises_1 = require("fs/promises");
8
- const path_1 = __importDefault(require("path"));
9
- const core_ts_lib_1 = require("@aneuhold/core-ts-lib");
10
- const CLIService_1 = __importDefault(require("../services/CLIService"));
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 = 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 = 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["ITerm2"] = 1] = "ITerm2";
37
- TerminalType[TerminalType["Unknown"] = 2] = "Unknown";
38
- })(TerminalType || (exports.TerminalType = TerminalType = {}));
39
- /**
40
- * Provides information relevant to the current environment this script is
41
- * running in.
42
- */
43
- class CurrentEnv {
44
- /**
45
- * Returns the type of terminal the current environment is using.
46
- */
47
- static terminal() {
48
- // See https://stackoverflow.com/questions/59733731/how-to-detect-if-running-in-the-new-windows-terminal
49
- // for information on why this method was chosen.
50
- if (process.env.WT_SESSION) {
51
- return TerminalType.WindowsTerminal;
52
- }
53
- if (process.env.TERM_PROGRAM && process.env.TERM_PROGRAM === 'iTerm.app') {
54
- return TerminalType.ITerm2;
55
- }
56
- return TerminalType.Unknown;
57
- }
58
- /**
59
- * Returns the type of shell the current environment is using.
60
- *
61
- * This might be arbitrary because it seems that the exec command will use
62
- * whatever the default shell is or whatever is specified as the shell
63
- * option.
64
- */
65
- static async shell() {
66
- const currentOs = CurrentEnv.os;
67
- if (currentOs === OperatingSystemType.Windows) {
68
- // Command comes from: https://stackoverflow.com/questions/34471956/how-to-determine-if-im-in-powershell-or-cmd
69
- const { output } = await CLIService_1.default.execCmd('(dir 2>&1 *`|echo CMD);&<# rem #>echo ($PSVersionTable).PSEdition');
70
- switch (output) {
71
- case 'CMD':
72
- return ShellType.CommandPrompt;
73
- case 'Desktop':
74
- return ShellType.PowerShellDesktop;
75
- case 'Core':
76
- return ShellType.PowerShellCore;
77
- default:
78
- core_ts_lib_1.Logger.verbose.failure(`No recognizable shell returned for Windows environment.`);
79
- }
80
- }
81
- else if (currentOs === OperatingSystemType.MacOSX) {
82
- // Mighbt want to use process.env.SHELL for Linux environments
83
- }
84
- return ShellType.Unknown;
85
- }
86
- /**
87
- * Gets all file names in the current directory.
88
- */
89
- static async fileNamesInDir() {
90
- return (0, promises_1.readdir)(path_1.default.resolve('.'));
91
- }
92
- /**
93
- * Runs the startup script for the current system. This command exits the
94
- * package.
95
- *
96
- * The startup scripts are defined in the
97
- * [dotfiles repo](https://github.com/aneuhold/dotfiles).
98
- */
99
- static async runStartupScript() {
100
- let cmd = '';
101
- if (CurrentEnv.os === OperatingSystemType.Windows) {
102
- // & says to powershell that you actually want to run the script in the
103
- // quotes afterwards
104
- // Also just running the startup script for now because of some infinite
105
- // loop issues with specifying arguments
106
- cmd = `& "$Home\\startup.ps1"`;
107
- }
108
- else {
109
- cmd = 'zsh';
110
- const args = ['startup.sh'];
111
- await CLIService_1.default.spawnCmd(cmd, args, process.env.HOME);
112
- return;
113
- }
114
- core_ts_lib_1.Logger.info(`Executing the following command: "${cmd}"`);
115
- const { output } = await CLIService_1.default.execCmd(cmd);
116
- core_ts_lib_1.Logger.info(output);
117
- process.exit();
118
- }
119
- /**
120
- * Determines the type of operating system in the current environment.
121
- *
122
- * This looks to be O(1) complexity.
123
- */
124
- static get os() {
125
- if (process.platform === 'win32') {
126
- return OperatingSystemType.Windows;
127
- }
128
- if (process.platform === 'darwin') {
129
- return OperatingSystemType.MacOSX;
130
- }
131
- return OperatingSystemType.Unknown;
132
- }
133
- static folderName() {
134
- return path_1.default.basename(path_1.default.resolve('.'));
135
- }
136
- }
137
- exports.default = CurrentEnv;
@@ -1,45 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,53 +0,0 @@
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;