Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): show next git steps based on current git repo #1507

Merged
merged 4 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat(cli): Show Next Git steps based on current git repo
  • Loading branch information
levinuncu committed Jul 11, 2023
commit ecc8ab26fa683b5a814e832f2061a724c781dffe
4 changes: 2 additions & 2 deletions cli/src/helpers/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ const isGitInstalled = (dir: string): boolean => {
};

/** @returns Whether or not the provided directory has a `.git` subdirectory in it. */
const isRootGitRepo = (dir: string): boolean => {
export const isRootGitRepo = (dir: string): boolean => {
return fs.existsSync(path.join(dir, ".git"));
};

/** @returns Whether or not this directory or a parent directory has a `.git` directory. */
const isInsideGitRepo = async (dir: string): Promise<boolean> => {
export const isInsideGitRepo = async (dir: string): Promise<boolean> => {
try {
// If this command succeeds, we're inside a git repo
await execa("git", ["rev-parse", "--is-inside-work-tree"], {
Expand Down
15 changes: 12 additions & 3 deletions cli/src/helpers/logNextSteps.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { isInsideGitRepo, isRootGitRepo } from "./git.js";
import { DEFAULT_APP_NAME } from "~/consts.js";
import { type InstallerOptions } from "~/installers/index.js";
import { getUserPkgManager } from "~/utils/getUserPkgManager.js";
import { logger } from "~/utils/logger.js";

// This logs the next steps that the user should take in order to advance the project
export const logNextSteps = ({
export const logNextSteps = async ({
projectName = DEFAULT_APP_NAME,
packages,
noInstall,
}: Pick<InstallerOptions, "projectName" | "packages" | "noInstall">) => {
projectDir,
}: Pick<
InstallerOptions,
"projectName" | "packages" | "noInstall" | "projectDir"
>) => {
const pkgManager = getUserPkgManager();

logger.info("Next steps:");
Expand All @@ -30,5 +35,9 @@ export const logNextSteps = ({

logger.info(` ${pkgManager === "npm" ? "npm run" : pkgManager} dev`);

logger.info(` git commit -m "initial commit"`);
if ((await isInsideGitRepo(projectDir)) || isRootGitRepo(projectDir)) {
logger.info(` git commit -m "initial commit"`);
} else {
logger.info(` git init`);
levinuncu marked this conversation as resolved.
Show resolved Hide resolved
}
};
7 changes: 6 additions & 1 deletion cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ const main = async () => {
await initializeGit(projectDir);
}

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

process.exit(0);
};
Expand Down
Loading