Merge pull request #653 from Hongarc/no-grep

No grep
This commit is contained in:
Peter Cottle 2020-03-05 12:38:50 -08:00 committed by GitHub
commit 079689c51a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 40 deletions

View file

@ -1,54 +1,33 @@
var sys = require('sys'); var { join } = require('path');
var { readFileSync } = require('fs');
var util = require('../util'); var util = require('../util');
var child_process = require('child_process'); var { strings } = require('../intl/strings');
var strings = require('../intl/strings').strings;
var searchCommand = 'grep -C 2 -r "intl.str(" ../../'; var easyRegex = /intl\.str\(\s*'([a-zA-Z\-]+)'/g;
var genBadKeyCommand = function(key) {
return 'grep -r "' + key + '" ../../';
};
var easyRegex = /intl.str\('([a-zA-Z\-]+)'/g; var allKetSet = new Set(Object.keys(strings));
var hardRegex = /\s+'([a-z\-]+)',/g; allKetSet.delete('error-untranslated'); // used in ./index.js
var findKey = function(badKey) { var goodKeySet = new Set();
child_process.exec(genBadKeyCommand(badKey), function(err, output) {
console.log(output);
});
};
var goodKeys = 0;
var validateKey = function(key) { var validateKey = function(key) {
if (!strings[key]) { if (!strings[key]) {
console.log('NO KEY for: "', key, '"'); console.log('NO KEY for: "', key, '"');
findKey(key);
} else { } else {
goodKeys++; goodKeySet.add(key);
allKetSet.delete(key);
} }
}; };
var processLines = function(lines) {
lines.forEach(function(line) {
var results = easyRegex.exec(line);
if (results && results[1]) {
validateKey(results[1]);
return;
}
// could be a multi-liner
results = hardRegex.exec(line);
if (results && results[1]) {
validateKey(results[1]);
}
});
};
if (!util.isBrowser()) { if (!util.isBrowser()) {
child_process.exec( util.readDirDeep(join(__dirname, '../../')).forEach(function(path) {
searchCommand, var content = readFileSync(path);
function(err, output) { var match;
processLines(output.split('\n')); while (match = easyRegex.exec(content)) {
console.log(goodKeys + ' good keys found!'); validateKey(match[1]);
} }
); });
console.log(goodKeySet.size, ' good keys found!');
console.log(allKetSet.size, ' keys did not use!');
console.log(allKetSet);
} }

View file

@ -1,3 +1,6 @@
var { readdirSync, lstatSync } = require('fs');
var { join } = require('path');
var escapeString = require('../util/escapeString'); var escapeString = require('../util/escapeString');
var constants = require('../util/constants'); var constants = require('../util/constants');
@ -56,3 +59,16 @@ exports.genParseCommand = function(regexMap, eventName) {
}; };
}; };
}; };
exports.readDirDeep = function(dir) {
var paths = [];
readdirSync(dir).forEach(function(path) {
var aPath = join(dir, path);
if (lstatSync(aPath).isDirectory()) {
paths.push(...exports.readDirDeep(aPath));
} else {
paths.push(aPath);
}
});
return paths;
};