Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

Commit

Permalink
feat: use Git to determine root folder
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Jun 5, 2018
1 parent 3dd3c67 commit d59dbd4
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 11 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,13 @@ Select the packages the commit affected.
### Footer

The footer is the place to reference any tasks related to this commit.



## Why this Fork?

```
11:10 $ npm i -g mol-conventional-changelog
+ mol-conventional-changelog@1.4.0
added 345 packages in 38.677s
```
1 change: 1 addition & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const main = async () => {
const answers = await runInteractiveQuestions(state);
const message = formatCommitMessage(state);

console.log(state);
console.log(message);
console.log(answers);
} catch (error) {
Expand Down
7 changes: 4 additions & 3 deletions lib/createState.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const appRoot = require('app-root-path');
const getGitRootDir = require('./util/getGitRootDir');
const getConfig = require('./getConfig');

const createState = () => {
const root = getGitRootDir();
const state = {
answers: {
body: '',
Expand All @@ -12,8 +13,8 @@ const createState = () => {
subject: '',
type: ''
},
config: getConfig(),
root: String(appRoot)
config: getConfig(root),
root
};

return state;
Expand Down
8 changes: 4 additions & 4 deletions lib/getConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const configFiles = [
'changelog.config.json'
];

const findOverrides = () => {
const dir = process.cwd();
const findOverrides = (root) => {
const dir = root || process.cwd();

for (const file of configFiles) {
const filename = path.join(dir, file);
Expand All @@ -36,8 +36,8 @@ const findOverrides = () => {
return {};
};

const getConfig = () => {
const overrides = findOverrides();
const getConfig = (root) => {
const overrides = findOverrides(root);

if (typeof overrides !== 'object') {
signale.fatal(new TypeError('Expected changelog config to be an object.'));
Expand Down
5 changes: 1 addition & 4 deletions lib/lernaUtils.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
/* eslint-disable global-require */
const path = require('path');
const fs = require('fs');

const getAllPackages = function () {
const Repository = require('lerna/lib/Repository');
const PackageUtilities = require('lerna/lib/PackageUtilities');

return PackageUtilities.getPackages(new Repository());
};

const getChangedPackages = function () {
Expand Down
11 changes: 11 additions & 0 deletions lib/util/getGitRootDir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const {execSync} = require('child_process');

const getGitRootDir = () => {
const dir = execSync('git rev-parse --show-toplevel 2>/dev/null')
.toString()
.trim();

return dir;
};

module.exports = getGitRootDir;

0 comments on commit d59dbd4

Please sign in to comment.