Files
2026-06-14 01:40:04 +02:00

77 lines
2.5 KiB
JavaScript

#!/usr/bin/env node
'use strict';
const { program } = require('commander');
const path = require('path');
const pkg = require('../package.json');
// ─── Shared helper: resolve cc3tools path ───
function resolveToolsDir(options) {
if (options.toolsPath) {
return path.resolve(options.toolsPath) + path.sep;
}
// If running as a packaged executable
if (process.pkg) {
return path.join(path.dirname(process.execPath), 'cc3tools') + path.sep;
}
// Default: ../cc3tools/ relative to this script's location
return path.resolve(__dirname, '..', 'cc3tools') + path.sep;
}
// ─── ra3apt expand ───
program
.command('expand')
.description('Convert a binary .apt file to human-readable XML')
.argument('<input>', 'Path to the .apt file')
.option('-o, --output <file>', 'Output XML file (default: <name>_edit.xml)')
.option('--tools-path <dir>', 'Path to cc3tools directory')
.option('--keep-temp', 'Keep temporary files for debugging')
.option('--old-style', 'Use old/verbose action name style')
.action(async (input, options) => {
const toolsDir = resolveToolsDir(options);
const { expand } = require('../lib/expand');
try {
await expand(input, options.output, {
toolsDir,
keepTemp: !!options.keepTemp,
oldStyle: !!options.oldStyle
});
} catch (err) {
console.error(err.message);
process.exit(1);
}
});
// ─── ra3apt build ───
program
.command('build')
.description('Build a binary .apt file from human-readable XML')
.argument('<input>', 'Path to the human-readable XML file')
.option('-o, --output <file>', 'Output .apt file (default: <name>.apt)')
.option('--tools-path <dir>', 'Path to cc3tools directory')
.option('--keep-temp', 'Keep temporary files for debugging')
.option('--old-style', 'Use old/verbose action name style')
.action(async (input, options) => {
const toolsDir = resolveToolsDir(options);
const { build } = require('../lib/build');
try {
await build(input, options.output, {
toolsDir,
keepTemp: !!options.keepTemp,
oldStyle: !!options.oldStyle
});
} catch (err) {
console.error(err.message);
process.exit(1);
}
});
// ─── Parse ───
program
.name('ra3apt')
.description('RA3 .apt file editor CLI — convert between binary .apt and human-readable XML.\nBased on Jonwil\'s cc3tools and utunnels\' ra3aptxmleditor.')
.version(pkg.version);
program.parse(process.argv);