2017-01-19 18:23:56 -05:00
|
|
|
/*
|
|
|
|
* Check that there are no duplicate strings in any individual l10n json file.
|
|
|
|
*/
|
|
|
|
var path = require('path');
|
|
|
|
var fs = require('fs');
|
|
|
|
var tap = require('tap');
|
|
|
|
|
|
|
|
var routes = require('../../src/routes.json');
|
|
|
|
|
2018-01-19 14:06:26 -05:00
|
|
|
const noDuplicateValues = (idsToCheck, name) => {
|
|
|
|
let values = {};
|
|
|
|
for (const key in idsToCheck) {
|
2017-01-19 18:23:56 -05:00
|
|
|
if (values.hasOwnProperty(idsToCheck[key])) {
|
|
|
|
// duplicate values
|
2018-01-19 14:06:26 -05:00
|
|
|
// return false;
|
|
|
|
tap.fail(`${name}.${idsToCheck[key]} has duplicates`);
|
2017-01-19 18:23:56 -05:00
|
|
|
} else {
|
|
|
|
values[idsToCheck[key]] = key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tap.pass();
|
2018-01-19 14:06:26 -05:00
|
|
|
// return true;
|
|
|
|
};
|
2017-01-19 18:23:56 -05:00
|
|
|
|
|
|
|
tap.test('generalCheckForDuplicates', function (t) {
|
2018-01-19 14:06:26 -05:00
|
|
|
const ids = require(path.resolve(__dirname, '../../src/l10n.json')); // eslint-disable-line global-require
|
2017-01-19 18:23:56 -05:00
|
|
|
noDuplicateValues(ids, 'general');
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
for (var v in routes) {
|
|
|
|
if (typeof routes[v].redirect !== 'undefined') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
var subdir = routes[v].view.split('/');
|
|
|
|
subdir.pop();
|
|
|
|
var name = routes[v].name;
|
2018-01-19 14:06:26 -05:00
|
|
|
var uri = path.resolve(__dirname, '../../src/views/' + subdir.join('/') + '/l10n.json');
|
2017-01-19 18:23:56 -05:00
|
|
|
try {
|
|
|
|
var file = fs.readFileSync(uri, 'utf8');
|
|
|
|
var ids = JSON.parse(file);
|
2018-01-19 14:06:26 -05:00
|
|
|
tap.test(name + 'CheckForDuplicates', function (t) { // eslint-disable-line no-loop-func
|
2017-01-19 18:23:56 -05:00
|
|
|
noDuplicateValues(ids, name);
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
if (err.code !== 'ENOENT') {
|
|
|
|
// ignore if ENOENT for routes with no l10n file, throw error for anything else
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|