mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
chore: add entry capitalization
This commit is contained in:
parent
bd4234c2f5
commit
644682292a
@ -1,4 +1,5 @@
|
|||||||
#!/usr/bin/env ts-node
|
#!/usr/bin/env ts-node
|
||||||
|
|
||||||
/* eslint-disable no-console */
|
/* eslint-disable no-console */
|
||||||
import { readFile, writeFile } from 'fs-extra';
|
import { readFile, writeFile } from 'fs-extra';
|
||||||
|
|
||||||
@ -8,18 +9,25 @@ import { readFile, writeFile } from 'fs-extra';
|
|||||||
* to the changelog.
|
* to the changelog.
|
||||||
* Current automatic changes:
|
* Current automatic changes:
|
||||||
* - Change all version titles to H2 ("### [vX.Y.Z]" to "## [vX.Y.Z]")
|
* - Change all version titles to H2 ("### [vX.Y.Z]" to "## [vX.Y.Z]")
|
||||||
|
* - Capitalize all list entries
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param from - Regular expression to search for
|
* Capitalize all list entries
|
||||||
* @param to - String to replace to
|
* @param input - String to search/replace
|
||||||
* @param filePath - File to search/replace
|
* @returns Promise with output string
|
||||||
* @returns Promise
|
|
||||||
*/
|
*/
|
||||||
async function replaceInFile(from: RegExp, to: string, filePath: string): Promise<void> {
|
async function capitalizeListEntries(input: string): Promise<string> {
|
||||||
const data = await readFile(filePath, 'utf8');
|
return input.replace(/^(\W*\* [a-z])/gmu, (match): string => match.toUpperCase());
|
||||||
const result = data.replace(from, to);
|
}
|
||||||
return writeFile(filePath, result, 'utf8');
|
|
||||||
|
/**
|
||||||
|
* Change all version titles to H2 ("### [vX.Y.Z]" to "## [vX.Y.Z]")
|
||||||
|
* @param input - String to search/replace
|
||||||
|
* @returns Promise with output string
|
||||||
|
*/
|
||||||
|
async function convertH3ToH2(input: string): Promise<string> {
|
||||||
|
return input.replace(/### \[/gu, '## [');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,4 +38,16 @@ function endProcess(error: Error): never {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
replaceInFile(/### \[/gu, '## [', 'CHANGELOG.md').catch(endProcess);
|
/**
|
||||||
|
* Main function for changelog formatting
|
||||||
|
* @param filePath - Path to the changelog file
|
||||||
|
* @returns Promise
|
||||||
|
*/
|
||||||
|
async function formatChangelog(filePath: string): Promise<void> {
|
||||||
|
let changelog = await readFile(filePath, 'utf8');
|
||||||
|
changelog = await convertH3ToH2(changelog);
|
||||||
|
changelog = await capitalizeListEntries(changelog);
|
||||||
|
return writeFile(filePath, changelog, 'utf8');
|
||||||
|
}
|
||||||
|
|
||||||
|
formatChangelog('CHANGELOG.md').catch(endProcess);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user