Skip to content

Commit

Permalink
feat: add update version feature
Browse files Browse the repository at this point in the history
  • Loading branch information
lekterable committed Apr 20, 2020
1 parent 267cb60 commit fdef971
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
commitRelease,
generateLine,
getCommitDetails,
getCommits
getCommits,
updateVersion
} from './utils'

export const changelog = async (version, options) => {
Expand Down Expand Up @@ -35,6 +36,7 @@ export const release = async version => {
}

try {
await updateVersion(newVersion)
await changelog(newVersion, { write: true })
await commitRelease(newVersion)
} catch (error) {
Expand Down
6 changes: 5 additions & 1 deletion src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ const execAsync = command =>
)

export const commitRelease = async version => {
await execAsync('git add CHANGELOG.md')
await execAsync('git add CHANGELOG.md package.json package-lock.json')
await execAsync(`git commit -m 'chore(release): ${version}'`)
await execAsync(`git tag ${version}`)
}

export const getCommits = async () => {
Expand Down Expand Up @@ -46,3 +47,6 @@ export const generateLine = (
if (normalizedScope === 'release') return `## ${message}\n\n`
return `- ${title} ${hash.slice(0, 8)}${lineSpace}`
}

export const updateVersion = version =>
execAsync(`npm version ${version} --no-git-tag-version`)
25 changes: 22 additions & 3 deletions src/utils/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
commitRelease,
generateLine,
getCommitDetails,
getCommits
getCommits,
updateVersion
} from './index'

jest.mock('child_process', () => ({
Expand All @@ -19,12 +20,16 @@ describe('utils', () => {
const version = '2.2.2'
await commitRelease(version)

expect(exec).toBeCalledTimes(2)
expect(exec).toBeCalledWith('git add CHANGELOG.md', expect.any(Function))
expect(exec).toBeCalledTimes(3)
expect(exec).toBeCalledWith(
'git add CHANGELOG.md package.json package-lock.json',
expect.any(Function)
)
expect(exec).toBeCalledWith(
`git commit -m 'chore(release): ${version}'`,
expect.any(Function)
)
expect(exec).toBeCalledWith(`git tag ${version}`, expect.any(Function))
})
})

Expand Down Expand Up @@ -140,4 +145,18 @@ describe('utils', () => {
expect(line).toEqual(mockedOutput)
})
})

describe('updateVersion', () => {
it('should update version', async () => {
exec.mockImplementation((_, cb) => cb(null))
const version = '3.3.3'
await updateVersion(version)

expect(exec).toBeCalledTimes(1)
expect(exec).toBeCalledWith(
`npm version ${version} --no-git-tag-version`,
expect.any(Function)
)
})
})
})

0 comments on commit fdef971

Please sign in to comment.