Closed spencern closed 7 years ago
Thanks! I just had to make one small change. You need to make sure that you are reading stdout
from the exec
method. The console usually shows the correct thing when you do it like you originally had it, but it outputs an object when piping that raw JSON to other places (like our analytics, for example).
Here's part of the raw versions object with your original code...
{
command: 'reaction',
_: [],
'$0': 'reaction',
os: 'macOS',
osVersion: '10.12.3',
node: '7.6.0',
npm: '4.1.2',
docker: '17.03.1-ce',
branchName: {
[String: 'development\n']
stdout: 'development\n',
stderr: '',
code: 0,
cat: [Function: bound ],
exec: [Function: bound ],
grep: [Function: bound ],
head: [Function: bound ],
sed: [Function: bound ],
sort: [Function: bound ],
tail: [Function: bound ],
to: [Function: bound ],
toEnd: [Function: bound ],
uniq: [Function: bound ]
},
cli: '0.7.9',
reaction: '1.1.0'
}
Note that you need to use stdout
to get a string from that object. I also removed the \n
character.
So this...
const branchName = exec('git rev-parse --abbrev-ref HEAD', { silent: true });
Should be this...
const branchName = exec('git rev-parse --abbrev-ref HEAD', { silent: true }).stdout.replace(/\r?\n|\r/g, '');
Which then fixes the versions object under the hood...
{
command: 'reaction',
_: [],
'$0': 'reaction',
os: 'macOS',
osVersion: '10.12.3',
node: '7.6.0',
npm: '4.1.2',
docker: '17.03.1-ce',
branchName: 'development',
cli: '0.7.9',
reaction: '1.1.0'
}
I also switched branchName
to reactionBranch
because we use that versions object in our analytics and I'd like to make sure the object key has an obvious name in case we ever add something else that potentially has different branches.
Thanks again!
During a discussion yesterday, it was brought up that knowing the branch name is often important for debugging community issues. This PR adds the git branch name to the
reaction -v
output.