Skip to content
Open
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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Using `Nuxtr: Create Nuxt project` command, you can create a new Nuxt project wi

### Directory and File Creation

Effortlessly generate all essential directories and files for your Nuxt project right from within VSCode. Utilize the command palette or context menus to swiftly create Vue/TypeScript files, as well as special files like [`.nuxtignore`](https://nuxt.com/docs/guide/directory-structure/nuxtignore), [`.nuxtrc`](https://nuxt.com/docs/api/configuration/nuxt-config), and [`app.config.ts`](https://nuxt.com/docs/guide/directory-structure/app-config).
Effortlessly generate all essential directories and files for your Nuxt project right from within VSCode. Utilize the command palette or context menus to swiftly create Vue/TypeScript/JavaScript files, as well as special files like [`.nuxtignore`](https://nuxt.com/docs/guide/directory-structure/nuxtignore), [`.nuxtrc`](https://nuxt.com/docs/api/configuration/nuxt-config), and [`app.config.(ts/js)`](https://nuxt.com/docs/guide/directory-structure/app-config).

To initiate any creation action, simply prepend it with the prefix **`Nuxtr: Create...`** and **`Nuxtr: Nuxt project structure...`** command for creating the entire project structure.

Expand All @@ -70,7 +70,8 @@ Customize Vue file templates with these settings:
"nuxtr.vueFiles.style.addStyleTag": true,
"nuxtr.vueFiles.style.alwaysScoped": true,
"nuxtr.vueFiles.style.defaultLanguage": "scss",
"nuxtr.piniaFiles.defaultTemplate": "options"
"nuxtr.piniaFiles.defaultTemplate": "options",
"nuxtr.nuxtFiles.defaultLanguage": "js"
```

Additionally, you can choose to automatically open the newly created file with:
Expand Down
13 changes: 11 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,16 @@
"setup"
],
"description": "Default language for script tag"
}
},
"nuxtr.nuxtFiles.defaultLanguage":{
"type": "string",
"default": "ts",
"enum": [
"js",
"ts"
],
"description": "Default language for nuxt files"
}
}
},
{
Expand Down Expand Up @@ -845,7 +854,7 @@
},
{
"command": "nuxtr.appConfig",
"title": "Create app.config.ts file",
"title": "Create app.config.(ts/js) file",
"category": "Nuxtr",
"when": "nuxtr.isNuxtProject"
},
Expand Down
4 changes: 2 additions & 2 deletions snippets/Nuxt/composables.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"useAsyncData": {
"prefix": "useAsyncData",
"body": [
"const { data, pending, error, refresh } = await useAsyncData(",
"const { data, status, error, refresh, clear } = await useAsyncData(",
" '$2',",
" () => \\$fetch('$3')",
");"
Expand Down Expand Up @@ -37,7 +37,7 @@
"useFetch": {
"prefix": "useFetch",
"body": [
"const { data, pending, error, refresh } = await useFetch('$1',{",
"const { data, status, error, refresh, clear } = await useFetch('$1',{",
" $2",
"})"
],
Expand Down
16 changes: 9 additions & 7 deletions src/commands/CSS.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { window } from 'vscode'
import { tailwindCSSFile, tailwindCSSJSConfig, tailwindCSSTSConfig, unoCSSConfig, vuetifyConfigFile, windiCSSConfig } from '../templates'
import { createFile, getInstallationCommand, isNuxtTwo, openExternalLink, projectRootDirectory, projectSrcDirectory, runCommand, updateNuxtConfig } from '../utils'
import { createFile, getInstallationCommand, isNuxtTwo, openExternalLink, projectRootDirectory, projectSrcDirectory, runCommand, updateNuxtConfig, nuxtrConfiguration } from '../utils'

const nuxtLang = nuxtrConfiguration().nuxtFiles.defaultLanguage

const frameworks = ['TailwindCSS', 'WindiCSS', 'UnoCSS', 'Vuetify']

Expand Down Expand Up @@ -106,9 +108,9 @@ const configureTailwind = () => {
if (selections.includes(TailwindOptions.createConfigFile)) {

await createFile({
fileName: `tailwind.config.${isNuxtTwo() ? 'js' : 'ts'}`,
fileName: `tailwind.config.${isNuxtTwo() ? 'js' : nuxtLang}`,
content: isNuxtTwo() ? tailwindCSSJSConfig : tailwindCSSTSConfig,
fullPath: `${projectRootDirectory()}/tailwind.config.${isNuxtTwo() ? 'js' : 'ts'}`,
fullPath: `${projectRootDirectory()}/tailwind.config.${isNuxtTwo() ? 'js' : nuxtLang}`,
})
}

Expand All @@ -128,7 +130,7 @@ const configureTailwind = () => {

const configureWindi = async () => {
try {
const filePath = `${await projectSrcDirectory()}/windi.config.${isNuxtTwo() ? 'js' : 'ts'}`
const filePath = `${await projectSrcDirectory()}/windi.config.${isNuxtTwo() ? 'js' : nuxtLang}`

const windiOptions = Object.values(WindiOptions)

Expand All @@ -155,7 +157,7 @@ const configureWindi = async () => {

if (selections.includes(WindiOptions.createConfigFile)) {
await createFile({
fileName: `windi.config.${isNuxtTwo() ? 'js' : 'ts'}`,
fileName: `windi.config.${isNuxtTwo() ? 'js' : nuxtLang}`,
content: windiCSSConfig,
fullPath: filePath,
})
Expand All @@ -176,7 +178,7 @@ const configureWindi = async () => {

const configureUno = async () => {
try {
const filePath = `${await projectSrcDirectory()}/uno.config.ts`
const filePath = `${await projectSrcDirectory()}/uno.config.${nuxtLang}`

const unoCSSOptions = Object.values(UnoCSSOptions)

Expand All @@ -203,7 +205,7 @@ const configureUno = async () => {

if (selections.includes(UnoCSSOptions.createConfigFile)) {
await createFile({
fileName: `uno.config.ts`,
fileName: `uno.config.${nuxtLang}`,
content: unoCSSConfig,
fullPath: filePath,
})
Expand Down
8 changes: 5 additions & 3 deletions src/commands/Composable.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { window } from 'vscode'
import { createDir, createFile, createSubFolders, normalizeFileExtension, projectSrcDirectory, showSubFolderQuickPick } from '../utils'
import { createDir, createFile, createSubFolders, normalizeFileExtension, projectSrcDirectory, showSubFolderQuickPick, nuxtrConfiguration } from '../utils'
import { composableTemplate } from '../templates'

const nuxtLang = nuxtrConfiguration().nuxtFiles.defaultLanguage

const createComposable = () => {
window
.showInputBox({
Expand Down Expand Up @@ -37,10 +39,10 @@ const directCreateComposable = (path: string) => {
.then((name) => {
if (!name) { return }

const filePath = `${path}/${normalizeFileExtension(name, '.ts')}.ts`
const filePath = `${path}/${normalizeFileExtension(name, `.${nuxtLang}`)}.${nuxtLang}`

createFile({
fileName: `${name}.ts`,
fileName: `${name}.${nuxtLang}`,
content: composableTemplate(name),
fullPath: filePath,
})
Expand Down
8 changes: 5 additions & 3 deletions src/commands/Middleware.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { window } from 'vscode'
import { createDir, createFile, createSubFolders, hasServerDir, normalizeFileExtension, projectSrcDirectory, showSubFolderQuickPick} from '../utils'
import { createDir, createFile, createSubFolders, hasServerDir, normalizeFileExtension, projectSrcDirectory, showSubFolderQuickPick, nuxtrConfiguration } from '../utils'
import { nitroDefaultTemplate, nuxtMiddlewareTemplate } from '../templates'

const nuxtLang = nuxtrConfiguration().nuxtFiles.defaultLanguage

const createMiddleware = () => {
window
.showInputBox({
Expand Down Expand Up @@ -40,10 +42,10 @@ const directCreateMiddleware = async (path: string) => {
.then((name) => {
if (!name) { return }

const filePath = `${path}/${normalizeFileExtension(name, '.ts')}.ts`
const filePath = `${path}/${normalizeFileExtension(name, `.${nuxtLang}`)}.${nuxtLang}`

createFile({
fileName: `${name}.ts`,
fileName: `${name}.${nuxtLang}`,
content: filePath.includes(`${serverDir}`) ? nitroDefaultTemplate : nuxtMiddlewareTemplate,
fullPath: filePath,
})
Expand Down
12 changes: 7 additions & 5 deletions src/commands/Nitro.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { window } from 'vscode'
import { createDir, createFile, createSubFolders, hasServerDir, normalizeFileExtension, projectSrcDirectory, showSubFolderQuickPick } from '../utils'
import { createDir, createFile, createSubFolders, hasServerDir, normalizeFileExtension, projectSrcDirectory, showSubFolderQuickPick, nuxtrConfiguration } from '../utils'
import { nitroDefaultTemplate, nitroPluginTemplate, nitroUtilTemplate } from '../templates'

const nuxtLang = nuxtrConfiguration().nuxtFiles.defaultLanguage

const createNitroAPI = () => {
window
.showInputBox({
Expand Down Expand Up @@ -145,9 +147,9 @@ const directCreateNitroAPI = (path: string) => {
await createDir('server')
await createDir('server/api')

const filePath = `${path}/${normalizeFileExtension(name, '.ts')}.ts`
const filePath = `${path}/${normalizeFileExtension(name, `.${nuxtLang}`)}.${nuxtLang}`
createFile({
fileName: `${name}.ts`,
fileName: `${name}.${nuxtLang}`,
content: nitroDefaultTemplate,
fullPath: filePath,
})
Expand All @@ -166,10 +168,10 @@ const directCreateNitroRoute = (path: string) => {
createDir('server')
createDir('server/routes')

const filePath = `${path}/${normalizeFileExtension(name, '.ts')}.ts`
const filePath = `${path}/${normalizeFileExtension(name, `.${nuxtLang}`)}.${nuxtLang}`

createFile({
fileName: `${name}.ts`,
fileName: `${name}.${nuxtLang}`,
content: nitroDefaultTemplate,
fullPath: filePath,
})
Expand Down
8 changes: 5 additions & 3 deletions src/commands/Plugin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { window } from 'vscode'
import { createDir, createFile, createSubFolders, hasServerDir, normalizeFileExtension, projectSrcDirectory, showSubFolderQuickPick } from '../utils'
import { createDir, createFile, createSubFolders, hasServerDir, normalizeFileExtension, projectSrcDirectory, showSubFolderQuickPick, nuxtrConfiguration } from '../utils'
import { nitroPluginTemplate, nuxtPluginTemplate } from '../templates'

const nuxtLang = nuxtrConfiguration().nuxtFiles.defaultLanguage

const createPlugin = () => {
window
.showInputBox({
Expand Down Expand Up @@ -39,11 +41,11 @@ const directCreatePlugin = async (path: string) => {
.then((name) => {
if (!name) { return }

const filePath = `${path}/${normalizeFileExtension(name, '.ts')}.ts`
const filePath = `${path}/${normalizeFileExtension(name, `.${nuxtLang}`)}.${nuxtLang}`


createFile({
fileName: `${name}.ts`,
fileName: `${name}.${nuxtLang}`,
content: filePath.includes(`${serverDir}`) ? nitroPluginTemplate : nuxtPluginTemplate,
fullPath: filePath,
})
Expand Down
9 changes: 6 additions & 3 deletions src/commands/Store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import {
normalizeFileExtension,
projectSrcDirectory,
runCommand,
updateNuxtConfig
updateNuxtConfig,
nuxtrConfiguration
} from '../utils'

import { vuexContent } from '../templates'

const nuxtLang = nuxtrConfiguration().nuxtFiles.defaultLanguage

async function detectPiniaModule() {
const moduleName = '@pinia/nuxt'
const isConfigured = isModuleConfigured(moduleName)
Expand Down Expand Up @@ -46,7 +49,7 @@ const createStore = () => {
.then(async (name: any) => {
if (!name) { return }

const filePath = `${await projectSrcDirectory()}/${isNuxtTwo() ? 'store' : 'stores'}/${name}.${isNuxtTwo() ? 'js' : 'ts'}`
const filePath = `${await projectSrcDirectory()}/${isNuxtTwo() ? 'store' : 'stores'}/${name}.${isNuxtTwo() ? 'js' : nuxtLang}`
await (isNuxtTwo() ? createFile({
fileName: name,
content: vuexContent,
Expand All @@ -70,7 +73,7 @@ const directCreateStore = (path: string) => {
.then(async (name) => {
if (!name) { return }

const filePath = `${path}/${normalizeFileExtension(name, isNuxtTwo() ? '.js' : '.ts' )}.${isNuxtTwo() ? 'js' : 'ts'}`
const filePath = `${path}/${normalizeFileExtension(name, isNuxtTwo() ? '.js' : `.${nuxtLang}` )}.${isNuxtTwo() ? 'js' : nuxtLang}`

await (isNuxtTwo() ? createFile({
fileName: name,
Expand Down
8 changes: 5 additions & 3 deletions src/commands/Structure.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { window } from 'vscode'
import { existsSync, mkdirSync } from 'node:fs'
import { createFile, generateVueFileTemplate, isNuxtTwo, projectRootDirectory, projectSrcDirectory } from '../utils'
import { createFile, generateVueFileTemplate, isNuxtTwo, projectRootDirectory, projectSrcDirectory, nuxtrConfiguration } from '../utils'
import { appConfigContent } from '../templates'

const nuxtLang = nuxtrConfiguration().nuxtFiles.defaultLanguage

function promptDirectorySelection() {
let directories = ['components', 'pages', 'assets', 'plugins', 'layouts', 'middleware', 'modules',]

Expand Down Expand Up @@ -53,9 +55,9 @@ const projectStructure = () => {

const appConfig = () => {
createFile({
fileName: 'app.config.ts',
fileName: `app.config.${nuxtLang}`,
content: appConfigContent,
fullPath: `${projectRootDirectory()}/app.config.ts`,
fullPath: `${projectRootDirectory()}/app.config.${nuxtLang}`,
})
}

Expand Down
8 changes: 5 additions & 3 deletions src/commands/Util.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { window } from 'vscode'
import { createDir, createFile, createSubFolders, hasServerDir, projectSrcDirectory, showSubFolderQuickPick } from '../utils'
import { createDir, createFile, createSubFolders, hasServerDir, projectSrcDirectory, showSubFolderQuickPick, nuxtrConfiguration } from '../utils'
import { nitroUtilTemplate, nuxtUtilTemplate } from '../templates'

const nuxtLang = nuxtrConfiguration().nuxtFiles.defaultLanguage

const createUtil = () => {
window
.showInputBox({
Expand Down Expand Up @@ -39,11 +41,11 @@ const directCreateUtil = async (path: string) => {
.then((name) => {
if (!name) { return }

const filePath = `${path}/${name}.ts`
const filePath = `${path}/${name}.${nuxtLang}`


createFile({
fileName: `${name}.ts`,
fileName: `${name}.${nuxtLang}`,
content: filePath.includes(`${serverDir}`) ? nitroUtilTemplate : nuxtUtilTemplate(),
fullPath: filePath,
})
Expand Down
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export interface NuxtrConfiguration {
defaultTemplate: string;
};
};
nuxtFiles:{
defaultLanguage: "js" | "ts"
}
intellisense: {
vueFiles: boolean;
nuxtignore: boolean;
Expand Down
Loading