From 0a474376d5a8f5b39c74bcc139e24f6e3491fa61 Mon Sep 17 00:00:00 2001 From: Charlike Mike Reagent Date: Wed, 15 Nov 2017 00:08:24 +0200 Subject: [PATCH] refactor(*): rename methods and default export now is object BREAKING CHANGE: default export is object with "publish" and "prepublish" methods Signed-off-by: Charlike Mike Reagent --- src/cli.js | 22 ++++++++++------------ src/index.js | 17 ++++++++++++++++- src/{publisher.sh => npmpubli.sh} | 0 test/index.js | 7 ++++--- 4 files changed, 30 insertions(+), 16 deletions(-) rename src/{publisher.sh => npmpubli.sh} (100%) diff --git a/src/cli.js b/src/cli.js index d2a207b..5ec9f56 100755 --- a/src/cli.js +++ b/src/cli.js @@ -5,18 +5,16 @@ * @license Apache-2.0 */ -const path = require('path') -const { shell } = require('execa-pro') -const newRelease = require('./index.js') +const { prepublish, publish } = require('./index.js') -async function init () { - const cwd = process.cwd() - const { nextVersion } = newRelease(cwd) +const cwd = process.cwd() - await shell([ - `yarn version --no-git-tag-version --new-version ${nextVersion}`, - `${path.join(__dirname, 'publisher.sh')}`, - ]) -} +prepublish(cwd) + .then(({ nextVersion }) => publish(nextVersion)) + .catch((er) => { + /* eslint-disable no-console */ + console.error('new-release error!') + console.error(er.stack) -init() + process.exit(1) + }) diff --git a/src/index.js b/src/index.js index 41f2781..d121a25 100644 --- a/src/index.js +++ b/src/index.js @@ -7,15 +7,18 @@ const path = require('path') const util = require('util') const semver = require('semver') const getPkg = require('get-pkg') +const { shell } = require('execa-pro') const parseGitLog = require('parse-git-log') const detectNext = require('detect-next-version') +module.exports = { prepublish, publish } + /** * * @param {*} dir */ -module.exports = async function newRelease (dir) { +async function prepublish (dir) { const commits = await parseGitLog.promise(dir) // TODO: respect all commits after the last tag, @@ -42,3 +45,15 @@ async function getNextVersion (increment, cwd) { return { currentVersion, nextVersion } } + +/** + * + * @param {*} nextVersion + */ + +function publish (nextVersion) { + return shell([ + `yarn version --no-git-tag-version --new-version ${nextVersion}`, + `${path.join(__dirname, 'npmpubli.sh')}`, + ]) +} diff --git a/src/publisher.sh b/src/npmpubli.sh similarity index 100% rename from src/publisher.sh rename to src/npmpubli.sh diff --git a/test/index.js b/test/index.js index 7791e07..bdf6595 100644 --- a/test/index.js +++ b/test/index.js @@ -4,9 +4,10 @@ */ const test = require('mukla') -const newRelease = require('../src/index.js') +const { prepublish, publish } = require('../src/index.js') -test('exports a function', (done) => { - test.strictEqual(typeof newRelease, 'function') +test('exports an object with "publish" and "prepublish" funciotions', (done) => { + test.strictEqual(typeof prepublish, 'function') + test.strictEqual(typeof publish, 'function') done() })