yeoman-generator
Version:
Rails-inspired generator system that provides scaffolding for your apps
54 lines (53 loc) • 1.72 kB
JavaScript
import githubUsername from 'github-username';
class GitUtil {
#parent;
constructor(parent) {
this.#parent = parent;
}
/**
* Retrieves user's name from Git in the global scope or the project scope
* (it'll take what Git will use in the current context)
* @return {Promise<string>} configured git name or undefined
*/
async name() {
const { value } = await this.#parent.simpleGit.getConfig('user.name');
return value ?? undefined;
}
/**
* Retrieves user's email from Git in the global scope or the project scope
* (it'll take what Git will use in the current context)
* @return {Promise<string>} configured git email or undefined
*/
async email() {
const { value } = await this.#parent.simpleGit.getConfig('user.email');
return value ?? undefined;
}
}
export class GitMixin {
_git;
get git() {
if (!this._git) {
this._git = new GitUtil(this);
}
return this._git;
}
/**
* @deprecated Will be removed in version 8.
* GitHub utilities.
*/
get github() {
return {
/**
* @deprecated Will be removed in version 8. Use 'github-username' package with `await this.git.email()` result instead.
*
* Retrieves GitHub's username from the GitHub API
* @return Resolved with the GitHub username or rejected if unable to
* get the information
*/
username: async () => {
const email = await this.git.email();
return email ? githubUsername(email) : email;
},
};
}
}