@cmj526/mason
v1.0.8
Published
Mason is a tool for creating new React components and pages for your project.
Downloads
509
Readme
@cmj526/mason
Mason is a lightweight and efficient tool designed to help developers create React components, pages, and sub-components effortlessly. Written in Python, this CLI tool automates the process of generating boilerplate code, enabling you to focus on building features rather than repetitive setup tasks.
Features
- Generate React Pages: Quickly scaffold fully functional React pages with components, hooks, styles, and tests.
- Create Components: Easily create reusable React components with styles and test files.
- Sub-component Support: Add sub-components to existing pages for better modularization.
Installation
To use Mason, first ensure you have Python 3 installed on your system. You can install Mason either globally or locally using npm:
Global Installation
Install Mason as a global npm package to use it across all your projects:
npm install -g @cmj526/mason
Local Installation
Install Mason as a local npm package to use it in a specific project:
npm install @cmj526/mason
Usage
Once installed globally, you can use Mason by running the following command:
mason
You will be prompted to choose what to create: a page, component, or sub-component. Follow the prompts to complete the process.
Alternatively, you can integrate Mason into your project’s workflow using yarn
or npm
scripts:
Add Mason to Your package.json
Scripts
Open your
package.json
.Add the following script:
{ "scripts": { "create": "mason" } }
Run the script:
npm run create
or
yarn run create
CLI Workflow
When you run mason
, Mason will guide you through the creation process with prompts:
Select the type of entity:
You will be asked to choose between:P
: Create a new pageC
: Create a new componentS
: Create a sub-component within an existing page.
Enter the name of the entity:
Provide the name of the page, component, or sub-component.Output:
Mason generates the necessary files and folders under the appropriate directories (src/pages/
,src/components/
, etc.).
Example
Creating a Page
- Run:
mason
- Select
P
(for a new page). - Enter a name for the page, e.g.,
Home
. - Mason will create a folder
src/pages/Home
with the following files:src/pages/Home/ ├── Component.tsx ├── Hooks.tsx ├── Styles.scss ├── Home.test.tsx └── index.tsx
Creating a Component
- Run:
mason
- Select
C
(for a new component). - Enter a name for the component, e.g.,
Button
. - Mason will create a folder
src/components/Button
with the following files:src/components/Button/ ├── index.tsx ├── styles.scss └── Button.test.tsx
Adding a Sub-component
- Run:
mason
- Select
S
(for a new sub-component). - Enter the parent page’s name (e.g.,
Home
) and the sub-component name (e.g.,Footer
). - Mason will add a folder under the
Home
page for the sub-component:src/pages/Home/components/Footer/ ├── index.tsx ├── styles.scss └── Footer.test.tsx
Directory Structure
Mason assumes the following project structure:
src/
├── pages/
│ └── [PageName]/
│ ├── Component.tsx
│ ├── Hooks.tsx
│ ├── Styles.scss
│ ├── [PageName].test.tsx
│ └── index.tsx
├── components/
│ └── [ComponentName]/
│ ├── index.tsx
│ ├── styles.scss
│ └── [ComponentName].test.tsx
If the structure doesn’t exist, Mason will create the necessary folders.
Requirements
- Python 3.6 or later
- npm or Yarn installed on your system
Troubleshooting
Common Errors
python3: command not found
:
Ensure Python 3 is installed and available in your system's PATH.
Test by running:python3 --version
Module not found
:
Ensure all necessary Python modules are installed. You can install missing modules usingpip
.File not found in
.bin
:
If you encounter an error wherecreate.py
is not found, verify that the package is correctly installed globally andcreate.py
is included in the package files.
Contributing
We welcome contributions to Mason! If you’d like to add features or fix bugs:
- Fork the repository.
- Make your changes.
- Submit a pull request on GitHub.
License
This project is licensed under the ISC License.
Contact
For issues or feedback, please visit our GitHub issues page. """
Write to README.md
with open("README.md", "w") as file: file.write(readme_content)
"README.md file has been created successfully!"