(configObj, dirs, configObjOverride = undefined)
| 11 | import TemplateEngineManager from "../src/Engines/TemplateEngineManager.js"; |
| 12 | |
| 13 | export async function getTemplateConfigInstance(configObj, dirs, configObjOverride = undefined) { |
| 14 | let eleventyConfig; |
| 15 | if(configObj instanceof TemplateConfig) { |
| 16 | eleventyConfig = configObj; |
| 17 | configObj = undefined; |
| 18 | |
| 19 | if(!(dirs instanceof ProjectDirectories)) { |
| 20 | throw new Error("Testing error: second argument to getTemplateConfigInstance must be a ProjectDirectories instance when the first argument is a TemplateConfig instance.") |
| 21 | } |
| 22 | } else { |
| 23 | eleventyConfig = new TemplateConfig(); |
| 24 | } |
| 25 | |
| 26 | eleventyConfig.setProjectUsingEsm(true); |
| 27 | |
| 28 | if(!(dirs instanceof ProjectDirectories)) { |
| 29 | dirs = new ProjectDirectories(); |
| 30 | if(isPlainObject(configObj) && !configObj.dir) { |
| 31 | throw new Error("Testing error: missing `dir` property on config object literal passed in.") |
| 32 | } |
| 33 | dirs.setViaConfigObject(configObj?.dir || {}); |
| 34 | } |
| 35 | |
| 36 | eleventyConfig.setDirectories(dirs); |
| 37 | |
| 38 | await eleventyConfig.init(configObjOverride || configObj); // overrides |
| 39 | |
| 40 | return eleventyConfig; |
| 41 | } |
| 42 | |
| 43 | export async function getTemplateConfigInstanceCustomCallback(dirObject, configCallback) { |
| 44 | let tmplCfg = new TemplateConfig(); |
no test coverage detected