npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@anephenix/rcg

v0.0.11

Published

React Component Generator

Downloads

39

Readme

RCG

A Node.js library and CLI for generating React components.

npm version CI Test Coverage Maintainability

Features

  • Generates a React component based on a given name
  • Creates the component and accompanying files and folders
  • Takes time out of generating files and folders for React components

Install

npm i @anephenix/rcg

Usage

There are 2 ways that you can use RCG - via CLI, or as an NPM module in your Node.js code.

via CLI

After you have installed rcg, cd into your React app, and run this:

npx rcg MyComponent

This will do the following:

  • Create a folder called 'my-component' in the src/components folder
  • Inside that folder, it will create these files:
    • A React component file called MyComponent.js
    • A styling file called MyComponent.scss
    • A test file called MyComponent.test.js

You can also generate the component in a different folder:

npx rcg LoginPage --directory pages

This will generate a folder called 'login-page' in the pages folder, such as for a Next.js app.

To add custom DOM to insert into the React component, you can pass the --dom flag:

npx rcg NavBar --dom="<div id='logo'>Logo here</div>"

To add custom CSS to insert into the SASS file for the component, you can pass the --css flag:

npx rcg NavBar --css="#logo { color: #ffcc00;}"

To specify a custom file extension for the component and test file names (e.g. jsx, tsx), you can pass the --jsExtension flag:

npx rcg NavBar --jsExtension=jsx

To specify a custom file extension for the css file (e.g. .style.js), you can pass the --cssExtension flag:

npx rcg NavBar --cssExtension=style.js

By default, it generates a scss file. This will likely change in the future to a default pattern of css-in-js

via NPM

You can load it this way:

const path = require('path');
const rcg = require('@anephenix/rcg');

const componentName = 'MyComponent';
const srcFolderPath = path.join(process.cwd(), 'src', 'components');

(async () => {
	await rcg(componentName, srcFolderPath);
})();

If you want the React component to include custom DOM and/or the SASS file to include custom CSS, you can also pass these parameters:

const path = require('path');
const rcg = require('@anephenix/rcg');

const componentName = 'MyComponent';
const srcFolderPath = path.join(process.cwd(), 'src', 'components');

const customDOM = '<p>Hello</p>';
const customCSS = 'p { color: red; } ';
const customJSExtension = 'jsx';
const customCssExtension = 'style.js';

(async () => {
	await rcg(
		componentName,
		srcFolderPath,
		customDOM,
		customCSS,
		customJSExtension,
		customCssExtension
	);
})();

Loading options from a config file

Rather than having to specify arguments via the CLI each time, you can load them via a rcg.config.js file, with these contents:

const path = require('path');

const config = {
	// Put the component folder and file in the components directory
	directory: path.join(process.cwd(), 'components'),
	// Use the jsx filename extension for the component files
	jsExtension: 'jsx',
};

module.exports = config;

You can create an rcg.config.js file by running this command:

npx rcg init

Running Tests

npm t

License and Credits

© 2022 Anephenix OÜ. RCG is licensed under the MIT License.