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

Commit 879d9c1

Browse files
committed
feat: 🎸 add back Lerna support
1 parent d59dbd4 commit 879d9c1

File tree

4 files changed

+57
-33
lines changed

4 files changed

+57
-33
lines changed

‎lib/defaults.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const questions = [
7979
'body',
8080
'breaking',
8181
'issues',
82-
// 'lerna'
82+
'lerna'
8383
];
8484

8585
module.exports = {

‎lib/lernaUtils.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

‎lib/questions/lerna.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
const {getAllPackages, getChangedPackages} = require('../util/lerna');
2+
13
exports.createQuestion = (state) => {
4+
const changedPackages = getChangedPackages(state);
25
const question = {
3-
choices: allPackages,
6+
choices: getAllPackages(state),
47
default: changedPackages,
58
message: `The packages that this commit has affected (${changedPackages.length} detected)\n`,
69
name: 'packages',

‎lib/util/lerna.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const {execSync} = require('child_process');
2+
const path = require('path');
3+
const fs = require('fs');
4+
5+
const isDir = (root) => (name) => {
6+
const filepath = path.join(root, name);
7+
8+
try {
9+
const stats = fs.statSync(filepath);
10+
11+
return stats.isDirectory();
12+
} catch (error) {
13+
return false;
14+
}
15+
};
16+
17+
const getAllPackages = (state) => {
18+
try {
19+
const dir = path.join(state.root, 'packages');
20+
21+
return fs.readdirSync(dir).map(isDir(dir));
22+
} catch (error) {
23+
return [];
24+
}
25+
};
26+
27+
const getChangedFiles = () =>
28+
execSync('git diff --cached --name-only 2>/dev/null')
29+
.toString()
30+
.trim()
31+
.split('\n');
32+
33+
const getChangedPackages = () => {
34+
const unique = {};
35+
const changedFiles = getChangedFiles();
36+
const regex = /^packages\/([^/]+)\//;
37+
38+
for (const filename of changedFiles) {
39+
const matches = filename.match(regex);
40+
41+
if (matches) {
42+
unique[matches[1]] = 1;
43+
}
44+
}
45+
46+
return Object.keys(unique);
47+
};
48+
49+
module.exports = {
50+
getAllPackages,
51+
getChangedPackages
52+
};

0 commit comments

Comments
 (0)