From 5abccbecb95b408c0307d65842bc6e6786bc1dc3 Mon Sep 17 00:00:00 2001 From: Yuki Hattori Date: Tue, 29 May 2018 20:55:03 +0900 Subject: [PATCH] Update version script to work with Mac (#31) * Update version script to work with Mac * Fix version script to add prefix "v" * Add CHANGELOG.md to git stage after updating version --- package.json | 2 +- version.js | 14 ++++++++++++++ version.sh | 4 ---- 3 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 version.js delete mode 100644 version.sh diff --git a/package.json b/package.json index 7b6c40e5..2447a12a 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "preversion": "npm-run-all --npm-path yarn --parallel format:check lint:all test:coverage", "test": "cross-env NODE_ENV=test mocha", "test:coverage": "cross-env NODE_ENV=test nyc mocha", - "version": "bash version.sh", + "version": "node version.js && git add -A CHANGELOG.md", "watch": "babel src --out-dir lib -w" }, "devDependencies": { diff --git a/version.js b/version.js new file mode 100644 index 00000000..ad884e3c --- /dev/null +++ b/version.js @@ -0,0 +1,14 @@ +const fs = require('fs') +const path = require('path') + +const unreleased = '## [Unreleased]' +const [date] = new Date().toISOString().split('T') +const version = `## v${process.env.npm_package_version} - ${date}` + +const changelog = path.resolve(__dirname, 'CHANGELOG.md') +const content = fs.readFileSync(changelog, 'utf8') + +fs.writeFileSync( + changelog, + content.replace(unreleased, `${unreleased}\n\n${version}`) +) diff --git a/version.sh b/version.sh deleted file mode 100644 index f04404c9..00000000 --- a/version.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -grep -q '## \[Unreleased\]' CHANGELOG.md && - sed -i "s/## \[Unreleased\]/&\n\n## v$npm_package_version - $(date -u '+%F')/" CHANGELOG.md && - git add -A CHANGELOG.md