diff --git a/.changeset/modern-pumas-cheer.md b/.changeset/modern-pumas-cheer.md new file mode 100644 index 00000000..e5713b1c --- /dev/null +++ b/.changeset/modern-pumas-cheer.md @@ -0,0 +1,5 @@ +--- +"@perfect-abstractions/compose-cli": patch +--- + +fix(cli): print correct init output path diff --git a/cli/src/modules/init/output.ts b/cli/src/modules/init/output.ts index 2257578d..f0558193 100644 --- a/cli/src/modules/init/output.ts +++ b/cli/src/modules/init/output.ts @@ -1,3 +1,4 @@ +import path from "node:path"; import { ComposeContext } from "../../context/types"; import { cyan, dim, green, yellow } from "../../utils/terminal"; import { COMPOSE_HEADER, COMPOSE_DOCS_URL } from "../../utils/metadata"; @@ -43,8 +44,9 @@ export function showSuccess(ctx: ComposeContext): void { console.log(green("Next steps:")); let stepCount = 1; - if (projectRoot !== process.cwd()) { - console.log(green(`${stepCount}.`) + ` cd ${projectName}`); + const projectPath = path.relative(process.cwd(), projectRoot); + if (projectPath) { + console.log(green(`${stepCount}.`) + ` cd "${projectPath}"`); stepCount++; } diff --git a/cli/test/modules/init/output.test.ts b/cli/test/modules/init/output.test.ts new file mode 100644 index 00000000..0c895ca2 --- /dev/null +++ b/cli/test/modules/init/output.test.ts @@ -0,0 +1,39 @@ +import path from "node:path"; +import { afterEach, describe, expect, it, vi } from "vitest"; +import { Context } from "../../../src/context/context"; +import { showSuccess } from "../../../src/modules/init/output"; + +describe("init success output", () => { + afterEach(() => { + vi.restoreAllMocks(); + }); + + it("prints the path relative to the current directory when --out is elsewhere", () => { + const projectRoot = path.resolve(process.cwd(), "..", "generated-projects", "my-diamond"); + const ctx = Context.create(); + ctx.param = { + projectName: "my-diamond", + projectRoot, + framework: "foundry", + }; + const log = vi.spyOn(console, "log").mockImplementation(() => undefined); + + showSuccess(ctx); + + expect(log.mock.calls.flat().join("\n")).toContain('cd "../generated-projects/my-diamond"'); + }); + + it("omits the directory change when already in the project directory", () => { + const ctx = Context.create(); + ctx.param = { + projectName: "my-diamond", + projectRoot: process.cwd(), + framework: "foundry", + }; + const log = vi.spyOn(console, "log").mockImplementation(() => undefined); + + showSuccess(ctx); + + expect(log.mock.calls.flat().join("\n")).not.toContain("cd "); + }); +});