Skip to content

Commit 20a80bb

Browse files
committed
chore: utils
1 parent 3177861 commit 20a80bb

File tree

22 files changed

+231
-161
lines changed

22 files changed

+231
-161
lines changed

src/commands/CSS.ts

Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
import { window } from 'vscode'
2-
import {
3-
isNuxtTwo,
4-
createFile,
5-
projectSrcDirectory,
6-
runCommand,
7-
openExternalLink,
8-
addNuxtModule,
9-
getInstallationCommand,
10-
} from '../utils'
11-
import {
12-
unoCSSConfig,
13-
windiCSSConfig,
14-
tailwindCSSFile,
15-
tailwindCSSConfig,
16-
vuetifyConfigFile,
17-
} from '../templates/css'
2+
import { unoCSSConfig, windiCSSConfig, tailwindCSSFile, tailwindCSSConfig, vuetifyConfigFile } from '../templates'
3+
import { isNuxtTwo, createFile, projectSrcDirectory, runCommand, openExternalLink, addNuxtModule, getInstallationCommand } from '../utils'
184

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

7+
enum TailwindOptions {
8+
installModule = 'Install @nuxtjs/tailwindcss module and add it to nuxt config',
9+
createConfigFile = 'Create TailwindCSS config file',
10+
createTailwindCSSFile = 'Create tailwind.css file inside assets/css',
11+
}
12+
13+
enum WindiOptions {
14+
installModule = 'Install nuxt-windicss module and add it to nuxt config',
15+
createConfigFile = 'Create WindiCSS config file',
16+
}
17+
18+
enum UnoCSSOptions {
19+
installModule = 'Install unocss/nuxt module and add it to nuxt config',
20+
createConfigFile = 'Create uno.config.ts file',
21+
}
22+
23+
enum VuetifyOptions {
24+
installModule = 'Install @nuxtjs/vuetify module and add it to nuxt config',
25+
createConfigFile = 'Create vuetify.options.js file',
26+
}
27+
2128
function configureCSS() {
2229
window
2330
.showQuickPick(frameworks, {
@@ -39,11 +46,8 @@ function configureCSS() {
3946

4047
const configureTailwind = () => {
4148
try {
42-
const tailwindOptions = [
43-
'Install @nuxtjs/tailwindcss module and add it to nuxt config',
44-
'Create TailwindCSS config file',
45-
'Create tailwind.css file inside assets/css',
46-
]
49+
50+
const tailwindOptions = Object.values(TailwindOptions)
4751

4852
window
4953
.showQuickPick(tailwindOptions, {
@@ -52,7 +56,7 @@ const configureTailwind = () => {
5256
})
5357
.then(async (selections) => {
5458
if (selections !== undefined && selections.length > 0) {
55-
if (selections.includes('Install @nuxtjs/tailwindcss module and add it to nuxt config')) {
59+
if (selections.includes(TailwindOptions.installModule)) {
5660
const moduleName = '@nuxtjs/tailwindcss'
5761
const command = await getInstallationCommand(moduleName, true)
5862

@@ -65,7 +69,7 @@ const configureTailwind = () => {
6569
await addNuxtModule({ npm: moduleName })
6670
}
6771

68-
if (selections.includes('Create tailwind.css file inside assets/css')) {
72+
if (selections.includes(TailwindOptions.createTailwindCSSFile)) {
6973
const filePath = `${projectSrcDirectory()}/assets/css/tailwind.css`
7074

7175
await createFile({
@@ -75,7 +79,7 @@ const configureTailwind = () => {
7579
})
7680
}
7781

78-
if (selections.includes('Create TailwindCSS config file')) {
82+
if (selections.includes(TailwindOptions.createConfigFile)) {
7983
await createFile({
8084
fileName: `tailwind.config.${isNuxtTwo() ? 'js' : 'ts'}`,
8185
content: tailwindCSSConfig,
@@ -101,10 +105,7 @@ const configureWindi = async () => {
101105
try {
102106
const filePath = `${projectSrcDirectory()}/windi.config.${isNuxtTwo() ? 'js' : 'ts'}`
103107

104-
const windiOptions = [
105-
'Install nuxt-windicss module and add it to nuxt config',
106-
'Create windi.config.js file',
107-
]
108+
const windiOptions = Object.values(WindiOptions)
108109

109110
window
110111
.showQuickPick(windiOptions, {
@@ -113,7 +114,7 @@ const configureWindi = async () => {
113114
})
114115
.then(async (selections) => {
115116
if (selections !== undefined && selections.length > 0) {
116-
if (selections.includes('Install nuxt-windicss module and add it to nuxt config')) {
117+
if (selections.includes(WindiOptions.installModule)) {
117118
const moduleName = 'nuxt-windicss'
118119
const command = await getInstallationCommand(moduleName, true)
119120

@@ -127,7 +128,7 @@ const configureWindi = async () => {
127128
await addNuxtModule({ npm: moduleName })
128129
}
129130

130-
if (selections.includes('Create windi.config.js file')) {
131+
if (selections.includes(WindiOptions.createConfigFile)) {
131132
await createFile({
132133
fileName: `windi.config.${isNuxtTwo() ? 'js' : 'ts'}`,
133134
content: windiCSSConfig,
@@ -152,19 +153,16 @@ const configureUno = async () => {
152153
try {
153154
const filePath = `${projectSrcDirectory()}/uno.config.ts`
154155

155-
const unoCssOptions = [
156-
'Install unocss/nuxt module and add it to nuxt config',
157-
'Create uno.config.ts file',
158-
]
156+
const unoCSSOptions = Object.values(UnoCSSOptions)
159157

160158
window
161-
.showQuickPick(unoCssOptions, {
159+
.showQuickPick(unoCSSOptions, {
162160
canPickMany: true,
163161
placeHolder: 'Select files to create',
164162
})
165163
.then(async (selections) => {
166164
if (selections !== undefined && selections.length > 0) {
167-
if (selections.includes('Install unocss/nuxt module and add it to nuxt config')) {
165+
if (selections.includes(UnoCSSOptions.installModule)) {
168166
const moduleName = '@unocss/nuxt'
169167
const command = await getInstallationCommand(moduleName, true)
170168

@@ -178,7 +176,7 @@ const configureUno = async () => {
178176
await addNuxtModule({ npm: moduleName })
179177
}
180178

181-
if (selections.includes('Create uno.config.ts file')) {
179+
if (selections.includes(UnoCSSOptions.createConfigFile)) {
182180
await createFile({
183181
fileName: `uno.config.ts`,
184182
content: unoCSSConfig,
@@ -203,10 +201,7 @@ const configureVuetify = async () => {
203201
try {
204202
const filePath = `${projectSrcDirectory()}/vuetify.options.js`
205203

206-
const vuetifyOptions = [
207-
'Install @nuxtjs/vuetify module and add it to nuxt config',
208-
'Create vuetify.options.js file',
209-
]
204+
const vuetifyOptions = Object.values(VuetifyOptions)
210205

211206
window
212207
.showQuickPick(vuetifyOptions, {
@@ -215,7 +210,7 @@ const configureVuetify = async () => {
215210
})
216211
.then(async (selections) => {
217212
if (selections !== undefined && selections.length > 0) {
218-
if (selections.includes('Install @nuxtjs/vuetify module and add it to nuxt config')) {
213+
if (selections.includes(VuetifyOptions.installModule)) {
219214
const moduleName = '@nuxtjs/vuetify'
220215
const command = await getInstallationCommand(moduleName, true)
221216

@@ -229,7 +224,7 @@ const configureVuetify = async () => {
229224
await addNuxtModule({ npm: moduleName })
230225
}
231226

232-
if (selections.includes('Create vuetify.options.js file')) {
227+
if (selections.includes(VuetifyOptions.createConfigFile)) {
233228
await createFile({
234229
fileName: `vuetify.options.js`,
235230
content: vuetifyConfigFile,

src/commands/Component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const createComponent = () => {
99
placeHolder: 'component name',
1010
})
1111
.then((name) => {
12-
if (!name) {return}
12+
if (!name) { return }
1313

1414
let componentsDir = `${projectSrcDirectory()}/components`
1515

@@ -33,7 +33,7 @@ const directCreateComponent = (path: string) => {
3333
placeHolder: 'component name',
3434
})
3535
.then((name) => {
36-
if (!name) {return}
36+
if (!name) { return }
3737

3838
let filePath = `${path}/${name}.vue`
3939

src/commands/Composable.ts

Lines changed: 3 additions & 3 deletions
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 { composableTemplate } from '../templates/typeScriptFiles'
3+
import { composableTemplate } from '../templates'
44

55
const createComposable = () => {
66
window
@@ -10,7 +10,7 @@ const createComposable = () => {
1010
})
1111
.then((name) => {
1212

13-
if (!name) {return}
13+
if (!name) { return }
1414

1515
let composablesDir = `${projectSrcDirectory()}/composables`
1616

@@ -35,7 +35,7 @@ const directCreateComposable = (path: string) => {
3535
placeHolder: 'composable name',
3636
})
3737
.then((name) => {
38-
if (!name) {return}
38+
if (!name) { return }
3939

4040
let filePath = `${path}/${name}.ts`
4141

src/commands/FileTemplates.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { window } from 'vscode'
22
import * as fs from 'fs'
33

4-
import { projectSrcDirectory, createFile, createSubFolders, showSubFolderQuickPick, createVueTemplate, generateVueFileTemplate, generateVueFileBasicTemplate } from '../utils'
4+
import { projectSrcDirectory, createFile, createSubFolders, showSubFolderQuickPick, createVueTemplate, generateVueFileTemplate, generateVueFileBasicTemplate } from '../utils'
55

66

77
function createPageTemplate() {
@@ -45,7 +45,7 @@ const createFileFromTemplate = (template?: string) => {
4545
placeHolder: `Page name`,
4646
})
4747
.then((name) => {
48-
if (!name) {return}
48+
if (!name) { return }
4949

5050
let pagesDir = `${projectSrcDirectory()}/pages`
5151

@@ -72,7 +72,7 @@ const createFileFromTemplate = (template?: string) => {
7272
placeHolder: 'Layout name',
7373
})
7474
.then((name) => {
75-
if (!name) {return}
75+
if (!name) { return }
7676

7777
let layoutDir = `${projectSrcDirectory()}/layouts`
7878

@@ -101,7 +101,7 @@ const createFileTemplate = (type: string) => {
101101
placeHolder: `${type} name`,
102102
})
103103
.then((name) => {
104-
if (!name) {return}
104+
if (!name) { return }
105105

106106
let filePath = `${projectSrcDirectory()}/.vscode/${name}.${type}-template`
107107

src/commands/Layout.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const createLayout = () => {
1212
placeHolder: 'Layout name',
1313
})
1414
.then((name) => {
15-
if (!name) {return}
15+
if (!name) { return }
1616

1717
let layoutDir = `${projectSrcDirectory()}/layouts`
1818

@@ -35,7 +35,7 @@ const directCreateLayout = (path: string) => {
3535
placeHolder: 'layout name',
3636
})
3737
.then((name) => {
38-
if (!name) {return}
38+
if (!name) { return }
3939

4040
let filePath = `${path}/${name}.vue`
4141

src/commands/Linters.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,21 @@ import { window } from 'vscode'
22
import { createFile, projectRootDirectory, runCommand, getInstallationCommand } from '../utils'
33

44
import * as fs from 'fs'
5-
import { eslintConfig, eslintIgnore, stylelintConfig, stylelintIgnore } from '../templates/linters'
6-
5+
import { eslintConfig, eslintIgnore, stylelintConfig, stylelintIgnore } from '../templates'
76
const frameworks = ['Eslint', 'Stylelint']
87

8+
enum EslintOptions {
9+
installModule = 'Install Eslint module',
10+
addScriptToPackageJSON = 'Add lint script to package.json',
11+
createESLintAndIgnoreFiles = 'Create .eslintrc & .eslintignore files',
12+
}
13+
14+
enum StylelintOptions {
15+
installModule = 'Install Stylelint & Stylelint module',
16+
addScriptToPackageJSON = 'Add lint script to package.json',
17+
createStyleLintAndIgnoreFiles = 'Create .stylelintrc & .stylelintignore files',
18+
}
19+
920
function configureLinters() {
1021
window
1122
.showQuickPick(frameworks, {
@@ -25,11 +36,7 @@ function configureLinters() {
2536

2637
const configureEslint = () => {
2738
try {
28-
const eslintOptions = [
29-
'Install Eslint module',
30-
'Add lint script to package.json',
31-
'Create .eslintrc & .eslintignore files',
32-
]
39+
const eslintOptions = Object.values(EslintOptions)
3340

3441
window
3542
.showQuickPick(eslintOptions, {
@@ -38,7 +45,7 @@ const configureEslint = () => {
3845
})
3946
.then(async (selections) => {
4047
if (selections !== undefined && selections.length > 0) {
41-
if (selections.includes('Install Eslint module')) {
48+
if (selections.includes(EslintOptions.installModule)) {
4249
const moduleName = '@nuxtjs/eslint-config-typescript eslint'
4350
const command = await getInstallationCommand(moduleName, true)
4451

@@ -50,7 +57,7 @@ const configureEslint = () => {
5057
})
5158
}
5259

53-
if (selections.includes('Add lint script to package.json')) {
60+
if (selections.includes(EslintOptions.addScriptToPackageJSON)) {
5461
const packageJsonPath = `${projectRootDirectory()}/package.json`
5562
const packageJson = require(packageJsonPath)
5663

@@ -59,7 +66,7 @@ const configureEslint = () => {
5966
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf-8')
6067
}
6168

62-
if (selections.includes('Create .eslintrc & .eslintignore files')) {
69+
if (selections.includes(EslintOptions.createESLintAndIgnoreFiles)) {
6370
const eslintPath = `${projectRootDirectory()}/.eslintrc`
6471
const eslintIgnorePath = `${projectRootDirectory()}/.eslintignore`
6572

@@ -83,11 +90,7 @@ const configureEslint = () => {
8390
}
8491

8592
const configureStylelint = () => {
86-
const stylelintOptions = [
87-
'Install Stylelint & Stylelint module',
88-
'Add lint script to package.json',
89-
'Create .stylelintrc & .stylelintignore files',
90-
]
93+
const stylelintOptions = Object.values(StylelintOptions)
9194

9295
window
9396
.showQuickPick(stylelintOptions, {
@@ -96,7 +99,7 @@ const configureStylelint = () => {
9699
})
97100
.then(async (selections) => {
98101
if (selections !== undefined && selections.length > 0) {
99-
if (selections.includes('Install Stylelint & Stylelint module')) {
102+
if (selections.includes(StylelintOptions.installModule)) {
100103

101104
const moduleName = 'stylelint @nuxtjs/stylelint-module stylelint-config-recommended-vue'
102105
const command = await getInstallationCommand(moduleName, true)
@@ -110,7 +113,7 @@ const configureStylelint = () => {
110113

111114
}
112115

113-
if (selections.includes('Add lint script to package.json')) {
116+
if (selections.includes(StylelintOptions.addScriptToPackageJSON)) {
114117
const packageJsonPath = `${projectRootDirectory()}/package.json`
115118
const packageJson = require(packageJsonPath)
116119

@@ -119,7 +122,7 @@ const configureStylelint = () => {
119122
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf-8')
120123
}
121124

122-
if (selections.includes('Create .stylelintrc & .stylelintignore files')) {
125+
if (selections.includes(StylelintOptions.createStyleLintAndIgnoreFiles)) {
123126
const stylelintPath = `${projectRootDirectory()}/.stylelintrc`
124127
const stylelintIgnorePath = `${projectRootDirectory()}/.stylelintignore`
125128

0 commit comments

Comments
 (0)