From 95134277fe5958f058ee79c76619e2eb9101fc4d Mon Sep 17 00:00:00 2001 From: freearhey <7253922+freearhey@users.noreply.github.com> Date: Fri, 30 Jun 2023 14:53:10 +0300 Subject: [PATCH] Update editor.js --- scripts/commands/channels/editor.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/scripts/commands/channels/editor.js b/scripts/commands/channels/editor.js index 8df89f04..33f46702 100644 --- a/scripts/commands/channels/editor.js +++ b/scripts/commands/channels/editor.js @@ -5,10 +5,11 @@ const { program } = require('commander') const inquirer = require('inquirer') program - .requiredOption('-i, --input ', 'Load channels from the file') + .argument('', 'Path to *.channels.xml file to edit') .option('-c, --country ', 'Source country', 'us') .parse(process.argv) +const filepath = program.args[0] const options = program.opts() const defaultCountry = options.country const newLabel = ` [new]` @@ -17,7 +18,12 @@ let site let channels = [] async function main() { - let result = await parser.parseChannels(options.input) + if (!(await file.exists(filepath))) { + throw new Error(`File "${filepath}" does not exists`) + return + } + + let result = await parser.parseChannels(filepath) site = result.site channels = result.channels channels = channels.map(c => { @@ -59,11 +65,13 @@ async function main() { main() function save() { + if (!file.existsSync(filepath)) return + const output = xml.create(channels, site) - file.writeSync(options.input, output) + file.writeSync(filepath, output) - logger.info(`\nFile '${options.input}' successfully saved`) + logger.info(`\nFile '${filepath}' successfully saved`) } nodeCleanup(() => {