Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const createDocumentFileChunks = (uidl: ProjectUIDL, options: EntryFileOptions) => {
const { settings, meta, assets, manifest } = uidl.globals
const htmlNode = ASTBuilders.createJSXTag('html')
const headNode = ASTBuilders.createJSXTag('Head')
const bodyNode = ASTBuilders.createJSXTag('body')
const mainNode = ASTBuilders.createJSXTag('Main')
const nextScriptNode = ASTBuilders.createJSXTag('NextScript')
ASTUtils.addChildJSXTag(bodyNode, mainNode)
ASTUtils.addChildJSXTag(bodyNode, nextScriptNode)
ASTUtils.addChildJSXTag(htmlNode, headNode)
ASTUtils.addChildJSXTag(htmlNode, bodyNode)
if (settings.language) {
ASTUtils.addAttributeToJSXTag(htmlNode, 'lang', settings.language)
}
// NOTE: Title is added in per page, not in the layout file
if (manifest) {
export const createDocumentFileChunks = (uidl: ProjectUIDL, options: EntryFileOptions) => {
const { settings, meta, assets, manifest } = uidl.globals
const htmlNode = ASTBuilders.createJSXTag('html')
const headNode = ASTBuilders.createJSXTag('Head')
const bodyNode = ASTBuilders.createJSXTag('body')
const mainNode = ASTBuilders.createJSXTag('Main')
const nextScriptNode = ASTBuilders.createJSXTag('NextScript')
ASTUtils.addChildJSXTag(bodyNode, mainNode)
ASTUtils.addChildJSXTag(bodyNode, nextScriptNode)
ASTUtils.addChildJSXTag(htmlNode, headNode)
ASTUtils.addChildJSXTag(htmlNode, bodyNode)
if (settings.language) {
ASTUtils.addAttributeToJSXTag(htmlNode, 'lang', settings.language)
}
// NOTE: Title is added in per page, not in the layout file
if (manifest) {
const linkTag = ASTBuilders.createJSXTag('link')
ASTUtils.addAttributeToJSXTag(linkTag, 'rel', 'manifest')
export const createDocumentFileChunks = (uidl: ProjectUIDL, options: EntryFileOptions) => {
const { settings, meta, assets, manifest } = uidl.globals
const htmlNode = ASTBuilders.createJSXTag('html')
const headNode = ASTBuilders.createJSXTag('Head')
const bodyNode = ASTBuilders.createJSXTag('body')
const mainNode = ASTBuilders.createJSXTag('Main')
const nextScriptNode = ASTBuilders.createJSXTag('NextScript')
ASTUtils.addChildJSXTag(bodyNode, mainNode)
ASTUtils.addChildJSXTag(bodyNode, nextScriptNode)
ASTUtils.addChildJSXTag(htmlNode, headNode)
ASTUtils.addChildJSXTag(htmlNode, bodyNode)
if (settings.language) {
ASTUtils.addAttributeToJSXTag(htmlNode, 'lang', settings.language)
}
// NOTE: Title is added in per page, not in the layout file
const generateHTMLNode = (uidl: ProjectUIDL, options: EntryFileOptions, t = types) => {
const { settings, meta, assets } = uidl.globals
const htmlNode = ASTBuilders.createJSXTag('html')
const headNode = ASTBuilders.createJSXTag('head')
const bodyNode = ASTBuilders.createJSXTag('body')
const noScriptNode = ASTBuilders.createJSXTag('noscript')
if (uidl.globals.manifest) {
const manifestTag = ASTBuilders.createJSXTag('link')
ASTUtils.addAttributeToJSXTag(manifestTag, 'rel', 'manifest')
ASTUtils.addAttributeToJSXTag(manifestTag, 'href', '/manifest.json')
ASTUtils.addChildJSXTag(headNode, manifestTag)
}
const charSetMetaTag = ASTBuilders.createSelfClosingJSXTag('meta')
ASTUtils.addAttributeToJSXTag(charSetMetaTag, 'charSet', 'utf-8')
ASTUtils.addChildJSXTag(headNode, charSetMetaTag)
const httpMetaTag = ASTBuilders.createSelfClosingJSXTag('meta')
export const createClassDeclaration = (
routes: UIDLConditionalNode[],
routeDefinitions: UIDLStateDefinition,
t = types
) => {
const stencilRouterTag = ASTBuilders.createJSXTag('stencil-router')
const stencilRouteSwitchTag = ASTBuilders.createJSXTag('stencil-route-switch')
ASTUtils.addChildJSXTag(stencilRouterTag, stencilRouteSwitchTag)
routes.forEach((routeNode) => {
const pageKey = routeNode.content.value.toString()
const pageDefinition = routeDefinitions.values.find((route) => route.value === pageKey)
const { componentName, navLink } = pageDefinition.pageOptions
const stencilRouteTag = ASTBuilders.createJSXTag('stencil-route')
ASTUtils.addAttributeToJSXTag(stencilRouteTag, 'url', navLink)
if (navLink === '/') {
ASTUtils.addAttributeToJSXTag(stencilRouteTag, 'exact', true)
}
ASTUtils.addAttributeToJSXTag(
stencilRouteTag,
'component',
routes.forEach((routeNode) => {
const pageKey = routeNode.content.value.toString()
const pageDefinition = routeDefinitions.values.find((route) => route.value === pageKey)
const { componentName, navLink } = pageDefinition.pageOptions
const stencilRouteTag = ASTBuilders.createJSXTag('stencil-route')
ASTUtils.addAttributeToJSXTag(stencilRouteTag, 'url', navLink)
if (navLink === '/') {
ASTUtils.addAttributeToJSXTag(stencilRouteTag, 'exact', true)
}
ASTUtils.addAttributeToJSXTag(
stencilRouteTag,
'component',
UIDLUtils.createWebComponentFriendlyName(componentName)
)
ASTUtils.addChildJSXTag(stencilRouteSwitchTag, stencilRouteTag)
})
const { componentName, navLink } = pageDefinition.pageOptions
const stencilRouteTag = ASTBuilders.createJSXTag('stencil-route')
ASTUtils.addAttributeToJSXTag(stencilRouteTag, 'url', navLink)
if (navLink === '/') {
ASTUtils.addAttributeToJSXTag(stencilRouteTag, 'exact', true)
}
ASTUtils.addAttributeToJSXTag(
stencilRouteTag,
'component',
UIDLUtils.createWebComponentFriendlyName(componentName)
)
ASTUtils.addChildJSXTag(stencilRouteSwitchTag, stencilRouteTag)
})
const mainTag = ASTBuilders.createJSXTag('main')
ASTUtils.addChildJSXTag(mainTag, stencilRouterTag)
const divTag = ASTBuilders.createJSXTag('div')
ASTUtils.addChildJSXTag(divTag, mainTag)
const returnAST = divTag as types.JSXElement
const classBodyAST = t.classBody([
t.classMethod(
'method',
t.identifier('render'),
[],
t.blockStatement([t.returnStatement(returnAST)])
),
])
const exportClass = t.exportNamedDeclaration(
const generateHTMLNode = (uidl: ProjectUIDL, options: EntryFileOptions, t = types) => {
const { settings, meta, assets } = uidl.globals
const htmlNode = ASTBuilders.createJSXTag('html')
const headNode = ASTBuilders.createJSXTag('head')
const bodyNode = ASTBuilders.createJSXTag('body')
const noScriptNode = ASTBuilders.createJSXTag('noscript')
if (uidl.globals.manifest) {
const manifestTag = ASTBuilders.createJSXTag('link')
ASTUtils.addAttributeToJSXTag(manifestTag, 'rel', 'manifest')
ASTUtils.addAttributeToJSXTag(manifestTag, 'href', '/manifest.json')
ASTUtils.addChildJSXTag(headNode, manifestTag)
}
const charSetMetaTag = ASTBuilders.createSelfClosingJSXTag('meta')
ASTUtils.addAttributeToJSXTag(charSetMetaTag, 'charSet', 'utf-8')
ASTUtils.addChildJSXTag(headNode, charSetMetaTag)
const httpMetaTag = ASTBuilders.createSelfClosingJSXTag('meta')
ASTUtils.addAttributeToJSXTag(httpMetaTag, 'httpEquiv', 'x-ua-compatible')
ASTUtils.addAttributeToJSXTag(httpMetaTag, 'content', 'ie=edge')
ASTUtils.addChildJSXTag(headNode, httpMetaTag)
const generateHTMLNode = (uidl: ProjectUIDL, options: EntryFileOptions, t = types) => {
const { settings, meta, assets } = uidl.globals
const htmlNode = ASTBuilders.createJSXTag('html')
const headNode = ASTBuilders.createJSXTag('head')
const bodyNode = ASTBuilders.createJSXTag('body')
const noScriptNode = ASTBuilders.createJSXTag('noscript')
if (uidl.globals.manifest) {
const manifestTag = ASTBuilders.createJSXTag('link')
ASTUtils.addAttributeToJSXTag(manifestTag, 'rel', 'manifest')
ASTUtils.addAttributeToJSXTag(manifestTag, 'href', '/manifest.json')
ASTUtils.addChildJSXTag(headNode, manifestTag)
}
const charSetMetaTag = ASTBuilders.createSelfClosingJSXTag('meta')
ASTUtils.addAttributeToJSXTag(charSetMetaTag, 'charSet', 'utf-8')
ASTUtils.addChildJSXTag(headNode, charSetMetaTag)
const httpMetaTag = ASTBuilders.createSelfClosingJSXTag('meta')
ASTUtils.addAttributeToJSXTag(httpMetaTag, 'httpEquiv', 'x-ua-compatible')
ASTUtils.addAttributeToJSXTag(httpMetaTag, 'content', 'ie=edge')
export const createRouteRouterTag = (flavour: string, routeJSXDefinitions: types.JSXElement[]) => {
const routerTag = ASTBuilders.createJSXTag('Router')
if (flavour === 'preact') {
routeJSXDefinitions.forEach((route) => ASTUtils.addChildJSXTag(routerTag, route))
return routerTag
}
const divContainer = ASTBuilders.createJSXTag('div')
ASTUtils.addChildJSXTag(routerTag, divContainer)
routeJSXDefinitions.forEach((route) => ASTUtils.addChildJSXTag(divContainer, route))
return routerTag
}