How to use the @teleporthq/teleport-shared.UIDLUtils.extractRoutes function in @teleporthq/teleport-shared

To help you get started, we’ve selected a few @teleporthq/teleport-shared examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github teleporthq / teleport-code-generators / packages / teleport-plugin-stencil-app-routing / src / index.ts View on Github external
const stencilAppRoutingtPlugin: ComponentPlugin = async (structure) => {
    const { chunks, uidl, dependencies } = structure

    dependencies.Component = STENCIL_CORE_DEPENDENCY
    dependencies.h = STENCIL_CORE_DEPENDENCY

    const routes = UIDLUtils.extractRoutes(uidl)
    const routeDefinitions = uidl.stateDefinitions.route

    /* The name should be injected only with AppRoot only then it acts as entry point,
    Sending only Root because app is appended while generation of decorators*/
    const params = {
      tag: 'app-root',
      shadow: true,
    }
    const decoratorAST = ASTBuilders.createComponentDecorator(params)

    chunks.push({
      name: componentDecoratorChunkName,
      type: ChunkType.AST,
      fileType: FileType.TSX,
      content: [decoratorAST],
      linkAfter: [importChunkName],
github teleporthq / teleport-code-generators / packages / teleport-plugin-react-app-routing / src / index.ts View on Github external
const reactAppRoutingPlugin: ComponentPlugin = async (structure) => {
    const { uidl, dependencies, options } = structure

    if (flavor === 'preact') {
      registerPreactRouterDeps(dependencies)
    } else {
      registerReactRouterDeps(dependencies)
    }

    const { stateDefinitions = {} } = uidl

    const routes = UIDLUtils.extractRoutes(uidl)
    const strategy = options.strategy
    const pageDependencyPrefix = options.localDependenciesPrefix || './'

    const routeJSXDefinitions = routes.map((conditionalNode) => {
      const { value: routeKey } = conditionalNode.content
      const routeValues = stateDefinitions.route.values || []

      const pageDefinition = routeValues.find((route) => route.value === routeKey)
      const defaultOptions: UIDLPageOptions = {}
      const { fileName, componentName, navLink } = pageDefinition.pageOptions || defaultOptions

      /* If pages are exported in their own folder and in custom file names.
         Import statements must then be:

         import Home from '../pages/home/component'
github teleporthq / teleport-code-generators / packages / teleport-plugin-vue-app-routing / src / index.ts View on Github external
path: 'vue-router',
    }
    dependencies.Meta = {
      type: 'library',
      path: 'vue-meta',
    }

    const routerDeclaration = t.expressionStatement(
      t.callExpression(t.identifier('Vue.use'), [t.identifier('Router')])
    )

    const metaDeclaration = t.expressionStatement(
      t.callExpression(t.identifier('Vue.use'), [t.identifier('Meta')])
    )

    const routes = UIDLUtils.extractRoutes(uidl)
    const routeValues = uidl.stateDefinitions.route.values || []
    const pageDependencyPrefix = options.localDependenciesPrefix || './'

    /* If pages are exported in their own folder and in custom file names.
         Import statements must then be:

         import Home from '../pages/home/component'

         so the `/component` suffix is computed below.
      */
    const pageStrategyOptions = (options.strategy && options.strategy.pages.options) || {}
    const pageComponentSuffix = pageStrategyOptions.createFolderForEachComponent ? '/index' : ''

    const routesAST = routes.map((routeNode) => {
      const pageKey = routeNode.content.value.toString()
github teleporthq / teleport-code-generators / packages / teleport-plugin-angular-module / src / index.ts View on Github external
const { moduleComponents } = options

    let routesAST: types.VariableDeclaration
    let ngModuleAST: types.Decorator
    let moduleDecoratorAST: types.ExportNamedDeclaration

    dependencies.NgModule = ANGULAR_CORE_DEPENDENCY
    dependencies.RouterModule = ANGULAR_ROUTER
    switch (moduleType) {
      case 'root':
        {
          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)
github teleporthq / teleport-code-generators / packages / teleport-project-generator / src / utils.ts View on Github external
export const createPageUIDLs = (uidl: ProjectUIDL, strategy: ProjectStrategy): ComponentUIDL[] => {
  const routeNodes = UIDLUtils.extractRoutes(uidl.root)
  return routeNodes.map((routeNode) => createPageUIDL(routeNode, uidl, strategy))
}