From 3e2e04bea132de6c5485fce41cc947aa86f33d5f Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 17 Dec 2024 16:43:44 +0100 Subject: [PATCH] Replace node-getopt with commander for args node-getopt isn't maintained and nodejs has started complaining about deprecated features in it. --- package.json | 1 - po/po2js | 18 +++++++----------- po/xgettext-html | 16 ++++++++-------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index e28850a8d..e45fde83d 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,6 @@ "karma-safari-launcher": "latest", "karma-script-launcher": "latest", "mocha": "latest", - "node-getopt": "latest", "po2json": "latest", "sinon": "latest", "sinon-chai": "latest" diff --git a/po/po2js b/po/po2js index 23b8bb24a..8d353a1d4 100755 --- a/po/po2js +++ b/po/po2js @@ -17,20 +17,16 @@ * along with this program. If not, see . */ -const getopt = require('node-getopt'); +const { program } = require('commander'); const fs = require('fs'); const po2json = require("po2json"); -const opt = getopt.create([ - ['h', 'help', 'display this help'], -]).bindHelp().parseSystem(); +program + .argument('') + .argument('') + .parse(process.argv); -if (opt.argv.length != 2) { - console.error("Incorrect number of arguments given"); - process.exit(1); -} - -const data = po2json.parseFileSync(opt.argv[0]); +const data = po2json.parseFileSync(program.args[0]); const bodyPart = Object.keys(data) .filter(msgid => msgid !== "") @@ -42,4 +38,4 @@ const bodyPart = Object.keys(data) const output = "{\n" + bodyPart + "\n}"; -fs.writeFileSync(opt.argv[1], output); +fs.writeFileSync(program.args[1], output); diff --git a/po/xgettext-html b/po/xgettext-html index 72d492354..f5ba57cc5 100755 --- a/po/xgettext-html +++ b/po/xgettext-html @@ -5,14 +5,14 @@ * Licensed under MPL 2.0 (see LICENSE.txt) */ -const getopt = require('node-getopt'); +const { program } = require('commander'); const jsdom = require("jsdom"); const fs = require("fs"); -const opt = getopt.create([ - ['o', 'output=FILE', 'write output to specified file'], - ['h', 'help', 'display this help'], -]).bindHelp().parseSystem(); +program + .argument('') + .requiredOption('-o, --output ', 'write output to specified file') + .parse(process.argv); const strings = {}; @@ -87,8 +87,8 @@ function process(elem, locator, enabled) { } } -for (let i = 0; i < opt.argv.length; i++) { - const fn = opt.argv[i]; +for (let i = 0; i < program.args.length; i++) { + const fn = program.args[i]; const file = fs.readFileSync(fn, "utf8"); const dom = new jsdom.JSDOM(file, { includeNodeLocations: true }); const body = dom.window.document.body; @@ -116,4 +116,4 @@ for (let str in strings) { output += "\n"; } -fs.writeFileSync(opt.options.output, output); +fs.writeFileSync(program.opts().output, output);