npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

add-component

v2.5.0

Published

Create React Component CLI

Downloads

29

Readme

add-component

Generate the component boilerplate, CSS, and a shallow render test with one line.

Install

Run

npm install -g add-component

Usage

# Generate PureComponent and shallow render test
$ add-component ${name}

# Generate PureComponent and shallow render test with stylesheet
$ add-component ${name} -c

# Generate Functional Component and shallow render test with stylesheet
$ add-component ${name} -c -f

# Generate a full redux store
$ add-component ${name} --redux

Example

Component

add-component example -c

Generates example folder with the following:

index.js

import Example from './example.js'

export default Example

style.css

.container {}

example.js

import React, { PureComponent } from 'react'

import style from './style.css'

class Example extends PureComponent {
  render () {
    return (
      <div className={style.container}>test</div>
    )
  }
}

export default Example

example.test.js

import React from 'react'
import { shallow } from 'enzyme'

import Example from './example.js'

it('renders without props', () => {
  shallow(<Example />)
})

Redux Store

add-component count --redux

Generates count folder with the following:

actions.js

import t from './actionTypes.js'

export function increment () {
  return {
    type: t.INCREMENT
  }
}

actionTypes.js

export default {
  INCREMENT: 'INCREMENT'
}

reducer.js

import t from './actionTypes'

const defaultState = {
  count: 0,
}

const score = (state = defaultState, action) => {
  switch (action.type) {

    case t.INCREMENT:
      return {
        ...state,
        count: state.count + 1
      }

    default:
      return state
  }
}

export default users

Additional options

# Define directory with components
$ add-react-component -d src Example

# Creates component with styled-components as styling solution
$ add-react-component -c styled-components Example

# Does not use summary index.js but puts component into it
$ add-react-component --no-index Example

Configuration

You can define all the options in configuration file. Also, with configuration, you can redefine technology generators, technology templates and filenames. Look into config.js to find out what cat be setted.

If you store your configuration file by .add-component/config.js path, you do not need any additional parameter. Just Run the command as usual.

If you want your configuration file to have another name or be in another folder, tell the command where it is:

# Run with configuration
$ add-react-component --config configs/addcomponent-config.js Example

# Example of configuration
$ cat .add-component/config.js

const path = require('path')

module.exports = {
  techsToGen: [
    'styled-components',
    'react',
    'storybook',
  ],
  techs: {
    'react': {
      fileName: 'index.js'
    },
   'storybook': {
      template: path.resolve(__dirname, './storybook-template.js')
    }
  },
  directory: './src',
}

Configuration details

Technologies to generate

In techsToGen, you can define the list of technologies to generate. This list will overwrite the default list, but if you include *, the default technologies will preserve. Note, that for custom technologies you will also need its configuration in techs field.

To re-define the list of technolofies:

module.exports = {
  techsToGen: [
    'styled-components',
    'react'
  ]
}

To save default list of technologies and add more:

module.exports = {
  techsToGen: [
    '*',
    'styled-components'
  ]
}
Path configuration

You can define a directory for your components. By default it is the root of your project.

module.exports = {
  directory: './src'
}

You can choose not to have a directory for every component but put the files for all the components into the same source folder. In this case, also configure the naming schemas for all the technologies so that all the files for different components contain the component name and do not overwrite each other.

module.exports = {
  componentDirectory: false
}

License

MIT © Jack Hanford