Skip to content

Commit c0c4d7b

Browse files
committed
Add release script
1 parent db77eda commit c0c4d7b

File tree

5 files changed

+928
-41
lines changed

5 files changed

+928
-41
lines changed

.release-it.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
scripts:
2+
beforeStage: yarn update-changelog
3+
git:
4+
tagName: 'v${version}'
5+
tagAnnotation: 'v${version}'
6+
commitMessage: 'v${version}'
7+
npm:
8+
publish: true

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
"scripts": {
1212
"start": "tsdx watch",
1313
"build": "tsdx build",
14-
"test": "tsdx test --env=jsdom"
14+
"test": "tsdx test --env=jsdom",
15+
"update-changelog": "node ./scripts/update-changelog",
16+
"release": "release-it"
1517
},
1618
"peerDependencies": {
1719
"react": "^16.8.0"
@@ -32,6 +34,7 @@
3234
"pretty-quick": "^1.10.0",
3335
"react": "^16.8.6",
3436
"react-dom": "^16.8.6",
37+
"release-it": "^12.2.0",
3538
"tsdx": "^0.5.9",
3639
"tslib": "^1.9.3",
3740
"typescript": "^3.4.5"

scripts/.eslintrc.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"parserOptions": {
3+
"sourceType": "script"
4+
},
5+
"env": {
6+
"browser": false,
7+
"jest": false
8+
},
9+
"rules": {
10+
"@typescript-eslint/no-var-requires": "off"
11+
}
12+
}

scripts/update-changelog.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require('fs')
4+
const { promisify } = require('util')
5+
6+
const readFile = promisify(fs.readFile)
7+
const writeFile = promisify(fs.writeFile)
8+
9+
const CHANGELOG_FILENAME = 'CHANGELOG.md'
10+
const UNRELEASED_SECTION = '## [Unreleased]'
11+
12+
const getVersion = () => {
13+
const package = require('../package.json')
14+
15+
return package.version
16+
}
17+
18+
const update = async () => {
19+
const changelog = (await readFile(CHANGELOG_FILENAME)).toString()
20+
21+
const unreleasedSectionIndex = changelog.indexOf(UNRELEASED_SECTION)
22+
const headerLength = unreleasedSectionIndex + UNRELEASED_SECTION.length + 1
23+
24+
const header = changelog.slice(0, headerLength)
25+
26+
const body = changelog.slice(headerLength)
27+
const now = new Date()
28+
29+
const year = now.getFullYear()
30+
const month = (now.getUTCMonth() + 1).toString().padStart(2, '0')
31+
const day = now
32+
.getUTCDate()
33+
.toString()
34+
.padStart(2, '0')
35+
36+
const newChangelog = `
37+
${header}
38+
## [${getVersion()}] - ${year}-${month}-${day}
39+
${body}
40+
`.trim()
41+
42+
await writeFile(CHANGELOG_FILENAME, newChangelog + '\n')
43+
}
44+
45+
update()

0 commit comments

Comments
 (0)