Skip to content

Commit

Permalink
fix: Check if dependencies are installed for next steps
Browse files Browse the repository at this point in the history
  • Loading branch information
pawanpaudel93 committed Nov 2, 2023
1 parent 9aec473 commit 30d0a9c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
20 changes: 17 additions & 3 deletions apps/cli/src/helpers/installDependencies.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import chalk from "chalk";
import { execa, type StdioOption } from "execa";
import ora, { type Ora } from "ora";
import path from "path";
import fs from "fs-extra";

import { getUserPkgManager, type PackageManager } from "@/utils/getUserPkgManager.js";
import { logger } from "@/utils/logger.js";
Expand Down Expand Up @@ -70,7 +72,19 @@ export const installDependencies = async ({ projectDir }: { projectDir: string }

const installSpinner = await runInstallCommand(pkgManager, projectDir);

// If the spinner was used to show the progress, use succeed method on it
// If not, use the succeed on a new spinner
(installSpinner ?? ora()).succeed(chalk.green("Successfully installed dependencies!\n"));
const isDependenciesInstalled = fs.existsSync(path.join(projectDir, "node_modules"));
if (isDependenciesInstalled) {
// If the spinner was used to show the progress, use succeed method on it
// If not, use the succeed on a new spinner
(installSpinner ?? ora()).succeed(chalk.green("Successfully installed dependencies!\n"));
return false;
} else {
(installSpinner ?? ora()).fail(
chalk.red(
"Failed to install dependencies! Please refer to https://github.com/labscommunity/starterkit#getting-started for troubleshooting steps to resolve this issue.\n"
)
);

return true;
}
};
5 changes: 3 additions & 2 deletions apps/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ const main = async () => {
setImportAlias(projectDir, importAlias);
}

let showInstallCommand = noInstall;
if (!noInstall) {
await installDependencies({ projectDir });
showInstallCommand = await installDependencies({ projectDir });
}

// Rename _eslintrc.json to .eslintrc.json - we use _eslintrc.json to avoid conflicts with the monorepos linter
Expand All @@ -92,7 +93,7 @@ const main = async () => {

await logNextSteps({
projectName: appDir,
noInstall,
noInstall: showInstallCommand,
projectDir,
});

Expand Down

0 comments on commit 30d0a9c

Please sign in to comment.