feat: use node.js module instead of

This commit is contained in:
hongarc 2020-03-05 12:09:28 +07:00
parent fd09d9c960
commit 8eaa9f285c
2 changed files with 29 additions and 39 deletions

View file

@ -1,54 +1,28 @@
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 hardRegex = /\s+'([a-z\-]+)',/g;
var findKey = function(badKey) {
child_process.exec(genBadKeyCommand(badKey), function(err, output) {
console.log(output);
});
};
var goodKeys = 0; 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++; goodKeys++;
} }
}; };
var processLines = function(lines) { if (!util.isBrowser()) {
lines.forEach(function(line) { util.readDirDeep(join(__dirname, '../..')).forEach(function(path) {
var results = easyRegex.exec(line); var content = readFileSync(path);
if (results && results[1]) { var match;
validateKey(results[1]); while (match = easyRegex.exec(content)) {
return; console.log(match[1])
} validateKey(match[1]);
// could be a multi-liner
results = hardRegex.exec(line);
if (results && results[1]) {
validateKey(results[1]);
} }
}); });
}; console.log(goodKeys + ' good keys found!');
if (!util.isBrowser()) {
child_process.exec(
searchCommand,
function(err, output) {
processLines(output.split('\n'));
console.log(goodKeys + ' good keys found!');
}
);
} }

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;
}