@boses/github-clone 1.1.1 → 1.1.2

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 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
@@ -2,165 +2,114 @@
2
2
 
3
3
  ![mlt](https://img.shields.io/badge/License-MIT-brightgreen) ![mlt](https://img.shields.io/badge/npm-1.1.1-brightgreen)
4
4
 
5
- 解决国内 GitHub clone 速度慢的工具
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
- 目前支持 CLI 和 Node 两种方式
20
-
21
- ### CLI
19
+ ### 安装
22
20
 
23
21
  ```sh
24
22
  yarn global add @boses/github-clone
25
23
  ```
26
24
 
27
- 之后可以简单通过`g clone <path>`形式来使用,更多详细输出可以使用`g ---help`来查看
28
-
29
- #### 用法
30
-
31
- **clone <path> [dir] <--branch [branchName]>**
32
-
33
- `<path>`
25
+ 之后通过`g clone <path>`形式来使用,更多`API`和`clone`的使用方法可以调用`g ---help`查看。
34
26
 
35
- - type:`stirng`
36
- - require:`true`
27
+ ### API
37
28
 
38
- 拉取 GitHub 仓库 对应的地址,可以拉取以下三种类型地址
29
+ #### Clone
39
30
 
40
- 1. https://github.com/bosens-China/github-clone
41
-
42
- 默认浏览器导航栏的地址
43
-
44
- 2. https://github.com/bosens-China/github-clone.git
31
+ **clone <path> [dir] <--branch [branchName]>**
45
32
 
46
- Github 右侧 Code HTTPS 的地址
33
+ - `<path>`
47
34
 
48
- 3. git@github.com:bosens-China/breeze-clone.git
35
+ - type:`stirng`
36
+ - require:`true`
49
37
 
50
- Github 右侧 Code SSH 的地址
38
+ 拉取 GitHub 仓库 对应的地址,可以拉取以下三种类型地址
51
39
 
52
- `[dir]`
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
- - type:`stirng`
55
- - require:`false`
46
+ - `[dir]`
56
47
 
57
- clone 到本地的目录名称
48
+ - type:`stirng`
49
+ - require:`false`
58
50
 
59
- #### --branch [branchName]
51
+ clone 到本地的目录名称
60
52
 
61
- `[branchName]`
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:`false`
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
- ### Node
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 GithubClone = require('@boses/github-clone');
95
- const github = new GithubClone({ url: 'https://github.com/SunshowerC/blog' });
96
- github.clone();
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
- **url**
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
- **dir**
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
- 注意使用这个方法之前你应当判断一下环境和 url 是否有效,例如:
135
-
136
- ```js
137
- if (!gitClone.isGithubLink(url)) {
138
- console.error(
139
- `${url} 不是有效链接,目前支持三种格式:\nhttps://github.com/bosens-China/github-clone\nhttps://github.com/bosens-China/github-clone.git\ngit@github.com:bosens-China/breeze-clone.git`,
140
- );
141
- return;
142
- }
143
- if (!gitClone.gitExist()) {
144
- console.error(`git在当前环境不存在,请安装后继续 https://git-scm.com/`);
145
- return;
146
- }
147
- ```
148
-
149
- **isGithubLink(url: string): boolean**
150
-
151
- 判断是否为支持的 GitHub 地址,目前只支持上面列举的三种
152
-
153
- **replaceMirror(currentWebsite: string, replaceWebsite: string): string**
154
-
155
- 返回被替换的镜像网站地址
156
-
157
- 例如传递 https://github.com/bosens-China/github-clone 会被替换成 https://github.com.cnpmjs.org/bosens-China/github-clone
158
-
159
- **getDir(url?: string): string**
160
-
161
- 根据 Github 地址返回默认的文件夹名称
105
+ #### options
162
106
 
163
- 例如 https://github.com.cnpmjs.org/bosens-China/github-clone 会返回 github-clone
107
+ | 名称 | 类型 | 是否必填 | 描述 |
108
+ | ------------- | --------- | -------- | ------------------------------------------ |
109
+ | dir | `string` | `false` | 拉取的目录名称 |
110
+ | branch | `string` | `false` | 拉取的分支名称 |
111
+ | mirrorAddress | `string` | `false` | 镜像网站,如果你需要使用镜像可以填写此网站 |
112
+ | silence | `boolean` | `false` | 是否静默模式执行 clone |
164
113
 
165
114
  ## 其他
166
115
 
@@ -1,2 +1,2 @@
1
- import{execSync as t,spawnSync as r}from"child_process";import e from"process";function n(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}function o(t,r){return function(t){if(Array.isArray(t))return t}(t)||function(t,r){var e=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=e){var n,o,i=[],c=!0,a=!1;try{for(e=e.call(t);!(c=(n=e.next()).done)&&(i.push(n.value),!r||i.length!==r);c=!0);}catch(t){a=!0,o=t}finally{try{c||null==e.return||e.return()}finally{if(a)throw o}}return i}}(t,r)||function(t,r){if(t){if("string"==typeof t)return n(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?n(t,r):void 0}}(t,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(t,r,e){return r in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t}function c(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function a(t,r){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable}))),e.push.apply(e,n)}return e}var u=function(){function n(t){!function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,n),this.option=function(t){for(var r=1;r<arguments.length;r++){var e=null!=arguments[r]?arguments[r]:{};r%2?a(Object(e),!0).forEach((function(r){i(t,r,e[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(e)):a(Object(e)).forEach((function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(e,r))}))}return t}({},t)}var u,l,f;return u=n,l=[{key:"gitExist",value:function(){try{return t("git --version"),!0}catch(t){return!1}}},{key:"clone",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:e.cwd(),r=this.option,n=r.url,o=r.dir,i=r.branch,c="git clone ".concat(n).concat(o?" ".concat(o):"").concat(i?" --branch ".concat(i):"");this.pull(c,t)}},{key:"isGithubLink",value:function(t){return!!/^(https:\/\/github\.com\/|git@github\.com:)[\s\S]+\/[\s\S]+(\.git)?$/.exec(t)}},{key:"replaceMirror",value:function(t,r){var e=t;if(e.startsWith("git@")){var n=o(e.match(/^git@github\.com:([\s\S]+)\/([\s\S]+)\.git$/)||[],3),i=n[1],c=n[2];e="https://github.com/".concat(i,"/").concat(c,".git")}return e.endsWith(".git")||(e+=".git"),e=e.replace("github.com",r)}},{key:"getDir",value:function(t){var r=(t||this.option.url).split("/").pop()||"";return r.includes(".git")?r.slice(0,r.indexOf(".git")):r}},{key:"pull",value:function(t,e){var n=t.split(" "),o=n.shift()||"",i=r(o,n,{stdio:"inherit",cwd:e});if(i.error)throw i.error;return i}}],l&&c(u.prototype,l),f&&c(u,f),n}();export{u as default};
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
@@ -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 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","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 r(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var e=r(require("process"));function n(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}function i(t,r){return function(t){if(Array.isArray(t))return t}(t)||function(t,r){var e=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=e){var n,i,o=[],c=!0,u=!1;try{for(e=e.call(t);!(c=(n=e.next()).done)&&(o.push(n.value),!r||o.length!==r);c=!0);}catch(t){u=!0,i=t}finally{try{c||null==e.return||e.return()}finally{if(u)throw i}}return o}}(t,r)||function(t,r){if(t){if("string"==typeof t)return n(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?n(t,r):void 0}}(t,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(t,r,e){return r in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t}function c(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function u(t,r){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable}))),e.push.apply(e,n)}return e}var a=function(){function r(t){!function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,r),this.option=function(t){for(var r=1;r<arguments.length;r++){var e=null!=arguments[r]?arguments[r]:{};r%2?u(Object(e),!0).forEach((function(r){o(t,r,e[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(e)):u(Object(e)).forEach((function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(e,r))}))}return t}({},t)}var n,a,l;return n=r,a=[{key:"gitExist",value:function(){try{return t.execSync("git --version"),!0}catch(t){return!1}}},{key:"clone",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:e.default.cwd(),r=this.option,n=r.url,i=r.dir,o=r.branch,c="git clone ".concat(n).concat(i?" ".concat(i):"").concat(o?" --branch ".concat(o):"");this.pull(c,t)}},{key:"isGithubLink",value:function(t){return!!/^(https:\/\/github\.com\/|git@github\.com:)[\s\S]+\/[\s\S]+(\.git)?$/.exec(t)}},{key:"replaceMirror",value:function(t,r){var e=t;if(e.startsWith("git@")){var n=i(e.match(/^git@github\.com:([\s\S]+)\/([\s\S]+)\.git$/)||[],3),o=n[1],c=n[2];e="https://github.com/".concat(o,"/").concat(c,".git")}return e.endsWith(".git")||(e+=".git"),e=e.replace("github.com",r)}},{key:"getDir",value:function(t){var r=(t||this.option.url).split("/").pop()||"";return r.includes(".git")?r.slice(0,r.indexOf(".git")):r}},{key:"pull",value:function(r,e){var n=r.split(" "),i=n.shift()||"",o=t.spawnSync(i,n,{stdio:"inherit",cwd:e});if(o.error)throw o.error;return o}}],a&&c(n.prototype,a),l&&c(n,l),r}();module.exports=a;
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
@@ -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 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","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"),t=require("os"),o=require("path"),r=require("fs"),n=require("./gitClone"),i=require("child_process");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=c(t),s=c(o),u=c(r),l=c(n),h=a.default.homedir(),g=s.default.join(h,".g.config"),d="github.com.cnpmjs.org",f=function(){return u.default.existsSync(g)&&u.default.readFileSync(g,"utf-8")||d},m=function(e){u.default.writeFileSync(g,e)},p=function(e,t){var o=s.default.join(process.cwd(),e),r="git remote set-url origin ".concat(t);i.execSync(r,{cwd:o})},b=new e.Command;b.version("1.1.1","-v, --version","输出当前版本号"),b.command("clone <url> [warehouse]").description("根据url拉取指定仓库").option("-b, --branch <value>","拉取指定分支").action((function(e,t){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=o.branch,n=new l.default({url:e,branch:r,dir:t});if(n.isGithubLink(e))if(n.gitExist()){n.option.url=n.replaceMirror(e,f());try{n.clone();var i=t||n.getDir();p(i,e)}catch(e){console.error("".concat(e instanceof Error?e.message:e))}}else console.error("git在当前环境不存在,请安装后继续 https://git-scm.com/");else console.error("".concat(e," 不是有效链接,目前支持三种格式:\nhttps://github.com/bosens-China/github-clone\nhttps://github.com/bosens-China/github-clone.git\ngit@github.com:bosens-China/breeze-clone.git"))})),b.command("set [path]").description("修改github的镜像仓库地址,<path>可选,如果省略,默认为: ".concat(d)).action((function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:d;try{m(e)}catch(e){console.error("set path error")}})),b.command("get [path]").description("读取当前的默认镜像地址").action((function(){var e=f();console.log("当前镜像地址为:".concat(e))})),b.parse(process.argv);
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","-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/utils.ts","../src/main.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","import path from 'path';\n\nimport { execSync } from 'child_process';\n\n/**\n * 替换git的远程推送源地址,这里暂定origin名称为固定的\n *\n * @export\n * @param {string} dir\n * @param {string} url\n * @return {*}\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","#!/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 } 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 const gitClone = new GitClone({\n url,\n branch,\n dir,\n });\n if (!gitClone.isGithubLink(url)) {\n console.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 return;\n }\n if (!gitClone.gitExist()) {\n console.error(`git在当前环境不存在,请安装后继续 https://git-scm.com/`);\n return;\n }\n\n // 替换镜像地址\n gitClone.option.url = gitClone.replaceMirror(url, getAddress());\n try {\n // 开始拉取\n gitClone.clone();\n // 拉取成功之后,进入拉取目录修改推送源地址\n const directory = dir || gitClone.getDir();\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 } 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"],"names":["dir","os","homedir","configPath","path","join","DEFAULTPATH","getAddress","fs","existsSync","readFileSync","setAddress","address","writeFileSync","setGitSource","url","dirPath","process","cwd","shellStr","execSync","program","Command","version","command","description","option","action","branch","gitClone","GitClone","isGithubLink","gitExist","replaceMirror","clone","directory","getDir","e","console","error","Error","message","pathUrl","log","parse","argv"],"mappings":";qPAIMA,EAAMC,UAAGC,UACTC,EAAaC,UAAKC,KAAKL,EAAK,aAGrBM,EAAc,wBAMdC,EAAa,kBACnBC,UAAGC,WAAWN,IAGZK,UAAGE,aAAaP,EAAY,UAF1BG,GASEK,EAAa,SAACC,GACzBJ,UAAGK,cAAcV,EAAYS,ICdlBE,EAAe,SAACd,EAAae,OAElCC,EAAUZ,UAAKC,KAAKY,QAAQC,MAAOlB,GAEnCmB,sCAAwCJ,GAC9CK,WAASD,EAAU,CAAED,IAAKF,KCTtBK,EAAU,IAAIC,UACpBD,EAAQE,gBAAiB,gBAAiB,WAE1CF,EACGG,QAAQ,2BACRC,YAAY,eACZC,OAAO,uBAAwB,UAC/BC,QAAO,SAACZ,EAAKf,gEAAkB,GAAX4B,IAAAA,OACbC,EAAW,IAAIC,UAAS,CAC5Bf,IAAAA,EACAa,OAAAA,EACA5B,IAAAA,OAEG6B,EAASE,aAAahB,MAMtBc,EAASG,YAMdH,EAASH,OAAOX,IAAMc,EAASI,cAAclB,EAAKR,SAGhDsB,EAASK,YAEHC,EAAYnC,GAAO6B,EAASO,SAClCtB,EAAaqB,EAAWpB,GACxB,MAAOsB,GACPC,QAAQC,gBAASF,aAAaG,MAAQH,EAAEI,QAAUJ,UAblDC,QAAQC,sDANRD,QAAQC,gBACHxB,yKAsBXM,EACGG,QAAQ,cACRC,yDAAkDnB,IAClDqB,QAAO,eAACe,yDAAUpC,MAEfK,EAAW+B,GACX,SACAJ,QAAQC,4BAGdlB,EACGG,QAAQ,cACRC,2BACAE,QAAO,eACAvB,EAAOG,IACb+B,QAAQK,sBAAevC,OAE3BiB,EAAQuB,MAAM3B,QAAQ4B"}
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,11 @@
1
+ export declare const DEFAULTPATH = "github.com.cnpmjs.org";
2
+ /**
3
+ * 读取配置
4
+ *
5
+ */
6
+ export declare const getAddress: () => string;
7
+ /**
8
+ * 设置配置
9
+ *
10
+ */
11
+ export declare const setAddress: (address: string) => void;
@@ -0,0 +1,8 @@
1
+ interface Options {
2
+ dir: string;
3
+ branch: string;
4
+ mirrorAddress: string;
5
+ silence: boolean;
6
+ }
7
+ declare const clone: (url: string, options: Partial<Options>) => void;
8
+ export default clone;
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "@boses/github-clone",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "main": "./dist/gitClone.js",
5
5
  "module": "./dist/gitClone.esm.js",
6
6
  "license": "MIT",
@@ -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;