Skip to content

Commit 079689c

Browse files
authored
Merge pull request pcottle#653 from Hongarc/no-grep
No grep
2 parents fd09d9c + 77bd782 commit 079689c

File tree

2 files changed

+35
-40
lines changed

2 files changed

+35
-40
lines changed

src/js/intl/checkStrings.js

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,33 @@
1-
var sys = require('sys');
2-
var util = require('../util');
3-
var child_process = require('child_process');
4-
var strings = require('../intl/strings').strings;
1+
var { join } = require('path');
2+
var { readFileSync } = require('fs');
53

6-
var searchCommand = 'grep -C 2 -r "intl.str(" ../../';
7-
var genBadKeyCommand = function(key) {
8-
return 'grep -r "' + key + '" ../../';
9-
};
4+
var util = require('../util');
5+
var { strings } = require('../intl/strings');
106

11-
var easyRegex = /intl.str\('([a-zA-Z\-]+)'/g;
12-
var hardRegex = /\s+'([a-z\-]+)',/g;
7+
var easyRegex = /intl\.str\(\s*'([a-zA-Z\-]+)'/g;
138

14-
var findKey = function(badKey) {
15-
child_process.exec(genBadKeyCommand(badKey), function(err, output) {
16-
console.log(output);
17-
});
18-
};
9+
var allKetSet = new Set(Object.keys(strings));
10+
allKetSet.delete('error-untranslated'); // used in ./index.js
1911

20-
var goodKeys = 0;
12+
var goodKeySet = new Set();
2113
var validateKey = function(key) {
2214
if (!strings[key]) {
2315
console.log('NO KEY for: "', key, '"');
24-
findKey(key);
2516
} else {
26-
goodKeys++;
17+
goodKeySet.add(key);
18+
allKetSet.delete(key);
2719
}
2820
};
2921

30-
var processLines = function(lines) {
31-
lines.forEach(function(line) {
32-
var results = easyRegex.exec(line);
33-
if (results && results[1]) {
34-
validateKey(results[1]);
35-
return;
36-
}
37-
// could be a multi-liner
38-
results = hardRegex.exec(line);
39-
if (results && results[1]) {
40-
validateKey(results[1]);
41-
}
42-
});
43-
};
44-
4522
if (!util.isBrowser()) {
46-
child_process.exec(
47-
searchCommand,
48-
function(err, output) {
49-
processLines(output.split('\n'));
50-
console.log(goodKeys + ' good keys found!');
23+
util.readDirDeep(join(__dirname, '../../')).forEach(function(path) {
24+
var content = readFileSync(path);
25+
var match;
26+
while (match = easyRegex.exec(content)) {
27+
validateKey(match[1]);
5128
}
52-
);
29+
});
30+
console.log(goodKeySet.size, ' good keys found!');
31+
console.log(allKetSet.size, ' keys did not use!');
32+
console.log(allKetSet);
5333
}
54-

src/js/util/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
var { readdirSync, lstatSync } = require('fs');
2+
var { join } = require('path');
3+
14
var escapeString = require('../util/escapeString');
25
var constants = require('../util/constants');
36

@@ -56,3 +59,16 @@ exports.genParseCommand = function(regexMap, eventName) {
5659
};
5760
};
5861
};
62+
63+
exports.readDirDeep = function(dir) {
64+
var paths = [];
65+
readdirSync(dir).forEach(function(path) {
66+
var aPath = join(dir, path);
67+
if (lstatSync(aPath).isDirectory()) {
68+
paths.push(...exports.readDirDeep(aPath));
69+
} else {
70+
paths.push(aPath);
71+
}
72+
});
73+
return paths;
74+
};

0 commit comments

Comments
 (0)