|
48 | 48 | }
|
49 | 49 |
|
50 | 50 | function getAst(markdownString) {
|
51 |
| - const tree = unified() |
52 |
| - .use(remarkParse) |
53 |
| - .parse(markdownString); |
| 51 | + const tree = unified().use(remarkParse).parse(markdownString); |
54 | 52 | return tree;
|
55 | 53 | }
|
56 | 54 |
|
@@ -94,7 +92,8 @@ function format(ast, path) {
|
94 | 92 | ) {
|
95 | 93 | const link = item.children[0];
|
96 | 94 | item.children = [item.children[1]];
|
97 |
| - item.children[0].value = link.children[0].value + item.children[0].value; |
| 95 | + item.children[0].value = |
| 96 | + link.children[0].value + item.children[0].value; |
98 | 97 | changed = true;
|
99 | 98 | } else if (item.children.length !== 1) {
|
100 | 99 | console.log(
|
@@ -189,6 +188,19 @@ function format(ast, path) {
|
189 | 188 | // checks on all ### headings
|
190 | 189 | if (item.type === "heading" && item.depth === 3) {
|
191 | 190 | // check it only uses one of the fixed options for change types
|
| 191 | + if (item.children.length === 1 && item.children[0].type === "text") { |
| 192 | + const val = item.children[0].value; |
| 193 | + if (val.toLowerCase().endsWith("breaking changes")) { |
| 194 | + item.children[0].value = "Changed"; |
| 195 | + changed = true; |
| 196 | + } else if (val.includes("Bug Fixes")) { |
| 197 | + item.children[0].value = "Fixed"; |
| 198 | + changed = true; |
| 199 | + } else if (val.includes("Features")) { |
| 200 | + item.children[0].value = "Added"; |
| 201 | + changed = true; |
| 202 | + } |
| 203 | + } |
192 | 204 | if (
|
193 | 205 | item.children.length !== 1 ||
|
194 | 206 | item.children[0].type !== "text" ||
|
@@ -226,10 +238,10 @@ function format(ast, path) {
|
226 | 238 |
|
227 | 239 | if (changed) {
|
228 | 240 | // ...work around convoluted API...
|
229 |
| - const wat = { data () {} }; |
| 241 | + const wat = { data() {} }; |
230 | 242 | remarkStringify.call(wat);
|
231 | 243 | const output = wat.compiler(ast);
|
232 |
| - writeFileSync(path, output, 'utf8'); |
| 244 | + writeFileSync(path, `# Changelog\n\n${output}`, "utf8"); |
233 | 245 | }
|
234 | 246 |
|
235 | 247 | return { correct: true, changed };
|
|
0 commit comments