Skip to content

Instantly share code, notes, and snippets.

@mjhenkes
Created July 31, 2020 13:09
Show Gist options
  • Select an option

  • Save mjhenkes/d6917ca0883408662b2546024e58dbf9 to your computer and use it in GitHub Desktop.

Select an option

Save mjhenkes/d6917ca0883408662b2546024e58dbf9 to your computer and use it in GitHub Desktop.
super ugly hacky script to update terra readmes one time
#!/usr/bin/env node
/* eslint-disable no-console */
/* eslint import/no-extraneous-dependencies: ["error", {"devDependencies": true}] */
const fs = require('fs');
const filePath = './CHANGELOG.md';
const output = fs.readFileSync(filePath, 'utf8');
const withoutH3 = output.replace(/### /g, '');
const withH1 = withoutH3.replace('Changelog', '# Changelog');
const withUpperH1 = withH1.replace('ChangeLog', '# Changelog');
const withoutDivider = withUpperH1.replace(/=========\n/g, '');
const withoutOtherDivider = withoutDivider.replace(/------------------/g, '');
const withoutYetAnotherDivider = withoutOtherDivider.replace(/-----------------/g, '');
const withoutLastDivider = withoutYetAnotherDivider.replace(/----------\n/g, '');
const withoutLastishDivider = withoutLastDivider.replace(/--------\n/g, '');
const withoutAnotherDivider = withoutLastishDivider.replace(/-------\n/g, '');
const withUnreleasedH2 = withoutAnotherDivider.replace('Unreleased', '## Unreleased');
const withH2 = withUnreleasedH2.replace(/^\d*\.\d*\.\d*/gm, '## $&');
const changed = withH2.replace(/^Changed$/gm, 'Changed\n');
const added = changed.replace(/^Added$/gm, 'Added\n');
const removed = added.replace(/^Removed$/gm, 'Removed\n');
const fixed = removed.replace(/^Fixed$/gm, 'Fixed\n');
const breaking = fixed.replace(/^Breaking Change$/gm, 'Breaking Change\n');
const breakings = breaking.replace(/^Breaking Changes$/gm, 'Breaking Change\n');
const spaceOutList = breakings.replace(/^\*/gm, ' *');
const changeAsList = spaceOutList.replace(/\n([a-zA-Z0-9_ ]*\n)\n/g, '\n* $1');
const intial = changeAsList.replace(/^ \* Initial release/gm, '* Initial stable release');
// console.log(filePath, '\n', breaking);
fs.writeFileSync(filePath, intial, { encoding: 'utf8', flag: 'w' });
// console.log('dirs', dirs);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment