Skip to content

Commit

Permalink
Accept template id without prefix as template name (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
tzyl authored Feb 16, 2024
1 parent 898679c commit 70f597a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
10 changes: 5 additions & 5 deletions packages/create-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ npx @osdk/create-app [project] [--<option>]

## Templates

| Template ID | Description |
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| template-react | [React](https://react.dev/) with [Vite](https://vitejs.dev/guide/why.html) |
| template-vue | [Vue](https://vuejs.org/) with [Vite](https://vitejs.dev/guide/why.html) |
| template-next-static-export | [Next.js](https://nextjs.org/) with [static export](https://nextjs.org/docs/pages/building-your-application/deploying/static-exports) |
| Template name | Description |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------- |
| react | [React](https://react.dev/) with [Vite](https://vitejs.dev/guide/why.html) |
| vue | [Vue](https://vuejs.org/) with [Vite](https://vitejs.dev/guide/why.html) |
| next-static-export | [Next.js](https://nextjs.org/) with [static export](https://nextjs.org/docs/pages/building-your-application/deploying/static-exports) |
5 changes: 5 additions & 0 deletions packages/create-app/changelog/@unreleased/pr-77.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Accept template id without prefix as template name
links:
- https://github.com/palantir/osdk-ts/pull/77
13 changes: 12 additions & 1 deletion packages/create-app/src/prompts/promptTemplate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,24 @@ test("it accepts valid template from prompt", async () => {
expect(vi.mocked(consola).prompt).toHaveBeenCalledTimes(1);
});

test("it accepts valid initial value without prompt", async () => {
test("it accepts valid initial template id value without prompt", async () => {
expect(await promptTemplate({ template: TEMPLATES[0].id })).toEqual(
TEMPLATES[0],
);
expect(vi.mocked(consola).prompt).not.toHaveBeenCalled();
});

test("it accepts valid initial template id value without 'template-' prefix without prompt", async () => {
expect(
await promptTemplate({
template: TEMPLATES[0].id.substring("template-".length),
}),
).toEqual(
TEMPLATES[0],
);
expect(vi.mocked(consola).prompt).not.toHaveBeenCalled();
});

test("it prompts if initial value is invalid", async () => {
vi.mocked(consola).prompt.mockResolvedValueOnce(TEMPLATES[0].id);
expect(await promptTemplate({ template: "missing" })).toEqual(
Expand Down
4 changes: 3 additions & 1 deletion packages/create-app/src/prompts/promptTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import { type Template, TEMPLATES } from "../templates.js";
export async function promptTemplate(
parsed: { template?: string },
): Promise<Template> {
let template = TEMPLATES.find((t) => t.id === parsed.template);
let template = TEMPLATES.find((t) =>
t.id === parsed.template || t.id === `template-${parsed.template}`
);
if (template == null) {
const templateId = (await consola.prompt(
parsed.template != null
Expand Down

0 comments on commit 70f597a

Please sign in to comment.