Skip to content

Commit

Permalink
New features to resolve-changelog (#9)
Browse files Browse the repository at this point in the history
* features

* New version 1.1.1. Read more https://github.com/V4Fire/cli/releases/tag/1.1.1
  • Loading branch information
Razdva122 authored Jul 9, 2021
1 parent 3090b34 commit 6326d9f
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 3 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
_Note: Gaps between patch versions are faulty, broken or test releases._

## v1.1.1 (2021-07-09)

#### :rocket: New Feature

- `resolve-changelog` - remove duplicates from changelog.

#### :nail_care: Polish

- `resolve-changelog` - delete trailing spaces from empty lines.

## v1.1.0 (2021-07-05)

#### :rocket: New Feature
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@v4fire/cli",
"version": "1.1.0",
"version": "1.1.1",
"description": "Tools for creating V4Fire blocks and pages from CLI",
"main": "index.js",
"bin": {
Expand Down
27 changes: 25 additions & 2 deletions src/controllers/resolve-changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ResolveChangelogController extends Controller {

const isValidFile = lines.every((line) => {
if (line.startsWith('## ')) {
return Boolean(line.match(/##\s\(\d{4}-\d{2}-\d{2}\)/));
return Boolean(line.match(/^##\s\(\d{4}-\d{2}-\d{2}\)/));
}

return true;
Expand Down Expand Up @@ -61,6 +61,7 @@ class ResolveChangelogController extends Controller {
updateChangelogContent(text) {
const actions = [
this.clearConflicts,
this.normalizeEmptyLines,
this.saveBoilerplate,
this.sortRecords,
this.returnBoilerplate
Expand Down Expand Up @@ -120,6 +121,26 @@ class ResolveChangelogController extends Controller {
.join('\n');
}

/**
* Replaces all lines consisting only of spaces with empty line
*
* @param {string} text
*
* @returns {string}
*/
normalizeEmptyLines(text) {
return text
.split('\n')
.map((line) => {
if (line.match(/^\s+$/)) {
return '';
}

return line;
})
.join('\n');
}

/**
* Sort records by dates
*
Expand All @@ -128,7 +149,7 @@ class ResolveChangelogController extends Controller {
* @returns {string}
*/
sortRecords(text) {
const records = text.split(this.divider).map((el, index) => {
let records = text.split(this.divider).map((el, index) => {
let elementWithNewLines = el;

if (index !== 0) {
Expand All @@ -142,6 +163,8 @@ class ResolveChangelogController extends Controller {

records.sort((a, b) => new Date(b.slice(0, 10)) - new Date(a.slice(0, 10)));

records = [...new Set(records)];

// Last element after sort should have only one \n
records[records.length - 1] = records[records.length - 1].slice(
0,
Expand Down
10 changes: 10 additions & 0 deletions tests/cases/resolve-changelog/complex.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,17 @@ ${startOfConflict}
* bar
>>>>>>> master
## (2021-06-11) @baz
#### :boom: Breaking Change
* boom
#### :rocket: New Feature
* rocket
## (2021-06-11) @baz
#### :boom: Breaking Change
Expand Down
25 changes: 25 additions & 0 deletions tests/cases/resolve-changelog/normalizeEmptyLines.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const emptyLines = `
foo
bar
`;

const emptyLinesResult = `
foo
bar
`;

module.exports = {
cases: [
{
description: 'Normalize empty lines',
input: emptyLines,
output: emptyLinesResult
}
]
};
45 changes: 45 additions & 0 deletions tests/cases/resolve-changelog/sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,57 @@ const sortOutput = `## (2021-06-11) @baz
* bar
`;

const sortDupsInput = `## (2021-05-12) @foo
#### :rocket: New Feature
* bar
## (2021-05-12) @foo
#### :rocket: New Feature
* bar
## (2021-06-11) @baz
#### :boom: Breaking Change
* boom
#### :rocket: New Feature
* rocket
`;

const sortDupsOutput = `## (2021-06-11) @baz
#### :boom: Breaking Change
* boom
#### :rocket: New Feature
* rocket
## (2021-05-12) @foo
#### :rocket: New Feature
* bar
`;

module.exports = {
cases: [
{
description: 'Sort of records',
input: sortInput,
output: sortOutput
},
{
description: 'Remove dups',
input: sortDupsInput,
output: sortDupsOutput
}
]
};
11 changes: 11 additions & 0 deletions tests/resolve-changelog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const complex = require('./cases/resolve-changelog/complex');
const boilerplate = require('./cases/resolve-changelog/boilerplate');
const sort = require('./cases/resolve-changelog/sort');
const conflicts = require('./cases/resolve-changelog/conflicts');
const emptyLines = require('./cases/resolve-changelog/normalizeEmptyLines');

const ResolveChangelogController = require('../src/controllers/resolve-changelog');

Expand Down Expand Up @@ -47,4 +48,14 @@ describe('Resolve-changelog controller methods', () => {
});
});
});

describe('normalizeEmptyLines', () => {
emptyLines.cases.forEach((caseEl) => {
it(caseEl.description, () => {
expect(
new ResolveChangelogController().normalizeEmptyLines(caseEl.input)
).to.equal(caseEl.output);
});
});
});
});

0 comments on commit 6326d9f

Please sign in to comment.