From 1a8248fe922d3cf4cdf3650b5efe82d8ee426cb0 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Fri, 12 Nov 2021 18:08:51 +0300 Subject: [PATCH] Create channels.js --- scripts/channels.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 scripts/channels.js diff --git a/scripts/channels.js b/scripts/channels.js new file mode 100644 index 00000000..13147826 --- /dev/null +++ b/scripts/channels.js @@ -0,0 +1,34 @@ +const { Command } = require('commander') +const fs = require('fs') +const path = require('path') +const { json2xml } = require('./utils') + +const program = new Command() +program + .requiredOption('-c, --config ', 'Config file') + .option('-o, --output ', 'Output file') + .parse(process.argv) + +const options = program.opts() + +async function main() { + const config = require(path.resolve(options.config)) + let channels = config.channels() + if (isPromise(channels)) { + channels = await channels + } + const xml = json2xml(channels, config.site) + + const dir = path.parse(options.config).dir + const output = options.output || `${dir}/${config.site}.channels.xml` + + fs.writeFileSync(path.resolve(output), xml) + + console.log(`File '${output}' successfully saved`) +} + +main() + +function isPromise(promise) { + return !!promise && typeof promise.then === 'function' +}