How to use the @teleporthq/teleport-types.FileType.JS function in @teleporthq/teleport-types

To help you get started, we’ve selected a few @teleporthq/teleport-types 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-postprocessor-vue-file / src / index.ts View on Github external
const processor: PostProcessor = (codeChunks) => {
    let jsCode
    let cssCode
    let htmlCode

    if (codeChunks[FileType.HTML]) {
      htmlCode = StringUtils.removeLastEmptyLine(codeChunks[FileType.HTML])
    } else {
      throw new Error('No code chunk of type HTML found, vue file concatenation aborded')
    }

    if (codeChunks[FileType.JS]) {
      jsCode = StringUtils.removeLastEmptyLine(codeChunks[FileType.JS])
    } else {
      throw new Error('No code chunk of type JS found, vue file concatenation aborded')
    }

    // if no CSS, skip the <style></style>
    if (codeChunks[FileType.CSS]) {
      cssCode = StringUtils.removeLastEmptyLine(codeChunks[FileType.CSS])
    }

    const formattedHTMLCode = StringUtils.addSpacesToEachLine(' '.repeat(2), htmlCode)
    const vueCode = buildVueFile(formattedHTMLCode, jsCode, cssCode)

    return {
      [FileType.VUE]: vueCode,
    }
github teleporthq / teleport-code-generators / packages / teleport-plugin-react-jss / __tests__ / index.ts View on Github external
nodesLookup: {
        container: {
          openingElement: {
            name: {
              name: '',
            },
            attributes: [],
          },
        },
      },
      dynamicRefPrefix: {
        prop: 'props.',
      },
    },
    type: ChunkType.AST,
    fileType: FileType.JS,
    linkAfter: ['import-local'],
    content: {},
  }

  it('generates no chunk if no styles exist', async () => {
    const uidlSample = component('JSS', elementNode('container'))
    const structure: ComponentStructure = {
      uidl: uidlSample,
      options: {},
      chunks: [componentChunk],
      dependencies: {},
    }

    const { chunks } = await plugin(structure)

    expect(chunks.length).toBe(1)
github teleporthq / teleport-code-generators / packages / teleport-plugin-jsx-inline-styles / __tests__ / index.ts View on Github external
nodesLookup: {
        container: {
          openingElement: {
            name: {
              name: '',
            },
            attributes: [],
          },
        },
      },
      dynamicRefPrefix: {
        prop: 'props.',
      },
    },
    type: ChunkType.AST,
    fileType: FileType.JS,
    linkAfter: ['import-local'],
    content: {},
  }

  it('adds nothing to the AST if not style is defined', async () => {
    const uidlSample = component('InlineStyles', elementNode('container'))
    const structure: ComponentStructure = {
      uidl: uidlSample,
      options: {},
      chunks: [componentChunk],
      dependencies: {},
    }

    const oldStructure = JSON.stringify(structure)
    await plugin(structure)
    const newStructure = JSON.stringify(structure)
github teleporthq / teleport-code-generators / packages / teleport-plugin-jsx-proptypes / __tests__ / index.ts View on Github external
describe('plugin-jsx-proptypes', () => {
  const plugin = createPropTypesPlugin()
  const reactChunk: ChunkDefinition = {
    type: ChunkType.AST,
    fileType: FileType.JS,
    name: 'jsx-component',
    content: {},
    linkAfter: [],
  }
  const exportChunk = {
    type: ChunkType.AST,
    fileType: FileType.JS,
    name: 'export',
    content: {},
    linkAfter: ['jsx-component'],
  }

  it('Should throw error when the chunk is supplied', async () => {
    const uidlSample = component('SimpleComponent', elementNode('container'))
    const structure: ComponentStructure = {
      uidl: uidlSample,
github teleporthq / teleport-code-generators / packages / teleport-plugin-jsx-proptypes / __tests__ / index.ts View on Github external
describe('plugin-jsx-proptypes', () => {
  const plugin = createPropTypesPlugin()
  const reactChunk: ChunkDefinition = {
    type: ChunkType.AST,
    fileType: FileType.JS,
    name: 'jsx-component',
    content: {},
    linkAfter: [],
  }
  const exportChunk = {
    type: ChunkType.AST,
    fileType: FileType.JS,
    name: 'export',
    content: {},
    linkAfter: ['jsx-component'],
  }

  it('Should throw error when the chunk is supplied', async () => {
    const uidlSample = component('SimpleComponent', elementNode('container'))
    const structure: ComponentStructure = {
      uidl: uidlSample,
      options: {},
      chunks: [],
      dependencies: {},
    }
    try {
      await plugin(structure)
    } catch (e) {
github teleporthq / teleport-code-generators / packages / teleport-plugin-css-modules / __tests__ / mocks.ts View on Github external
nodesLookup: {
        [elementKey]: {
          openingElement: {
            name: {
              name: '',
            },
            attributes: [],
          },
        },
      },
      dynamicRefPrefix: {
        prop: 'props.',
      },
    },
    type: ChunkType.AST,
    fileType: FileType.JS,
    linkAfter: ['import-local'],
    content: {},
  }

  return componentChunk
}
github teleporthq / teleport-code-generators / packages / teleport-plugin-preact-base-component / src / index.ts View on Github external
}

    const jsxTagStructure = createJSXSyntax(uidl.node, jsxParams, jsxOptions)

    if (!usePureComponent) {
      dependencies.Component = PREACT_COMPONENT_DEPENDENCY
    }

    const componentName = UIDLUtils.getComponentClassName(uidl)
    const preactComponent = usePureComponent
      ? createPureComponent(componentName, propDefinitions, jsxTagStructure)
      : createClassComponent(componentName, propDefinitions, stateDefinitions, jsxTagStructure)

    structure.chunks.push({
      type: ChunkType.AST,
      fileType: FileType.JS,
      name: componentChunkName,
      meta: {
        nodesLookup,
        dynamicRefPrefix: jsxOptions.dynamicReferencePrefixMap,
      },
      content: preactComponent,
      linkAfter: [importChunkName],
    })

    structure.chunks.push({
      type: ChunkType.AST,
      fileType: FileType.JS,
      name: exportChunkName,
      content: ASTBuilders.createDefaultExport(componentName),
      linkAfter: [componentChunkName],
    })
github teleporthq / teleport-code-generators / packages / teleport-plugin-react-app-routing / src / index.ts View on Github external
const pureComponent = ASTBuilders.createFunctionalComponent(uidl.name, rootRouterTag)

    structure.chunks.push({
      type: ChunkType.AST,
      fileType: FileType.JS,
      name: componentChunkName,
      content: pureComponent,
      linkAfter: [importChunkName],
    })

    if (flavor === 'preact') {
      const exportJSXApp = ASTBuilders.createDefaultExport('App')

      structure.chunks.push({
        type: ChunkType.AST,
        fileType: FileType.JS,
        name: domRenderChunkName,
        content: exportJSXApp,
        linkAfter: [componentChunkName],
      })
    } else {
      const reactDomBind = ASTBuilders.createFunctionCall('ReactDOM.render', [
        ASTBuilders.createSelfClosingJSXTag(uidl.name),
        ASTBuilders.createFunctionCall('document.getElementById', ['app']),
      ])

      structure.chunks.push({
        type: ChunkType.AST,
        fileType: FileType.JS,
        name: domRenderChunkName,
        content: reactDomBind,
        linkAfter: [componentChunkName],
github teleporthq / teleport-code-generators / packages / teleport-plugin-export-components / src / index.ts View on Github external
)
    })

    let exportSpecifiers = []
    exportSpecifiers = Object.keys(components).map((component) =>
      t.exportSpecifier(
        t.identifier(StringUtils.capitalize(component)),
        t.identifier(StringUtils.capitalize(component))
      )
    )
    const exportAST = t.exportNamedDeclaration(null, exportSpecifiers)

    chunks.push({
      name: importChunkName,
      type: ChunkType.AST,
      fileType: FileType.JS,
      content: importsAST,
      linkAfter: [],
    })

    chunks.push({
      name: exportChunkName,
      type: ChunkType.AST,
      fileType: FileType.JS,
      content: exportAST,
      linkAfter: [importChunkName],
    })

    return structure
  }
github teleporthq / teleport-code-generators / packages / teleport-plugin-import-statements / src / index.ts View on Github external
export const createImportPlugin: ComponentPluginFactory = (config) =&gt; {
  const {
    importLibsChunkName = 'import-lib',
    importPackagesChunkName = 'import-pack',
    importLocalsChunkName = 'import-local',
    fileType = FileType.JS,
  } = config || {}

  const importPlugin: ComponentPlugin = async (structure) =&gt; {
    const { dependencies } = structure

    const libraryDependencies = groupDependenciesByPackage(dependencies, 'library')
    const packageDependencies = groupDependenciesByPackage(dependencies, 'package')
    const localDependencies = groupDependenciesByPackage(dependencies, 'local')
    addImportChunk(structure.chunks, libraryDependencies, importLibsChunkName, fileType)
    addImportChunk(structure.chunks, packageDependencies, importPackagesChunkName, fileType)
    addImportChunk(structure.chunks, localDependencies, importLocalsChunkName, fileType)
    return structure
  }

  return importPlugin
}