@aneuhold/core-ts-lib 2.2.2 → 2.2.4
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/LICENSE +1 -1
- package/lib/services/FileSystemService/FileSystemService.d.ts +11 -3
- package/lib/services/FileSystemService/FileSystemService.d.ts.map +1 -1
- package/lib/services/FileSystemService/FileSystemService.js +25 -7
- package/lib/services/FileSystemService/FileSystemService.js.map +1 -1
- package/lib/services/FileSystemService/FileSystemService.ts +31 -9
- package/package.json +5 -6
- package/lib/services/DateService/DateService.spec.ts +0 -98
- package/lib/services/FileSystemService/FileSystemService.spec.ts +0 -133
package/LICENSE
CHANGED
|
@@ -21,9 +21,17 @@ export default class FileSystemService {
|
|
|
21
21
|
* @param targetFolderPath
|
|
22
22
|
* @param ignoreExtensions is an array with extensions that should be
|
|
23
23
|
* ignored. For example, if you want to ignore all .ts files, you would pass
|
|
24
|
-
* in ['ts'].
|
|
24
|
+
* in ['.ts']. Multi-part extensions like '.spec.ts' are also supported.
|
|
25
25
|
*/
|
|
26
26
|
static copyFolderContents(sourceFolderPath: string, targetFolderPath: string, ignoreExtensions?: string[]): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Checks if a file should be ignored based on the provided extensions.
|
|
29
|
+
* Supports both simple extensions (e.g., '.ts') and multi-part extensions (e.g., '.spec.ts').
|
|
30
|
+
*
|
|
31
|
+
* @param filePath the path to the file to check
|
|
32
|
+
* @param ignoreExtensions array of extensions to ignore
|
|
33
|
+
*/
|
|
34
|
+
private static shouldIgnoreFile;
|
|
27
35
|
static checkOrCreateFolder(folderPath: string): Promise<void>;
|
|
28
36
|
static deleteFolder(folderPath: string): Promise<void>;
|
|
29
37
|
/**
|
|
@@ -33,7 +41,7 @@ export default class FileSystemService {
|
|
|
33
41
|
*
|
|
34
42
|
* If only relative file paths are needed, use {@link getAllFilePathsRelative}.
|
|
35
43
|
*
|
|
36
|
-
* @param dirPath
|
|
44
|
+
* @param dirPath the directory path to search for files in
|
|
37
45
|
*/
|
|
38
46
|
static getAllFilePaths(dirPath: string): Promise<string[]>;
|
|
39
47
|
/**
|
|
@@ -43,7 +51,7 @@ export default class FileSystemService {
|
|
|
43
51
|
*
|
|
44
52
|
* If absolute file paths are needed, use {@link getAllFilePaths}.
|
|
45
53
|
*
|
|
46
|
-
* @param dirPath
|
|
54
|
+
* @param dirPath the directory path to search for files in
|
|
47
55
|
*/
|
|
48
56
|
static getAllFilePathsRelative(dirPath: string): Promise<string[]>;
|
|
49
57
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileSystemService.d.ts","sourceRoot":"","sources":["../../../src/services/FileSystemService/FileSystemService.ts"],"names":[],"mappings":"AAoBA;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC;;;;;;;;;OASG;WACU,iBAAiB,CAC5B,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,IAAI,CAAC;IAsBhB;;;;;;;;OAQG;WACU,kBAAkB,CAC7B,gBAAgB,EAAE,MAAM,EACxB,gBAAgB,EAAE,MAAM,EACxB,gBAAgB,CAAC,EAAE,MAAM,EAAE,GAC1B,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"FileSystemService.d.ts","sourceRoot":"","sources":["../../../src/services/FileSystemService/FileSystemService.ts"],"names":[],"mappings":"AAoBA;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC;;;;;;;;;OASG;WACU,iBAAiB,CAC5B,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,IAAI,CAAC;IAsBhB;;;;;;;;OAQG;WACU,kBAAkB,CAC7B,gBAAgB,EAAE,MAAM,EACxB,gBAAgB,EAAE,MAAM,EACxB,gBAAgB,CAAC,EAAE,MAAM,EAAE,GAC1B,OAAO,CAAC,IAAI,CAAC;IAgChB;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;WAkBlB,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;WAWtD,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAU5D;;;;;;;;OAQG;WACU,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAoBhE;;;;;;;;OAQG;WACU,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAOxE;;;;;OAKG;WACU,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC;IAYlD;;;;;;;;;OASG;WACU,cAAc,CACzB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAUzB;;;;;;;;OAQG;WACU,kBAAkB,CAC7B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,EAAE,CAAC;IASpB;;;;;;;OAOG;mBACkB,qBAAqB;CA0C3C"}
|
|
@@ -47,7 +47,7 @@ export default class FileSystemService {
|
|
|
47
47
|
* @param targetFolderPath
|
|
48
48
|
* @param ignoreExtensions is an array with extensions that should be
|
|
49
49
|
* ignored. For example, if you want to ignore all .ts files, you would pass
|
|
50
|
-
* in ['ts'].
|
|
50
|
+
* in ['.ts']. Multi-part extensions like '.spec.ts' are also supported.
|
|
51
51
|
*/
|
|
52
52
|
static async copyFolderContents(sourceFolderPath, targetFolderPath, ignoreExtensions) {
|
|
53
53
|
// Check if the source directory exists first
|
|
@@ -61,18 +61,36 @@ export default class FileSystemService {
|
|
|
61
61
|
await FileSystemService.checkOrCreateFolder(targetFolderPath);
|
|
62
62
|
// Get the files in the source directory
|
|
63
63
|
const sourceFilePaths = await FileSystemService.getAllFilePathsRelative(sourceFolderPath);
|
|
64
|
-
// console.log(sourceFilePaths);
|
|
65
64
|
await Promise.all(sourceFilePaths.map(async (sourceFilePath) => {
|
|
66
65
|
const sourceFile = path.join(sourceFolderPath, sourceFilePath);
|
|
67
66
|
const targetFile = path.join(targetFolderPath, sourceFilePath);
|
|
68
|
-
|
|
69
|
-
if (
|
|
70
|
-
ignoreExtensions
|
|
67
|
+
// Check if the file should be ignored based on extensions
|
|
68
|
+
if (ignoreExtensions &&
|
|
69
|
+
FileSystemService.shouldIgnoreFile(sourceFile, ignoreExtensions)) {
|
|
71
70
|
return;
|
|
72
71
|
}
|
|
73
72
|
await cp(sourceFile, targetFile, { recursive: true });
|
|
74
73
|
}));
|
|
75
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Checks if a file should be ignored based on the provided extensions.
|
|
77
|
+
* Supports both simple extensions (e.g., '.ts') and multi-part extensions (e.g., '.spec.ts').
|
|
78
|
+
*
|
|
79
|
+
* @param filePath the path to the file to check
|
|
80
|
+
* @param ignoreExtensions array of extensions to ignore
|
|
81
|
+
*/
|
|
82
|
+
static shouldIgnoreFile(filePath, ignoreExtensions) {
|
|
83
|
+
const fileName = path.basename(filePath);
|
|
84
|
+
return ignoreExtensions.some((extension) => {
|
|
85
|
+
// Handle multi-part extensions like '.spec.ts'
|
|
86
|
+
if (extension.includes('.', 1)) {
|
|
87
|
+
return fileName.endsWith(extension);
|
|
88
|
+
}
|
|
89
|
+
// Handle simple extensions like '.ts'
|
|
90
|
+
const fileExtension = StringService.getFileNameExtension(filePath);
|
|
91
|
+
return fileExtension === extension;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
76
94
|
static async checkOrCreateFolder(folderPath) {
|
|
77
95
|
try {
|
|
78
96
|
await access(folderPath);
|
|
@@ -99,7 +117,7 @@ export default class FileSystemService {
|
|
|
99
117
|
*
|
|
100
118
|
* If only relative file paths are needed, use {@link getAllFilePathsRelative}.
|
|
101
119
|
*
|
|
102
|
-
* @param dirPath
|
|
120
|
+
* @param dirPath the directory path to search for files in
|
|
103
121
|
*/
|
|
104
122
|
static async getAllFilePaths(dirPath) {
|
|
105
123
|
const filePaths = [];
|
|
@@ -123,7 +141,7 @@ export default class FileSystemService {
|
|
|
123
141
|
*
|
|
124
142
|
* If absolute file paths are needed, use {@link getAllFilePaths}.
|
|
125
143
|
*
|
|
126
|
-
* @param dirPath
|
|
144
|
+
* @param dirPath the directory path to search for files in
|
|
127
145
|
*/
|
|
128
146
|
static async getAllFilePathsRelative(dirPath) {
|
|
129
147
|
const filePaths = await this.getAllFilePaths(dirPath);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileSystemService.js","sourceRoot":"","sources":["../../../src/services/FileSystemService/FileSystemService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EACL,MAAM,EACN,UAAU,EACV,EAAE,EACF,KAAK,EACL,QAAQ,EACR,OAAO,EACP,EAAE,EACF,IAAI,EACJ,SAAS,EACV,MAAM,aAAa,CAAC;AACrB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,UAAU,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,aAAa,MAAM,qBAAqB,CAAC;AAEhD,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;AAElC;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC;;;;;;;;;OASG;IACH,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAC5B,UAAkB,EAClB,QAAgB,EAChB,YAAoB;QAEpB,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QAEjD,M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,CAAC;gBACvB,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACvB,IAAI,SAAS,EAAE,CAAC;oBACd,OAAO,OAAO,CAAC;gBACjB,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,yCAAyC;YAC3C,CAAC;YAED,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YAC3C,IAAI,SAAS,KAAK,UAAU,EAAE,CAAC;gBAC7B,6BAA6B;gBAC7B,MAAM;YACR,CAAC;YACD,UAAU,GAAG,SAAS,CAAC;QACzB,CAAC;QAED,wCAAwC;QACxC,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QACjD,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAC;YACvB,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACzB,CAAC;QAAC,MAAM,CAAC;YACP,iBAAiB;QACnB,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
|
|
@@ -66,7 +66,7 @@ export default class FileSystemService {
|
|
|
66
66
|
* @param targetFolderPath
|
|
67
67
|
* @param ignoreExtensions is an array with extensions that should be
|
|
68
68
|
* ignored. For example, if you want to ignore all .ts files, you would pass
|
|
69
|
-
* in ['ts'].
|
|
69
|
+
* in ['.ts']. Multi-part extensions like '.spec.ts' are also supported.
|
|
70
70
|
*/
|
|
71
71
|
static async copyFolderContents(
|
|
72
72
|
sourceFolderPath: string,
|
|
@@ -86,18 +86,15 @@ export default class FileSystemService {
|
|
|
86
86
|
const sourceFilePaths =
|
|
87
87
|
await FileSystemService.getAllFilePathsRelative(sourceFolderPath);
|
|
88
88
|
|
|
89
|
-
// console.log(sourceFilePaths);
|
|
90
|
-
|
|
91
89
|
await Promise.all(
|
|
92
90
|
sourceFilePaths.map(async (sourceFilePath) => {
|
|
93
91
|
const sourceFile = path.join(sourceFolderPath, sourceFilePath);
|
|
94
92
|
const targetFile = path.join(targetFolderPath, sourceFilePath);
|
|
95
93
|
|
|
96
|
-
|
|
97
|
-
StringService.getFileNameExtension(sourceFile);
|
|
94
|
+
// Check if the file should be ignored based on extensions
|
|
98
95
|
if (
|
|
99
|
-
|
|
100
|
-
ignoreExtensions
|
|
96
|
+
ignoreExtensions &&
|
|
97
|
+
FileSystemService.shouldIgnoreFile(sourceFile, ignoreExtensions)
|
|
101
98
|
) {
|
|
102
99
|
return;
|
|
103
100
|
}
|
|
@@ -107,6 +104,31 @@ export default class FileSystemService {
|
|
|
107
104
|
);
|
|
108
105
|
}
|
|
109
106
|
|
|
107
|
+
/**
|
|
108
|
+
* Checks if a file should be ignored based on the provided extensions.
|
|
109
|
+
* Supports both simple extensions (e.g., '.ts') and multi-part extensions (e.g., '.spec.ts').
|
|
110
|
+
*
|
|
111
|
+
* @param filePath the path to the file to check
|
|
112
|
+
* @param ignoreExtensions array of extensions to ignore
|
|
113
|
+
*/
|
|
114
|
+
private static shouldIgnoreFile(
|
|
115
|
+
filePath: string,
|
|
116
|
+
ignoreExtensions: string[]
|
|
117
|
+
): boolean {
|
|
118
|
+
const fileName = path.basename(filePath);
|
|
119
|
+
|
|
120
|
+
return ignoreExtensions.some((extension) => {
|
|
121
|
+
// Handle multi-part extensions like '.spec.ts'
|
|
122
|
+
if (extension.includes('.', 1)) {
|
|
123
|
+
return fileName.endsWith(extension);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Handle simple extensions like '.ts'
|
|
127
|
+
const fileExtension = StringService.getFileNameExtension(filePath);
|
|
128
|
+
return fileExtension === extension;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
110
132
|
static async checkOrCreateFolder(folderPath: string): Promise<void> {
|
|
111
133
|
try {
|
|
112
134
|
await access(folderPath);
|
|
@@ -135,7 +157,7 @@ export default class FileSystemService {
|
|
|
135
157
|
*
|
|
136
158
|
* If only relative file paths are needed, use {@link getAllFilePathsRelative}.
|
|
137
159
|
*
|
|
138
|
-
* @param dirPath
|
|
160
|
+
* @param dirPath the directory path to search for files in
|
|
139
161
|
*/
|
|
140
162
|
static async getAllFilePaths(dirPath: string): Promise<string[]> {
|
|
141
163
|
const filePaths: string[] = [];
|
|
@@ -164,7 +186,7 @@ export default class FileSystemService {
|
|
|
164
186
|
*
|
|
165
187
|
* If absolute file paths are needed, use {@link getAllFilePaths}.
|
|
166
188
|
*
|
|
167
|
-
* @param dirPath
|
|
189
|
+
* @param dirPath the directory path to search for files in
|
|
168
190
|
*/
|
|
169
191
|
static async getAllFilePathsRelative(dirPath: string): Promise<string[]> {
|
|
170
192
|
const filePaths = await this.getAllFilePaths(dirPath);
|
package/package.json
CHANGED
|
@@ -2,18 +2,19 @@
|
|
|
2
2
|
"name": "@aneuhold/core-ts-lib",
|
|
3
3
|
"author": "Anton G. Neuhold Jr.",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "2.2.
|
|
5
|
+
"version": "2.2.4",
|
|
6
6
|
"description": "A core library for all of my TypeScript projects",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "rimraf lib && tsc --project tsconfig.build.json && tsx ./scripts/copyTsFiles.ts",
|
|
10
10
|
"watch": "nodemon --ignore lib/ -e ts --exec \"tsc --project tsconfig.build.json && tsx ./scripts/copyTsFiles.ts\"",
|
|
11
11
|
"lint": "eslint",
|
|
12
|
-
"test": "
|
|
12
|
+
"test": "vitest run",
|
|
13
13
|
"jsr:validate": "tsx ./scripts/validateJsrPublish.ts",
|
|
14
14
|
"npm:validate": "tsx ./scripts/validateNpmPublish.ts",
|
|
15
15
|
"checkAll": "pnpm build && pnpm lint && pnpm test && pnpm jsr:validate",
|
|
16
16
|
"jsr:publish": "tsx ./scripts/publishJsr.ts",
|
|
17
|
+
"npm:publish": "npm publish --access public",
|
|
17
18
|
"upgrade:all": "pnpm up"
|
|
18
19
|
},
|
|
19
20
|
"main": "lib/index.js",
|
|
@@ -41,16 +42,14 @@
|
|
|
41
42
|
"Node.js"
|
|
42
43
|
],
|
|
43
44
|
"devDependencies": {
|
|
44
|
-
"@types/jest": "^29.5.14",
|
|
45
45
|
"@types/node": "^22.15.3",
|
|
46
46
|
"eslint": "^9.26.0",
|
|
47
|
-
"jest": "^29.7.*",
|
|
48
47
|
"jsr": "*",
|
|
49
48
|
"nodemon": "^3.1.10",
|
|
50
49
|
"prettier": "^3.5.3",
|
|
51
50
|
"rimraf": "^6.0.1",
|
|
52
|
-
"ts-jest": "^29.3.2",
|
|
53
51
|
"tsx": "^4.19.4",
|
|
54
|
-
"typescript": "~5.8.3"
|
|
52
|
+
"typescript": "~5.8.3",
|
|
53
|
+
"vitest": "^3.2.3"
|
|
55
54
|
}
|
|
56
55
|
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import DateService from './DateService.js';
|
|
2
|
-
|
|
3
|
-
describe('DateService', () => {
|
|
4
|
-
describe('addWeeks', () => {
|
|
5
|
-
it('should successfully add weeks to a date', () => {
|
|
6
|
-
const result = DateService.addWeeks(new Date(2024, 0, 1), 1);
|
|
7
|
-
expect(result).toEqual(new Date(2024, 0, 8));
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('should successfully add weeks to a date that crosses months', () => {
|
|
11
|
-
const result = DateService.addWeeks(new Date(2024, 0, 23), 2);
|
|
12
|
-
expect(result).toEqual(new Date(2024, 1, 6));
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('should successfully add weeks to a date that crosses years', () => {
|
|
16
|
-
const result = DateService.addWeeks(new Date(2024, 11, 25), 1);
|
|
17
|
-
expect(result).toEqual(new Date(2025, 0, 1));
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
describe('getWeekOfMonth', () => {
|
|
22
|
-
it('should successfully get the week of month for a date', () => {
|
|
23
|
-
const result = DateService.getWeekOfMonth(new Date(2024, 0, 14));
|
|
24
|
-
expect(result).toEqual(3);
|
|
25
|
-
|
|
26
|
-
const result2 = DateService.getWeekOfMonth(new Date(2024, 0, 1));
|
|
27
|
-
expect(result2).toEqual(1);
|
|
28
|
-
|
|
29
|
-
const result3 = DateService.getWeekOfMonth(new Date(2024, 0, 31));
|
|
30
|
-
expect(result3).toEqual(5);
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
describe('getWeekDayOfXWeekOfMonth', () => {
|
|
35
|
-
it('should successfully get the 2nd monday of January 2024', () => {
|
|
36
|
-
const result = DateService.getWeekDayOfXWeekOfMonth(
|
|
37
|
-
new Date(2024, 0, 1),
|
|
38
|
-
1,
|
|
39
|
-
2
|
|
40
|
-
);
|
|
41
|
-
expect(result).toEqual(new Date(2024, 0, 8));
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('should successfully get the 3rd monday of January 2024', () => {
|
|
45
|
-
const result = DateService.getWeekDayOfXWeekOfMonth(
|
|
46
|
-
new Date(2024, 0, 1),
|
|
47
|
-
1,
|
|
48
|
-
3
|
|
49
|
-
);
|
|
50
|
-
expect(result).toEqual(new Date(2024, 0, 15));
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('should successfully get the 3rd tuesday of January 2024', () => {
|
|
54
|
-
const result = DateService.getWeekDayOfXWeekOfMonth(
|
|
55
|
-
new Date(2024, 0, 1),
|
|
56
|
-
2,
|
|
57
|
-
3
|
|
58
|
-
);
|
|
59
|
-
expect(result).toEqual(new Date(2024, 0, 16));
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('should successfully get the 1st Saturday of January 2024', () => {
|
|
63
|
-
const result = DateService.getWeekDayOfXWeekOfMonth(
|
|
64
|
-
new Date(2024, 0, 1),
|
|
65
|
-
6,
|
|
66
|
-
1
|
|
67
|
-
);
|
|
68
|
-
expect(result).toEqual(new Date(2024, 0, 6));
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('should successfully get the 1st sunday of January 2024', () => {
|
|
72
|
-
const result = DateService.getWeekDayOfXWeekOfMonth(
|
|
73
|
-
new Date(2024, 0, 1),
|
|
74
|
-
0,
|
|
75
|
-
1
|
|
76
|
-
);
|
|
77
|
-
expect(result).toEqual(new Date(2024, 0, 7));
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('should successfully get the last sunday of January 2024', () => {
|
|
81
|
-
const result = DateService.getWeekDayOfXWeekOfMonth(
|
|
82
|
-
new Date(2024, 0, 1),
|
|
83
|
-
0,
|
|
84
|
-
'last'
|
|
85
|
-
);
|
|
86
|
-
expect(result).toEqual(new Date(2024, 0, 28));
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('should return null if the week and day do not exist', () => {
|
|
90
|
-
const result = DateService.getWeekDayOfXWeekOfMonth(
|
|
91
|
-
new Date(2024, 0, 1),
|
|
92
|
-
0,
|
|
93
|
-
5
|
|
94
|
-
);
|
|
95
|
-
expect(result).toEqual(null);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
});
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { writeFile } from 'fs/promises';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import FileSystemService from './FileSystemService.js';
|
|
4
|
-
|
|
5
|
-
const TEST_FOLDER_NAME = '__fileSystemService-tests__';
|
|
6
|
-
|
|
7
|
-
describe('FileSystemService', () => {
|
|
8
|
-
afterAll(async () => {
|
|
9
|
-
await deleteTestFolder();
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
describe('copyFolderContents', () => {
|
|
13
|
-
it('should successfully copy all contents when target folder doesnt exist', async () => {
|
|
14
|
-
// Make a test folder with a folder and a couple files in it
|
|
15
|
-
const testName = 'copyFolderContents-1';
|
|
16
|
-
const sourceFolderName = `${testName}-source`;
|
|
17
|
-
const sourceFolderPath = await createTestFolder(sourceFolderName);
|
|
18
|
-
await createTestFiles(sourceFolderPath, {
|
|
19
|
-
'file1.txt': 'test text',
|
|
20
|
-
'file2.txt': 'test text',
|
|
21
|
-
subFolder: {
|
|
22
|
-
'subFile1.txt': 'sub test text',
|
|
23
|
-
'subFile2.txt': 'sub test text'
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
const targetFolderPath = path.join(
|
|
28
|
-
TEST_FOLDER_NAME,
|
|
29
|
-
`${testName}-target`
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
// Execute
|
|
33
|
-
await FileSystemService.copyFolderContents(
|
|
34
|
-
sourceFolderPath,
|
|
35
|
-
targetFolderPath
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
// Assert
|
|
39
|
-
const expectedContents = (
|
|
40
|
-
await FileSystemService.getAllFilePathsRelative(sourceFolderPath)
|
|
41
|
-
).sort();
|
|
42
|
-
const actualContents = (
|
|
43
|
-
await FileSystemService.getAllFilePathsRelative(targetFolderPath)
|
|
44
|
-
).sort();
|
|
45
|
-
expect(actualContents).toEqual(expectedContents);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('should successfully copy only files that arent ignored', async () => {
|
|
49
|
-
// Make a test folder with a folder and a couple files in it
|
|
50
|
-
const testName = 'copyFolderContents-2';
|
|
51
|
-
const sourceFolderName = `${testName}-source`;
|
|
52
|
-
const sourceFolderPath = await createTestFolder(sourceFolderName);
|
|
53
|
-
await createTestFiles(sourceFolderPath, {
|
|
54
|
-
'file1.txt': 'test text',
|
|
55
|
-
'file2.txt': 'test text',
|
|
56
|
-
subFolder: {
|
|
57
|
-
'subFile1.txt': 'sub test text',
|
|
58
|
-
'subFile2.txt': 'sub test text'
|
|
59
|
-
},
|
|
60
|
-
javascript: {
|
|
61
|
-
'file1.js': 'test text',
|
|
62
|
-
'file2.js': 'test text'
|
|
63
|
-
},
|
|
64
|
-
typescript: {
|
|
65
|
-
'file1.ts': 'test text',
|
|
66
|
-
'file2.ts': 'test text'
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
const targetFolderPath = path.join(
|
|
71
|
-
TEST_FOLDER_NAME,
|
|
72
|
-
`${testName}-target`
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
// Execute
|
|
76
|
-
await FileSystemService.copyFolderContents(
|
|
77
|
-
sourceFolderPath,
|
|
78
|
-
targetFolderPath,
|
|
79
|
-
['ts']
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
// Assert
|
|
83
|
-
const expectedContents = (
|
|
84
|
-
await FileSystemService.getAllFilePathsRelative(sourceFolderPath)
|
|
85
|
-
)
|
|
86
|
-
.filter((sourceFilePath) => !sourceFilePath.endsWith('.ts'))
|
|
87
|
-
.sort();
|
|
88
|
-
const actualContents = (
|
|
89
|
-
await FileSystemService.getAllFilePathsRelative(targetFolderPath)
|
|
90
|
-
).sort();
|
|
91
|
-
expect(actualContents).toEqual(expectedContents);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Creates test files and folders based on the provided structure
|
|
98
|
-
*
|
|
99
|
-
* @param folderPath The path where the files and folders should be created
|
|
100
|
-
* @param fileStructure An object representing the file structure to create
|
|
101
|
-
*/
|
|
102
|
-
async function createTestFiles(folderPath: string, fileStructure: object) {
|
|
103
|
-
await FileSystemService.checkOrCreateFolder(folderPath);
|
|
104
|
-
|
|
105
|
-
await Promise.all(
|
|
106
|
-
Object.entries(fileStructure).map(async ([key, value]) => {
|
|
107
|
-
if (typeof value === 'string') {
|
|
108
|
-
await writeFile(path.join(folderPath, key), value);
|
|
109
|
-
} else if (typeof value === 'object') {
|
|
110
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
111
|
-
await createTestFiles(path.join(folderPath, key), value);
|
|
112
|
-
}
|
|
113
|
-
})
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Creates a test folder within the main test directory
|
|
119
|
-
*
|
|
120
|
-
* @param folderName The name of the folder to create
|
|
121
|
-
*/
|
|
122
|
-
async function createTestFolder(folderName: string): Promise<string> {
|
|
123
|
-
const testFolderPath = path.join(TEST_FOLDER_NAME, folderName);
|
|
124
|
-
await FileSystemService.checkOrCreateFolder(testFolderPath);
|
|
125
|
-
return testFolderPath;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Deletes the main test folder and all its contents
|
|
130
|
-
*/
|
|
131
|
-
async function deleteTestFolder(): Promise<void> {
|
|
132
|
-
await FileSystemService.deleteFolder(TEST_FOLDER_NAME);
|
|
133
|
-
}
|