From ddb02850f2096d8c9ec36e766ea74e10d2efce3f Mon Sep 17 00:00:00 2001 From: qxb3 Date: Wed, 11 May 2022 15:07:50 +0800 Subject: [PATCH 1/3] feat: using degit to clone the templates --- package-lock.json | 17 +++++++++++++++++ package.json | 1 + src/utilities/install.js | 16 ++++++++++------ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1ef5e51..e35a80f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "MIT", "dependencies": { "colorette": "^2.0.16", + "degit": "^2.8.4", "execa": "^6.1.0", "find-up": "6.3.0", "ora": "^6.1.0", @@ -1297,6 +1298,17 @@ "clone": "^1.0.2" } }, + "node_modules/degit": { + "version": "2.8.4", + "resolved": "https://registry.npmjs.org/degit/-/degit-2.8.4.tgz", + "integrity": "sha512-vqYuzmSA5I50J882jd+AbAhQtgK6bdKUJIex1JNfEUPENCgYsxugzKVZlFyMwV4i06MmnV47/Iqi5Io86zf3Ng==", + "bin": { + "degit": "degit" + }, + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/detect-file": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/detect-file/-/detect-file-1.0.0.tgz", @@ -5640,6 +5652,11 @@ "clone": "^1.0.2" } }, + "degit": { + "version": "2.8.4", + "resolved": "https://registry.npmjs.org/degit/-/degit-2.8.4.tgz", + "integrity": "sha512-vqYuzmSA5I50J882jd+AbAhQtgK6bdKUJIex1JNfEUPENCgYsxugzKVZlFyMwV4i06MmnV47/Iqi5Io86zf3Ng==" + }, "detect-file": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/detect-file/-/detect-file-1.0.0.tgz", diff --git a/package.json b/package.json index 6184d6b..40552fc 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "homepage": "https://github.com/sern-handler/cli#readme", "dependencies": { "colorette": "^2.0.16", + "degit": "^2.8.4", "execa": "^6.1.0", "find-up": "6.3.0", "ora": "^6.1.0", diff --git a/src/utilities/install.js b/src/utilities/install.js index d25d0bb..bb3d2c2 100644 --- a/src/utilities/install.js +++ b/src/utilities/install.js @@ -5,6 +5,7 @@ import path from 'path'; import { readFile } from 'fs/promises'; import { findUp } from 'find-up'; import ora from 'ora'; +import degit from 'degit'; /** * It installs dependencies from a package.json file @@ -40,12 +41,15 @@ export async function installDeps(choice, name) { * @param {string} name - The name of the project */ export async function cloneRepo(lang, name) { - await execa('git', [ - 'clone', - `https://github.com/sern-handler/templates.git`, // ? See the idea of @Allyedge having templates built in cli - ]); - copyRecursiveSync(`templates/templates/${lang}`, name); - fs.rmSync(`templates/`, { recursive: true, force: true }); + const emitter = degit('sern-handler/templates/templates', { + cache: true, + force: true, + }); + + await emitter.clone('templates'); + + copyRecursiveSync(`templates/${lang}`, name); + fs.rmSync('templates', { recursive: true, force: true }); } /** From fc01554fae2726f4ebd39a66ef1cb634a421dd9f Mon Sep 17 00:00:00 2001 From: qxb3 Date: Wed, 11 May 2022 16:16:58 +0800 Subject: [PATCH 2/3] fix: fix degit erroring when there's no cache --- src/utilities/install.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/utilities/install.js b/src/utilities/install.js index bb3d2c2..e18cb95 100644 --- a/src/utilities/install.js +++ b/src/utilities/install.js @@ -1,6 +1,7 @@ import { execa } from 'execa'; import { redBright } from 'colorette'; import fs from 'fs'; +import os from 'os'; import path from 'path'; import { readFile } from 'fs/promises'; import { findUp } from 'find-up'; @@ -41,8 +42,11 @@ export async function installDeps(choice, name) { * @param {string} name - The name of the project */ export async function cloneRepo(lang, name) { + const isCached = fs.existsSync( + path.join(os.homedir(), '.degit/github/sern-handler/templates') + ); const emitter = degit('sern-handler/templates/templates', { - cache: true, + cached: isCached, force: true, }); From fa689360ce054c63dab77e8b8f0b794b3b8736e4 Mon Sep 17 00:00:00 2001 From: qxb3 Date: Wed, 11 May 2022 17:23:13 +0800 Subject: [PATCH 3/3] fix(install.js): fix mistyped. cached -> cache --- src/utilities/install.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utilities/install.js b/src/utilities/install.js index e18cb95..5e03391 100644 --- a/src/utilities/install.js +++ b/src/utilities/install.js @@ -46,7 +46,7 @@ export async function cloneRepo(lang, name) { path.join(os.homedir(), '.degit/github/sern-handler/templates') ); const emitter = degit('sern-handler/templates/templates', { - cached: isCached, + cache: isCached, force: true, });