1
1
#!/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 */
3
3
/* eslint curly: 0 */
4
4
import 'colors' ;
5
5
import 'shelljs/global' ;
@@ -15,7 +15,6 @@ config.fatal = false;
15
15
// constants
16
16
const repoRoot = pwd ( ) ;
17
17
const packagePath = path . join ( repoRoot , 'package.json' ) ;
18
- const changelog = path . join ( repoRoot , 'CHANGELOG.md' ) ;
19
18
20
19
const npmjson = JSON . parse ( cat ( packagePath ) ) ;
21
20
const isPrivate = npmjson . private ;
@@ -140,6 +139,11 @@ function safeRun(command) {
140
139
}
141
140
}
142
141
142
+ function safeRm ( ...args ) {
143
+ if ( argv . dryRun ) console . log ( `[rm ${ args . join ( ' ' ) } ]` . grey , 'DRY RUN' . magenta ) ;
144
+ else rm ( args ) ;
145
+ }
146
+
143
147
/**
144
148
* Npm's `package.json` 'repository.url' could be set to one of three forms:
145
149
* [email protected] :<author>/<repo-name>.git
@@ -181,11 +185,7 @@ function releaseAdRepo(repo, srcFolder, tmpFolder, vVersion) {
181
185
safeRun ( `git tag -a --message=${ vVersion } ${ vVersion } ` ) ;
182
186
safeRun ( 'git push --follow-tags' ) ;
183
187
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 ) ;
189
189
}
190
190
191
191
function release ( { type, preid, npmTagName } ) {
@@ -255,9 +255,31 @@ function release({ type, preid, npmTagName }) {
255
255
// generate changelog
256
256
// within mt-changelog at this stage `./bin/changelog` is already built and tested
257
257
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
+
258
270
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 } ` ) ;
260
278
safeRun ( `git add ${ changelog } ` ) ;
279
+ if ( preid || changelogAlphaRemovedFlag ) {
280
+ safeRun ( `git add -A ${ changelogAlpha } ` ) ;
281
+ }
282
+
261
283
console . log ( 'Generated Changelog' . cyan ) ;
262
284
}
263
285
@@ -267,7 +289,7 @@ function release({ type, preid, npmTagName }) {
267
289
console . log ( 'Tagging: ' . cyan + vVersion . green ) ;
268
290
if ( isCommitsChangelogUsed ) {
269
291
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 } ` ) ;
271
293
} else {
272
294
safeRun ( `git tag -a --message="${ versionAndNotes } " ${ vVersion } ` ) ;
273
295
}
0 commit comments