@meldscience/meld
Version:
pipeable one-shot prompt scripting toolkit
74 lines • 2.68 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const commander_1 = require("commander");
const meld_1 = require("../src/meld");
const fs_1 = require("fs");
const promises_1 = require("fs/promises");
const readline_1 = require("readline");
const program = new commander_1.Command();
async function promptOverwrite(file) {
const rl = (0, readline_1.createInterface)({
input: process.stdin,
output: process.stdout
});
return new Promise((resolve) => {
rl.question(`File ${file} already exists. Overwrite? [Y/n] `, (answer) => {
rl.close();
resolve(answer.toLowerCase() !== 'n');
});
});
}
program
.name('meld')
.description('Process a markdown file containing embedded commands')
.argument('<input>', 'Input .meld.md file')
.option('-o, --outfile <path>', 'Output file path')
.option('--dry-run', 'Print commands that would be executed without running them')
.option('--overwrite', 'Overwrite output file without prompting')
.option('--debug', 'Enable debug logging')
.action(async (input, options) => {
try {
const outputFile = options.outfile || input.replace(/\.meld\.md$/, '.md');
// Check if file exists and we need to prompt
if ((0, fs_1.existsSync)(outputFile) && !options.overwrite) {
const shouldOverwrite = await promptOverwrite(outputFile);
if (!shouldOverwrite) {
console.log('Aborted.');
process.exit(0);
}
}
const meld = new meld_1.Meld({
inputPath: input,
workspacePath: process.cwd(),
outputFile,
dryRun: options.dryRun || false,
debug: options.debug || false
});
const result = await meld.process();
if (result.errors.length > 0) {
console.error('Errors occurred during processing:');
result.errors.forEach(error => console.error(`- ${error}`));
process.exit(1);
}
if (options.dryRun) {
console.log('\nCommands that would be executed:');
console.log(result.content);
}
else {
await (0, promises_1.writeFile)(outputFile, result.content, 'utf-8');
console.log(`🦾 ${input} → ${outputFile}`);
}
}
catch (error) {
if (error instanceof Error) {
console.error('Error:', error.message);
}
else {
console.error('An unknown error occurred:', error);
}
process.exit(1);
}
});
program.parse();
//# sourceMappingURL=meld.js.map