Skip to content

Commit 3447255

Browse files
committed
feat: pinia setup template
1 parent a05527b commit 3447255

File tree

14 files changed

+70
-25
lines changed

14 files changed

+70
-25
lines changed

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@
500500
}
501501
},
502502
{
503-
"title": "Vue Files",
503+
"title": "File Creation",
504504
"type": "object",
505505
"properties": {
506506
"nuxtr.vueFiles.template.defaultLanguage": {
@@ -571,6 +571,15 @@
571571
"type": "string",
572572
"default": "default.layout-template",
573573
"description": "Default layout template"
574+
},
575+
"nuxtr.piniaFiles.defaultTemplate": {
576+
"type": "string",
577+
"default": "options",
578+
"enum": [
579+
"options",
580+
"setup"
581+
],
582+
"description": "Default language for script tag"
574583
}
575584
}
576585
},

src/commands/Component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { window } from 'vscode'
22
import { projectSrcDirectory, createSubFolders, showSubFolderQuickPick, createFile, createDir } from '../utils'
3-
import { generateVueFileBasicTemplate } from '../utils/vueFiles'
3+
import { generateVueFileBasicTemplate } from '../utils/files'
44

55
const createComponent = () => {
66
window

src/commands/Layout.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { window } from 'vscode'
22
import { projectSrcDirectory, createFile, createDir } from '../utils'
33

44

5-
import { generateVueFileTemplate } from '../utils/vueFiles'
5+
import { generateVueFileTemplate } from '../utils/files'
66

77

88
const createLayout = () => {

src/commands/Page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { window } from 'vscode'
22
import { createSubFolders, showSubFolderQuickPick, createFile, projectSrcDirectory, createDir } from '../utils'
33

4-
import { generateVueFileTemplate } from '../utils/vueFiles'
4+
import { generateVueFileTemplate } from '../utils/files'
55

66
const createPage = () => {
77
window

src/commands/Store.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { window } from 'vscode'
2-
import { projectSrcDirectory, isNuxtTwo, createFile } from '../utils'
3-
import { piniaContent, vuexContent } from '../templates'
2+
import { projectSrcDirectory, isNuxtTwo, createFile, generatePiniaTemplates } from '../utils'
3+
import { vuexContent } from '../templates'
44

55
const createStore = () => {
66
window
@@ -21,7 +21,7 @@ const createStore = () => {
2121
} else {
2222
createFile({
2323
fileName: name,
24-
content: piniaContent(name),
24+
content: generatePiniaTemplates(name),
2525
fullPath: filePath,
2626
})
2727
}
@@ -48,7 +48,7 @@ const directCreateStore = (path: string) => {
4848
} else {
4949
createFile({
5050
fileName: name,
51-
content: piniaContent(name),
51+
content: generatePiniaTemplates(name),
5252
fullPath: filePath,
5353
})
5454
}

src/commands/Structure.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { window } from 'vscode'
22
import { mkdirSync, existsSync } from 'node:fs'
33
import { isNuxtTwo, createFile, projectRootDirectory, projectSrcDirectory } from '../utils'
44
import { appConfigContent } from '../templates'
5-
import { generateVueFileTemplate } from '../utils/vueFiles'
5+
import { generateVueFileTemplate } from '../utils/files'
66

77
function promptDirectorySelection() {
88
let directories = [

src/templates/appConfig.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const appConfigContent = `export default defineAppConfig({
2+
3+
})
4+
`
5+
6+
export { appConfigContent }

src/templates/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
nitroUtilTemplate
1111
} from './typeScriptFiles'
1212
import { generateStyleTag, generateScriptTag, templateTag } from './vueFiles'
13-
import { vuexContent, piniaContent, appConfigContent } from './stores'
13+
import { vuexContent, piniaOptionsContent, piniaSetupContent } from './stores'
14+
import { appConfigContent } from './appConfig'
1415

1516

1617
export {
@@ -34,6 +35,7 @@ export {
3435
generateScriptTag,
3536
templateTag,
3637
vuexContent,
37-
piniaContent,
38+
piniaOptionsContent,
39+
piniaSetupContent,
3840
appConfigContent
3941
}

src/templates/stores.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
import { capitalize } from "string-ts"
22

3-
const piniaContent = (name: string) => {
3+
const piniaOptionsContent = (name: string): string => {
44
return `import { defineStore } from 'pinia'
55
66
export const useMy${capitalize(name)}Store = defineStore({
77
id: 'my${capitalize(name)}Store',
88
state: () => ({ }),
9-
actions: {},
9+
actions: {}
1010
})
1111
`}
1212

13+
const piniaSetupContent = (name: string): string => {
14+
return `import { defineStore } from 'pinia'
15+
16+
export const use${capitalize(name)}Store = defineStore('${name}', () => {
17+
return {}
18+
})
19+
`}
20+
21+
1322
const vuexContent = `export const state = () => ({ })
1423
1524
export const mutations = {}
1625
1726
export const actions = { }
1827
`
1928

20-
const appConfigContent = `export default defineAppConfig({
21-
22-
})
23-
`
29+
// piniaContent,
2430

2531
export {
26-
piniaContent,
32+
piniaOptionsContent,
33+
piniaSetupContent,
2734
vuexContent,
28-
appConfigContent
2935
}

src/types.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ export interface NuxtrConfiguration {
5454
nuxt: boolean;
5555
nitro: boolean;
5656
}
57+
58+
piniaFiles: {
59+
defaultTemplate: "options" | "setup";
60+
}
5761
}
5862

5963
interface TSConfigNuxt extends TSConfig {

0 commit comments

Comments
 (0)