Skip to content

Commit 77917c3

Browse files
committed
hotfix for cli help/usage
should now work in directories w/o `package.json` or `CHANGELOG.md`
1 parent a3a5d4f commit 77917c3

File tree

3 files changed

+32
-14
lines changed

3 files changed

+32
-14
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# gh-release changelog
22

3+
## 1.0.5 - 2015-02-08
4+
* hotfix for help/usage in dir w/o `package.json` or `CHANGELOG.md`
5+
36
## 1.0.4 - 2015-02-07
47
* remove `files` from `package.json` to fix cli again
58

get-defaults.js

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,43 @@
11
var fs = require('fs')
22
var path = require('path')
3-
var pkg = require(path.resolve(process.cwd(), 'package.json'))
3+
var pkg = { version: null }
4+
var log = {
5+
version: null,
6+
body: null
7+
}
8+
var owner = null
9+
var repo = null
10+
var version = null
411

512
module.exports = function getDefaults () {
6-
var repoPath = pkg.repository.url.split('github.com/')[1].split('/')
7-
var owner = repoPath[0]
8-
var repo = repoPath[1].split('.git')[0]
9-
var logPath = path.resolve(process.cwd(), 'CHANGELOG.md')
10-
var log = fs.readFileSync(logPath, { encoding: 'utf-8' })
11-
var logVersion = log.split('## ')[1].split('\n')[0].split(' ')[0]
13+
try {
14+
pkg = require(path.resolve(process.cwd(), 'package.json'))
15+
var repoPath = pkg.repository.url.split('github.com/')[1].split('/')
16+
owner = repoPath[0]
17+
repo = repoPath[1].split('.git')[0]
18+
} catch (e) {}
1219

13-
if (logVersion.indexOf('v') === 0) logVersion = logVersion.slice(1)
20+
try {
21+
var logPath = path.resolve(process.cwd(), 'CHANGELOG.md')
22+
log.src = fs.readFileSync(logPath, { encoding: 'utf-8' })
23+
log.version = log.src.split('## ')[1].split('\n')[0].split(' ')[0]
24+
if (log.version.indexOf('v') === 0) log.version = log.version.slice(1)
25+
log.body = log.src.split('## ')[1].split('\n').slice(1).join('\n')
26+
} catch (e) {}
1427

15-
if (logVersion !== pkg.version) {
28+
if (log.version !== pkg.version) {
1629
var err = 'CHANGELOG.md out of sync with package.json'
17-
err += '(' + logVersion + ' !== ' + pkg.version + ')'
30+
err += '(' + log.version + ' !== ' + pkg.version + ')'
1831
throw new Error(err)
1932
}
2033

34+
version = pkg.version ? 'v' + pkg.version : null
35+
2136
return {
22-
tag_name: 'v' + pkg.version,
37+
tag_name: version,
2338
target_commitish: 'master',
24-
name: 'v' + pkg.version,
25-
body: log.split('## ')[1].split('\n').slice(1).join('\n'),
39+
name: version,
40+
body: log.body,
2641
owner: owner,
2742
repo: repo,
2843
draft: false,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "gh-release",
33
"description": "Create a release for a node package on github.",
4-
"version": "1.0.4",
4+
"version": "1.0.5",
55
"author": "Nate Goldman <[email protected]>",
66
"bin": {
77
"gh-release": "./bin/cli.js"

0 commit comments

Comments
 (0)