25 lines
465 B
JavaScript
25 lines
465 B
JavaScript
|
import { TemplateEngine } from './index.js';
|
||
|
import { basename } from 'node:path';
|
||
|
|
||
|
// Check arguments
|
||
|
if (process.argv.length !== 3) {
|
||
|
console.error(`Usage: node ${basename(process.argv[1])} filename`);
|
||
|
process.exit(1);
|
||
|
}
|
||
|
const fileName = process.argv[2];
|
||
|
|
||
|
const tp = new TemplateEngine();
|
||
|
|
||
|
let result;
|
||
|
|
||
|
try {
|
||
|
result = await tp.render(fileName);
|
||
|
} catch (e) {
|
||
|
console.error(e.message);
|
||
|
process.exit(1);
|
||
|
}
|
||
|
|
||
|
if (result) {
|
||
|
process.stdout.write(result);
|
||
|
}
|