# @earle-poole/scaffoldit 中文文档

规范地址：https://npmcn.com/package/%40earle-poole/scaffoldit/

版本：1\.0\.11
npm 元数据更新时间：2023-10-17T13:54:00.552Z
中文译文更新时间：2026-11-13T03:37:19.809Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40earle-poole/scaffoldit
原文对照：https://npmcn.com/package/%40earle-poole/scaffoldit/?lang=original
源码仓库：https://github.com/Earle-Poole/scaffoldit

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：67.7 kB，63 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：1 个
- 首次发布：2023-03-20T14:09:59.524Z
- 最新版本发布：2023-10-17T13:54:00.395Z
- 近 30 天下载量：17321（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：11（近 12 个月 0 个）

## 中文简介

脚手架是一个用于脚手架反应组件和页面的 CLI 工具

## 安装

```sh
npm install @earle-poole/scaffoldit
```

也可以使用：`pnpm add @earle-poole/scaffoldit`、`yarn add @earle-poole/scaffoldit`、`bun add @earle-poole/scaffoldit`

## README

# 脚手架

## 如何使用

### 安装

在全球安装软件包...

```cmd
$ npm install -g @earle-poole/scaffoldit

# or

$ yarn global add @earle-poole/scaffoldit
```

... 或安装到本地并将其运行的脚本添加到您的 `package.json` 文档.

```cmd
$ npm install @earle-poole/scaffoldit

# or

$ yarn add @earle-poole/scaffoldit
```

### 使用量

全球安装

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

当地安装, `scaffoldit` 脚本添加到 `package.json`

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

  

## 实例

```
$ npm run scaffoldit src\components\atoms Input
```

此命令将创建以下文件结构 :

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

  

## 演示

本地安装 : ![916C92F9-6B84-4588-953A-616001DA5BF0](https://user-images.githubusercontent.com/44408506/232561882-bbd61311-9bf6-4ec1-93fe-68745c4c1ec7.gif)

全局安装 : ![6683229F-B8D1-4CBA-B294-572DD38E5085](https://user-images.githubusercontent.com/44408506/232561893-a1fa9343-b025-443b-986e-6395d52a2932.gif)

  

## 配置文件

你可以创建自己的模板,并用到脚手架. 要做到这一点,你需要创建一个 `scaffoldit.config.js` 在您的项目根中的文件。 您可以手动创建此文件, 或是使用 `-i, --init` 为您创建旗帜 .

```
$ npm run scaffoldit --init

# or

$ npm run scaffoldit -i
```

这是一个例子 `scaffoldit.config.js` 文件 :

```js
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
  },
}
```

## 默认模板

在没有配置文件的情况下运行脚手架时,会使用默认模板. 这些模板位于 `templates` 文件夹。 默认模板如下:

-   `component.ts` - > (中文) `<ComponentName>.tsx`
-   `story.ts` - > (中文) `<ComponentName>.stories.tsx`
-   `tests.ts` - > (中文) `<ComponentName>.test.tsx`
-   `types.ts` - > (中文) `<ComponentName>.types.ts`
-   `entry.ts` - > (中文) `index.ts`

默认模板在启用自定义模板时被明确禁用之前会被使用.

## 制作自定义模板

要制作自定义模板,需要创建 `.mjs` 文档中 `templates` 您的工程文件夹 。 模板文件名应与要使用的模板名称相同。 例如,如果您想要使用自定义模板,则 `component` 模板,您需要创建名为 `component.mjs` 输入 `templates` 文件夹.

模板文件应导出返回模板字元的函数。 该职能将获得提供 `component-name` 作为争论。 模板字面应包含要创建的文件的模板.

示例模板文件 :

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

## 使用自定义模板

在配置文件初始化期间,您将询问是否想要使用自定义模板 。 如果你选择这样做,将被要求提供 `path` 到您的自定义模板。 路径应该相对于您的项目的根. 接下来将提示您提供 `templates` 你想用这个。 模板应以下列格式提供:

```txt
<template-filename>@<output-extension>
```

实例提示 `init` 进程 :

```cmd
$ Templates to use:
$ component@tsx, story@stories.tsx, tests@test.tsx, types@types.ts
```

以上示例将以下列方式为模板建立文件名并进行输出扩展映射:

-   `component.mjs` - > (中文) `<ComponentName>.tsx`
-   `story.mjs` - > (中文) `<ComponentName>.stories.tsx`
-   `tests.mjs` - > (中文) `<ComponentName>.test.tsx`
-   `types.mjs` - > (中文) `<ComponentName>.types.ts`

_**说明:** 如果您的自定义模板与默认模板相同, 如果启用了默认模板, 它们会覆盖默认模板 ._

## 参数

| 名称/旗帜 | 说明 | 数值 |
| --- | --- | --- |
| `destination-path` | **第一个参数 :** 创建新组件的路径 . | 有效的文件路径 . |
| `component-name` | **第二参数 :** 要创建的组件名称 . | 有效的字符串 . |
| `-i, --init` | 初始化一个配置文件 . | `true`, (中文(简体) ), **`false`** |
| `-f, --force` | 强制覆盖现有文件 . | `true`, (中文(简体) ), **`false`** |
| `-nt, --no-tests` | 从生成的文件中排除测试 . | `true`, (中文(简体) ), **`false`** |
| `-nts, --no-typescript` | 从生成的文件中排除类型脚本 . | `true`, (中文(简体) ), **`false`** |
| `-ns, --no-stories` | 排除故事书文件的创建. | `true`, (中文(简体) ), **`false`** |
| `-ne, --no-entry` | 排除创建 `index.ts` 文档. | `true`, (中文(简体) ), **`false`** |

## 未来特征

-   [x] ~支持自定义模板~
-   [x] ~支持配置文件创建和使用~
-   [x] ~支持自定义文件扩展名~
-   [ ] 支持JS图书馆
    -   [ ] CSS 模块
    -   [ ] 样式组件
    -   [ ] 情感
-   [ ] 添加自定义文件名的支持
-   [ ] 自动检测新添加的模板

## 常见问题

### @earle-poole/scaffoldit 是什么？

脚手架是一个用于脚手架反应组件和页面的 CLI 工具

### 如何安装 @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 和提交记录判断。

