@boses/github-clone 1.1.5 → 1.1.6
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/dist/gitClone.esm.js +1 -1
- package/dist/gitClone.esm.js.map +1 -1
- package/dist/gitClone.js +1 -1
- package/dist/gitClone.js.map +1 -1
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/src/gitClone.d.ts +2 -1
- package/package.json +1 -1
package/dist/gitClone.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{execSync as t,spawnSync as r}from"child_process";import i from"process";import"path";const o=(o,e)=>{if(!(()=>{try{return t("git --version"),!0}catch(t){return!1}})())throw new Error("Git does not exist!");if(!(t=>!!/^(https:\/\/github\.com\/|git@github\.com:)[\s\S]+\/[\s\S]+(\.git)?$/.exec(t))(o))throw new Error(`The current URL ${o} is not in a valid GitHub clone format!`);const{
|
|
1
|
+
import{execSync as t,spawnSync as r}from"child_process";import i from"process";import"path";const o=(o,e)=>{if(!(()=>{try{return t("git --version"),!0}catch(t){return!1}})())throw new Error("Git does not exist!");if(!(t=>!!/^(https:\/\/github\.com\/|git@github\.com:)[\s\S]+\/[\s\S]+(\.git)?$/.exec(t))(o))throw new Error(`The current URL ${o} is not in a valid GitHub clone format!`);const{dirName:s,branch:c,cwd:n=i.cwd(),mirrorAddress:h,silence:g}=e||{};((t,i)=>{const o=t.split(" "),e=o.shift()||"",s=r(e,o,i);if(s.error)throw s.error})(["git","clone",h?((t,r)=>{let i=t;if(i.startsWith("git@")){const[,t,r]=i.match(/^git@github\.com:([\s\S]+)\/([\s\S]+)\.git$/)||[];i=`https://github.com/${t}/${r}.git`}return i.endsWith(".git")||(i+=".git"),i=i.replace("github.com",r),i})(o,h):o,`${s||""}`,c?`--branch ${c}`:""].filter((t=>t)).join(" "),{cwd:n,stdio:g?"pipe":"inherit"})};export{o as default};
|
|
2
2
|
//# sourceMappingURL=gitClone.esm.js.map
|
package/dist/gitClone.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gitClone.esm.js","sources":["../src/utils.ts","../src/gitClone.ts"],"sourcesContent":["import path from 'path';\nimport { execSync } from 'child_process';\n\n/**\n * 替换git的远程推送源地址,这里暂定origin名称为固定的\n */\nexport const setGitSource = (dir: string, url: string) => {\n // 仓库所在文件地址\n const dirPath = path.join(process.cwd(), dir);\n // 先删除在执行\n const shellStr = `git remote set-url origin ${url}`;\n execSync(shellStr, { cwd: dirPath });\n};\n\n/**\n * 根据github的url返回对应的文件夹名称\n * https://github.com.cnpmjs.org/bosens-China/github-clone会返回github-clone\n *\n */\nexport const getDir = (url: string) => {\n const str = url;\n const dir = str.split('/').pop() || '';\n return dir.includes('.git') ? dir.slice(0, dir.indexOf('.git')) : dir;\n};\n\n/* 是否为支持的git clone拉取格式\n * https://github.com/bosens-China/breeze-cli\n * https://github.com/bosens-China/breeze-cli.git\n * git@github.com:bosens-China/breeze-cli.git\n */\nexport const isGithubLink = (url: string) => {\n const reg = /^(https:\\/\\/github\\.com\\/|git@github\\.com:)[\\s\\S]+\\/[\\s\\S]+(\\.git)?$/;\n return !!reg.exec(url);\n};\n\n/**\n * 将当前的网站替换成镜像网站,例如\n * https://github.com/bosens-China/github-clone会被替换成\n * https://github.com.cnpmjs.org/bosens-China/github-clone\n */\n\nexport const replaceMirror = (currentWebsite: string, replaceWebsite: string) => {\n let s = currentWebsite;\n // 这里处理一下以git@开头的情况,如果git@开头,把用户名和仓库提取出来,用https的形式拉取\n // https://github.com/bosens-China/breeze-cli.git\n // git@github.com:bosens-China/breeze-cli.git\n if (s.startsWith('git@')) {\n const [, name, warehouse] = s.match(/^git@github\\.com:([\\s\\S]+)\\/([\\s\\S]+)\\.git$/) || [];\n s = `https://github.com/${name}/${warehouse}.git`;\n }\n if (!s.endsWith('.git')) {\n s += '.git';\n }\n s = s.replace('github.com', replaceWebsite);\n return s;\n};\n","import { execSync, spawnSync, SpawnSyncOptionsWithBufferEncoding } from 'child_process';\nimport process from 'process';\nimport { isGithubLink, replaceMirror } from './utils';\n\n/**\n * 判断git是否存在\n */\nconst gitExist = () => {\n try {\n execSync(`git --version`);\n return true;\n } catch {\n return false;\n }\n};\n\nconst pull = (shellStr: string, option?: SpawnSyncOptionsWithBufferEncoding) => {\n const args = shellStr.split(' ');\n const name = args.shift() || '';\n const info = spawnSync(name, args, option);\n if (info.error) {\n throw info.error;\n }\n return info;\n};\ninterface Options {\n
|
|
1
|
+
{"version":3,"file":"gitClone.esm.js","sources":["../src/utils.ts","../src/gitClone.ts"],"sourcesContent":["import path from 'path';\nimport { execSync } from 'child_process';\n\n/**\n * 替换git的远程推送源地址,这里暂定origin名称为固定的\n */\nexport const setGitSource = (dir: string, url: string) => {\n // 仓库所在文件地址\n const dirPath = path.join(process.cwd(), dir);\n // 先删除在执行\n const shellStr = `git remote set-url origin ${url}`;\n execSync(shellStr, { cwd: dirPath });\n};\n\n/**\n * 根据github的url返回对应的文件夹名称\n * https://github.com.cnpmjs.org/bosens-China/github-clone会返回github-clone\n *\n */\nexport const getDir = (url: string) => {\n const str = url;\n const dir = str.split('/').pop() || '';\n return dir.includes('.git') ? dir.slice(0, dir.indexOf('.git')) : dir;\n};\n\n/* 是否为支持的git clone拉取格式\n * https://github.com/bosens-China/breeze-cli\n * https://github.com/bosens-China/breeze-cli.git\n * git@github.com:bosens-China/breeze-cli.git\n */\nexport const isGithubLink = (url: string) => {\n const reg = /^(https:\\/\\/github\\.com\\/|git@github\\.com:)[\\s\\S]+\\/[\\s\\S]+(\\.git)?$/;\n return !!reg.exec(url);\n};\n\n/**\n * 将当前的网站替换成镜像网站,例如\n * https://github.com/bosens-China/github-clone会被替换成\n * https://github.com.cnpmjs.org/bosens-China/github-clone\n */\n\nexport const replaceMirror = (currentWebsite: string, replaceWebsite: string) => {\n let s = currentWebsite;\n // 这里处理一下以git@开头的情况,如果git@开头,把用户名和仓库提取出来,用https的形式拉取\n // https://github.com/bosens-China/breeze-cli.git\n // git@github.com:bosens-China/breeze-cli.git\n if (s.startsWith('git@')) {\n const [, name, warehouse] = s.match(/^git@github\\.com:([\\s\\S]+)\\/([\\s\\S]+)\\.git$/) || [];\n s = `https://github.com/${name}/${warehouse}.git`;\n }\n if (!s.endsWith('.git')) {\n s += '.git';\n }\n s = s.replace('github.com', replaceWebsite);\n return s;\n};\n","import { execSync, spawnSync, SpawnSyncOptionsWithBufferEncoding } from 'child_process';\nimport process from 'process';\nimport { isGithubLink, replaceMirror } from './utils';\n\n/**\n * 判断git是否存在\n */\nconst gitExist = () => {\n try {\n execSync(`git --version`);\n return true;\n } catch {\n return false;\n }\n};\n\nconst pull = (shellStr: string, option?: SpawnSyncOptionsWithBufferEncoding) => {\n const args = shellStr.split(' ');\n const name = args.shift() || '';\n const info = spawnSync(name, args, option);\n if (info.error) {\n throw info.error;\n }\n return info;\n};\ninterface Options {\n dirName: string;\n branch: string;\n mirrorAddress: string;\n cwd: string;\n silence: boolean;\n}\n\nconst clone = (url: string, options?: Partial<Options>) => {\n if (!gitExist()) {\n throw new Error(`Git does not exist!`);\n }\n if (!isGithubLink(url)) {\n throw new Error(`The current URL ${url} is not in a valid GitHub clone format!`);\n }\n const { dirName, branch, cwd = process.cwd(), mirrorAddress, silence } = options || {};\n // 如果存在镜像网站就替换一下格式\n const template = mirrorAddress ? replaceMirror(url, mirrorAddress) : url;\n const shellArr = ['git', 'clone', template, `${dirName || ''}`, branch ? `--branch ${branch}` : ''];\n const shell = shellArr.filter((f) => f).join(' ');\n pull(shell, { cwd, stdio: silence ? 'pipe' : 'inherit' });\n};\n\nexport default clone;\n"],"names":["clone","url","options","execSync","gitExist","Error","exec","isGithubLink","dirName","branch","cwd","process","mirrorAddress","silence","shellStr","option","args","split","name","shift","info","spawnSync","error","pull","currentWebsite","replaceWebsite","s","startsWith","warehouse","match","endsWith","replace","replaceMirror","filter","f","join","stdio"],"mappings":"4FA8BO,MCGDA,EAAQ,CAACC,EAAaC,KAC1B,IA3Be,MACf,IAEE,OADAC,EAAS,kBACF,EACP,SACA,OAAO,IAsBJC,GACH,MAAM,IAAIC,MAAM,uBAElB,IDP0B,CAACJ,KACf,uEACCK,KAAKL,GCKbM,CAAaN,GAChB,MAAM,IAAII,MAAM,mBAAmBJ,4CAErC,MAAMO,QAAEA,EAAOC,OAAEA,EAAMC,IAAEA,EAAMC,EAAQD,MAAKE,cAAEA,EAAaC,QAAEA,GAAYX,GAAW,GAxBzE,EAACY,EAAkBC,KAC9B,MAAMC,EAAOF,EAASG,MAAM,KACtBC,EAAOF,EAAKG,SAAW,GACvBC,EAAOC,EAAUH,EAAMF,EAAMD,GACnC,GAAIK,EAAKE,MACP,MAAMF,EAAKE,OAwBbC,CAFiB,CAAC,MAAO,QADRX,EDDU,EAACY,EAAwBC,KACpD,IAAIC,EAAIF,EAIR,GAAIE,EAAEC,WAAW,QAAS,CACxB,OAAST,EAAMU,GAAaF,EAAEG,MAAM,gDAAkD,GACtFH,EAAI,sBAAsBR,KAAQU,QAMpC,OAJKF,EAAEI,SAAS,UACdJ,GAAK,QAEPA,EAAIA,EAAEK,QAAQ,aAAcN,GACrBC,GCZ0BM,CAAc/B,EAAKW,GAAiBX,EACzB,GAAGO,GAAW,KAAMC,EAAS,YAAYA,IAAW,IACzEwB,QAAQC,GAAMA,IAAGC,KAAK,KACjC,CAAEzB,IAAAA,EAAK0B,MAAOvB,EAAU,OAAS"}
|
package/dist/gitClone.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var t=require("child_process"),r=require("process");function e(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}require("path");var i=e(r);module.exports=(r,e)=>{if(!(()=>{try{return t.execSync("git --version"),!0}catch(t){return!1}})())throw new Error("Git does not exist!");if(!(t=>!!/^(https:\/\/github\.com\/|git@github\.com:)[\s\S]+\/[\s\S]+(\.git)?$/.exec(t))(r))throw new Error(`The current URL ${r} is not in a valid GitHub clone format!`);const{
|
|
1
|
+
"use strict";var t=require("child_process"),r=require("process");function e(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}require("path");var i=e(r);module.exports=(r,e)=>{if(!(()=>{try{return t.execSync("git --version"),!0}catch(t){return!1}})())throw new Error("Git does not exist!");if(!(t=>!!/^(https:\/\/github\.com\/|git@github\.com:)[\s\S]+\/[\s\S]+(\.git)?$/.exec(t))(r))throw new Error(`The current URL ${r} is not in a valid GitHub clone format!`);const{dirName:o,branch:c,cwd:s=i.default.cwd(),mirrorAddress:n,silence:h}=e||{};((r,e)=>{const i=r.split(" "),o=i.shift()||"",c=t.spawnSync(o,i,e);if(c.error)throw c.error})(["git","clone",n?((t,r)=>{let e=t;if(e.startsWith("git@")){const[,t,r]=e.match(/^git@github\.com:([\s\S]+)\/([\s\S]+)\.git$/)||[];e=`https://github.com/${t}/${r}.git`}return e.endsWith(".git")||(e+=".git"),e=e.replace("github.com",r),e})(r,n):r,`${o||""}`,c?`--branch ${c}`:""].filter((t=>t)).join(" "),{cwd:s,stdio:h?"pipe":"inherit"})};
|
|
2
2
|
//# sourceMappingURL=gitClone.js.map
|
package/dist/gitClone.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gitClone.js","sources":["../src/gitClone.ts","../src/utils.ts"],"sourcesContent":["import { execSync, spawnSync, SpawnSyncOptionsWithBufferEncoding } from 'child_process';\nimport process from 'process';\nimport { isGithubLink, replaceMirror } from './utils';\n\n/**\n * 判断git是否存在\n */\nconst gitExist = () => {\n try {\n execSync(`git --version`);\n return true;\n } catch {\n return false;\n }\n};\n\nconst pull = (shellStr: string, option?: SpawnSyncOptionsWithBufferEncoding) => {\n const args = shellStr.split(' ');\n const name = args.shift() || '';\n const info = spawnSync(name, args, option);\n if (info.error) {\n throw info.error;\n }\n return info;\n};\ninterface Options {\n
|
|
1
|
+
{"version":3,"file":"gitClone.js","sources":["../src/gitClone.ts","../src/utils.ts"],"sourcesContent":["import { execSync, spawnSync, SpawnSyncOptionsWithBufferEncoding } from 'child_process';\nimport process from 'process';\nimport { isGithubLink, replaceMirror } from './utils';\n\n/**\n * 判断git是否存在\n */\nconst gitExist = () => {\n try {\n execSync(`git --version`);\n return true;\n } catch {\n return false;\n }\n};\n\nconst pull = (shellStr: string, option?: SpawnSyncOptionsWithBufferEncoding) => {\n const args = shellStr.split(' ');\n const name = args.shift() || '';\n const info = spawnSync(name, args, option);\n if (info.error) {\n throw info.error;\n }\n return info;\n};\ninterface Options {\n dirName: string;\n branch: string;\n mirrorAddress: string;\n cwd: string;\n silence: boolean;\n}\n\nconst clone = (url: string, options?: Partial<Options>) => {\n if (!gitExist()) {\n throw new Error(`Git does not exist!`);\n }\n if (!isGithubLink(url)) {\n throw new Error(`The current URL ${url} is not in a valid GitHub clone format!`);\n }\n const { dirName, branch, cwd = process.cwd(), mirrorAddress, silence } = options || {};\n // 如果存在镜像网站就替换一下格式\n const template = mirrorAddress ? replaceMirror(url, mirrorAddress) : url;\n const shellArr = ['git', 'clone', template, `${dirName || ''}`, branch ? `--branch ${branch}` : ''];\n const shell = shellArr.filter((f) => f).join(' ');\n pull(shell, { cwd, stdio: silence ? 'pipe' : 'inherit' });\n};\n\nexport default clone;\n","import path from 'path';\nimport { execSync } from 'child_process';\n\n/**\n * 替换git的远程推送源地址,这里暂定origin名称为固定的\n */\nexport const setGitSource = (dir: string, url: string) => {\n // 仓库所在文件地址\n const dirPath = path.join(process.cwd(), dir);\n // 先删除在执行\n const shellStr = `git remote set-url origin ${url}`;\n execSync(shellStr, { cwd: dirPath });\n};\n\n/**\n * 根据github的url返回对应的文件夹名称\n * https://github.com.cnpmjs.org/bosens-China/github-clone会返回github-clone\n *\n */\nexport const getDir = (url: string) => {\n const str = url;\n const dir = str.split('/').pop() || '';\n return dir.includes('.git') ? dir.slice(0, dir.indexOf('.git')) : dir;\n};\n\n/* 是否为支持的git clone拉取格式\n * https://github.com/bosens-China/breeze-cli\n * https://github.com/bosens-China/breeze-cli.git\n * git@github.com:bosens-China/breeze-cli.git\n */\nexport const isGithubLink = (url: string) => {\n const reg = /^(https:\\/\\/github\\.com\\/|git@github\\.com:)[\\s\\S]+\\/[\\s\\S]+(\\.git)?$/;\n return !!reg.exec(url);\n};\n\n/**\n * 将当前的网站替换成镜像网站,例如\n * https://github.com/bosens-China/github-clone会被替换成\n * https://github.com.cnpmjs.org/bosens-China/github-clone\n */\n\nexport const replaceMirror = (currentWebsite: string, replaceWebsite: string) => {\n let s = currentWebsite;\n // 这里处理一下以git@开头的情况,如果git@开头,把用户名和仓库提取出来,用https的形式拉取\n // https://github.com/bosens-China/breeze-cli.git\n // git@github.com:bosens-China/breeze-cli.git\n if (s.startsWith('git@')) {\n const [, name, warehouse] = s.match(/^git@github\\.com:([\\s\\S]+)\\/([\\s\\S]+)\\.git$/) || [];\n s = `https://github.com/${name}/${warehouse}.git`;\n }\n if (!s.endsWith('.git')) {\n s += '.git';\n }\n s = s.replace('github.com', replaceWebsite);\n return s;\n};\n"],"names":["url","options","execSync","gitExist","Error","exec","isGithubLink","dirName","branch","cwd","process","mirrorAddress","silence","shellStr","option","args","split","name","shift","info","spawnSync","error","pull","currentWebsite","replaceWebsite","s","startsWith","warehouse","match","endsWith","replace","replaceMirror","filter","f","join","stdio"],"mappings":"mLAiCc,CAACA,EAAaC,KAC1B,IA3Be,MACf,IAEE,OADAC,WAAS,kBACF,EACP,SACA,OAAO,IAsBJC,GACH,MAAM,IAAIC,MAAM,uBAElB,ICP0B,CAACJ,KACf,uEACCK,KAAKL,GDKbM,CAAaN,GAChB,MAAM,IAAII,MAAM,mBAAmBJ,4CAErC,MAAMO,QAAEA,EAAOC,OAAEA,EAAMC,IAAEA,EAAMC,UAAQD,MAAKE,cAAEA,EAAaC,QAAEA,GAAYX,GAAW,GAxBzE,EAACY,EAAkBC,KAC9B,MAAMC,EAAOF,EAASG,MAAM,KACtBC,EAAOF,EAAKG,SAAW,GACvBC,EAAOC,YAAUH,EAAMF,EAAMD,GACnC,GAAIK,EAAKE,MACP,MAAMF,EAAKE,OAwBbC,CAFiB,CAAC,MAAO,QADRX,ECDU,EAACY,EAAwBC,KACpD,IAAIC,EAAIF,EAIR,GAAIE,EAAEC,WAAW,QAAS,CACxB,OAAST,EAAMU,GAAaF,EAAEG,MAAM,gDAAkD,GACtFH,EAAI,sBAAsBR,KAAQU,QAMpC,OAJKF,EAAEI,SAAS,UACdJ,GAAK,QAEPA,EAAIA,EAAEK,QAAQ,aAAcN,GACrBC,GDZ0BM,CAAc/B,EAAKW,GAAiBX,EACzB,GAAGO,GAAW,KAAMC,EAAS,YAAYA,IAAW,IACzEwB,QAAQC,GAAMA,IAAGC,KAAK,KACjC,CAAEzB,IAAAA,EAAK0B,MAAOvB,EAAU,OAAS"}
|
package/dist/main.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var e=require("commander"),t=require("os"),r=require("path"),o=require("fs"),i=require("./gitClone"),c=require("child_process");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=n(t),a=n(r),u=n(o),l=n(i);const d=s.default.homedir(),g=a.default.join(d,".g.config"),h="github.com.cnpmjs.org",m=()=>u.default.existsSync(g)&&u.default.readFileSync(g,"utf-8")||h,p=new e.Command;p.version("1.1.
|
|
2
|
+
"use strict";var e=require("commander"),t=require("os"),r=require("path"),o=require("fs"),i=require("./gitClone"),c=require("child_process");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=n(t),a=n(r),u=n(o),l=n(i);const d=s.default.homedir(),g=a.default.join(d,".g.config"),h="github.com.cnpmjs.org",m=()=>u.default.existsSync(g)&&u.default.readFileSync(g,"utf-8")||h,p=new e.Command;p.version("1.1.6","-v, --version","输出当前版本号"),p.command("clone <url> [warehouse]").description("根据url拉取指定仓库").option("-b, --branch <value>","拉取指定分支").action(((e,t,{branch:r}={})=>{try{l.default(e,{dirName:t,branch:r,mirrorAddress:m()});const o=t||(e=>{const t=e.split("/").pop()||"";return t.includes(".git")?t.slice(0,t.indexOf(".git")):t})(m()?((e,t)=>{let r=e;if(r.startsWith("git@")){const[,e,t]=r.match(/^git@github\.com:([\s\S]+)\/([\s\S]+)\.git$/)||[];r=`https://github.com/${e}/${t}.git`}return r.endsWith(".git")||(r+=".git"),r=r.replace("github.com",t),r})(e,m()):e);((e,t)=>{const r=a.default.join(process.cwd(),e),o=`git remote set-url origin ${t}`;c.execSync(o,{cwd:r})})(o,e)}catch(e){console.error(`${e instanceof Error?e.message:e}`)}})),p.command("set [path]").description(`修改github的镜像仓库地址,<path>可选,如果省略,默认为: ${h}`).action(((e=h)=>{try{t=e,u.default.writeFileSync(g,t),console.log(`set ${e}成功`)}catch(e){console.error("set path error")}var t})),p.command("get [path]").description("读取当前的默认镜像地址").action((()=>{const e=m();console.log(`当前镜像地址为:${e}`)})),p.parse(process.argv);
|
|
3
3
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sources":["../src/config.ts","../src/main.ts","../src/utils.ts"],"sourcesContent":["import os from 'os';\nimport path from 'path';\nimport fs from 'fs';\n\nconst dir = os.homedir();\nconst configPath = path.join(dir, '.g.config');\n\n// 默认github镜像网站\nexport const DEFAULTPATH = 'github.com.cnpmjs.org';\n\n/**\n * 读取配置\n *\n */\nexport const getAddress = () => {\n if (!fs.existsSync(configPath)) {\n return DEFAULTPATH;\n }\n return fs.readFileSync(configPath, 'utf-8') || DEFAULTPATH;\n};\n\n/**\n * 设置配置\n *\n */\nexport const setAddress = (address: string) => {\n fs.writeFileSync(configPath, address);\n};\n","#!/usr/bin/env node\n\nimport { Command } from 'commander';\nimport { version } from '../package.json';\nimport { getAddress, setAddress, DEFAULTPATH } from './config';\nimport GitClone from './gitClone';\nimport { setGitSource, getDir, replaceMirror } from './utils';\n\nconst program = new Command();\nprogram.version(version, '-v, --version', '输出当前版本号');\n// git clone 支持多个命令,但是这里只让他支持-b也就是拉取指定分支,非必填\nprogram\n .command('clone <url> [warehouse]')\n .description('根据url拉取指定仓库')\n .option('-b, --branch <value>', '拉取指定分支')\n .action((url,
|
|
1
|
+
{"version":3,"file":"main.js","sources":["../src/config.ts","../src/main.ts","../src/utils.ts"],"sourcesContent":["import os from 'os';\nimport path from 'path';\nimport fs from 'fs';\n\nconst dir = os.homedir();\nconst configPath = path.join(dir, '.g.config');\n\n// 默认github镜像网站\nexport const DEFAULTPATH = 'github.com.cnpmjs.org';\n\n/**\n * 读取配置\n *\n */\nexport const getAddress = () => {\n if (!fs.existsSync(configPath)) {\n return DEFAULTPATH;\n }\n return fs.readFileSync(configPath, 'utf-8') || DEFAULTPATH;\n};\n\n/**\n * 设置配置\n *\n */\nexport const setAddress = (address: string) => {\n fs.writeFileSync(configPath, address);\n};\n","#!/usr/bin/env node\n\nimport { Command } from 'commander';\nimport { version } from '../package.json';\nimport { getAddress, setAddress, DEFAULTPATH } from './config';\nimport GitClone from './gitClone';\nimport { setGitSource, getDir, replaceMirror } from './utils';\n\nconst program = new Command();\nprogram.version(version, '-v, --version', '输出当前版本号');\n// git clone 支持多个命令,但是这里只让他支持-b也就是拉取指定分支,非必填\nprogram\n .command('clone <url> [warehouse]')\n .description('根据url拉取指定仓库')\n .option('-b, --branch <value>', '拉取指定分支')\n .action((url, dirName, { branch } = {}) => {\n try {\n // 开始拉取\n GitClone(url, { dirName, branch, mirrorAddress: getAddress() });\n // 拉取成功之后,进入拉取目录修改推送源地址\n const directory = dirName || getDir(getAddress() ? replaceMirror(url, getAddress()) : url);\n setGitSource(directory, url);\n } catch (e) {\n console.error(`${e instanceof Error ? e.message : e}`);\n }\n });\n\nprogram\n .command('set [path]')\n .description(`修改github的镜像仓库地址,<path>可选,如果省略,默认为: ${DEFAULTPATH}`)\n .action((pathUrl = DEFAULTPATH) => {\n try {\n setAddress(pathUrl);\n console.log(`set ${pathUrl}成功`);\n } catch {\n console.error(`set path error`);\n }\n });\nprogram\n .command('get [path]')\n .description(`读取当前的默认镜像地址`)\n .action(() => {\n const path = getAddress();\n console.log(`当前镜像地址为:${path}`);\n });\nprogram.parse(process.argv);\n","import path from 'path';\nimport { execSync } from 'child_process';\n\n/**\n * 替换git的远程推送源地址,这里暂定origin名称为固定的\n */\nexport const setGitSource = (dir: string, url: string) => {\n // 仓库所在文件地址\n const dirPath = path.join(process.cwd(), dir);\n // 先删除在执行\n const shellStr = `git remote set-url origin ${url}`;\n execSync(shellStr, { cwd: dirPath });\n};\n\n/**\n * 根据github的url返回对应的文件夹名称\n * https://github.com.cnpmjs.org/bosens-China/github-clone会返回github-clone\n *\n */\nexport const getDir = (url: string) => {\n const str = url;\n const dir = str.split('/').pop() || '';\n return dir.includes('.git') ? dir.slice(0, dir.indexOf('.git')) : dir;\n};\n\n/* 是否为支持的git clone拉取格式\n * https://github.com/bosens-China/breeze-cli\n * https://github.com/bosens-China/breeze-cli.git\n * git@github.com:bosens-China/breeze-cli.git\n */\nexport const isGithubLink = (url: string) => {\n const reg = /^(https:\\/\\/github\\.com\\/|git@github\\.com:)[\\s\\S]+\\/[\\s\\S]+(\\.git)?$/;\n return !!reg.exec(url);\n};\n\n/**\n * 将当前的网站替换成镜像网站,例如\n * https://github.com/bosens-China/github-clone会被替换成\n * https://github.com.cnpmjs.org/bosens-China/github-clone\n */\n\nexport const replaceMirror = (currentWebsite: string, replaceWebsite: string) => {\n let s = currentWebsite;\n // 这里处理一下以git@开头的情况,如果git@开头,把用户名和仓库提取出来,用https的形式拉取\n // https://github.com/bosens-China/breeze-cli.git\n // git@github.com:bosens-China/breeze-cli.git\n if (s.startsWith('git@')) {\n const [, name, warehouse] = s.match(/^git@github\\.com:([\\s\\S]+)\\/([\\s\\S]+)\\.git$/) || [];\n s = `https://github.com/${name}/${warehouse}.git`;\n }\n if (!s.endsWith('.git')) {\n s += '.git';\n }\n s = s.replace('github.com', replaceWebsite);\n return s;\n};\n"],"names":["dir","os","homedir","configPath","path","join","DEFAULTPATH","getAddress","fs","existsSync","readFileSync","program","Command","version","command","description","option","action","url","dirName","branch","GitClone","mirrorAddress","directory","split","pop","includes","slice","indexOf","getDir","currentWebsite","replaceWebsite","s","startsWith","name","warehouse","match","endsWith","replace","replaceMirror","dirPath","process","cwd","shellStr","execSync","setGitSource","e","console","error","Error","message","pathUrl","address","writeFileSync","log","parse","argv"],"mappings":";qPAIA,MAAMA,EAAMC,UAAGC,UACTC,EAAaC,UAAKC,KAAKL,EAAK,aAGrBM,EAAc,wBAMdC,EAAa,IACnBC,UAAGC,WAAWN,IAGZK,UAAGE,aAAaP,EAAY,UAF1BG,ECRLK,EAAU,IAAIC,UACpBD,EAAQE,gBAAiB,gBAAiB,WAE1CF,EACGG,QAAQ,2BACRC,YAAY,eACZC,OAAO,uBAAwB,UAC/BC,QAAO,CAACC,EAAKC,GAAWC,OAAAA,GAAW,MAClC,IAEEC,UAASH,EAAK,CAAEC,QAAAA,EAASC,OAAAA,EAAQE,cAAef,MAEhD,MAAMgB,EAAYJ,GCDF,CAACD,IACrB,MACMlB,EADMkB,EACIM,MAAM,KAAKC,OAAS,GACpC,OAAOzB,EAAI0B,SAAS,QAAU1B,EAAI2B,MAAM,EAAG3B,EAAI4B,QAAQ,SAAW5B,GDFjC6B,CAAOtB,ICqBb,EAACuB,EAAwBC,KACpD,IAAIC,EAAIF,EAIR,GAAIE,EAAEC,WAAW,QAAS,CACxB,OAASC,EAAMC,GAAaH,EAAEI,MAAM,gDAAkD,GACtFJ,EAAI,sBAAsBE,KAAQC,QAMpC,OAJKH,EAAEK,SAAS,UACdL,GAAK,QAEPA,EAAIA,EAAEM,QAAQ,aAAcP,GACrBC,GDlCgDO,CAAcrB,EAAKX,KAAgBW,GCdhE,EAAClB,EAAakB,KAExC,MAAMsB,EAAUpC,UAAKC,KAAKoC,QAAQC,MAAO1C,GAEnC2C,EAAW,6BAA6BzB,IAC9C0B,WAASD,EAAU,CAAED,IAAKF,KDUtBK,CAAatB,EAAWL,GACxB,MAAO4B,GACPC,QAAQC,MAAM,GAAGF,aAAaG,MAAQH,EAAEI,QAAUJ,SAIxDnC,EACGG,QAAQ,cACRC,YAAY,sCAAsCT,KAClDW,QAAO,CAACkC,EAAU7C,KACjB,IDNuB8C,ECOVD,EDNf3C,UAAG6C,cAAclD,EAAYiD,GCOzBL,QAAQO,IAAI,OAAOH,OACnB,SACAJ,QAAQC,MAAM,kBDVM,IAACI,KCa3BzC,EACGG,QAAQ,cACRC,YAAY,eACZE,QAAO,KACN,MAAMb,EAAOG,IACbwC,QAAQO,IAAI,WAAWlD,QAE3BO,EAAQ4C,MAAMd,QAAQe"}
|
package/dist/src/gitClone.d.ts
CHANGED