Skip to content

Commit

Permalink
[added] 'CHANGELOG-alpha.md' is generating for pre-releases now
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKVal committed Sep 16, 2015
1 parent 0d01cb0 commit 2c52100
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ If your `preid` tag and npm tag name are the same, then you can just:
```
It will produce `v0.25.100-beta.0` and `npm publish --tag beta`.

`changelog` generated output will go into `CHANGELOG-alpha.md` for pre-releases,
and with the next release this file will be removed.

#### Alternative npm package root folder

Say you want to publish to `npmjs` only the content of your `lib` folder.
Expand Down
40 changes: 31 additions & 9 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, which */
/* globals cat, config, cp, ls, popd, pushd, pwd, rm, test, exec, exit, which */
/* eslint curly: 0 */
import 'colors';
import 'shelljs/global';
Expand All @@ -15,7 +15,6 @@ config.fatal = false;
// constants
const repoRoot = pwd();
const packagePath = path.join(repoRoot, 'package.json');
const changelog = path.join(repoRoot, 'CHANGELOG.md');

const npmjson = JSON.parse(cat(packagePath));
const isPrivate = npmjson.private;
Expand Down Expand Up @@ -140,6 +139,11 @@ function safeRun(command) {
}
}

function safeRm(...args) {
if (argv.dryRun) console.log(`[rm ${args.join(' ')}]`.grey, 'DRY RUN'.magenta);
else rm(args);
}

/**
* Npm's `package.json` 'repository.url' could be set to one of three forms:
* [email protected]:<author>/<repo-name>.git
Expand Down Expand Up @@ -181,11 +185,7 @@ function releaseAdRepo(repo, srcFolder, tmpFolder, vVersion) {
safeRun(`git tag -a --message=${vVersion} ${vVersion}`);
safeRun('git push --follow-tags');
popd();
if (argv.dryRun) {
console.log(`[rm -rf ${tmpFolder}]`.grey, 'DRY RUN'.magenta);
} else {
rm('-rf', tmpFolder);
}
safeRm('-rf', tmpFolder);
}

function release({ type, preid, npmTagName }) {
Expand Down Expand Up @@ -255,9 +255,31 @@ function release({ type, preid, npmTagName }) {
// generate changelog
// within mt-changelog at this stage `./bin/changelog` is already built and tested
const changelogCmd = isWithinMtChangelog ? './bin/changelog' : 'changelog';

const changelog = path.join(repoRoot, 'CHANGELOG.md');
const changelogAlpha = path.join(repoRoot, 'CHANGELOG-alpha.md');
let changelogOutput, changelogArgs;
if (preid) {
changelogOutput = changelogAlpha;
changelogArgs = '';
} else {
changelogOutput = changelog;
changelogArgs = '--exclude-pre-releases';
}

if (isCommitsChangelogUsed) {
run(`${changelogCmd} --title="${versionAndNotes}" --out ${changelog}`);
let changelogAlphaRemovedFlag = false;
if (test('-e', changelogAlpha)) {
rm('-rf', changelogAlpha);
changelogAlphaRemovedFlag = true;
}

run(`${changelogCmd} --title="${versionAndNotes}" --out ${changelogOutput} ${changelogArgs}`);
safeRun(`git add ${changelog}`);
if (preid || changelogAlphaRemovedFlag) {
safeRun(`git add -A ${changelogAlpha}`);
}

console.log('Generated Changelog'.cyan);
}

Expand All @@ -267,7 +289,7 @@ function release({ type, preid, npmTagName }) {
console.log('Tagging: '.cyan + vVersion.green);
if (isCommitsChangelogUsed) {
notesForRelease = run(`${changelogCmd} --title="${versionAndNotes}" -s`);
safeRun(`changelog --title="${versionAndNotes}" -s | git tag -a -F - ${vVersion}`);
safeRun(`changelog --title="${versionAndNotes}" ${changelogArgs} -s | git tag -a -F - ${vVersion}`);
} else {
safeRun(`git tag -a --message="${versionAndNotes}" ${vVersion}`);
}
Expand Down

0 comments on commit 2c52100

Please sign in to comment.