|
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'); |
5 | 3 |
|
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'); |
10 | 6 |
|
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; |
13 | 8 |
|
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 |
19 | 11 |
|
20 |
| -var goodKeys = 0; |
| 12 | +var goodKeySet = new Set(); |
21 | 13 | var validateKey = function(key) {
|
22 | 14 | if (!strings[key]) {
|
23 | 15 | console.log('NO KEY for: "', key, '"');
|
24 |
| - findKey(key); |
25 | 16 | } else {
|
26 |
| - goodKeys++; |
| 17 | + goodKeySet.add(key); |
| 18 | + allKetSet.delete(key); |
27 | 19 | }
|
28 | 20 | };
|
29 | 21 |
|
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 |
| - |
45 | 22 | 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]); |
51 | 28 | }
|
52 |
| - ); |
| 29 | + }); |
| 30 | + console.log(goodKeySet.size, ' good keys found!'); |
| 31 | + console.log(allKetSet.size, ' keys did not use!'); |
| 32 | + console.log(allKetSet); |
53 | 33 | }
|
54 |
| - |
0 commit comments