Skip to content

Commit

Permalink
fix: specify path for changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
shipjs committed Nov 6, 2020
1 parent 67d45f0 commit 6918d14
Show file tree
Hide file tree
Showing 3 changed files with 258 additions and 101 deletions.
6 changes: 4 additions & 2 deletions packages/shipjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
"arg": "4.1.3",
"chalk": "4.0.0",
"change-case": "4.1.1",
"conventional-changelog": "^3.1.15",
"conventional-changelog-angular": "^5.0.6",
"conventional-changelog-core": "^4.1.4",
"conventional-changelog-preset-loader": "^2.3.0",
"dotenv": "^8.2.0",
"ejs": "^3.0.0",
"esm": "3.2.25",
Expand Down Expand Up @@ -76,4 +78,4 @@
"jest": "26.0.1",
"jest-watch-typeahead": "0.6.0"
}
}
}
32 changes: 27 additions & 5 deletions packages/shipjs/src/step/prepare/updateChangelog.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'path';
import fs from 'fs';
import conventionalChangelog from 'conventional-changelog';
import conventionalChangelogCore from 'conventional-changelog-core';
import conventionalChangelogPresetLoader from 'conventional-changelog-preset-loader';
import tempfile from 'tempfile';
import addStream from 'add-stream';
import runStep from '../runStep';
Expand Down Expand Up @@ -39,6 +40,7 @@ export default ({
gitRawCommitsOpts,
resolve,
reject,
dir,
});
});
}
Expand Down Expand Up @@ -118,9 +120,25 @@ export function prepareParams({
}
const templateContext =
args.context && require(path.resolve(dir, args.context));
if (args.config) {
args.config = require(path.resolve(dir, args.config));
args.config = args.config ? require(path.resolve(dir, args.config)) : {};

if (args.preset) {
try {
args.config = {
...conventionalChangelogPresetLoader(args.preset),
...args.config,
};
} catch (err) {
if (typeof args.preset === 'object') {
args.warn(`Preset: "${args.preset.name}" ${err.message}`);
} else if (typeof args.preset === 'string') {
args.warn(`Preset: "${args.preset}" ${err.message}`);
} else {
args.warn(`Preset: ${err.message}`);
}
}
}

return { args, gitRawCommitsOpts, templateContext };
}

Expand All @@ -130,15 +148,19 @@ function runConventionalChangelog({
gitRawCommitsOpts,
resolve,
reject,
dir,
}) {
if (!fs.existsSync(args.outfile)) {
fs.writeFileSync(args.outfile, '');
}

const changelogStream = conventionalChangelog(
const changelogStream = conventionalChangelogCore(
args,
templateContext,
gitRawCommitsOpts
gitRawCommitsOpts,
undefined,
undefined,
{ path: dir }
).on('error', reject);

const readStream = fs.createReadStream(args.infile).on('error', reject);
Expand Down
Loading

0 comments on commit 6918d14

Please sign in to comment.