fix: git not installed errors during init (#79)

Co-authored-by: EvolutionX <evolutionx9777@gmail.com>
This commit is contained in:
2022-09-22 09:08:49 +02:00
committed by GitHub
parent aa398a871c
commit 69287ab1bd
2 changed files with 27 additions and 17 deletions

View File

@@ -1,4 +1,4 @@
import { greenBright, redBright } from 'colorette';
import { greenBright, redBright, underline } from 'colorette';
import { execa } from 'execa';
import { findUp } from 'find-up';
import ora from 'ora';
@@ -98,19 +98,19 @@ async function git(data: Data) {
spinner: 'aesthetic',
}).start();
const exe = await execa('git', ['init', data.name]);
await wait(300);
if (!exe || exe?.failed) {
try {
await execa('git', ['init', data.name]);
await wait(300);
spin.succeed('Git initialized!');
} catch (error) {
spin.fail(
`${redBright('Failed')} to initialize git!` +
'\nMaybe you should run git init?'
`${redBright(
'Failed'
)} to initialize git!\nTry to install it at ${underline(
'https://git-scm.com'
)}\nSkipping for now.`
);
process.exit(1);
}
spin.succeed('Git initialized!');
}
/** Wait for a specified number of milliseconds, then return a promise that resolves to undefined. */

View File

@@ -36,6 +36,7 @@ export async function installDeps(choice: PackageManagerChoice, name: string) {
const result = await execa(choice, ['install'], {
cwd: process.cwd() + '/' + name,
}).catch(() => null);
if (!result || result?.failed) {
spin.fail(`${redBright('Failed')} to install dependencies!`);
process.exit(1);
@@ -48,12 +49,21 @@ export async function installDeps(choice: PackageManagerChoice, name: string) {
* @param name - The name of the project
*/
export async function cloneRepo(lang: string, name: string) {
await execa('git', [
'clone',
`https://github.com/sern-handler/templates.git`,
]);
copyRecursiveSync(`templates/templates/${lang}`, name);
fs.rmSync(`templates/`, { recursive: true, force: true });
try {
await execa('git', [
'clone',
`https://github.com/sern-handler/templates.git`,
]);
copyRecursiveSync(`templates/templates/${lang}`, name);
fs.rmSync(`templates/`, { recursive: true, force: true });
} catch (error) {
console.log(
`${redBright(
'✖ Failed'
)} to clone github templates repo. Install git and try again!`
);
process.exit(1);
}
}
/**