@liuhange/dsh-data-inventory 2.0.2 → 2.0.3
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/lib/assetListGenerator.js +24 -0
- package/lib/directoryScanner.js +35 -0
- package/lib/valueAssessor.js +22 -0
- package/package.json +2 -2
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export class AssetListGenerator {
|
|
2
|
+
generate(files, valueAssessor, valueRules) {
|
|
3
|
+
return files.map((file) => {
|
|
4
|
+
const assessment = valueAssessor.assess(file.fileName, valueRules);
|
|
5
|
+
return {
|
|
6
|
+
fileName: file.fileName,
|
|
7
|
+
size: this.humanReadableSize(file.size),
|
|
8
|
+
type: file.format,
|
|
9
|
+
valueAssessment: assessment.label,
|
|
10
|
+
description: assessment.recommendation,
|
|
11
|
+
};
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
humanReadableSize(bytes) {
|
|
15
|
+
if (bytes < 1024)
|
|
16
|
+
return `${bytes} B`;
|
|
17
|
+
if (bytes < 1024 * 1024)
|
|
18
|
+
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
19
|
+
if (bytes < 1024 * 1024 * 1024)
|
|
20
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
21
|
+
return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)} GB`;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=assetListGenerator.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
const SUPPORTED_EXTENSIONS = ['csv', 'xlsx', 'json', 'txt'];
|
|
4
|
+
export class DirectoryScanner {
|
|
5
|
+
scan(directory) {
|
|
6
|
+
const files = [];
|
|
7
|
+
let skippedFiles = 0;
|
|
8
|
+
if (!fs.existsSync(directory)) {
|
|
9
|
+
return { files, skippedFiles };
|
|
10
|
+
}
|
|
11
|
+
const entries = fs.readdirSync(directory);
|
|
12
|
+
for (const entry of entries) {
|
|
13
|
+
const fullPath = path.join(directory, entry);
|
|
14
|
+
try {
|
|
15
|
+
const stats = fs.statSync(fullPath);
|
|
16
|
+
if (!stats.isFile())
|
|
17
|
+
continue;
|
|
18
|
+
const ext = path.extname(entry).toLowerCase().slice(1);
|
|
19
|
+
if (!SUPPORTED_EXTENSIONS.includes(ext))
|
|
20
|
+
continue;
|
|
21
|
+
files.push({
|
|
22
|
+
fileName: entry,
|
|
23
|
+
fullPath,
|
|
24
|
+
size: stats.size,
|
|
25
|
+
format: ext,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
skippedFiles++;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return { files, skippedFiles };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=directoryScanner.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export class ValueAssessor {
|
|
2
|
+
assess(fileName, rules) {
|
|
3
|
+
const ruleLevels = [rules.highValue, rules.mediumValue, rules.lowValue];
|
|
4
|
+
for (const rule of ruleLevels) {
|
|
5
|
+
for (const keyword of rule.keywords) {
|
|
6
|
+
if (fileName.includes(keyword)) {
|
|
7
|
+
return {
|
|
8
|
+
stars: rule.score,
|
|
9
|
+
label: rule.label,
|
|
10
|
+
recommendation: rule.recommendation,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
stars: rules.defaultValue.score,
|
|
17
|
+
label: rules.defaultValue.label,
|
|
18
|
+
recommendation: rules.defaultValue.recommendation,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=valueAssessor.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liuhange/dsh-data-inventory",
|
|
3
3
|
"description": "Data inventory plugin: directory scanning, value assessment, asset list generation",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.3",
|
|
5
5
|
"publishConfig": { "access": "public" },
|
|
6
6
|
"repository": { "type": "git", "url": "git+https://github.com/liuhange789/data-asset-inspector.git", "directory": "packages/data-asset/data-inventory" },
|
|
7
7
|
"type": "module",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"./src/*": "./src/*",
|
|
14
14
|
"./package.json": "./package.json"
|
|
15
15
|
},
|
|
16
|
-
"files": ["lib
|
|
16
|
+
"files": ["lib/**/*.js", "lib/types/**/*.d.ts"],
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"scripts": {
|
|
19
19
|
"typecheck": "tsc --noEmit",
|