@gibsonmurray/ghooks-cli
v1.0.8
Published
A CLI for managing React hooks in your project
Readme
GHooks
GHooks is a command-line tool and React hooks library that allows you to easily add pre-built React hooks to your project.
Table of Contents
Installation
Install GHooks globally using your preferred package manager:
npm install -g @gibsonmurray/ghooks-cliCommand-Line Usage
After installation, you can use the ghooks command in your terminal:
Add Hooks
To add hooks interactively:
ghooks addTo add a specific hook by name:
ghooks add <hook-name>List Available Hooks
To list all available hooks:
ghooks listUpdate Library & CLI
To update the hooks in the project:
ghooks updateTo upgrade the CLI to the latest version:
ghooks upgradeHooks Library
The GHooks library provides the following hooks:
useArrayuseAsyncuseClickOutsideuseClipboarduseCookieuseDarkModeuseDebounceuseDebuguseDeepEffectuseDocumentTitleuseDragDropuseEventListeneruseFetchuseFlipGSAPuseFormuseGeolocationuseGlobalStateuseHoveruseIdleuseImageLoaduseKeyPressuseLockScrolluseLongPressuseMediaDevicesuseMediaQueryuseMounteduseMouseuseOnlineStatususeOnScreenuseOrientationusePermissionusePrevioususeRenderCountuseScriptuseSizeuseStateHistoryuseStateValidationuseLocalStorageuseSessionStorageuseTimeoutuseToggleuseUnmounteduseUpdateduseWindowSize
Library Usage
You can also use the hooks directly in your React projects:
- Install the library:
npm install @gibsonmurray/react-hooks- Import the hook you need:
import { useDebounce } from "@gibsonmurray/react-hooks"
const MyComponent = () => {
const [value, setValue] = useState("")
const debouncedValue = useDebounce(value, 500)
// ... rest of your component
}CLI Implementation
The GHooks CLI is implemented in the index.ts file, which provides the following functionality:
- Adding Hooks: Users can add hooks interactively or by specifying a hook name.
- Listing Hooks: Displays all available hooks from the repository.
- Updating Hooks: Updates existing hooks in the project to their latest versions.
- Upgrading CLI: Upgrades the GHooks CLI to the latest version.
- Version Information: Displays the current version of the CLI.
The CLI uses several dependencies:
commander: For parsing command-line arguments and defining commands.inquirer: For interactive command-line user interfaces.axios: For making HTTP requests to fetch hook data.chalk: For colorful console output.semver: For semantic versioning comparisons.
The main commands implemented in index.ts are:
ghooks add [hookName]: Adds one or more hooks to the project.ghooks list: Lists all available hooks.ghooks update: Updates existing hooks in the project.ghooks upgrade: Upgrades the GHooks CLI to the latest version.ghooks version: Displays the current version of the CLI.
The CLI fetches hook data from the GitHub repository, ensuring that users always have access to the latest versions of the hooks.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
