Replace node-getopt with commander for args

node-getopt isn't maintained and nodejs has started complaining about
deprecated features in it.
This commit is contained in:
Pierre Ossman 2024-12-17 16:43:44 +01:00
parent 52392ec150
commit 3e2e04bea1
3 changed files with 15 additions and 20 deletions

View File

@ -56,7 +56,6 @@
"karma-safari-launcher": "latest", "karma-safari-launcher": "latest",
"karma-script-launcher": "latest", "karma-script-launcher": "latest",
"mocha": "latest", "mocha": "latest",
"node-getopt": "latest",
"po2json": "latest", "po2json": "latest",
"sinon": "latest", "sinon": "latest",
"sinon-chai": "latest" "sinon-chai": "latest"

View File

@ -17,20 +17,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
const getopt = require('node-getopt'); const { program } = require('commander');
const fs = require('fs'); const fs = require('fs');
const po2json = require("po2json"); const po2json = require("po2json");
const opt = getopt.create([ program
['h', 'help', 'display this help'], .argument('<input>')
]).bindHelp().parseSystem(); .argument('<output>')
.parse(process.argv);
if (opt.argv.length != 2) { const data = po2json.parseFileSync(program.args[0]);
console.error("Incorrect number of arguments given");
process.exit(1);
}
const data = po2json.parseFileSync(opt.argv[0]);
const bodyPart = Object.keys(data) const bodyPart = Object.keys(data)
.filter(msgid => msgid !== "") .filter(msgid => msgid !== "")
@ -42,4 +38,4 @@ const bodyPart = Object.keys(data)
const output = "{\n" + bodyPart + "\n}"; const output = "{\n" + bodyPart + "\n}";
fs.writeFileSync(opt.argv[1], output); fs.writeFileSync(program.args[1], output);

View File

@ -5,14 +5,14 @@
* Licensed under MPL 2.0 (see LICENSE.txt) * Licensed under MPL 2.0 (see LICENSE.txt)
*/ */
const getopt = require('node-getopt'); const { program } = require('commander');
const jsdom = require("jsdom"); const jsdom = require("jsdom");
const fs = require("fs"); const fs = require("fs");
const opt = getopt.create([ program
['o', 'output=FILE', 'write output to specified file'], .argument('<INPUT...>')
['h', 'help', 'display this help'], .requiredOption('-o, --output <FILE>', 'write output to specified file')
]).bindHelp().parseSystem(); .parse(process.argv);
const strings = {}; const strings = {};
@ -87,8 +87,8 @@ function process(elem, locator, enabled) {
} }
} }
for (let i = 0; i < opt.argv.length; i++) { for (let i = 0; i < program.args.length; i++) {
const fn = opt.argv[i]; const fn = program.args[i];
const file = fs.readFileSync(fn, "utf8"); const file = fs.readFileSync(fn, "utf8");
const dom = new jsdom.JSDOM(file, { includeNodeLocations: true }); const dom = new jsdom.JSDOM(file, { includeNodeLocations: true });
const body = dom.window.document.body; const body = dom.window.document.body;
@ -116,4 +116,4 @@ for (let str in strings) {
output += "\n"; output += "\n";
} }
fs.writeFileSync(opt.options.output, output); fs.writeFileSync(program.opts().output, output);