shelljs-github-user
uses shelljs
and git config
to retrieve user git properties from the local machine.
$ npm install --save shelljs-github-user
import github_user from 'shelljs-github-user';
github_user().then((github_obj) => {
console.log(github_obj);
// {name:'sample_user_name', email:'samplemail@sample_address.com'}
});
Adding gitInfo
to Yeoman Generator
user-interactions example.
const Generator = require('yeoman-generator');
const github_user = require('shelljs-github-user');
module.exports = class extends Generator {
constructor(args, opts) {
super(args, opts);
}
prompting() {
const self = this;
const done = this.async();
github_user().then((github_obj) => {
self.gitInfo = github_obj;
_prompt_project_info();
}).catch((reason) => {
self.log(reason);
_prompt_project_info(); // skip gitInfo
});
function _prompt_project_info() {
self.prompt([{
type: 'input',
name: 'name',
message: 'Your project name',
default: this.appname // Default to current folder name
}, {
type: 'confirm',
name: 'cool',
message: 'Would you like to enable the Cool feature?'
}]).then((answers) => {
self.log('app name', answers.name);
self.log('cool feature', answers.cool);
done();
});
}
}
}
@robwierzbowski offers the following approach in issues/190:
this.gitInfo = {
name: shelljs.exec('git config user.name', {silent: true}).output.replace(/\n/g, ''),
email: shelljs.exec('git config user.email', {silent: true}).output.replace(/\n/g, ''),
github: shelljs.exec('git config github.user', {silent: true}).output.replace(/\n/g, ''),
};
This approach works for shelljs prior to version "shelljs": "^0.6"
. shelljs-github-user
intends to provide a solution for "shelljs": "^0.7.6"
.
shelljs-github-user
is created using nod.
MIT © saun4app