Template-Engine/cli.js

25 lines
465 B
JavaScript
Raw Normal View History

2022-09-02 23:31:55 -07:00
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);
}