# addcomp

> Quickly and flexibly add a new react component in your `src/components` directory using the CLI

Latest version **0.0.20** (published 2024-04-11) · ISC license · 0 weekly downloads

## Install

```sh
npm install addcomp
pnpm add addcomp
yarn add addcomp
bun add addcomp
```

Provides the command `add_compt`.

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.20 |
| Published | 2024-04-11 |
| First published | 2024-04-10 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 1.5 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | kay.eg |
| Maintainers | kay.eg |
| Keywords | CLI, react, add, util, components, boilerplate |

## Links

- npm: https://www.npmjs.com/package/addcomp
- npm.io page: https://npm.io/package/addcomp

## Dependencies (5)

- [chalk](https://npm.io/package/chalk.md) ^5.3.0
- [table](https://npm.io/package/table.md) ^6.8.2
- [commander](https://npm.io/package/commander.md) ^12.0.0
- [console-table-printer](https://npm.io/package/console-table-printer.md) ^2.12.0
- [sanitize-filename-truncate](https://npm.io/package/sanitize-filename-truncate.md) ^1.0.2

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.0.20 (latest) — 2024-04-11
- 0.0.19 — 2024-04-11
- 0.0.18 — 2024-04-11
- 0.0.17 — 2024-04-11
- 0.0.16 — 2024-04-11
- 0.0.15 — 2024-04-11
- 0.0.14 — 2024-04-11
- 0.0.13 — 2024-04-11
- 0.0.12 — 2024-04-11
- 0.0.11 — 2024-04-11
- 0.0.10 — 2024-04-11
- 0.0.9 — 2024-04-11
- 0.0.8 — 2024-04-11
- 0.0.7 — 2024-04-11
- 0.0.6 — 2024-04-10
- … 5 more at https://npm.io/package/addcomp/versions

## README

# NPM addcomp.js

- [Usage](#usage)
- [Quick Guide](#quick-guide)
- [Using The Command Line](#using-the-command-line)
  - [Passing Component Name](#passing-component-name)
  - [Options](#options)
    - [Negating flags](#negating-flags)
- [Override Default Configurations \(addcomp.config.js\)](#override-defualt-configurations-addcompconfigjs)
  - [File structure](#file-structure)
  - [Options](#options-1)
  - [Conflicts](#conflicts)
- [Media](#media)
  - [help](#help)
  - [logs](#logs)
    - [Success](#success)
    - [Fail](#fail)

## Usage

```bash
npx addcomp <...tokens> [options]
```

## Quick Guide

```
Usage: index [options] <tokens...>

Arguments:
  tokens                          component name

Options:
  -s, --add-css                   Create a CSS file
  -no-s, --no-add-css

  -m, --css-as-module             Create css file as a .module.css file
  -no-m, --no-css-as-module

  -i --create-index               Create the component's index.js file
  -no-i, --no-create-index

  -c --add-children-props         Deconstruct children from component's props
  -no-c, --no-add-children-props

  -u --add-use-client             Add "use clinet" directive to component
  -no-u, --no-add-use-client

  -l --use-inline-export          Export component function with declaration
  -no-l, --no-use-inline-export

  -x --add-x                      Append x to component file extension
  -no-x, --no-add-x

  -n --css-name [name]            CSS file name (preset: "COMPONENT_NAME")
  -e --file-ext <ext>             Component file extension
  -h, --help                      display help for command
```

> For Example
>
> ```
> npx addcomp button group grid -s -no-m -e ts -x
> ```
>
> changes in project structure
>
> ```
> .
> ├── src/
> │   └── components/
> │       └── ButtonGroupGird/
> │           ├── ButtonGroupGird.tsx
> │           ├── buttonGroupGird.css
> │           └── index.js
> ├── index.js
> └── package.json
> ```
>
> ButtonGroupGird.tsx
>
> ```ts
> import React from 'react';
> import styles from 'buttonGroupGird.css';
>
> function ButtonGroupGird({}) {
>   return (
>     <div>
>       <div>ButtonGroupGird</div>
>     </div>
>   );
> }
>
> export default ButtonGroupGird;
> ```
>
> index.js
>
> ```js
> export * from './ButtonGroupGird.tsx';
> export { default } from './ButtonGroupGird.tsx';
> ```
>
> ```
>
> ```

## Using The Command Line

The command line is used to pass the compoent name, as well as, options to customize the creation of the component and its files.

### Passing Component Name

You can pass the component name as a single string or a space seperated word which would automatically be formated.

> For Example
>
> ```
>
> npx addcomp button group grid
>
> ```

This will generate a component with the name `ButtonGroupGrid`.

> note
>
> Based on how the command line parser works, any value that is not a flag, or a flag parameter is considerend a an argument for the component name
>
> `npx addcomp button -s group -x -n grid` => ButtonGroup

### Options

| Description                                 | Short Flag | Long Flag               |
| ------------------------------------------- | ---------- | ----------------------- |
| Create a CSS file                           | -s         | --add-css               |
|                                             | -no-s      | --no-add-css            |
| Create CSS file as a .module.css file       | -m         | --css-as-module         |
|                                             | -no-m      | --no-css-as-module      |
| Create the component's index.js file        | -i         | --create-index          |
|                                             | -no-i      | --no-create-index       |
| Deconstruct children from component's props | -c         | --add-children-props    |
|                                             | -no-c      | --no-add-children-props |
| Add "use client" directive to component     | -u         | --add-use-client        |
|                                             | -no-u      | --no-add-use-client     |
| Export component function with declaration  | -l         | --use-inline-export     |
|                                             | -no-l      | --no-use-inline-export  |
| Append x to component file extension        | -x         | --add-x                 |
|                                             | -no-x      | --no-add-x              |
| CSS file name (preset: "COMPONENT_NAME")    | -n         | --css-name [name]       |
| Component file extension                    | -e         | --file-ext <ext>        |
| Display help for command                    | -h         | --help                  |

#### Negating flags

To negate an option, you can prefix its flag with `no-`.

> For Example
>
> ```
> -no-s --no-create-index ...
> ```

## Override Defualt Configurations (addcomp.config.js)

It is also possible to have a `addcomp.config.js` file in project root to override the default options.

### File structure

```js
const configs = {
  CREATE_CSS_FILE: undefined,
  CREATE_CSS_FILE_AS_MODULE: undefined,
  CREATE_COMPONENT_INDEX: undefined,
  ADD_CHILDREN_PROPS: undefined,
  ADD_USE_CLIENT_DIRECTIVE: undefined,
  USE_INLINE_EXPORT: undefined,
  ADD_X_TO_EXTENSION: undefined,
  CSS_FILE_NAME: undefined,
  COMPONENT_FILE_EXTENSION: undefined,
};

export default configs;
```

### Options

| Description                                 | Option                    | Default        | Flag                     |
| ------------------------------------------- | ------------------------- | -------------- | ------------------------ |
| Create a CSS file                           | CREATE_CSS_FILE           | true           | -s, --add-css            |
| Create css file as a .module.css file       | CREATE_CSS_FILE_AS_MODULE | true           | -m, --css-as-module      |
| Create the component's index.js file        | CREATE_COMPONENT_INDEX    | true           | -i, --create-index       |
| Deconstruct children from component's props | ADD_CHILDREN_PROPS        | false          | -c, --add-children-props |
| Add "use client" directive to component     | ADD_USE_CLIENT_DIRECTIVE  | false          | -u, --add-use-client     |
| Export component function with declaration  | USE_INLINE_EXPORT         | false          | -l, --use-inline-export  |
| Append x to component file extension        | ADD_X_TO_EXTENSION        | false          | -x, --add-x              |
| CSS file name                               | CSS_FILE_NAME             | COMPONENT_NAME | -n, --css-name [name]    |
| Component file extension                    | COMPONENT_FILE_EXTENSION  | js             | -e, --file-ext <ext>     |

### Conflicts

If there is a conflict between the local `.confg` file and the CLI options, i.e. the same option has two different values in both, then always the CLI option takes priority over the `.config` file option.

> For Example
>
> ```
> npx addcompt --no-add-css
> ```
>
> ```js
> const configs = {
>   CREATE_CSS_FILE: true,
> };
>
> export default configs;
> ```
>
> Then, `CREATE_CSS_FILE` be resolved to `false`, since the CLI has more priority.

## Media

### help

![npx addcomp -h](readme/help.png)

### logs

#### Success

```
 npx addcomp@latest button-group grid -no-m -u -n styles -l
```

![success logs](readme/success.png)

#### Fail

```
 npx addcomp@latest button-group grid -no-m -u -n styles -l
```

![fail logs](readme/fail.png)

---
_Source: https://npm.io/package/addcomp · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
