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

Commit

Permalink
feat: 🎸 add back Lerna support
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Jun 5, 2018
1 parent d59dbd4 commit 879d9c1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 33 deletions.
2 changes: 1 addition & 1 deletion lib/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const questions = [
'body',
'breaking',
'issues',
// 'lerna'
'lerna'
];

module.exports = {
Expand Down
31 changes: 0 additions & 31 deletions lib/lernaUtils.js

This file was deleted.

5 changes: 4 additions & 1 deletion lib/questions/lerna.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const {getAllPackages, getChangedPackages} = require('../util/lerna');

exports.createQuestion = (state) => {
const changedPackages = getChangedPackages(state);
const question = {
choices: allPackages,
choices: getAllPackages(state),
default: changedPackages,
message: `The packages that this commit has affected (${changedPackages.length} detected)\n`,
name: 'packages',
Expand Down
52 changes: 52 additions & 0 deletions lib/util/lerna.js
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
};

0 comments on commit 879d9c1

Please sign in to comment.