From 1d013713e6ecbd278679dfefd6a16925d9b9807f Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Wed, 13 Oct 2021 19:56:46 +0300 Subject: [PATCH] Update create-matrix.js --- scripts/create-matrix.js | 50 ++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/scripts/create-matrix.js b/scripts/create-matrix.js index 75fabcbf..fa4e989e 100644 --- a/scripts/create-matrix.js +++ b/scripts/create-matrix.js @@ -1,27 +1,37 @@ +const { Command } = require('commander') const file = require('./file') const parser = require('./parser') -file - .list('sites/*.channels.xml', [ - 'sites/andorradifusio.ad.channels.xml', - 'sites/arianaafgtv.com.channels.xml' - ]) - .then(files => { - const matrix = { - guide: [] - } +const program = new Command() +program + .option('--include ', 'List of files to include', parseList) + .option('--exclude ', 'List of files to exclude', parseList) + .parse(process.argv) - files.forEach(filename => { - const channelsFile = file.read(filename) - const parsed = parser.parseChannels(channelsFile) - parsed.groups.forEach(group => { - matrix.guide.push({ - site: parsed.site, - country: group.country.toLowerCase() - }) +const options = program.opts() + +file.list('sites/*.channels.xml', options.include, options.exclude).then(files => { + const matrix = { + guide: [] + } + + files.forEach(filename => { + const channelsFile = file.read(filename) + const parsed = parser.parseChannels(channelsFile) + parsed.groups.forEach(group => { + matrix.guide.push({ + site: parsed.site, + country: group.country.toLowerCase() }) }) - - const output = `::set-output name=matrix::${JSON.stringify(matrix)}` - console.log(output) }) + + const output = `::set-output name=matrix::${JSON.stringify(matrix)}` + console.log(output) +}) + +function parseList(str) { + if (!str) return [] + + return str.split(',') +}