0.38.3 โ€ข Published 25 days ago

@teleporthq/teleport-publisher-github v0.38.3

Weekly downloads
49
License
MIT
Repository
github
Last release
25 days ago

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.

The code generators are a part of the teleportHQ ecosystem, which we're actively building in an effort to streamline the creation of web and mobile applications. You can read more about our inception in this article.

The code generators are used by the online visual editor (coming soon), a platform that lets you build applications via a familiar design tool interface. 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.).

The philosophy behind the code generators is:

  • User interfaces are decomposed into components, hence the focus on component generation
  • What can be built with React, can also be built with Vue or on top of the Web Components standard - we support multiple targets
  • A project built with the visual editor should have a high standard of quality (performance, security, accessibility included)
  • Generated code quality should be as high as possible, so that any developer could pick up the work from there on and enhance the project
  • The code generation architecture is open and extendable, we invite everyone to contribute!

Read 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
npm install @teleporthq/teleport-component-generator-stencil
npm install @teleporthq/teleport-component-generator-preact
npm install @teleporthq/teleport-component-generator-reactnative

or using yarn:

yarn add @teleporthq/teleport-component-generator-react
yarn add @teleporthq/teleport-component-generator-vue
yarn add @teleporthq/teleport-component-generator-angular
yarn add @teleporthq/teleport-component-generator-stencil
yarn add @teleporthq/teleport-component-generator-preact
yarn add @teleporthq/teleport-component-generator-reactnative

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.

Component Generators

We have official component generators for a couple of popular web frontend frameworks, but we are actively working on supporting mobile application with react-native. 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.

Flavors

  • teleport-component-generator-react - with styling: css-modules, styled-components, styled-jsx, etc.
  • teleport-component-generator-vue - generating standard .vue files
  • teleport-component-generator-angular - generates .ts, .html and .css files
  • teleport-component-generator-preact - similar to react, with a bunch of styling options
  • teleport-component-generator-stencil - (experimental) - generates .tsx files and standard .css files
  • teleport-component-generator-react-native - (experimental)
  • teleport-component-generator-svelte - (coming soon)

Capabilities

Here's a list of functionalities that the UIDL and the component generators are supporting at the moment, besides the obvious presentational layer:

  • Dynamic values (props, state) inside html nodes or at attribute level
  • Type definitions for component props (PropTypes in React, props in Vue)
  • External dependencies definition
  • Simple component state (using hooks in React, component instance in Vue)
  • Event Handlers (related to state changes)
  • Repeat structures (.map in React, v-for in Vue)
  • Support for slots

Project Generators

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

Flavors

  • teleport-project-generator-react - react + react-router and css-modules on top of create-react-app
  • teleport-project-generator-next - based on Next.js
  • teleport-project-generator-vue - with a structure starting from the vue-cli
  • teleport-project-generator-nuxt - based on Nuxt.js
  • teleport-project-generator-preact - based on the preact-cli
  • teleport-project-generator-angular - based on the angular-cli
  • teleport-project-generator-gatsby
  • teleport-project-generator-gridsome
  • teleport-project-generator-stencil (experimental)
  • teleport-project-generator-react-native (experimental)
  • teleport-project-generator-static (coming soon)

Capabilities

Besides the regular files and folders generated at the end of the process, project generators are also taking care of:

  • Support for global settings, meta tags, style, scripts, etc.
  • Extracting all external dependencies and adding them to the package.json.
  • Creating the entry point for each application (it can be an index.html or something that is framework specific).
  • Creating a routing file for the client routes of the project.
  • Generating a web manifest for PWA support.

Project Packers

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 now or github, or in creating an in-memory zip file or simply writing the folder to disk.

Publishers

  • teleport-publisher-now
  • teleport-publisher-github
  • teleport-publisher-codesandbox
  • teleport-publisher-zip
  • teleport-publisher-disk
  • teleport-publisher-netlify (coming soon)

Further Reading

A few useful links to get you up to speed with the entire teleport ecosystem:

This project uses:

  • TypeScript for type safety and easy refactoring
  • lerna for managing the monorepo with multiple npm packages
  • jest for all types of tests and for calculating the code coverage

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 standalone

The standalone version uses the teleport-code-generator package and the statically declared templates. To test with the github templates and the custom packer instance, you have to:

cp config.example.json config.json

You will have to replace the placeholder with your own github token. Then you can run it with:

npm run packer

This version of the packer uses the UIDLs from the examples/uidl-sample. If the process runs successfully, you will see the responoses from the project packer in the format: { success: true, payload: 'dist' }. The task uses the teleport-publisher-disk package and generates four different project files in the dist folder.

Please open an issue for any irregularity, potential bug that you find while running this, or if you simply have any questions or curiosities about this project.

It's not just our code that's open source, we're also planning the development of the code generators on GitHub. We have a number of issues opened and we expect further contributions on this.

We're especially interested in opening discussions around the issues tagged with the discussion label.

Official Release

The official release will be a switch to version 1.0. ETA for this is around the end of 2019.

We'd be super happy to have community involvement around this project. We strongly believe in the power of open source, so we're planning on building the best possible code generators, together with the entire development community.

We envision different types of involvement from this point on:

  • Trying out the generators and reporting back any bugs and potential points of improvement
  • Contributing to the existing issues, either on the core modules or on the existing generators and plugins
  • Exploring and building new plugins for the existing generators
  • Exploring and building new generators based on the existing architecture

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

Reach out to us on any of these channels:

0.37.6

26 days ago

0.38.0

25 days ago

0.38.3

25 days ago

0.37.3

1 month ago

0.37.2

1 month ago

0.36.6

2 months ago

0.36.0

4 months ago

0.33.6

5 months ago

0.33.0

6 months ago

0.34.0

5 months ago

0.35.0

5 months ago

0.32.10

8 months ago

0.32.7

9 months ago

0.32.4

10 months ago

0.32.3

11 months ago

0.32.1

12 months ago

0.32.0

12 months ago

0.31.6

1 year ago

0.42.0-alpha.0

1 year ago

0.29.0

1 year ago

0.34.0-alpha.0

1 year ago

0.45.5-alpha.0

1 year ago

0.31.0-alpha.0

1 year ago

0.32.0-alpha.0

1 year ago

0.40.0-alpha.0

1 year ago

0.39.0-alpha.0

1 year ago

0.45.1-alpha.0

1 year ago

0.36.0-alpha.0

1 year ago

0.41.0

1 year ago

0.33.0-alpha.0

1 year ago

0.30.0

1 year ago

0.30.0-alpha.0

1 year ago

0.44.0-alpha.0

1 year ago

0.35.0-alpha.0

1 year ago

0.29.0-alpha.0

1 year ago

0.43.0-alpha.0

1 year ago

0.31.0

1 year ago

0.28.0

1 year ago

0.45.3-alpha.0

1 year ago

0.28.0-alpha.0

1 year ago

0.27.8

1 year ago

0.27.5

2 years ago

0.27.6-alpha.0

2 years ago

0.27.3-alpha.3

2 years ago

0.27.3-alpha.4

2 years ago

0.27.3-alpha.2

2 years ago

0.27.3-alpha.0

2 years ago

0.27.5-alpha.0

2 years ago

0.27.3

2 years ago

0.27.4-alpha.0

2 years ago

0.27.0

2 years ago

0.26.0

2 years ago

0.26.5

2 years ago

0.25.2

2 years ago

0.25.1

2 years ago

0.25.0

2 years ago

0.24.0

2 years ago

0.23.0

2 years ago

0.22.0

2 years ago

0.21.7

3 years ago

0.21.0

3 years ago

0.20.7

3 years ago

0.20.3

3 years ago

0.19.22

3 years ago

0.19.23

3 years ago

0.20.0

3 years ago

0.19.20

3 years ago

0.19.21

3 years ago

0.19.19

3 years ago

0.19.9

3 years ago

0.19.15

3 years ago

0.19.17

3 years ago

0.19.10

3 years ago

0.19.8

3 years ago

0.19.0

3 years ago

0.18.1

3 years ago

0.19.1

3 years ago

0.19.4

3 years ago

0.18.0

3 years ago

0.17.7

3 years ago

0.17.3

3 years ago

0.17.0

4 years ago

0.16.3

4 years ago

0.16.1

4 years ago

0.16.2

4 years ago

0.16.0

4 years ago

0.15.0

4 years ago

0.14.0

4 years ago

0.13.3

4 years ago

0.13.0

4 years ago

0.12.4

4 years ago

0.12.2

4 years ago

0.12.1

4 years ago

0.12.0

5 years ago

0.11.0

5 years ago

0.10.11

5 years ago

0.10.8

5 years ago

0.10.7

5 years ago

0.10.6

5 years ago

0.10.5

5 years ago

0.10.4

5 years ago

0.10.1

5 years ago

0.10.0

5 years ago

0.10.0-alpha.6

5 years ago

0.10.0-alpha.5

5 years ago

0.10.0-alpha.4

5 years ago

0.10.0-alpha.3

5 years ago

0.10.0-alpha.2

5 years ago

0.10.0-alpha.1

5 years ago

0.10.0-alpha.0

5 years ago

0.9.0

5 years ago

0.8.1

5 years ago

0.8.0

5 years ago

0.7.0

6 years ago