@bemoje/fs 0.0.13 → 0.1.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 (154) hide show
  1. package/README.md +6 -34
  2. package/package.json +10 -10
  3. package/{dist/types → src}/index.d.ts +0 -1
  4. package/src/index.js +39 -0
  5. package/src/index.js.map +1 -0
  6. package/{dist/types → src}/lib/AppData.d.ts +0 -1
  7. package/src/lib/AppData.js +24 -0
  8. package/src/lib/AppData.js.map +1 -0
  9. package/{dist/types → src}/lib/JsonFile.d.ts +0 -1
  10. package/src/lib/JsonFile.js +146 -0
  11. package/src/lib/JsonFile.js.map +1 -0
  12. package/{dist/types → src}/lib/LogFile.d.ts +0 -1
  13. package/src/lib/LogFile.js +158 -0
  14. package/src/lib/LogFile.js.map +1 -0
  15. package/{dist/types → src}/lib/absoluteToRelativePath.d.ts +0 -1
  16. package/src/lib/absoluteToRelativePath.js +25 -0
  17. package/src/lib/absoluteToRelativePath.js.map +1 -0
  18. package/{dist/types → src}/lib/appendLineToFile.d.ts +0 -1
  19. package/src/lib/appendLineToFile.js +28 -0
  20. package/src/lib/appendLineToFile.js.map +1 -0
  21. package/{dist/types → src}/lib/cleanDirectorySync.d.ts +0 -1
  22. package/src/lib/cleanDirectorySync.js +29 -0
  23. package/src/lib/cleanDirectorySync.js.map +1 -0
  24. package/{dist/types → src}/lib/createDirectory.d.ts +0 -1
  25. package/src/lib/createDirectory.js +25 -0
  26. package/src/lib/createDirectory.js.map +1 -0
  27. package/{dist/types → src}/lib/createDirectorySync.d.ts +0 -1
  28. package/src/lib/createDirectorySync.js +20 -0
  29. package/src/lib/createDirectorySync.js.map +1 -0
  30. package/{dist/types → src}/lib/createFileExtensionFilter.d.ts +0 -1
  31. package/src/lib/createFileExtensionFilter.js +32 -0
  32. package/src/lib/createFileExtensionFilter.js.map +1 -0
  33. package/{dist/types → src}/lib/cwdpath.d.ts +0 -1
  34. package/src/lib/cwdpath.js +21 -0
  35. package/src/lib/cwdpath.js.map +1 -0
  36. package/{dist/types → src}/lib/deleteDirectory.d.ts +0 -1
  37. package/src/lib/deleteDirectory.js +23 -0
  38. package/src/lib/deleteDirectory.js.map +1 -0
  39. package/{dist/types → src}/lib/deleteDirectorySafe.d.ts +0 -1
  40. package/src/lib/deleteDirectorySafe.js +25 -0
  41. package/src/lib/deleteDirectorySafe.js.map +1 -0
  42. package/{dist/types → src}/lib/deleteDirectorySafeSync.d.ts +0 -1
  43. package/src/lib/deleteDirectorySafeSync.js +23 -0
  44. package/src/lib/deleteDirectorySafeSync.js.map +1 -0
  45. package/{dist/types → src}/lib/deleteDirectorySync.d.ts +0 -1
  46. package/src/lib/deleteDirectorySync.js +22 -0
  47. package/src/lib/deleteDirectorySync.js.map +1 -0
  48. package/{dist/types → src}/lib/ensureValidWindowsPath.d.ts +0 -1
  49. package/src/lib/ensureValidWindowsPath.js +54 -0
  50. package/src/lib/ensureValidWindowsPath.js.map +1 -0
  51. package/{dist/types → src}/lib/getDiskDrivesWindows.d.ts +0 -1
  52. package/src/lib/getDiskDrivesWindows.js +19 -0
  53. package/src/lib/getDiskDrivesWindows.js.map +1 -0
  54. package/{dist/types → src}/lib/getDownloadsDirectory.d.ts +0 -1
  55. package/src/lib/getDownloadsDirectory.js +11 -0
  56. package/src/lib/getDownloadsDirectory.js.map +1 -0
  57. package/{dist/types → src}/lib/getHomeDirectory.d.ts +0 -1
  58. package/src/lib/getHomeDirectory.js +13 -0
  59. package/src/lib/getHomeDirectory.js.map +1 -0
  60. package/{dist/types → src}/lib/getLastMofifiedFileIn.d.ts +0 -1
  61. package/src/lib/getLastMofifiedFileIn.js +22 -0
  62. package/src/lib/getLastMofifiedFileIn.js.map +1 -0
  63. package/{dist/types → src}/lib/getRootDir.d.ts +0 -1
  64. package/src/lib/getRootDir.js +10 -0
  65. package/src/lib/getRootDir.js.map +1 -0
  66. package/{dist/types → src}/lib/isWindows.d.ts +0 -1
  67. package/src/lib/isWindows.js +8 -0
  68. package/src/lib/isWindows.js.map +1 -0
  69. package/{dist/types → src}/lib/normalizeFileExtension.d.ts +0 -1
  70. package/src/lib/normalizeFileExtension.js +36 -0
  71. package/src/lib/normalizeFileExtension.js.map +1 -0
  72. package/{dist/types → src}/lib/readFileLastLines.d.ts +1 -4
  73. package/src/lib/readFileLastLines.js +18 -0
  74. package/src/lib/readFileLastLines.js.map +1 -0
  75. package/{dist/types → src}/lib/readJsonFile.d.ts +0 -1
  76. package/src/lib/readJsonFile.js +23 -0
  77. package/src/lib/readJsonFile.js.map +1 -0
  78. package/{dist/types → src}/lib/readJsonFileSync.d.ts +0 -1
  79. package/src/lib/readJsonFileSync.js +21 -0
  80. package/src/lib/readJsonFileSync.js.map +1 -0
  81. package/{dist/types → src}/lib/readPackageJson.d.ts +0 -1
  82. package/src/lib/readPackageJson.js +15 -0
  83. package/src/lib/readPackageJson.js.map +1 -0
  84. package/{dist/types → src}/lib/removeIllegalFilenameCharacters.d.ts +0 -1
  85. package/src/lib/removeIllegalFilenameCharacters.js +8 -0
  86. package/src/lib/removeIllegalFilenameCharacters.js.map +1 -0
  87. package/{dist/types → src}/lib/tempFile.d.ts +0 -1
  88. package/src/lib/tempFile.js +26 -0
  89. package/src/lib/tempFile.js.map +1 -0
  90. package/{dist/types → src}/lib/types/IEnsureValidWindowsPathOptions.d.ts +0 -1
  91. package/src/lib/types/IEnsureValidWindowsPathOptions.js +3 -0
  92. package/src/lib/types/IEnsureValidWindowsPathOptions.js.map +1 -0
  93. package/{dist/types → src}/lib/types/ILogFileData.d.ts +0 -1
  94. package/src/lib/types/ILogFileData.js +3 -0
  95. package/src/lib/types/ILogFileData.js.map +1 -0
  96. package/{dist/types → src}/lib/unzipFile.d.ts +0 -1
  97. package/src/lib/unzipFile.js +12 -0
  98. package/src/lib/unzipFile.js.map +1 -0
  99. package/{dist/types → src}/lib/unzipMergeFiles.d.ts +0 -1
  100. package/src/lib/unzipMergeFiles.js +29 -0
  101. package/src/lib/unzipMergeFiles.js.map +1 -0
  102. package/{dist/types → src}/lib/wipeDirectorySafe.d.ts +0 -1
  103. package/src/lib/wipeDirectorySafe.js +14 -0
  104. package/src/lib/wipeDirectorySafe.js.map +1 -0
  105. package/{dist/types → src}/lib/writeJsonFile.d.ts +0 -1
  106. package/src/lib/writeJsonFile.js +25 -0
  107. package/src/lib/writeJsonFile.js.map +1 -0
  108. package/{dist/types → src}/lib/writeJsonFileSync.d.ts +0 -1
  109. package/src/lib/writeJsonFileSync.js +22 -0
  110. package/src/lib/writeJsonFileSync.js.map +1 -0
  111. package/LICENSE +0 -21
  112. package/dist/index.cjs.js +0 -6
  113. package/dist/index.cjs.js.map +0 -1
  114. package/dist/index.esm.js +0 -6
  115. package/dist/index.esm.js.map +0 -1
  116. package/dist/types/index.d.ts.map +0 -1
  117. package/dist/types/lib/AppData.d.ts.map +0 -1
  118. package/dist/types/lib/JsonFile.d.ts.map +0 -1
  119. package/dist/types/lib/LogFile.d.ts.map +0 -1
  120. package/dist/types/lib/absoluteToRelativePath.d.ts.map +0 -1
  121. package/dist/types/lib/appendLineToFile.d.ts.map +0 -1
  122. package/dist/types/lib/cleanDirectorySync.d.ts.map +0 -1
  123. package/dist/types/lib/createDirectory.d.ts.map +0 -1
  124. package/dist/types/lib/createDirectorySync.d.ts.map +0 -1
  125. package/dist/types/lib/createFileExtensionFilter.d.ts.map +0 -1
  126. package/dist/types/lib/cwdpath.d.ts.map +0 -1
  127. package/dist/types/lib/deleteDirectory.d.ts.map +0 -1
  128. package/dist/types/lib/deleteDirectorySafe.d.ts.map +0 -1
  129. package/dist/types/lib/deleteDirectorySafeSync.d.ts.map +0 -1
  130. package/dist/types/lib/deleteDirectorySync.d.ts.map +0 -1
  131. package/dist/types/lib/ensureValidWindowsPath.d.ts.map +0 -1
  132. package/dist/types/lib/getDiskDrivesWindows.d.ts.map +0 -1
  133. package/dist/types/lib/getDownloadsDirectory.d.ts.map +0 -1
  134. package/dist/types/lib/getHomeDirectory.d.ts.map +0 -1
  135. package/dist/types/lib/getLastMofifiedFileIn.d.ts.map +0 -1
  136. package/dist/types/lib/getRootDir.d.ts.map +0 -1
  137. package/dist/types/lib/isWindows.d.ts.map +0 -1
  138. package/dist/types/lib/normalizeFileExtension.d.ts.map +0 -1
  139. package/dist/types/lib/readFileLastLines.d.ts.map +0 -1
  140. package/dist/types/lib/readJsonFile.d.ts.map +0 -1
  141. package/dist/types/lib/readJsonFileSync.d.ts.map +0 -1
  142. package/dist/types/lib/readPackageJson.d.ts.map +0 -1
  143. package/dist/types/lib/removeIllegalFilenameCharacters.d.ts.map +0 -1
  144. package/dist/types/lib/tempFile.d.ts.map +0 -1
  145. package/dist/types/lib/types/IEnsureValidWindowsPathOptions.d.ts.map +0 -1
  146. package/dist/types/lib/types/ILogFileData.d.ts.map +0 -1
  147. package/dist/types/lib/unzipFile.d.ts.map +0 -1
  148. package/dist/types/lib/unzipMergeFiles.d.ts.map +0 -1
  149. package/dist/types/lib/wipeDirectorySafe.d.ts.map +0 -1
  150. package/dist/types/lib/writeJsonFile.d.ts.map +0 -1
  151. package/dist/types/lib/writeJsonFileSync.d.ts.map +0 -1
  152. package/jest.config.ts +0 -13
  153. package/project.json +0 -30
  154. package/tsconfig.spec.json +0 -9
package/README.md CHANGED
@@ -1,39 +1,11 @@
1
- # @bemoje/fs
2
- Tools for working with the local filesystem in nodejs.
1
+ # fs
3
2
 
4
- ![GitHub Top Language](https://img.shields.io/github/languages/top/bemoje/https://github.com/bemoje/tsmono)
3
+ This library was generated with [Nx](https://nx.dev).
5
4
 
6
- ##### Github
7
- ![GitHub Last Commit](https://img.shields.io/github/last-commit/bemoje/https://github.com/bemoje/tsmono?color=red)
8
- ![GitHub Stars](https://img.shields.io/github/stars/bemoje/https://github.com/bemoje/tsmono)
9
- ![GitHub Forks](https://img.shields.io/github/forks/bemoje/https://github.com/bemoje/tsmono)
10
- ![GitHub Watchers](https://img.shields.io/github/watchers/bemoje/https://github.com/bemoje/tsmono)
11
- ![GitHub Repo Size](https://img.shields.io/github/repo-size/bemoje/https://github.com/bemoje/tsmono)
5
+ ## Building
12
6
 
13
- ##### NPM
14
- <span><a href="https://npmjs.org/@bemoje/fs" title="View this project on NPM"><img src="https://img.shields.io/npm/v/@bemoje/fs" alt="NPM Version" /></a></span>
15
- <span><a href="https://npmjs.org/@bemoje/fs" title="NPM Downloads"><img src="https://img.shields.io/npm/dt/@bemoje/fs" alt="NPM Downloads" /></a></span>
7
+ Run `nx build fs` to build the library.
16
8
 
17
- ## Documentation
18
- [fs docs](https://bemoje.github.io/tsmono/modules/fs.html)
9
+ ## Running unit tests
19
10
 
20
- ##### Donate
21
- <span><a href="https://www.patreon.com/user?u=40752770" title="Donate using Patreon"><img src="https://img.shields.io/badge/patreon-donate-yellow.svg" alt="Patreon Donation" /></a></span>
22
-
23
- ## Installation
24
- This library is published in the NPM registry and can be installed using any compatible package manager.
25
-
26
- #### NPM
27
- ```sh
28
- npm install @bemoje/fs
29
- ```
30
-
31
-
32
- ## Issues
33
- Please let me know of any bugs or [issues](https://github.com/bemoje/https://github.com/bemoje/tsmono/issues).
34
-
35
- ## Contribute
36
- Contributors are welcome to open a [pull request](https://github.com/bemoje/https://github.com/bemoje/tsmono/pulls).
37
-
38
- ## License
39
- Released under the [MIT License](./LICENSE).
11
+ Run `nx test fs` to execute the unit tests via [Jest](https://jestjs.io).
package/package.json CHANGED
@@ -1,13 +1,9 @@
1
1
  {
2
2
  "name": "@bemoje/fs",
3
- "version": "0.0.13",
3
+ "version": "0.1.0",
4
4
  "description": "Tools for working with the local filesystem in nodejs.",
5
- "main": "dist/index.cjs.js",
6
- "module": "dist/index.esm.js",
7
- "types": "dist/types/index.d.ts",
8
- "scripts": {
9
- "build": "rimraf dist && rollup --config ./rollup.config.js --bundleConfigAsCjs"
10
- },
5
+ "main": "./src/index.js",
6
+ "scripts": {},
11
7
  "author": {
12
8
  "name": "Benjamin Møller Jensen",
13
9
  "email": "bemoje@bemoje.net",
@@ -19,7 +15,8 @@
19
15
  "@bemoje/string": "latest",
20
16
  "appdata-path": "^1.0.0",
21
17
  "extract-zip": "^2.0.1",
22
- "read-last-lines": "^1.8.0"
18
+ "read-last-lines": "^1.8.0",
19
+ "tslib": "^2.3.0"
23
20
  },
24
21
  "repository": {
25
22
  "type": "git",
@@ -35,5 +32,8 @@
35
32
  "homepage": "https://github.com/bemoje/tsmono",
36
33
  "devDependencies": {
37
34
  "@types/extract-zip": "^2.0.1"
38
- }
39
- }
35
+ },
36
+ "type": "commonjs",
37
+ "typings": "./src/index.d.ts",
38
+ "types": "./src/index.d.ts"
39
+ }
@@ -33,4 +33,3 @@ export * from './lib/unzipMergeFiles';
33
33
  export * from './lib/wipeDirectorySafe';
34
34
  export * from './lib/writeJsonFile';
35
35
  export * from './lib/writeJsonFileSync';
36
- //# sourceMappingURL=index.d.ts.map
package/src/index.js ADDED
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./lib/absoluteToRelativePath"), exports);
5
+ tslib_1.__exportStar(require("./lib/AppData"), exports);
6
+ tslib_1.__exportStar(require("./lib/appendLineToFile"), exports);
7
+ tslib_1.__exportStar(require("./lib/cleanDirectorySync"), exports);
8
+ tslib_1.__exportStar(require("./lib/createDirectory"), exports);
9
+ tslib_1.__exportStar(require("./lib/createDirectorySync"), exports);
10
+ tslib_1.__exportStar(require("./lib/createFileExtensionFilter"), exports);
11
+ tslib_1.__exportStar(require("./lib/cwdpath"), exports);
12
+ tslib_1.__exportStar(require("./lib/deleteDirectory"), exports);
13
+ tslib_1.__exportStar(require("./lib/deleteDirectorySafe"), exports);
14
+ tslib_1.__exportStar(require("./lib/deleteDirectorySafeSync"), exports);
15
+ tslib_1.__exportStar(require("./lib/deleteDirectorySync"), exports);
16
+ tslib_1.__exportStar(require("./lib/ensureValidWindowsPath"), exports);
17
+ tslib_1.__exportStar(require("./lib/getDiskDrivesWindows"), exports);
18
+ tslib_1.__exportStar(require("./lib/getDownloadsDirectory"), exports);
19
+ tslib_1.__exportStar(require("./lib/getHomeDirectory"), exports);
20
+ tslib_1.__exportStar(require("./lib/getLastMofifiedFileIn"), exports);
21
+ tslib_1.__exportStar(require("./lib/getRootDir"), exports);
22
+ tslib_1.__exportStar(require("./lib/isWindows"), exports);
23
+ tslib_1.__exportStar(require("./lib/JsonFile"), exports);
24
+ tslib_1.__exportStar(require("./lib/LogFile"), exports);
25
+ tslib_1.__exportStar(require("./lib/normalizeFileExtension"), exports);
26
+ tslib_1.__exportStar(require("./lib/readFileLastLines"), exports);
27
+ tslib_1.__exportStar(require("./lib/readJsonFile"), exports);
28
+ tslib_1.__exportStar(require("./lib/readJsonFileSync"), exports);
29
+ tslib_1.__exportStar(require("./lib/readPackageJson"), exports);
30
+ tslib_1.__exportStar(require("./lib/removeIllegalFilenameCharacters"), exports);
31
+ tslib_1.__exportStar(require("./lib/tempFile"), exports);
32
+ tslib_1.__exportStar(require("./lib/types/IEnsureValidWindowsPathOptions"), exports);
33
+ tslib_1.__exportStar(require("./lib/types/ILogFileData"), exports);
34
+ tslib_1.__exportStar(require("./lib/unzipFile"), exports);
35
+ tslib_1.__exportStar(require("./lib/unzipMergeFiles"), exports);
36
+ tslib_1.__exportStar(require("./lib/wipeDirectorySafe"), exports);
37
+ tslib_1.__exportStar(require("./lib/writeJsonFile"), exports);
38
+ tslib_1.__exportStar(require("./lib/writeJsonFileSync"), exports);
39
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/fs/src/index.ts"],"names":[],"mappings":";;;AAAA,uEAA4C;AAC5C,wDAA6B;AAC7B,iEAAsC;AACtC,mEAAwC;AACxC,gEAAqC;AACrC,oEAAyC;AACzC,0EAA+C;AAC/C,wDAA6B;AAC7B,gEAAqC;AACrC,oEAAyC;AACzC,wEAA6C;AAC7C,oEAAyC;AACzC,uEAA4C;AAC5C,qEAA0C;AAC1C,sEAA2C;AAC3C,iEAAsC;AACtC,sEAA2C;AAC3C,2DAAgC;AAChC,0DAA+B;AAC/B,yDAA8B;AAC9B,wDAA6B;AAC7B,uEAA4C;AAC5C,kEAAuC;AACvC,6DAAkC;AAClC,iEAAsC;AACtC,gEAAqC;AACrC,gFAAqD;AACrD,yDAA8B;AAC9B,qFAA0D;AAC1D,mEAAwC;AACxC,0DAA+B;AAC/B,gEAAqC;AACrC,kEAAuC;AACvC,8DAAmC;AACnC,kEAAuC"}
@@ -8,4 +8,3 @@ export declare class AppData<A extends Record<string, unknown>, C extends Record
8
8
  history: LogFile<ILogFileData<C>>;
9
9
  constructor(appAuthor: string, appName: string, configName: string);
10
10
  }
11
- //# sourceMappingURL=AppData.d.ts.map
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AppData = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const appdata_path_1 = tslib_1.__importDefault(require("appdata-path"));
6
+ const path_1 = tslib_1.__importDefault(require("path"));
7
+ const JsonFile_1 = require("./JsonFile");
8
+ const LogFile_1 = require("./LogFile");
9
+ class AppData {
10
+ constructor(appAuthor, appName, configName) {
11
+ this.directory = path_1.default.join((0, appdata_path_1.default)(), appAuthor, appName, configName);
12
+ this.app = new JsonFile_1.JsonFile(path_1.default.join(this.directory, 'appdata.json'), false);
13
+ this.user = new JsonFile_1.JsonFile(path_1.default.join(this.directory, 'config.json'), true);
14
+ this.history = new LogFile_1.LogFile(path_1.default.join(this.directory, 'history.log'));
15
+ this.app.on('set', (time, k, v) => tslib_1.__awaiter(this, void 0, void 0, function* () {
16
+ yield this.history.append({ source: 'app', key: k, value: v }, time);
17
+ }));
18
+ this.user.on('set', (time, k, v) => tslib_1.__awaiter(this, void 0, void 0, function* () {
19
+ yield this.history.append({ source: 'user', key: k, value: v }, time);
20
+ }));
21
+ }
22
+ }
23
+ exports.AppData = AppData;
24
+ //# sourceMappingURL=AppData.js.map
@@ -0,0 +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EAAE,EAAE,IAAI,CAAC,CAAA;QACvE,CAAC,CAAA,CAAC,CAAA;IACJ,CAAC;CACF;AAlBD,0BAkBC"}
@@ -76,4 +76,3 @@ export declare class JsonFile<T extends Record<string, any>> extends EventEmitte
76
76
  */
77
77
  loadFile(): void;
78
78
  }
79
- //# sourceMappingURL=JsonFile.d.ts.map
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ var _JsonFile_data;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.JsonFile = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const events_1 = tslib_1.__importDefault(require("events"));
7
+ const fs_1 = tslib_1.__importDefault(require("fs"));
8
+ const path_1 = tslib_1.__importDefault(require("path"));
9
+ const readJsonFileSync_1 = require("./readJsonFileSync");
10
+ const writeJsonFileSync_1 = require("./writeJsonFileSync");
11
+ /**
12
+ * Represents a JSON file manager that ensures immutable data since everything is serialized and deserialized before receiving or returning any data.
13
+ */
14
+ class JsonFile extends events_1.default {
15
+ /**
16
+ * Gets the data stored in the JSON file.
17
+ * @returns A deep copy of the data.
18
+ */
19
+ get data() {
20
+ return JSON.parse(JSON.stringify(tslib_1.__classPrivateFieldGet(this, _JsonFile_data, "f")));
21
+ }
22
+ /**
23
+ * Constructs a new instance of the JsonFile class.
24
+ * @param filepath - The filepath of the JSON file.
25
+ * @param prettyPrint - Determines whether the JSON file should be pretty-printed.
26
+ */
27
+ constructor(filepath, prettyPrint = false) {
28
+ super();
29
+ /**
30
+ * The data stored in the JSON file.
31
+ */
32
+ _JsonFile_data.set(this, void 0);
33
+ this.filepath = filepath;
34
+ tslib_1.__classPrivateFieldSet(this, _JsonFile_data, {}, "f");
35
+ this.prettyPrint = prettyPrint;
36
+ this.ensureDirectoryExists();
37
+ if (fs_1.default.existsSync(this.filepath)) {
38
+ this.loadFile();
39
+ }
40
+ else {
41
+ (0, writeJsonFileSync_1.writeJsonFileSync)(this.filepath, tslib_1.__classPrivateFieldGet(this, _JsonFile_data, "f"), this.prettyPrint);
42
+ }
43
+ }
44
+ /**
45
+ * Gets the value associated with the specified key.
46
+ * @param key - The key to retrieve the value for.
47
+ * @returns The value associated with the key.
48
+ */
49
+ get(key) {
50
+ return JSON.parse(JSON.stringify(tslib_1.__classPrivateFieldGet(this, _JsonFile_data, "f")[key]));
51
+ }
52
+ /**
53
+ * Sets the value associated with the specified key.
54
+ * @param key - The key to set the value for.
55
+ * @param value - The value to set.
56
+ */
57
+ set(key, value) {
58
+ if (tslib_1.__classPrivateFieldGet(this, _JsonFile_data, "f")[key] === value)
59
+ return;
60
+ const json = JSON.stringify(value);
61
+ if (json === JSON.stringify(tslib_1.__classPrivateFieldGet(this, _JsonFile_data, "f")[key]))
62
+ return;
63
+ value = JSON.parse(json);
64
+ tslib_1.__classPrivateFieldGet(this, _JsonFile_data, "f")[key] = value;
65
+ this.saveFile();
66
+ this.emit('set', Date.now(), key, value);
67
+ }
68
+ /**
69
+ * Checks if the specified key exists in the JSON file.
70
+ * @param key - The key to check.
71
+ * @returns True if the key exists, false otherwise.
72
+ */
73
+ has(key) {
74
+ return tslib_1.__classPrivateFieldGet(this, _JsonFile_data, "f")[key] !== undefined;
75
+ }
76
+ /**
77
+ * Deletes the value associated with the specified key.
78
+ * @param key - The key to delete.
79
+ */
80
+ delete(key) {
81
+ delete tslib_1.__classPrivateFieldGet(this, _JsonFile_data, "f")[key];
82
+ this.saveFile();
83
+ this.emit('set', Date.now(), key, void 0);
84
+ }
85
+ /**
86
+ * Gets the value associated with the specified key, or sets it to the provided default value if it doesn't exist.
87
+ * @param key - The key to get or set.
88
+ * @param getValue - A function that returns the default value if the key doesn't exist.
89
+ * @returns The value associated with the key, or the default value if it doesn't exist.
90
+ */
91
+ getOrElse(key, getValue) {
92
+ if (this.has(key)) {
93
+ return JSON.parse(JSON.stringify(this.get(key)));
94
+ }
95
+ const value = JSON.parse(JSON.stringify(getValue()));
96
+ this.set(key, value);
97
+ return value;
98
+ }
99
+ /**
100
+ * Clears all the data in the JSON file.
101
+ */
102
+ clear() {
103
+ const time = Date.now();
104
+ for (const key of Object.keys(tslib_1.__classPrivateFieldGet(this, _JsonFile_data, "f"))) {
105
+ this.emit('set', time, key, void 0);
106
+ }
107
+ tslib_1.__classPrivateFieldSet(this, _JsonFile_data, {}, "f");
108
+ fs_1.default.writeFileSync(this.filepath, '{}', 'utf8');
109
+ }
110
+ /**
111
+ * Assigns new data to the JSON file.
112
+ * @param data - The data to assign.
113
+ */
114
+ assign(data) {
115
+ data = JSON.parse(JSON.stringify(data));
116
+ const time = Date.now();
117
+ for (const [key, value] of Object.entries(data)) {
118
+ if (tslib_1.__classPrivateFieldGet(this, _JsonFile_data, "f")[key] && JSON.stringify(tslib_1.__classPrivateFieldGet(this, _JsonFile_data, "f")[key]) !== JSON.stringify(value)) {
119
+ this.emit('set', time, key, value);
120
+ }
121
+ }
122
+ Object.assign(tslib_1.__classPrivateFieldGet(this, _JsonFile_data, "f"), data);
123
+ this.saveFile();
124
+ }
125
+ /**
126
+ * Ensures that the directory containing the JSON file exists.
127
+ */
128
+ ensureDirectoryExists() {
129
+ fs_1.default.mkdirSync(path_1.default.dirname(this.filepath), { recursive: true });
130
+ }
131
+ /**
132
+ * Saves the data to the JSON file.
133
+ */
134
+ saveFile() {
135
+ (0, writeJsonFileSync_1.writeJsonFileSync)(this.filepath, tslib_1.__classPrivateFieldGet(this, _JsonFile_data, "f"), this.prettyPrint);
136
+ }
137
+ /**
138
+ * Loads the data from the JSON file.
139
+ */
140
+ loadFile() {
141
+ tslib_1.__classPrivateFieldSet(this, _JsonFile_data, (0, readJsonFileSync_1.readJsonFileSync)(this.filepath), "f");
142
+ }
143
+ }
144
+ exports.JsonFile = JsonFile;
145
+ _JsonFile_data = new WeakMap();
146
+ //# sourceMappingURL=JsonFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsonFile.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/JsonFile.ts"],"names":[],"mappings":";;;;;AAAA,4DAAiC;AACjC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;QACN,+BAAA,IAAI,kBAAS,IAAA,mCAAgB,EAAC,IAAI,CAAC,QAAQ,CAAM,MAAA,CAAA;IACnD,CAAC;CACF;AApJD,4BAoJC"}
@@ -48,4 +48,3 @@ export declare class LogFile<T> {
48
48
  */
49
49
  ensureDirectoryExists(): void;
50
50
  }
51
- //# sourceMappingURL=LogFile.d.ts.map
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LogFile = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
6
+ const path_1 = tslib_1.__importDefault(require("path"));
7
+ const readline_1 = tslib_1.__importDefault(require("readline"));
8
+ /**
9
+ * Represents a log file manager that appends log entries to a file.
10
+ * It does not ensure extremely precise ordering of log entries' timestamps if used asynchronously. It logs them as they are received.
11
+ */
12
+ class LogFile {
13
+ /**
14
+ * Creates a new instance of the LogFile class.
15
+ * @param filepath - The path to the log file.
16
+ */
17
+ constructor(filepath) {
18
+ this.filepath = filepath;
19
+ this.ensureDirectoryExists();
20
+ }
21
+ /**
22
+ * Appends a log entry to the log file.
23
+ * @param data - The data to be logged.
24
+ * @param time - The timestamp of the log entry. Defaults to the current time.
25
+ * @returns A promise that resolves when the log entry is appended.
26
+ */
27
+ append(data, time = Date.now()) {
28
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
29
+ yield fs_1.default.promises.appendFile(this.filepath, time + '|' + JSON.stringify(data) + '\n', 'utf8');
30
+ });
31
+ }
32
+ /**
33
+ * Resets the log file by removing it.
34
+ */
35
+ reset() {
36
+ fs_1.default.rmSync(this.filepath);
37
+ }
38
+ /**
39
+ * Reads the log entire file and returns an array of log entries, sorted by timestamp in descending order.
40
+ * @returns An array of log entries, sorted by timestamp in descending order.
41
+ */
42
+ readFile() {
43
+ const data = fs_1.default.readFileSync(this.filepath, 'utf8');
44
+ const lines = data.split('\n');
45
+ const result = [];
46
+ for (const line of lines) {
47
+ const i = line.indexOf('|');
48
+ if (i === -1)
49
+ continue;
50
+ const time = parseInt(line.substring(0, i));
51
+ const data = JSON.parse(line.substring(i + 1));
52
+ result.push([time, data]);
53
+ }
54
+ return result.sort((a, b) => b[0] - a[0]);
55
+ }
56
+ /**
57
+ * Returns an async generator that yields the timestamps of log entries in the log file.
58
+ * @yields The timestamps of log entries.
59
+ */
60
+ keys() {
61
+ return tslib_1.__asyncGenerator(this, arguments, function* keys_1() {
62
+ var _a, e_1, _b, _c;
63
+ const fileStream = fs_1.default.createReadStream(this.filepath, 'utf8');
64
+ const rl = readline_1.default.createInterface({
65
+ input: fileStream,
66
+ crlfDelay: Infinity,
67
+ });
68
+ try {
69
+ for (var _d = true, rl_1 = tslib_1.__asyncValues(rl), rl_1_1; rl_1_1 = yield tslib_1.__await(rl_1.next()), _a = rl_1_1.done, !_a; _d = true) {
70
+ _c = rl_1_1.value;
71
+ _d = false;
72
+ const line = _c;
73
+ const i = line.indexOf('|');
74
+ const time = parseInt(line.substring(0, i));
75
+ yield yield tslib_1.__await(time);
76
+ }
77
+ }
78
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
79
+ finally {
80
+ try {
81
+ if (!_d && !_a && (_b = rl_1.return)) yield tslib_1.__await(_b.call(rl_1));
82
+ }
83
+ finally { if (e_1) throw e_1.error; }
84
+ }
85
+ });
86
+ }
87
+ /**
88
+ * Returns an async generator that yields the values of log entries in the log file.
89
+ * @yields The values of log entries.
90
+ */
91
+ values() {
92
+ return tslib_1.__asyncGenerator(this, arguments, function* values_1() {
93
+ var _a, e_2, _b, _c;
94
+ const fileStream = fs_1.default.createReadStream(this.filepath, 'utf8');
95
+ const rl = readline_1.default.createInterface({
96
+ input: fileStream,
97
+ crlfDelay: Infinity,
98
+ });
99
+ try {
100
+ for (var _d = true, rl_2 = tslib_1.__asyncValues(rl), rl_2_1; rl_2_1 = yield tslib_1.__await(rl_2.next()), _a = rl_2_1.done, !_a; _d = true) {
101
+ _c = rl_2_1.value;
102
+ _d = false;
103
+ const line = _c;
104
+ const i = line.indexOf('|');
105
+ const data = JSON.parse(line.substring(i + 1));
106
+ yield yield tslib_1.__await(data);
107
+ }
108
+ }
109
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
110
+ finally {
111
+ try {
112
+ if (!_d && !_a && (_b = rl_2.return)) yield tslib_1.__await(_b.call(rl_2));
113
+ }
114
+ finally { if (e_2) throw e_2.error; }
115
+ }
116
+ });
117
+ }
118
+ /**
119
+ * Returns an async generator that yields the entries (timestamp and value) of log entries in the log file.
120
+ * @yields The entries (timestamp and value) of log entries.
121
+ */
122
+ entries() {
123
+ return tslib_1.__asyncGenerator(this, arguments, function* entries_1() {
124
+ var _a, e_3, _b, _c;
125
+ const fileStream = fs_1.default.createReadStream(this.filepath, 'utf8');
126
+ const rl = readline_1.default.createInterface({
127
+ input: fileStream,
128
+ crlfDelay: Infinity,
129
+ });
130
+ try {
131
+ for (var _d = true, rl_3 = tslib_1.__asyncValues(rl), rl_3_1; rl_3_1 = yield tslib_1.__await(rl_3.next()), _a = rl_3_1.done, !_a; _d = true) {
132
+ _c = rl_3_1.value;
133
+ _d = false;
134
+ const line = _c;
135
+ const i = line.indexOf('|');
136
+ const time = parseInt(line.substring(0, i));
137
+ const data = JSON.parse(line.substring(i + 1));
138
+ yield yield tslib_1.__await([time, data]);
139
+ }
140
+ }
141
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
142
+ finally {
143
+ try {
144
+ if (!_d && !_a && (_b = rl_3.return)) yield tslib_1.__await(_b.call(rl_3));
145
+ }
146
+ finally { if (e_3) throw e_3.error; }
147
+ }
148
+ });
149
+ }
150
+ /**
151
+ * Ensures that the directory containing the log file exists.
152
+ */
153
+ ensureDirectoryExists() {
154
+ fs_1.default.mkdirSync(path_1.default.dirname(this.filepath), { recursive: true });
155
+ }
156
+ }
157
+ exports.LogFile = LogFile;
158
+ //# sourceMappingURL=LogFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LogFile.js","sourceR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G,CAAC,CAAA;oBAC3B,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,CAAM,CAAA;oBACnD,4BAAM,IAAI,CAAA,CAAA;iBACX;;;;;;;;;QACH,CAAC;KAAA;IAED;;;OAGG;IACI,OAAO;;;YACZ,MAAM,UAAU,GAAG,YAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;YAC7D,MAAM,EAAE,GAAG,kBAAQ,CAAC,eAAe,CAAC;gBAClC,KAAK,EAAE,UAAU;gBACjB,SAAS,EAAE,QAAQ;aACpB,CAAC,CAAA;;gBACF,KAAyB,eAAA,OAAA,sBAAA,EAAE,CAAA,QAAA,iFAAE;oBAAJ,kBAAE;oBAAF,WAAE;oBAAhB,MAAM,IAAI,KAAA,CAAA;oBACnB,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;oBAC3B,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;oBAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,CAAM,CAAA;oBACnD,4BAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA,CAAA;iBACnB;;;;;;;;;QACH,CAAC;KAAA;IAED;;OAEG;IACH,qBAAqB;QACnB,YAAE,CAAC,SAAS,CAAC,cAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IAChE,CAAC;CACF;AA5GD,0BA4GC"}
@@ -11,4 +11,3 @@
11
11
  * ```
12
12
  */
13
13
  export declare function absoluteToRelativePath(absolute: string, workingDirectory?: string): string;
14
- //# sourceMappingURL=absoluteToRelativePath.d.ts.map
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.absoluteToRelativePath = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const string_1 = require("@bemoje/string");
6
+ const path_1 = tslib_1.__importDefault(require("path"));
7
+ /**
8
+ * If the filepath is somewhere in the current working directory, it can be converted into a relative path.
9
+ * @remarks This function takes an absolute path as input and returns a relative path. It replaces the current working directory in the path with an empty string,
10
+ * replaces all backslashes with forward slashes, and removes any leading forward slashes.
11
+ * @param workingDirectory The directory relative to which the path should be converted. Defaults to the current working directory.
12
+ * @returns The relative path.
13
+ * @param absolute the absolute filepath to convert.
14
+ * @example ```ts
15
+ * absoluteToRelativePath(__filename)
16
+ * //=> 'src/absoluteToRelativePath.ts'
17
+ * ```
18
+ */
19
+ function absoluteToRelativePath(absolute, workingDirectory = process.cwd()) {
20
+ return path_1.default
21
+ .normalize(absolute)
22
+ .replace(new RegExp((0, string_1.regexEscapeString)(path_1.default.normalize(workingDirectory) + path_1.default.sep), 'i'), '');
23
+ }
24
+ exports.absoluteToRelativePath = absoluteToRelativePath;
25
+ //# sourceMappingURL=absoluteToRelativePath.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"absoluteToRelativePath.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/absoluteToRelativePath.ts"],"names":[],"mappings":";;;;AAAA,2CAAkD;AAClD,wDAAuB;AAEvB;;;;;;;;;;;GAWG;AACH,SAAgB,sBAAsB,CAAC,QAAgB,EAAE,gBAAgB,GAAG,OAAO,CAAC,GAAG,EAAE;IACvF,OAAO,cAAI;SACR,SAAS,CAAC,QAAQ,CAAC;SACnB,OAAO,CAAC,IAAI,MAAM,CAAC,IAAA,0BAAiB,EAAC,cAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,GAAG,cAAI,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAA;AACjG,CAAC;AAJD,wDAIC"}
@@ -9,4 +9,3 @@
9
9
  * ```
10
10
  */
11
11
  export declare function appendLineToFile(filepath: string, line: string, linebreakBefore?: boolean): Promise<void>;
12
- //# sourceMappingURL=appendLineToFile.d.ts.map
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.appendLineToFile = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
6
+ const path_1 = tslib_1.__importDefault(require("path"));
7
+ const createDirectory_1 = require("./createDirectory");
8
+ /**
9
+ * Append a line to a file. Creates the file if it does not exist.
10
+ * @param filepath The path of the file.
11
+ * @param line The string data to append.
12
+ * @returns A Promise that resolves when the line has been appended to the file.
13
+ * @throws Will throw an error if the operation fails.
14
+ * @example ```ts
15
+ * await appendLineToFile('/path/to/file', 'This is a new line')
16
+ * ```
17
+ */
18
+ function appendLineToFile(filepath, line, linebreakBefore = false) {
19
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
20
+ if (!fs_1.default.existsSync(filepath)) {
21
+ yield (0, createDirectory_1.createDirectory)(path_1.default.dirname(filepath));
22
+ yield fs_1.default.promises.writeFile(filepath, '');
23
+ }
24
+ yield fs_1.default.promises.appendFile(filepath, linebreakBefore ? '\n' + line : line + '\n');
25
+ });
26
+ }
27
+ exports.appendLineToFile = appendLineToFile;
28
+ //# sourceMappingURL=appendLineToFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"appendLineToFile.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/appendLineToFile.ts"],"names":[],"mappings":";;;;AAAA,oDAAmB;AACnB,wDAAuB;AACvB,uDAAmD;AAEnD;;;;;;;;;GASG;AACH,SAAsB,gBAAgB,CAAC,QAAgB,EAAE,IAAY,EAAE,eAAe,GAAG,KAAK;;QAC5F,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;YAC5B,MAAM,IAAA,iCAAe,EAAC,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAA;YAC7C,MAAM,YAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;SAC1C;QACD,MAAM,YAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,CAAA;IACrF,CAAC;CAAA;AAND,4CAMC"}
@@ -14,4 +14,3 @@ import type { Stats } from 'fs';
14
14
  * ```
15
15
  */
16
16
  export declare function cleanDirectorySync(dirpath: string, predicate: (filepath: string, stat: Stats) => boolean): void;
17
- //# sourceMappingURL=cleanDirectorySync.d.ts.map
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cleanDirectorySync = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
6
+ const path_1 = tslib_1.__importDefault(require("path"));
7
+ /**
8
+ * Synchronously cleans a directory by removing files that satisfy a given predicate.
9
+ * @remarks This function is a part of the File System module.
10
+ * @param dirpath - The path to the directory that needs to be cleaned.
11
+ * @param predicate - A function that takes a filepath and its stats as arguments and returns a boolean. If the function returns true for a file, that file is removed from the directory.
12
+ * @throws If the directory at the provided path does not exist or cannot be read.
13
+ * @example ```ts
14
+ * import { Stats } from 'fs';
15
+ * const dirpath = './my-directory';
16
+ * const predicate = (filepath: string, stat: Stats) => stat.size > 1024;
17
+ * cleanDirectorySync(dirpath, predicate);
18
+ * ```
19
+ */
20
+ function cleanDirectorySync(dirpath, predicate) {
21
+ for (const filename of fs_1.default.readdirSync(dirpath)) {
22
+ const filepath = path_1.default.join(dirpath, filename);
23
+ const stat = fs_1.default.statSync(filepath);
24
+ if (predicate(filepath, stat))
25
+ fs_1.default.unlinkSync(filepath);
26
+ }
27
+ }
28
+ exports.cleanDirectorySync = cleanDirectorySync;
29
+ //# sourceMappingURL=cleanDirectorySync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cleanDirectorySync.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/cleanDirectorySync.ts"],"names":[],"mappings":";;;;AACA,oDAAmB;AACnB,wDAAuB;AAEvB;;;;;;;;;;;;GAYG;AACH,SAAgB,kBAAkB,CAAC,OAAe,EAAE,SAAqD;IACvG,KAAK,MAAM,QAAQ,IAAI,YAAE,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE;QAC9C,MAAM,QAAQ,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;QAC7C,MAAM,IAAI,GAAG,YAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;QAClC,IAAI,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC;YAAE,YAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;KACvD;AACH,CAAC;AAND,gDAMC"}
@@ -11,4 +11,3 @@
11
11
  * ```
12
12
  */
13
13
  export declare function createDirectory(dirpath: string): Promise<string>;
14
- //# sourceMappingURL=createDirectory.d.ts.map