Skip to content

Commit d0e5890

Browse files
Adds gulp operations to VS Code extension commands. Closes #422 (#480)
Added new VSCode commands to perform gulp operations from the command palette. ## 🎯 Aim The aim is to add support for every gulp task to the extension commands. Currently we can only run bundle, package, and publish. I have added, possibility to run build, clean, serve, test, trust self signed developer certificate, deploy project assets to azure storage gulp tasks. ## 📷 Result Marked in orange are the available extension commands after the change ![image](https://github.com/user-attachments/assets/26cc06d3-894c-44d4-9190-7d1e6df30873) ![image](https://github.com/user-attachments/assets/e4be6c40-257e-4b6b-9705-715aa0c8d3e8) ## ✅ What was done Added the missing commands in the ```package.json``` file as below, ![image](https://github.com/user-attachments/assets/e281dcf7-24c4-4fc1-a883-67447dd969f6) Also, to execute terminal commands such as ```gulp clean``` , ```gulp build```, ```gulp test```, ```gulp trust-dev-cert```, ```gulp deploy-azure-storage```, `Registered and activated these commands in the ```extensions.ts``` as below. ![image](https://github.com/user-attachments/assets/a9b04fbb-2c85-4ae2-ba00-c31a72485a69) - [] not done - [X] done ## 🔗 Related issue Closes: #422
1 parent 194d1c1 commit d0e5890

File tree

4 files changed

+106
-5
lines changed

4 files changed

+106
-5
lines changed

package.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,42 @@
784784
"title": "Publish",
785785
"category": "SPFx Toolkit",
786786
"icon": "$(sync)"
787+
},
788+
{
789+
"command": "spfx-toolkit.serveProject",
790+
"title": "Serve",
791+
"category": "SPFx Toolkit",
792+
"icon": "$(sync)"
793+
},
794+
{
795+
"command": "spfx-toolkit.cleanProject",
796+
"title": "Clean",
797+
"category": "SPFx Toolkit",
798+
"icon": "$(sync)"
799+
},
800+
{
801+
"command": "spfx-toolkit.buildProject",
802+
"title": "Build",
803+
"category": "SPFx Toolkit",
804+
"icon": "$(sync)"
805+
},
806+
{
807+
"command": "spfx-toolkit.testProject",
808+
"title": "Test",
809+
"category": "SPFx Toolkit",
810+
"icon": "$(sync)"
811+
},
812+
{
813+
"command": "spfx-toolkit.trustDevCert",
814+
"title": "Trust self-signed developer certificate",
815+
"category": "SPFx Toolkit",
816+
"icon": "$(sync)"
817+
},
818+
{
819+
"command": "spfx-toolkit.deployToAzureStorage",
820+
"title": "Deploy project assets to Azure Storage",
821+
"category": "SPFx Toolkit",
822+
"icon": "$(sync)"
787823
}
788824
],
789825
"menus": {

src/constants/Commands.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,21 @@ export const Commands = {
5858
// Serving
5959
serveProject: `${EXTENSION_NAME}.serveProject`,
6060

61+
// Clean
62+
cleanProject: `${EXTENSION_NAME}.cleanProject`,
63+
64+
// Build
65+
buildProject: `${EXTENSION_NAME}.buildProject`,
66+
67+
// Test
68+
testProject: `${EXTENSION_NAME}.testProject`,
69+
70+
// Trust dev cert
71+
trustDevCert: `${EXTENSION_NAME}.trustDevCert`,
72+
73+
// Deploy to Azure Storage
74+
deployToAzureStorage: `${EXTENSION_NAME}.deployToAzureStorage`,
75+
6176
// TreeViews
6277
refreshAppCatalogTreeView: `${EXTENSION_NAME}.refreshAppCatalogTreeView`,
6378
refreshAccountTreeView: `${EXTENSION_NAME}.refreshAccountTreeView`,

src/panels/CommandPanel.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,15 +288,15 @@ export class CommandPanel {
288288

289289
private static taskTreeView() {
290290
const taskCommands: ActionTreeItem[] = [
291-
new ActionTreeItem('Build project', '', { name: 'debug-start', custom: false }, undefined, Commands.executeTerminalCommand, 'gulp build'),
291+
new ActionTreeItem('Build project', '', { name: 'debug-start', custom: false }, undefined, Commands.buildProject),
292292
new ActionTreeItem('Bundle project', '', { name: 'debug-start', custom: false }, undefined, Commands.bundleProject),
293-
new ActionTreeItem('Clean project', '', { name: 'debug-start', custom: false }, undefined, Commands.executeTerminalCommand, 'gulp clean'),
294-
new ActionTreeItem('Deploy project assets to Azure Storage', '', { name: 'debug-start', custom: false }, undefined, Commands.executeTerminalCommand, 'gulp deploy-azure-storage'),
293+
new ActionTreeItem('Clean project', '', { name: 'debug-start', custom: false }, undefined, Commands.cleanProject),
294+
new ActionTreeItem('Deploy project assets to Azure Storage', '', { name: 'debug-start', custom: false }, undefined, Commands.deployToAzureStorage),
295295
new ActionTreeItem('Package', '', { name: 'debug-start', custom: false }, undefined, Commands.packageProject),
296296
new ActionTreeItem('Publish', '', { name: 'debug-start', custom: false }, undefined, Commands.publishProject),
297297
new ActionTreeItem('Serve', '', { name: 'debug-start', custom: false }, undefined, Commands.serveProject),
298-
new ActionTreeItem('Test', '', { name: 'debug-start', custom: false }, undefined, Commands.executeTerminalCommand, 'gulp test'),
299-
new ActionTreeItem('Trust self-signed developer certificate', '', { name: 'debug-start', custom: false }, undefined, Commands.executeTerminalCommand, 'gulp trust-dev-cert'),
298+
new ActionTreeItem('Test', '', { name: 'debug-start', custom: false }, undefined, Commands.testProject),
299+
new ActionTreeItem('Trust self-signed developer certificate', '', { name: 'debug-start', custom: false }, undefined, Commands.trustDevCert),
300300
];
301301

302302
window.registerTreeDataProvider('pnp-view-tasks', new ActionTreeDataProvider(taskCommands));

src/services/executeWrappers/TerminalCommandExecuter.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@ export class TerminalCommandExecuter {
3535
subscriptions.push(
3636
commands.registerCommand(Commands.executeTerminalCommand, TerminalCommandExecuter.runCommand)
3737
);
38+
subscriptions.push(
39+
commands.registerCommand(Commands.cleanProject, TerminalCommandExecuter.cleanProject)
40+
);
41+
subscriptions.push(
42+
commands.registerCommand(Commands.buildProject, TerminalCommandExecuter.buildProject)
43+
);
44+
subscriptions.push(
45+
commands.registerCommand(Commands.testProject, TerminalCommandExecuter.testProject)
46+
);
47+
subscriptions.push(
48+
commands.registerCommand(Commands.trustDevCert, TerminalCommandExecuter.trustDevCert)
49+
);
50+
subscriptions.push(
51+
commands.registerCommand(Commands.deployToAzureStorage, TerminalCommandExecuter.deployToAzureStorage)
52+
);
3853

3954
TerminalCommandExecuter.initShellPath();
4055
}
@@ -188,6 +203,41 @@ export class TerminalCommandExecuter {
188203
});
189204
}
190205

206+
/**
207+
* Cleans the project by executing the Gulp clean command.
208+
*/
209+
private static cleanProject() {
210+
commands.executeCommand(Commands.executeTerminalCommand, 'gulp clean');
211+
}
212+
213+
/**
214+
* Builds the project by executing the Gulp build command.
215+
*/
216+
private static buildProject() {
217+
commands.executeCommand(Commands.executeTerminalCommand, 'gulp build');
218+
}
219+
220+
/**
221+
* Tests the project by executing the Gulp test command.
222+
*/
223+
private static testProject() {
224+
commands.executeCommand(Commands.executeTerminalCommand, 'gulp test');
225+
}
226+
227+
/**
228+
* Trusts the development certificate by executing the Gulp trust-dev-cert command.
229+
*/
230+
private static trustDevCert() {
231+
commands.executeCommand(Commands.executeTerminalCommand, 'gulp trust-dev-cert');
232+
}
233+
234+
/**
235+
* Deploys to Azure CDN by executing the Gulp deploy-to-azure-storage command.
236+
*/
237+
private static deployToAzureStorage() {
238+
commands.executeCommand(Commands.executeTerminalCommand, 'gulp deploy-azure-storage');
239+
}
240+
191241
/**
192242
* Initializes the shell path for executing terminal commands.
193243
* If the shell path is an object with a `path` property, it sets the `shellPath` to that value.

0 commit comments

Comments
 (0)