forked from channel-io/bezier-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bezier-icons): add changeset generating job to workflow
- Loading branch information
1 parent
18e9213
commit bc9cb03
Showing
3 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const { exec } = require('child_process') | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
const { getChangeLog } = require('./utils/getChangeLog') | ||
|
||
const changesetPath = path.resolve(__dirname, `../../../.changeset/icon-update-${new Date().valueOf()}.md`) | ||
|
||
exec('git log -1 --name-status --pretty="format:"', async (_undefined, stdout) => { | ||
fs.writeFileSync(changesetPath, getChangeLog(stdout), 'utf-8') | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const statusByKey = { | ||
M: '**CHANGE**', | ||
A: '**ADD**', | ||
D: '**DELETE**', | ||
} | ||
|
||
const getIconName = (path) => path.split('/').at(-1) | ||
|
||
const getIconChangeLog = (iconsByStatus) => { | ||
let res = '' | ||
|
||
for (const [key, icons] of Object.entries(iconsByStatus)) { | ||
res += statusByKey[key] | ||
res += '\n\n' | ||
res += icons.map(icon => `- ${icon}`).join('\n') | ||
res += '\n\n' | ||
} | ||
|
||
return res | ||
} | ||
|
||
const getIconNamesByStatus = (gitLog) => gitLog | ||
.trim() | ||
.split('\n') | ||
.map(line => line.split('\t')) | ||
.filter(line => line[1].endsWith('.svg')) | ||
.reduce((acc, cur) => { | ||
const [key, file] = cur | ||
const icon = getIconName(file) | ||
|
||
if (!icon) { return acc } | ||
|
||
if (!acc[key]) { | ||
acc[key] = [icon] | ||
} else { | ||
acc[key].push(icon) | ||
} | ||
return acc | ||
}, {}) | ||
|
||
const getChangeLog = (gitLog) => { | ||
const iconsByStatus = getIconNamesByStatus(gitLog) | ||
|
||
let description = | ||
`--- | ||
"@channel.io/bezier-icons": minor | ||
--- | ||
Update icons | ||
` | ||
|
||
description += getIconChangeLog(iconsByStatus) | ||
|
||
return description.trim() | ||
} | ||
|
||
module.exports = { | ||
getChangeLog, | ||
} |