From fdef971e2cb81062be1dedefac4da1c8d1b36dd7 Mon Sep 17 00:00:00 2001 From: Kornel Dubieniecki Date: Tue, 21 Apr 2020 01:06:53 +0200 Subject: [PATCH] feat: add update version feature --- src/index.js | 4 +++- src/utils/index.js | 6 +++++- src/utils/index.test.js | 25 ++++++++++++++++++++++--- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index c5fac38..a12878b 100644 --- a/src/index.js +++ b/src/index.js @@ -4,7 +4,8 @@ import { commitRelease, generateLine, getCommitDetails, - getCommits + getCommits, + updateVersion } from './utils' export const changelog = async (version, options) => { @@ -35,6 +36,7 @@ export const release = async version => { } try { + await updateVersion(newVersion) await changelog(newVersion, { write: true }) await commitRelease(newVersion) } catch (error) { diff --git a/src/utils/index.js b/src/utils/index.js index 6395924..212f9b0 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -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 () => { @@ -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`) diff --git a/src/utils/index.test.js b/src/utils/index.test.js index f333e54..04e3c74 100644 --- a/src/utils/index.test.js +++ b/src/utils/index.test.js @@ -3,7 +3,8 @@ import { commitRelease, generateLine, getCommitDetails, - getCommits + getCommits, + updateVersion } from './index' jest.mock('child_process', () => ({ @@ -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)) }) }) @@ -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) + ) + }) + }) })