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
4 changes: 2 additions & 2 deletions docs/guide/cli/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ export default defineTemplate({
});
```

Run it with `tsed generate service --name Logger`.
Run it with `tsed generate service Logger`.

::: tip Need a starting point?
To scaffold a boilerplate file in `.templates/`, run:

```bash
tsed generate template
tsed template
```

:::
Expand Down
2 changes: 1 addition & 1 deletion docs/introduction/whats-new-v7.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default defineTemplate({
```

- Hooks (`$afterCreateSourceFile`) integrate with `ts-morph` to auto-format or inject imports post-generation.
- `tsed generate template` scaffolds boilerplate TypeScript templates in `.templates/`, replacing legacy Handlebars snippets with native template literals.
- `tsed template` scaffolds boilerplate TypeScript templates in `.templates/`, replacing legacy Handlebars snippets with native template literals.

Templates currently target the functional API exclusively; decorate classes aren’t required.

Expand Down
70 changes: 70 additions & 0 deletions packages/cli/src/commands/mcp/tools/setWorkspaceTool.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import {CliFs, ProjectPackageJson} from "@tsed/cli-core";
import {DITest, injector} from "@tsed/di";
import {afterEach, beforeEach, describe, expect, it, vi} from "vitest";

import {setWorkspaceTool} from "./setWorkspaceTool.js";

describe("setWorkspaceTool", () => {
let fs: {exists: ReturnType<typeof vi.fn>};
let projectPackage: any;

beforeEach(() => {
DITest.create({env: "test"});

fs = {
exists: vi.fn().mockReturnValue(true)
};
projectPackage = {
cwd: "/project",
preferences: {
convention: "conv_default",
packageManager: "yarn",
platform: "express",
runtime: "node"
},
setCWD: vi.fn(),
toJSON: vi.fn().mockReturnValue({name: "tsed-app"})
};

injector()
.addProvider(CliFs, {
useValue: fs
})
.addProvider(ProjectPackageJson, {
useValue: projectPackage
});
});
afterEach(() => DITest.reset());

it("should return a structured content that matches the declared output schema", async () => {
const instance = injector().invoke(setWorkspaceTool);

const result: any = await instance.handler({cwd: "/project"} as any, {} as any);
const outputSchema = (instance.outputSchema as any)["~standard"].jsonSchema.output({target: "draft-2020-12"});
const declared = Object.keys(outputSchema.properties);

expect(projectPackage.setCWD).toHaveBeenCalledWith("/project");
expect(result.structuredContent).toEqual({
cwd: "/project",
pkg: {name: "tsed-app"},
preferences: {
convention: "conv_default",
packageManager: "yarn",
platform: "express",
runtime: "node"
}
});
expect(Object.keys(result.structuredContent).every((key) => declared.includes(key))).toBe(true);
});

it("should return an error when the directory does not exist", async () => {
fs.exists.mockReturnValue(false);

const instance = injector().invoke(setWorkspaceTool);
const result: any = await instance.handler({cwd: "/missing"} as any, {} as any);

expect(projectPackage.setCWD).not.toHaveBeenCalled();
expect(result.isError).toBe(true);
expect(result.structuredContent.code).toBe("E_CWD_NOT_FOUND");
});
});
2 changes: 1 addition & 1 deletion packages/cli/src/commands/mcp/tools/setWorkspaceTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const setWorkspaceTool = defineTool({
}),
outputSchema: s.object({
cwd: s.string().description("Resolved project root (nearest package.json directory or the provided path)."),
packageJson: s.object().optional().description("Resolved package json"),
pkg: s.object().optional().description("Resolved package.json content"),
preferences: ProjectPreferenceSchema
}),
async handler(args) {
Expand Down
Loading