Skip to content
This repository has been archived by the owner on Nov 20, 2019. It is now read-only.

Commit

Permalink
refactor(*): rename methods and default export now is object
Browse files Browse the repository at this point in the history
BREAKING CHANGE: default export is object with "publish" and "prepublish" methods

Signed-off-by: Charlike Mike Reagent <[email protected]>
  • Loading branch information
Charlike Mike Reagent committed Nov 14, 2017
1 parent def5c49 commit 0a47437
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
22 changes: 10 additions & 12 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
17 changes: 16 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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')}`,
])
}
File renamed without changes.
7 changes: 4 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})

0 comments on commit 0a47437

Please sign in to comment.