@savaryna/git-add-account 2.2.2 → 2.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/bin/main.js +7 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
🔐 A small CLI app that allows you to easily add multiple Git accounts on one machine. It switches between accounts automatically based on the workspace you are in.
|
|
4
4
|
|
|
5
|
+
## Agent usage (skill)
|
|
6
|
+
|
|
7
|
+
Add the skill using
|
|
8
|
+
|
|
9
|
+
```shell
|
|
10
|
+
npx skills add savaryna/git-add-account
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
and ask your agent to "add a new git account".
|
|
14
|
+
|
|
5
15
|
## CLI usage
|
|
6
16
|
|
|
7
17
|
Run the command direcly with
|
package/bin/main.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var T=Object.create;var
|
|
2
|
+
"use strict";var T=Object.create;var h=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var O=Object.getPrototypeOf,Y=Object.prototype.hasOwnProperty;var H=(e,i,n,s)=>{if(i&&typeof i=="object"||typeof i=="function")for(let t of I(i))!Y.call(e,t)&&t!==n&&h(e,t,{get:()=>i[t],enumerable:!(s=N(i,t))||s.enumerable});return e};var d=(e,i,n)=>(n=e!=null?T(O(e)):{},H(i||!e||!e.__esModule?h(n,"default",{value:e,enumerable:!0}):n,e));var S=d(require("yargs")),P=require("yargs/helpers");var G=require("os"),$=require("path"),u=d(require("prompts"));var C=require("child_process"),v=require("fs"),a=require("fs/promises"),g=require("os"),r=require("path"),k=require("util"),m=d(require("mustache"));var y=`
|
|
3
3
|
[includeIf "gitdir:{{{paths.workspace}}}/"]
|
|
4
4
|
path = {{{paths.gitConfig}}}
|
|
5
|
-
`;var
|
|
5
|
+
`;var b=`# Config for GIT account {{{configDetails.email}}}
|
|
6
6
|
[user]
|
|
7
7
|
name = {{{configDetails.name}}}
|
|
8
8
|
email = {{{configDetails.email}}}
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
[user]
|
|
21
21
|
signingkey = {{{paths.privateKey}}}
|
|
22
22
|
{{/configDetails.signYourWork}}
|
|
23
|
-
`;var
|
|
23
|
+
`;var w=`# Config for GIT account {{{configDetails.email}}}
|
|
24
24
|
Host {{{configDetails.host}}}
|
|
25
25
|
IgnoreUnknown AddKeysToAgent
|
|
26
26
|
HostName {{{configDetails.host}}}
|
|
@@ -28,15 +28,15 @@ Host {{{configDetails.host}}}
|
|
|
28
28
|
AddKeysToAgent yes
|
|
29
29
|
IdentitiesOnly yes
|
|
30
30
|
IdentityFile {{{paths.privateKey}}}
|
|
31
|
-
`;var
|
|
32
|
-
`)},
|
|
31
|
+
`;var p=require("zod"),z=(e,i)=>{let{success:n,error:s}=e.safeParse(i);return!n&&s.errors.map(({path:t,message:o})=>t.length?`${t}: ${o}`:o).join(`
|
|
32
|
+
`)},c=z;var L=(0,k.promisify)(C.exec);async function R(e){let i=`id_ed25519_git_${e.host}`,n=i,s=`${i}.pub`,t=(0,r.resolve)((0,g.tmpdir)(),n),o=(0,r.resolve)((0,g.tmpdir)(),s);await(0,a.rm)(t,{force:!0}),await(0,a.rm)(o,{force:!0}),await L(`ssh-keygen -t ed25519 -C "${e.email}" -f ${t} -N ""`);let f=await(0,a.readFile)(t,"utf8"),F=await(0,a.readFile)(o,"utf8");return await(0,a.rm)(t,{force:!0}),await(0,a.rm)(o,{force:!0}),{privateKeyName:n,publicKeyName:s,privateKey:f,publicKey:F}}var l=p.z.object({name:p.z.string().min(1),email:p.z.string().email(),host:p.z.string().refine(e=>e.includes(".")&&URL.canParse(`https://${e}`),{message:"Invalid host, must be a valid domain (e.g., github.com)"}),workspace:p.z.string().min(1).refine(e=>!(0,v.existsSync)(e),"Path already exists"),signYourWork:p.z.boolean()});async function K(e){let i=c(l,e);if(i)throw new Error(i);let n=await R(e),s=(0,r.resolve)(e.workspace),t=(0,r.resolve)(s,".config"),o={workspace:s,config:t,gitConfigGlobal:(0,r.resolve)((0,g.homedir)(),".gitconfig"),gitConfig:(0,r.resolve)(t,"gitconfig"),sshConfig:(0,r.resolve)(t,"sshconfig"),privateKey:(0,r.resolve)(t,n.privateKeyName),publicKey:(0,r.resolve)(t,n.publicKeyName)};return{gitConfigGlobal:{path:o.gitConfigGlobal,content:m.default.render(y,{configDetails:e,paths:o})},gitConfig:{path:o.gitConfig,content:m.default.render(b,{configDetails:e,paths:o})},sshConfig:{path:o.sshConfig,content:m.default.render(w,{configDetails:e,paths:o})},privateKey:{path:o.privateKey,content:n.privateKey,secret:!0},publicKey:{path:o.publicKey,content:n.publicKey}}}async function x(e,i){let n=(0,r.resolve)(e.workspace,".config");await(0,a.mkdir)(n,{recursive:!0});let s=Object.values(i).map(({path:t,content:o,secret:f})=>(0,a.appendFile)(t,o,{encoding:"utf8",mode:f?384:420}));await Promise.all(s)}var A={command:["$0","add"],describe:"Add a new Git account",builder:e=>e.option("name",{type:"string",describe:"Full name for Git commits (e.g., John Doe)"}).option("email",{type:"string",describe:"Email for this Git account"}).option("host",{type:"string",describe:"Git provider host (e.g., github.com, gitlab.com)"}).option("workspace",{type:"string",describe:"Absolute path to the workspace for this account"}).option("signYourWork",{type:"boolean",describe:"Sign commits and tags with your SSH key",default:!0}).option("non-interactive",{type:"boolean",describe:"Run in non-interactive mode, all required options must be provided"}).option("dry-run",{type:"boolean",describe:"Preview the generated config files without writing them to disk"}),handler:async e=>{console.log("Let's add a new Git account.");let i=[{type:"text",name:"name",message:"Full name for Git commits (e.g., John Doe):",validate:o=>c(l.shape.name,o)||!0},{type:"text",name:"email",message:"Email for this Git account:",validate:o=>c(l.shape.email,o)||!0},{type:"text",name:"host",message:"Git provider host (e.g., github.com, gitlab.com):",initial:o=>o.split("@")[1],validate:o=>c(l.shape.host,o)||!0},{type:"text",name:"workspace",message:"Absolute path to the workspace for this account:",initial:o=>(0,$.resolve)((0,G.homedir)(),"code",o),validate:o=>c(l.shape.workspace,o)||!0},{type:"toggle",name:"signYourWork",message:"Sign commits and tags with your SSH key?",initial:!0,active:"yes",inactive:"no"}],n={onCancel:()=>{throw new Error("Operation cancelled by the user.")}};if(e!=null&&e.nonInteractive){let o=c(l,e);if(o)throw new Error(o)}u.default.override(e);let s=await(0,u.default)(i,n),t=await K(s);if(e!=null&&e.dryRun){console.log(`
|
|
33
33
|
Config files that would be generated/updated:`);for(let o of Object.values(t))console.log(`
|
|
34
|
-
Path:`,o.path),console.log(o.secret?"[Content hidden for security]":o.content)}else await
|
|
34
|
+
Path:`,o.path),console.log(o.secret?"[Content hidden for security]":o.content)}else await x(s,t),console.log(`
|
|
35
35
|
Your public SSH key is:
|
|
36
36
|
${t.publicKey.content}`),console.log(`You can also find it here:
|
|
37
37
|
${t.publicKey.path}`),console.log(`
|
|
38
38
|
Next, add the key to ${s.host}:`),console.log("1. Copy the public SSH key above."),console.log(`2. Go to the SSH keys settings page on ${s.host}.`),console.log("3. Add the key as an 'Authentication Key'."),s.signYourWork&&console.log("4. Add the same key again as a 'Signing Key'."),console.log(`
|
|
39
|
-
Done! Any git command you run from '${s.workspace}',`),console.log("(and its subdirectories), will now use this new account.")}};var
|
|
39
|
+
Done! Any git command you run from '${s.workspace}',`),console.log("(and its subdirectories), will now use this new account.")}};var D=[A];(0,S.default)((0,P.hideBin)(process.argv)).scriptName("git-add-account").usage("$0 <command> [options]").command(D).demandCommand(0,1).help("h").alias("h","help").strict().fail((e,i,n)=>{e&&console.log(n.help()),console.log(`
|
|
40
40
|
${e||(i==null?void 0:i.message)}
|
|
41
41
|
`),console.log(`\u{1F635} Exited! Thanks for using @savaryna/git-add-account!
|
|
42
42
|
`),process.exit(1)}).parse();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@savaryna/git-add-account",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.3",
|
|
4
4
|
"description": "🔐 A small CLI app that allows you to easily add multiple Git accounts on one machine. It switches between accounts automatically based on the workspace you are in.",
|
|
5
5
|
"homepage": "https://github.com/savaryna/git-add-account#readme",
|
|
6
6
|
"keywords": [
|