@earle-poole/scaffoldit

中文文档
1.0.11发布于 2023/10/17MITTypeScriptES Module近 30 天下载 1.7万

Scaffoldit is a CLI tool to scaffold React components and pages

原始使用文档
文档目录11 节
  1. How to use
  2. Installation
  3. Usage
  4. Examples
  5. Demo
  6. Config File
  7. Default Templates
  8. Making a Custom Template
  9. Using Custom Templates
  10. Arguments
  11. Future Features

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/FlagDescriptionValues
destination-pathFirst arg: The path where the new component will be created.A valid file path.
component-nameSecond arg: The name of the component to be created.A valid string.
-i, --initInitialize a config file.true, false
-f, --forceForces overwriting of existing files.true, false
-nt, --no-testsExclude tests from the generated files.true, false
-nts, --no-typescriptExclude TypeScript from the generated files.true, false
-ns, --no-storiesExclude the creation of storybook files.true, false
-ne, --no-entryExclude the creation of an index.ts file.true, false

Future Features

  • Support custom templates
  • Support config file creation & usage
  • 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

版本与发布记录

@earle-poole/scaffoldit 共发布 11 个版本,首次发布于 2023/03/20;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.11latest2023/10/173 年前
1.0.102023/05/293 年前
1.0.92023/04/133 年前
1.0.82023/04/123 年前
1.0.72023/04/123 年前
1.0.62023/04/123 年前

关于 @earle-poole/scaffoldit 的常见问题

@earle-poole/scaffoldit 是什么?

Scaffoldit is a CLI tool to scaffold React components and pages

如何安装 @earle-poole/scaffoldit?

在项目目录运行 npm install @earle-poole/scaffoldit,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 scaffoldit,可以用 npx scaffoldit 直接运行。

@earle-poole/scaffoldit 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@earle-poole/scaffoldit 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@earle-poole/scaffoldit 可以商用吗?

@earle-poole/scaffoldit 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@earle-poole/scaffoldit 的下载量有多少?

根据 npm 官方下载统计,@earle-poole/scaffoldit 在 2026/10/13 – 2026/11/11 这 30 天内被下载 17,321 次,日均约 577 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@earle-poole/scaffoldit 还在维护吗?

最新版本 1.0.11 发布于 2023/10/17(3 年前);至今共发布 11 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/03/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。