Skip to content

Commit 0391cb6

Browse files
committed
Merge remote-tracking branch 'origin/main' into create-projects-command
2 parents 83f5878 + 701518e commit 0391cb6

File tree

5 files changed

+35
-18
lines changed

5 files changed

+35
-18
lines changed

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,12 @@
898898
"category": "Nuxtr",
899899
"when": "nuxtr.isNuxtProject"
900900
},
901+
{
902+
"command": "nuxtr.errorLayout",
903+
"title": "Create error.vue Layout",
904+
"category": "Nuxtr",
905+
"when": "nuxtr.isNuxtProject"
906+
},
901907
{
902908
"command": "nuxtr.installDependencies",
903909
"title": "Install Dependencies",

src/commands/Structure.ts

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
import { window } from 'vscode'
22
import { mkdirSync, existsSync } from 'node:fs'
3-
import { isNuxtTwo, createFile, projectRootDirectory, projectSrcDirectory } from '../utils'
3+
import { isNuxtTwo, createFile, projectRootDirectory, projectSrcDirectory, generateVueFileTemplate } from '../utils'
44
import { appConfigContent } from '../templates'
5-
import { generateVueFileTemplate } from '../utils/files'
65

76
function promptDirectorySelection() {
8-
let directories = [
9-
'components',
10-
'pages',
11-
'assets',
12-
'plugins',
13-
'layouts',
14-
'middleware',
15-
'modules',
16-
]
7+
let directories = ['components', 'pages', 'assets', 'plugins', 'layouts', 'middleware', 'modules',]
178

189
let nuxtTwoDirectories = ['static', 'store',]
1910

@@ -23,6 +14,8 @@ function promptDirectorySelection() {
2314
? (directories = [...directories, ...nuxtTwoDirectories])
2415
: (directories = [...directories, ...nuxtThreeDirectories])
2516

17+
directories.sort()
18+
2619
window
2720
.showQuickPick(directories, {
2821
canPickMany: true,
@@ -31,16 +24,24 @@ function promptDirectorySelection() {
3124
.then((selectedDirs) => {
3225
if (selectedDirs !== undefined && selectedDirs.length > 0) {
3326
selectedDirs.forEach((dir) => {
34-
let path = `${projectSrcDirectory()}/${dir}`
35-
if (!existsSync(path)) {
36-
mkdirSync(path)
27+
let dirPath = `${projectSrcDirectory()}/${dir}`
28+
if (!existsSync(dirPath)) {
29+
mkdirSync(dirPath)
3730
}
3831

3932
if (dir === 'pages') {
4033
createFile({
4134
fileName: `index.vue`,
4235
content: generateVueFileTemplate('page'),
43-
fullPath: `${path}/index.vue`,
36+
fullPath: `${dirPath}/index.vue`,
37+
})
38+
}
39+
40+
if (dir === 'layouts') {
41+
createFile({
42+
fileName: `default.vue`,
43+
content: generateVueFileTemplate('layout'),
44+
fullPath: `${dirPath}/default.vue`,
4445
})
4546
}
4647
})
@@ -76,4 +77,12 @@ const nuxtRC = () => {
7677
})
7778
}
7879

79-
export { projectStructure, appConfig, nuxtIgnore, nuxtRC }
80+
const errorLayout = () => {
81+
createFile({
82+
fileName: 'error.vue',
83+
content: generateVueFileTemplate('page'),
84+
fullPath: `${projectSrcDirectory()}/error.vue`,
85+
})
86+
}
87+
88+
export { projectStructure, appConfig, nuxtIgnore, nuxtRC, errorLayout }

src/commands/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { createLayout, directCreateLayout } from './Layout'
55
import { createPlugin, directCreatePlugin } from './Plugin'
66
import { createMiddleware, directCreateMiddleware } from './Middleware'
77
import { createNitroAPI, directCreateNitroAPI, createNitroRoute, directCreateNitroRoute, createNitroPlugin, createNitroMiddleware, createNitroUtil } from './Nitro'
8-
import { projectStructure, appConfig, nuxtIgnore, nuxtRC } from './Structure'
8+
import { projectStructure, appConfig, nuxtIgnore, nuxtRC, errorLayout } from './Structure'
99
import { openDocumentation, openModules } from './externalLinks'
1010
import { nuxtDev, nuxtBuild, nuxtGenerate, nuxtCleanUp, nuxtAnalyze, nuxtInfo, nuxtModule, showCLICommands } from './Nuxi'
1111
import { createStore, directCreateStore } from './Store'
@@ -60,6 +60,7 @@ const commands = {
6060
appConfig,
6161
nuxtIgnore,
6262
nuxtRC,
63+
errorLayout,
6364
installDependencies,
6465
upgradePackage,
6566
managePackageVersion,

src/extension.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const commandList = [
3636
{ command: 'nuxtr.appConfig', function: nuxtrCommands.appConfig },
3737
{ command: 'nuxtr.nuxtIgnore', function: nuxtrCommands.nuxtIgnore },
3838
{ command: 'nuxtr.nuxtRC', function: nuxtrCommands.nuxtRC },
39+
{ command: 'nuxtr.errorLayout', function: nuxtrCommands.errorLayout },
3940
{ command: 'nuxtr.installDependencies', function: nuxtrCommands.installDependencies },
4041
{ command: 'nuxtr.openSettings', function: nuxtrCommands.openSettings },
4142
{ command: 'nuxtr.configureCSS', function: nuxtrCommands.configureCSS },

src/utils/files.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let piniaConfig = nuxtrConfiguration().piniaFiles.defaultTemplate
77
let eolConfiguration = vscodeConfiguration().files.eol
88
let eol = eolConfiguration === 'auto' ? '\n' : eolConfiguration
99

10-
export function generateVueFileTemplate(type: string, template?: string) {
10+
export function generateVueFileTemplate(type: 'page' | 'layout', template?: string) {
1111
const userDefaultTemplate = template || (type === 'page'
1212
? vueFilesConfig.pages.defaultTemplate
1313
: vueFilesConfig.layouts.defaultTemplate);

0 commit comments

Comments
 (0)