1
1
'use strict' ;
2
2
3
+ import * as fs from 'fs' ;
4
+ import * as path from 'path' ;
3
5
import * as vscode from 'vscode' ;
4
6
import { IFeature } from '../feature' ;
5
7
import { ILogger } from '../logging' ;
@@ -47,25 +49,21 @@ export class PDKFeature implements IFeature {
47
49
{ id : 'extension.pdkNewDefinedType' , request : 'pdk new defined_type' , type : 'Puppet defined_type' } ,
48
50
] . forEach ( ( command ) => {
49
51
context . subscriptions . push (
50
- vscode . commands . registerCommand ( command . id , ( ) => {
51
- const nameOpts : vscode . QuickPickOptions = {
52
- placeHolder : `Enter a name for the new ${ command . type } ` ,
53
- matchOnDescription : true ,
54
- matchOnDetail : true ,
55
- } ;
56
-
57
- vscode . window . showInputBox ( nameOpts ) . then ( ( name ) => {
58
- if ( name === undefined ) {
59
- vscode . window . showWarningMessage ( `No ${ command . type } value specifed. Exiting.` ) ;
60
- return ;
61
- }
62
- const request = `${ command . request } ${ name } ` ;
63
- this . terminal . sendText ( request ) ;
64
- this . terminal . show ( ) ;
65
- if ( reporter ) {
66
- reporter . sendTelemetryEvent ( command . id ) ;
67
- }
52
+ vscode . commands . registerCommand ( command . id , async ( ) => {
53
+ const name = await vscode . window . showInputBox ( {
54
+ prompt : `Enter a name for the new ${ command . type } ` ,
68
55
} ) ;
56
+ if ( name === undefined ) {
57
+ vscode . window . showWarningMessage ( 'No module name specifed. Exiting.' ) ;
58
+ return ;
59
+ }
60
+
61
+ const request = `${ command . request } ${ name } ` ;
62
+ this . terminal . sendText ( request ) ;
63
+ this . terminal . show ( ) ;
64
+ if ( reporter ) {
65
+ reporter . sendTelemetryEvent ( command . id ) ;
66
+ }
69
67
} ) ,
70
68
) ;
71
69
logger . debug ( `Registered ${ command . id } command` ) ;
@@ -76,31 +74,52 @@ export class PDKFeature implements IFeature {
76
74
this . terminal . dispose ( ) ;
77
75
}
78
76
79
- private pdkNewModuleCommand ( ) : void {
80
- const nameOpts : vscode . QuickPickOptions = {
81
- placeHolder : 'Enter a name for the new Puppet module' ,
82
- matchOnDescription : true ,
83
- matchOnDetail : true ,
84
- } ;
85
- const dirOpts : vscode . QuickPickOptions = {
86
- placeHolder : 'Enter a path for the new Puppet module' ,
87
- matchOnDescription : true ,
88
- matchOnDetail : true ,
89
- } ;
77
+ private async pdkNewModuleCommand ( ) : Promise < void > {
78
+ const name = await vscode . window . showInputBox ( {
79
+ prompt : 'Enter a name for the new Puppet module' ,
80
+ } ) ;
81
+ if ( name === undefined ) {
82
+ vscode . window . showWarningMessage ( 'No module name specifed. Exiting.' ) ;
83
+ return ;
84
+ }
85
+ const directory = await vscode . window . showOpenDialog ( {
86
+ canSelectMany : false ,
87
+ canSelectFiles : false ,
88
+ canSelectFolders : true ,
89
+ openLabel : 'Choose the path for the new Puppet module' ,
90
+ } ) ;
91
+ if ( directory === undefined ) {
92
+ vscode . window . showWarningMessage ( 'No directory specifed. Exiting.' ) ;
93
+ return ;
94
+ }
95
+
96
+ const p = path . join ( directory [ 0 ] . fsPath , name ) ;
97
+
98
+ this . terminal . sendText ( `pdk new module --skip-interview ${ name } ${ p } ` ) ;
99
+ this . terminal . show ( ) ;
90
100
91
- vscode . window . showInputBox ( nameOpts ) . then ( ( moduleName ) => {
92
- if ( moduleName === undefined ) {
93
- vscode . window . showWarningMessage ( 'No module name specifed. Exiting.' ) ;
94
- return ;
95
- }
96
- vscode . window . showInputBox ( dirOpts ) . then ( ( dir ) => {
97
- this . terminal . sendText ( `pdk new module --skip-interview ${ moduleName } ${ dir } ` ) ;
98
- this . terminal . sendText ( `code ${ dir } ` ) ;
99
- this . terminal . show ( ) ;
100
- if ( reporter ) {
101
- reporter . sendTelemetryEvent ( PDKCommandStrings . PdkNewModuleCommandId ) ;
101
+ await new Promise < void > ( ( resolve ) => {
102
+ let count = 0 ;
103
+ const handle = setInterval ( ( ) => {
104
+ count ++ ;
105
+ if ( count >= 30 ) {
106
+ clearInterval ( handle ) ;
107
+ resolve ( ) ;
108
+ return ;
102
109
}
103
- } ) ;
110
+
111
+ if ( fs . existsSync ( p ) ) {
112
+ resolve ( ) ;
113
+ return ;
114
+ }
115
+ } , 1000 ) ;
104
116
} ) ;
117
+
118
+ const uri = vscode . Uri . file ( p ) ;
119
+ await vscode . commands . executeCommand ( 'vscode.openFolder' , uri ) ;
120
+
121
+ if ( reporter ) {
122
+ reporter . sendTelemetryEvent ( PDKCommandStrings . PdkNewModuleCommandId ) ;
123
+ }
105
124
}
106
125
}
0 commit comments