-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(add): move templates to separate files and add new ones (#379)
- Loading branch information
1 parent
dacb6c0
commit af2ea90
Showing
20 changed files
with
367 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { Template } from '.' | ||
import { resolve } from 'pathe' | ||
import { applySuffix } from '.' | ||
|
||
const httpMethods = [ | ||
'connect', | ||
'delete', | ||
'get', | ||
'head', | ||
'options', | ||
'post', | ||
'put', | ||
'trace', | ||
'patch', | ||
] | ||
|
||
const api: Template = ({ name, args, nuxtOptions }) => { | ||
return { | ||
path: resolve(nuxtOptions.srcDir, nuxtOptions.serverDir, `api/${name}${applySuffix(args, httpMethods, 'method')}.ts`), | ||
contents: ` | ||
export default defineEventHandler(event => { | ||
return 'Hello ${name}' | ||
}) | ||
`, | ||
} | ||
} | ||
|
||
export { api } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type { Template } from '.' | ||
import { resolve } from 'pathe' | ||
|
||
const appConfig: Template = ({ nuxtOptions }) => ({ | ||
path: resolve(nuxtOptions.srcDir, 'app.config.ts'), | ||
contents: ` | ||
export default defineAppConfig({}) | ||
`, | ||
}) | ||
|
||
export { appConfig } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { Template } from '.' | ||
import { resolve } from 'pathe' | ||
|
||
const app: Template = ({ args, nuxtOptions }) => ({ | ||
path: resolve(nuxtOptions.srcDir, 'app.vue'), | ||
contents: args.pages | ||
? ` | ||
<script setup lang="ts"></script> | ||
<template> | ||
<div> | ||
<NuxtLayout> | ||
<NuxtPage/> | ||
</NuxtLayout> | ||
</div> | ||
</template> | ||
<style scoped></style> | ||
` | ||
: ` | ||
<script setup lang="ts"></script> | ||
<template> | ||
<div> | ||
<h1>Hello World!</h1> | ||
</div> | ||
</template> | ||
<style scoped></style> | ||
`, | ||
}) | ||
|
||
export { app } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { Template } from '.' | ||
import { resolve } from 'pathe' | ||
import { applySuffix } from '.' | ||
|
||
const component: Template = ({ name, args, nuxtOptions }) => ({ | ||
path: resolve(nuxtOptions.srcDir, `components/${name}${applySuffix( | ||
args, | ||
['client', 'server'], | ||
'mode', | ||
)}.vue`), | ||
contents: ` | ||
<script setup lang="ts"></script> | ||
<template> | ||
<div> | ||
Component: ${name} | ||
</div> | ||
</template> | ||
<style scoped></style> | ||
`, | ||
}) | ||
|
||
export { component } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { Template } from '.' | ||
import { resolve } from 'pathe' | ||
import { pascalCase } from 'scule' | ||
|
||
const composable: Template = ({ name, nuxtOptions }) => { | ||
const nameWithoutUsePrefix = name.replace(/^use-?/, '') | ||
const nameWithUsePrefix = `use${pascalCase(nameWithoutUsePrefix)}` | ||
|
||
return { | ||
path: resolve(nuxtOptions.srcDir, `composables/${name}.ts`), | ||
contents: ` | ||
export const ${nameWithUsePrefix} = () => { | ||
return ref() | ||
} | ||
`, | ||
} | ||
} | ||
|
||
export { composable } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { Template } from '.' | ||
import { resolve } from 'pathe' | ||
|
||
const error: Template = ({ nuxtOptions }) => ({ | ||
path: resolve(nuxtOptions.srcDir, 'error.vue'), | ||
contents: ` | ||
<script setup lang="ts"> | ||
import type { NuxtError } from '#app' | ||
const props = defineProps({ | ||
error: Object as () => NuxtError | ||
}) | ||
</script> | ||
<template> | ||
<div> | ||
<h1>{{ error.statusCode }}</h1> | ||
<NuxtLink to="/">Go back home</NuxtLink> | ||
</div> | ||
</template> | ||
<style scoped></style> | ||
`, | ||
}) | ||
|
||
export { error } |
Oops, something went wrong.