← 教程列表
coding

Task 1: Extract Frontmatter Parsing

📅 2026/6/12 16:30:02⏱ 约 5 分钟阅读👁 10 阅读

**Files:** - Create: `lib/skills-core.js` - Reference: `.codex/superpowers-codex` (lines 40-74) **Step 1: Create lib/skills-core.js with extractFrontmatter function** ```javascript #!/usr/bin/env node const fs = require('fs'); const path = require('path'); /** * Extract YAML frontmatter from a skill file. * Current format: * --- * name: skill-name * description: Use when [condition] - [what it does] * --- * * @param {string} filePath - Path to SKILL.md file * @returns {{name: string, description: string}} */ function extractFrontmatter(filePath) { try { const content = fs.readFileSync(filePath, 'utf8'); const lines = content.split('\n'); let inFrontmatter = false; let name = ''; let description = ''; for (const line of lines) { if (line.trim() === '---') { if (inFrontmatter) break; inFrontmatter = true; continue; } if (inFrontmatter) { const match = line.match(/^(\w+):\s*(.*)$/); if (match) { const [, key, value] = match; switch (key) { case 'name': name = value.trim(); break; case 'description': description = value.trim(); break; } } } } return { name, description }; } catch (error) { return { name: '', description: '' }; } } module.exports = { extractFrontmatter }; ``` **Step 2: Verify file was created** Run: `ls -l lib/skills-core.js` Expected: File exists **Step 3: Commit** ```bash git add lib/skills-core.js git commit -m "feat: create shared skills core module with frontmatter parser" ``` ---

← 返回教程列表 AI8899 · 内容仅供学习参考