jj-cli
Version:
1 lines • 2.65 kB
JavaScript
;const{runSpawnCommand:a,commandExec:t,runCommand:r,runCommandAndOutput:e}=require("../../untils/terminal"),i="win32"===process.platform?"npm.cmd":"npm",n="win32"===process.platform?"":"bash ",s=require("path"),l=require("../../untils/common"),o=require("../../untils/logs"),c=require("../../untils/format"),g=async(a,t,e)=>{await l.isInstalled("git")||o.logFatal("Please install GIT first."),a||o.logFatal("Write your commit noted"),t=t||await y(),e=e||await h(),o.logInfo(`Your branch is: ${t}`),o.logInfo(`Your depository is: ${e}`);try{await l.runTask("add...",(async()=>{await r("git add .")})),await l.runTask("commit...",(async()=>{await r(`git commit -m "${a}"`)})),await l.runTask("push...",(async()=>{await r(`git push ${e} ${t}`)})),o.logFriendly("Exec Done")}catch(a){o.logError(a)}},u=async(a,t)=>{await l.isInstalled("git")||(o.logInfo("Please install GIT first."),process.exit(1)),t=t||await h(),a=a||await y();try{await l.runTask("fetch...",(async()=>{await r(`git fetch ${t} ${a}`)})),await l.runTask("pull...",(async()=>{await r(`git pull ${t} ${a}`)}))}catch(a){o.logError(a)}},m=async(a,t)=>{await l.isInstalled("git")||o.logFatal("Please install GIT first."),t=t||await h();const e=await y(),i=p();a=a||`${e}-${i}`;try{await l.runTask("tag...",(async()=>{await r(`git tag ${a}`)})),await l.runTask("push...",(async()=>{await r(`git push ${t} ${a}`)}))}catch(a){o.logError(a)}},w=async(a,t)=>{if(!a||"clear"!=a)return void o.logFatal("you mean git clear ?");await l.isInstalled("git")||o.logFatal("Please install GIT first."),t=t||await h();try{await l.runCommandWithTask("Clear remote depository cache...\n",`git remote prune ${t}`)}catch(a){o.logWarn("Clear remote depository cache error: ",a)}try{await l.runCommandWithTask("Aggressive prune...\n","git gc --aggressive --prune=now")}catch(a){o.logWarn("Aggressive prune error: ",a)}try{const a=`git branch -r | grep -v "$(git rev-parse --abbrev-ref HEAD)" | sed "s#${t}/##" | xargs -I {} git branch -dr ${t}/{}`;await l.runCommandWithTask("Delete all remote tracking branches...\n",a)}catch(a){o.logWarn("Delete all remote tracking branches error: ",a)}try{await l.runCommandWithTask("Delete all local tags...\n","git tag | xargs git tag -d")}catch(a){o.logWarn("Delete all local tags error: ",a)}},y=async()=>{try{var a=await r("git rev-parse --abbrev-ref HEAD")}catch(t){a="master"}return a.replace(/\n/g,"")},p=async()=>c.formatDate((new Date).getTime(),"yyyy-MM-dd-hhmmss"),h=async()=>{const a=await r("git remote -v");try{var t=a.split(" ")[0].split("\t")[0]}catch(a){t="origin"}return t};module.exports={gpushAction:g,gpullAction:u,gtagAction:m,gClearAction:w};