electron/script/gen-hunspell-filenames.js

36 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-03-20 20:28:31 +00:00
const fs = require('fs');
const path = require('path');
2020-03-20 20:28:31 +00:00
const check = process.argv.includes('--check');
2020-03-20 20:28:31 +00:00
const dictsPath = path.resolve(__dirname, '..', '..', 'third_party', 'hunspell_dictionaries');
const gclientPath = 'third_party/hunspell_dictionaries';
2020-03-20 20:28:31 +00:00
const allFiles = fs.readdirSync(dictsPath);
const dictionaries = allFiles
2020-03-20 20:28:31 +00:00
.filter(file => path.extname(file) === '.bdic');
const licenses = allFiles
2020-03-20 20:28:31 +00:00
.filter(file => file.startsWith('LICENSE') || file.startsWith('COPYING'));
const content = `hunspell_dictionaries = [
${dictionaries.map(f => `"//${path.posix.join(gclientPath, f)}"`).join(',\n ')},
]
hunspell_licenses = [
${licenses.map(f => `"//${path.posix.join(gclientPath, f)}"`).join(',\n ')},
]
2020-03-20 20:28:31 +00:00
`;
2020-03-20 20:28:31 +00:00
const filenamesPath = path.resolve(__dirname, '..', 'filenames.hunspell.gni');
if (check) {
2020-03-20 20:28:31 +00:00
const currentContent = fs.readFileSync(filenamesPath, 'utf8');
if (currentContent !== content) {
2020-03-20 20:28:31 +00:00
throw new Error('hunspell filenames need to be regenerated, latest generation does not match current file. Please run node gen-hunspell-filenames.js');
}
} else {
2020-03-20 20:28:31 +00:00
fs.writeFileSync(filenamesPath, content);
}