26 lines
1.2 KiB
TypeScript
26 lines
1.2 KiB
TypeScript
// npx ts-node html-templates.ts
|
|
import * as readline from "node:readline/promises" // This uses the promise-based APIs
|
|
import { stdin as input, stdout as output } from "node:process"
|
|
import { htmlTemplateX } from "../libs/html-templates-lib"
|
|
import { templateOption } from "../libs/report-template"
|
|
import fs from "fs"
|
|
;(async () => {
|
|
const rl = readline.createInterface({ input, output })
|
|
const e = await rl.question("Output extension(pdf,png,jpeg): ")
|
|
const ext = e ? e : "pdf"
|
|
const dpath = await rl.question("JSON data path(./html.json): ")
|
|
const datapath = dpath ? dpath : "./html.json"
|
|
const data_raw = fs.readFileSync(datapath)
|
|
const tdata: templateOption = JSON.parse(data_raw.toString())
|
|
const bpath = await rl.question("templates path(../templates/html): ")
|
|
const basepath = bpath ? bpath : "../templates/html"
|
|
// const template = await fs.promises.readFile(`${basepath}/${tdata.template}.docx`)
|
|
let url =
|
|
"https://bma-dashboard.frappet.synology.me/d/ANtkJay4z/4Lic4Li54LmJ4Lie4Li04LiB4Liy4Lij?orgId=1&kiosk"
|
|
//let url = "https://pantip.com"
|
|
// let url = "https://google.com"
|
|
|
|
let buffer = await htmlTemplateX(url, tdata, ext)
|
|
fs.writeFileSync(".output/" + tdata.reportName + "." + ext, buffer)
|
|
rl.close()
|
|
})()
|