Skip to content

Commit

Permalink
Add install recipe (#834)
Browse files Browse the repository at this point in the history
  • Loading branch information
scotttrinh authored Jan 12, 2024
1 parent dd8744e commit ead4189
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
1 change: 0 additions & 1 deletion packages/create/src/recipes/_base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
43 changes: 43 additions & 0 deletions packages/create/src/recipes/_install/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -27,6 +28,48 @@ const recipe: Recipe<InstallOptions> = {
},
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;
}
}
},
};

Expand Down

0 comments on commit ead4189

Please sign in to comment.