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): add barrel template to new command #5202

Merged
merged 1 commit into from
Sep 21, 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
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Qwik uses Vite to build the project. The `vite.config.ts` file contains the Vite

## Utilities

Qwik has a utility command called `new` that allows developers to easily create new components and routes.
Qwik has a utility command called `new` that allows developers to easily create new components and routes.

Let's say you wanted to create a new component called `Button`, you would run the command:
```tsx
Expand All @@ -113,7 +113,7 @@ qwik-app-demo
│ │ └── router-head
│ │ └── router-head.tsx
│ │ Button
│ │ └── index.tsx
│ │ └── button.tsx
│ ├── entry.ssr.tsx
│ ├── global.css
│ ├── root.tsx
Expand All @@ -130,4 +130,19 @@ qwik-app-demo
└── vite.config.ts
```

If you prefer to generate the `Button` component with the `Button/index.tsx` naming convention, you can could use the command:
```tsx
pnpm qwik new --barrel Button
```

In that case, the `src/components` folder would look like this:
```bash
src
│ ├── components
│ │ └── router-head
│ │ └── router-head.tsx
│ │ Button
│ │ └── index.tsx
```

> This feature was added in Qwik v1.2, and those using an older version will not see this functionality.
13 changes: 13 additions & 0 deletions starters/templates/barrel/component/index.tsx.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { component$ } from '@builder.io/qwik';

export interface [name]Props {

}

export const [name] = component$<[name]Props>((props) => {
return (
<div>
[name] component works!
</div>
);
});
5 changes: 5 additions & 0 deletions starters/templates/barrel/markdown/index.md.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: New Route
---

New route works.
5 changes: 5 additions & 0 deletions starters/templates/barrel/mdx/index.mdx.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: New Route
---

New route works.
9 changes: 9 additions & 0 deletions starters/templates/barrel/route/index.tsx.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { component$ } from '@builder.io/qwik';

export default component$(() => {
return (
<div>
New route works.
</div>
);
});