UNPKG

2.04 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var FilesRegister = /** @class */ (function () {
4 function FilesRegister(dataFactory) {
5 this.dataFactory = dataFactory;
6 this.files = {};
7 this.dataFactory = dataFactory;
8 }
9 FilesRegister.prototype.keys = function () {
10 return Object.keys(this.files);
11 };
12 FilesRegister.prototype.add = function (filePath) {
13 this.files[filePath] = {
14 mtime: undefined,
15 data: this.dataFactory(undefined)
16 };
17 };
18 FilesRegister.prototype.remove = function (filePath) {
19 if (this.has(filePath)) {
20 delete this.files[filePath];
21 }
22 };
23 FilesRegister.prototype.has = function (filePath) {
24 return this.files.hasOwnProperty(filePath);
25 };
26 FilesRegister.prototype.get = function (filePath) {
27 if (!this.has(filePath)) {
28 throw new Error('File "' + filePath + '" not found in register.');
29 }
30 return this.files[filePath];
31 };
32 FilesRegister.prototype.ensure = function (filePath) {
33 if (!this.has(filePath)) {
34 this.add(filePath);
35 }
36 };
37 FilesRegister.prototype.getData = function (filePath) {
38 return this.get(filePath).data;
39 };
40 FilesRegister.prototype.mutateData = function (filePath, mutator) {
41 this.ensure(filePath);
42 mutator(this.files[filePath].data);
43 };
44 FilesRegister.prototype.getMtime = function (filePath) {
45 return this.get(filePath).mtime;
46 };
47 FilesRegister.prototype.setMtime = function (filePath, mtime) {
48 this.ensure(filePath);
49 if (this.files[filePath].mtime !== mtime) {
50 this.files[filePath].mtime = mtime;
51 // file has been changed - we have to reset data
52 this.files[filePath].data = this.dataFactory(this.files[filePath].data);
53 }
54 };
55 return FilesRegister;
56}());
57exports.FilesRegister = FilesRegister;
58//# sourceMappingURL=FilesRegister.js.map
\No newline at end of file