-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.ts
More file actions
executable file
·45 lines (36 loc) · 1.55 KB
/
cli.ts
File metadata and controls
executable file
·45 lines (36 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env bun
import { program } from 'commander';
import { XivCompiler, CompilerError } from './src/compiler';
import { write } from 'bun';
import path from 'path';
program
.name('xiv')
.description('A simple template engine for creating component-based HTML.')
.version('1.0.0');
program
.argument('<input_file>', 'The main XIV file to compile.')
.option('-o, --output_file <path>', 'Path to the output HTML file', './index.html')
.action(async (inputFile, options) => {
console.log(`\n--- Starting XIV compilation ---`);
console.log(` Input file: ${inputFile}`);
console.log(` Output file: ${options.output_file}`);
const compiler = new XivCompiler();
try {
const compiledHtml = await compiler.compile(inputFile, options.output_file);
const outputPath = path.resolve(options.output_file);
await write(outputPath, compiledHtml);
console.log(`\n✅ Compilation successful. Output saved to '${options.output_file}'`);
console.log("\n--- Compilation Result Preview (first 500 characters) ---");
console.log(compiledHtml.substring(0, 500) + (compiledHtml.length > 500 ? "..." : ""));
} catch (error) {
if (error instanceof CompilerError) {
console.error(`\n❌ Compilation failed: ${error.message}`);
} else if (error instanceof Error) {
console.error(`\n❌ An unexpected error occurred: ${error.message}`);
} else {
console.error(`\n❌ An unexpected and unknown error occurred.`);
}
process.exit(1);
}
});
program.parse(process.argv);