From ead4189d9ba1350affd42cca60462190af44c172 Mon Sep 17 00:00:00 2001 From: Scott Trinh Date: Fri, 12 Jan 2024 11:15:58 -0500 Subject: [PATCH] Add install recipe (#834) --- packages/create/src/recipes/_base/index.ts | 1 - packages/create/src/recipes/_install/index.ts | 43 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/packages/create/src/recipes/_base/index.ts b/packages/create/src/recipes/_base/index.ts index 8fccb228b..84492e10b 100644 --- a/packages/create/src/recipes/_base/index.ts +++ b/packages/create/src/recipes/_base/index.ts @@ -4,7 +4,6 @@ import path from "node:path"; import debug from "debug"; import * as p from "@clack/prompts"; - import { updatePackage } from "write-package"; import { getPackageManager, copyTemplateFiles } from "../../utils.js"; diff --git a/packages/create/src/recipes/_install/index.ts b/packages/create/src/recipes/_install/index.ts index 249aa1bc0..a794b0094 100644 --- a/packages/create/src/recipes/_install/index.ts +++ b/packages/create/src/recipes/_install/index.ts @@ -2,6 +2,7 @@ import debug from "debug"; import * as p from "@clack/prompts"; import type { BaseOptions, Recipe } from "../types.js"; +import { execInLoginShell } from "../../utils.js"; const logger = debug("@edgedb/create:recipe:install"); @@ -27,6 +28,48 @@ const recipe: Recipe = { }, async apply(baseOptions: BaseOptions, recipeOptions: InstallOptions) { logger("Running install recipe"); + + const spinner = p.spinner(); + + if (recipeOptions.shouldGitInit) { + spinner.start("Initializing git repository"); + try { + await execInLoginShell("git init", { + cwd: baseOptions.projectDir, + }); + spinner.stop("Initialized git repository"); + } catch (err) { + spinner.stop("Failed to initialize git repository"); + throw err; + } + } + + if (recipeOptions.shouldInstall) { + const command = `${baseOptions.packageManager} install`; + spinner.start(`Installing dependencies: ${command}`); + try { + await execInLoginShell(command, { + cwd: baseOptions.projectDir, + }); + spinner.stop("Installed dependencies"); + } catch (err) { + spinner.stop("Failed to install dependencies"); + throw err; + } + } + + if (recipeOptions.shouldGitInit) { + spinner.start("Staging changes"); + try { + await execInLoginShell("git add .", { + cwd: baseOptions.projectDir, + }); + spinner.stop("Staged changes"); + } catch (err) { + spinner.stop("Failed to stage changes"); + throw err; + } + } }, };