Repository: aliyun/fun
Pull request #167 (2019-03-07 02:22:43)

git 克隆模板仓库最上面一层
如题


Patch:
diff --git a/lib/init/vcs.js b/lib/init/vcs.js
index cb6387c..a9c9778 100644
--- a/lib/init/vcs.js
+++ b/lib/init/vcs.js
@@ -33,12 +33,21 @@ function isVCSInstalled(repoType) {
 function makeSurePathExists(p) {
   if (fs.existsSync(p)) {
     return true;
-  } 
+  }
   if (makeSurePathExists(path.dirname(p))) {
     fs.mkdirSync(p);
     return true;
   }
-  
+
+}
+
+function cloneArguments(repoType, repoUrl) {
+  switch (repoType) {
+  case 'git':
+    return ['clone', '--depth=1', repoUrl];
+  default:
+    return ['clone', repoUrl];
+  }
 }
 
 async function clone(repoUrl, cloneToDir = '.', checkout) {
@@ -67,7 +76,7 @@ async function clone(repoUrl, cloneToDir = '.', checkout) {
   debug('repoDir is %s', repoDir);
   await promptForExistingPath(repoDir, `You've downloaded ${repoDir} before. Is it okay to delete and re-download it?`, true);
   console.log('start cloning...');
-  spawnSync(repoType, ['clone', repoUrl], { cmd: repoDir, stdio: 'inherit' });
+  spawnSync(repoType, cloneArguments(repoType, repoUrl), { cmd: repoDir, stdio: 'inherit' });
   console.log('finish cloning.');
 
   if (checkout) {
diff --git a/package-lock.json b/package-lock.json
index 030c2c8..5149caf 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -136,6 +136,15 @@
       "integrity": "sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw==",
       "dev": true
     },
+    "@sinonjs/commons": {
+      "version": "1.4.0",
+      "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.4.0.tgz",
+      "integrity": "sha512-9jHK3YF/8HtJ9wCAbG+j8cD0i0+ATS9A7gXFqS36TblLPNy6rEEc+SB0imo91eCboGaBYGV/MT1/br/J+EE7Tw==",
+      "dev": true,
+      "requires": {
+        "type-detect": "4.0.8"
+      }
+    },
     "@sinonjs/formatio": {
       "version": "2.0.0",
       "resolved": "http://registry.npmjs.org/@sinonjs/formatio/-/formatio-2.0.0.tgz",
@@ -145,14 +154,11 @@
         "samsam": "1.3.0"
       }
     },
-    "@sinonjs/samsam": {
-      "version": "2.1.0",
-      "resolved": "http://registry.npm.taobao.org/@sinonjs/samsam/download/@sinonjs/samsam-2.1.0.tgz",
-      "integrity": "sha1-uLj1uBlgW9Y2Aabt5FkVaIDzjqM=",
-      "dev": true,
-      "requires": {
-        "array-from": "^2.1.1"
-      }
+    "@sinonjs/text-encoding": {
+      "version": "0.7.1",
+      "resolved": "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.1.tgz",
+      "integrity": "sha512-+iTbntw2IZPb/anVDbypzfQa+ay64MW0Zo8aJ8gZPWMMK6/OubMVb6lUPMagqjOPnmtauXnFCACVl3O7ogjeqQ==",
+      "dev": true
     },
     "JSONStream": {
       "version": "1.3.2",
@@ -295,7 +301,7 @@
     },
     "array-flatten": {
       "version": "1.1.1",
-      "resolved": "http://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
+      "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
       "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI="
     },
     "array-from": {
@@ -611,7 +617,7 @@
     },
     "buffer": {
       "version": "4.9.1",
-      "resolved": "http://registry.npmjs.org/buffer/-/buffer-4.9.1.tgz",
+      "resolved": "https://registry.npmjs.org/buffer/-/buffer-4.9.1.tgz",
       "integrity": "sha1-bRu2AbB6TvztlwlBMgkwJ8lbwpg=",
       "requires": {
         "base64-js": "^1.0.2",
@@ -2355,7 +2361,7 @@
     },
     "int64-buffer": {
       "version": "0.1.9",
-      "resolved": "http://registry.npmjs.org/int64-buffer/-/int64-buffer-0.1.9.tgz",
+      "resolved": "https://registry.npmjs.org/int64-buffer/-/int64-buffer-0.1.9.tgz",
       "integrity": "sha1-ngOdoEOyT3ixlrKD4EZT716ZD2E="
     },
     "into-stream": {
@@ -2710,12 +2716,6 @@
         }
       }
     },
-    "just-extend": {
-      "version": "3.0.0",
-      "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-3.0.0.tgz",
-      "integrity": "sha512-Fu3T6pKBuxjWT/p4DkqGHFRsysc8OauWr4ZRTY9dIx07Y9O0RkoR5jcv28aeD1vuAwhm3nLkDurwLXoALp4DpQ==",
-      "dev": true
-    },
     "kind-of": {
       "version": "6.0.2",
       "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz",
@@ -2947,7 +2947,7 @@
     },
     "mkdirp": {
       "version": "0.5.1",
-      "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
+      "resolved": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
       "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
       "requires": {
         "minimist": "0.0.8"
@@ -3062,26 +3062,44 @@
       "integrity": "sha512-kgq1CuvLyUcbcIuTiCA93cQ2IJFSlRwXcN+hLcb2qLJwC2qrePHGZZa7IipyWqaWF6tQjdax2pQnVxdq19Zzwg=="
     },
     "nise": {
-      "version": "1.4.6",
-      "resolved": "https://registry.npmjs.org/nise/-/nise-1.4.6.tgz",
-      "integrity": "sha512-1GedetLKzmqmgwabuMSqPsT7oumdR77SBpDfNNJhADRIeA3LN/2RVqR4fFqwvzhAqcTef6PPCzQwITE/YQ8S8A==",
+      "version": "1.4.10",
+      "resolved": "https://registry.npmjs.org/nise/-/nise-1.4.10.tgz",
+      "integrity": "sha512-sa0RRbj53dovjc7wombHmVli9ZihXbXCQ2uH3TNm03DyvOSIQbxg+pbqDKrk2oxMK1rtLGVlKxcB9rrc6X5YjA==",
       "dev": true,
       "requires": {
-        "@sinonjs/formatio": "3.0.0",
-        "just-extend": "^3.0.0",
+        "@sinonjs/formatio": "^3.1.0",
+        "@sinonjs/text-encoding": "^0.7.1",
+        "just-extend": "^4.0.2",
         "lolex": "^2.3.2",
-        "path-to-regexp": "^1.7.0",
-        "text-encoding": "^0.6.4"
+        "path-to-regexp": "^1.7.0"
       },
       "dependencies": {
         "@sinonjs/formatio": {
-          "version": "3.0.0",
-          "resolved": "https://registry.npmjs.org/@sinonjs/formatio/-/formatio-3.0.0.tgz",
-          "integrity": "sha512-vdjoYLDptCgvtJs57ULshak3iJe4NW3sJ3g36xVDGff5AE8P30S6A093EIEPjdi2noGhfuNOEkbxt3J3awFW1w==",
+          "version": "3.2.1",
+          "resolved": "https://registry.npmjs.org/@sinonjs/formatio/-/formatio-3.2.1.tgz",
+          "integrity": "sha512-tsHvOB24rvyvV2+zKMmPkZ7dXX6LSLKZ7aOtXY6Edklp0uRcgGpOsQTTGTcWViFyx4uhWc6GV8QdnALbIbIdeQ==",
+          "dev": true,
+          "requires": {
+            "@sinonjs/commons": "^1",
+            "@sinonjs/samsam": "^3.1.0"
+          }
+        },
+        "@sinonjs/samsam": {
+          "version": "3.2.0",
+          "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-3.2.0.tgz",
+          "integrity": "sha512-j5F1rScewLtx6pbTK0UAjA3jJj4RYiSKOix53YWv+Jzy/AZ69qHxUpU8fwVLjyKbEEud9QrLpv6Ggs7WqTimYw==",
           "dev": true,
           "requires": {
-            "@sinonjs/samsam": "2.1.0"
+            "@sinonjs/commons": "^1.0.2",
+            "array-from": "^2.1.1",
+            "lodash": "^4.17.11"
           }
+        },
+        "just-extend": {
+          "version": "4.0.2",
+          "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-4.0.2.tgz",
+          "integrity": "sha512-FrLwOgm+iXrPV+5zDU6Jqu4gCRXbWEQg2O3SKONsWE4w7AXFRkryS53bpWdaL9cNol+AmR3AEYz6kn+o0fCPnw==",
+          "dev": true
         }
       }
     },
@@ -4397,9 +4415,9 @@
       }
     },
     "tablestore": {
-      "version": "4.2.0",
-      "resolved": "https://registry.npmjs.org/tablestore/-/tablestore-4.2.0.tgz",
-      "integrity": "sha512-usAhh7VA+ilP5qMNLFuj8V6NVbbCxeofHSjVkkFBJ1E4AZth//jC4k8O8n5ijKdee3ImboMrmJPs3GmjvBbObA==",
+      "version": "4.3.0",
+      "resolved": "https://registry.npmjs.org/tablestore/-/tablestore-4.3.0.tgz",
+      "integrity": "sha512-B2XelmC3hOO4qrtxRd5xsv+nbx3L8+xZ2ajPhqHRNCL1BUANFqQOPfQfH4Uhd3obEh4F3sThb2i6s4pG5gwj4g==",
       "requires": {
         "buffer": "4.9.1",
         "int64-buffer": "0.1.9",
@@ -4434,12 +4452,6 @@
       "integrity": "sha1-CnwOom06Oa+n4OvqnB/AvE2qAR0=",
       "dev": true
     },
-    "text-encoding": {
-      "version": "0.6.4",
-      "resolved": "https://registry.npmjs.org/text-encoding/-/text-encoding-0.6.4.tgz",
-      "integrity": "sha1-45mpgiV6J22uQou5KEXLcb3CbRk=",
-      "dev": true
-    },
     "text-table": {
       "version": "0.2.0",
       "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz",
diff --git a/package.json b/package.json
index 939a81b..2e166a4 100644
--- a/package.json
+++ b/package.json
@@ -69,7 +69,7 @@
     "require-from-string": "^2.0.2",
     "rimraf": "^2.6.2",
     "semver": "^5.5.0",
-    "tablestore": "^4.2.0",
+    "tablestore": "^4.3.0",
     "urlencode": "^1.1.0"
   },
   "files": [


Test patch:
diff --git a/test/init/vcs.test.js b/test/init/vcs.test.js
index d53ef2d..6dd24bb 100644
--- a/test/init/vcs.test.js
+++ b/test/init/vcs.test.js
@@ -71,7 +71,7 @@ describe('vcs', () => {
     commandExists.sync.returns(true);
     const repoUrl = 'https://github.com/foo/bar.git';
     const repoDir = await vcsStub.clone(repoUrl, '.');
-    sandbox.assert.calledWith(child_process.spawnSync, 'git', ['clone', repoUrl], {cmd: repoDir, stdio: 'inherit'});
+    sandbox.assert.calledWith(child_process.spawnSync, 'git', ['clone', '--depth=1', repoUrl], {cmd: repoDir, stdio: 'inherit'});
     expect(repoDir).to.be('.bar');
 
   });