Skip to content

Commit 34ced5c

Browse files
authored
feat: Nitro support
feat: Nitro support
2 parents 1c80adc + 0d0cace commit 34ced5c

File tree

14 files changed

+236
-57
lines changed

14 files changed

+236
-57
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,20 @@ And auto open the created file using:
9393

9494
**Nuxt Snippets**: You can use Nuxt snippets by typing `nuxt` for components, `use` for Composables or just start typing Nuxt utils and selecting your snippet from the list.
9595

96-
Nuxt Snippets is enabled by default. You can enable/disable Nuxt snippets from the settings.
96+
Nuxt Snippets is enabled by default. You can enable/disable them using this setting.
9797

9898
```JSON
9999
"nuxtr.snippets.nuxt": true
100100
```
101101

102+
**Nitro Snippets**: Nitro is empoweing Nuxt Server Engine. Please, refer to [Nitro Docs](https://nitro.unjs.io) for more information.
103+
104+
Nitro Snippets is enabled by default. You can enable/disable them using this setting.
105+
106+
```JSON
107+
"nuxtr.snippets.nitro": true
108+
```
109+
102110
**Custom Snippets**: Easily manage your custom snippets from the sidebar. You can create, edit or delete your snippets.
103111

104112
More on this side of the extension is coming soon!

package.json

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"vscode": "^1.81.0"
99
},
1010
"categories": [
11-
"Other"
11+
"Programming Languages",
12+
"Snippets"
1213
],
1314
"repository": "https://github.com/nuxtrdev/nuxtr-vscode",
1415
"homepage": "https://nuxtr.com",
@@ -21,11 +22,11 @@
2122
"license": "MIT",
2223
"keywords": [
2324
"Nuxt",
24-
"nuxt.js",
2525
"Vue",
26-
"Vue.js",
27-
"DX",
28-
"Nuxt Framework"
26+
"Nuxt Framework",
27+
"VSCode",
28+
"Nuxtr",
29+
"Nuxtr VSCode"
2930
],
3031
"contributes": {
3132
"snippets": [
@@ -60,6 +61,14 @@
6061
{
6162
"language": "typescript",
6263
"path": "./snippets/nuxt/utils.json"
64+
},
65+
{
66+
"language": "javascript",
67+
"path": "./snippets/nitro/imports.json"
68+
},
69+
{
70+
"language": "typescript",
71+
"path": "./snippets/nitro/imports.json"
6372
}
6473
],
6574
"languages": [
@@ -176,7 +185,7 @@
176185
"when": "nuxtr.isNuxtProject"
177186
},
178187
{
179-
"command": "nuxtr.createApi",
188+
"command": "nuxtr.createNitroAPI",
180189
"when": "nuxtr.isNuxtProject"
181190
},
182191
{
@@ -268,11 +277,11 @@
268277
"when": "false"
269278
},
270279
{
271-
"command": "nuxtr.directCreateApi",
280+
"command": "nuxtr.directCreateNitroAPI",
272281
"when": "false"
273282
},
274283
{
275-
"command": "nuxtr.directCreateRoute",
284+
"command": "nuxtr.directCreateNitroRoute",
276285
"when": "false"
277286
},
278287
{
@@ -365,12 +374,12 @@
365374
"group": "navigation"
366375
},
367376
{
368-
"command": "nuxtr.directCreateApi",
377+
"command": "nuxtr.directCreateNitroAPI",
369378
"when": "(nuxtr.isNuxtProject && resourceFilename =~ /(api.*)/) || ( nuxtr.isNuxtProject && resourceDirname =~ /(api.*)/ && explorerResourceIsFolder)",
370379
"group": "navigation"
371380
},
372381
{
373-
"command": "nuxtr.directCreateRoute",
382+
"command": "nuxtr.directCreateNitroRoute",
374383
"when": "(nuxtr.isNuxtProject && resourceFilename =~ /(routes.*)/) || ( nuxtr.isNuxtProject && resourceDirname =~ /(routes.*)/ && explorerResourceIsFolder)",
375384
"group": "navigation"
376385
},
@@ -538,6 +547,11 @@
538547
"type": "boolean",
539548
"default": true,
540549
"description": "Enable / Disable Nuxt Snippets"
550+
},
551+
"nuxtr.snippets.nitro": {
552+
"type": "boolean",
553+
"default": true,
554+
"description": "Enable / Disable Nitro Snippets"
541555
}
542556
}
543557
}
@@ -585,6 +599,12 @@
585599
"category": "Nuxtr",
586600
"when": "nuxtr.isNuxtProject"
587601
},
602+
{
603+
"command": "nuxtr.createNitroPlugin",
604+
"title": "Create new Nitro Plugin",
605+
"category": "Nuxtr",
606+
"when": "nuxtr.isNuxtProject"
607+
},
588608
{
589609
"command": "nuxtr.directCreatePlugin",
590610
"title": "New Plugin...",
@@ -604,26 +624,38 @@
604624
"when": "nuxtr.isNuxtProject"
605625
},
606626
{
607-
"command": "nuxtr.createApi",
608-
"title": "Create new API",
627+
"command": "nuxtr.createNitroAPI",
628+
"title": "Create new Nitro API",
629+
"category": "Nuxtr",
630+
"when": "nuxtr.isNuxtProject"
631+
},
632+
{
633+
"command": "nuxtr.createNitroPlugin",
634+
"title": "Create new Nitro Plugin",
635+
"category": "Nuxtr",
636+
"when": "nuxtr.isNuxtProject"
637+
},
638+
{
639+
"command": "nuxtr.createNitroMiddleware",
640+
"title": "Create new Nitro Middleware",
609641
"category": "Nuxtr",
610642
"when": "nuxtr.isNuxtProject"
611643
},
612644
{
613-
"command": "nuxtr.createRoute",
614-
"title": "Create new Route",
645+
"command": "nuxtr.createNitroRoute",
646+
"title": "Create new Nitro Route",
615647
"category": "Nuxtr",
616648
"when": "nuxtr.isNuxtProject"
617649
},
618650
{
619-
"command": "nuxtr.directCreateApi",
651+
"command": "nuxtr.directCreateNitroAPI",
620652
"title": "New API...",
621653
"shortTitle": "Create new API",
622654
"category": "Nuxtr",
623655
"when": "nuxtr.isNuxtProject"
624656
},
625657
{
626-
"command": "nuxtr.directCreateRoute",
658+
"command": "nuxtr.directCreateNitroRoute",
627659
"title": "New Route...",
628660
"shortTitle": "Create new Route",
629661
"category": "Nuxtr",

snippets/Nitro/imports.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"defineNitroPlugin": {
3+
"prefix": "defineNitroPlugin",
4+
"description": "Define Nitro Plugins",
5+
"body": [
6+
"export default defineNitroPlugin((${1:plugin}) => {",
7+
" $2",
8+
"})"
9+
],
10+
"isFileTemplate": true
11+
},
12+
"getRouteRules": {
13+
"prefix": "getRouteRules",
14+
"description": "Get Route Rules",
15+
"body": [
16+
"const ${1:routeRules} = getRouteRules($2);"
17+
]
18+
},
19+
"useNitroApp": {
20+
"prefix": "useNitroApp",
21+
"description": "Use Nitro App",
22+
"body": [
23+
"const ${1:nitroApp} = useNitroApp();"
24+
]
25+
},
26+
"useStorage": {
27+
"prefix": "useStorage",
28+
"description": "Use Storage",
29+
"body": [
30+
"const ${1:storage} = useStorage();"
31+
]
32+
},
33+
"defineRenderHandler": {
34+
"prefix": "defineRenderHandler",
35+
"body": [
36+
"export function defineRenderHandler(${1:handler}) {",
37+
" return eventHandler(async (event) => {",
38+
" ${2:}",
39+
" })",
40+
"}"
41+
],
42+
"description": "defineRenderHandler"
43+
}
44+
}

src/commands/Middleware.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { window } from 'vscode'
2-
import { projectSrcDirectory, createSubFolders, showSubFolderQuickPick, createFile, createDir } from '../utils'
3-
import { middlewareTemplate } from '../templates/typeScriptFiles'
2+
import { projectSrcDirectory, createSubFolders, showSubFolderQuickPick, createFile, createDir, hasServerDir } from '../utils'
3+
import { nuxtMiddlewareTemplate, nitroDefaultTemplate } from '../templates/typeScriptFiles'
44

55
const createMiddleware = () => {
66
window
@@ -22,14 +22,16 @@ const createMiddleware = () => {
2222
name,
2323
subFolders: subFolders,
2424
commandType: 'middleware',
25-
content: middlewareTemplate
25+
content: nuxtMiddlewareTemplate
2626
})
2727

2828

2929
})
3030
}
3131

3232
const directCreateMiddleware = (path: string) => {
33+
const serverDir = hasServerDir()
34+
3335
window
3436
.showInputBox({
3537
prompt: 'What is your middleware name?',
@@ -42,7 +44,7 @@ const directCreateMiddleware = (path: string) => {
4244

4345
createFile({
4446
fileName: `${name}.ts`,
45-
content: middlewareTemplate,
47+
content: filePath.includes(`${serverDir}`) ? nitroDefaultTemplate : nuxtMiddlewareTemplate,
4648
fullPath: filePath,
4749
})
4850
})

src/commands/Nitro.ts

Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { window } from 'vscode'
22
import { projectSrcDirectory, createSubFolders, showSubFolderQuickPick, createFile, hasServerDir, createDir } from '../utils'
3-
import { apiTemplate } from '../templates/typeScriptFiles'
3+
import { nitroDefaultTemplate, nitroPluginTemplate } from '../templates/typeScriptFiles'
44

55
let serverDir = `${projectSrcDirectory()}/${hasServerDir()}/`
66

77

8-
const createApi = () => {
8+
const createNitroAPI = () => {
99
const apiDir = `${serverDir}/api`
1010

1111
window
@@ -26,12 +26,12 @@ const createApi = () => {
2626
name,
2727
subFolders: subFolders,
2828
commandType: 'api',
29-
content: apiTemplate(name)
29+
content: nitroDefaultTemplate
3030
})
3131
})
3232
}
3333

34-
const createRoute = () => {
34+
const createNitroRoute = () => {
3535
const routeDir = `${serverDir}/routes`
3636

3737
window
@@ -52,13 +52,65 @@ const createRoute = () => {
5252
name,
5353
subFolders: subFolders,
5454
commandType: 'route',
55-
content: apiTemplate(name)
55+
content: nitroDefaultTemplate
5656
})
5757
})
5858
}
5959

60+
const createNitroPlugin = () => {
61+
const pluginsDir = `${serverDir}/plugins`
6062

61-
const directCreateApi = (path: string) => {
63+
window
64+
.showInputBox({
65+
prompt: 'What is your route name?',
66+
placeHolder: 'Route name',
67+
})
68+
.then((name) => {
69+
if (!name) { return }
70+
71+
72+
createDir('server')
73+
createDir('server/plugins')
74+
75+
let subFolders = createSubFolders(pluginsDir, 'nitroPlugin')
76+
77+
showSubFolderQuickPick({
78+
name,
79+
subFolders: subFolders,
80+
commandType: 'nitroPlugin',
81+
content: nitroPluginTemplate
82+
})
83+
})
84+
}
85+
86+
const createNitroMiddleware = () => {
87+
const middlewareDir = `${serverDir}/middleware`
88+
89+
window
90+
.showInputBox({
91+
prompt: 'What is your route name?',
92+
placeHolder: 'Route name',
93+
})
94+
.then((name) => {
95+
if (!name) { return }
96+
97+
98+
createDir('server')
99+
createDir('server/middleware')
100+
101+
let subFolders = createSubFolders(middlewareDir, 'nitroMiddleware')
102+
103+
showSubFolderQuickPick({
104+
name,
105+
subFolders: subFolders,
106+
commandType: 'nitroMiddleware',
107+
content: nitroDefaultTemplate
108+
})
109+
})
110+
}
111+
112+
113+
const directCreateNitroAPI = (path: string) => {
62114
window
63115
.showInputBox({
64116
prompt: 'What is your api name?',
@@ -73,13 +125,13 @@ const directCreateApi = (path: string) => {
73125
let filePath = `${path}/${name}.ts`
74126
createFile({
75127
fileName: `${name}.ts`,
76-
content: apiTemplate(name),
128+
content: nitroDefaultTemplate,
77129
fullPath: filePath,
78130
})
79131
})
80132
}
81133

82-
const directCreateRoute = (path: string) => {
134+
const directCreateNitroRoute = (path: string) => {
83135
window
84136
.showInputBox({
85137
prompt: 'What is your route name?',
@@ -95,10 +147,17 @@ const directCreateRoute = (path: string) => {
95147

96148
createFile({
97149
fileName: `${name}.ts`,
98-
content: apiTemplate(name),
150+
content: nitroDefaultTemplate,
99151
fullPath: filePath,
100152
})
101153
})
102154
}
103155

104-
export { createApi, directCreateApi, createRoute, directCreateRoute}
156+
export {
157+
createNitroAPI,
158+
directCreateNitroAPI,
159+
createNitroRoute,
160+
directCreateNitroRoute,
161+
createNitroPlugin,
162+
createNitroMiddleware
163+
}

0 commit comments

Comments
 (0)