Skip to content

Commit

Permalink
updates CHANGE log and script to valid it
Browse files Browse the repository at this point in the history
  • Loading branch information
tsamaya committed Jun 3, 2024
1 parent e44b361 commit 8b5a72f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
19 changes: 13 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
# Changelog

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
And, this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [unreleased]

## [2.0.0-alpha-1] (2024-06-xx)

### Features

- Refactor using typescript, microbundle for packaging

### Chore

- Script to validate CHANGELOG file

### Documentation

- Uses [typedoc](https://typedoc.org/)

<!-- ## [unreleased] -->

## [1.0.6] (2024-06-xx)
## [1.0.6] (2024-06-03)

### Chore

- Drop CircleCI
- Uses pnpm as package manager
- upgrade dependencies
- Upgrade dependencies
- Drop CircleCI
- GHActions codecov and meterian runs only on branch master

## [1.0.5] (2024-04-27)
Expand Down
36 changes: 22 additions & 14 deletions scripts/valid-changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ const changelog = readFileSync('./CHANGELOG.md', 'utf-8');
const packageJson = JSON.parse(readFileSync('./package.json', 'utf-8'));

if (!packageJson || !packageJson.version) {
throw new Error('Could not get current version from package.json');
console.error('❌ Could not get current version from package.json');
process.exit();
}

if (!changelog.startsWith('# Changelog')) {
throw new Error('Change log should start with changelog title');
console.error('❌ Change log should start with changelog title');
process.exit();
}

const version = `[${packageJson.version}]`;
Expand All @@ -23,34 +25,40 @@ console.log(`Version detected: ${version}`);

const changes = changelog.split('## ');

if (!changes[1].startsWith(version)) {
throw new Error('Latest version is not latest change log title');
// console.log(changes);

if (!changes[2].startsWith(version)) {
console.error('❌ Latest version is not latest change log title');
process.exit();
}

if (changes.length === 0) {
throw new Error('No changes detected in change log');
console.error('❌ No changes detected in change log');
process.exit();
}

if (changes.length === 1) {
throw new Error(
'Changelog appears invalid with only one change title and no entries'
console.error(
'Changelog appears invalid with only one change title and no entries'
);
process.exit();
}

if (changes[0].startsWith('[') && changes[1].startsWith('[')) {
throw new Error('Changelog should always have at least one change');
if (changes[2].startsWith('[') && changes[3].startsWith('[')) {
console.error('❌ Changelog should always have at least one change');
process.exit();
}

const lastChanges = changelog.split('## [')[1];

const lastChangesTypes = lastChanges.split('###');
const lastChanges = changelog.split('## [')[2];

const lastChangesTypes = lastChanges.split('### ');
lastChangesTypes.shift(); // Remove title

const lastGranularChanges = lastChanges.split('- ');

if (lastGranularChanges.length === 0) {
throw new Error('Changelog should always have at least one change');
if (lastGranularChanges.length === 1) {
console.error('❌ Changelog should always have at least one change per type');
process.exit();
}

console.log(`Changelog for ${packageJson.version} is valid! ✅`);
Expand Down

0 comments on commit 8b5a72f

Please sign in to comment.