|
1 | 1 | const fs = require('node:fs')
|
2 | 2 | const path = require('node:path')
|
3 | 3 |
|
| 4 | +const extraKeys = ['createDiscreteApi'] |
| 5 | +const componentMapping = { |
| 6 | + 'n-collapse-item': 'n-collapse', |
| 7 | + 'n-float-button-group': 'n-float-button', |
| 8 | + 'n-checkbox-group': 'n-checkbox', |
| 9 | + 'n-form-item': 'n-form', |
| 10 | + 'n-form-item-gi': 'n-form-item', |
| 11 | + 'n-input-group': 'n-input', |
| 12 | + 'n-upload-trigger': 'n-upload', |
| 13 | + 'n-descriptions-item': 'n-descriptions', |
| 14 | + 'n-image-group': 'n-image', |
| 15 | + 'n-list-item': 'n-list', |
| 16 | + 'n-timeline-item': 'n-timeline', |
| 17 | + 'n-anchor-link': 'n-anchor', |
| 18 | + 'n-breadcrumb-item': 'n-breadcrumb', |
| 19 | + 'n-tab-pane': 'n-tabs', |
| 20 | + 'n-drawer-content': 'n-drawer', |
| 21 | + 'n-layout-sider': 'n-layout', |
| 22 | + 'n-layout-header': 'n-layout', |
| 23 | + 'n-layout-footer': 'n-layout', |
| 24 | + 'n-layout-content': 'n-layout', |
| 25 | + 'n-grid-item': 'n-grid' |
| 26 | +} |
| 27 | + |
4 | 28 | function parseChangelog(content) {
|
5 | 29 | const logs = {}
|
6 | 30 | let version = ''
|
@@ -32,35 +56,53 @@ function parseChangelog(content) {
|
32 | 56 | return
|
33 | 57 | }
|
34 | 58 |
|
35 |
| - const componentMatch = line.match(/^- .*?`(n-[^`]*)`/) |
36 |
| - const apiMatch = line.match(/^- .*?`([^`]*Api)`/) |
| 59 | + const componentMatches = Array.from(line.matchAll(/`(n-[^`]*)`/g)).map( |
| 60 | + match => match[1] |
| 61 | + ) |
37 | 62 |
|
38 |
| - const name = componentMatch |
39 |
| - ? componentMatch[1] |
40 |
| - : apiMatch |
41 |
| - ? apiMatch[1] |
42 |
| - : '' |
| 63 | + const extraMatches = extraKeys.filter(key => line.includes(`\`${key}\``)) |
43 | 64 |
|
44 |
| - const content = isBreaking ? `${line.trim()} 🚨` : `${line.trim()}` |
| 65 | + const names = new Set() |
45 | 66 |
|
46 |
| - if (!logs[name]) { |
47 |
| - logs[name] = [] |
48 |
| - } |
| 67 | + componentMatches.forEach((name) => { |
| 68 | + if (componentMapping[name]) { |
| 69 | + names.add(componentMapping[name]) |
| 70 | + } |
| 71 | + else { |
| 72 | + names.add(name) |
| 73 | + } |
| 74 | + }) |
49 | 75 |
|
50 |
| - const existingLog = logs[name].find( |
51 |
| - log => log.version === version && log.date === date |
52 |
| - ) |
| 76 | + extraMatches.forEach((name) => { |
| 77 | + names.add(name) |
| 78 | + }) |
53 | 79 |
|
54 |
| - if (existingLog) { |
55 |
| - existingLog.changes.push(content) |
56 |
| - } |
57 |
| - else { |
58 |
| - logs[name].push({ |
59 |
| - version, |
60 |
| - date, |
61 |
| - changes: [content] |
62 |
| - }) |
| 80 | + if (names.size === 0) { |
| 81 | + names.add('') |
63 | 82 | }
|
| 83 | + |
| 84 | + const content = isBreaking ? `${line.trim()} 🚨` : `${line.trim()}` |
| 85 | + |
| 86 | + names.forEach((name) => { |
| 87 | + if (!logs[name]) { |
| 88 | + logs[name] = [] |
| 89 | + } |
| 90 | + |
| 91 | + const existingLog = logs[name].find( |
| 92 | + log => log.version === version && log.date === date |
| 93 | + ) |
| 94 | + |
| 95 | + if (existingLog) { |
| 96 | + existingLog.changes.push(content) |
| 97 | + } |
| 98 | + else { |
| 99 | + logs[name].push({ |
| 100 | + version, |
| 101 | + date, |
| 102 | + changes: [content] |
| 103 | + }) |
| 104 | + } |
| 105 | + }) |
64 | 106 | })
|
65 | 107 |
|
66 | 108 | return logs
|
|
0 commit comments