From 8570c30211363c2eb81d29d1c3ea0692224b57e7 Mon Sep 17 00:00:00 2001 From: AlexKVal Date: Mon, 13 Jul 2015 17:21:54 +0300 Subject: [PATCH] [change] the usage of '[rf|mt]-changelog' package is optional now If a project uses one of '[rf|mt]-changelog' packages, then this script will automatically use them. --- README.md | 6 +++--- package.json | 3 --- src/release.js | 24 +++++++++++++++++++----- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index d39cde3..ecf5602 100644 --- a/README.md +++ b/README.md @@ -61,9 +61,9 @@ E.g.: - checks linting and tests by running `npm run test` command - does version bump, with `preid` if it is requested - builds all by `npm run build` command -- generates changelog using `mt-changelog` -- adds and commits changed `CHANGELOG.md` and `package.json` files to git repo -- adds git tag with changelog message and new version +- if one of `[rf|mt]-changelog` is used in 'devDependencies', then changelog is generated +- adds and commits changed `package.json` (and `CHANGELOG.md`, if used) files to git repo +- adds git tag with new version (and changelog message, if used) - pushes changes to github repo - releases npm package by `npm publish` command - if `bowerRepo` field is present in the `package.json`, then it releases bower package: diff --git a/package.json b/package.json index 3bfb1b8..abc7909 100644 --- a/package.json +++ b/package.json @@ -37,9 +37,6 @@ "url": "https://github.com/AlexKVal/release-script/issues" }, "homepage": "https://github.com/AlexKVal/release-script#readme", - "peerDependencies": { - "mt-changelog": "^0.5.3" - }, "devDependencies": { "babel": "^5.6.14", "babel-eslint": "^3.1.23", diff --git a/src/release.js b/src/release.js index b49a27d..9dd887f 100644 --- a/src/release.js +++ b/src/release.js @@ -1,5 +1,5 @@ #!/usr/bin/env node -/* globals cat, config, cp, ls, popd, pushd, pwd, rm, exec, exit */ +/* globals cat, config, cp, ls, popd, pushd, pwd, rm, exec, exit, which */ /* eslint curly: 0 */ import 'colors'; import 'shelljs/global'; @@ -18,6 +18,17 @@ const changelog = path.join(repoRoot, 'CHANGELOG.md'); const npmjson = JSON.parse(cat(packagePath)); +//------------------------------------------------------------------------------ +// check if one of 'rf-changelog' or 'mt-changelog' is used by project +const devDepsNode = npmjson.devDependencies; +const isCommitsChangelogUsed = devDepsNode && + devDepsNode['rf-changelog'] || devDepsNode['mt-changelog']; +if (isCommitsChangelogUsed && !which('changelog')) { + printErrorAndExit('The "[rf|mt]-changelog" package is present in "devDependencies", but it is not installed.'); +} + +//------------------------------------------------------------------------------ +// options const configOptions = npmjson['release-script'] || {}; const bowerRoot = path.join(repoRoot, (configOptions.bowerRoot || 'amd/')); const tmpBowerRepo = path.join(repoRoot, (configOptions.tmpBowerRepo || 'tmp-bower-repo')); @@ -157,13 +168,16 @@ function release({ type, preid }) { } console.log('Completed: '.cyan + 'build'.green); - // generate changelog const vVersion = `v${newVersion}`; - run(`changelog --title ${vVersion} --out ${changelog}`); - safeRun(`git add ${changelog}`); + // generate changelog + if (isCommitsChangelogUsed) { + run(`changelog --title ${vVersion} --out ${changelog}`); + safeRun(`git add ${changelog}`); + console.log('Generated Changelog'.cyan); + } + safeRun(`git commit -m "Release ${vVersion}"`); - console.log('Generated Changelog'.cyan); // tag and release console.log('Tagging: '.cyan + vVersion.green);