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 all commits
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
5 changes: 5 additions & 0 deletions .changeset/wild-walls-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-t3-app": minor
---

If the project is not in a Git repo, the next steps will show git init instead of git commit -m "initial commit".
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
12 changes: 10 additions & 2 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, "noInstall" | "packages" | "projectName">) => {
projectDir,
}: Pick<
InstallerOptions,
"projectName" | "packages" | "noInstall" | "projectDir"
>) => {
const pkgManager = getUserPkgManager();

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

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

if (!(await isInsideGitRepo(projectDir)) && !isRootGitRepo(projectDir)) {
logger.info(` git init`);
levinuncu marked this conversation as resolved.
Show resolved Hide resolved
}
logger.info(` git commit -m "initial commit"`);
};
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