Code Monkey home page Code Monkey logo

gencomp's Introduction

gencomp

CI Workflow Badge

SAY GOODBYE TO HUGE NESTED COMPONENTS!

GenComp is a vscode extension that generates a new component from the selected line(s) of code. Furthermore, it extracts the selected code and copies its imports and creates a new react component from it.

DEMO: https://www.youtube.com/watch?v=3QkPesu2xHs

Install

Install through VS Code extensions. Search for gencomp

Can also be installed in VS Code: Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.

ext install StephenAsuncion.gencomp

Instruction

Once you've installed the extension, open your project folder. To be able to generate components we need an output folder.

To set an output folder, right-click on any folder and choose GenComp: Set Output Path.

Setting Output Path

Now that you've setup your output path, you can now select JSX code to extract. Right-click on your selection and choose GenComp: Generate Component.

Generating Component

After this you would see a GenComp<#>.js/tsx component in your outputPath.

Generated Component

License

MIT

gencomp's People

Contributors

stephenasunciondev avatar

Stargazers

 avatar

Watchers

 avatar

gencomp's Issues

Multiline Imports Support

Currently, the way the extension retrieves imports is by getting activeTextEditor's whole file content as a string. Prettier formats the code and then it loops through each line and check if the character from 0-6 is equal to import. If it is then it will push the line to an array.

Ref Code:

const editor = window.activeTextEditor;
   if (!editor) window.showErrorMessage('GenComp: Cannot find active editor');

   const fileCode = editor!.document.getText();
   
   let importsArr: Array<string> = [];

   const lineArr = prettier.format(fileCode, {
       tabWidth: 4,
       parser: 'babel'
   }).split("\n");

   // @TODO: this does not support multiline imports
   lineArr.forEach((line) => {
       if (line.slice(0, 6).toLowerCase() === 'import') {
           importsArr.push(line);
       }
   });

   let imports = '';
   importsArr.forEach((imp, idx, arr) => {
       imports += imp + (idx === arr.length - 1 ? '' : '\n');
   });

from: https://github.com/stephenasuncionDEV/gencomp/blob/main/src/commands.ts

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.