UNPKG

sdin

Version:

JavaScript package builder.

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