-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a work in progress to try upgrading to webpack 5.
- Loading branch information
Showing
12 changed files
with
2,299 additions
and
1,864 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import jade from "jade" | ||
import path from "path" | ||
import { first, isArray } from "lodash" | ||
|
||
type RenderOptions = { | ||
basePath?: string, | ||
compilerOptions?: object, | ||
locals?: object, | ||
} | ||
|
||
export default function renderTemplate(templates: string, options: RenderOptions): string; | ||
export default function renderTemplate(templates: string[], options: RenderOptions): string[]; | ||
export default function renderTemplate(templates: string | string[], options: RenderOptions = {}): string | string[] { | ||
const normalizedTemplates = isArray(templates) ? templates : [templates] | ||
|
||
const { basePath = "", compilerOptions = {}, locals = {} } = options | ||
|
||
const templateFns = normalizedTemplates.map(file => { | ||
return jade.compileFile(path.join(basePath, file), compilerOptions) as (obj: any) => string | ||
}) | ||
|
||
const renderedTemplates = templateFns.map(template => template(locals)) | ||
|
||
// If user only passed in a single template, return a single template | ||
const out = | ||
renderedTemplates.length > 1 ? renderedTemplates : first(renderedTemplates) | ||
|
||
return out | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.