epg/scripts/create-matrix.js
2021-10-28 22:57:59 +03:00

31 lines
771 B
JavaScript

const { Command } = require('commander')
const file = require('./file')
const program = new Command()
program
.option('--include <include>', 'List of files to include', parseList)
.option('--exclude <exclude>', 'List of files to exclude', parseList)
.parse(process.argv)
const options = program.opts()
file.list('sites/*/*.channels.xml', options.include, options.exclude).then(files => {
const matrix = {
guide: []
}
files.forEach(filename => {
const [_, site, country] = filename.match(/sites\/.*\/(.*)_(.*)\.channels\.xml/i)
matrix.guide.push({ site, country })
})
const output = `::set-output name=matrix::${JSON.stringify(matrix)}`
console.log(output)
})
function parseList(str) {
if (!str) return []
return str.split(',')
}