UNPKG

@elora-cloud/elora-cli

Version:
72 lines (69 loc) 1.99 kB
import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; import { execaSync } from 'execa'; import { isMonorepo } from '../../common/index.mjs'; import { CWD } from '../../common/constant.mjs'; // 获取当前模块文件的 URL const __filename = fileURLToPath(import.meta.url); // 获取当前模块文件的目录路径 const __dirname = dirname(__filename); function formatType(type) { const MAP = { fix: 'Bug Fixes', feat: 'Feature', docs: 'Document', types: 'Types', }; return MAP[type] || type; } function getPackagesInfo(filter) { let data; if (filter) { data = execaSync('node', [join(__dirname, './execPackages.mjs'), `--name=${filter}`]); } else { data = execaSync('node', [join(__dirname, './execPackages.mjs')]); } try { return JSON.parse(data.stdout); } catch (e) { console.log('e ==> ', e); return false; } } // 格式化代码 function transform(item, _context) { if (item.type === 'chore' || item.type === 'test') { return null; } const typeTmp = formatType(item.type); if (isMonorepo()) { const pkgInfo = getPackagesInfo(item.scope); if (pkgInfo) { // // 当前是一个monorepo的项目 const first = pkgInfo[0]; if (!first) return null; if (first.dir !== CWD) { return null; } } else { return null; } } let shortHash = item.shortHash; if (item.hash) { shortHash = item.hash.slice(0, 8); } if (item.references.length) { item.references.forEach((ref) => { if (ref.issue && item.subject) { item.subject = item.subject.replace(` (#${ref.issue})`, ''); } }); } return { ...item, type: typeTmp, shortHash }; } export { formatType, getPackagesInfo, transform };