UNPKG

git-mob

Version:
27 lines (24 loc) 6.13 kB
import z from"node:os";import D from"minimist";import{stripIndents as U}from"common-tags";import{getAllAuthors as a,getPrimaryAuthor as v,getSelectedCoAuthors as R,gitMobConfig as $,gitConfig as k,gitRevParse as W,setCoAuthors as I,setPrimaryAuthor as F,updateGitTemplate as J,Author as N,pathToCoAuthors as B}from"git-mob-core";import{EOL as C}from"node:os";import{stripIndent as P}from"common-tags";import L from"update-notifier";var c={name:"git-mob",version:"4.0.1",description:"CLI tool for adding co-authors to commits.",homepage:"https://github.com/rkotze/git-mob/blob/master/packages/git-mob/README.md",type:"module",scripts:{build:"rimraf dist && bob","test:w":"npm run build -- -w -t & env-cmd -f test-helpers/env.cjs ava --watch --serial --no-worker-threads",pretest:"npm run build -- -t",test:"npm run testbase",checks:"npm run test && npm run lint",lint:"xo --cwd=../../",testbase:"ava --serial --no-worker-threads",minifytest:"npm run build -- -m -t && npm run testbase",preversion:"npm run checks",prepack:"npm run build -- -m",postinstall:"node ./dist/install/create-author-file.js"},bin:{"git-mob":"bin/mob.js","git-mob-print":"bin/mob-print.js","git-solo":"bin/solo.js","git-add-coauthor":"bin/add-coauthor.js","git-suggest-coauthors":"bin/suggest-coauthors.js"},repository:{type:"git",url:"git@github.com:rkotze/git-mob.git",directory:"packages/git-mob"},engines:{node:">=16"},keywords:["cli","cli-app","git-pair","git-duet","git","github","co-author","pairing","pair programming","mob programming","extreme programming","xp","social coding"],author:"Richard Kotze",license:"MIT",contributors:[{name:"Richard Kotze",url:"https://github.com/rkotze"},{name:"Dennis Ideler",url:"https://github.com/dideler"}],dependencies:{"@inquirer/checkbox":"^4.1.4","common-tags":"^1.8.2","git-mob-core":"^0.10.1",minimist:"^1.2.8","update-notifier":"^7.3.1"},devDependencies:{"@ava/typescript":"^5.0.0","@types/common-tags":"^1.8.4","@types/minimist":"^1.2.5","@types/node":"^22.13.14","@types/sinon":"^17.0.4","@types/update-notifier":"^6.0.8",ava:"^6.2.0",bob:"file:../bob",coffee:"^5.5.1",eol:"^0.10.0",rimraf:"^6.0.1",sinon:"^20.0.0",tempy:"^3.1.0",typescript:"^5.8.2"},ava:{files:["dist/**/*.spec.js"],require:["./test-helpers/env.cjs"],"watchMode.ignoreChanges":["dist","test-env","test-helpers"],typescript:{rewritePaths:{"src/":"build/"},compile:!1},nodeArguments:["--experimental-vm-modules"]}};var M=1e3*60*60*24*7;function l(){let t=P` Usage $ git mob <co-author-initials> <GitHub username> $ git solo $ git mob-print $ git add-coauthor <co-author-initials> "Coauthor Name" <coauthor-email-address> $ git suggest-coauthors [author name | author email] Options -h Prints usage information -v Prints current version -l Prints list of available co-authors -o Overwrite the main author -p Print path to .git-coauthors file Examples $ git mob jd # Set John Doe as co-author $ git mob jd am # Set John & Amy as co-authors $ git mob rkotze # Set co-author from GitHub username $ git mob -l # Show a list of all co-authors $ git mob -o jd # Will change main author to jd $ git solo # Dissipate the mob $ git mob-print # Prints git-mob template to stdout. Used for prepare-commit-msg hook. `;console.log(t)}function g(){console.log(c.version)}function h(t=M){L({pkg:c,updateCheckInterval:t}).notify({isGlobal:!0})}function p(t){console.log(t.map(o=>`${o.key}, ${o.name}, ${o.email}`).join(C))}import f from"node:os";function d({name:t,email:o}){let e="";return(t===""||o==="")&&(e="Warning: Missing information for the primary author. Set with:"),t===""&&(e+=f.EOL+'$ git config --global user.name "Jane Doe"'),o===""&&(e+=f.EOL+'$ git config --global user.email "jane@example.com"'),e}var b={red:"\x1B[31m",yellow:"\x1B[33m"},w="\x1B[0m";function n(t){return b.red+t+w}function u(t){return b.yellow+t+w}import{fetchGitHubAuthors as G,saveNewCoAuthors as H,gitMobConfig as S}from"git-mob-core";async function y(t,o,e=G,r=H){if(!await S.fetchFromGitHub())return[];let i=T(t,o);if(i.length>0){let m=await e(i,"git-mob-cli");return await r(m),m.map(E=>E.toString())}return[]}function T(t,o){return t.filter(e=>!O(e,o))}function O(t,o){return o.some(e=>e.key===t)}h();var _=D(process.argv.slice(2),{boolean:["h","v","l","o","p"],alias:{h:"help",v:"version",l:"list",o:"override",p:"coauthors-path"}});await q(_).catch(()=>null);async function q(t){if(t.help&&(l(),process.exit(0)),t.version&&(g(),process.exit(0)),t["coauthors-path"]&&(console.log(await B()),process.exit(0)),t.list&&(await K(),process.exit(0)),await W.insideWorkTree()||(console.error(n("Error: not a Git repository")),process.exit(1)),t.override){let e=t._.shift();e&&await Z(e),await A(t._)}else await A(t._)}async function A(t){if(t.length===0){let o=await v(),[e,r,s]=await Promise.all([a(),$.localTemplate(),k.getLocalCommitTemplate()]),i=await R(e);x(o,i,r,s),s&&i&&await J(i)}else await V(t)}function x(t,o,e,r){let s=t||new N("","",""),i=d(s);i&&(console.log(n(i)),process.exit(1)),console.log(s.toString()),o&&o.length>0&&console.log(o.join(z.EOL)),!e&&r&&console.log(u(U`Warning: Git Mob uses Git global config. Using local commit.template could mean your template does not have selected co-authors appended after switching projects. See: https://github.com/rkotze/git-mob/discussions/81`))}async function K(){try{let t=await a();p(t)}catch(t){console.error(n(`listCoAuthors error: ${t.message}`)),process.exit(1)}}async function V(t){try{let o=await a();await y(t,o);let e=await I(t),[r,s]=await Promise.all([$.localTemplate(),k.getLocalCommitTemplate()]),i=await v();x(i,e,r,s)}catch(o){let e=o;console.error(n(`setMob error: ${e.message}`)),e.message.includes("not found!")&&console.log(u('Run "git config --global git-mob-config.github-fetch true" to fetch GitHub authors.')),process.exit(1)}}async function Z(t){try{let e=(await a()).find(r=>r.key===t);if(!e)throw new Error(`${t} author key not found!`);await F(e)}catch(o){console.error(n(`setAuthor error: ${o.message}`)),process.exit(1)}}