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