Skip to content

Commit

Permalink
✨ Implement format option
Browse files Browse the repository at this point in the history
  • Loading branch information
frinyvonnick committed Aug 30, 2018
1 parent 0e65018 commit 806ce07
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"hash":"0e650182544bd4e16cccbdd42e6f1e36b320095c","date":"2018-08-30T10:35:17+02:00","subject":"Merge branch 'master' into refactor/remove-babel","body":""},{"hash":"802c0f7dc29508876c6b4d178bbcc8274ee308b5","date":"2018-08-29T14:42:42+02:00","subject":":green_heart: Ignore node_modules in linter","body":""},{"hash":"32e0d943c2b4d06b610b17748486d3cc1e4f3a5a","date":"2018-08-28T20:59:50+02:00","subject":":wrench: missing package.json to update","body":""},{"hash":"4df1b8c92e04902698e13041664642ae16c4c3b4","date":"2018-08-28T19:49:30+02:00","subject":":sparkles: add 'use strict'","body":""},{"hash":"dfe9aa9ebaca0003f2a403fee8bdd8d612512dee","date":"2018-08-28T19:48:51+02:00","subject":":fire: remove bad property in package.json","body":""},{"hash":"e93603e071062aac50a126f85121e5ee6ff427aa","date":"2018-08-28T19:37:41+02:00","subject":":wrench: add engines attribute to node 10 in package.json","body":""},{"hash":"1213a06adf517cf57867a1d7c380c5c2e1936b67","date":"2018-08-28T19:36:31+02:00","subject":":recycle: refactor code to native node 10","body":""},{"hash":"379d1854991d4d974a50179f6b72a7e83fa674f9","date":"2018-08-28T19:32:56+02:00","subject":":wrench: remove .babelrc and change eslint to remove babel parser","body":""},{"hash":"f3a2a5cff11d4e0835ae74e70b74acdd8379347b","date":"2018-08-28T19:31:20+02:00","subject":":heavy_minus_sign: remove babel dependencies","body":""},{"hash":"b165f695f4c1a49ff16a5f03918545bfb36cf367","date":"2018-08-28T16:54:26+02:00","subject":":sparkles: Convert changelog to markdown","body":""},{"hash":"10c6d3e20b82f5a0f6ce5cd372899e6519bc2412","date":"2018-08-28T16:09:52+02:00","subject":":sparkles: Generate markdown first draft function","body":""},{"hash":"a4a12bb4f7133e7e5e40436da4c884f135abf03d","date":"2018-08-28T15:51:52+02:00","subject":":tada: Intialize markdown project","body":""},{"hash":"86ca3eaefb18fd9c9b6bb4256ed2f6fa711aef59","date":"2018-08-28T15:45:31+02:00","subject":":sparkles: Generate changelog JSON file","body":""},{"hash":"c912efd73b9b286711d468ccb73bf1a03bd6f848","date":"2018-08-28T15:28:30+02:00","subject":":sparkles: Handle when no repository found","body":""},{"hash":"a1526b38e164b8471954e3dd0c658e10595ee966","date":"2018-08-28T15:07:19+02:00","subject":":package: Fix build","body":""},{"hash":"acba6f776196d8312c470ccefce8be81bafd8d52","date":"2018-08-28T14:57:33+02:00","subject":":package: Build dist file","body":""},{"hash":"73207b70d85ad2371def0ec9045e5a6ea46fee8c","date":"2018-08-28T14:56:10+02:00","subject":":fire: remove parsing multiple commit","body":""},{"hash":"0b4f39408e675f368c9562bd7645ac74abcd2293","date":"2018-08-28T14:33:10+02:00","subject":":tada: intialize cli project","body":""},{"hash":"44e401db08cc828fcc8c19b027350ac9d310773e","date":"2018-08-28T14:24:08+02:00","subject":":sparkles: implements changelog generation to json","body":""},{"hash":"e29f239dee8dc393caee9d320371e54a37eb90ae","date":"2018-08-28T11:17:18+02:00","subject":":truck: move parse functions into parser.js","body":""},{"hash":"cb35644a640cfe3cb2c246345fe25202d814c436","date":"2018-08-28T11:14:04+02:00","subject":":sparkles: add edge cases for commit parsing","body":""},{"hash":"195b59431dde83a4cff26be5c3ab362d97a9604e","date":"2018-08-28T10:48:18+02:00","subject":":sparkles: Implements parse commit function","body":""},{"hash":"7f091a3900605ee9bc44e793ddbb10a7272112fa","date":"2018-08-21T17:05:39+02:00","subject":":wrench: Fix main script in core module","body":""},{"hash":"efbc04d902ac201b128a8e02692b778eff109b12","date":"2018-08-21T17:01:31+02:00","subject":":wrench: Add build script","body":""},{"hash":"9faf008d457d777afe0fa3443c34af510c1098fa","date":"2018-08-21T16:21:56+02:00","subject":":wrench: Add lint","body":""},{"hash":"dda9b287989c1ca2e9513c4a5a4a3d1b6749e816","date":"2018-08-21T15:28:38+02:00","subject":":green_heart: Set up travis configuration","body":""},{"hash":"656c8bbb506fc8f9064df1fc7aa64e2f1869751e","date":"2018-08-21T15:21:01+02:00","subject":":wrench: Set up tests","body":""},{"hash":"34c8f53a58487a6368016de09989465cd2a96786","date":"2018-08-21T11:41:57+02:00","subject":":wrench: Add package.json","body":""},{"hash":"a60d98def5bcbbef74a19db9e8f43af7a6ff6865","date":"2018-08-21T11:37:12+02:00","subject":"Initial commit","body":""}]
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

- Merge branch 'master' into refactor/remove-babel (0e650182544bd4e16cccbdd42e6f1e36b320095c)
- :green_heart: Ignore node_modules in linter (802c0f7dc29508876c6b4d178bbcc8274ee308b5)
- :wrench: missing package.json to update (32e0d943c2b4d06b610b17748486d3cc1e4f3a5a)
- :sparkles: add 'use strict' (4df1b8c92e04902698e13041664642ae16c4c3b4)
- :fire: remove bad property in package.json (dfe9aa9ebaca0003f2a403fee8bdd8d612512dee)
- :wrench: add engines attribute to node 10 in package.json (e93603e071062aac50a126f85121e5ee6ff427aa)
- :recycle: refactor code to native node 10 (1213a06adf517cf57867a1d7c380c5c2e1936b67)
- :wrench: remove .babelrc and change eslint to remove babel parser (379d1854991d4d974a50179f6b72a7e83fa674f9)
- :heavy_minus_sign: remove babel dependencies (f3a2a5cff11d4e0835ae74e70b74acdd8379347b)
- :sparkles: Convert changelog to markdown (b165f695f4c1a49ff16a5f03918545bfb36cf367)
- :sparkles: Generate markdown first draft function (10c6d3e20b82f5a0f6ce5cd372899e6519bc2412)
- :tada: Intialize markdown project (a4a12bb4f7133e7e5e40436da4c884f135abf03d)
- :sparkles: Generate changelog JSON file (86ca3eaefb18fd9c9b6bb4256ed2f6fa711aef59)
Expand Down
3 changes: 2 additions & 1 deletion packages/gitmoji-changelog-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"homepage": "https://github.com/frinyvonnick/gitmoji-changelog#readme",
"dependencies": {
"@gitmoji-changelog/core": "0.0.1",
"@gitmoji-changelog/markdown": "0.0.1"
"@gitmoji-changelog/markdown": "0.0.1",
"yargs": "^12.0.1"
}
}
23 changes: 23 additions & 0 deletions packages/gitmoji-changelog-cli/src/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const { changelog } = require('@gitmoji-changelog/core')
const { convert } = require('@gitmoji-changelog/markdown')
const fs = require('fs')

async function main({ format } = {}) {
try {
const changes = await changelog()

switch (format) {
case 'json':
fs.writeFileSync('./CHANGELOG.json', changes)
break;
case 'markdown':
default: {
fs.writeFileSync('./CHANGELOG.md', convert(changes))
}
}
} catch (e) {
console.error('Cannot find a git repository in current path.')
}
}

module.exports = { main }
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const { changelog } = require('@gitmoji-changelog/core');
const { main } = require('./index');
const { main } = require('./cli');

console.error = jest.fn()

describe('cli', () => {
it('should throw an error if not a git project', () => {
it('should throw an error if not a git project', async () => {
changelog.mockImplementationOnce(() => {
throw new Error()
})

main()
await main()

expect(console.error).toHaveBeenCalledWith('Cannot find a git repository in current path.')
})
Expand Down
33 changes: 13 additions & 20 deletions packages/gitmoji-changelog-cli/src/index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
#! /usr/bin/env node

'use strict'

const fs = require('fs')
const { changelog } = require('@gitmoji-changelog/core')
const { convert } = require('@gitmoji-changelog/markdown')

async function main() {
try {
const changes = await changelog()
fs.writeFileSync('./CHANGELOG.md', convert(changes))
} catch (e) {
console.error('Cannot find a git repository in current path.')
}
}

main()

module.exports = {
main,
}
const yargs = require('yargs')
const { main } = require('./cli')

const args = yargs
.option('format', {
alias: 'f',
default: 'markdown',
description: 'changelog output format',
choices: ['json', 'markdown'],
})
.parse()

main(args)
13 changes: 13 additions & 0 deletions packages/gitmoji-changelog-markdown/dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.convert = convert;
function convert(json) {
const commits = JSON.parse(json);

return commits.reduce((markdown, commit) => {
return `${markdown}- ${commit.subject} (${commit.hash})\n`;
}, '# Changelog\n\n');
}
66 changes: 66 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,12 @@ decamelize@^1.0.0, decamelize@^1.1.0, decamelize@^1.1.1, decamelize@^1.1.2:
version "1.2.0"
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290"

decamelize@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-2.0.0.tgz#656d7bbc8094c4c788ea53c5840908c9c7d063c7"
dependencies:
xregexp "4.0.0"

decode-uri-component@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.0.tgz#eb3913333458775cb84cd1a1fae062106bb87545"
Expand Down Expand Up @@ -1424,6 +1430,12 @@ find-up@^2.0.0, find-up@^2.1.0:
dependencies:
locate-path "^2.0.0"

find-up@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/find-up/-/find-up-3.0.0.tgz#49169f1d7993430646da61ecc5ae355c21c97b73"
dependencies:
locate-path "^3.0.0"

flat-cache@^1.2.1:
version "1.3.0"
resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-1.3.0.tgz#d3030b32b38154f4e3b7e9c709f490f7ef97c481"
Expand Down Expand Up @@ -2706,6 +2718,13 @@ locate-path@^2.0.0:
p-locate "^2.0.0"
path-exists "^3.0.0"

locate-path@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-3.0.0.tgz#dbec3b3ab759758071b58fe59fc41871af21400e"
dependencies:
p-locate "^3.0.0"
path-exists "^3.0.0"

lodash._reinterpolate@~3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d"
Expand Down Expand Up @@ -3206,16 +3225,32 @@ p-limit@^1.1.0:
dependencies:
p-try "^1.0.0"

p-limit@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-2.0.0.tgz#e624ed54ee8c460a778b3c9f3670496ff8a57aec"
dependencies:
p-try "^2.0.0"

p-locate@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-2.0.0.tgz#20a0103b222a70c8fd39cc2e580680f3dde5ec43"
dependencies:
p-limit "^1.1.0"

p-locate@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-3.0.0.tgz#322d69a05c0264b25997d9f40cd8a891ab0064a4"
dependencies:
p-limit "^2.0.0"

p-try@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/p-try/-/p-try-1.0.0.tgz#cbc79cdbaf8fd4228e13f621f2b1a237c1b207b3"

p-try@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/p-try/-/p-try-2.0.0.tgz#85080bb87c64688fa47996fe8f7dfbe8211760b1"

package-json@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/package-json/-/package-json-4.0.1.tgz#8869a0401253661c4c4ca3da6c2121ed555f5eed"
Expand Down Expand Up @@ -4435,6 +4470,10 @@ xml-name-validator@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-3.0.0.tgz#6ae73e06de4d8c6e47f9fb181f78d648ad457c6a"

[email protected]:
version "4.0.0"
resolved "https://registry.yarnpkg.com/xregexp/-/xregexp-4.0.0.tgz#e698189de49dd2a18cc5687b05e17c8e43943020"

xtend@~4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af"
Expand All @@ -4443,6 +4482,10 @@ y18n@^3.2.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/y18n/-/y18n-3.2.1.tgz#6d15fba884c08679c0d77e88e7759e811e07fa41"

"y18n@^3.2.1 || ^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.0.tgz#95ef94f85ecc81d007c264e190a120f0a3c8566b"

yallist@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/yallist/-/yallist-2.1.2.tgz#1c11f9218f076089a47dd512f93c6699a6a81d52"
Expand All @@ -4451,6 +4494,12 @@ yallist@^3.0.0, yallist@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.0.2.tgz#8452b4bb7e83c7c188d8041c1a837c773d6d8bb9"

yargs-parser@^10.1.0:
version "10.1.0"
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-10.1.0.tgz#7202265b89f7e9e9f2e5765e0fe735a905edbaa8"
dependencies:
camelcase "^4.1.0"

yargs-parser@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-7.0.0.tgz#8d0ac42f16ea55debd332caf4c4038b3e3f5dfd9"
Expand Down Expand Up @@ -4480,6 +4529,23 @@ yargs@^11.0.0:
y18n "^3.2.1"
yargs-parser "^9.0.2"

yargs@^12.0.1:
version "12.0.1"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-12.0.1.tgz#6432e56123bb4e7c3562115401e98374060261c2"
dependencies:
cliui "^4.0.0"
decamelize "^2.0.0"
find-up "^3.0.0"
get-caller-file "^1.0.1"
os-locale "^2.0.0"
require-directory "^2.1.1"
require-main-filename "^1.0.1"
set-blocking "^2.0.0"
string-width "^2.0.0"
which-module "^2.0.0"
y18n "^3.2.1 || ^4.0.0"
yargs-parser "^10.1.0"

yargs@^8.0.2:
version "8.0.2"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-8.0.2.tgz#6299a9055b1cefc969ff7e79c1d918dceb22c360"
Expand Down

0 comments on commit 806ce07

Please sign in to comment.