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

@earle-poole/scaffoldit

v1.0.11

Published

Scaffoldit is a CLI tool to scaffold React components and pages

Downloads

1,548

Readme

Scaffoldit

How to use

Installation

Install the package globally ...

$ npm install -g @earle-poole/scaffoldit

# or

$ yarn global add @earle-poole/scaffoldit

... or install it locally and add its run script to your package.json file.

$ npm install @earle-poole/scaffoldit

# or

$ yarn add @earle-poole/scaffoldit

Usage

Global installation

$ scaffoldit <destination-path> <component-name> [options]

Local installation, scaffoldit script added to package.json

$ npm run scaffoldit <destination-path> <component-name> [options]

Examples

$ npm run scaffoldit src\components\atoms Input

This command will create the following file structure:

src/
└── components/
    └── atoms/
        └── Input/
            ├── index.ts
            ├── Input.stories.tsx
            ├── Input.tsx
            ├── Input.test.tsx
            └── Input.types.ts

Demo

Local install: 916C92F9-6B84-4588-953A-616001DA5BF0

Global install: 6683229F-B8D1-4CBA-B294-572DD38E5085

Config File

You can create your own templates and use them with Scaffoldit. To do so, you need to create a scaffoldit.config.js file in the root of your project. You can create this file manually, or you can use the -i, --init flag to create it for you.

$ npm run scaffoldit --init

# or

$ npm run scaffoldit -i

This is an example of a scaffoldit.config.js file:

export default {
  forceOverwrite: false, // Force accept all overwrite prompts
  noEntry: false, // Exclude creation of default `index` file
  noStories: false, // Exclude creation of default `stories` file
  noTests: false, // Exclude creation of default `test` file
  noTypescript: false, // Exclude creation of default `types` file
  customTemplates: {
    enabled: false, // Enable custom templates
    path: "", // Path to custom templates
    templates: [], // Custom templates filenames with output extension
    defaultTemplatesEnabled: true, // Enable default templates
  },
}

Default Templates

When running Scaffoldit without a config file, it will use the default templates. These templates are located in the templates folder of the package. The default templates are as follows:

  • component.ts -> <ComponentName>.tsx
  • story.ts -> <ComponentName>.stories.tsx
  • tests.ts -> <ComponentName>.test.tsx
  • types.ts -> <ComponentName>.types.ts
  • entry.ts -> index.ts

Default templates will be used until they are explicitly disabled when enabling custom templates.

Making a Custom Template

To make a custom template, you need to create a .mjs file in the templates folder of your project. The filename of the template should be the same as the name of the template you want to use. For example, if you want to use a custom template for the component template, you need to create a file named component.mjs in the templates folder.

The template file should export a function that returns a template literal. The function will receive the provided component-name as an argument. The template literal should contain the template for the file you want to create.

Example template file:

export default (componentName) => `export const ${componentName} = () => {
    return <div>${componentName}</div>;
  };
`

Using Custom Templates

During the initialization of the config file, you will be asked if you want to use custom templates. If you choose to do so, you will be asked to provide the path to your custom templates. The path should be relative to the root of your project. Next you will be prompted to provide the templates you want to use. The templates should be provided in the following format:

<template-filename>@<output-extension>

Example prompt during init process:

$ Templates to use:
$ component@tsx, [email protected], [email protected], [email protected]

The example above will establish a filename for a template to look for and an output extension mapping in the following way:

  • component.mjs -> <ComponentName>.tsx
  • story.mjs -> <ComponentName>.stories.tsx
  • tests.mjs -> <ComponentName>.test.tsx
  • types.mjs -> <ComponentName>.types.ts

Note: If your custom templates are named identically to the default templates, they will override the default templates, if default templates are enabled.

Arguments

| Name/Flag | Description | Values | | ----------------------- | ------------------------------------------------------------------- | ------------------- | | destination-path | First arg: The path where the new component will be created. | A valid file path. | | component-name | Second arg: The name of the component to be created. | A valid string. | | -i, --init | Initialize a config file. | true, false | | -f, --force | Forces overwriting of existing files. | true, false | | -nt, --no-tests | Exclude tests from the generated files. | true, false | | -nts, --no-typescript | Exclude TypeScript from the generated files. | true, false | | -ns, --no-stories | Exclude the creation of storybook files. | true, false | | -ne, --no-entry | Exclude the creation of an index.ts file. | true, false |

Future Features

  • [x] ~~Support custom templates~~
  • [x] ~~Support config file creation & usage~~
  • [x] ~~Support custom file extensions~~
  • [ ] Support for CSS-in-JS libraries
    • [ ] CSS Modules
    • [ ] Styled Components
    • [ ] Emotion
  • [ ] Add support for custom file names
  • [ ] Automated detection of newly added templates