Skip to content
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/modern-pumas-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@perfect-abstractions/compose-cli": patch
---

fix(cli): print correct init output path
6 changes: 4 additions & 2 deletions cli/src/modules/init/output.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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++;
}

Expand Down
39 changes: 39 additions & 0 deletions cli/test/modules/init/output.test.ts
Original file line number Diff line number Diff line change
@@ -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 ");
});
});
Loading