Skip to content
This repository has been archived by the owner on Jun 16, 2023. It is now read-only.

Commit

Permalink
feat(changelog): add changelog script
Browse files Browse the repository at this point in the history
  • Loading branch information
jgfidelis committed Feb 14, 2018
1 parent 5e774f4 commit d226393
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
33 changes: 33 additions & 0 deletions changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env node

const git = require('simple-git');
const changelog = require('generate-changelog');
const fs = require('fs');
const idx = require('idx');
const argv = require('minimist')(process.argv.slice(1));

git().tags((err, tags) => {
const currentChangelog = fs.readFileSync('./CHANGELOG.md');
const matched = tags.latest.match(/v\d+.\d+.\d+-(\d+)/);
const build = (idx(matched, _ => Number(_[1])) || 0) + 1;

changelog
.generate({
major: argv.major,
minor: argv.minor,
patch: argv.patch,
})
.then(function(changelog) {
const rxVersion = /\d+\.\d+\.\d+/;
const newVersion = argv.version || idx(changelog.match(rxVersion), _ => _[0]) + `-${build}`;

changelog = changelog.replace(rxVersion, newVersion) + currentChangelog;
fs.writeFileSync('./CHANGELOG.md', changelog);

const addFile = c => git().add('CHANGELOG.md', c);
const commit = c => git().commit(`build(change-log): v${newVersion}`, c);
const addTag = c => git().addAnnotatedTag(`v${newVersion}`, `build(tag): v${newVersion}`, c);

addFile(() => commit(() => addTag()));
});
});
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
"husky": "^0.14.3",
"lint-staged": "^5.0.0",
"pre-commit": "^1.2.2",
"prettier": "^1.9.2"
"prettier": "^1.9.2",
"generate-changelog": "1.7.0",
"simple-git": "1.89.0",
"idx": "2.2.0",
"minimist": "1.2.0"
},
"homepage": "https://github.com/react-native-community/react-native-camera",
"keywords": [
Expand Down
28 changes: 27 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ balanced-match@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"

bluebird@^3.0.6:
version "3.5.1"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.1.tgz#d9551f9de98f1fcda1e683d17ee91a0602ee2eb9"

brace-expansion@^1.1.7:
version "1.1.8"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.8.tgz#c07b211c7c952ec1f8efd51a77ef0d1d3990a292"
Expand Down Expand Up @@ -856,6 +860,14 @@ functional-red-black-tree@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz#1b0ab3bd553b2a0d6399d29c0e3ea0b252078327"

[email protected]:
version "1.7.0"
resolved "https://registry.yarnpkg.com/generate-changelog/-/generate-changelog-1.7.0.tgz#e6321226207d5cbcfe24de39d7ffd65d51698596"
dependencies:
bluebird "^3.0.6"
commander "^2.9.0"
github-url-from-git "^1.4.0"

get-own-enumerable-property-symbols@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/get-own-enumerable-property-symbols/-/get-own-enumerable-property-symbols-2.0.1.tgz#5c4ad87f2834c4b9b4e84549dc1e0650fb38c24b"
Expand All @@ -882,6 +894,10 @@ git-raw-commits@^1.3.0:
split2 "^2.0.0"
through2 "^2.0.0"

github-url-from-git@^1.4.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/github-url-from-git/-/github-url-from-git-1.5.0.tgz#f985fedcc0a9aa579dc88d7aff068d55cc6251a0"

glob@^7.0.3, glob@^7.0.5, glob@^7.1.2:
version "7.1.2"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15"
Expand Down Expand Up @@ -954,6 +970,10 @@ iconv-lite@^0.4.17, iconv-lite@~0.4.13:
version "0.4.19"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.19.tgz#f7468f60135f5e5dad3399c0a81be9a1603a082b"

[email protected]:
version "2.2.0"
resolved "https://registry.yarnpkg.com/idx/-/idx-2.2.0.tgz#8544749f9faba6409822b5d9488ba5bc77b8fbfe"

ignore@^3.3.3:
version "3.3.7"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.7.tgz#612289bfb3c220e186a58118618d5be8c1bab021"
Expand Down Expand Up @@ -1439,7 +1459,7 @@ [email protected]:
version "0.0.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"

minimist@^1.1.3:
minimist@1.2.0, minimist@^1.1.3:
version "1.2.0"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"

Expand Down Expand Up @@ -1897,6 +1917,12 @@ signal-exit@^3.0.0, signal-exit@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"

[email protected]:
version "1.89.0"
resolved "https://registry.yarnpkg.com/simple-git/-/simple-git-1.89.0.tgz#ef52fe734d5060566ce187b2bbace36c2323e34c"
dependencies:
debug "^3.1.0"

[email protected]:
version "0.0.4"
resolved "https://registry.yarnpkg.com/slice-ansi/-/slice-ansi-0.0.4.tgz#edbf8903f66f7ce2f8eafd6ceed65e264c831b35"
Expand Down

0 comments on commit d226393

Please sign in to comment.