add clean option to CLI
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
* for better version control and diff visibility.
|
||||
*
|
||||
* Usage:
|
||||
* node extract-elx.js <input-file-path> [--overwrite]
|
||||
* node extract-elx.js <input-file-path> [--overwrite] [--clean]
|
||||
*
|
||||
* Output:
|
||||
* Creates a folder named after the input file (without extension) containing:
|
||||
@@ -344,16 +344,20 @@ async function readInputFile(filePath) {
|
||||
/**
|
||||
* Create output directory for extracted properties
|
||||
*/
|
||||
async function createOutputDirectory(outputPath, allowOverwrite = false) {
|
||||
if (existsSync(outputPath)) {
|
||||
if (!allowOverwrite) {
|
||||
throw new Error(
|
||||
`Output directory already exists: ${outputPath}\n` +
|
||||
`Use --overwrite flag to replace it.`
|
||||
);
|
||||
}
|
||||
// Optionally remove existing directory
|
||||
console.log(`Removing existing directory: ${outputPath}`);
|
||||
async function createOutputDirectory(outputPath, allowOverwrite = false, cleanExisting = false) {
|
||||
if (!allowOverwrite && !cleanExisting && existsSync(outputPath)) {
|
||||
throw new Error(
|
||||
`Output directory already exists: ${outputPath}\n` +
|
||||
`Use --overwrite flag to replace it or --clean flag to remove its contents.`
|
||||
);
|
||||
}
|
||||
|
||||
// Optionally remove existing directory
|
||||
if (cleanExisting) {
|
||||
console.log(`Removing existing directory contents: ${outputPath}`);
|
||||
await fs.rm(`${outputPath}`, { recursive: true, force: true });
|
||||
} else if (allowOverwrite) {
|
||||
console.log(`Overwriting existing directory: ${outputPath}`);
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -612,13 +616,14 @@ async function main() {
|
||||
const args = process.argv.slice(2);
|
||||
|
||||
if (args.length === 0) {
|
||||
console.error('Usage: node extract-elx.js <input-file-path> [--overwrite]');
|
||||
console.error('Usage: node extract-elx.js <input-file-path> [--overwrite] [--clean]');
|
||||
console.error('Example: node extract-elx.js elxforms_4951.elx');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const inputPath = args[0];
|
||||
const allowOverwrite = args.includes('--overwrite');
|
||||
const cleanExisting = args.includes('--clean');
|
||||
|
||||
// Validate input file
|
||||
if (!existsSync(inputPath)) {
|
||||
@@ -640,7 +645,7 @@ async function main() {
|
||||
|
||||
// Create output directory
|
||||
console.log(`\n📂 Creating output: ${outputPath}`);
|
||||
await createOutputDirectory(outputPath, allowOverwrite);
|
||||
await createOutputDirectory(outputPath, allowOverwrite, cleanExisting);
|
||||
|
||||
// Process each root property
|
||||
console.log('\n⚙️ Processing properties:\n');
|
||||
|
||||
Reference in New Issue
Block a user