diff --git a/package-lock.json b/package-lock.json index d0194e84..78118235 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,13 +24,14 @@ "eth-connect": "^0.3.0", "ethers": "^4.0.38", "express": "^4.16.2", + "extract-zip": "^2.0.1", "fs-extra": "^7.0.1", "glob": "^7.1.3", "global": "^4.4.0", "google-protobuf": "^3.8.0", "ignore": "^4.0.6", "inquirer": "^6.2.0", - "isomorphic-fetch": "^2.2.1", + "isomorphic-fetch": "^3.0.0", "opn": "^5.2.0", "ora": "^3.0.0", "package-json": "^7.0.0", @@ -56,7 +57,7 @@ "@types/fs-extra": "^5.0.0", "@types/glob": "^7.1.1", "@types/inquirer": "0.0.36", - "@types/isomorphic-fetch": "0.0.34", + "@types/isomorphic-fetch": "^0.0.36", "@types/node": "^12.12.55", "@types/puppeteer": "^1.11.2", "@types/request": "^2.48.1", @@ -3237,9 +3238,10 @@ } }, "node_modules/@types/isomorphic-fetch": { - "version": "0.0.34", - "dev": true, - "license": "MIT" + "version": "0.0.36", + "resolved": "https://registry.npmjs.org/@types/isomorphic-fetch/-/isomorphic-fetch-0.0.36.tgz", + "integrity": "sha512-ulw4d+vW1HKn4oErSmNN2HYEcHGq0N1C5exlrMM0CRqX1UUpFhGb5lwiom5j9KN3LBJJDLRmYIZz1ghm7FIzZw==", + "dev": true }, "node_modules/@types/json-schema": { "version": "7.0.9", @@ -3495,6 +3497,15 @@ "@types/node": "*" } }, + "node_modules/@types/yauzl": { + "version": "2.10.0", + "resolved": "https://registry.npmjs.org/@types/yauzl/-/yauzl-2.10.0.tgz", + "integrity": "sha512-Cn6WYCm0tXv8p6k+A8PvbDG763EDpBoTzHdA+Q/MF6H3sapGjCm9NzoaJncJS9tUKSuCoDs9XHxYYsQDgxR6kw==", + "optional": true, + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@typescript-eslint/eslint-plugin": { "version": "5.4.0", "dev": true, @@ -5106,11 +5117,12 @@ }, "node_modules/concat-stream": { "version": "1.6.2", + "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", + "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", "dev": true, "engines": [ "node >= 0.8" ], - "license": "MIT", "dependencies": { "buffer-from": "^1.0.0", "inherits": "^2.0.3", @@ -5913,10 +5925,22 @@ } }, "node_modules/encoding": { - "version": "0.1.12", - "license": "MIT", + "version": "0.1.13", + "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.13.tgz", + "integrity": "sha512-ETBauow1T35Y/WZMkio9jiM0Z5xjHHmJ4XmjZOq1l/dXz3lr2sRn87nJy20RupqSh1F2m3HHPSp8ShIPQJrJ3A==", + "dependencies": { + "iconv-lite": "^0.6.2" + } + }, + "node_modules/encoding/node_modules/iconv-lite": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", "dependencies": { - "iconv-lite": "~0.4.13" + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" } }, "node_modules/end-of-stream": { @@ -7232,31 +7256,53 @@ } }, "node_modules/extract-zip": { - "version": "1.7.0", - "dev": true, - "license": "BSD-2-Clause", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-2.0.1.tgz", + "integrity": "sha512-GDhU9ntwuKyGXdZBUgTIe+vXnWj0fppUEtMDL0+idd5Sta8TGpHssn/eusA9mrPr9qNDym6SxAYZjNvCn/9RBg==", "dependencies": { - "concat-stream": "^1.6.2", - "debug": "^2.6.9", - "mkdirp": "^0.5.4", + "debug": "^4.1.1", + "get-stream": "^5.1.0", "yauzl": "^2.10.0" }, "bin": { "extract-zip": "cli.js" + }, + "engines": { + "node": ">= 10.17.0" + }, + "optionalDependencies": { + "@types/yauzl": "^2.9.1" } }, "node_modules/extract-zip/node_modules/debug": { - "version": "2.6.9", - "dev": true, - "license": "MIT", + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", "dependencies": { - "ms": "2.0.0" + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } } }, - "node_modules/extract-zip/node_modules/ms": { - "version": "2.0.0", - "dev": true, - "license": "MIT" + "node_modules/extract-zip/node_modules/get-stream": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz", + "integrity": "sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA==", + "dependencies": { + "pump": "^3.0.0" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } }, "node_modules/extsprintf": { "version": "1.3.0", @@ -7381,7 +7427,6 @@ }, "node_modules/fd-slicer": { "version": "1.1.0", - "dev": true, "license": "MIT", "dependencies": { "pend": "~1.2.0" @@ -9453,19 +9498,12 @@ } }, "node_modules/isomorphic-fetch": { - "version": "2.2.1", - "license": "MIT", - "dependencies": { - "node-fetch": "^1.0.1", - "whatwg-fetch": ">=0.10.0" - } - }, - "node_modules/isomorphic-fetch/node_modules/node-fetch": { - "version": "1.7.3", - "license": "MIT", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-3.0.0.tgz", + "integrity": "sha512-qvUtwJ3j6qwsF3jLxkZ72qCgjMysPzDfeV240JHiGZsANBYd+EEuu35v7dfrJ9Up0Ak07D7GGSkGhCHTqg/5wA==", "dependencies": { - "encoding": "^0.1.11", - "is-stream": "^1.0.1" + "node-fetch": "^2.6.1", + "whatwg-fetch": "^3.4.1" } }, "node_modules/isomorphic-ws": { @@ -10952,7 +10990,6 @@ }, "node_modules/pend": { "version": "1.2.0", - "dev": true, "license": "MIT" }, "node_modules/performance-now": { @@ -11248,6 +11285,36 @@ "ms": "^2.1.1" } }, + "node_modules/puppeteer/node_modules/extract-zip": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-1.7.0.tgz", + "integrity": "sha512-xoh5G1W/PB0/27lXgMQyIhP5DSY/LhoCsOyZgb+6iMmRtCwVBo55uKaMoEYrDCKQhWvqEip5ZPKAc6eFNyf/MA==", + "dev": true, + "dependencies": { + "concat-stream": "^1.6.2", + "debug": "^2.6.9", + "mkdirp": "^0.5.4", + "yauzl": "^2.10.0" + }, + "bin": { + "extract-zip": "cli.js" + } + }, + "node_modules/puppeteer/node_modules/extract-zip/node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/puppeteer/node_modules/extract-zip/node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "dev": true + }, "node_modules/qs": { "version": "6.5.2", "license": "BSD-3-Clause", @@ -12919,8 +12986,9 @@ }, "node_modules/typedarray": { "version": "0.0.6", - "dev": true, - "license": "MIT" + "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", + "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", + "dev": true }, "node_modules/typescript": { "version": "4.4.4", @@ -13286,6 +13354,24 @@ "version": "10.17.29", "license": "MIT" }, + "node_modules/web3x/node_modules/isomorphic-fetch": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz", + "integrity": "sha1-YRrhrPFPXoH3KVB0coGf6XM1WKk=", + "dependencies": { + "node-fetch": "^1.0.1", + "whatwg-fetch": ">=0.10.0" + } + }, + "node_modules/web3x/node_modules/node-fetch": { + "version": "1.7.3", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz", + "integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==", + "dependencies": { + "encoding": "^0.1.11", + "is-stream": "^1.0.1" + } + }, "node_modules/web3x/node_modules/utf8": { "version": "3.0.0", "license": "MIT" @@ -13304,8 +13390,9 @@ } }, "node_modules/whatwg-fetch": { - "version": "2.0.4", - "license": "MIT" + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.6.2.tgz", + "integrity": "sha512-bJlen0FcuU/0EMLrdbJ7zOnW6ITZLrZMIarMUVmdKtsGvZna8vxKYaexICWPfZ8qwf9fzNq+UEIZrnSaApt6RA==" }, "node_modules/whatwg-url": { "version": "5.0.0", @@ -13456,7 +13543,6 @@ }, "node_modules/yauzl": { "version": "2.10.0", - "dev": true, "license": "MIT", "dependencies": { "buffer-crc32": "~0.2.3", @@ -15146,7 +15232,9 @@ } }, "@types/isomorphic-fetch": { - "version": "0.0.34", + "version": "0.0.36", + "resolved": "https://registry.npmjs.org/@types/isomorphic-fetch/-/isomorphic-fetch-0.0.36.tgz", + "integrity": "sha512-ulw4d+vW1HKn4oErSmNN2HYEcHGq0N1C5exlrMM0CRqX1UUpFhGb5lwiom5j9KN3LBJJDLRmYIZz1ghm7FIzZw==", "dev": true }, "@types/json-schema": { @@ -15370,6 +15458,15 @@ "@types/node": "*" } }, + "@types/yauzl": { + "version": "2.10.0", + "resolved": "https://registry.npmjs.org/@types/yauzl/-/yauzl-2.10.0.tgz", + "integrity": "sha512-Cn6WYCm0tXv8p6k+A8PvbDG763EDpBoTzHdA+Q/MF6H3sapGjCm9NzoaJncJS9tUKSuCoDs9XHxYYsQDgxR6kw==", + "optional": true, + "requires": { + "@types/node": "*" + } + }, "@typescript-eslint/eslint-plugin": { "version": "5.4.0", "dev": true, @@ -16474,6 +16571,8 @@ }, "concat-stream": { "version": "1.6.2", + "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", + "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", "dev": true, "requires": { "buffer-from": "^1.0.0", @@ -17050,9 +17149,21 @@ "version": "1.0.2" }, "encoding": { - "version": "0.1.12", + "version": "0.1.13", + "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.13.tgz", + "integrity": "sha512-ETBauow1T35Y/WZMkio9jiM0Z5xjHHmJ4XmjZOq1l/dXz3lr2sRn87nJy20RupqSh1F2m3HHPSp8ShIPQJrJ3A==", "requires": { - "iconv-lite": "~0.4.13" + "iconv-lite": "^0.6.2" + }, + "dependencies": { + "iconv-lite": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "requires": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + } + } } }, "end-of-stream": { @@ -17967,25 +18078,31 @@ } }, "extract-zip": { - "version": "1.7.0", - "dev": true, + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-2.0.1.tgz", + "integrity": "sha512-GDhU9ntwuKyGXdZBUgTIe+vXnWj0fppUEtMDL0+idd5Sta8TGpHssn/eusA9mrPr9qNDym6SxAYZjNvCn/9RBg==", "requires": { - "concat-stream": "^1.6.2", - "debug": "^2.6.9", - "mkdirp": "^0.5.4", + "@types/yauzl": "^2.9.1", + "debug": "^4.1.1", + "get-stream": "^5.1.0", "yauzl": "^2.10.0" }, "dependencies": { "debug": { - "version": "2.6.9", - "dev": true, + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", "requires": { - "ms": "2.0.0" + "ms": "2.1.2" } }, - "ms": { - "version": "2.0.0", - "dev": true + "get-stream": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz", + "integrity": "sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA==", + "requires": { + "pump": "^3.0.0" + } } } }, @@ -18077,7 +18194,6 @@ }, "fd-slicer": { "version": "1.1.0", - "dev": true, "requires": { "pend": "~1.2.0" } @@ -19474,19 +19590,12 @@ "version": "3.0.1" }, "isomorphic-fetch": { - "version": "2.2.1", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-3.0.0.tgz", + "integrity": "sha512-qvUtwJ3j6qwsF3jLxkZ72qCgjMysPzDfeV240JHiGZsANBYd+EEuu35v7dfrJ9Up0Ak07D7GGSkGhCHTqg/5wA==", "requires": { - "node-fetch": "^1.0.1", - "whatwg-fetch": ">=0.10.0" - }, - "dependencies": { - "node-fetch": { - "version": "1.7.3", - "requires": { - "encoding": "^0.1.11", - "is-stream": "^1.0.1" - } - } + "node-fetch": "^2.6.1", + "whatwg-fetch": "^3.4.1" } }, "isomorphic-ws": { @@ -20482,8 +20591,7 @@ } }, "pend": { - "version": "1.2.0", - "dev": true + "version": "1.2.0" }, "performance-now": { "version": "2.1.0" @@ -20681,6 +20789,35 @@ "requires": { "ms": "^2.1.1" } + }, + "extract-zip": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-1.7.0.tgz", + "integrity": "sha512-xoh5G1W/PB0/27lXgMQyIhP5DSY/LhoCsOyZgb+6iMmRtCwVBo55uKaMoEYrDCKQhWvqEip5ZPKAc6eFNyf/MA==", + "dev": true, + "requires": { + "concat-stream": "^1.6.2", + "debug": "^2.6.9", + "mkdirp": "^0.5.4", + "yauzl": "^2.10.0" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, + "requires": { + "ms": "2.0.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "dev": true + } + } } } }, @@ -21823,6 +21960,8 @@ }, "typedarray": { "version": "0.0.6", + "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", + "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", "dev": true }, "typescript": { @@ -22067,6 +22206,24 @@ "@types/node": { "version": "10.17.29" }, + "isomorphic-fetch": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz", + "integrity": "sha1-YRrhrPFPXoH3KVB0coGf6XM1WKk=", + "requires": { + "node-fetch": "^1.0.1", + "whatwg-fetch": ">=0.10.0" + } + }, + "node-fetch": { + "version": "1.7.3", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz", + "integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==", + "requires": { + "encoding": "^0.1.11", + "is-stream": "^1.0.1" + } + }, "utf8": { "version": "3.0.0" } @@ -22082,7 +22239,9 @@ "dev": true }, "whatwg-fetch": { - "version": "2.0.4" + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.6.2.tgz", + "integrity": "sha512-bJlen0FcuU/0EMLrdbJ7zOnW6ITZLrZMIarMUVmdKtsGvZna8vxKYaexICWPfZ8qwf9fzNq+UEIZrnSaApt6RA==" }, "whatwg-url": { "version": "5.0.0", @@ -22198,7 +22357,6 @@ }, "yauzl": { "version": "2.10.0", - "dev": true, "requires": { "buffer-crc32": "~0.2.3", "fd-slicer": "~1.1.0" diff --git a/package.json b/package.json index 874d4d95..2ec0b17f 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "@types/fs-extra": "^5.0.0", "@types/glob": "^7.1.1", "@types/inquirer": "0.0.36", - "@types/isomorphic-fetch": "0.0.34", + "@types/isomorphic-fetch": "^0.0.36", "@types/node": "^12.12.55", "@types/puppeteer": "^1.11.2", "@types/request": "^2.48.1", @@ -84,13 +84,14 @@ "eth-connect": "^0.3.0", "ethers": "^4.0.38", "express": "^4.16.2", + "extract-zip": "^2.0.1", "fs-extra": "^7.0.1", "glob": "^7.1.3", "global": "^4.4.0", "google-protobuf": "^3.8.0", "ignore": "^4.0.6", "inquirer": "^6.2.0", - "isomorphic-fetch": "^2.2.1", + "isomorphic-fetch": "^3.0.0", "opn": "^5.2.0", "ora": "^3.0.0", "package-json": "^7.0.0", diff --git a/samples/remote-scenes.json b/samples/remote-scenes.json index ab8451b3..1444cba8 100644 --- a/samples/remote-scenes.json +++ b/samples/remote-scenes.json @@ -2,27 +2,27 @@ "scenes": [ { "title": "Cube spawner", - "url": "https://github.com/decentraland-scenes/cube-spawner" + "url": "https://github.com/decentraland-scenes/cube-spawner/archive/refs/heads/main.zip" }, { "title": "Basic interactions", - "url": "https://github.com/decentraland-scenes/Basic-Interactions" + "url": "https://github.com/decentraland-scenes/Basic-Interactions/archive/refs/heads/master.zip" }, { "title": "Moving platforms", - "url": "https://github.com/decentraland-scenes/moving-platforms" + "url": "https://github.com/decentraland-scenes/moving-platforms/archive/refs/heads/master.zip" }, { "title": "Video streaming", - "url": "https://github.com/decentraland-scenes/video-streaming" + "url": "https://github.com/decentraland-scenes/video-streaming/archive/refs/heads/main.zip" }, { "title": "Lazy loading", - "url": "https://github.com/decentraland-scenes/lazy-loading" + "url": "https://github.com/decentraland-scenes/lazy-loading/archive/refs/heads/main.zip" }, { "title": "POAP booth", - "url": "https://github.com/decentraland-scenes/POAP-Booth" + "url": "https://github.com/decentraland-scenes/POAP-Booth/archive/refs/heads/master.zip" } ] } diff --git a/src/commands/init.ts b/src/commands/init.ts index 46e06715..364caba8 100644 --- a/src/commands/init.ts +++ b/src/commands/init.ts @@ -11,12 +11,10 @@ import installDependencies from '../project/installDependencies' import { isEmptyDirectory } from '../utils/filesystem' import { ProjectType } from '@dcl/schemas/dist/sdk' -import { downloadRepo } from '../utils/shellCommands' -import path from 'path' -import { remove } from 'fs-extra' import * as spinner from '../utils/spinner' import * as remoteScenesJSON from '../../samples/remote-scenes.json' +import { downloadRepoZip } from '../utils/download' export const help = () => ` Usage: ${chalk.bold('dcl init [options]')} @@ -217,8 +215,9 @@ async function initRepository(dcl: Decentraland, url: string) { try { spinner.create('Downloading example...') - await downloadRepo(project.getProjectWorkingDir(), url, '.') - await remove(path.resolve(project.getProjectWorkingDir(), '.git')) + + await downloadRepoZip(url, project.getProjectWorkingDir()) + spinner.succeed('Example downloaded') } catch (error: any) { spinner.fail(`Failed fetching the repo ${url}.`) diff --git a/src/utils/download.ts b/src/utils/download.ts new file mode 100644 index 00000000..935eb3e9 --- /dev/null +++ b/src/utils/download.ts @@ -0,0 +1,47 @@ +import extract from 'extract-zip' +import { rmdirSync } from 'fs' +import { move, readdir, remove, writeFile } from 'fs-extra' +import path from 'path' +import fetch from 'isomorphic-fetch' + +export const downloadFile = async function (url: string, dest: string) { + const data = await (await fetch(url)).arrayBuffer() + await writeFile(dest, Buffer.from(data)) +} + +export const downloadRepoZip = async function (url: string, dest: string) { + const zipFilePath = path.resolve(dest, 'temp-zip-project.zip') + await downloadFile(url, zipFilePath) + + const oldFiles = await readdir(dest) + + try { + await extract(zipFilePath, { dir: dest }) + } catch (err) { + console.log(`Couldn't extract the zip of the repository.`, err) + throw err + } + + const newFiles = await readdir(dest) + + const directoryCreated = newFiles.filter((value) => !oldFiles.includes(value)) + + if (directoryCreated.length !== 1) { + throw new Error( + 'Please, make sure not to modify the directory while the example repository is downloading.' + ) + } + + const extractedPath = path.resolve(dest, directoryCreated[0]) + const filesToMove = await readdir(extractedPath) + + for (const filePath of filesToMove) { + await move( + path.resolve(extractedPath, filePath), + path.resolve(dest, filePath) + ) + } + + rmdirSync(extractedPath) + await remove(zipFilePath) +} diff --git a/test/e2e/snapshots/start.test.ts.md b/test/e2e/snapshots/start.test.ts.md index 784d5658..ba300507 100644 --- a/test/e2e/snapshots/start.test.ts.md +++ b/test/e2e/snapshots/start.test.ts.md @@ -549,6 +549,33 @@ Generated by [AVA](https://ava.li). ␊ ␊