diff options
| author | Kevin J Hoerr <kjhoerr@protonmail.com> | 2019-12-09 18:11:26 -0500 |
|---|---|---|
| committer | Kevin J Hoerr <kjhoerr@protonmail.com> | 2019-12-09 18:11:26 -0500 |
| commit | 85d646880e1e3fef1d9547b72c2d0107e3465d90 (patch) | |
| tree | aaa1b2e2347daf1fa277baf33a6b0bedf35c009d /src/templates.ts | |
| parent | 05204ed4699f983887db85416dba9a387b1c235a (diff) | |
| download | ao-coverage-85d646880e1e3fef1d9547b72c2d0107e3465d90.tar.gz ao-coverage-85d646880e1e3fef1d9547b72c2d0107e3465d90.tar.bz2 ao-coverage-85d646880e1e3fef1d9547b72c2d0107e3465d90.zip | |
Add template process to serve bash file
Unfortunately, a static file can't really be used to serve the
connection - the host address is needed to link back to the server.
Only a light library is needed to handle the template file though,
and if more are needed in the future it should be a non-trivial
task to add them to the process.
By default I'm configuring this to work with drone.io, since that
is the CI that I personally will be using (most likely). It should
be non-trivial to configure other CI to handle the script as well.
Diffstat (limited to 'src/templates.ts')
| -rw-r--r-- | src/templates.ts | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/templates.ts b/src/templates.ts new file mode 100644 index 0000000..2ffd0dd --- /dev/null +++ b/src/templates.ts @@ -0,0 +1,30 @@ +import winston from "winston"; +import handlebars from "handlebars"; +import path from "path"; +import fs from "fs"; + +import loggerConfig from "./util/logger"; +import { configOrError } from "./util/config"; + +const logger = winston.createLogger(loggerConfig("TEMPLATE")); + +const HOST_DIR = configOrError("HOST_DIR"); +const TARGET_URL = process.env.TARGET_URL || "http://localhost:3000"; + +fs.promises + .readFile(path.join(__dirname, "..", "public", "bash.template"), "utf-8") + .then(buffer => { + const translate = handlebars.compile(buffer); + + return { + name: "bash", + data: translate({ TARGET_URL }) + }; + }) + .then(file => + fs.promises + .writeFile(path.join(HOST_DIR, file.name), file.data) + .then(() => file) + ) + .then(file => logger.debug("Generated '%s' from template file", file.name)) + .catch(err => logger.error("Error while generating template file: %s", err)); |
