Skip to content

Commit

Permalink
change component template to work well with intellij
Browse files Browse the repository at this point in the history
  • Loading branch information
lazaroofarrill committed Mar 29, 2022
1 parent 8dd77d7 commit eb3ae7b
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions packages/nuxi/src/utils/templates.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { upperFirst } from 'scule'
import {upperFirst} from 'scule'

interface Template {
(options: { name: string }): { path: string, contents: string }
}

const api: Template = ({ name }) => ({
const api: Template = ({name}) => ({
path: `server/api/${name}.ts`,
contents: `
import { defineHandle } from 'h3'
Expand All @@ -15,16 +15,21 @@ export default defineHandle((req, res) => {
`
})

const plugin: Template = ({ name }) => ({
const plugin: Template = ({name}) => ({
path: `plugins/${name}.ts`,
contents: `
export default defineNuxtPlugin((nuxtApp) => {})
`
})

const component: Template = ({ name }) => ({
const component: Template = ({name}) => ({
path: `components/${name}.vue`,
contents: `
<script lang="ts">
export default {
name: ${name.split('/').join('-')}
}
</script>
<script lang="ts" setup></script>
<template>
Expand All @@ -37,7 +42,7 @@ const component: Template = ({ name }) => ({
`
})

const composable: Template = ({ name }) => {
const composable: Template = ({name}) => {
const nameWithUsePrefix = name.startsWith('use') ? name : `use${upperFirst(name)}`
return {
path: `composables/${name}.ts`,
Expand All @@ -49,14 +54,14 @@ export const ${nameWithUsePrefix} = () => {
}
}

const middleware: Template = ({ name }) => ({
const middleware: Template = ({name}) => ({
path: `middleware/${name}.ts`,
contents: `
export default defineNuxtRouteMiddleware((to, from) => {})
`
})

const layout: Template = ({ name }) => ({
const layout: Template = ({name}) => ({
path: `layouts/${name}.vue`,
contents: `
<script lang="ts" setup></script>
Expand All @@ -72,7 +77,7 @@ const layout: Template = ({ name }) => ({
`
})

const page: Template = ({ name }) => ({
const page: Template = ({name}) => ({
path: `pages/${name}.vue`,
contents: `
<script lang="ts" setup></script>
Expand Down

0 comments on commit eb3ae7b

Please sign in to comment.