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
undefinedUse 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 - (Storybook 文件,如
*.stories.*)Button.stories.tsx - (声明文件,如
*.d.ts)global.d.ts
Exclude the following file types:
- /
index.ts(barrel export files themselves)index.js - (test files, e.g.,
*.test.*)Button.test.tsx - (spec files, e.g.,
*.spec.*)format.spec.ts - (Storybook files, e.g.,
*.stories.*)Button.stories.tsx - (declaration files, e.g.,
*.d.ts)global.d.ts
步骤 4:应用 _store 特殊规则
Step 4: Apply _store special rule
判断当前目录是否为 目录:
_store- 如果是 目录:只导出
_store/store.ts和store.js/provider.tsprovider.js - 如果是其他目录:导出所有合法文件
Determine if the current directory is a directory:
_store- If it is a directory: Only export
_store/store.tsandstore.js/provider.tsprovider.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 syntax
export * from - 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 已存在:
- 读取现有 内容
index.ts - 对比现有导出和新生成的导出
- 如果不一致,更新文件
If index.ts does not exist:
Create a new file and write the generated export statements
If index.ts already exists:
- Read the existing content
index.ts - Compare existing exports with newly generated exports
- 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.tsbash
ls -la index.ts- 如果不存在:报告错误,建议先生成
index.ts - 如果存在:继续执行后续检查
Use system commands to check if an file exists in the target directory:
index.tsbash
ls -la index.ts- If it does not exist: Report an error and suggest generating first
index.ts - If it exists: Proceed with subsequent checks
步骤 3:读取并解析 index.ts
Step 3: Read and parse index.ts
使用 工具读取 的完整内容,解析每一行导出语句。
read_fileindex.tsUse the tool to read the full content of and parse each line of export statements.
read_fileindex.ts步骤 4:扫描目录文件
Step 4: Scan directory files
使用系统命令扫描当前目录下的所有文件:
bash
ls -1 *.ts *.tsx *.js *.jsx 2>/dev/null识别合法的源文件类型:
- (TypeScript)
.ts - (TypeScript + JSX)
.tsx - (JavaScript)
.js - (JavaScript + JSX)
.jsx
Use system commands to scan all files in the current directory:
bash
ls -1 *.ts *.tsx *.js *.jsx 2>/dev/nullIdentify valid source file types:
- (TypeScript)
.ts - (TypeScript + JSX)
.tsx - (JavaScript)
.js - (JavaScript + JSX)
.jsx
步骤 5:执行核心检查项
Step 5: Execute core check items
执行以下检查:
检查项 1:文件存在性检查
- 检查 文件是否存在
index.ts
检查项 2:导出格式规范检查
- 检查所有导出语句是否使用 格式
export * from - 检查是否有 、
export default等不规范格式export { }
检查项 3:排序检查
- 检查导出语句是否按模块名字母顺序排序
检查项 4:重复导出检查
- 检查是否存在重复的模块导出
检查项 5:导出有效性检查
- 检查每个导出的模块是否在目录中实际存在
- 检查文件名大小写是否匹配
检查项 6:排除规则检查
- 检查是否导出了应排除的文件:
- (测试文件)
*.test.* - (规格文件)
*.spec.* - (Storybook 文件)
*.stories.* - (声明文件)
*.d.ts
检查项 7:_store 特殊规则检查
- 如果目录名为 ,检查是否只导出
_store和storeprovider
Perform the following checks:
Check Item 1: File existence check
- Check if the file exists
index.ts
Check Item 2: Export format specification check
- Check if all export statements use the format
export * from - Check for non-standard formats such as ,
export default, etc.export { }
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 files)
*.test.* - (spec files)
*.spec.* - (Storybook files)
*.stories.* - (declaration files)
*.d.ts
Check Item 7: _store special rule check
- If the directory is named , check if only
_storeandstoreare exportedprovider
步骤 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 文件,就必须:
- 使用统一格式:
export * from './模块名'; - 按字母顺序排序:导出语句按模块名字母顺序排列
- 排除不应导出的文件:test、spec、stories、d.ts 等文件不导出
- 遵循 _store 特殊规则:如果是 目录,只导出
_store和storeprovider - 确保导出有效性:所有导出的模块必须实际存在
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:
- Use unified format:
export * from './模块名'; - Sort alphabetically: Export statements are sorted alphabetically by module name
- Exclude non-exportable files: Do not export test, spec, stories, d.ts, etc.
- Follow _store special rule: If it is a directory, only export
_storeandstoreprovider - 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 directories only export
_storeandstore; other files should not be exposedprovider - Descriptions in documents must be consistent to avoid ambiguity
- Mandatory compliance: All index files must comply with the barrel export specification without exceptions