Loading repository data…
Loading repository data…
teleporthq / repository
A collection of code generators for modern JavaScript applications
We are not far from the first official version of the code generators, but meanwhile, keep in mind that some of the parts of the ecosystem are experimental.
teleportHQ is a low-code platform that enables teams to build applications via a familiar design tool interface, in real-time.
This repository holds the code generators that power the visual editor of the platform.
https://user-images.githubusercontent.com/3997538/123211638-63efaa00-d4cc-11eb-90b1-49bd61a95732.mp4
The glue between the platform and the code generators is the UIDL Standard. The UIDL defines the user interfaces in an abstract way, independent of any framework or even the web platform itself. Starting from the UIDL, you can convert that abstraction into different flavors of coding (e.g. React, Vue, WebComponents etc.).
These code generators are part of a larger ecosystem, which we're actively building in an effort to streamline the creation of web applications. You can read more about our inception in this article.
The philosophy behind the code generators is:
React, can also be built with Vue or on top of the Web Components standard - we support multiple targetsRead more about the UIDL Standard.
The easiest way to jump into the teleport ecosystem is to try out one of the pre-configured component generators:
npm install @teleporthq/teleport-component-generator-react
npm install @teleporthq/teleport-component-generator-vue
npm install @teleporthq/teleport-component-generator-angular
or using yarn:
yarn add @teleporthq/teleport-component-generator-react
yarn add @teleporthq/teleport-component-generator-vue
yarn add @teleporthq/teleport-component-generator-angular
For generating a simple component, you have to start from a component UIDL:
{
"name": "My First Component",
"node": {
"type": "element",
"content": {
"elementType": "text",
"children": [
{
"type": "static",
"content": "Hello World!"
}
]
}
}
}
Using the pre-configured component generators is as easy as calling an async function:
import ReactGenerator from '@teleporthq/teleport-component-generator-react'
const uidl = { ... } // your sample here
const { files } = await ReactGenerator.generateComponent(uidl)
console.log(files[0].content)
The console output will be something like:
import React from 'react'
const MyFirstComponent = (props) => {
return <span>Hello World!</span>
}
export default MyFirstComponent
For other frameworks, just switch the package:
import VueGenerator from '@teleporthq/teleport-component-generator-vue'
const uidl = { ... } // your sample here
const { files } = await VueGenerator.generateComponent(uidl)
console.log(files[0].content)
The console output will be something like:
<template>
<span>Hello World!</span>
</template>
<script>
export default {
name: 'MyFirstComponent',
}
</script>
You can play with the UIDL structure and also observe the generated code in the online REPL. While there, can also check different examples of components written in the UIDL format.
The teleport ecosystem consists of three main categories of packages: component generators, project generators and project packers.
We have official component generators for a couple of popular web frontend frameworks. Check out the official docs for an in depth understanding of the architecture behind the component generators.
All the component generators are exposing an instance of the teleport-component-generator package. You can also install this package and build your own generator with plugins, mappings and postprocessors.
In the docs, you'll find a complete guide on how to build your custom component generator.
teleport-component-generator-react - with styling: css-modules, styled-components, styled-jsx, etc.teleport-component-generator-vue - generating standard .vue filesteleport-component-generator-angular - generates .ts, .html and .css filesteleport-component-generator-html - (experimental)teleport-component-generator-svelte - (coming soon)Here's a list of functionalities that the UIDL and the component generators are supporting at the moment, besides the obvious presentational layer:
Project generators rely on a ProjectUIDL input and on a project strategy. The ProjectUIDL will contain all the information about routing, pages, components and global settings. The strategy will tell the generators where to put each file and which component generator to use.
The generators will output an abstract structure with folders and files, without writing anything to disk. The project packer is tasked with taking the output of a project generator and publishing it somewhere.
Check the official guides on how to use an existing project generator or how to create your custom configuration
teleport-project-generator-react - react + react-router and css-modules on top of create-react-appteleport-project-generator-next - based on Next.jsteleport-project-generator-vue - with a structure starting from the vue-cliteleport-project-generator-nuxt - based on Nuxt.jsteleport-project-generator-angular - based on the angular-cliteleport-project-generator-html (experimental)Besides the regular files and folders generated at the end of the process, project generators are also taking care of:
package.json.index.html or something that is framework specific).Once a generator created the code for the components and pages, the project packer will take that output, put it on top of an existing project template, add any local assets required and then will pass the entire result to a publisher. The publishers are specialized in deploying the entire folder structure to a 3rd party like vercel or github, or in creating an in-memory zip file or simply writing the folder to disk.
teleport-publisher-vercelteleport-publisher-githubteleport-publisher-codesandboxteleport-publisher-zipteleport-publisher-diskteleport-publisher-netlify (coming soon)A few useful links to get you up to speed with the entire teleport ecosystem:
This project uses:
In order to give it a spin locally, we recommend using yarn, as it integrates better with lerna and all the contributors are using it:
yarn
This installs the dependencies in the root folder, but also creates the symlinks between the independent modules inside the packages folder.
To complete the lerna setup, you need to run:
yarn build
This will run the build task inside each individual package, creating the output lib folder. We have two outputs for each package: cjs - common js style modules and esm - modern es modules. If you want to speed up your build time, you can run just build:cjs to avoid the esm build.
Running the test suite:
yarn test
yarn test:coverage
Furthermore, there's a private package inside the lerna folder called teleport-test. That packages can be used to test the code/file generation process with any flavor of project/component generator. In order to give it a spin you will have to:
cd packages/teleport-test
npm run stan