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

create-react-typescript-file

v0.0.5

Published

CLI tool to quickly create React Typescript files

Downloads

2

Readme

create-react-typescript-file

An opinionated, but simple CLI tool to quickly create React Typescript files.

Side-project, loosely based on the excellent work of Josh Comeau's new-component

🚧 Under Construction 🚧

Usage

Installation

# Yarn:
yarn global add create-react-typescript-file

# or NPM:
npm i -g create-react-typescript-file

Usage

Navigate into your project's directory and run:

ctf

The tool will give you 3 actions:

  • Create files
  • Initialize (root) folder structure
  • Set up CTF configuration file

Set up CTF configuration file

By running this action, the tool will create a .ctf-config.json file with all defaults and the root you entered. It will ask you for the root folder name and which styling framework you want to use. Currently it "supports" CSS Modules, Styled Components and Vanilla-Extract. But it doesn't really add import statements to those files, so they are easily adoptable with other frameworks.

{
  "root": "src",
  "dirs": {
    "components": "components",
    "hooks": "hooks",
    "adapters": "adapters",
    "config": "config",
    "pages": "pages",
    "helpers": "helpers",
    "types": "types"
  },
  "stylingType": "styled-components",
  "addStylingFileToComponent": true
}

After this setup, the tool will load up this configuration to get the needed default values per action.

Initialize (root) folder structure

This action will quickly setup an entire folder structure for the core parts of your application:

  • components
  • hooks
  • config
  • adapters
  • helpers
  • pages

All of these will be added to the root folder you entered in the configuration action. You can choose to opt out of any of these.

If you've chosen to add an index file per folder, it'll create one within each of those folders with a simple export {} that you can update later.

If you'd like to skip the "index file" question, you can add "addIndexFileToRootFolders": true, to the configuration file.

Create files

Components Currently you can add either a component or a hooks file. When you select a component, you can opt in to create a styling file as well (in the examples below, CSS-modules was selected). After selecting the name and entering the location (or keeping the default), you'll end up with a new directory that has three files:

// Button/index.ts
export { default } from './Button';
// components/Button/Button.tsx
import React from 'react';
import styles from './button.module.css';

type Props = React.ComponentPropsWithoutRef<'div'> & {};

const Button: React.FunctionComponent<Props> = () => {
  return <div />;
};

export default Button;

And an empty style file

// components/Button/button.module.css

If found, it will also add an export statement to the index file of the parent directory.

Hooks Creating a hook will give you similar behavior, except that it will not create an index file, but will only create the following:

// hooks/useMyHook.ts
const useMyHook = () => {
  return {};
};

export default useMyHook;