This repository has been archived by the owner on Jun 16, 2021. It is now read-only.
forked from streamich/git-cz
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
57 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,7 +79,7 @@ const questions = [ | |
'body', | ||
'breaking', | ||
'issues', | ||
// 'lerna' | ||
'lerna' | ||
]; | ||
|
||
module.exports = { | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const {execSync} = require('child_process'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
const isDir = (root) => (name) => { | ||
const filepath = path.join(root, name); | ||
|
||
try { | ||
const stats = fs.statSync(filepath); | ||
|
||
return stats.isDirectory(); | ||
} catch (error) { | ||
return false; | ||
} | ||
}; | ||
|
||
const getAllPackages = (state) => { | ||
try { | ||
const dir = path.join(state.root, 'packages'); | ||
|
||
return fs.readdirSync(dir).map(isDir(dir)); | ||
} catch (error) { | ||
return []; | ||
} | ||
}; | ||
|
||
const getChangedFiles = () => | ||
execSync('git diff --cached --name-only 2>/dev/null') | ||
.toString() | ||
.trim() | ||
.split('\n'); | ||
|
||
const getChangedPackages = () => { | ||
const unique = {}; | ||
const changedFiles = getChangedFiles(); | ||
const regex = /^packages\/([^/]+)\//; | ||
|
||
for (const filename of changedFiles) { | ||
const matches = filename.match(regex); | ||
|
||
if (matches) { | ||
unique[matches[1]] = 1; | ||
} | ||
} | ||
|
||
return Object.keys(unique); | ||
}; | ||
|
||
module.exports = { | ||
getAllPackages, | ||
getChangedPackages | ||
}; |