Giter Site home page Giter Site logo

rakataprime / sveno Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pocinnovation/sveno

0.0 0.0 0.0 458 KB

A tool to convert any React JS app to Svelte app ๐Ÿš€

License: MIT License

Shell 0.78% JavaScript 29.27% Python 67.73% CSS 1.36% HTML 0.86%

sveno's Introduction

Sveno

ย python versionย ย license

Sveno is a component transpiler that transform React components to Svelte components. It only works on simple small non-library components so far, but more updates are coming. โฌ Sveno aims to become a powerful tool able to transpile complete projects, and to help developpers ๐Ÿ’ป discover the advantages of using Svelte. ๐Ÿ˜Ž

React to Svelte

Summary

Why Svelte

While React is a library that adds extra weight to your code base and uses a virtual DOM, Svelte compiles it's files to ideal javascript, thus reducing the actual weight โš–๏ธ. As a result, Svelte is significantly faster ๐Ÿƒโšก than any framework or library using virtual DOMs when it comes to downloading webpages into a browser.

Learn more here

Setup

You'll need Python3 ๐Ÿ and pip3 installed. You will also need npm installed. Install the requirements by launching the script ./install.sh
Congratz ๐Ÿฅณ ! You're ready to go!

Usage

The program takes 2 arguments: the react source folder and a svelte destination folder

python3 ./src/main.py react_source_folder svelte_destination_folder

How it works

  1. The program looks ๐Ÿ”Ž through each file, starting from the source root folder, that has a .js or a .jsx extension. Style files with .css extension are also taken into account and can be integrated into the correct svelte component.
  2. Using a set of regex ๐Ÿ”ค (regular expressions), key elements are gathered and stored into dataclasses. Try some regex here.
  3. Dataclasses ๐Ÿ’พ are the main element that will be worked upon. Class Components, Functionnal Components, Variables, and other important pieces of code have their own dataclass. They are used to access information and transform syntactic elements from react to svelte syntax. Some elements are substituted while others are simply deleted (eg: this.props.name will become name)
  4. New files and folders ๐Ÿ“‚ are created. Because React files can contain multiple components, contrarly to Svelte files, each component will be translated into a new file of the same name. They will be contained in a folder bearing the name of the initial react file.
    For example, a file named actions.jsx and containing 2 components named simpleAction and doubleAction will result in a folder named actions with two svelte files named simpleAction.svelte and doubleAction.svelte
  5. Components are written ๐Ÿ“ in the new files, using the dataclasses and corresponding templates.

Functionnalities

As of today, the following elements can be transpiled:

  • Functionnal components
  • Class components
  • 'Classic' functions
  • Props
  • Class Lifecycle methods (ComponentWillMount, ComponentDidMount, ComponentDidUpdate, GetSnapshotBeforeUpdate)
  • UseEffect (The functionnal component LifeCycle hook)
  • SetState, UseState, this.state - initialize and set variable values
  • Events (onClick, onMouseMove, etc)

Documentation

  • Install Doxygen
  • To generate the documentation, just do
    • doxygen .doxygen
  • You can now consult the documentation by running the html statically for example with chrome
    • google-chrome doc/html/index.html

Upcoming

  • ReactDOM.render() and entrypoint
  • Better utilitary files handling
  • Loops
  • Conditions
  • Routing

sveno's People

Contributors

amozpay avatar gfaim avatar barbo69 avatar tomchv avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.