Update validate.js

This commit is contained in:
Aleksandr Statciuk 2022-04-09 04:02:02 +03:00
parent 6087a6c06a
commit 34d05d513f

View file

@ -53,6 +53,25 @@ async function main() {
} }
fileErrors = fileErrors.concat(findDuplicatesById(data)) fileErrors = fileErrors.concat(findDuplicatesById(data))
let categories = await csv.fromFile('data/categories.csv').catch(err => {
logger.error(chalk.red(`\nError: ${err.message}`))
process.exit(1)
})
categories = categories.map(c => c.id)
data.forEach((row, i) => {
if (
categories.length &&
row.categories.length &&
intersection(categories, row.categories).length !== row.categories.length
) {
fileErrors.push({
line: i + 2,
message: `"${row.id}" has the wrong categories "${row.categories.join(';')}"`
})
}
})
} else if (filename === 'blocklist') { } else if (filename === 'blocklist') {
let channels = await csv.fromFile('data/channels.csv').catch(err => { let channels = await csv.fromFile('data/channels.csv').catch(err => {
logger.error(chalk.red(`\nError: ${err.message}`)) logger.error(chalk.red(`\nError: ${err.message}`))
@ -118,3 +137,9 @@ function findDuplicatesById(data) {
return errors return errors
} }
function intersection(array1, array2) {
return array1.filter(function (n) {
return array2.indexOf(n) !== -1
})
}