barrel-export

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

桶导出操作工具

Barrel Export Operation Tool

任务目标

Task Objectives

本 Skill 用于自动生成、优化、修复和检查桶导出文件,确保所有 index 文件都遵循统一的规范:
  • 核心原则:所有 index 文件(index.ts / index.js)都必须遵循桶导出规范
  • 自动生成符合规范的 index.ts 文件
  • 修复不符合规范的导出
  • 检查导出规范并生成报告
This Skill is used to automatically generate, optimize, fix, and check barrel export files, ensuring all index files comply with unified specifications:
  • Core Principle: All index files (index.ts / index.js) must follow the barrel export specification
  • Automatically generate compliant index.ts files
  • Fix non-compliant exports
  • Check export specifications and generate reports

触发条件

Trigger Conditions

当用户提出以下需求时触发本 Skill:
核心原则:所有 index 文件(index.ts / index.js)都必须遵循桶导出规范。
场景 1:自动生成/优化/修复桶导出文件
  • "生成桶导出"
  • "优化桶导出"
  • "修复桶导出"
  • "修复 index.ts"
  • "生成 index.ts"
  • "更新桶导出"
场景 2:检查导出规范
  • "检查导出是否符合规范"
  • "检查 index.ts"
  • "验证桶导出"
  • "检查导出文件"
This Skill is triggered when the user has the following needs:
Core Principle: All index files (index.ts / index.js) must follow the barrel export specification.
Scenario 1: Automatically generate/optimize/fix barrel export files
  • "Generate barrel export"
  • "Optimize barrel export"
  • "Fix barrel export"
  • "Fix index.ts"
  • "Generate index.ts"
  • "Update barrel export"
Scenario 2: Check export specifications
  • "Check if exports comply with specifications"
  • "Check index.ts"
  • "Verify barrel export"
  • "Check export files"

操作步骤

Operation Steps

场景 1:自动生成/优化/修复桶导出文件

Scenario 1: Automatically generate/optimize/fix barrel export files

步骤 1:确认目标目录

Step 1: Confirm target directory

默认锁定当前目录(
.
)作为操作对象。如果用户指定了目录,则使用指定目录。
The current directory (
.
) is locked as the operation object by default. If the user specifies a directory, use the specified directory.

步骤 2:扫描当前目录文件

Step 2: Scan current directory files

使用系统命令扫描当前目录下的所有文件:
bash
undefined
Use system commands to scan all files in the current directory:
bash
undefined

列出所有文件

列出所有文件

ls -1
ls -1

或扫描特定扩展名

或扫描特定扩展名

ls -1 *.ts *.tsx *.js *.jsx 2>/dev/null

识别合法的源文件类型:
- `.ts`(TypeScript)
- `.tsx`(TypeScript + JSX)
- `.js`(JavaScript)
- `.jsx`(JavaScript + JSX)
ls -1 *.ts *.tsx *.js *.jsx 2>/dev/null

Identify valid source file types:
- `.ts` (TypeScript)
- `.tsx` (TypeScript + JSX)
- `.js` (JavaScript)
- `.jsx` (JavaScript + JSX)

步骤 3:应用过滤规则

Step 3: Apply filtering rules

排除以下文件类型:
  • index.ts
    /
    index.js
    (桶导出文件本身)
  • *.test.*
    (测试文件,如
    Button.test.tsx
  • *.spec.*
    (规格文件,如
    format.spec.ts
  • *.stories.*
    (Storybook 文件,如
    Button.stories.tsx
  • *.d.ts
    (声明文件,如
    global.d.ts
Exclude the following file types:
  • index.ts
    /
    index.js
    (barrel export files themselves)
  • *.test.*
    (test files, e.g.,
    Button.test.tsx
    )
  • *.spec.*
    (spec files, e.g.,
    format.spec.ts
    )
  • *.stories.*
    (Storybook files, e.g.,
    Button.stories.tsx
    )
  • *.d.ts
    (declaration files, e.g.,
    global.d.ts
    )

步骤 4:应用 _store 特殊规则

Step 4: Apply _store special rule

判断当前目录是否为
_store
目录:
  • 如果是
    _store
    目录
    :只导出
    store.ts
    /
    store.js
    provider.ts
    /
    provider.js
  • 如果是其他目录:导出所有合法文件
Determine if the current directory is a
_store
directory:
  • If it is a
    _store
    directory
    : Only export
    store.ts
    /
    store.js
    and
    provider.ts
    /
    provider.js
  • If it is another directory: Export all valid files

步骤 5:生成导出语句

Step 5: Generate export statements

为每个合法模块生成导出语句:
统一格式
ts
export * from './模块名';
要求
  • 使用
    export * from
    语法
  • 使用相对路径
    ./
  • 按字母顺序排序
  • 保持文件名大小写与实际文件一致
Generate export statements for each valid module:
Unified format:
ts
export * from './模块名';
Requirements:
  • Use
    export * from
    syntax
  • Use relative path
    ./
  • Sort alphabetically
  • Keep filename case consistent with actual files

步骤 6:写入或更新 index.ts

Step 6: Write or update index.ts

如果 index.ts 不存在: 创建新文件,写入生成的导出语句
如果 index.ts 已存在
  1. 读取现有
    index.ts
    内容
  2. 对比现有导出和新生成的导出
  3. 如果不一致,更新文件
If index.ts does not exist: Create a new file and write the generated export statements
If index.ts already exists:
  1. Read the existing
    index.ts
    content
  2. Compare existing exports with newly generated exports
  3. Update the file if there are inconsistencies

步骤 7:验证结果

Step 7: Verify results

检查以下内容:
  • ✅ 所有合法模块已导出
  • ✅ 无效/重复导出已删除
  • _store
    特殊规则已应用(如适用)
  • ✅ 导出格式统一且按字母排序
  • ✅ 文件名大小写与实际文件一致
  • ✅ 无"找不到模块"错误

Check the following items:
  • ✅ All valid modules have been exported
  • ✅ Invalid/duplicate exports have been removed
  • ✅ _store special rule has been applied (if applicable)
  • ✅ Export format is unified and sorted alphabetically
  • ✅ Filename case is consistent with actual files
  • ✅ No "module not found" errors

场景 2:检查导出规范

Scenario 2: Check export specifications

步骤 1:确认目标目录

Step 1: Confirm target directory

与用户确认要检查的目录路径。如果未指定,默认使用当前目录(
.
)。
Confirm the directory path to be checked with the user. If not specified, use the current directory (
.
) by default.

步骤 2:检查 index.ts 是否存在

Step 2: Check if index.ts exists

使用系统命令检查目标目录下是否存在
index.ts
文件:
bash
ls -la index.ts
  • 如果不存在:报告错误,建议先生成
    index.ts
  • 如果存在:继续执行后续检查
Use system commands to check if an
index.ts
file exists in the target directory:
bash
ls -la index.ts
  • If it does not exist: Report an error and suggest generating
    index.ts
    first
  • If it exists: Proceed with subsequent checks

步骤 3:读取并解析 index.ts

Step 3: Read and parse index.ts

使用
read_file
工具读取
index.ts
的完整内容,解析每一行导出语句。
Use the
read_file
tool to read the full content of
index.ts
and parse each line of export statements.

步骤 4:扫描目录文件

Step 4: Scan directory files

使用系统命令扫描当前目录下的所有文件:
bash
ls -1 *.ts *.tsx *.js *.jsx 2>/dev/null
识别合法的源文件类型:
  • .ts
    (TypeScript)
  • .tsx
    (TypeScript + JSX)
  • .js
    (JavaScript)
  • .jsx
    (JavaScript + JSX)
Use system commands to scan all files in the current directory:
bash
ls -1 *.ts *.tsx *.js *.jsx 2>/dev/null
Identify valid source file types:
  • .ts
    (TypeScript)
  • .tsx
    (TypeScript + JSX)
  • .js
    (JavaScript)
  • .jsx
    (JavaScript + JSX)

步骤 5:执行核心检查项

Step 5: Execute core check items

执行以下检查:
检查项 1:文件存在性检查
  • 检查
    index.ts
    文件是否存在
检查项 2:导出格式规范检查
  • 检查所有导出语句是否使用
    export * from
    格式
  • 检查是否有
    export default
    export { }
    等不规范格式
检查项 3:排序检查
  • 检查导出语句是否按模块名字母顺序排序
检查项 4:重复导出检查
  • 检查是否存在重复的模块导出
检查项 5:导出有效性检查
  • 检查每个导出的模块是否在目录中实际存在
  • 检查文件名大小写是否匹配
检查项 6:排除规则检查
  • 检查是否导出了应排除的文件:
    • *.test.*
      (测试文件)
    • *.spec.*
      (规格文件)
    • *.stories.*
      (Storybook 文件)
    • *.d.ts
      (声明文件)
检查项 7:_store 特殊规则检查
  • 如果目录名为
    _store
    ,检查是否只导出
    store
    provider
Perform the following checks:
Check Item 1: File existence check
  • Check if the
    index.ts
    file exists
Check Item 2: Export format specification check
  • Check if all export statements use the
    export * from
    format
  • Check for non-standard formats such as
    export default
    ,
    export { }
    , etc.
Check Item 3: Sorting check
  • Check if export statements are sorted alphabetically by module name
Check Item 4: Duplicate export check
  • Check for duplicate module exports
Check Item 5: Export validity check
  • Check if each exported module actually exists in the directory
  • Check if filename case matches
Check Item 6: Exclusion rule check
  • Check if excluded files are exported:
    • *.test.*
      (test files)
    • *.spec.*
      (spec files)
    • *.stories.*
      (Storybook files)
    • *.d.ts
      (declaration files)
Check Item 7: _store special rule check
  • If the directory is named
    _store
    , check if only
    store
    and
    provider
    are exported

步骤 6:生成检查报告

Step 6: Generate check report

按照以下格式生成详细的检查报告:
=== 桶导出规范检查报告 ===

📁 检查目录: <目录路径>

📊 统计信息
- 导出模块总数: X
- 问题总数: X

✅ 检查通过: <数量>
❌ 检查失败: <数量>

---

详细检查结果

1. 文件存在性检查
   ✅ 通过 / ❌ 失败
   说明: <详细说明>

2. 导出格式规范检查
   ✅ 通过 / ❌ 失败
   说明: <详细说明>
   问题列表: <如有问题,列出所有问题>

...

---

💡 修复建议
<如有问题,提供修复建议>

🎯 总体评价
✅ 完全符合规范 / ⚠️ 部分符合规范 / ❌ 不符合规范
Generate a detailed check report in the following format:
=== Barrel Export Specification Check Report ===

📁 Check Directory: <Directory Path>

📊 Statistical Information
- Total Exported Modules: X
- Total Issues: X

✅ Passed Checks: <Quantity>
❌ Failed Checks: <Quantity>

---

Detailed Check Results

1. File Existence Check
   ✅ Passed / ❌ Failed
   Description: <Detailed Description>

2. Export Format Specification Check
   ✅ Passed / ❌ Failed
   Description: <Detailed Description>
   Issue List: <List all issues if any>

...

---

💡 Fix Recommendations
<Provide fix recommendations if there are issues>

🎯 Overall Evaluation
✅ Fully Compliant / ⚠️ Partially Compliant / ❌ Non-Compliant

步骤 7:提供修复建议

Step 7: Provide fix recommendations

对于每个失败的检查项,提供具体的修复建议。
For each failed check item, provide specific fix recommendations.

注意事项

Notes

核心原则

Core Principles

所有 index 文件(index.ts / index.js)都必须遵循桶导出规范
无论目录类型、文件数量、项目规模如何,只要存在 index 文件,就必须:
  1. 使用统一格式
    export * from './模块名';
  2. 按字母顺序排序:导出语句按模块名字母顺序排列
  3. 排除不应导出的文件:test、spec、stories、d.ts 等文件不导出
  4. 遵循 _store 特殊规则:如果是
    _store
    目录,只导出
    store
    provider
  5. 确保导出有效性:所有导出的模块必须实际存在
All index files (index.ts / index.js) must follow the barrel export specification
Regardless of directory type, number of files, or project scale, as long as index files exist, they must:
  1. Use unified format:
    export * from './模块名';
  2. Sort alphabetically: Export statements are sorted alphabetically by module name
  3. Exclude non-exportable files: Do not export test, spec, stories, d.ts, etc.
  4. Follow _store special rule: If it is a
    _store
    directory, only export
    store
    and
    provider
  5. Ensure export validity: All exported modules must actually exist

使用原则

Usage Principles

  • 桶导出文件仅负责导出,不包含任何业务逻辑
  • 支持目录路径和文件路径输入,文件路径会自动定位到所在目录
  • _store
    目录的桶导出只导出
    store
    provider
    ,其他文件不应暴露
  • 文档前后描述必须保持一致,避免歧义
  • 强制遵循规范:所有 index 文件都必须符合桶导出规范,无例外
  • Barrel export files are only responsible for exports and do not contain any business logic
  • Supports directory path and file path input; file paths will automatically locate to the directory they belong to
  • Barrel exports for
    _store
    directories only export
    store
    and
    provider
    ; other files should not be exposed
  • Descriptions in documents must be consistent to avoid ambiguity
  • Mandatory compliance: All index files must comply with the barrel export specification without exceptions