1 00:00:00,420 --> 00:00:05,178 Task in VS Code aren't limited to what the application can detect 2 00:00:05,178 --> 00:00:07,185 in tools like npm and Gulp. 3 00:00:07,185 --> 00:00:10,902 You can also create your own custom tasks to launch any script 4 00:00:10,902 --> 00:00:14,248 or process you have permission to run on your computer. 5 00:00:14,248 --> 00:00:17,983 It's all done by configuring additional task in your 6 00:00:17,983 --> 00:00:20,473 tasks.json file, like the one here 7 00:00:20,473 --> 00:00:24,225 we customized earlier. To add a custom task, 8 00:00:24,225 --> 00:00:28,268 I could just copy the one already in this file and paste it as a 9 00:00:28,268 --> 00:00:30,386 second element in the task array. 10 00:00:30,386 --> 00:00:32,820 I could then make whatever changes I want to it. 11 00:00:32,820 --> 00:00:36,56 However, I want to show you how to create a custom task 12 00:00:36,56 --> 00:00:40,260 if you don't already have a tasks.json file in your project. 13 00:00:40,260 --> 00:00:43,773 I'll first close the existing file. 14 00:00:43,773 --> 00:00:47,215 I'll then delete it in the file explorer. 15 00:00:47,215 --> 00:00:57,386 Remember that it lives in the .vscode directory. 16 00:00:57,386 --> 00:01:05,621 I'll now open the command palette and search for task. 17 00:01:05,621 --> 00:01:11,684 I'm going to run the configure task command. That auto detects the 18 00:01:11,684 --> 00:01:15,00 two npm scripts I already discussed, 19 00:01:15,00 --> 00:01:20,06 but just below that is an option to create tasks.json file 20 00:01:20,06 --> 00:01:21,257 from template. 21 00:01:21,257 --> 00:01:24,917 Since I no longer have a tasks.json file in my project, 22 00:01:24,917 --> 00:01:27,387 that's what I'm going to select. 23 00:01:27,387 --> 00:01:31,41 The next choice I have to make is which template to use. 24 00:01:31,41 --> 00:01:34,477 You can see there are several for different build environments, 25 00:01:34,477 --> 00:01:37,710 but I'm going to select others at the bottom of the list. 26 00:01:37,710 --> 00:01:42,256 It's the most flexible and lets me effectively configure 27 00:01:42,256 --> 00:01:43,578 whatever I want. 28 00:01:43,578 --> 00:01:49,590 That creates a new tasks.json file in my .vscode directory. 29 00:01:49,590 --> 00:01:54,244 It has a single basic task in the file ready for me to customize. 30 00:01:54,244 --> 00:01:58,605 I'm going to customize it to run a PowerShell command that will show 31 00:01:58,605 --> 00:02:02,120 me all of the VS Code processes running on my computer. 32 00:02:02,120 --> 00:02:05,918 The first thing I'll do is change the label value to be something 33 00:02:05,918 --> 00:02:06,927 more descriptive. 34 00:02:06,927 --> 00:02:10,447 This is the text I'll see when picking the task from a list. 35 00:02:10,447 --> 00:02:19,651 I'll change it to show VS Code processes. 36 00:02:19,651 --> 00:02:25,699 The type property can be set to either shell as you see here 37 00:02:25,699 --> 00:02:28,457 or process. You use shell 38 00:02:28,457 --> 00:02:29,913 if you're going to have the task 39 00:02:29,913 --> 00:02:33,724 execute a shell script and process, if you're going to launch 40 00:02:33,724 --> 00:02:34,951 some other program. 41 00:02:34,951 --> 00:02:37,330 Since I'm going to run a PowerShell command, 42 00:02:37,330 --> 00:02:41,577 I'll leave it set to shell. Before I set the command value, 43 00:02:41,577 --> 00:02:45,504 I want to set the properties that will specifically run PowerShell. 44 00:02:45,504 --> 00:02:54,347 To do that, I'll first add the options element. 45 00:02:54,347 --> 00:02:58,842 It's assigned an object. 46 00:02:58,842 --> 00:03:05,941 That object has a shell property. 47 00:03:05,941 --> 00:03:09,535 It is also assigned an object. 48 00:03:09,535 --> 00:03:13,905 The properties available on it are the path to the shell executable 49 00:03:13,905 --> 00:03:17,348 and an args property for any options you want to pass 50 00:03:17,348 --> 00:03:18,606 to that executable. 51 00:03:18,606 --> 00:03:25,944 I'll set the executable property to PowerShell. 52 00:03:25,944 --> 00:03:31,822 Windows will find it without me providing a full path, 53 00:03:31,822 --> 00:03:33,964 but if I were using a different shell, 54 00:03:33,964 --> 00:03:37,58 I would provide the full path to the executable. 55 00:03:37,58 --> 00:03:39,459 I don't need to pass any arguments to it. 56 00:03:39,459 --> 00:03:42,823 I've now configured the task to use PowerShell. 57 00:03:42,823 --> 00:03:47,499 The next step is to specify the command execute in the shell. 58 00:03:47,499 --> 00:03:51,486 I do that with the cleverly named command property below. 59 00:03:51,486 --> 00:03:53,877 I'll have it run the PowerShell commandlet 60 00:03:53,877 --> 00:04:01,100 "Get-Process." 61 00:04:01,100 --> 00:04:03,660 I want to pass an argument to it, 62 00:04:03,660 --> 00:04:08,985 so I'll also add the args property. 63 00:04:08,985 --> 00:04:13,756 The value for this is an array, but I'll just pass it the 64 00:04:13,756 --> 00:04:17,846 single string code, which will filter the list of 65 00:04:17,846 --> 00:04:21,765 processes to just those containing that string. 66 00:04:21,765 --> 00:04:28,134 The last property I'm going to add to this task is named 67 00:04:28,134 --> 00:04:29,987 problemMatcher. 68 00:04:29,987 --> 00:04:35,941 Problem matchers process the output from a task and can present 69 00:04:35,941 --> 00:04:40,406 output from them in the editor or problems panel. 70 00:04:40,406 --> 00:04:44,638 VS Code ships with several problem matchers for TypeScript, 71 00:04:44,638 --> 00:04:46,640 ESLint, and a few other tools. 72 00:04:46,640 --> 00:04:51,78 You can also create your own using regular expressions to process 73 00:04:51,78 --> 00:04:53,20 the text output by the task. 74 00:04:53,20 --> 00:04:56,243 I'm not too concerned about my task generating errors, 75 00:04:56,243 --> 00:05:00,157 so I'm going to leave the problem matcher array empty. 76 00:05:00,157 --> 00:05:04,283 There are a few other properties you can explore when configuring 77 00:05:04,283 --> 00:05:06,797 your task, but this is a pretty complete 78 00:05:06,797 --> 00:05:10,858 example and all I need to review some basic process information. 79 00:05:10,858 --> 00:05:12,355 Let's now try it out. 80 00:05:12,355 --> 00:05:16,20 I'll run the task from the command palette. 81 00:05:16,20 --> 00:05:22,219 I'll search for task and then select "Run Task." 82 00:05:22,219 --> 00:05:28,255 Show VS Code processes now appears in the list of available task. 83 00:05:28,255 --> 00:05:30,517 I can just press "Enter" to run it. 84 00:05:30,517 --> 00:05:35,108 That starts PowerShell in a new terminal window and runs the 85 00:05:35,108 --> 00:05:39,626 Get-Process command with the code argument I specified on the task. 86 00:05:39,626 --> 00:05:44,607 The output shows me the processes being used by VS Code right now. 87 00:05:44,607 --> 00:05:49,306 Tasks are a great way to run common developer tools and scripts 88 00:05:49,306 --> 00:05:50,897 right inside VS Code. 89 00:05:50,897 --> 00:05:55,237 It's another feature that helps you do more of the things you need 90 00:05:55,237 --> 00:05:59,310 to do without switching to another application or environment. 91 00:05:59,310 --> 00:06:04,98 Okay. The last topic I'm going to cover in the course is debugging 92 00:06:04,98 --> 00:06:05,203 inside VS Code. 93 00:06:05,203 --> 00:06:07,162 If you never have bugs in your code, 94 00:06:07,162 --> 00:06:09,344 then feel free to skip the next chapter. 95 00:06:09,344 --> 00:06:13,00 For everyone else, you should probably keep watching.