Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
UIDLUtils.traverseElements(node, (element) => {
const { style, key } = element
if (!style) {
return
}
const { staticStyles, dynamicStyles } = UIDLUtils.splitDynamicAndStaticStyles(style)
const root = templateLookup[key]
if (Object.keys(staticStyles).length > 0) {
const elementClassName = StringUtils.camelCaseToDashCase(key)
const componentFileName = UIDLUtils.getComponentFileName(uidl) // Filename used to enforce dash case naming
const className = forceScoping // when the framework doesn't provide automating scoping for classNames
? `${componentFileName}-${elementClassName}`
: elementClassName
jssStylesArray.push(
StyleBuilders.createCSSClass(className, StyleUtils.getContentOfStyleObject(staticStyles))
)
if (templateStyle === 'html') {
HASTUtils.addClassToNode(root, className)
} else {
ASTUtils.addClassStringOnJSXTag(root, className, classAttributeName)
}
}
if (Object.keys(dynamicStyles).length > 0) {
dependencies.BrowserModule = ANGULAR_PLATFORM_BROWSER
dependencies.ComponentsModule = constructRouteForComponentsModule('.')
dependencies.AppComponent = APP_COMPONENT
const routes = UIDLUtils.extractRoutes(uidl)
routesAST = createRoutesAST(routes, stateDefinitions)
ngModuleAST = createRootModuleDecorator()
moduleDecoratorAST = createExportModuleAST('AppModule')
}
break
case 'page':
{
dependencies.ComponentsModule = constructRouteForComponentsModule('../..')
dependencies.CommonModule = ANGULAR_COMMON_MODULE
const componentName = UIDLUtils.getComponentClassName(uidl)
const fileName = UIDLUtils.getComponentFileName(uidl)
dependencies[componentName] = constructLocalDependency(fileName)
routesAST = createPageRouteAST(componentName)
ngModuleAST = createPageModuleModuleDecorator(componentName)
moduleDecoratorAST = createExportModuleAST(uidl.outputOptions.moduleName)
// Acording to widely followed convention module should have .module in its name
uidl.outputOptions.fileName = fileName.replace('.component', '.module')
}
break
case 'component':
{
dependencies.CommonModule = ANGULAR_COMMON_MODULE
// Looping through all components and importing them into component module
Object.keys(moduleComponents).forEach((componentKey) => {
chunks.push({
type: ChunkType.HAST,
name: angularTemplateChunkName,
fileType: FileType.HTML,
meta: {
nodesLookup: templateLookup,
},
content: templateContent,
linkAfter: [],
})
const componentName = UIDLUtils.getComponentClassName(uidl)
const params = {
selector: UIDLUtils.createWebComponentFriendlyName(componentName),
templateUrl: `${UIDLUtils.getComponentFileName(uidl)}.${FileType.HTML}`,
}
const componentDecoratorAST = ASTBuilders.createComponentDecorator(params)
chunks.push({
type: ChunkType.AST,
name: componentDecoratorChunkName,
fileType: FileType.TS,
linkAfter: tsChunkAfter,
content: componentDecoratorAST,
})
/* We need to import EventEmitter and Output in Angular to temit events to the parent
So, to make sure if we need to import them we need to loop through all the methods and
check if any of them are referring to the function that is passed as prop*/
if (Object.keys(methodsObject).length > 0) {
const shouldImportEventEmitter = Object.keys(methodsObject).some((method) => {
throw new Error('No plugins found. Component generation cannot work without any plugins!')
}
const { chunks, externalDependencies } = await assemblyLine.run(resolvedUIDL, options)
let codeChunks: Record = {}
Object.keys(chunks).forEach((fileType) => {
codeChunks[fileType] = chunksLinker.link(chunks[fileType])
})
processors.forEach((processor) => {
codeChunks = processor(codeChunks)
})
const fileName = UIDLUtils.getComponentFileName(resolvedUIDL)
const styleFileName = UIDLUtils.getStyleFileName(resolvedUIDL)
const templateFileName = UIDLUtils.getTemplateFileName(resolvedUIDL)
const files = fileBundler(codeChunks, fileName, styleFileName, templateFileName)
return {
files,
dependencies: externalDependencies,
}
}
Object.keys(moduleComponents).forEach((componentKey) => {
const component = moduleComponents[componentKey]
const componentClassName = UIDLUtils.getComponentClassName(component)
const componentFileName = UIDLUtils.getComponentFileName(component)
const componentFolderPath = UIDLUtils.getComponentFolderPath(component)
dependencies[componentClassName] = constructComponentDependency(
componentFolderPath,
componentFileName
)
})
const setLocalDependencyPath = (
element: UIDLElement,
components: Record,
fromPath: string[],
toBasePath: string[]
) => {
const componentKey = element.elementType
const component = components[componentKey]
const componentPath = UIDLUtils.getComponentFolderPath(component)
const componentClassName = UIDLUtils.getComponentClassName(component)
const toPath = toBasePath.concat(componentPath)
const importFileName = UIDLUtils.getComponentFileName(component)
const importPath = generateLocalDependenciesPrefix(fromPath, toPath)
element.dependency.path = `${importPath}${importFileName}`
element.elementType = componentClassName
}