Skip to content

Commit 80eab3f

Browse files
committed
(GH-115) Add PDK Support
This adds minimal support for PDK commands: new module, new class, validate, and test unit
1 parent f6449ae commit 80eab3f

15 files changed

+377
-43
lines changed

client/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ tmp/
55

66
// Ignore generated module output
77
*.vsix
8+
.vscode-test

client/CHANGELOG.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
66

77
## Unreleased
88

9-
## 0.6.1
10-
9+
* Added support for the PDK(https://puppet.com/blog/develop-modules-faster-new-puppet-development-kit)
1110
* Added telemetry to understand which parts Puppet users find useful. This will help us refine which commands we add in the future. We track whether the following commands are executed:
12-
* `foo`
13-
* `bar`
11+
* `puppet resource`
12+
* `pdk new module`
13+
* `pdk new class`
14+
* `pdk validate`
15+
* `pdk test unit`
1416

1517
> Please` note, you can turn off telemetry reporting for VS Code and all extensions through the ["telemetry.enableTelemetry": false setting](https://code.visualstudio.com/docs/supporting/faq#_how-to-disable-telemetry-reporting).
1618

client/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Open any Puppet manifest with the extension '.pp' or 'epp' and the extension wil
3838
- Validation of `metadata.json` files
3939
- Import from `puppet resource` directly into manifests
4040
- Node graph preview
41+
- Puppet Development Kit integration
4142

4243
## Feature information
4344

@@ -77,6 +78,21 @@ You can preview the [node graph](https://puppet.com/blog/visualize-your-infrastr
7778

7879
The node graph will appear next to the manifest
7980

81+
### Puppet Development Kit
82+
83+
You can use the [Puppet Development Kit](https://puppet.com/blog/develop-modules-faster-new-puppet-development-kit) inside VS Code from the command palette.
84+
85+
** Note: The PDK must be installed prior to using these commands
86+
87+
The following commands are supported:
88+
89+
- pdk new module
90+
- pdk new class
91+
- pdk validate
92+
- pdk test unit
93+
94+
To use any of the above commands, open the command palette and start typing a command. You can also use the right-click context menu or the editor menu to reach these commands.
95+
8096
## Installing the Extension
8197

8298
You can install the official release of the Puppet extension by following the steps
@@ -117,3 +133,4 @@ This extension collects telemetry data to help us build a better experience for
117133
## License
118134

119135
This extension is [licensed under the Apache-2.0 License](LICENSE.txt).
136+

client/images/puppet_logo_sm.svg

Lines changed: 5 additions & 0 deletions
Loading

client/package-lock.json

Lines changed: 17 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 107 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@
4141
"onCommand:extension.puppetLint",
4242
"onCommand:extension.puppetParserValidate",
4343
"onCommand:extension.puppetShowNodeGraphToSide",
44-
"onCommand:extension.puppetResource"
44+
"onCommand:extension.puppetResource",
45+
"onCommand:extension.pdkNewModule",
46+
"onCommand:extension.pdkNewClass",
47+
"onCommand:extension.pdkTestUnit",
48+
"onCommand:extension.pdkValidate"
4549
],
4650
"main": "./out/src/extension",
4751
"contributes": {
@@ -83,11 +87,34 @@
8387
}
8488
],
8589
"commands": [
90+
{
91+
"command": "extension.pdkNewModule",
92+
"category": "Puppet",
93+
"title": "PDK New Module",
94+
"icon": {
95+
"dark": "images/puppet_logo_sm.svg",
96+
"light": "images/puppet_logo_sm.svg"
97+
}
98+
},
99+
{
100+
"command": "extension.pdkTestUnit",
101+
"category": "Puppet",
102+
"title": "PDK Test Unit"
103+
},
104+
{
105+
"command": "extension.pdkValidate",
106+
"category": "Puppet",
107+
"title": "PDK Validate"
108+
},
109+
{
110+
"command": "extension.pdkNewClass",
111+
"category": "Puppet",
112+
"title": "PDK New Class"
113+
},
86114
{
87115
"command": "extension.puppetResource",
88116
"category": "Puppet",
89-
"title": "Puppet Resource",
90-
"when": "editorTextFocus && editorLangId == 'puppet'"
117+
"title": "Puppet Resource"
91118
},
92119
{
93120
"command": "extension.puppetShowNodeGraphToSide",
@@ -100,24 +127,87 @@
100127
}
101128
],
102129
"menus": {
130+
"commandPalette": [
131+
{
132+
"command": "extension.pdkNewModule"
133+
},
134+
{
135+
"command": "extension.pdkTestUnit",
136+
"when": "resourceLangId == 'puppet'"
137+
},
138+
{
139+
"command": "extension.pdkValidate",
140+
"when": "resourceLangId == 'puppet'"
141+
},
142+
{
143+
"command": "extension.pdkNewClass",
144+
"when": "resourceLangId == 'puppet'"
145+
},
146+
{
147+
"command": "extension.puppetResource",
148+
"when": "editorTextFocus && editorLangId == 'puppet'"
149+
},
150+
{
151+
"command": "extension.puppetShowNodeGraphToSide",
152+
"when": "resourceLangId == 'puppet'"
153+
}
154+
],
103155
"editor/title": [
156+
{
157+
"command": "extension.pdkNewModule",
158+
"group": "navigation@100"
159+
},
160+
{
161+
"when": "resourceLangId == 'puppet'",
162+
"command": "extension.pdkNewClass",
163+
"group": "pdk@2"
164+
},
165+
{
166+
"when": "resourceLangId == 'puppet' ",
167+
"command": "extension.pdkValidate",
168+
"group": "pdk@3"
169+
},
170+
{
171+
"when": "resourceLangId == 'puppet'",
172+
"command": "extension.pdkTestUnit",
173+
"group": "pdk@4"
174+
},
104175
{
105176
"when": "resourceLangId == 'puppet'",
106177
"command": "extension.puppetShowNodeGraphToSide",
107-
"alt": "extension.puppetShowNodeGraphToSide"
178+
"group": "puppet"
179+
},
180+
{
181+
"when": "resourceLangId == 'puppet'",
182+
"command": "extension.puppetResource",
183+
"group": "puppet"
108184
}
109185
],
110186
"editor/context": [
187+
{
188+
"when": "resourceLangId == 'puppet'",
189+
"command": "extension.pdkNewClass",
190+
"group": "pdk@1"
191+
},
192+
{
193+
"when": "resourceLangId == 'puppet'",
194+
"command": "extension.pdkValidate",
195+
"group": "pdk@2"
196+
},
197+
{
198+
"when": "resourceLangId == 'puppet'",
199+
"command": "extension.pdkTestUnit",
200+
"group": "pdk@3"
201+
},
111202
{
112203
"when": "resourceLangId == 'puppet'",
113204
"command": "extension.puppetShowNodeGraphToSide",
114-
"alt": "extension.puppetShowNodeGraphToSide"
205+
"group": "puppet"
115206
},
116207
{
117208
"when": "resourceLangId == 'puppet'",
118209
"command": "extension.puppetResource",
119-
"alt": "extension.puppetResource",
120-
"group": ""
210+
"group": "puppet"
121211
}
122212
]
123213
},
@@ -168,9 +258,9 @@
168258
"description": "Set the minimum log level that the user will see on the Puppet OutputChannel (Allowed values: verbose, debug, normal, warning, error)"
169259
},
170260
"puppet.puppetAgentDir": {
171-
"type": "string",
172-
"default": "normal",
173-
"description": "The fully qualified path to the Puppet agent install directory. For example: 'C:\\Program Files\\Puppet Labs\\Puppet' or '/opt/puppetlabs/puppet'"
261+
"type": "string",
262+
"default": "normal",
263+
"description": "The fully qualified path to the Puppet agent install directory. For example: 'C:\\Program Files\\Puppet Labs\\Puppet' or '/opt/puppetlabs/puppet'"
174264
}
175265
}
176266
}
@@ -183,16 +273,16 @@
183273
"test": "node ./node_modules/vscode/bin/test"
184274
},
185275
"devDependencies": {
186-
"typescript": "^2.0.3",
187-
"vscode": "^1.0.0",
188-
"vsce": "^1.18.0",
276+
"@types/mocha": "^2.2.32",
277+
"@types/node": "^6.0.40",
278+
"del": "^2.2.2",
189279
"gulp": "^3.9.1",
190280
"gulp-bump": "^2.7.0",
191-
"yargs": "^8.0.1",
192-
"del": "^2.2.2",
193281
"run-sequence": "^1.2.2",
194-
"@types/node": "^6.0.40",
195-
"@types/mocha": "^2.2.32"
282+
"typescript": "^2.0.3",
283+
"vsce": "^1.18.0",
284+
"vscode": "^1.0.0",
285+
"yargs": "^8.0.1"
196286
},
197287
"dependencies": {
198288
"vscode-languageclient": "~3.3.0",
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict';
2+
3+
import * as vscode from 'vscode';
4+
import * as cp from 'child_process';
5+
import ChildProcess = cp.ChildProcess;
6+
import { Logger } from '../../logging';
7+
import { reporter } from '../../telemetry/telemetry';
8+
import * as messages from '../../messages';
9+
10+
export class pdkNewClassCommand {
11+
private logger: Logger = undefined;
12+
private terminal: vscode.Terminal = undefined;
13+
14+
constructor(logger: Logger, terminal: vscode.Terminal) {
15+
this.logger = logger;
16+
this.terminal = terminal;
17+
}
18+
19+
public run() {
20+
let nameOpts: vscode.QuickPickOptions = {
21+
placeHolder: "Enter a name for the new Puppet class",
22+
matchOnDescription: true,
23+
matchOnDetail: true
24+
};
25+
vscode.window.showInputBox(nameOpts).then(moduleName => {
26+
this.terminal.sendText(`pdk new class ${moduleName}`);
27+
this.terminal.show();
28+
if (reporter) {
29+
reporter.sendTelemetryEvent('command', {
30+
command: messages.PDKCommandStrings.PdkNewClassCommandId
31+
});
32+
}
33+
})
34+
}
35+
36+
public dispose(): any {
37+
this.terminal.dispose();
38+
this.terminal = undefined;
39+
}
40+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
'use strict';
2+
3+
import * as vscode from 'vscode';
4+
import { Logger } from '../../logging';
5+
import { reporter } from '../../telemetry/telemetry';
6+
import * as messages from '../../messages';
7+
8+
export class pdkNewModuleCommand {
9+
private logger: Logger = undefined;
10+
private terminal: vscode.Terminal = undefined;
11+
12+
constructor(logger: Logger, terminal: vscode.Terminal) {
13+
this.logger = logger;
14+
this.terminal = terminal;
15+
}
16+
17+
public run() {
18+
let nameOpts: vscode.QuickPickOptions = {
19+
placeHolder: "Enter a name for the new Puppet module",
20+
matchOnDescription: true,
21+
matchOnDetail: true
22+
};
23+
let dirOpts: vscode.QuickPickOptions = {
24+
placeHolder: "Enter a path for the new Puppet module",
25+
matchOnDescription: true,
26+
matchOnDetail: true
27+
};
28+
29+
vscode.window.showInputBox(nameOpts).then(moduleName => {
30+
if (moduleName == undefined) {
31+
vscode.window.showWarningMessage('No module name specifed. Exiting.')
32+
return;
33+
}
34+
vscode.window.showInputBox(dirOpts).then(dir => {
35+
this.terminal.sendText(`pdk new module --skip-interview ${moduleName} ${dir}`);
36+
this.terminal.sendText(`code ${dir}`)
37+
this.terminal.show();
38+
if (reporter) {
39+
reporter.sendTelemetryEvent('command', {
40+
command: messages.PDKCommandStrings.PdkNewModuleCommandId
41+
});
42+
}
43+
})
44+
})
45+
}
46+
47+
public dispose(): any {
48+
this.terminal.dispose();
49+
this.terminal = undefined;
50+
}
51+
}

0 commit comments

Comments
 (0)