@breadstone-tools/localizator-core 0.0.39 → 0.0.40
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/Index.d.ts +4 -4
- package/Index.d.ts.map +1 -1
- package/Index.js +7 -7
- package/Index.js.map +1 -1
- package/Resources/Models/TypeScriptResourceInfo.d.ts +1 -1
- package/Resources/Models/TypeScriptResourceInfo.js +3 -3
- package/Resources/Models/TypeScriptResourceInfo.js.map +1 -1
- package/Resources/Readers/Adapter/Interfaces/IResourceReaderAdapter.d.ts +26 -0
- package/Resources/Readers/Adapter/Interfaces/IResourceReaderAdapter.d.ts.map +1 -0
- package/Resources/Readers/Adapter/Interfaces/IResourceReaderAdapter.js +4 -0
- package/Resources/Readers/Adapter/Interfaces/IResourceReaderAdapter.js.map +1 -0
- package/Resources/Readers/Adapter/JsonResourceReaderAdapter.d.ts +44 -0
- package/Resources/Readers/Adapter/JsonResourceReaderAdapter.d.ts.map +1 -0
- package/Resources/Readers/Adapter/JsonResourceReaderAdapter.js +120 -0
- package/Resources/Readers/Adapter/JsonResourceReaderAdapter.js.map +1 -0
- package/Resources/Readers/Adapter/ResxResourceReaderAdapter.d.ts +44 -0
- package/Resources/Readers/Adapter/ResxResourceReaderAdapter.d.ts.map +1 -0
- package/Resources/Readers/Adapter/ResxResourceReaderAdapter.js +120 -0
- package/Resources/Readers/Adapter/ResxResourceReaderAdapter.js.map +1 -0
- package/Resources/Readers/ResourceReader.d.ts +41 -0
- package/Resources/Readers/ResourceReader.d.ts.map +1 -0
- package/Resources/Readers/ResourceReader.js +77 -0
- package/Resources/Readers/ResourceReader.js.map +1 -0
- package/Resources/ResourceMode.d.ts +10 -4
- package/Resources/ResourceMode.d.ts.map +1 -1
- package/Resources/ResourceMode.js +6 -5
- package/Resources/ResourceMode.js.map +1 -1
- package/Resources/ResourceProcessor.d.ts +3 -3
- package/Resources/ResourceProcessor.d.ts.map +1 -1
- package/Resources/ResourceProcessor.js +4 -4
- package/Resources/ResourceProcessor.js.map +1 -1
- package/Resources/Scanners/Adapter/Interfaces/IResourceReaderAdapter.d.ts +26 -0
- package/Resources/Scanners/Adapter/Interfaces/IResourceReaderAdapter.d.ts.map +1 -0
- package/Resources/Scanners/Adapter/Interfaces/IResourceReaderAdapter.js +4 -0
- package/Resources/Scanners/Adapter/Interfaces/IResourceReaderAdapter.js.map +1 -0
- package/Resources/Scanners/Adapter/JsonResourceReaderAdapter.d.ts +44 -0
- package/Resources/Scanners/Adapter/JsonResourceReaderAdapter.d.ts.map +1 -0
- package/Resources/Scanners/Adapter/JsonResourceReaderAdapter.js +120 -0
- package/Resources/Scanners/Adapter/JsonResourceReaderAdapter.js.map +1 -0
- package/Resources/Scanners/Adapter/JsonScannerAdapter.d.ts +5 -1
- package/Resources/Scanners/Adapter/JsonScannerAdapter.d.ts.map +1 -1
- package/Resources/Scanners/Adapter/JsonScannerAdapter.js +20 -2
- package/Resources/Scanners/Adapter/JsonScannerAdapter.js.map +1 -1
- package/Resources/Scanners/Adapter/ResxResourceReaderAdapter.d.ts +44 -0
- package/Resources/Scanners/Adapter/ResxResourceReaderAdapter.d.ts.map +1 -0
- package/Resources/Scanners/Adapter/ResxResourceReaderAdapter.js +120 -0
- package/Resources/Scanners/Adapter/ResxResourceReaderAdapter.js.map +1 -0
- package/Resources/Scanners/Adapter/ResxScannerAdapter.d.ts +5 -1
- package/Resources/Scanners/Adapter/ResxScannerAdapter.d.ts.map +1 -1
- package/Resources/Scanners/Adapter/ResxScannerAdapter.js +20 -2
- package/Resources/Scanners/Adapter/ResxScannerAdapter.js.map +1 -1
- package/Resources/Scanners/ResourceReader.d.ts +41 -0
- package/Resources/Scanners/ResourceReader.d.ts.map +1 -0
- package/Resources/Scanners/ResourceReader.js +77 -0
- package/Resources/Scanners/ResourceReader.js.map +1 -0
- package/Resources/Scanners/ResourceScanner.d.ts +16 -7
- package/Resources/Scanners/ResourceScanner.d.ts.map +1 -1
- package/Resources/Scanners/ResourceScanner.js +32 -14
- package/Resources/Scanners/ResourceScanner.js.map +1 -1
- package/Resources/Transformers/ResourceTransformer.d.ts +3 -3
- package/Resources/Transformers/ResourceTransformer.js +3 -3
- package/package.json +2 -2
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// #region Imports
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ResxResourceReaderAdapter = void 0;
|
|
5
|
+
const utilities_1 = require("@breadstone-infrastructure/utilities");
|
|
6
|
+
const ResxResourceInfo_1 = require("../../Models/ResxResourceInfo");
|
|
7
|
+
const ResourceType_1 = require("../../Models/Interfaces/ResourceType");
|
|
8
|
+
// #endregion
|
|
9
|
+
/**
|
|
10
|
+
* A resource reader adapter that scans directories for RESX files.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
class ResxResourceReaderAdapter {
|
|
15
|
+
// #region Fields
|
|
16
|
+
_fileSystem;
|
|
17
|
+
_logger;
|
|
18
|
+
_glob;
|
|
19
|
+
// #endregion
|
|
20
|
+
// #region Ctor
|
|
21
|
+
/**
|
|
22
|
+
* Constructs a new instance of the `ResxResourceReaderAdapter` class.
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
constructor(fileSystem, logger) {
|
|
27
|
+
this._fileSystem = fileSystem;
|
|
28
|
+
this._logger = logger;
|
|
29
|
+
this._glob = '**/*.resx';
|
|
30
|
+
}
|
|
31
|
+
// #endregion
|
|
32
|
+
// #region Methods
|
|
33
|
+
/**
|
|
34
|
+
* Scans the specified directory for .resx files.
|
|
35
|
+
*
|
|
36
|
+
* @public
|
|
37
|
+
* @param path - The directory to scan.
|
|
38
|
+
* @returns The resource information.
|
|
39
|
+
*/
|
|
40
|
+
scanDirectory(path) {
|
|
41
|
+
this.invalidateDirectory(path);
|
|
42
|
+
const globPath = utilities_1.Path.combine(path, this._glob);
|
|
43
|
+
this._logger.log(` Scanning ${(0, utilities_1.gray)(globPath)}`);
|
|
44
|
+
const scans = this._fileSystem.glob(globPath).map((file) => {
|
|
45
|
+
this._logger.log(` Scanning ${(0, utilities_1.gray)(utilities_1.Path.getFileName(file))}`);
|
|
46
|
+
const resx = this._fileSystem.readAllResx(file);
|
|
47
|
+
this._logger.log(` Found ${(0, utilities_1.bold)(resx.length.toString())} keys in language ${(0, utilities_1.bold)(this._fileSystem.getLocale(file))}`);
|
|
48
|
+
return {
|
|
49
|
+
file: file,
|
|
50
|
+
content: () => resx
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
return scans.map((scan) => new ResxResourceInfo_1.ResxResourceInfo({
|
|
54
|
+
type: ResourceType_1.ResourceType.Resx,
|
|
55
|
+
content: scan.content,
|
|
56
|
+
locale: this._fileSystem.getLocale(scan.file),
|
|
57
|
+
name: this._fileSystem.getFileName(scan.file),
|
|
58
|
+
path: scan.file
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Scans a specific file for resource information.
|
|
63
|
+
*
|
|
64
|
+
* @public
|
|
65
|
+
* @param path - The path to the file to scan.
|
|
66
|
+
* @returns The resource information or null if the file is not a valid resource.
|
|
67
|
+
*/
|
|
68
|
+
scanFile(path) {
|
|
69
|
+
this.invalidateFile(path);
|
|
70
|
+
const resx = this._fileSystem.readAllResx(path);
|
|
71
|
+
if (resx.length === 0) {
|
|
72
|
+
this._logger.warn(`The file ${(0, utilities_1.gray)(path)} does not contain any resources.`);
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
this._logger.log(` Found ${(0, utilities_1.bold)(resx.length.toString())} keys in language ${(0, utilities_1.bold)(this._fileSystem.getLocale(path))}`);
|
|
76
|
+
return new ResxResourceInfo_1.ResxResourceInfo({
|
|
77
|
+
type: ResourceType_1.ResourceType.Resx,
|
|
78
|
+
content: () => resx,
|
|
79
|
+
locale: this._fileSystem.getLocale(path),
|
|
80
|
+
name: this._fileSystem.getFileName(path),
|
|
81
|
+
path: path
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* @private
|
|
86
|
+
*/
|
|
87
|
+
invalidateDirectory(path) {
|
|
88
|
+
if (this._fileSystem.isFileOrDirectory(path) !== 'directory') {
|
|
89
|
+
throw new Error(`The path ${(0, utilities_1.gray)(path)} is not a valid directory.`);
|
|
90
|
+
}
|
|
91
|
+
if (!this._fileSystem.exists(path)) {
|
|
92
|
+
throw new Error(`The path ${(0, utilities_1.gray)(path)} does not exist.`);
|
|
93
|
+
}
|
|
94
|
+
if (this._fileSystem.glob(path).length === 0) {
|
|
95
|
+
throw new Error(`The path ${(0, utilities_1.gray)(path)} is empty or does not contain any files.`);
|
|
96
|
+
}
|
|
97
|
+
if (this._glob.endsWith(this._glob)) {
|
|
98
|
+
throw new Error(`The path should not end with ${(0, utilities_1.gray)(this._glob)}.`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* @private
|
|
103
|
+
*/
|
|
104
|
+
invalidateFile(path) {
|
|
105
|
+
if (this._fileSystem.isFileOrDirectory(path) !== 'file') {
|
|
106
|
+
throw new Error(`The path ${(0, utilities_1.gray)(path)} is not a valid file.`);
|
|
107
|
+
}
|
|
108
|
+
if (!this._fileSystem.exists(path)) {
|
|
109
|
+
throw new Error(`The path ${(0, utilities_1.gray)(path)} does not exist.`);
|
|
110
|
+
}
|
|
111
|
+
if (!this._fileSystem.glob(path).length) {
|
|
112
|
+
throw new Error(`The path ${(0, utilities_1.gray)(path)} does not contain any files.`);
|
|
113
|
+
}
|
|
114
|
+
if (!path.endsWith('.resx')) {
|
|
115
|
+
throw new Error('The path should end with .resx.');
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.ResxResourceReaderAdapter = ResxResourceReaderAdapter;
|
|
120
|
+
//# sourceMappingURL=ResxResourceReaderAdapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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AI,CAAC,uBAAuB,CAAC,CAAC;QACnE,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC,YAAY,IAAA,gBAAI,EAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;QAC9D,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;YACtC,MAAM,IAAI,KAAK,CAAC,YAAY,IAAA,gBAAI,EAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;QAC1E,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;QACvD,CAAC;IACL,CAAC;CAIJ;AAvID,8DAuIC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IScannerAdapter } from './Interfaces/
|
|
1
|
+
import type { IScannerAdapter } from './Interfaces/IResourceReaderAdapter';
|
|
2
2
|
import type { IResxResourceInfo } from '../../Models/Interfaces/IResxResourceInfo';
|
|
3
3
|
import { type IFileSystem, type ILogger } from '@breadstone-infrastructure/utilities';
|
|
4
4
|
/**
|
|
@@ -24,5 +24,9 @@ export declare class ResxScannerAdapter implements IScannerAdapter {
|
|
|
24
24
|
* @returns The resource information.
|
|
25
25
|
*/
|
|
26
26
|
scan(path: string): Array<IResxResourceInfo>;
|
|
27
|
+
/**
|
|
28
|
+
* @private
|
|
29
|
+
*/
|
|
30
|
+
private invalidatePath;
|
|
27
31
|
}
|
|
28
32
|
//# sourceMappingURL=ResxScannerAdapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResxScannerAdapter.d.ts","sourceRoot":"","sources":["../../../../src/Resources/Scanners/Adapter/ResxScannerAdapter.ts"],"names":[],"mappings":"AAEA,OAAO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ScannerAdapter {
|
|
|
38
38
|
* @returns The resource information.
|
|
39
39
|
*/
|
|
40
40
|
scan(path) {
|
|
41
|
+
this.invalidatePath(path);
|
|
41
42
|
const globPath = utilities_1.Path.combine(path, this._glob);
|
|
42
43
|
this._logger.log(` Scanning ${(0, utilities_1.gray)(globPath)}`);
|
|
43
|
-
const
|
|
44
|
+
const scans = this._fileSystem.glob(globPath).map((file) => {
|
|
44
45
|
this._logger.log(` Scanning ${(0, utilities_1.gray)(utilities_1.Path.getFileName(file))}`);
|
|
45
46
|
const resx = this._fileSystem.readAllResx(file);
|
|
46
47
|
this._logger.log(` Found ${(0, utilities_1.bold)(resx.length.toString())} keys in language ${(0, utilities_1.bold)(this._fileSystem.getLocale(file))}`);
|
|
@@ -49,7 +50,7 @@ class ResxScannerAdapter {
|
|
|
49
50
|
content: () => resx
|
|
50
51
|
};
|
|
51
52
|
});
|
|
52
|
-
return
|
|
53
|
+
return scans.map((scan) => new ResxResourceInfo_1.ResxResourceInfo({
|
|
53
54
|
type: ResourceType_1.ResourceType.Resx,
|
|
54
55
|
content: scan.content,
|
|
55
56
|
locale: this._fileSystem.getLocale(scan.file),
|
|
@@ -57,6 +58,23 @@ class ResxScannerAdapter {
|
|
|
57
58
|
path: scan.file
|
|
58
59
|
}));
|
|
59
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* @private
|
|
63
|
+
*/
|
|
64
|
+
invalidatePath(path) {
|
|
65
|
+
if (this._fileSystem.isFileOrDirectory(path) !== 'directory') {
|
|
66
|
+
throw new Error(`The path ${(0, utilities_1.gray)(path)} is not a valid directory.`);
|
|
67
|
+
}
|
|
68
|
+
if (!this._fileSystem.exists(path)) {
|
|
69
|
+
throw new Error(`The path ${(0, utilities_1.gray)(path)} does not exist.`);
|
|
70
|
+
}
|
|
71
|
+
if (this._fileSystem.glob(path).length === 0) {
|
|
72
|
+
throw new Error(`The path ${(0, utilities_1.gray)(path)} is empty or does not contain any files.`);
|
|
73
|
+
}
|
|
74
|
+
if (this._glob.endsWith(this._glob)) {
|
|
75
|
+
throw new Error(`The glob pattern ${(0, utilities_1.gray)(this._glob)} should not end with .resx.`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
60
78
|
}
|
|
61
79
|
exports.ResxScannerAdapter = ResxScannerAdapter;
|
|
62
80
|
//# sourceMappingURL=ResxScannerAdapter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResxScannerAdapter.js","sourceRoot":"","sources":["../../../../src/Resources/Scanners/Adapter/ResxScannerAdapter.ts"],"names":[],"mappings":";AAAA,kBAAkB;;;AAIlB,oEAAwG;AACxG,oEAAiE;AACjE,uEAAoE;AAEpE,aAAa;AAEb;;;;GAIG;AACH,MAAa,kBAAkB;IAE3B,iBAAiB;IAEA,WAAW,CAAc;IACzB,OAAO,CAAU;IACjB,KAAK,CAAS;IAE/B,aAAa;IAEb,eAAe;IAEf;;;;OAIG;IACH,YAAmB,UAAuB,EAAE,MAAe;QACvD,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC;IAC7B,CAAC;IAED,aAAa;IAEb,kBAAkB;IAElB;;;;;;OAMG;IACI,IAAI,CAAC,IAAY;QACpB,MAAM,QAAQ,GAAG,gBAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QAEhD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,IAAA,gBAAI,EAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAEjD,MAAM,
|
|
1
|
+
{"version":3,"file":"ResxScannerAdapter.js","sourceRoot":"","sources":["../../../../src/Resources/Scanners/Adapter/ResxScannerAdapter.ts"],"names":[],"mappings":";AAAA,kBAAkB;;;AAIlB,oEAAwG;AACxG,oEAAiE;AACjE,uEAAoE;AAEpE,aAAa;AAEb;;;;GAIG;AACH,MAAa,kB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sFC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { IResourceInfo } from '../Models/Interfaces/IResourceInfo';
|
|
2
|
+
import { ResourceMode } from '../ResourceMode';
|
|
3
|
+
import { type IFileSystem, type ILogger } from '@breadstone-infrastructure/utilities';
|
|
4
|
+
/**
|
|
5
|
+
* The `ResourceReader` class is responsible for processing resources.
|
|
6
|
+
* It can be resolves json or resx files.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export declare class ResourceReader {
|
|
11
|
+
private readonly _fileSystem;
|
|
12
|
+
private readonly _logger;
|
|
13
|
+
private readonly _adapters;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new instance of `ResourceReader`.
|
|
16
|
+
*
|
|
17
|
+
* @public
|
|
18
|
+
* @param logger - The logger interface.
|
|
19
|
+
* @param fileSystem - The file system interface.
|
|
20
|
+
*/
|
|
21
|
+
constructor(logger: ILogger, fileSystem: IFileSystem);
|
|
22
|
+
/**
|
|
23
|
+
* Scans a directory for resources of the given type.
|
|
24
|
+
*
|
|
25
|
+
* @public
|
|
26
|
+
* @param path - The path to scan.
|
|
27
|
+
* @param type - The type of resource to scan for.
|
|
28
|
+
* @returns An array of resource information found in the directory.
|
|
29
|
+
*/
|
|
30
|
+
scanDirectory(path: string, type: ResourceMode): Array<IResourceInfo>;
|
|
31
|
+
/**
|
|
32
|
+
* Scans a specific file for resources of the given type.
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
35
|
+
* @param path - The path to the file to scan.
|
|
36
|
+
* @param type - The type of resource to scan for.
|
|
37
|
+
* @returns The resource information or null if the file is not a valid resource.
|
|
38
|
+
*/
|
|
39
|
+
scanFile(path: string, type: ResourceMode): IResourceInfo | null;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=ResourceReader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResourceReader.d.ts","sourceRoot":"","sources":["../../../src/Resources/Scanners/ResourceReader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAQ,KAAK,WAAW,EAAE,KAAK,OAAO,EAAsB,MAAM,sCAAsC,CAAC;AAIhH;;;;;GAKG;AACH,qBAAa,cAAc;IAIvB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAc;IAC1C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAClC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA4C;IAMtE;;;;;;OAMG;gBACgB,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW;IAY3D;;;;;;;OAOG;IACI,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,KAAK,CAAC,aAAa,CAAC;IAgB5E;;;;;;;OAOG;IACI,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,aAAa,GAAG,IAAI;CAkB1E"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// #region Imports
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ResourceReader = void 0;
|
|
5
|
+
const JsonResourceReaderAdapter_1 = require("./Adapter/JsonResourceReaderAdapter");
|
|
6
|
+
const ResourceMode_1 = require("../ResourceMode");
|
|
7
|
+
const ResxResourceReaderAdapter_1 = require("./Adapter/ResxResourceReaderAdapter");
|
|
8
|
+
const utilities_1 = require("@breadstone-infrastructure/utilities");
|
|
9
|
+
// #endregion
|
|
10
|
+
/**
|
|
11
|
+
* The `ResourceReader` class is responsible for processing resources.
|
|
12
|
+
* It can be resolves json or resx files.
|
|
13
|
+
*
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
class ResourceReader {
|
|
17
|
+
// #region Fields
|
|
18
|
+
_fileSystem;
|
|
19
|
+
_logger;
|
|
20
|
+
_adapters;
|
|
21
|
+
// #endregion
|
|
22
|
+
// #region Ctor
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new instance of `ResourceReader`.
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
27
|
+
* @param logger - The logger interface.
|
|
28
|
+
* @param fileSystem - The file system interface.
|
|
29
|
+
*/
|
|
30
|
+
constructor(logger, fileSystem) {
|
|
31
|
+
this._fileSystem = fileSystem;
|
|
32
|
+
this._logger = logger;
|
|
33
|
+
this._adapters = new Map()
|
|
34
|
+
.set(ResourceMode_1.ResourceMode.Json, new JsonResourceReaderAdapter_1.JsonResourceReaderAdapter(this._fileSystem, this._logger))
|
|
35
|
+
.set(ResourceMode_1.ResourceMode.Resx, new ResxResourceReaderAdapter_1.ResxResourceReaderAdapter(this._fileSystem, this._logger));
|
|
36
|
+
}
|
|
37
|
+
// #endregion
|
|
38
|
+
// #region Methods
|
|
39
|
+
/**
|
|
40
|
+
* Scans a directory for resources of the given type.
|
|
41
|
+
*
|
|
42
|
+
* @public
|
|
43
|
+
* @param path - The path to scan.
|
|
44
|
+
* @param type - The type of resource to scan for.
|
|
45
|
+
* @returns An array of resource information found in the directory.
|
|
46
|
+
*/
|
|
47
|
+
scanDirectory(path, type) {
|
|
48
|
+
this._logger.log((0, utilities_1.t) `${(0, utilities_1.magenta)(`Scanning for ${(0, utilities_1.bold)(type)} resources...`)}`);
|
|
49
|
+
const adapter = this._adapters.get(type);
|
|
50
|
+
if (!adapter) {
|
|
51
|
+
throw new Error('No adapter found for the specified mode.');
|
|
52
|
+
}
|
|
53
|
+
const result = adapter.scanDirectory(path);
|
|
54
|
+
this._logger.log((0, utilities_1.t) `${(0, utilities_1.magenta)(`Scanning complete.${result.length === 0 ? (0, utilities_1.yellow)(' No resources found.') : ''}`)}`);
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Scans a specific file for resources of the given type.
|
|
59
|
+
*
|
|
60
|
+
* @public
|
|
61
|
+
* @param path - The path to the file to scan.
|
|
62
|
+
* @param type - The type of resource to scan for.
|
|
63
|
+
* @returns The resource information or null if the file is not a valid resource.
|
|
64
|
+
*/
|
|
65
|
+
scanFile(path, type) {
|
|
66
|
+
this._logger.log((0, utilities_1.t) `${(0, utilities_1.magenta)(`Scanning for ${(0, utilities_1.bold)(type)} resource in file...`)}`);
|
|
67
|
+
const adapter = this._adapters.get(type);
|
|
68
|
+
if (!adapter) {
|
|
69
|
+
throw new Error('No adapter found for the specified mode.');
|
|
70
|
+
}
|
|
71
|
+
const result = adapter.scanFile(path);
|
|
72
|
+
this._logger.log((0, utilities_1.t) `${(0, utilities_1.magenta)(`Scanning complete.${result ? '' : (0, utilities_1.yellow)(' No resource found.')}`)}`);
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.ResourceReader = ResourceReader;
|
|
77
|
+
//# sourceMappingURL=ResourceReader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResourceReader.js","sourceRoot":"","sources":["../../../src/Resources/Scanners/ResourceReader.ts"],"names":[],"mappings":";AAAA,kBAAkB;;;AAGlB,mFAAgF;AAEhF,kDAA+C;AAC/C,mFAAgF;AAChF,oEAAgH;AAEhH,aAAa;AAEb;;;;;GAKG;AACH,MAAa,cAAc;IAEvB,iBAAiB;IAEA,WAAW,CAAc;IACzB,OAAO,CAAU;IACjB,SAAS,CAA4C;IAEtE,aAAa;IAEb,eAAe;IAEf;;;;;;OAMG;IACH,YAAmB,MAAe,EAAE,UAAuB;QACvD,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EAAwC;aAC3D,GAAG,CAAC,2BAAY,CAAC,IAAI,EAAE,IAAI,qDAAyB,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,O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X,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;QAChE,CAAC;QAED,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAEtC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAA,aAAC,EAAA,GAAG,IAAA,mBAAO,EAAC,qBAAqB,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAA,kBAAM,EAAC,qBAAqB,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QAEpG,OAAO,MAAM,CAAC;IAClB,CAAC;CAIJ;AAjFD,wCAiFC"}
|
|
@@ -2,17 +2,17 @@ import type { IResourceInfo } from './../Models/Interfaces/IResourceInfo';
|
|
|
2
2
|
import { ResourceMode } from './../ResourceMode';
|
|
3
3
|
import { type IFileSystem, type ILogger } from '@breadstone-infrastructure/utilities';
|
|
4
4
|
/**
|
|
5
|
-
* The `
|
|
5
|
+
* The `ResourceReader` class is responsible for processing resources.
|
|
6
6
|
* It can be resolves json or resx files.
|
|
7
7
|
*
|
|
8
8
|
* @public
|
|
9
9
|
*/
|
|
10
|
-
export declare class
|
|
10
|
+
export declare class ResourceReader {
|
|
11
11
|
private readonly _fileSystem;
|
|
12
12
|
private readonly _logger;
|
|
13
13
|
private readonly _adapters;
|
|
14
14
|
/**
|
|
15
|
-
* Creates a new instance of `
|
|
15
|
+
* Creates a new instance of `ResourceReader`.
|
|
16
16
|
*
|
|
17
17
|
* @public
|
|
18
18
|
* @param logger - The logger interface.
|
|
@@ -20,13 +20,22 @@ export declare class ResourceScanner {
|
|
|
20
20
|
*/
|
|
21
21
|
constructor(logger: ILogger, fileSystem: IFileSystem);
|
|
22
22
|
/**
|
|
23
|
-
* Scans
|
|
23
|
+
* Scans a directory for resources of the given type.
|
|
24
24
|
*
|
|
25
25
|
* @public
|
|
26
26
|
* @param path - The path to scan.
|
|
27
|
-
* @param type - The type of
|
|
28
|
-
* @returns
|
|
27
|
+
* @param type - The type of resource to scan for.
|
|
28
|
+
* @returns An array of resource information found in the directory.
|
|
29
29
|
*/
|
|
30
|
-
|
|
30
|
+
scanDirectory(path: string, type: ResourceMode): Array<IResourceInfo>;
|
|
31
|
+
/**
|
|
32
|
+
* Scans a specific file for resources of the given type.
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
35
|
+
* @param path - The path to the file to scan.
|
|
36
|
+
* @param type - The type of resource to scan for.
|
|
37
|
+
* @returns The resource information or null if the file is not a valid resource.
|
|
38
|
+
*/
|
|
39
|
+
scanFile(path: string, type: ResourceMode): IResourceInfo | null;
|
|
31
40
|
}
|
|
32
41
|
//# sourceMappingURL=ResourceScanner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResourceScanner.d.ts","sourceRoot":"","sources":["../../../src/Resources/Scanners/ResourceScanner.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAQ,KAAK,WAAW,EAAE,KAAK,OAAO,EAAsB,MAAM,sCAAsC,CAAC;AAIhH;;;;;GAKG;AACH,qBAAa,
|
|
1
|
+
{"version":3,"file":"ResourceScanner.d.ts","sourceRoot":"","sources":["../../../src/Resources/Scanners/ResourceScanner.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAQ,KAAK,WAAW,EAAE,KAAK,OAAO,EAAsB,MAAM,sCAAsC,CAAC;AAIhH;;;;;GAKG;AACH,qBAAa,cAAc;IAIvB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAc;IAC1C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAClC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA4C;IAMtE;;;;;;OAMG;gBACgB,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW;IAY3D;;;;;;;OAOG;IACI,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,KAAK,CAAC,aAAa,CAAC;IAgB5E;;;;;;;OAOG;IACI,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,aAAa,GAAG,IAAI;CAkB1E"}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// #region Imports
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
5
|
-
const
|
|
4
|
+
exports.ResourceReader = void 0;
|
|
5
|
+
const JsonResourceReaderAdapter_1 = require("./Adapter/JsonResourceReaderAdapter");
|
|
6
6
|
const ResourceMode_1 = require("./../ResourceMode");
|
|
7
|
-
const
|
|
7
|
+
const ResxResourceReaderAdapter_1 = require("./Adapter/ResxResourceReaderAdapter");
|
|
8
8
|
const utilities_1 = require("@breadstone-infrastructure/utilities");
|
|
9
9
|
// #endregion
|
|
10
10
|
/**
|
|
11
|
-
* The `
|
|
11
|
+
* The `ResourceReader` class is responsible for processing resources.
|
|
12
12
|
* It can be resolves json or resx files.
|
|
13
13
|
*
|
|
14
14
|
* @public
|
|
15
15
|
*/
|
|
16
|
-
class
|
|
16
|
+
class ResourceReader {
|
|
17
17
|
// #region Fields
|
|
18
18
|
_fileSystem;
|
|
19
19
|
_logger;
|
|
@@ -21,7 +21,7 @@ class ResourceScanner {
|
|
|
21
21
|
// #endregion
|
|
22
22
|
// #region Ctor
|
|
23
23
|
/**
|
|
24
|
-
* Creates a new instance of `
|
|
24
|
+
* Creates a new instance of `ResourceReader`.
|
|
25
25
|
*
|
|
26
26
|
* @public
|
|
27
27
|
* @param logger - The logger interface.
|
|
@@ -31,29 +31,47 @@ class ResourceScanner {
|
|
|
31
31
|
this._fileSystem = fileSystem;
|
|
32
32
|
this._logger = logger;
|
|
33
33
|
this._adapters = new Map()
|
|
34
|
-
.set(ResourceMode_1.ResourceMode.Json, new
|
|
35
|
-
.set(ResourceMode_1.ResourceMode.Resx, new
|
|
34
|
+
.set(ResourceMode_1.ResourceMode.Json, new JsonResourceReaderAdapter_1.JsonResourceReaderAdapter(this._fileSystem, this._logger))
|
|
35
|
+
.set(ResourceMode_1.ResourceMode.Resx, new ResxResourceReaderAdapter_1.ResxResourceReaderAdapter(this._fileSystem, this._logger));
|
|
36
36
|
}
|
|
37
37
|
// #endregion
|
|
38
38
|
// #region Methods
|
|
39
39
|
/**
|
|
40
|
-
* Scans
|
|
40
|
+
* Scans a directory for resources of the given type.
|
|
41
41
|
*
|
|
42
42
|
* @public
|
|
43
43
|
* @param path - The path to scan.
|
|
44
|
-
* @param type - The type of
|
|
45
|
-
* @returns
|
|
44
|
+
* @param type - The type of resource to scan for.
|
|
45
|
+
* @returns An array of resource information found in the directory.
|
|
46
46
|
*/
|
|
47
|
-
|
|
47
|
+
scanDirectory(path, type) {
|
|
48
48
|
this._logger.log((0, utilities_1.t) `${(0, utilities_1.magenta)(`Scanning for ${(0, utilities_1.bold)(type)} resources...`)}`);
|
|
49
49
|
const adapter = this._adapters.get(type);
|
|
50
50
|
if (!adapter) {
|
|
51
51
|
throw new Error('No adapter found for the specified mode.');
|
|
52
52
|
}
|
|
53
|
-
const result = adapter.
|
|
53
|
+
const result = adapter.scanDirectory(path);
|
|
54
54
|
this._logger.log((0, utilities_1.t) `${(0, utilities_1.magenta)(`Scanning complete.${result.length === 0 ? (0, utilities_1.yellow)(' No resources found.') : ''}`)}`);
|
|
55
55
|
return result;
|
|
56
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Scans a specific file for resources of the given type.
|
|
59
|
+
*
|
|
60
|
+
* @public
|
|
61
|
+
* @param path - The path to the file to scan.
|
|
62
|
+
* @param type - The type of resource to scan for.
|
|
63
|
+
* @returns The resource information or null if the file is not a valid resource.
|
|
64
|
+
*/
|
|
65
|
+
scanFile(path, type) {
|
|
66
|
+
this._logger.log((0, utilities_1.t) `${(0, utilities_1.magenta)(`Scanning for ${(0, utilities_1.bold)(type)} resource in file...`)}`);
|
|
67
|
+
const adapter = this._adapters.get(type);
|
|
68
|
+
if (!adapter) {
|
|
69
|
+
throw new Error('No adapter found for the specified mode.');
|
|
70
|
+
}
|
|
71
|
+
const result = adapter.scanFile(path);
|
|
72
|
+
this._logger.log((0, utilities_1.t) `${(0, utilities_1.magenta)(`Scanning complete.${result ? '' : (0, utilities_1.yellow)(' No resource found.')}`)}`);
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
57
75
|
}
|
|
58
|
-
exports.
|
|
76
|
+
exports.ResourceReader = ResourceReader;
|
|
59
77
|
//# sourceMappingURL=ResourceScanner.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResourceScanner.js","sourceRoot":"","sources":["../../../src/Resources/Scanners/ResourceScanner.ts"],"names":[],"mappings":";AAAA,kBAAkB;;;AAGlB,
|
|
1
|
+
{"version":3,"file":"ResourceScanner.js","sourceRoot":"","sources":["../../../src/Resources/Scanners/ResourceScanner.ts"],"names":[],"mappings":";AAAA,kBAAkB;;;AAGlB,mFAAgF;AAEhF,oDAAiD;AACjD,mFAAgF;AAChF,oEAAgH;AAEhH,aAAa;AAEb;;;;;GAKG;AACH,MAAa,cAAc;IAEvB,iBAAiB;IAEA,WAAW,CAAc;IACzB,OAAO,CAAU;IACjB,SAAS,CAA4C;IAEtE,aAAa;IAEb,eAAe;IAEf;;;;;;OAMG;IACH,YAAmB,MAAe,EAAE,UAAuB;QACvD,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EAAwC;aAC3D,GAAG,CAAC,2BAAY,CAAC,IAAI,EAAE,IAAI,qDAAyB,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAA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;YACX,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;QAChE,CAAC;QAED,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAEtC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAA,aAAC,EAAA,GAAG,IAAA,mBAAO,EAAC,qBAAqB,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAA,kBAAM,EAAC,qBAAqB,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QAEpG,OAAO,MAAM,CAAC;IAClB,CAAC;CAIJ;AAjFD,wCAiFC"}
|
|
@@ -28,14 +28,14 @@ export declare class ResourceTransformer {
|
|
|
28
28
|
*/
|
|
29
29
|
registerAdapter(resourceType: ResourceType | string, adapter: IResourceTransformerAdapter<IResourceInfo>): void;
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
31
|
+
* Unregister a transformer adapter for a specific resource type.
|
|
32
32
|
*
|
|
33
33
|
* @public
|
|
34
34
|
* @param resourceType - The type of resource to unregister.
|
|
35
35
|
*/
|
|
36
36
|
unregisterAdapter(resourceType: ResourceType | string): void;
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
38
|
+
* Register a serializer for a specific resource type.
|
|
39
39
|
*
|
|
40
40
|
* @public
|
|
41
41
|
* @param resourceType - The type of resource the serializer handles.
|
|
@@ -43,7 +43,7 @@ export declare class ResourceTransformer {
|
|
|
43
43
|
*/
|
|
44
44
|
registerSerializer(resourceType: ResourceType | string, serializer: IResourceSerializer<IResourceInfo>): void;
|
|
45
45
|
/**
|
|
46
|
-
*
|
|
46
|
+
* Unregister a serializer for a specific resource type.
|
|
47
47
|
*
|
|
48
48
|
* @public
|
|
49
49
|
* @param resourceType - The type of resource to unregister.
|
|
@@ -49,7 +49,7 @@ class ResourceTransformer {
|
|
|
49
49
|
this._adapters.set(resourceType, adapter);
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
|
-
*
|
|
52
|
+
* Unregister a transformer adapter for a specific resource type.
|
|
53
53
|
*
|
|
54
54
|
* @public
|
|
55
55
|
* @param resourceType - The type of resource to unregister.
|
|
@@ -58,7 +58,7 @@ class ResourceTransformer {
|
|
|
58
58
|
this._adapters.delete(resourceType);
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
|
-
*
|
|
61
|
+
* Register a serializer for a specific resource type.
|
|
62
62
|
*
|
|
63
63
|
* @public
|
|
64
64
|
* @param resourceType - The type of resource the serializer handles.
|
|
@@ -68,7 +68,7 @@ class ResourceTransformer {
|
|
|
68
68
|
this._serializers.set(resourceType, serializer);
|
|
69
69
|
}
|
|
70
70
|
/**
|
|
71
|
-
*
|
|
71
|
+
* Unregister a serializer for a specific resource type.
|
|
72
72
|
*
|
|
73
73
|
* @public
|
|
74
74
|
* @param resourceType - The type of resource to unregister.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@breadstone-tools/localizator-core",
|
|
3
3
|
"description": "Localizator core library",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.40",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "andre.wehlert <awehlert@breadstone.de> (https://www.breadstone.de)",
|
|
7
7
|
"repository": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"module": "./Index.js",
|
|
14
14
|
"types": "./Index.d.ts",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@breadstone-infrastructure/utilities": "^0.0.
|
|
16
|
+
"@breadstone-infrastructure/utilities": "^0.0.40",
|
|
17
17
|
"cheerio": "^1.1.0"
|
|
18
18
|
}
|
|
19
19
|
}
|