1+ import { window } from 'vscode'
2+ import { existsSync } from 'fs'
3+ import { projectRootDirectory , runCommand , getInstallationCommand } from '../utils'
4+ import type { TSConfigNuxt } from '../types'
5+ import { writeTSConfig , readTSConfig } from 'pkg-types'
6+
7+ export enum PugConfigurationSteps {
8+ installPug = 'Install Pug' ,
9+ installLanguagePlugin = 'Install @vue/language-plugin-pug' ,
10+ addPluginToTSConfig = 'Add @vue/language-plugin-pug to tsconfig.json' ,
11+ }
12+
13+ const defaultOptions = Object . values ( PugConfigurationSteps )
14+
15+
16+ export const configurePug = ( options : string [ ] = defaultOptions ) => {
17+ try {
18+ window
19+ . showQuickPick ( options , {
20+ canPickMany : true ,
21+ placeHolder : 'Select files to create' ,
22+ } )
23+ . then ( async ( selections ) => {
24+ if ( selections !== undefined && selections . length > 0 ) {
25+ if ( selections . includes ( PugConfigurationSteps . installPug ) ) {
26+ const moduleName = 'pug'
27+ const command = await getInstallationCommand ( moduleName , true )
28+
29+ await runCommand ( {
30+ command,
31+ message : 'Installing Pug' ,
32+ successMessage : 'Pug installed successfully' ,
33+ errorMessage : 'Pug installation failed' ,
34+ } )
35+ }
36+
37+ if ( selections . includes ( PugConfigurationSteps . installLanguagePlugin ) ) {
38+ const moduleName = '@vue/language-plugin-pug'
39+ const command = await getInstallationCommand ( moduleName , true )
40+
41+ await runCommand ( {
42+ command,
43+ message : 'Installing @vue/language-plugin-pug' ,
44+ successMessage : '@vue/language-plugin-pug installed successfully' ,
45+ errorMessage : '@vue/language-plugin-pug installation failed' ,
46+ } )
47+ }
48+
49+ if ( selections . includes ( PugConfigurationSteps . addPluginToTSConfig ) ) {
50+ const path = `${ projectRootDirectory ( ) } /tsconfig.json` ;
51+
52+ if ( ! existsSync ( path ) ) {
53+ return ;
54+ }
55+
56+ let tsconfig : TSConfigNuxt = await readTSConfig ( path ) ;
57+ tsconfig . vueCompilerOptions = {
58+ plugins : [
59+ '@vue/language-plugin-pug'
60+ ]
61+ }
62+
63+ await writeTSConfig ( path , tsconfig )
64+
65+ window . showInformationMessage ( 'Pug is added to tsconfig.json' )
66+ }
67+ }
68+ } )
69+ } catch ( error ) {
70+ console . error ( error )
71+ }
72+ }
0 commit comments