11import path from 'path' ;
22import fs from 'fs' ;
3- import conventionalChangelog from 'conventional-changelog' ;
3+ import conventionalChangelogCore from 'conventional-changelog-core' ;
4+ import conventionalChangelogPresetLoader from 'conventional-changelog-preset-loader' ;
45import tempfile from 'tempfile' ;
56import addStream from 'add-stream' ;
7+ import merge from 'deepmerge' ;
68import runStep from '../runStep' ;
79import { parseArgs } from '../../util' ;
810
@@ -25,20 +27,22 @@ export default ({
2527 }
2628 return new Promise ( ( resolve , reject ) => {
2729 const { conventionalChangelogArgs } = config ;
28- const { args , gitRawCommitsOpts , templateContext } = prepareParams ( {
30+ prepareParams ( {
2931 dir,
3032 conventionalChangelogArgs,
3133 releaseCount,
3234 firstRelease,
3335 revisionRange,
3436 reject,
35- } ) ;
36- runConventionalChangelog ( {
37- args,
38- templateContext,
39- gitRawCommitsOpts,
40- resolve,
41- reject,
37+ } ) . then ( ( { args, gitRawCommitsOpts, templateContext } ) => {
38+ runConventionalChangelog ( {
39+ args,
40+ templateContext,
41+ gitRawCommitsOpts,
42+ resolve,
43+ reject,
44+ dir,
45+ } ) ;
4246 } ) ;
4347 } ) ;
4448 }
@@ -78,7 +82,7 @@ const argSpec = {
7882 '-t' : '--tag-prefix' ,
7983} ;
8084
81- export function prepareParams ( {
85+ export async function prepareParams ( {
8286 dir,
8387 conventionalChangelogArgs,
8488 releaseCount,
@@ -118,9 +122,24 @@ export function prepareParams({
118122 }
119123 const templateContext =
120124 args . context && require ( path . resolve ( dir , args . context ) ) ;
121- if ( args . config ) {
122- args . config = require ( path . resolve ( dir , args . config ) ) ;
125+ args . config = args . config ? require ( path . resolve ( dir , args . config ) ) : { } ;
126+ if ( args . preset ) {
127+ try {
128+ args . config = merge (
129+ await conventionalChangelogPresetLoader ( args . preset ) ,
130+ args . config
131+ ) ;
132+ } catch ( err ) {
133+ if ( typeof args . preset === 'object' ) {
134+ args . warn ( `Preset: "${ args . preset . name } " ${ err . message } ` ) ;
135+ } else if ( typeof args . preset === 'string' ) {
136+ args . warn ( `Preset: "${ args . preset } " ${ err . message } ` ) ;
137+ } else {
138+ args . warn ( `Preset: ${ err . message } ` ) ;
139+ }
140+ }
123141 }
142+
124143 return { args, gitRawCommitsOpts, templateContext } ;
125144}
126145
@@ -130,15 +149,19 @@ function runConventionalChangelog({
130149 gitRawCommitsOpts,
131150 resolve,
132151 reject,
152+ dir,
133153} ) {
134154 if ( ! fs . existsSync ( args . outfile ) ) {
135155 fs . writeFileSync ( args . outfile , '' ) ;
136156 }
137157
138- const changelogStream = conventionalChangelog (
158+ const changelogStream = conventionalChangelogCore (
139159 args ,
140160 templateContext ,
141- gitRawCommitsOpts
161+ { ...gitRawCommitsOpts , path : dir } ,
162+ undefined ,
163+ undefined ,
164+ { path : dir , cwd : dir }
142165 ) . on ( 'error' , reject ) ;
143166
144167 const readStream = fs . createReadStream ( args . infile ) . on ( 'error' , reject ) ;
0 commit comments