Skip to content

Commit

Permalink
Merge pull request #5 from streamich/fix-lerna
Browse files Browse the repository at this point in the history
Fix lerna
  • Loading branch information
streamich authored Jun 7, 2018
2 parents ad1878f + 395c0c7 commit 60787d2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
34 changes: 23 additions & 11 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,31 @@ const executeCommand = (command, args = [], env = process.env) => {
});
};

// eslint-disable-next-line no-process-env
const appendToExecuteCommand = (prepend) => (command, args = [], env = process.env) =>
executeCommand(command, [...args, ...prepend], env);

const main = async () => {
try {
const state = createState();

await runInteractiveQuestions(state);

const message = formatCommitMessage(state);

const {_: args, ...params} = minimist(process.argv.slice(2));

for (const arg of args) {
params[arg] = true;
}

const {'dry-run': isDryRun, ...passThroughParams} = params;

if (isDryRun) {
// eslint-disable-next-line no-console
console.log('Running in dry mode.');
}

await runInteractiveQuestions(state);

const message = formatCommitMessage(state);

const appendedArgs = [];

// eslint-disable-next-line guard-for-in
for (const key in params) {
for (const key in passThroughParams) {
const value = params[key];

if (key.length === 1) {
Expand All @@ -56,9 +59,18 @@ const main = async () => {
}
}

const exec = appendToExecuteCommand(appendedArgs);
const executeCommandArgs = ['commit', '--message', message, ...appendedArgs];

if (isDryRun) {
const command = shellescape(['git', ...executeCommandArgs]);

exec('git', ['commit', '--message', message]);
// eslint-disable-next-line no-console
console.log('Will execute command:');
// eslint-disable-next-line no-console
console.log(command);
} else {
executeCommand('git', executeCommandArgs);
}
} catch (error) {
signale.fatal(error);
}
Expand Down
4 changes: 3 additions & 1 deletion lib/questions/lerna.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ exports.createQuestion = (state) => {
}

const changedPackages = getChangedPackages(state);
const allPackages = getAllPackages(state);

const question = {
choices: getAllPackages(state),
choices: allPackages,
default: changedPackages,
message: `The packages that this commit has affected (${changedPackages.length} detected)\n`,
name: 'packages',
Expand Down
2 changes: 1 addition & 1 deletion lib/util/lerna.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const getAllPackages = (state) => {
try {
const dir = path.join(state.root, 'packages');

return fs.readdirSync(dir).map(isDir(dir));
return fs.readdirSync(dir).filter(isDir(dir));
} catch (error) {
return [];
}
Expand Down

1 comment on commit 60787d2

@streamich
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build version: 1.7.0-master.28 🤞 master on Travis 🎉

Please sign in to comment.