From 77917c3a6709acae3d0f56a7906701d45dfcaaf6 Mon Sep 17 00:00:00 2001 From: Nate Goldman Date: Sun, 8 Feb 2015 00:06:38 -0800 Subject: [PATCH] hotfix for cli help/usage should now work in directories w/o `package.json` or `CHANGELOG.md` --- CHANGELOG.md | 3 +++ get-defaults.js | 41 ++++++++++++++++++++++++++++------------- package.json | 2 +- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48b0799..0e759d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # gh-release changelog +## 1.0.5 - 2015-02-08 +* hotfix for help/usage in dir w/o `package.json` or `CHANGELOG.md` + ## 1.0.4 - 2015-02-07 * remove `files` from `package.json` to fix cli again diff --git a/get-defaults.js b/get-defaults.js index 89f8a51..0d5d3f9 100644 --- a/get-defaults.js +++ b/get-defaults.js @@ -1,28 +1,43 @@ var fs = require('fs') var path = require('path') -var pkg = require(path.resolve(process.cwd(), 'package.json')) +var pkg = { version: null } +var log = { + version: null, + body: null +} +var owner = null +var repo = null +var version = null module.exports = function getDefaults () { - var repoPath = pkg.repository.url.split('github.com/')[1].split('/') - var owner = repoPath[0] - var repo = repoPath[1].split('.git')[0] - var logPath = path.resolve(process.cwd(), 'CHANGELOG.md') - var log = fs.readFileSync(logPath, { encoding: 'utf-8' }) - var logVersion = log.split('## ')[1].split('\n')[0].split(' ')[0] + try { + pkg = require(path.resolve(process.cwd(), 'package.json')) + var repoPath = pkg.repository.url.split('github.com/')[1].split('/') + owner = repoPath[0] + repo = repoPath[1].split('.git')[0] + } catch (e) {} - if (logVersion.indexOf('v') === 0) logVersion = logVersion.slice(1) + try { + var logPath = path.resolve(process.cwd(), 'CHANGELOG.md') + log.src = fs.readFileSync(logPath, { encoding: 'utf-8' }) + log.version = log.src.split('## ')[1].split('\n')[0].split(' ')[0] + if (log.version.indexOf('v') === 0) log.version = log.version.slice(1) + log.body = log.src.split('## ')[1].split('\n').slice(1).join('\n') + } catch (e) {} - if (logVersion !== pkg.version) { + if (log.version !== pkg.version) { var err = 'CHANGELOG.md out of sync with package.json' - err += '(' + logVersion + ' !== ' + pkg.version + ')' + err += '(' + log.version + ' !== ' + pkg.version + ')' throw new Error(err) } + version = pkg.version ? 'v' + pkg.version : null + return { - tag_name: 'v' + pkg.version, + tag_name: version, target_commitish: 'master', - name: 'v' + pkg.version, - body: log.split('## ')[1].split('\n').slice(1).join('\n'), + name: version, + body: log.body, owner: owner, repo: repo, draft: false, diff --git a/package.json b/package.json index a4d072f..8eae54c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "gh-release", "description": "Create a release for a node package on github.", - "version": "1.0.4", + "version": "1.0.5", "author": "Nate Goldman ", "bin": { "gh-release": "./bin/cli.js"