Skip to content

Commit

Permalink
build(release): changelog fixes and updating scssVariables
Browse files Browse the repository at this point in the history
Not really sure why the config doesn't work when using my custom preset
with lerna.
  • Loading branch information
mlaursen committed Feb 28, 2021
1 parent 1065688 commit e5b8dba
Show file tree
Hide file tree
Showing 10 changed files with 337 additions and 102 deletions.
218 changes: 194 additions & 24 deletions changelog.config.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,203 @@
const { createConfig } = require('@mlaursen/changelog-preset/createConfig');
const { readFileSync } = require('fs');
const { resolve } = require('path');

const { tokens, packages } = require('./changelogData');

const PACKAGE_REGEXP = new RegExp(`${packages.join('|')}`);

module.exports = createConfig({
tokens,
getCommitScope({ scope }) {
if (PACKAGE_REGEXP.test(scope)) {
return `@react-md/${scope}`;
const GROUPS = [
'Bug Fixes',
'Features',
'Documentation',
'Performance Improvements',
'Other Internal Changes',
];

function getCommitType({ type, scope, revert }) {
if (type === 'revert' || revert) {
return 'Reverts';
}

if (scope === 'docs') {
return 'Documentation';
}

switch (type) {
case 'feat':
return 'Features';
case 'fix':
case 'bugfix':
return 'Bug Fixes';
case 'perf':
return 'Performance Improvements';
case 'docs':
return 'Documentation';
default:
return 'Other Internal Changes';
}
}

function getCommitScope({ scope }) {
if (PACKAGE_REGEXP.test(scope)) {
return `@react-md/${scope}`;
}

switch (scope) {
// these are mostly to create the initial changelog
case 'docs':
case 'pages':
case 'sassdoc':
case 'sandbox':
case 'demos':
case 'blog':
case 'indexer':
case 'guides':
return 'react-md.dev';
case 'slider':
return '@react-md/form';
case 'grid':
return '@react-md/utils';
default:
return scope || '';
}
}

const TOKEN_REGEXP = new RegExp(
`(?<=\\s|^)(${tokens.join('|')})(?=\\s|$)`,
'g'
);

function tokenize(subject) {
return subject
.replace(TOKEN_REGEXP, '`$1`')
.replace(/([a-z][A-z]+Props)/g, '`$1`');
}

const parserOpts = {
headerPattern: /^(\w*)(?:\((.*)\))?: (.*)$/,
headerCorrespondence: ['type', 'scope', 'subject'],
noteKeywords: ['BREAKING CHANGE'],
revertPattern: /^(?:Revert|revert:)\s"?([\s\S]+?)"?\s*This reverts commit (\w*)\./i,
revertCorrespondence: ['header', 'hash'],
};

const writerOpts = {
transform: (commit, context) => {
// don't want to show the release tag in changelog
if (commit.scope === 'release') {
return;
}

const issues = [];
let isBreaking = false;
commit.notes.forEach((note) => {
isBreaking = false;
note.title = 'BREAKING CHANGES';
});

commit.type = getCommitType(commit);
commit.scope = getCommitScope(commit);
if (!isBreaking && (!commit.type || commit.scope.includes('deps'))) {
// don't include un-typed commits in changelogs or deps
return;
}

if (typeof commit.hash === 'string') {
commit.shortHash = commit.hash.substring(0, 7);
}

switch (scope) {
// these are mostly to create the initial changelog
case 'docs':
case 'pages':
case 'sassdoc':
case 'sandbox':
case 'demos':
case 'blog':
case 'indexer':
case 'guides':
return 'react-md.dev';
case 'slider':
return '@react-md/form';
case 'grid':
return '@react-md/utils';
default:
return scope || '';
if (typeof commit.subject === 'string') {
let url = context.repository
? `${context.host}/${context.owner}/${context.repository}`
: context.repoUrl;

if (url) {
url = `${url}/issues/`;
commit.subject = commit.subject.replace(/#([0-9]+)/g, (_, issue) => {
issues.push(issue);
return `[#${issue}](${url}${issue})`;
});
}

commit.subject = tokenize(commit.subject);
}

// remove references that already appear in the subject
commit.references = commit.references.filter(
(reference) => !issues.includes(reference.issue)
);

return commit;
},
groupBy: 'type',
commitGroupsSort: function (a, b) {
const aIndex = GROUPS.indexOf(a.title);
const bIndex = GROUPS.indexOf(b.title);
if (aIndex !== -1 && bIndex !== -1) {
return aIndex - bIndex;
}

return a.title.localeCompare(b.title);
},
commitsSort: ['scope', 'subject'],
noteGroupsSort: 'title',
mainTemplate: readFileSync(
resolve(__dirname, './templates/template.hbs'),
'utf-8'
),
headerPartial: readFileSync(
resolve(__dirname, './templates/header.hbs'),
'utf-8'
),
commitPartial: readFileSync(
resolve(__dirname, './templates/commit.hbs'),
'utf-8'
),
footerPartial: readFileSync(
resolve(__dirname, './templates/footer.hbs'),
'utf-8'
),
};

/**
* This is basically the conventional-changelog-angular with a few changes to
* allow more commit messages to appear. I also "tokenize" known packages and
* exports from react-md in the changelogs.
*/
module.exports = {
parserOpts,
writerOpts,
conventionalChangelog: {
writerOpts,
parserOpts,
},
recommendedBumpOpts: {
config: {
parserOpts,
writerOpts,
},

whatBump: (commits) => {
let level = 2;
let breaking = 0;
let features = 0;
commits.forEach((commit) => {
if (commit.notes.length > 0) {
breaking += commit.notes.length;
level = 0;
} else if (commit.type === 'feat') {
features += 1;
if (level === 2) {
level = 1;
}
}
});

const verb = breaking === 1 ? 'is' : 'are';
return {
level,
reason: `There ${verb} ${breaking} BREAKING CHANGES and ${features} features`,
};
},
},
});
};
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"**/*.md"
],
"changelogPreset": {
"name": "@mlaursen/changelog-preset"
"name": "./changelog.config.js"
},
"useWorkspaces": true,
"npmClient": "yarn",
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@
"homepage": "https://react-md.dev",
"devDependencies": {
"@babel/plugin-transform-typescript": "^7.12.13",
"@mlaursen/changelog-preset": "^1.0.0",
"@mlaursen/eslint-config": "^1.1.1",
"@mlaursen/eslint-config": "^1.1.2",
"@testing-library/dom": "^7.29.4",
"@testing-library/jest-dom": "^5.11.9",
"@testing-library/react": "^11.2.5",
Expand Down
16 changes: 15 additions & 1 deletion packages/dev-utils/src/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import { changelogData } from "./changelogData";
import { clean } from "./clean";
import { projectRoot } from "./constants";
import { libsize } from "./libsize";
import { getLernaVersion, git, replaceTag, run } from "./utils";
import {
getLernaVersion,
git,
replaceTag,
run,
uncommittedFiles,
} from "./utils";
import { initBlog } from "./utils/initBlog";
import { variables } from "./variables";

Expand Down Expand Up @@ -108,6 +114,11 @@ A token can be created at:
// the variables from the react-md package
run("yarn build");

const updatedVariables = uncommittedFiles();
if (updatedVariables) {
git("stash");
}

await changelogData();
run(`npx lerna version ${type} --no-push${yes}`);
const changelog = await initBlog();
Expand All @@ -122,6 +133,9 @@ A token can be created at:
});

git("add themes");
if (updatedVariables) {
git("stash pop");
}

if (blog) {
log.info("Update the blog...");
Expand Down
4 changes: 2 additions & 2 deletions packages/sheet/src/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ $rmd-sheet-dark-background-color: if(
$rmd-sheet-background-color: if(
$rmd-theme-light,
$rmd-sheet-light-background-color,
$rmd-theme-dark-background-color
$rmd-sheet-dark-background-color
) !default;

/// The background color for a sheet raised above other content in the light
Expand Down Expand Up @@ -146,7 +146,7 @@ $rmd-sheet-raised-dark-background-color: if(
$rmd-sheet-raised-background-color: if(
$rmd-theme-light,
$rmd-sheet-raised-light-background-color,
$rmd-theme-raised-dark-background-color
$rmd-sheet-raised-dark-background-color
) !default;

/// The duration for the enter transition.
Expand Down
61 changes: 61 additions & 0 deletions templates/commit.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
*{{#if scope}} **{{scope}}:**
{{~/if}} {{#if subject}}
{{~subject}}
{{~else}}
{{~header}}
{{~/if}}

{{~!-- commit link --}} {{#if @root.linkReferences~}}
([{{shortHash}}](
{{~#if @root.repository}}
{{~#if @root.host}}
{{~@root.host}}/
{{~/if}}
{{~#if @root.owner}}
{{~@root.owner}}/
{{~/if}}
{{~@root.repository}}
{{~else}}
{{~@root.repoUrl}}
{{~/if}}/
{{~@root.commit}}/{{hash}}))
{{~else}}
{{~shortHash}}
{{~/if}}

{{~!-- commit references --}}
{{~#if references~}}
, closes
{{~#each references}} {{#if @root.linkReferences~}}
[
{{~#if this.owner}}
{{~this.owner}}/
{{~/if}}
{{~this.repository}}#{{this.issue}}](
{{~#if @root.repository}}
{{~#if @root.host}}
{{~@root.host}}/
{{~/if}}
{{~#if this.repository}}
{{~#if this.owner}}
{{~this.owner}}/
{{~/if}}
{{~this.repository}}
{{~else}}
{{~#if @root.owner}}
{{~@root.owner}}/
{{~/if}}
{{~@root.repository}}
{{~/if}}
{{~else}}
{{~@root.repoUrl}}
{{~/if}}/
{{~@root.issue}}/{{this.issue}})
{{~else}}
{{~#if this.owner}}
{{~this.owner}}/
{{~/if}}
{{~this.repository}}#{{this.issue}}
{{~/if}}{{/each}}
{{~/if}}

12 changes: 12 additions & 0 deletions templates/footer.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{#if noteGroups}}
{{#each noteGroups}}

### {{title}}

{{#each notes}}
* {{#if commit.scope}}**{{commit.scope}}:** {{/if}}{{text}}
{{/each}}
{{/each}}

{{/if}}

Loading

0 comments on commit e5b8dba

Please sign in to comment.