@aneuhold/core-ts-lib 1.1.52 → 2.0.5

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 (67) hide show
  1. package/LICENSE +21 -0
  2. package/lib/helperFunctions/sleep.d.ts.map +1 -1
  3. package/lib/helperFunctions/sleep.js +2 -4
  4. package/lib/helperFunctions/sleep.js.map +1 -0
  5. package/lib/helperFunctions/sleep.ts +8 -0
  6. package/lib/index.d.ts +12 -12
  7. package/lib/index.d.ts.map +1 -1
  8. package/lib/index.js +13 -26
  9. package/lib/index.js.map +1 -0
  10. package/lib/index.ts +29 -0
  11. package/lib/services/ArrayService.d.ts +8 -0
  12. package/lib/services/ArrayService.d.ts.map +1 -1
  13. package/lib/services/ArrayService.js +10 -4
  14. package/lib/services/ArrayService.js.map +1 -0
  15. package/lib/services/ArrayService.ts +26 -0
  16. package/lib/services/DateService/DateService.d.ts +8 -0
  17. package/lib/services/DateService/DateService.d.ts.map +1 -1
  18. package/lib/services/DateService/DateService.js +14 -4
  19. package/lib/services/DateService/DateService.js.map +1 -0
  20. package/lib/services/DateService/DateService.spec.ts +98 -0
  21. package/lib/services/DateService/DateService.ts +209 -0
  22. package/lib/services/DependencyService.d.ts +19 -3
  23. package/lib/services/DependencyService.d.ts.map +1 -1
  24. package/lib/services/DependencyService.js +66 -17
  25. package/lib/services/DependencyService.js.map +1 -0
  26. package/lib/services/DependencyService.ts +156 -0
  27. package/lib/services/FileSystemService/FileSystemService.d.ts +7 -0
  28. package/lib/services/FileSystemService/FileSystemService.d.ts.map +1 -1
  29. package/lib/services/FileSystemService/FileSystemService.js +49 -34
  30. package/lib/services/FileSystemService/FileSystemService.js.map +1 -0
  31. package/lib/services/FileSystemService/FileSystemService.spec.ts +117 -0
  32. package/lib/services/FileSystemService/FileSystemService.ts +185 -0
  33. package/lib/services/PackageService.d.ts +28 -0
  34. package/lib/services/PackageService.d.ts.map +1 -0
  35. package/lib/services/PackageService.js +131 -0
  36. package/lib/services/PackageService.js.map +1 -0
  37. package/lib/services/PackageService.ts +148 -0
  38. package/lib/services/StringService.d.ts.map +1 -1
  39. package/lib/services/StringService.js +2 -4
  40. package/lib/services/StringService.js.map +1 -0
  41. package/lib/services/StringService.ts +15 -0
  42. package/lib/utils/ErrorUtils.d.ts +7 -0
  43. package/lib/utils/ErrorUtils.d.ts.map +1 -1
  44. package/lib/utils/ErrorUtils.js +19 -4
  45. package/lib/utils/ErrorUtils.js.map +1 -0
  46. package/lib/utils/ErrorUtils.ts +37 -0
  47. package/lib/utils/Logger.d.ts +3 -0
  48. package/lib/utils/Logger.d.ts.map +1 -1
  49. package/lib/utils/Logger.js +5 -4
  50. package/lib/utils/Logger.js.map +1 -0
  51. package/lib/utils/Logger.ts +122 -0
  52. package/lib/utils/TestUtils.d.ts +3 -0
  53. package/lib/utils/TestUtils.d.ts.map +1 -1
  54. package/lib/utils/TestUtils.js +5 -4
  55. package/lib/utils/TestUtils.js.map +1 -0
  56. package/lib/utils/TestUtils.ts +33 -0
  57. package/package.json +29 -21
  58. package/readme.md +61 -2
  59. package/lib/helperFunctions/dateFunctions.d.ts +0 -10
  60. package/lib/helperFunctions/dateFunctions.d.ts.map +0 -1
  61. package/lib/helperFunctions/dateFunctions.js +0 -15
  62. package/lib/services/DateService/DateService.spec.d.ts +0 -2
  63. package/lib/services/DateService/DateService.spec.d.ts.map +0 -1
  64. package/lib/services/DateService/DateService.spec.js +0 -62
  65. package/lib/services/FileSystemService/FileSystemService.spec.d.ts +0 -2
  66. package/lib/services/FileSystemService/FileSystemService.spec.d.ts.map +0 -1
  67. package/lib/services/FileSystemService/FileSystemService.spec.js +0 -88
@@ -1 +1 @@
1
- {"version":3,"file":"DependencyService.d.ts","sourceRoot":"","sources":["../../src/services/DependencyService.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/C,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC;;;;OAIG;WACU,uBAAuB,IAAI,OAAO,CAAC,IAAI,CAAC;CA+DtD"}
1
+ {"version":3,"file":"DependencyService.d.ts","sourceRoot":"./src/","sources":["services/DependencyService.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,WAAY,SAAQ,uBAAuB;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/C;AAED,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,oBAAY,WAAW;IACrB,KAAK,UAAU;IACf,KAAK,UAAU;IACf,KAAK,UAAU;CAChB;AAED;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC;;;;OAIG;WACU,uBAAuB,IAAI,OAAO,CAAC,IAAI,CAAC;IAgErD;;;;OAIG;WACU,WAAW,CACtB,WAAW,GAAE,WAA+B,GAC3C,OAAO,CAAC,IAAI,CAAC;CA+CjB"}
@@ -1,16 +1,22 @@
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 FileSystemService_1 = __importDefault(require("./FileSystemService/FileSystemService"));
1
+ import { access, readFile, writeFile } from 'fs/promises';
2
+ import path from 'path';
3
+ import ErrorUtils from '../utils/ErrorUtils.js';
4
+ import Logger from '../utils/Logger.js';
5
+ import FileSystemService from './FileSystemService/FileSystemService.js';
6
+ /**
7
+ * Standard Semantic Versioning bump types.
8
+ */
9
+ export var VersionType;
10
+ (function (VersionType) {
11
+ VersionType["Patch"] = "patch";
12
+ VersionType["Minor"] = "minor";
13
+ VersionType["Major"] = "major";
14
+ })(VersionType || (VersionType = {}));
9
15
  /**
10
16
  * A service which can be used to manage dependencies in the current project
11
17
  * in various ways.
12
18
  */
13
- class DependencyService {
19
+ export default class DependencyService {
14
20
  /**
15
21
  * Updates the package.json files of all sub-directories based on the root
16
22
  * package.json file. This will match any versions of dependencies in the
@@ -18,16 +24,16 @@ class DependencyService {
18
24
  */
19
25
  static async updateChildPackageJsons() {
20
26
  // Read the root package.json file
21
- const rootPackageJsonPath = path_1.default.join(process.cwd(), 'package.json');
27
+ const rootPackageJsonPath = path.join(process.cwd(), 'package.json');
22
28
  try {
23
- await (0, promises_1.access)(rootPackageJsonPath);
29
+ await access(rootPackageJsonPath);
24
30
  }
25
31
  catch {
26
32
  throw new Error('No package.json file found in the current directory.');
27
33
  }
28
- const rootPackageJsonData = JSON.parse(await (0, promises_1.readFile)(rootPackageJsonPath, 'utf-8'));
34
+ const rootPackageJsonData = JSON.parse(await readFile(rootPackageJsonPath, 'utf-8'));
29
35
  // Get all files and in the current directory
30
- const filePaths = await FileSystemService_1.default.getAllFilePathsRelative(process.cwd());
36
+ const filePaths = await FileSystemService.getAllFilePathsRelative(process.cwd());
31
37
  const packageJsonPaths = filePaths.filter((filePath) => !filePath.includes('node_modules') &&
32
38
  !filePath.includes('dist') &&
33
39
  !filePath.includes('build') &&
@@ -39,8 +45,8 @@ class DependencyService {
39
45
  };
40
46
  // Iterate over all package.json files
41
47
  await Promise.all(packageJsonPaths.map(async (packageJsonPath) => {
42
- const fullPackageJsonPath = path_1.default.join(process.cwd(), packageJsonPath);
43
- const packageJsonData = JSON.parse(await (0, promises_1.readFile)(fullPackageJsonPath, 'utf-8'));
48
+ const fullPackageJsonPath = path.join(process.cwd(), packageJsonPath);
49
+ const packageJsonData = JSON.parse(await readFile(fullPackageJsonPath, 'utf-8'));
44
50
  const dependencies = packageJsonData.dependencies;
45
51
  if (dependencies) {
46
52
  Object.keys(dependencies).forEach((dependency) => {
@@ -58,8 +64,51 @@ class DependencyService {
58
64
  });
59
65
  }
60
66
  // Write the updated package.json file
61
- await (0, promises_1.writeFile)(fullPackageJsonPath, JSON.stringify(packageJsonData, null, 2));
67
+ await writeFile(fullPackageJsonPath, JSON.stringify(packageJsonData, null, 2));
62
68
  }));
63
69
  }
70
+ /**
71
+ * Bumps the version of the package.json and jsr.json files in the current
72
+ * working directory.
73
+ * @param versionType The type of version bump (patch, minor, major).
74
+ */
75
+ static async bumpVersion(versionType = VersionType.Patch) {
76
+ const bump = (version) => {
77
+ const [major, minor, patch] = version.split('.').map(Number);
78
+ switch (versionType) {
79
+ case VersionType.Major:
80
+ return `${major + 1}.0.0`;
81
+ case VersionType.Minor:
82
+ return `${major}.${minor + 1}.0`;
83
+ case VersionType.Patch:
84
+ default:
85
+ return `${major}.${minor}.${patch + 1}`;
86
+ }
87
+ };
88
+ const updateVersion = async (filePath) => {
89
+ try {
90
+ await access(filePath);
91
+ }
92
+ catch {
93
+ Logger.info(`No ${path.basename(filePath)} file found in the current directory.`);
94
+ return;
95
+ }
96
+ try {
97
+ const fileData = JSON.parse(await readFile(filePath, 'utf-8'));
98
+ const oldVersion = fileData.version;
99
+ const newVersion = bump(oldVersion);
100
+ fileData.version = newVersion;
101
+ await writeFile(filePath, JSON.stringify(fileData, null, 2));
102
+ Logger.info(`Bumped ${path.basename(filePath)} from ${oldVersion} to ${newVersion}`);
103
+ }
104
+ catch (error) {
105
+ const errorString = ErrorUtils.getErrorString(error);
106
+ Logger.error(`Failed to update ${path.basename(filePath)}: ${errorString}`);
107
+ }
108
+ };
109
+ const rootDir = process.cwd();
110
+ await updateVersion(path.join(rootDir, 'package.json'));
111
+ await updateVersion(path.join(rootDir, 'jsr.json'));
112
+ }
64
113
  }
65
- exports.default = DependencyService;
114
+ //# sourceMappingURL=DependencyService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DependencyService.js","sourceRoot":"./src/","sources":["services/DependencyService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,UAAU,MAAM,wBAAwB,CAAC;AAChD,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,iBAAiB,MAAM,0CAA0C,CAAC;AAczE;;GAEG;AACH,MAAM,CAAN,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,8BAAe,CAAA;IACf,8BAAe,CAAA;IACf,8BAAe,CAAA;AACjB,CAAC,EAJW,WAAW,KAAX,WAAW,QAItB;AAED;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAC,uBAAuB;QAClC,kCAAkC;QAClC,MAAM,mBAAmB,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,CAAC;QACrE,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAC;QACpC,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;QAC1E,CAAC;QACD,MAAM,mBAAmB,GAAG,IAAI,CAAC,KAAK,CACpC,MAAM,QAAQ,CAAC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logger from '../utils/Logger.js';
5
+ import FileSystemService from './FileSystemService/FileSystemService.js';
6
+
7
+ export interface PackageJson extends JsonWithVersionProperty {
8
+ name: string;
9
+ dependencies?: Record<string, string>;
10
+ devDependencies?: Record<string, string>;
11
+ peerDependencies?: Record<string, string>;
12
+ optionalDependencies?: Record<string, string>;
13
+ }
14
+
15
+ export interface JsonWithVersionProperty {
16
+ version: string;
17
+ }
18
+
19
+ /**
20
+ * Standard Semantic Versioning bump types.
21
+ */
22
+ export enum VersionType {
23
+ Patch = 'patch',
24
+ Minor = 'minor',
25
+ Major = 'major'
26
+ }
27
+
28
+ /**
29
+ * A service which can be used to manage dependencies in the current project
30
+ * in various ways.
31
+ */
32
+ export default class DependencyService {
33
+ /**
34
+ * Updates the package.json files of all sub-directories based on the root
35
+ * package.json file. This will match any versions of dependencies in the
36
+ * sub-directories to the version in the root package.json file.
37
+ */
38
+ static async updateChildPackageJsons(): Promise<void> {
39
+ // Read the root package.json file
40
+ const rootPackageJsonPath = path.join(process.cwd(), 'package.json');
41
+ try {
42
+ await access(rootPackageJsonPath);
43
+ } catch {
44
+ throw new Error('No package.json file found in the current directory.');
45
+ }
46
+ const rootPackageJsonData = JSON.parse(
47
+ await readFile(rootPackageJsonPath, 'utf-8')
48
+ ) as PackageJson;
49
+
50
+ // Get all files and in the current directory
51
+ const filePaths = await FileSystemService.getAllFilePathsRelative(
52
+ process.cwd()
53
+ );
54
+ const packageJsonPaths = filePaths.filter(
55
+ (filePath) =>
56
+ !filePath.includes('node_modules') &&
57
+ !filePath.includes('dist') &&
58
+ !filePath.includes('build') &&
59
+ filePath !== '/package.json' &&
60
+ filePath.endsWith('package.json')
61
+ );
62
+
63
+ const rootDependencies = {
64
+ ...rootPackageJsonData.dependencies,
65
+ ...rootPackageJsonData.devDependencies
66
+ };
67
+
68
+ // Iterate over all package.json files
69
+ await Promise.all(
70
+ packageJsonPaths.map(async (packageJsonPath) => {
71
+ const fullPackageJsonPath = path.join(process.cwd(), packageJsonPath);
72
+ const packageJsonData = JSON.parse(
73
+ await readFile(fullPackageJsonPath, 'utf-8')
74
+ ) as PackageJson;
75
+
76
+ const dependencies = packageJsonData.dependencies;
77
+ if (dependencies) {
78
+ Object.keys(dependencies).forEach((dependency) => {
79
+ if (rootDependencies[dependency]) {
80
+ dependencies[dependency] = rootDependencies[dependency];
81
+ }
82
+ });
83
+ }
84
+ const devDependencies = packageJsonData.devDependencies;
85
+ if (devDependencies) {
86
+ Object.keys(devDependencies).forEach((dependency) => {
87
+ if (rootDependencies[dependency]) {
88
+ devDependencies[dependency] = rootDependencies[dependency];
89
+ }
90
+ });
91
+ }
92
+
93
+ // Write the updated package.json file
94
+ await writeFile(
95
+ fullPackageJsonPath,
96
+ JSON.stringify(packageJsonData, null, 2)
97
+ );
98
+ })
99
+ );
100
+ }
101
+
102
+ /**
103
+ * Bumps the version of the package.json and jsr.json files in the current
104
+ * working directory.
105
+ * @param versionType The type of version bump (patch, minor, major).
106
+ */
107
+ static async bumpVersion(
108
+ versionType: VersionType = VersionType.Patch
109
+ ): Promise<void> {
110
+ const bump = (version: string): string => {
111
+ const [major, minor, patch] = version.split('.').map(Number);
112
+ switch (versionType) {
113
+ case VersionType.Major:
114
+ return `${major + 1}.0.0`;
115
+ case VersionType.Minor:
116
+ return `${major}.${minor + 1}.0`;
117
+ case VersionType.Patch:
118
+ default:
119
+ return `${major}.${minor}.${patch + 1}`;
120
+ }
121
+ };
122
+
123
+ const updateVersion = async (filePath: string): Promise<void> => {
124
+ try {
125
+ await access(filePath);
126
+ } catch {
127
+ Logger.info(
128
+ `No ${path.basename(filePath)} file found in the current directory.`
129
+ );
130
+ return;
131
+ }
132
+
133
+ try {
134
+ const fileData = JSON.parse(
135
+ await readFile(filePath, 'utf-8')
136
+ ) as JsonWithVersionProperty;
137
+ const oldVersion = fileData.version;
138
+ const newVersion = bump(oldVersion);
139
+ fileData.version = newVersion;
140
+ await writeFile(filePath, JSON.stringify(fileData, null, 2));
141
+ Logger.info(
142
+ `Bumped ${path.basename(filePath)} from ${oldVersion} to ${newVersion}`
143
+ );
144
+ } catch (error) {
145
+ const errorString = ErrorUtils.getErrorString(error);
146
+ Logger.error(
147
+ `Failed to update ${path.basename(filePath)}: ${errorString}`
148
+ );
149
+ }
150
+ };
151
+
152
+ const rootDir = process.cwd();
153
+ await updateVersion(path.join(rootDir, 'package.json'));
154
+ await updateVersion(path.join(rootDir, 'jsr.json'));
155
+ }
156
+ }
@@ -38,5 +38,12 @@ export default class FileSystemService {
38
38
  * If absolute file paths are needed, use {@link getAllFilePaths}.
39
39
  */
40
40
  static getAllFilePathsRelative(dirPath: string): Promise<string[]>;
41
+ /**
42
+ * Checks if there are any pending uncommitted changes in the git repository
43
+ * in the current working directory.
44
+ *
45
+ * @returns true if there are pending changes, false otherwise.
46
+ */
47
+ static hasPendingChanges(): Promise<boolean>;
41
48
  }
42
49
  //# sourceMappingURL=FileSystemService.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FileSystemService.d.ts","sourceRoot":"","sources":["../../../src/services/FileSystemService/FileSystemService.ts"],"names":[],"mappings":"AAeA;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC;;;;;;;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;WAmCH,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;CAMzE"}
1
+ {"version":3,"file":"FileSystemService.d.ts","sourceRoot":"./src/","sources":["services/FileSystemService/FileSystemService.ts"],"names":[],"mappings":"AAoBA;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC;;;;;;;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;WAmCH,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;IAOxE;;;;;OAKG;WACU,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC;CAWnD"}
@@ -1,17 +1,16 @@
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 Logger_1 = __importDefault(require("../../utils/Logger"));
9
- const StringService_1 = __importDefault(require("../StringService"));
1
+ import { exec } from 'child_process';
2
+ import { access, appendFile, cp, mkdir, readFile, readdir, rm, stat, writeFile } from 'fs/promises';
3
+ import path from 'path';
4
+ import { promisify } from 'util';
5
+ import ErrorUtils from '../../utils/ErrorUtils.js';
6
+ import Logger from '../../utils/Logger.js';
7
+ import StringService from '../StringService.js';
8
+ const execAsync = promisify(exec);
10
9
  /**
11
10
  * A service which can be used to interact with the file system, only in build
12
11
  * steps.
13
12
  */
14
- class FileSystemService {
13
+ export default class FileSystemService {
15
14
  /**
16
15
  * Tries to add the provided snippet of text to the path provided. If the file
17
16
  * doesn't exist, it creates it. If the folders to the file don't exist, it
@@ -21,22 +20,22 @@ class FileSystemService {
21
20
  * be updated
22
21
  */
23
22
  static async findAndInsertText(folderPath, fileName, textToInsert) {
24
- const filePath = path_1.default.join(folderPath, fileName);
23
+ const filePath = path.join(folderPath, fileName);
25
24
  await FileSystemService.checkOrCreateFolder(folderPath);
26
25
  try {
27
- await (0, promises_1.access)(filePath);
28
- const fileContents = await (0, promises_1.readFile)(filePath);
26
+ await access(filePath);
27
+ const fileContents = await readFile(filePath);
29
28
  if (!fileContents.includes(textToInsert)) {
30
- await (0, promises_1.appendFile)(filePath, `\n${textToInsert}`);
31
- Logger_1.default.info(`Added "${textToInsert}" to "${filePath}"`);
29
+ await appendFile(filePath, `\n${textToInsert}`);
30
+ Logger.info(`Added "${textToInsert}" to "${filePath}"`);
32
31
  }
33
32
  else {
34
- Logger_1.default.info(`"${textToInsert}" already exists in "${filePath}"`);
33
+ Logger.info(`"${textToInsert}" already exists in "${filePath}"`);
35
34
  }
36
35
  }
37
36
  catch {
38
- Logger_1.default.info(`File at "${filePath}" didn't exist. Creating it now and adding "${textToInsert}" to it.`);
39
- await (0, promises_1.writeFile)(filePath, textToInsert);
37
+ Logger.info(`File at "${filePath}" didn't exist. Creating it now and adding "${textToInsert}" to it.`);
38
+ await writeFile(filePath, textToInsert);
40
39
  }
41
40
  }
42
41
  /**
@@ -49,10 +48,10 @@ class FileSystemService {
49
48
  static async copyFolderContents(sourceFolderPath, targetFolderPath, ignoreExtensions) {
50
49
  // Check if the source directory exists first
51
50
  try {
52
- await (0, promises_1.access)(sourceFolderPath);
51
+ await access(sourceFolderPath);
53
52
  }
54
53
  catch {
55
- Logger_1.default.error(`Source directory "${sourceFolderPath}" does not exist.`);
54
+ Logger.error(`Source directory "${sourceFolderPath}" does not exist.`);
56
55
  return;
57
56
  }
58
57
  await FileSystemService.checkOrCreateFolder(targetFolderPath);
@@ -60,34 +59,34 @@ class FileSystemService {
60
59
  const sourceFilePaths = await FileSystemService.getAllFilePathsRelative(sourceFolderPath);
61
60
  // console.log(sourceFilePaths);
62
61
  await Promise.all(sourceFilePaths.map(async (sourceFilePath) => {
63
- const sourceFile = path_1.default.join(sourceFolderPath, sourceFilePath);
64
- const targetFile = path_1.default.join(targetFolderPath, sourceFilePath);
65
- const sourceFileExtension = StringService_1.default.getFileNameExtension(sourceFile);
62
+ const sourceFile = path.join(sourceFolderPath, sourceFilePath);
63
+ const targetFile = path.join(targetFolderPath, sourceFilePath);
64
+ const sourceFileExtension = StringService.getFileNameExtension(sourceFile);
66
65
  if (sourceFileExtension &&
67
66
  ignoreExtensions?.includes(sourceFileExtension)) {
68
67
  return;
69
68
  }
70
- await (0, promises_1.cp)(sourceFile, targetFile, { recursive: true });
69
+ await cp(sourceFile, targetFile, { recursive: true });
71
70
  }));
72
71
  }
73
72
  static async checkOrCreateFolder(folderPath) {
74
73
  try {
75
- await (0, promises_1.access)(folderPath);
74
+ await access(folderPath);
76
75
  }
77
76
  catch {
78
- Logger_1.default.verbose.info(`Directory "${folderPath}" does not exist. Creating it now...`);
79
- await (0, promises_1.mkdir)(folderPath, { recursive: true });
77
+ Logger.verbose.info(`Directory "${folderPath}" does not exist. Creating it now...`);
78
+ await mkdir(folderPath, { recursive: true });
80
79
  }
81
80
  }
82
81
  static async deleteFolder(folderPath) {
83
82
  try {
84
- await (0, promises_1.access)(folderPath);
83
+ await access(folderPath);
85
84
  }
86
85
  catch {
87
- Logger_1.default.error(`Directory "${folderPath}" does not exist.`);
86
+ Logger.error(`Directory "${folderPath}" does not exist.`);
88
87
  return;
89
88
  }
90
- await (0, promises_1.rm)(folderPath, { recursive: true });
89
+ await rm(folderPath, { recursive: true });
91
90
  }
92
91
  /**
93
92
  * Gets all the file paths in the directory provided, including all
@@ -98,10 +97,10 @@ class FileSystemService {
98
97
  */
99
98
  static async getAllFilePaths(dirPath) {
100
99
  const filePaths = [];
101
- const fileOrFolderNames = await (0, promises_1.readdir)(dirPath);
100
+ const fileOrFolderNames = await readdir(dirPath);
102
101
  await Promise.all(fileOrFolderNames.map(async (fileOrFolder) => {
103
- const absolutePath = path_1.default.join(dirPath, fileOrFolder);
104
- const fileStat = await (0, promises_1.stat)(absolutePath);
102
+ const absolutePath = path.join(dirPath, fileOrFolder);
103
+ const fileStat = await stat(absolutePath);
105
104
  if (fileStat.isDirectory()) {
106
105
  filePaths.push(...(await this.getAllFilePaths(absolutePath)));
107
106
  }
@@ -124,5 +123,21 @@ class FileSystemService {
124
123
  return filePath.replace(dirPath, '');
125
124
  });
126
125
  }
126
+ /**
127
+ * Checks if there are any pending uncommitted changes in the git repository
128
+ * in the current working directory.
129
+ *
130
+ * @returns true if there are pending changes, false otherwise.
131
+ */
132
+ static async hasPendingChanges() {
133
+ try {
134
+ const { stdout } = await execAsync('git status --porcelain');
135
+ return stdout.trim().length > 0;
136
+ }
137
+ catch (error) {
138
+ Logger.error(`Failed to check for pending changes: ${ErrorUtils.getErrorString(error)}`);
139
+ return false;
140
+ }
141
+ }
127
142
  }
128
- exports.default = FileSystemService;
143
+ //# sourceMappingURL=FileSystemService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FileSystemService.js","sourceRoot":"./src/","sources":["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,O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M,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QACtD,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE;YAChC,OAAO,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACvC,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,iBAAiB;QAC5B,IAAI,CAAC;YACH,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,SAAS,CAAC,wBAAwB,CAAC,CAAC;YAC7D,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;QAClC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CACV,wCAAwC,UAAU,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,CAC3E,CAAC;YACF,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,117 @@
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
+ const actualContents =
42
+ await FileSystemService.getAllFilePathsRelative(targetFolderPath);
43
+ expect(actualContents).toEqual(expectedContents);
44
+ });
45
+
46
+ it('should successfully copy only files that arent ignored', async () => {
47
+ // Make a test folder with a folder and a couple files in it
48
+ const testName = 'copyFolderContents-2';
49
+ const sourceFolderName = `${testName}-source`;
50
+ const sourceFolderPath = await createTestFolder(sourceFolderName);
51
+ await createTestFiles(sourceFolderPath, {
52
+ 'file1.txt': 'test text',
53
+ 'file2.txt': 'test text',
54
+ subFolder: {
55
+ 'subFile1.txt': 'sub test text',
56
+ 'subFile2.txt': 'sub test text'
57
+ },
58
+ javascript: {
59
+ 'file1.js': 'test text',
60
+ 'file2.js': 'test text'
61
+ },
62
+ typescript: {
63
+ 'file1.ts': 'test text',
64
+ 'file2.ts': 'test text'
65
+ }
66
+ });
67
+
68
+ const targetFolderPath = path.join(
69
+ TEST_FOLDER_NAME,
70
+ `${testName}-target`
71
+ );
72
+
73
+ // Execute
74
+ await FileSystemService.copyFolderContents(
75
+ sourceFolderPath,
76
+ targetFolderPath,
77
+ ['ts']
78
+ );
79
+
80
+ // Assert
81
+ const expectedContents = (
82
+ await FileSystemService.getAllFilePathsRelative(sourceFolderPath)
83
+ )
84
+ .filter((sourceFilePath) => !sourceFilePath.endsWith('.ts'))
85
+ .sort();
86
+ const actualContents = (
87
+ await FileSystemService.getAllFilePathsRelative(targetFolderPath)
88
+ ).sort();
89
+ expect(actualContents).toEqual(expectedContents);
90
+ });
91
+ });
92
+ });
93
+
94
+ async function createTestFiles(folderPath: string, fileStructure: object) {
95
+ await FileSystemService.checkOrCreateFolder(folderPath);
96
+
97
+ await Promise.all(
98
+ Object.entries(fileStructure).map(async ([key, value]) => {
99
+ if (typeof value === 'string') {
100
+ await writeFile(path.join(folderPath, key), value);
101
+ } else if (typeof value === 'object') {
102
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
103
+ await createTestFiles(path.join(folderPath, key), value);
104
+ }
105
+ })
106
+ );
107
+ }
108
+
109
+ async function createTestFolder(folderName: string): Promise<string> {
110
+ const testFolderPath = path.join(TEST_FOLDER_NAME, folderName);
111
+ await FileSystemService.checkOrCreateFolder(testFolderPath);
112
+ return testFolderPath;
113
+ }
114
+
115
+ async function deleteTestFolder(): Promise<void> {
116
+ await FileSystemService.deleteFolder(TEST_FOLDER_NAME);
117
+ }