Security News
Combatting Alert Fatigue by Prioritizing Malicious Intent
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
@anephenix/rcg
Advanced tools
A Node.js library and CLI for generating React components.
npm i @anephenix/rcg
There are 2 ways that you can use RCG - via CLI, or as an NPM module in your Node.js code.
After you have installed rcg, cd into your React app, and run this:
npx rcg MyComponent
This will do the following:
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
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
);
})();
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
npm t
© 2022 Anephenix OÜ. RCG is licensed under the MIT License.
FAQs
React Component Generator
We found that @anephenix/rcg demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.