Skip to content

Commit

Permalink
[change] the usage of '[rf|mt]-changelog' package is optional now
Browse files Browse the repository at this point in the history
If a project uses one of '[rf|mt]-changelog' packages,
then this script will automatically use them.
  • Loading branch information
AlexKVal committed Jul 13, 2015
1 parent 6551bab commit 8570c30
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
24 changes: 19 additions & 5 deletions src/release.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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'));
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8570c30

Please sign in to comment.