0.0.20 • Published 21 days ago

addcomp v0.0.20

Weekly downloads
-
License
ISC
Repository
-
Last release
21 days ago

NPM addcomp.js

Usage

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

import React from 'react';
import styles from 'buttonGroupGird.css';

function ButtonGroupGird({}) {
  return (
    <div>
      <div>ButtonGroupGird</div>
    </div>
  );
}

export default ButtonGroupGird;

index.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

DescriptionShort FlagLong 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
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

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

DescriptionOptionDefaultFlag
Create a CSS fileCREATE_CSS_FILEtrue-s, --add-css
Create css file as a .module.css fileCREATE_CSS_FILE_AS_MODULEtrue-m, --css-as-module
Create the component's index.js fileCREATE_COMPONENT_INDEXtrue-i, --create-index
Deconstruct children from component's propsADD_CHILDREN_PROPSfalse-c, --add-children-props
Add "use client" directive to componentADD_USE_CLIENT_DIRECTIVEfalse-u, --add-use-client
Export component function with declarationUSE_INLINE_EXPORTfalse-l, --use-inline-export
Append x to component file extensionADD_X_TO_EXTENSIONfalse-x, --add-x
CSS file nameCSS_FILE_NAMECOMPONENT_NAME-n, --css-name name
Component file extensionCOMPONENT_FILE_EXTENSIONjs-e, --file-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
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

logs

Success

 npx addcomp@latest button-group grid -no-m -u -n styles -l

success logs

Fail

 npx addcomp@latest button-group grid -no-m -u -n styles -l

fail logs

0.0.20

21 days ago

0.0.10

21 days ago

0.0.11

21 days ago

0.0.12

21 days ago

0.0.13

21 days ago

0.0.14

21 days ago

0.0.15

21 days ago

0.0.9

21 days ago

0.0.16

21 days ago

0.0.8

21 days ago

0.0.17

21 days ago

0.0.18

21 days ago

0.0.19

21 days ago

0.0.7

21 days ago

0.0.6

22 days ago

0.0.5

22 days ago

0.0.4

22 days ago

0.0.3

22 days ago

0.0.2

22 days ago

0.0.1

22 days ago