@aneuhold/core-ts-lib 1.0.13 → 1.0.14
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/index.d.ts +3 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -4
- package/lib/services/ConfigService/ConfigService.spec.d.ts +2 -0
- package/lib/services/ConfigService/ConfigService.spec.d.ts.map +1 -0
- package/lib/services/ConfigService/ConfigService.spec.js +28 -0
- package/lib/services/DOFunctionService.d.ts +0 -10
- package/lib/services/DOFunctionService.d.ts.map +1 -1
- package/lib/services/applications/FileSystemService/FileSystemService.d.ts +45 -0
- package/lib/services/applications/FileSystemService/FileSystemService.d.ts.map +1 -0
- package/lib/services/applications/FileSystemService/FileSystemService.js +176 -0
- package/lib/services/applications/FileSystemService/FileSystemService.spec.d.ts +2 -0
- package/lib/services/applications/FileSystemService/FileSystemService.spec.d.ts.map +1 -0
- package/lib/services/applications/FileSystemService/FileSystemService.spec.js +85 -0
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import datesAreOnSameDay from './helperFunctions/dateFunctions';
|
|
2
2
|
import sleep from './helperFunctions/sleep';
|
|
3
|
-
import getFileNameExtension from './helperFunctions/stringFunctions';
|
|
4
3
|
import ChromeService from './services/applications/ChromeService';
|
|
5
4
|
import DockerService from './services/applications/DockerService';
|
|
6
|
-
import FileSystemService from './services/applications/FileSystemService';
|
|
5
|
+
import FileSystemService from './services/applications/FileSystemService/FileSystemService';
|
|
7
6
|
import ITermService from './services/applications/ITermService';
|
|
8
7
|
import CLIService from './services/CLIService';
|
|
9
8
|
import ConfigService from './services/ConfigService/ConfigService';
|
|
10
|
-
import DOFunctionService
|
|
9
|
+
import DOFunctionService from './services/DOFunctionService';
|
|
11
10
|
import StringService from './services/StringService';
|
|
12
11
|
import CurrentEnv, { OperatingSystemType, ShellType, TerminalType } from './utils/CurrentEnv';
|
|
13
12
|
import Logger from './utils/Logger';
|
|
14
|
-
export { CLIService, StringService, CurrentEnv, ChromeService, DockerService, FileSystemService, sleep, OperatingSystemType, ShellType, Logger, TerminalType, datesAreOnSameDay,
|
|
13
|
+
export { CLIService, StringService, CurrentEnv, ChromeService, DockerService, FileSystemService, sleep, OperatingSystemType, ShellType, Logger, TerminalType, datesAreOnSameDay, ITermService, ConfigService, DOFunctionService };
|
|
15
14
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,iCAAiC,CAAC;AAChE,OAAO,KAAK,MAAM,yBAAyB,CAAC;AAC5C,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,iCAAiC,CAAC;AAChE,OAAO,KAAK,MAAM,yBAAyB,CAAC;AAC5C,OAAO,aAAa,MAAM,uCAAuC,CAAC;AAClE,OAAO,aAAa,MAAM,uCAAuC,CAAC;AAClE,OAAO,iBAAiB,MAAM,6DAA6D,CAAC;AAC5F,OAAO,YAAY,MAAM,sCAAsC,CAAC;AAChE,OAAO,UAAU,MAAM,uBAAuB,CAAC;AAC/C,OAAO,aAAa,MAAM,wCAAwC,CAAC;AACnE,OAAO,iBAAiB,MAAM,8BAA8B,CAAC;AAC7D,OAAO,aAAa,MAAM,0BAA0B,CAAC;AACrD,OAAO,UAAU,EAAE,EACjB,mBAAmB,EACnB,SAAS,EACT,YAAY,EACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,MAAM,MAAM,gBAAgB,CAAC;AAGpC,OAAO,EACL,UAAU,EACV,aAAa,EACb,UAAU,EACV,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,KAAK,EACL,mBAAmB,EACnB,SAAS,EACT,MAAM,EACN,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,iBAAiB,EAClB,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -26,18 +26,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.DOFunctionService = exports.ConfigService = exports.ITermService = exports.
|
|
29
|
+
exports.DOFunctionService = exports.ConfigService = exports.ITermService = exports.datesAreOnSameDay = exports.TerminalType = exports.Logger = exports.ShellType = exports.OperatingSystemType = exports.sleep = exports.FileSystemService = exports.DockerService = exports.ChromeService = exports.CurrentEnv = exports.StringService = exports.CLIService = void 0;
|
|
30
30
|
const dateFunctions_1 = __importDefault(require("./helperFunctions/dateFunctions"));
|
|
31
31
|
exports.datesAreOnSameDay = dateFunctions_1.default;
|
|
32
32
|
const sleep_1 = __importDefault(require("./helperFunctions/sleep"));
|
|
33
33
|
exports.sleep = sleep_1.default;
|
|
34
|
-
const stringFunctions_1 = __importDefault(require("./helperFunctions/stringFunctions"));
|
|
35
|
-
exports.getFileNameExtension = stringFunctions_1.default;
|
|
36
34
|
const ChromeService_1 = __importDefault(require("./services/applications/ChromeService"));
|
|
37
35
|
exports.ChromeService = ChromeService_1.default;
|
|
38
36
|
const DockerService_1 = __importDefault(require("./services/applications/DockerService"));
|
|
39
37
|
exports.DockerService = DockerService_1.default;
|
|
40
|
-
const FileSystemService_1 = __importDefault(require("./services/applications/FileSystemService"));
|
|
38
|
+
const FileSystemService_1 = __importDefault(require("./services/applications/FileSystemService/FileSystemService"));
|
|
41
39
|
exports.FileSystemService = FileSystemService_1.default;
|
|
42
40
|
const ITermService_1 = __importDefault(require("./services/applications/ITermService"));
|
|
43
41
|
exports.ITermService = ITermService_1.default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConfigService.spec.d.ts","sourceRoot":"","sources":["../../../src/services/ConfigService/ConfigService.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,28 @@
|
|
|
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 console_1 = require("console");
|
|
7
|
+
const ConfigService_1 = __importDefault(require("./ConfigService"));
|
|
8
|
+
const TestUtils_1 = __importDefault(require("../../utils/TestUtils"));
|
|
9
|
+
describe('ConfigService', () => {
|
|
10
|
+
describe('useConfig', () => {
|
|
11
|
+
/**
|
|
12
|
+
* Depends upon a GitHub token being available in the local environment.
|
|
13
|
+
* This will be a local `.env` file with the CONFIG_GITHUB_TOKEN variable
|
|
14
|
+
* set.
|
|
15
|
+
*/
|
|
16
|
+
it('should load configuration from GitHub', async () => {
|
|
17
|
+
const env = 'local';
|
|
18
|
+
await ConfigService_1.default.useConfig(env);
|
|
19
|
+
(0, console_1.assert)(process.env.SOME_KEY === 'SOME_VALUE');
|
|
20
|
+
});
|
|
21
|
+
it('should throw an error when loading configuration fails', async () => {
|
|
22
|
+
const env = 'invalid_env';
|
|
23
|
+
TestUtils_1.default.suppressConsole();
|
|
24
|
+
await expect(ConfigService_1.default.useConfig(env)).rejects.toThrow();
|
|
25
|
+
TestUtils_1.default.restoreConsole();
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Output from a Digital Ocean function must always be an object.
|
|
3
|
-
*/
|
|
4
|
-
export type DOFunctionOutput<TOutput extends object> = {
|
|
5
|
-
/**
|
|
6
|
-
* The body is an object, which means it will automatically be serialized to
|
|
7
|
-
* JSON and the Content-Type header will be set to application/json.
|
|
8
|
-
*/
|
|
9
|
-
body: TOutput;
|
|
10
|
-
};
|
|
11
1
|
/**
|
|
12
2
|
* A service to provide some utility common to multiple Digital Ocean functions.
|
|
13
3
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DOFunctionService.d.ts","sourceRoot":"","sources":["../../src/services/DOFunctionService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DOFunctionService.d.ts","sourceRoot":"","sources":["../../src/services/DOFunctionService.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAiB;CAAG"}
|
|
@@ -0,0 +1,45 @@
|
|
|
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 FileSystemService {
|
|
6
|
+
static openNugetCache(): Promise<void>;
|
|
7
|
+
/**
|
|
8
|
+
* Tries to add the provided snippet of text to the path provided. If the file
|
|
9
|
+
* doesn't exist, it creates it. If the folders to the file don't exist, it
|
|
10
|
+
* creates those. If the text already exists in the file, it does nothing.
|
|
11
|
+
*
|
|
12
|
+
* @param folderPath the path to the folder which contains the file that should
|
|
13
|
+
* be updated
|
|
14
|
+
*/
|
|
15
|
+
static findAndInsertText(folderPath: string, fileName: string, textToInsert: string): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Copies the contents of one folder to another folder.
|
|
18
|
+
*
|
|
19
|
+
* @param ignoreExtensions is an array with extensions that should be
|
|
20
|
+
* ignored. For example, if you want to ignore all .ts files, you would pass
|
|
21
|
+
* in ['ts'].
|
|
22
|
+
*/
|
|
23
|
+
static copyFolderContents(sourceFolderPath: string, targetFolderPath: string, ignoreExtensions?: string[]): Promise<void>;
|
|
24
|
+
static checkOrCreateFolder(folderPath: string): Promise<void>;
|
|
25
|
+
static deleteFolder(folderPath: string): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Gets all the file paths in the directory provided, including all
|
|
28
|
+
* subdirectories, as an array of strings. The returned result will include
|
|
29
|
+
* the directory path provided.
|
|
30
|
+
*
|
|
31
|
+
* If only relative file paths are needed, use {@link getAllFilePathsRelative}.
|
|
32
|
+
*/
|
|
33
|
+
static getAllFilePaths(dirPath: string): Promise<string[]>;
|
|
34
|
+
/**
|
|
35
|
+
* Gets all the file paths in the directory provided, including all
|
|
36
|
+
* subdirectories, as an array of strings. The returned result will not
|
|
37
|
+
* include the directory path provided.
|
|
38
|
+
*
|
|
39
|
+
* If absolute file paths are needed, use {@link getAllFilePaths}.
|
|
40
|
+
*/
|
|
41
|
+
static getAllFilePathsRelative(dirPath: string): Promise<string[]>;
|
|
42
|
+
private static openWindowsNugetCache;
|
|
43
|
+
private static openMacNugetCache;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=FileSystemService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileSystemService.d.ts","sourceRoot":"","sources":["../../../../src/services/applications/FileSystemService/FileSystemService.ts"],"names":[],"mappings":"AAiBA;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAiB;WACvB,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;IAsBhB;;;;;;OAMG;WACU,kBAAkB,CAC7B,gBAAgB,EAAE,MAAM,EACxB,gBAAgB,EAAE,MAAM,EACxB,gBAAgB,CAAC,EAAE,MAAM,EAAE,GAC1B,OAAO,CAAC,IAAI,CAAC;WAoCH,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;WAWtD,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAU5D;;;;;;OAMG;WACU,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAoBhE;;;;;;OAMG;WACU,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;mBAOnD,qBAAqB;mBAOrB,iBAAiB;CAMvC"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const promises_1 = require("fs/promises");
|
|
30
|
+
const path_1 = __importDefault(require("path"));
|
|
31
|
+
const CurrentEnv_1 = __importStar(require("../../../utils/CurrentEnv"));
|
|
32
|
+
const Logger_1 = __importDefault(require("../../../utils/Logger"));
|
|
33
|
+
const CLIService_1 = __importDefault(require("../../CLIService"));
|
|
34
|
+
const StringService_1 = __importDefault(require("../../StringService"));
|
|
35
|
+
/**
|
|
36
|
+
* A service which can be used to interact with the file system application on
|
|
37
|
+
* the current system.
|
|
38
|
+
*/
|
|
39
|
+
class FileSystemService {
|
|
40
|
+
static async openNugetCache() {
|
|
41
|
+
if (CurrentEnv_1.default.os === CurrentEnv_1.OperatingSystemType.Windows) {
|
|
42
|
+
await FileSystemService.openWindowsNugetCache();
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (CurrentEnv_1.default.os === CurrentEnv_1.OperatingSystemType.MacOSX) {
|
|
46
|
+
await FileSystemService.openMacNugetCache();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
Logger_1.default.error('Not implemented for this OS yet.');
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Tries to add the provided snippet of text to the path provided. If the file
|
|
53
|
+
* doesn't exist, it creates it. If the folders to the file don't exist, it
|
|
54
|
+
* creates those. If the text already exists in the file, it does nothing.
|
|
55
|
+
*
|
|
56
|
+
* @param folderPath the path to the folder which contains the file that should
|
|
57
|
+
* be updated
|
|
58
|
+
*/
|
|
59
|
+
static async findAndInsertText(folderPath, fileName, textToInsert) {
|
|
60
|
+
const filePath = path_1.default.join(folderPath, fileName);
|
|
61
|
+
await FileSystemService.checkOrCreateFolder(folderPath);
|
|
62
|
+
try {
|
|
63
|
+
await (0, promises_1.access)(filePath);
|
|
64
|
+
const fileContents = await (0, promises_1.readFile)(filePath);
|
|
65
|
+
if (!fileContents.includes(textToInsert)) {
|
|
66
|
+
await (0, promises_1.appendFile)(filePath, `\n${textToInsert}`);
|
|
67
|
+
Logger_1.default.info(`Added "${textToInsert}" to "${filePath}"`);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
Logger_1.default.info(`"${textToInsert}" already exists in "${filePath}"`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
Logger_1.default.info(`File at "${filePath}" didn't exist. Creating it now and adding "${textToInsert}" to it.`);
|
|
75
|
+
await (0, promises_1.writeFile)(filePath, textToInsert);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Copies the contents of one folder to another folder.
|
|
80
|
+
*
|
|
81
|
+
* @param ignoreExtensions is an array with extensions that should be
|
|
82
|
+
* ignored. For example, if you want to ignore all .ts files, you would pass
|
|
83
|
+
* in ['ts'].
|
|
84
|
+
*/
|
|
85
|
+
static async copyFolderContents(sourceFolderPath, targetFolderPath, ignoreExtensions) {
|
|
86
|
+
// Check if the source directory exists first
|
|
87
|
+
try {
|
|
88
|
+
await (0, promises_1.access)(sourceFolderPath);
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
Logger_1.default.error(`Source directory "${sourceFolderPath}" does not exist.`);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
await FileSystemService.checkOrCreateFolder(targetFolderPath);
|
|
95
|
+
// Get the files in the source directory
|
|
96
|
+
const sourceFilePaths = await FileSystemService.getAllFilePathsRelative(sourceFolderPath);
|
|
97
|
+
// console.log(sourceFilePaths);
|
|
98
|
+
await Promise.all(sourceFilePaths.map(async (sourceFilePath) => {
|
|
99
|
+
const sourceFile = path_1.default.join(sourceFolderPath, sourceFilePath);
|
|
100
|
+
const targetFile = path_1.default.join(targetFolderPath, sourceFilePath);
|
|
101
|
+
const sourceFileExtension = StringService_1.default.getFileNameExtension(sourceFile);
|
|
102
|
+
if (sourceFileExtension &&
|
|
103
|
+
ignoreExtensions?.includes(sourceFileExtension)) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
await (0, promises_1.cp)(sourceFile, targetFile, { recursive: true });
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
static async checkOrCreateFolder(folderPath) {
|
|
110
|
+
try {
|
|
111
|
+
await (0, promises_1.access)(folderPath);
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
Logger_1.default.verbose.info(`Directory "${folderPath}" does not exist. Creating it now...`);
|
|
115
|
+
await (0, promises_1.mkdir)(folderPath, { recursive: true });
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
static async deleteFolder(folderPath) {
|
|
119
|
+
try {
|
|
120
|
+
await (0, promises_1.access)(folderPath);
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
Logger_1.default.error(`Directory "${folderPath}" does not exist.`);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
await (0, promises_1.rm)(folderPath, { recursive: true });
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Gets all the file paths in the directory provided, including all
|
|
130
|
+
* subdirectories, as an array of strings. The returned result will include
|
|
131
|
+
* the directory path provided.
|
|
132
|
+
*
|
|
133
|
+
* If only relative file paths are needed, use {@link getAllFilePathsRelative}.
|
|
134
|
+
*/
|
|
135
|
+
static async getAllFilePaths(dirPath) {
|
|
136
|
+
const filePaths = [];
|
|
137
|
+
const fileOrFolderNames = await (0, promises_1.readdir)(dirPath);
|
|
138
|
+
await Promise.all(fileOrFolderNames.map(async (fileOrFolder) => {
|
|
139
|
+
const absolutePath = path_1.default.join(dirPath, fileOrFolder);
|
|
140
|
+
const fileStat = await (0, promises_1.stat)(absolutePath);
|
|
141
|
+
if (fileStat.isDirectory()) {
|
|
142
|
+
filePaths.push(...(await this.getAllFilePaths(absolutePath)));
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
filePaths.push(absolutePath);
|
|
146
|
+
}
|
|
147
|
+
}));
|
|
148
|
+
return filePaths;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Gets all the file paths in the directory provided, including all
|
|
152
|
+
* subdirectories, as an array of strings. The returned result will not
|
|
153
|
+
* include the directory path provided.
|
|
154
|
+
*
|
|
155
|
+
* If absolute file paths are needed, use {@link getAllFilePaths}.
|
|
156
|
+
*/
|
|
157
|
+
static async getAllFilePathsRelative(dirPath) {
|
|
158
|
+
const filePaths = await this.getAllFilePaths(dirPath);
|
|
159
|
+
return filePaths.map((filePath) => {
|
|
160
|
+
return filePath.replace(dirPath, '');
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
static async openWindowsNugetCache() {
|
|
164
|
+
await Promise.all([
|
|
165
|
+
CLIService_1.default.execCmd(`ii $HOME/localNuget`),
|
|
166
|
+
CLIService_1.default.execCmd(`ii $HOME/.nuget/packages`)
|
|
167
|
+
]);
|
|
168
|
+
}
|
|
169
|
+
static async openMacNugetCache() {
|
|
170
|
+
await Promise.all([
|
|
171
|
+
CLIService_1.default.execCmd(`open $HOME/localNuget`),
|
|
172
|
+
CLIService_1.default.execCmd(`open $HOME/.nuget/packages`)
|
|
173
|
+
]);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
exports.default = FileSystemService;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileSystemService.spec.d.ts","sourceRoot":"","sources":["../../../../src/services/applications/FileSystemService/FileSystemService.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,85 @@
|
|
|
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 path_1 = __importDefault(require("path"));
|
|
7
|
+
const promises_1 = require("fs/promises");
|
|
8
|
+
const FileSystemService_1 = __importDefault(require("./FileSystemService"));
|
|
9
|
+
const TEST_FOLDER_NAME = '__fileSystemService-tests__';
|
|
10
|
+
describe('FileSystemService', () => {
|
|
11
|
+
afterAll(async () => {
|
|
12
|
+
await deleteTestFolder();
|
|
13
|
+
});
|
|
14
|
+
describe('copyFolderContents', () => {
|
|
15
|
+
it('should successfully copy all contents when target folder doesnt exist', async () => {
|
|
16
|
+
// Make a test folder with a folder and a couple files in it
|
|
17
|
+
const testName = 'copyFolderContents-1';
|
|
18
|
+
const sourceFolderName = `${testName}-source`;
|
|
19
|
+
const sourceFolderPath = await createTestFolder(sourceFolderName);
|
|
20
|
+
await createTestFiles(sourceFolderPath, {
|
|
21
|
+
'file1.txt': 'test text',
|
|
22
|
+
'file2.txt': 'test text',
|
|
23
|
+
subFolder: {
|
|
24
|
+
'subFile1.txt': 'sub test text',
|
|
25
|
+
'subFile2.txt': 'sub test text'
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
const targetFolderPath = path_1.default.join(TEST_FOLDER_NAME, `${testName}-target`);
|
|
29
|
+
// Execute
|
|
30
|
+
await FileSystemService_1.default.copyFolderContents(sourceFolderPath, targetFolderPath);
|
|
31
|
+
// Assert
|
|
32
|
+
const expectedContents = await FileSystemService_1.default.getAllFilePathsRelative(sourceFolderPath);
|
|
33
|
+
const actualContents = await FileSystemService_1.default.getAllFilePathsRelative(targetFolderPath);
|
|
34
|
+
expect(actualContents).toEqual(expectedContents);
|
|
35
|
+
});
|
|
36
|
+
it('should successfully copy only files that arent ignored', async () => {
|
|
37
|
+
// Make a test folder with a folder and a couple files in it
|
|
38
|
+
const testName = 'copyFolderContents-2';
|
|
39
|
+
const sourceFolderName = `${testName}-source`;
|
|
40
|
+
const sourceFolderPath = await createTestFolder(sourceFolderName);
|
|
41
|
+
await createTestFiles(sourceFolderPath, {
|
|
42
|
+
'file1.txt': 'test text',
|
|
43
|
+
'file2.txt': 'test text',
|
|
44
|
+
subFolder: {
|
|
45
|
+
'subFile1.txt': 'sub test text',
|
|
46
|
+
'subFile2.txt': 'sub test text'
|
|
47
|
+
},
|
|
48
|
+
javascript: {
|
|
49
|
+
'file1.js': 'test text',
|
|
50
|
+
'file2.js': 'test text'
|
|
51
|
+
},
|
|
52
|
+
typescript: {
|
|
53
|
+
'file1.ts': 'test text',
|
|
54
|
+
'file2.ts': 'test text'
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
const targetFolderPath = path_1.default.join(TEST_FOLDER_NAME, `${testName}-target`);
|
|
58
|
+
// Execute
|
|
59
|
+
await FileSystemService_1.default.copyFolderContents(sourceFolderPath, targetFolderPath, ['ts']);
|
|
60
|
+
// Assert
|
|
61
|
+
const expectedContents = (await FileSystemService_1.default.getAllFilePathsRelative(sourceFolderPath)).filter((sourceFilePath) => !sourceFilePath.endsWith('.ts'));
|
|
62
|
+
const actualContents = await FileSystemService_1.default.getAllFilePathsRelative(targetFolderPath);
|
|
63
|
+
expect(actualContents).toEqual(expectedContents);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
async function createTestFiles(folderPath, fileStructure) {
|
|
68
|
+
await FileSystemService_1.default.checkOrCreateFolder(folderPath);
|
|
69
|
+
await Promise.all(Object.entries(fileStructure).map(async ([key, value]) => {
|
|
70
|
+
if (typeof value === 'string') {
|
|
71
|
+
await (0, promises_1.writeFile)(path_1.default.join(folderPath, key), value);
|
|
72
|
+
}
|
|
73
|
+
else if (typeof value === 'object') {
|
|
74
|
+
await createTestFiles(path_1.default.join(folderPath, key), value);
|
|
75
|
+
}
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
async function createTestFolder(folderName) {
|
|
79
|
+
const testFolderPath = path_1.default.join(TEST_FOLDER_NAME, folderName);
|
|
80
|
+
await FileSystemService_1.default.checkOrCreateFolder(testFolderPath);
|
|
81
|
+
return testFolderPath;
|
|
82
|
+
}
|
|
83
|
+
async function deleteTestFolder() {
|
|
84
|
+
await FileSystemService_1.default.deleteFolder(TEST_FOLDER_NAME);
|
|
85
|
+
}
|