How to use the @teleporthq/teleport-types.ChunkType.STRING 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-plugin-css / src / index.ts View on Github external
const inlineStyles = createDynamicInlineStyle(rootStyles)
            HASTUtils.addAttributeToNode(root, inlineStyleAttributeKey, `{${inlineStyles}}`)
          } else {
            // jsx object expression
            const inlineStyles = UIDLUtils.transformDynamicStyles(rootStyles, (styleValue) =>
              StyleBuilders.createDynamicStyleExpression(styleValue, propsPrefix)
            )
            ASTUtils.addAttributeToJSXTag(root, inlineStyleAttributeKey, inlineStyles)
          }
        }
      }
    })

    if (jssStylesArray.length > 0) {
      chunks.push({
        type: ChunkType.STRING,
        name: chunkName,
        fileType: FileType.CSS,
        content: jssStylesArray.join('\n'),
        linkAfter: [],
      })

      /**
       * Setup an import statement for the styles
       * The name of the file is either in the meta of the component generator
       * or we fallback to the name of the component
       */
      const cssFileName = UIDLUtils.getStyleFileName(uidl)

      if (declareDependency === 'decorator' && componentDecoratorChunk) {
        const decoratorAST = componentDecoratorChunk.content
        const decoratorParam = decoratorAST.expression.arguments[0]
github teleporthq / teleport-code-generators / packages / teleport-component-generator / src / builder / index.ts View on Github external
import { generator as babelCodeGenerator } from './generators/js-ast-to-code'
import { generator as htmlGenerator } from './generators/html-to-string'
import {
  ChunkDefinition,
  CodeGeneratorFunction,
  ChunkContent,
  ChunkType,
} from '@teleporthq/teleport-types'

export default class Builder {
  private chunkDefinitions: ChunkDefinition[] = []

  private generators: { [key: string]: CodeGeneratorFunction } = {
    [ChunkType.AST]: babelCodeGenerator,
    [ChunkType.HAST]: htmlGenerator,
    [ChunkType.STRING]: (str: string) => str, // no-op for string chunks
  }

  constructor(chunkDefinitions: ChunkDefinition[] = []) {
    this.chunkDefinitions = chunkDefinitions
  }

  /**
   * Links all chunks together based on their requirements. Returns an array
   * of ordered chunk names which need to be compiled and glued together.
   */
  public link(chunkDefinitions: ChunkDefinition[] = []): string {
    const chunks = chunkDefinitions || this.chunkDefinitions
    if (chunks.length <= 0) {
      return ''
    }
github teleporthq / teleport-code-generators / packages / teleport-component-generator / __tests__ / index.ts View on Github external
it('works with no postprocessor', () => {
      const generator = createComponentGenerator()
      const codeChunks: Record = {
        js: [
          {
            type: ChunkType.STRING,
            fileType: FileType.JS,
            name: 'chunk',
            content: 'import lib from "lib"',
            linkAfter: [],
          },
        ],
      }

      generator.addPostProcessor((_) => _)

      const result = generator.linkCodeChunks(codeChunks, 'output')
      expect(result[0].fileType).toBe('js')
      expect(result[0].content).toContain('import lib from "lib"')
      expect(result[0].name).toBe('output')
    })
  })
github teleporthq / teleport-code-generators / packages / teleport-project-generator / src / file-handlers.ts View on Github external
if (asset.options && asset.options.iconSizes) {
        HASTUtils.addAttributeToNode(iconTag, 'sizes', asset.options.iconSizes)
      }
      HASTUtils.addChildNode(headNode, iconTag)
    }
  })

  if (customHeadContent) {
    HASTUtils.addTextNode(headNode, customHeadContent)
  }

  const chunks: Record = {
    [FileType.HTML]: [
      {
        name: 'doctype',
        type: ChunkType.STRING,
        fileType: FileType.HTML,
        content: '',
        linkAfter: [],
      },
      {
        name: 'html-node',
        type: ChunkType.HAST,
        fileType: FileType.HTML,
        content: htmlNode,
        linkAfter: ['doctype'],
      },
    ],
  }

  return chunks
}
github teleporthq / teleport-code-generators / packages / teleport-plugin-css-modules / src / index.ts View on Github external
* In case the moduleExtension flag is passed, the file name should be in the form [fileName].module.css
     */
    if (moduleExtension) {
      cssFileName = `${cssFileName}.module`
      uidl.outputOptions = uidl.outputOptions || {}
      uidl.outputOptions.styleFileName = cssFileName
    }

    dependencies[styleObjectImportName] = {
      type: 'local',
      path: `./${cssFileName}.${FileType.CSS}`,
    }

    structure.chunks.push({
      name: styleChunkName,
      type: ChunkType.STRING,
      fileType: FileType.CSS,
      content: cssClasses.join('\n'),
      linkAfter: [],
    })

    return structure
  }
github teleporthq / teleport-code-generators / packages / teleport-plugin-css-modules / src / index.ts View on Github external
* In case the moduleExtension flag is passed, the file name should be in the form [fileName].module.css
     */
    if (moduleExtension) {
      cssFileName = `${cssFileName}.module`
      uidl.outputOptions = uidl.outputOptions || {}
      uidl.outputOptions.styleFileName = cssFileName
    }

    dependencies[styleObjectImportName] = {
      type: 'local',
      path: `./${cssFileName}.${FileType.CSS}`,
    }

    structure.chunks.push({
      name: styleChunkName,
      type: ChunkType.STRING,
      fileType: FileType.CSS,
      content: cssClasses.join('\n'),
      linkAfter: [],
    })

    return structure
  }