|
1 | | -'use strict'; |
2 | | - |
| 1 | +import * as fs from 'fs'; |
| 2 | +import * as path from 'path'; |
3 | 3 | import * as vscode from 'vscode'; |
4 | 4 | import { IFeature } from '../feature'; |
5 | 5 | import { ILogger } from '../logging'; |
@@ -76,31 +76,52 @@ export class PDKFeature implements IFeature { |
76 | 76 | this.terminal.dispose(); |
77 | 77 | } |
78 | 78 |
|
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 | | - }; |
| 79 | + private async pdkNewModuleCommand(): Promise<void> { |
| 80 | + const name = await vscode.window.showInputBox({ |
| 81 | + prompt: 'Enter a name for the new Puppet module', |
| 82 | + }); |
| 83 | + if (name === undefined) { |
| 84 | + vscode.window.showWarningMessage('No module name specifed. Exiting.'); |
| 85 | + return; |
| 86 | + } |
| 87 | + const directory = await vscode.window.showOpenDialog({ |
| 88 | + canSelectMany: false, |
| 89 | + canSelectFiles: false, |
| 90 | + canSelectFolders: true, |
| 91 | + openLabel: 'Choose the path for the new Puppet module', |
| 92 | + }); |
| 93 | + if (directory === undefined) { |
| 94 | + vscode.window.showWarningMessage('No directory specifed. Exiting.'); |
| 95 | + return; |
| 96 | + } |
| 97 | + |
| 98 | + const p = path.join(directory[0].fsPath, name); |
| 99 | + |
| 100 | + this.terminal.sendText(`pdk new module --skip-interview ${name} ${p}`); |
| 101 | + this.terminal.show(); |
90 | 102 |
|
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); |
| 103 | + await new Promise<void>((resolve) => { |
| 104 | + let count = 0; |
| 105 | + const handle = setInterval(() => { |
| 106 | + count++; |
| 107 | + if (count >= 30) { |
| 108 | + clearInterval(handle); |
| 109 | + resolve(); |
| 110 | + return; |
102 | 111 | } |
103 | | - }); |
| 112 | + |
| 113 | + if (fs.existsSync(p)) { |
| 114 | + resolve(); |
| 115 | + return; |
| 116 | + } |
| 117 | + }, 1000); |
104 | 118 | }); |
| 119 | + |
| 120 | + const uri = vscode.Uri.file(p); |
| 121 | + await vscode.commands.executeCommand('vscode.openFolder', uri); |
| 122 | + |
| 123 | + if (reporter) { |
| 124 | + reporter.sendTelemetryEvent(PDKCommandStrings.PdkNewModuleCommandId); |
| 125 | + } |
105 | 126 | } |
106 | 127 | } |
0 commit comments