@boses/github-clone 1.1.0 → 1.1.4
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/License +21 -21
- package/README.md +53 -89
- 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/config.d.ts +11 -0
- package/dist/src/gitClone.d.ts +8 -0
- package/dist/src/main.d.ts +2 -0
- package/dist/src/utils.d.ts +17 -0
- package/package.json +2 -2
- package/dist/gitClone.d.ts +0 -76
package/License
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) [2021] [boses]
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) [2021] [boses]
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,151 +1,115 @@
|
|
|
1
1
|
# GitHub-clone
|
|
2
2
|
|
|
3
|
-
  
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
为了解决国内 GitHub clone 速度慢较慢的工具
|
|
6
6
|
|
|
7
|
-
>
|
|
7
|
+
> 注意以下文档书写形式遵循下述规范:
|
|
8
8
|
>
|
|
9
|
-
> `[]`代表这个字段必填,`<>`则为选填,而`name?:string
|
|
9
|
+
> `[]`代表这个字段必填,`<>`则为选填,而`name?:string`,表示这个参数为非必填为`string`类型。
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## 执行流程
|
|
12
12
|
|
|
13
13
|
- 首先将输入的 `github.com`替换成设置的镜像网站地址,默认为(github.com.cnpmjs.org)
|
|
14
14
|
- 执行 `git clone [url]` 的操作
|
|
15
15
|
- 拉取镜像完成之后,重写 git 的远程仓库推送地址,将镜像推送地址重置为 github 的镜像地址
|
|
16
16
|
|
|
17
|
-
## 使用方式
|
|
17
|
+
## CLI 使用方式
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
### CLI
|
|
19
|
+
### 安装
|
|
22
20
|
|
|
23
21
|
```sh
|
|
24
22
|
yarn global add @boses/github-clone
|
|
25
23
|
```
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
#### 用法
|
|
30
|
-
|
|
31
|
-
**clone <path> [dir] <--branch [branchName]>**
|
|
32
|
-
|
|
33
|
-
`<path>`
|
|
34
|
-
|
|
35
|
-
- type:`stirng`
|
|
36
|
-
- require:`true`
|
|
25
|
+
之后通过`g clone <path>`形式来使用,更多`API`和`clone`的使用方法可以调用`g ---help`查看。
|
|
37
26
|
|
|
38
|
-
|
|
27
|
+
### API
|
|
39
28
|
|
|
40
|
-
|
|
29
|
+
#### Clone
|
|
41
30
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
2. https://github.com/bosens-China/github-clone.git
|
|
31
|
+
**clone <path> [dir] <--branch [branchName]>**
|
|
45
32
|
|
|
46
|
-
|
|
33
|
+
- `<path>`
|
|
47
34
|
|
|
48
|
-
|
|
35
|
+
- type:`stirng`
|
|
36
|
+
- require:`true`
|
|
49
37
|
|
|
50
|
-
|
|
38
|
+
拉取 GitHub 仓库 对应的地址,可以拉取以下三种类型地址
|
|
51
39
|
|
|
52
|
-
|
|
40
|
+
| 类型 | 说明 |
|
|
41
|
+
| ------------------------------------------------ | ----------------------------- |
|
|
42
|
+
| https://github.com/bosens-China/github-clone | 默认浏览器导航栏的地址 |
|
|
43
|
+
| https://github.com/bosens-China/github-clone.git | Github 右侧 Code HTTPS 的地址 |
|
|
44
|
+
| git@github.com:bosens-China/breeze-clone.git | Github 右侧 Code SSH 的地址 |
|
|
53
45
|
|
|
54
|
-
-
|
|
55
|
-
- require:`false`
|
|
46
|
+
- `[dir]`
|
|
56
47
|
|
|
57
|
-
|
|
48
|
+
- type:`stirng`
|
|
49
|
+
- require:`false`
|
|
58
50
|
|
|
59
|
-
|
|
51
|
+
clone 到本地的目录名称
|
|
60
52
|
|
|
61
|
-
|
|
53
|
+
- `--branch [branchName]`
|
|
62
54
|
|
|
63
|
-
- type:`stirng`
|
|
64
|
-
- require:`false`
|
|
55
|
+
- type:`stirng`
|
|
56
|
+
- require:`false`
|
|
65
57
|
|
|
66
|
-
指定拉取的分支名称,可以以`--branch`长形式使用也可以以`-b`的短形式使用,例如:
|
|
58
|
+
指定拉取的分支名称,可以以`--branch`长形式使用也可以以`-b`的短形式使用,例如:
|
|
67
59
|
|
|
68
|
-
```sh
|
|
69
|
-
g clone https://github.com/bosens-China/github-clone.git -b dev
|
|
70
|
-
```
|
|
60
|
+
```sh
|
|
61
|
+
g clone https://github.com/bosens-China/github-clone.git -b dev
|
|
62
|
+
```
|
|
71
63
|
|
|
72
64
|
#### set [url]
|
|
73
65
|
|
|
74
|
-
`[url]`
|
|
66
|
+
- `[url]`
|
|
75
67
|
|
|
76
|
-
- type:`stirng`
|
|
77
|
-
- require:`
|
|
68
|
+
- type:`stirng`
|
|
69
|
+
- require:`true`
|
|
78
70
|
|
|
79
|
-
用于配置镜像网站
|
|
71
|
+
用于配置镜像网站
|
|
80
72
|
|
|
81
73
|
#### get
|
|
82
74
|
|
|
83
75
|
返回用户配置的`set [url]`地址,默认为`github.com.cnpmjs.org`
|
|
84
76
|
|
|
85
|
-
|
|
77
|
+
## Node
|
|
78
|
+
|
|
79
|
+
### 安装
|
|
86
80
|
|
|
87
81
|
```sh
|
|
88
82
|
yarn add @boses/github-clone
|
|
89
83
|
```
|
|
90
84
|
|
|
91
|
-
使用方式
|
|
92
|
-
|
|
93
85
|
```js
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
github.
|
|
86
|
+
const clone = require('@boses/github-clone');
|
|
87
|
+
// 也可以通过es模块引用
|
|
88
|
+
// import clone from '@boses/github-clone/gitClone.esm'
|
|
89
|
+
clone('https://github.com/SunshowerC/blog');
|
|
97
90
|
```
|
|
98
91
|
|
|
99
92
|
> clone 会以同步的形式运行,记得使用 `try` 包裹住可能的错误
|
|
100
93
|
|
|
101
|
-
|
|
94
|
+
### API
|
|
102
95
|
|
|
103
|
-
|
|
96
|
+
`clone: (url: string, options: Partial<Options>) => void`
|
|
97
|
+
|
|
98
|
+
#### url
|
|
104
99
|
|
|
105
100
|
- type:`string`
|
|
106
101
|
- require: `true`
|
|
107
102
|
|
|
108
103
|
拉取的 GitHub 仓库地址
|
|
109
104
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
- type:`string`
|
|
113
|
-
- require:`false`
|
|
114
|
-
|
|
115
|
-
拉取的目录名称
|
|
116
|
-
|
|
117
|
-
**branch**
|
|
118
|
-
|
|
119
|
-
- type:`string`
|
|
120
|
-
- require:`false`
|
|
121
|
-
|
|
122
|
-
拉取的分支名称
|
|
123
|
-
|
|
124
|
-
#### 方法
|
|
125
|
-
|
|
126
|
-
**gitExist(): boolean**
|
|
127
|
-
|
|
128
|
-
判断 git 是否存在
|
|
129
|
-
|
|
130
|
-
**clone(cwd?: string): void**
|
|
131
|
-
|
|
132
|
-
git clone 拉取路径
|
|
133
|
-
|
|
134
|
-
**isGithubLink(url: string): boolean**
|
|
135
|
-
|
|
136
|
-
判断是否为支持的 GitHub 地址,目前只支持上面列举的三种
|
|
137
|
-
|
|
138
|
-
**replaceMirror(currentWebsite: string, replaceWebsite: string): string**
|
|
139
|
-
|
|
140
|
-
返回被替换的镜像网站地址
|
|
141
|
-
|
|
142
|
-
例如传递 https://github.com/bosens-China/github-clone 会被替换成 https://github.com.cnpmjs.org/bosens-China/github-clone
|
|
143
|
-
|
|
144
|
-
**getDir(url?: string): string**
|
|
145
|
-
|
|
146
|
-
根据 Github 地址返回默认的文件夹名称
|
|
105
|
+
#### options
|
|
147
106
|
|
|
148
|
-
|
|
107
|
+
| 名称 | 类型 | 是否必填 | 描述 |
|
|
108
|
+
| ------------- | --------- | -------- | ------------------------------------------ |
|
|
109
|
+
| dir | `string` | `false` | 拉取的目录名称 |
|
|
110
|
+
| branch | `string` | `false` | 拉取的分支名称 |
|
|
111
|
+
| mirrorAddress | `string` | `false` | 镜像网站,如果你需要使用镜像可以填写此网站 |
|
|
112
|
+
| silence | `boolean` | `false` | 是否静默模式执行 clone |
|
|
149
113
|
|
|
150
114
|
## 其他
|
|
151
115
|
|
package/dist/gitClone.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{execSync as t,spawnSync as r}from"child_process";import
|
|
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{dir:s,branch:c,mirrorAddress:h,silence:n}=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?` ${s}`:""}${c?` --branch ${c}`:""}`,{cwd:i.cwd(),stdio:n?"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":["../node_modules/@babel/runtime/helpers/esm/arrayLikeToArray.js","../node_modules/@babel/runtime/helpers/esm/slicedToArray.js","../node_modules/@babel/runtime/helpers/esm/arrayWithHoles.js","../node_modules/@babel/runtime/helpers/esm/iterableToArrayLimit.js","../node_modules/@babel/runtime/helpers/esm/unsupportedIterableToArray.js","../node_modules/@babel/runtime/helpers/esm/nonIterableRest.js","../node_modules/@babel/runtime/helpers/esm/defineProperty.js","../node_modules/@babel/runtime/helpers/esm/createClass.js","../src/gitClone.ts","../node_modules/@babel/runtime/helpers/esm/classCallCheck.js"],"sourcesContent":["export default function _arrayLikeToArray(arr, len) {\n if (len == null || len > arr.length) len = arr.length;\n\n for (var i = 0, arr2 = new Array(len); i < len; i++) {\n arr2[i] = arr[i];\n }\n\n return arr2;\n}","import arrayWithHoles from \"./arrayWithHoles.js\";\nimport iterableToArrayLimit from \"./iterableToArrayLimit.js\";\nimport unsupportedIterableToArray from \"./unsupportedIterableToArray.js\";\nimport nonIterableRest from \"./nonIterableRest.js\";\nexport default function _slicedToArray(arr, i) {\n return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || unsupportedIterableToArray(arr, i) || nonIterableRest();\n}","export default function _arrayWithHoles(arr) {\n if (Array.isArray(arr)) return arr;\n}","export default function _iterableToArrayLimit(arr, i) {\n var _i = arr == null ? null : typeof Symbol !== \"undefined\" && arr[Symbol.iterator] || arr[\"@@iterator\"];\n\n if (_i == null) return;\n var _arr = [];\n var _n = true;\n var _d = false;\n\n var _s, _e;\n\n try {\n for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {\n _arr.push(_s.value);\n\n if (i && _arr.length === i) break;\n }\n } catch (err) {\n _d = true;\n _e = err;\n } finally {\n try {\n if (!_n && _i[\"return\"] != null) _i[\"return\"]();\n } finally {\n if (_d) throw _e;\n }\n }\n\n return _arr;\n}","import arrayLikeToArray from \"./arrayLikeToArray.js\";\nexport default function _unsupportedIterableToArray(o, minLen) {\n if (!o) return;\n if (typeof o === \"string\") return arrayLikeToArray(o, minLen);\n var n = Object.prototype.toString.call(o).slice(8, -1);\n if (n === \"Object\" && o.constructor) n = o.constructor.name;\n if (n === \"Map\" || n === \"Set\") return Array.from(o);\n if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return arrayLikeToArray(o, minLen);\n}","export default function _nonIterableRest() {\n throw new TypeError(\"Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\");\n}","export default function _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}","function _defineProperties(target, props) {\n for (var i = 0; i < props.length; i++) {\n var descriptor = props[i];\n descriptor.enumerable = descriptor.enumerable || false;\n descriptor.configurable = true;\n if (\"value\" in descriptor) descriptor.writable = true;\n Object.defineProperty(target, descriptor.key, descriptor);\n }\n}\n\nexport default function _createClass(Constructor, protoProps, staticProps) {\n if (protoProps) _defineProperties(Constructor.prototype, protoProps);\n if (staticProps) _defineProperties(Constructor, staticProps);\n return Constructor;\n}","import { execSync, spawnSync } from 'child_process';\nimport process from 'process';\n\nexport interface Option {\n url: string;\n dir?: string;\n branch?: string;\n}\n\nclass GitClone {\n public option: Option;\n\n public constructor(option: Option) {\n this.option = {\n ...option,\n };\n }\n\n /**\n * 判断git是否存在\n *\n * @memberof GitClone\n */\n public gitExist() {\n try {\n execSync(`git --version`);\n return true;\n } catch {\n return false;\n }\n }\n\n public clone(cwd = process.cwd()) {\n const { url, dir, branch } = this.option;\n if (!this.isGithubLink(url)) {\n throw new Error(\n `${url} 不是有效链接,目前支持三种格式:\\nhttps://github.com/bosens-China/github-clone\\nhttps://github.com/bosens-China/github-clone.git\\ngit@github.com:bosens-China/breeze-clone.git`,\n );\n }\n if (!this.gitExist()) {\n throw new Error(`git在当前环境不存在,请安装后继续 https://git-scm.com/`);\n }\n const shell = `git clone ${url}${dir ? ` ${dir}` : ''}${branch ? ` --branch ${branch}` : ''}`;\n this.pull(shell, cwd);\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 */\n public 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 * @param {string} currentWebsite\n * @param {string} replaceWebsite\n * @memberof GitClone\n */\n public 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\n /**\n * 根据github的url返回对应的文件夹名称\n * https://github.com.cnpmjs.org/bosens-China/github-clone会返回github-clone\n *\n * @param {string} url\n * @memberof GitClone\n */\n public getDir(url?: string) {\n const str = url || this.option.url;\n const dir = str.split('/').pop() || '';\n return dir.includes('.git') ? dir.slice(0, dir.indexOf('.git')) : dir;\n }\n\n /**\n * 执行git clone拉取\n *\n * @private\n * @param {string} shellStr\n * @memberof GitClone\n */\n private pull(shellStr: string, cwd?: string) {\n const args = shellStr.split(' ');\n const name = args.shift() || '';\n // 关键 { stdio: 'inherit' }\n const info = spawnSync(name, args, { stdio: 'inherit', cwd });\n if (info.error) {\n throw info.error;\n }\n return info;\n }\n}\n\nexport default GitClone;\n","export default function _classCallCheck(instance, Constructor) {\n if (!(instance instanceof Constructor)) {\n throw new TypeError(\"Cannot call a class as a function\");\n }\n}"],"names":["_arrayLikeToArray","arr","len","length","i","arr2","Array","_slicedToArray","isArray","arrayWithHoles","_i","Symbol","iterator","_s","_e","_arr","_n","_d","call","next","done","push","value","err","iterableToArrayLimit","o","minLen","arrayLikeToArray","n","Object","prototype","toString","slice","constructor","name","from","test","unsupportedIterableToArray","TypeError","nonIterableRest","_defineProperty","obj","key","defineProperty","enumerable","configurable","writable","_defineProperties","target","props","descriptor","GitClone","option","instance","Constructor","protoProps","staticProps","execSync","cwd","process","this","url","dir","branch","isGithubLink","Error","gitExist","shell","pull","exec","currentWebsite","replaceWebsite","s","startsWith","match","warehouse","endsWith","replace","split","pop","includes","indexOf","shellStr","args","shift","info","spawnSync","stdio","error"],"mappings":"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"}
|
|
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 dir: string;\n branch: string;\n mirrorAddress: 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 { dir, branch, mirrorAddress, silence } = options || {};\n // 如果存在镜像网站就替换一下格式\n const template = mirrorAddress ? replaceMirror(url, mirrorAddress) : url;\n const shell = `git clone ${template}${dir ? ` ${dir}` : ''}${branch ? ` --branch ${branch}` : ''}`;\n pull(shell, { cwd: process.cwd(), stdio: silence ? 'pipe' : 'inherit' });\n};\n\nexport default clone;\n"],"names":["clone","url","options","execSync","gitExist","Error","exec","isGithubLink","dir","branch","mirrorAddress","silence","shellStr","option","args","split","name","shift","info","spawnSync","error","pull","currentWebsite","replaceWebsite","s","startsWith","warehouse","match","endsWith","replace","replaceMirror","cwd","process","stdio"],"mappings":"4FA8BO,MCEDA,EAAQ,CAACC,EAAaC,KAC1B,IA1Be,MACf,IAEE,OADAC,EAAS,kBACF,EACP,SACA,OAAO,IAqBJC,GACH,MAAM,IAAIC,MAAM,uBAElB,IDN0B,CAACJ,KACf,uEACCK,KAAKL,GCIbM,CAAaN,GAChB,MAAM,IAAII,MAAM,mBAAmBJ,4CAErC,MAAMO,IAAEA,EAAGC,OAAEA,EAAMC,cAAEA,EAAaC,QAAEA,GAAYT,GAAW,GAvBhD,EAACU,EAAkBC,KAC9B,MAAMC,EAAOF,EAASG,MAAM,KACtBC,EAAOF,EAAKG,SAAW,GACvBC,EAAOC,EAAUH,EAAMF,EAAMD,GACnC,GAAIK,EAAKE,MACP,MAAMF,EAAKE,OAsBbC,CADc,aADGX,EDAU,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,GCb0BM,CAAc7B,EAAKS,GAAiBT,IAC/BO,EAAM,IAAIA,IAAQ,KAAKC,EAAS,aAAaA,IAAW,KAClF,CAAEsB,IAAKC,EAAQD,MAAOE,MAAOtB,EAAU,OAAS"}
|
package/dist/gitClone.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var t=require("child_process");function
|
|
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{dir:o,branch:c,mirrorAddress:s,silence:n}=e||{};((r,e)=>{const i=r.split(" "),o=i.shift()||"",c=t.spawnSync(o,i,e);if(c.error)throw c.error})(`git clone ${s?((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,s):r}${o?` ${o}`:""}${c?` --branch ${c}`:""}`,{cwd:i.default.cwd(),stdio:n?"pipe":"inherit"})};
|
|
2
2
|
//# sourceMappingURL=gitClone.js.map
|
package/dist/gitClone.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gitClone.js","sources":["../node_modules/@babel/runtime/helpers/esm/arrayLikeToArray.js","../node_modules/@babel/runtime/helpers/esm/slicedToArray.js","../node_modules/@babel/runtime/helpers/esm/arrayWithHoles.js","../node_modules/@babel/runtime/helpers/esm/iterableToArrayLimit.js","../node_modules/@babel/runtime/helpers/esm/unsupportedIterableToArray.js","../node_modules/@babel/runtime/helpers/esm/nonIterableRest.js","../node_modules/@babel/runtime/helpers/esm/defineProperty.js","../node_modules/@babel/runtime/helpers/esm/createClass.js","../src/gitClone.ts","../node_modules/@babel/runtime/helpers/esm/classCallCheck.js"],"sourcesContent":["export default function _arrayLikeToArray(arr, len) {\n if (len == null || len > arr.length) len = arr.length;\n\n for (var i = 0, arr2 = new Array(len); i < len; i++) {\n arr2[i] = arr[i];\n }\n\n return arr2;\n}","import arrayWithHoles from \"./arrayWithHoles.js\";\nimport iterableToArrayLimit from \"./iterableToArrayLimit.js\";\nimport unsupportedIterableToArray from \"./unsupportedIterableToArray.js\";\nimport nonIterableRest from \"./nonIterableRest.js\";\nexport default function _slicedToArray(arr, i) {\n return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || unsupportedIterableToArray(arr, i) || nonIterableRest();\n}","export default function _arrayWithHoles(arr) {\n if (Array.isArray(arr)) return arr;\n}","export default function _iterableToArrayLimit(arr, i) {\n var _i = arr == null ? null : typeof Symbol !== \"undefined\" && arr[Symbol.iterator] || arr[\"@@iterator\"];\n\n if (_i == null) return;\n var _arr = [];\n var _n = true;\n var _d = false;\n\n var _s, _e;\n\n try {\n for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {\n _arr.push(_s.value);\n\n if (i && _arr.length === i) break;\n }\n } catch (err) {\n _d = true;\n _e = err;\n } finally {\n try {\n if (!_n && _i[\"return\"] != null) _i[\"return\"]();\n } finally {\n if (_d) throw _e;\n }\n }\n\n return _arr;\n}","import arrayLikeToArray from \"./arrayLikeToArray.js\";\nexport default function _unsupportedIterableToArray(o, minLen) {\n if (!o) return;\n if (typeof o === \"string\") return arrayLikeToArray(o, minLen);\n var n = Object.prototype.toString.call(o).slice(8, -1);\n if (n === \"Object\" && o.constructor) n = o.constructor.name;\n if (n === \"Map\" || n === \"Set\") return Array.from(o);\n if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return arrayLikeToArray(o, minLen);\n}","export default function _nonIterableRest() {\n throw new TypeError(\"Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\");\n}","export default function _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}","function _defineProperties(target, props) {\n for (var i = 0; i < props.length; i++) {\n var descriptor = props[i];\n descriptor.enumerable = descriptor.enumerable || false;\n descriptor.configurable = true;\n if (\"value\" in descriptor) descriptor.writable = true;\n Object.defineProperty(target, descriptor.key, descriptor);\n }\n}\n\nexport default function _createClass(Constructor, protoProps, staticProps) {\n if (protoProps) _defineProperties(Constructor.prototype, protoProps);\n if (staticProps) _defineProperties(Constructor, staticProps);\n return Constructor;\n}","import { execSync, spawnSync } from 'child_process';\nimport process from 'process';\n\nexport interface Option {\n url: string;\n dir?: string;\n branch?: string;\n}\n\nclass GitClone {\n public option: Option;\n\n public constructor(option: Option) {\n this.option = {\n ...option,\n };\n }\n\n /**\n * 判断git是否存在\n *\n * @memberof GitClone\n */\n public gitExist() {\n try {\n execSync(`git --version`);\n return true;\n } catch {\n return false;\n }\n }\n\n public clone(cwd = process.cwd()) {\n const { url, dir, branch } = this.option;\n if (!this.isGithubLink(url)) {\n throw new Error(\n `${url} 不是有效链接,目前支持三种格式:\\nhttps://github.com/bosens-China/github-clone\\nhttps://github.com/bosens-China/github-clone.git\\ngit@github.com:bosens-China/breeze-clone.git`,\n );\n }\n if (!this.gitExist()) {\n throw new Error(`git在当前环境不存在,请安装后继续 https://git-scm.com/`);\n }\n const shell = `git clone ${url}${dir ? ` ${dir}` : ''}${branch ? ` --branch ${branch}` : ''}`;\n this.pull(shell, cwd);\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 */\n public 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 * @param {string} currentWebsite\n * @param {string} replaceWebsite\n * @memberof GitClone\n */\n public 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\n /**\n * 根据github的url返回对应的文件夹名称\n * https://github.com.cnpmjs.org/bosens-China/github-clone会返回github-clone\n *\n * @param {string} url\n * @memberof GitClone\n */\n public getDir(url?: string) {\n const str = url || this.option.url;\n const dir = str.split('/').pop() || '';\n return dir.includes('.git') ? dir.slice(0, dir.indexOf('.git')) : dir;\n }\n\n /**\n * 执行git clone拉取\n *\n * @private\n * @param {string} shellStr\n * @memberof GitClone\n */\n private pull(shellStr: string, cwd?: string) {\n const args = shellStr.split(' ');\n const name = args.shift() || '';\n // 关键 { stdio: 'inherit' }\n const info = spawnSync(name, args, { stdio: 'inherit', cwd });\n if (info.error) {\n throw info.error;\n }\n return info;\n }\n}\n\nexport default GitClone;\n","export default function _classCallCheck(instance, Constructor) {\n if (!(instance instanceof Constructor)) {\n throw new TypeError(\"Cannot call a class as a function\");\n }\n}"],"names":["_arrayLikeToArray","arr","len","length","i","arr2","Array","_slicedToArray","isArray","arrayWithHoles","_i","Symbol","iterator","_s","_e","_arr","_n","_d","call","next","done","push","value","err","iterableToArrayLimit","o","minLen","arrayLikeToArray","n","Object","prototype","toString","slice","constructor","name","from","test","unsupportedIterableToArray","TypeError","nonIterableRest","_defineProperty","obj","key","defineProperty","enumerable","configurable","writable","_defineProperties","target","props","descriptor","GitClone","option","instance","Constructor","protoProps","staticProps","execSync","cwd","process","this","url","dir","branch","isGithubLink","Error","gitExist","shell","pull","exec","currentWebsite","replaceWebsite","s","startsWith","match","warehouse","endsWith","replace","split","pop","includes","indexOf","shellStr","args","shift","info","spawnSync","stdio","error"],"mappings":"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"}
|
|
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 dir: string;\n branch: string;\n mirrorAddress: 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 { dir, branch, mirrorAddress, silence } = options || {};\n // 如果存在镜像网站就替换一下格式\n const template = mirrorAddress ? replaceMirror(url, mirrorAddress) : url;\n const shell = `git clone ${template}${dir ? ` ${dir}` : ''}${branch ? ` --branch ${branch}` : ''}`;\n pull(shell, { cwd: process.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","dir","branch","mirrorAddress","silence","shellStr","option","args","split","name","shift","info","spawnSync","error","pull","currentWebsite","replaceWebsite","s","startsWith","warehouse","match","endsWith","replace","replaceMirror","cwd","process","stdio"],"mappings":"mLAgCc,CAACA,EAAaC,KAC1B,IA1Be,MACf,IAEE,OADAC,WAAS,kBACF,EACP,SACA,OAAO,IAqBJC,GACH,MAAM,IAAIC,MAAM,uBAElB,ICN0B,CAACJ,KACf,uEACCK,KAAKL,GDIbM,CAAaN,GAChB,MAAM,IAAII,MAAM,mBAAmBJ,4CAErC,MAAMO,IAAEA,EAAGC,OAAEA,EAAMC,cAAEA,EAAaC,QAAEA,GAAYT,GAAW,GAvBhD,EAACU,EAAkBC,KAC9B,MAAMC,EAAOF,EAASG,MAAM,KACtBC,EAAOF,EAAKG,SAAW,GACvBC,EAAOC,YAAUH,EAAMF,EAAMD,GACnC,GAAIK,EAAKE,MACP,MAAMF,EAAKE,OAsBbC,CADc,aADGX,ECAU,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,GDb0BM,CAAc7B,EAAKS,GAAiBT,IAC/BO,EAAM,IAAIA,IAAQ,KAAKC,EAAS,aAAaA,IAAW,KAClF,CAAEsB,IAAKC,UAAQD,MAAOE,MAAOtB,EAAU,OAAS"}
|
package/dist/main.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var e=require("commander"),
|
|
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.3","-v, --version","输出当前版本号"),p.command("clone <url> [warehouse]").description("根据url拉取指定仓库").option("-b, --branch <value>","拉取指定分支").action(((e,t,{branch:r}={})=>{try{l.default(e,{dir: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/
|
|
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, dir, { branch } = {}) => {\n try {\n // 开始拉取\n GitClone(url, { dir, branch, mirrorAddress: getAddress() });\n // 拉取成功之后,进入拉取目录修改推送源地址\n const directory = dir || 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","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,EAAKlB,GAAOmB,OAAAA,GAAW,MAC9B,IAEEC,UAASF,EAAK,CAAElB,IAAAA,EAAKmB,OAAAA,EAAQE,cAAed,MAE5C,MAAMe,EAAYtB,GCDF,CAACkB,IACrB,MACMlB,EADMkB,EACIK,MAAM,KAAKC,OAAS,GACpC,OAAOxB,EAAIyB,SAAS,QAAUzB,EAAI0B,MAAM,EAAG1B,EAAI2B,QAAQ,SAAW3B,GDFrC4B,CAAOrB,ICqBT,EAACsB,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,GDlC4CO,CAAcpB,EAAKX,KAAgBW,GCd5D,EAAClB,EAAakB,KAExC,MAAMqB,EAAUnC,UAAKC,KAAKmC,QAAQC,MAAOzC,GAEnC0C,EAAW,6BAA6BxB,IAC9CyB,WAASD,EAAU,CAAED,IAAKF,KDUtBK,CAAatB,EAAWJ,GACxB,MAAO2B,GACPC,QAAQC,MAAM,GAAGF,aAAaG,MAAQH,EAAEI,QAAUJ,SAIxDlC,EACGG,QAAQ,cACRC,YAAY,sCAAsCT,KAClDW,QAAO,CAACiC,EAAU5C,KACjB,IDNuB6C,ECOVD,EDNf1C,UAAG4C,cAAcjD,EAAYgD,GCOzBL,QAAQO,IAAI,OAAOH,OACnB,SACAJ,QAAQC,MAAM,kBDVM,IAACI,KCa3BxC,EACGG,QAAQ,cACRC,YAAY,eACZE,QAAO,KACN,MAAMb,EAAOG,IACbuC,QAAQO,IAAI,WAAWjD,QAE3BO,EAAQ2C,MAAMd,QAAQe"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 替换git的远程推送源地址,这里暂定origin名称为固定的
|
|
3
|
+
*/
|
|
4
|
+
export declare const setGitSource: (dir: string, url: string) => void;
|
|
5
|
+
/**
|
|
6
|
+
* 根据github的url返回对应的文件夹名称
|
|
7
|
+
* https://github.com.cnpmjs.org/bosens-China/github-clone会返回github-clone
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
export declare const getDir: (url: string) => string;
|
|
11
|
+
export declare const isGithubLink: (url: string) => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* 将当前的网站替换成镜像网站,例如
|
|
14
|
+
* https://github.com/bosens-China/github-clone会被替换成
|
|
15
|
+
* https://github.com.cnpmjs.org/bosens-China/github-clone
|
|
16
|
+
*/
|
|
17
|
+
export declare const replaceMirror: (currentWebsite: string, replaceWebsite: string) => string;
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@boses/github-clone",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"main": "./dist/gitClone.js",
|
|
5
5
|
"module": "./dist/gitClone.esm.js",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bin": {
|
|
8
8
|
"g": "./dist/main.js"
|
|
9
9
|
},
|
|
10
|
-
"types": "./dist/gitClone.d.ts",
|
|
10
|
+
"types": "./dist/src/gitClone.d.ts",
|
|
11
11
|
"engines": {
|
|
12
12
|
"node": ">=10.6.0"
|
|
13
13
|
},
|
package/dist/gitClone.d.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
interface Option {
|
|
2
|
-
url: string;
|
|
3
|
-
dir?: string;
|
|
4
|
-
branch?: string;
|
|
5
|
-
}
|
|
6
|
-
declare class GitClone {
|
|
7
|
-
option: Option;
|
|
8
|
-
constructor(option: Option);
|
|
9
|
-
/**
|
|
10
|
-
* 判断git是否存在
|
|
11
|
-
*
|
|
12
|
-
* @memberof GitClone
|
|
13
|
-
*/
|
|
14
|
-
gitExist(): boolean;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* 执行拉取操作
|
|
18
|
-
*
|
|
19
|
-
* @param {string} [cwd]
|
|
20
|
-
* @memberof GitClone
|
|
21
|
-
*/
|
|
22
|
-
clone(cwd?: string): void;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* 是否为支持的git clone拉取格式,目前支持下面三种格式
|
|
26
|
-
*
|
|
27
|
-
* https://github.com/bosens-China/breeze-cli
|
|
28
|
-
*
|
|
29
|
-
* https://github.com/bosens-China/breeze-cli.git
|
|
30
|
-
*
|
|
31
|
-
* git@github.com:bosens-China/breeze-cli.git
|
|
32
|
-
*
|
|
33
|
-
* @param {string} url
|
|
34
|
-
* @return {*} {boolean}
|
|
35
|
-
* @memberof GitClone
|
|
36
|
-
*/
|
|
37
|
-
isGithubLink(url: string): boolean;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* 将当前的网站替换成镜像网站,例如
|
|
41
|
-
*
|
|
42
|
-
* https://github.com/bosens-China/github-clone
|
|
43
|
-
*
|
|
44
|
-
* 替换成
|
|
45
|
-
*
|
|
46
|
-
* https://github.com.cnpmjs.org/bosens-China/github-clone
|
|
47
|
-
*
|
|
48
|
-
* @param {string} currentWebsite
|
|
49
|
-
* @param {string} replaceWebsite
|
|
50
|
-
* @memberof GitClone
|
|
51
|
-
*/
|
|
52
|
-
|
|
53
|
-
replaceMirror(currentWebsite: string, replaceWebsite: string): string;
|
|
54
|
-
/**
|
|
55
|
-
* 根据github的url返回对应的文件夹名称
|
|
56
|
-
*
|
|
57
|
-
* 例如:https://github.com.cnpmjs.org/bosens-China/github-clone
|
|
58
|
-
*
|
|
59
|
-
* 返回 github-clone
|
|
60
|
-
*
|
|
61
|
-
* @param {string} url
|
|
62
|
-
* @memberof GitClone
|
|
63
|
-
*/
|
|
64
|
-
|
|
65
|
-
getDir(url?: string): string;
|
|
66
|
-
/**
|
|
67
|
-
* 执行git clone拉取
|
|
68
|
-
*
|
|
69
|
-
* @private
|
|
70
|
-
* @param {string} shellStr
|
|
71
|
-
* @memberof GitClone
|
|
72
|
-
*/
|
|
73
|
-
private pull;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export = GitClone;
|