1 | const fs = require('fs-extra')
|
2 | const path = require('path')
|
3 | const getCwd = require('../utils/get-cwd')
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | const validateTemplate = async (template) => {
|
14 | if (typeof template !== 'string')
|
15 | throw new Error('validate-template: `template` need to be String')
|
16 |
|
17 | let templateStr
|
18 | if (fs.existsSync(template)) {
|
19 | templateStr = await fs.readFile(template, 'utf-8')
|
20 | } else if (template.substr(0, 2) === './') {
|
21 | templateStr = await fs.readFile(path.resolve(getCwd(), template), 'utf-8')
|
22 | } else if (path.isAbsolute(template)) {
|
23 | templateStr = await fs.readFile(path.resolve(template), 'utf-8')
|
24 | }
|
25 |
|
26 | return (templateStr + `\n<!-- rendered by using koot.js ${process.env.KOOT_VERSION} -->`)
|
27 | }
|
28 |
|
29 | module.exports = validateTemplate
|