sdin
Version:
JavaScript package builder.
2 lines • 1.41 kB
JavaScript
import{set as i}from"lodash";import{resolve as e}from"path";import{pathExists as o}from"fs-extra";import{isEmail as a}from"./check";import{green as t,red as s,printTask as n,yellow as c}from"./print";import{execute as l}from"./execute";import{GitError as m}from"./errors";async function r(r){let t="";try{t=await l("git config --global --list")}catch(t){if(r)throw new m(m.READ_GIT_GLOBAL_CONFIG_FAILED,"Cannot read git global config.");return}let e={};if(t.split("\n").forEach(t=>{var r;t&&0<(r=t.indexOf("="))&&i(e,t.slice(0,r),t.slice(r+1))}),!(e.user&&e.user.name&&e.user.email))throw new m(m.NO_GIT_USER_CONFIG,"Please config git global user name and email.");if(e.userName=e.user.name,e.userEmail=e.user.email,a(e.userEmail))return e;throw new m(m.GIT_USER_EMAIL_FORMAT_ERROR,"Git global user email config format error.")}async function f(r){return n({exitCode:m.CREATE_GIT_REPOSITORY_FAILED,task:async t=>{t=t.loading;await o(e(r,".git"))||await l("cd ".concat(r,' && git init && git add . && git commit -m "chore: project is created"'),t)},loading:t=>{if(t){if("string"==typeof t)return t;if(t.toString)return t.toString()}return"Creating git repository to ".concat(c(r),".")},resolve:()=>"Successfully created git repository to ".concat(t(r),"."),reject:()=>"Failed to create git repository to ".concat(s(r),".")})}export{r as readGlobalGitInfo,f as createGitRepository};
//# sourceMappingURL=git.js.map