Coder Social home page Coder Social logo

adedoyin-emmanuel / methane-cli Goto Github PK

View Code? Open in Web Editor NEW
26.0 1.0 1.0 1.6 MB

A CLI tool for efficient creation of React components, pages and Service Worker files.

Home Page: http://npmjs.com/package/methane-cli

JavaScript 2.43% TypeScript 97.57%
cli command-line-tool javascript-cli productivity productivity-tools react react-cli reactjs typescript-cli typescript-support

methane-cli's Introduction

Methane ๐Ÿš€

wakatime

GitHub stars GitHub forks GitHub downloads

Methane is a CLI tool that helps developers easily create React components, pages or NextJS components, pages, dynamic pages and service worker files with boilerplate codes. It also comes with extra configration that allows you choose either JavaScript or TypeScript templates.

Methane Logo

What's New โ“

The new major version 2.0.0 comes with support for NextJS. This is a game changer for NextJs developers, with Methane you can easily generate your components from the command line and bingo ๐Ÿš€

  1. Support for NextJS
  2. Migrated codebase from JS to TS
  3. Cleaner CLI Interface
  4. Customize your project based on your local configuration.

Installation ๐Ÿ’ฟ

To install Methane-Cli, run the following command. Note you've to install it as a global package. Note You've to init methane before using it in your project.

# npm
npm install -g methane-cli

Usage ๐Ÿšฆ

To use methane or rg, simply run the command

methane
rg

This would show a welcome message with information about the tool. Then you need to run the init command. This would help you to configure methane to your taste. ๐Ÿ˜›

methane init

This would prompt you to answer some questions and a config file will be created. Note you can't use Methane if you don't have the config file.

Commands

The following commands are available in methane-cli

  • --help or -h: Displays a list of available commands.
  • --version or -v: Displays the version of methane-cli.
  • --generate or -g: Generates Components, Pages or Service Worker files.
  • --config or -c: Configures the CLI tool to your taste.
  • --init or -i: Initializes default configuration files in root directory.
  • --list-config or -lc: Lists all Methane-Cli configurations.

To run a command, simply add it at the end of methane or rg for example,

Configurations ๐Ÿ”ฅ

By default, when you run methane init you would be prompted to select some configurations. If you would love to change the configurations at some point, You can follow this format.

{
  "template": "jsx",
  "component": "arrow",
  "page": "arrow",
  "generateStylesheet": "true",
  "generateFolder": "true",
  "register": "true",
  "stylesheetType": "css"
}

To change the configurations, run the following command.

Change Template

To change the template to tsx run the following command.

doyin@doyinHpLaptop:~/Desktop/react-app$ methane c --template tsx

jsx or tsx are the only options available

Change Component Generation Style

To change the component generation style, run the following command.

doyin@doyinHpLaptop:~/Desktop/react-app$ methane config -c arrow

arrow or functional are the only options available

Change Page Generation Style

To change the page generation style, run the following command

doyin@doyinHpLaptop:~/Desktop/react-app$ methane config -p arrow

arrow or functional are the only options available

Generate Stylesheet

To generate stylesheet file for components and pages, run the following command

doyin@doyinHpLaptop:~/Desktop/react-app$ methane config -gs true

true or false are the only options available

Generate Folder

To generate a folder for components and pages, run the following command

doyin@doyinHpLaptop:~/Desktop/react-app$ methane config -gf true

true or false are the only options available

Register Generated Pages

To register the generated pages in your App.js or App.jsx or App.tsx or App.ts file, run the following command. This is strictly or React and not NextJS

doyin@doyinHpLaptop:~/Desktop/react-app$ methane config -r true

true or false are the only options available

Stylesheet Type

To change the stylesheet type for your components and pages, run the following command.

doyin@doyinHpLaptop:~/Desktop/react-app$ methane config -st css

css or scss are the only options available

Create a Component โญ

With the new update, you can generate React or NextJS server or client components. Intresting right ๐Ÿ˜„. But the commands are different.

Generating A React Component

doyin@doyinHpLaptop:~/Desktop/react-app$ methane g -c componentName

Generating A NextJS Component

doyin@doyinHpLaptop:~/Desktop/react-app$ methane g -nc componentName

Optionally, you can specify your nextJs component to be a server or client component To do this, Simply add the ct flag, then you can specify server or client omitting the ct would generate a client component by default.

The convention is that you've a component or components directory in your application. Methane would find that directory and then place your component in it.

Note

_You don't have to be in your react-app components folder. You can run the command from the root folder of your react-application and that's infact how

Create a Page โญ

With the new update, you can generate React or NextJS server or client pages.

Generating A React Page

doyin@doyinHpLaptop:~/Desktop/react-app$ methane g -p pageName

This would create a new page according to the global configuration and add the pages to the components pages in your react-app application. By default, a page generated comes with a useNavigate() hook and the Link tag.

Generating A NextJS Page

doyin@doyinHpLaptop:~/Desktop/react-app$ methane g -np pageName

This would generate a new page according to the configuration in your /methane/methane.json file. Methane would check for your project structure and then create a new page in according to your project structure. By default a generated NextJS page comes with a useRouter and usePathname hook for navigation and also a Rafce component template.

Optionally, you can specify your nextJs page to be a server or client page To do this, Simply add the ct flag, then you can specify server or client omitting the ct would generate a client page by default.

doyin@doyinHpLaptop:~/Desktop/react-app$ methane g -np pageName -ct server

Generating A Dynamic NextJS Page

As you already know, in NextJS dynamic pages are pages whose content is determined by parameters included in the URL. For example /product/1 is a dynamic URL. Now Methane can also help you create dynamic pages. Usually, a dynamic page would be nested within a page. For example, I've a products page already /products, my dynamic page would most likely be productId. So using Methane, you can generate a dynamic page using the command below

doyin@doyinHpLaptop:~/Desktop/react-app$ methane g -ndp productId -sp /products
Command Arguments
  1. -npd -npid (Next Dynamic Page) is the dynamic page name, which in this case is productId
  2. -sp -sp is an optional parameter called (Start Page) which is indicates the folder to place the dynamic page in. You don't need to specify the default nextJS /app when specifying the folder to place the dynamic page.

Optionally, you can specify your nextJs page to be a server or client page To do this, Simply add the ct flag, then you can specify server or client omitting the ct would generate a client page by default.

doyin@doyinHpLaptop:~/Desktop/react-app$ methane g -ndp productId -sp /products -ct server

You can also nest different directory structure. for example, if you've a /products directory and then you've a dynamic page called /products/[productId]/ you can still add a page like /products/[productId]/edit or even /products/[productId]/sub/[subId]/edit. The choice is yours. With this awesome command, you would never have to manually create a new page.

Configurations โš™๏ธ

Added a new command list-config [ls]

  • --list-config or -lc: Lists all Methane configurations.
doyin@doyinHpLaptop:~/Desktop/react-app$ methane list-config

All configurations
{
  template: 'jsx',
  component: 'arrow',
  page: 'arrow',
  generateStylesheet: 'true',
  generateFolder: 'true',
  register: 'true',
  stylesheetType: 'css'
}


```bash
doyin@doyinHpLaptop:~/Desktop/react-app$ methane g -sw

Create a Service Worker โญ

This would create a service worker and add the service worker to the [index.js, main.js, index.jsx, main.jsx] or tsx respectively.

You can now register the service worker by adding

serviceWorkerRegistration.register();

Note

You don't have specify any name for the service-worker

Stuck :(

If you are stuck or you want to learn more about the different configurations, run the following command.

doyin@doyinHpLaptop:~/Desktop/react-app$ methane c --help

Architecture ๐Ÿ› 

methane-cli uses a modular architecture.It consists of different modules that perform specific tasks such as generating components, pages, and service worker files.

Contributing โค๏ธ

If you'd like to contribute to methane, please follow these steps:

  1. Fork the repository
  2. Create a new branch
  3. Make your changes and commit them
  4. Push your changes to your fork
  5. Create a pull request :)

Please star this repo if you find it useful. Also share the good news with your community.

License ๐Ÿง

methane-cli is licensed under the MIT License.

Contibutors ๐Ÿ‘จโ€

Adedoyin Emmanuel Adeniyi

methane-cli's People

Contributors

adedoyin-emmanuel avatar imgbotapp avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

esinshadrach

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.