Skip to content

Commit 2c52100

Browse files
committed
[added] 'CHANGELOG-alpha.md' is generating for pre-releases now
1 parent 0d01cb0 commit 2c52100

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ If your `preid` tag and npm tag name are the same, then you can just:
9393
```
9494
It will produce `v0.25.100-beta.0` and `npm publish --tag beta`.
9595

96+
`changelog` generated output will go into `CHANGELOG-alpha.md` for pre-releases,
97+
and with the next release this file will be removed.
98+
9699
#### Alternative npm package root folder
97100

98101
Say you want to publish to `npmjs` only the content of your `lib` folder.

src/release.js

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env node
2-
/* globals cat, config, cp, ls, popd, pushd, pwd, rm, exec, exit, which */
2+
/* globals cat, config, cp, ls, popd, pushd, pwd, rm, test, exec, exit, which */
33
/* eslint curly: 0 */
44
import 'colors';
55
import 'shelljs/global';
@@ -15,7 +15,6 @@ config.fatal = false;
1515
// constants
1616
const repoRoot = pwd();
1717
const packagePath = path.join(repoRoot, 'package.json');
18-
const changelog = path.join(repoRoot, 'CHANGELOG.md');
1918

2019
const npmjson = JSON.parse(cat(packagePath));
2120
const isPrivate = npmjson.private;
@@ -140,6 +139,11 @@ function safeRun(command) {
140139
}
141140
}
142141

142+
function safeRm(...args) {
143+
if (argv.dryRun) console.log(`[rm ${args.join(' ')}]`.grey, 'DRY RUN'.magenta);
144+
else rm(args);
145+
}
146+
143147
/**
144148
* Npm's `package.json` 'repository.url' could be set to one of three forms:
145149
* [email protected]:<author>/<repo-name>.git
@@ -181,11 +185,7 @@ function releaseAdRepo(repo, srcFolder, tmpFolder, vVersion) {
181185
safeRun(`git tag -a --message=${vVersion} ${vVersion}`);
182186
safeRun('git push --follow-tags');
183187
popd();
184-
if (argv.dryRun) {
185-
console.log(`[rm -rf ${tmpFolder}]`.grey, 'DRY RUN'.magenta);
186-
} else {
187-
rm('-rf', tmpFolder);
188-
}
188+
safeRm('-rf', tmpFolder);
189189
}
190190

191191
function release({ type, preid, npmTagName }) {
@@ -255,9 +255,31 @@ function release({ type, preid, npmTagName }) {
255255
// generate changelog
256256
// within mt-changelog at this stage `./bin/changelog` is already built and tested
257257
const changelogCmd = isWithinMtChangelog ? './bin/changelog' : 'changelog';
258+
259+
const changelog = path.join(repoRoot, 'CHANGELOG.md');
260+
const changelogAlpha = path.join(repoRoot, 'CHANGELOG-alpha.md');
261+
let changelogOutput, changelogArgs;
262+
if (preid) {
263+
changelogOutput = changelogAlpha;
264+
changelogArgs = '';
265+
} else {
266+
changelogOutput = changelog;
267+
changelogArgs = '--exclude-pre-releases';
268+
}
269+
258270
if (isCommitsChangelogUsed) {
259-
run(`${changelogCmd} --title="${versionAndNotes}" --out ${changelog}`);
271+
let changelogAlphaRemovedFlag = false;
272+
if (test('-e', changelogAlpha)) {
273+
rm('-rf', changelogAlpha);
274+
changelogAlphaRemovedFlag = true;
275+
}
276+
277+
run(`${changelogCmd} --title="${versionAndNotes}" --out ${changelogOutput} ${changelogArgs}`);
260278
safeRun(`git add ${changelog}`);
279+
if (preid || changelogAlphaRemovedFlag) {
280+
safeRun(`git add -A ${changelogAlpha}`);
281+
}
282+
261283
console.log('Generated Changelog'.cyan);
262284
}
263285

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

0 commit comments

Comments
 (0)