Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// analysis of source code (html, ts):
// listing of all used keys for customText
const fs = require("fs");
let foundKeys = {};
let foundSourceFiles = [];
function analyse ( fileName, isHtml ) {
const fileContent = fs.readFileSync(fileName, 'utf8').toString();
const searchPattern = isHtml ? /\|\s*customtext:\s*'\w+'/g : /\.getCustomText\s*\(\s*'\w+'\s*\)/g;
const matches = fileContent.match(searchPattern);
if (matches) {
foundSourceFiles.push(fileName);
for (let i = 0; i < matches.length; i++) {
const posStart = matches[i].indexOf("'");
const posEnd = matches[i].lastIndexOf("'");
const foundKey = matches[i].substr(posStart + 1, posEnd - posStart - 1);
if (foundKeys[foundKey]) {
foundKeys[foundKey] += 1;
} else {
foundKeys[foundKey] = 1;
}
}
}
}
function takeFolder(sourceFolder ) {
const dirEntries = fs.readdirSync(sourceFolder);
for (let i = 0; i < dirEntries.length; i++) {
const fullObjectName = sourceFolder + '/' + dirEntries[i];
const stats = fs.statSync(fullObjectName);
if (stats.isDirectory()) {
takeFolder(fullObjectName);
} else if (stats.isFile()) {
const dotPos = fullObjectName.lastIndexOf('.');
if (dotPos > 0) {
const fileExtension = fullObjectName.substr(dotPos + 1);
if (fileExtension.toUpperCase() === 'TS') {
analyse(fullObjectName, false);
} else if (fileExtension.toUpperCase() === 'HTML') {
analyse(fullObjectName, true);
}
}
}
}
}
takeFolder('../app');
console.log(foundKeys);
console.log(foundSourceFiles);
console.log('done.');