<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Borys Kupar</title>
    <description>The latest articles on DEV Community by Borys Kupar (@borys_kupar).</description>
    <link>https://dev.to/borys_kupar</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F6178%2F06f29342-7769-4ab5-a2dc-54c54d63e2c5.jpg</url>
      <title>DEV Community: Borys Kupar</title>
      <link>https://dev.to/borys_kupar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/borys_kupar"/>
    <language>en</language>
    <item>
      <title>How To Improve Your Daily Routine with VSCode Tasks</title>
      <dc:creator>Borys Kupar</dc:creator>
      <pubDate>Fri, 01 May 2020 16:58:59 +0000</pubDate>
      <link>https://dev.to/borys_kupar/how-to-improve-your-daily-routine-with-vscode-tasks-17nb</link>
      <guid>https://dev.to/borys_kupar/how-to-improve-your-daily-routine-with-vscode-tasks-17nb</guid>
      <description>&lt;p&gt;Have you tried using VSCode Tasks already? If not, from this post you can learn how to run &lt;code&gt;npm&lt;/code&gt; scripts quickly, directly in VSCode, and use the shortcuts.&lt;/p&gt;

&lt;p&gt;All JavaScript projects I worked on have a set of defined scripts, that you can execute for an application. Usually, those would be commands to lint, test, build, or deploy your code. Most developers I've worked with use a command-line of their choice to run these commands. You either have to remember your project scripts by heart, or your command line may have some typeahead feature, or you just scrap the history to find that command you ran in the past like I always did:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;history | grep 'npm run'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead, you could use Tasks to run the scripts for you. You can start with opening Command Palette - &lt;code&gt;Cmd + Shift + P&lt;/code&gt;, and select "Tasks: Run Task". VSCode will offer you multiple task types it supports. Go ahead and select "npm". The editor will quickly scan your &lt;code&gt;package.json&lt;/code&gt; and offer the tasks you have defined:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VfttUOKn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0oz0k2gm6jdx8g1jrifn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VfttUOKn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0oz0k2gm6jdx8g1jrifn.png" alt="VS Code Task List"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select one of your scripts, and you are done! A new built-in Terminal window is opened, and you can see the output of your script, and continue working from where you left off.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FSV3ruG2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5l4cp8hrwarfb5jg4zgb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FSV3ruG2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5l4cp8hrwarfb5jg4zgb.png" alt="VS Code Task Run"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Okay, this looks cool. But you probably think &lt;em&gt;"Hey, my project is not that simple, I have tasks that have arguments, different options, and maybe I need to open sub-folder first!"&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;Sure, you can do that too!&lt;/p&gt;

&lt;h1&gt;
  
  
  Configure Tasks
&lt;/h1&gt;

&lt;p&gt;Say, you want to run unit tests for a specific test file. Your test command might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm test 'my-component.js' --auto-watch --no-single-run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;My usual workflow is the following: I want to run unit tests that I am working on in the watch mode. Usually, you would need to insert the file name in the test command, but instead, VSCode can do that for you. To achieve that, we can use some replacement variables that are provided for us. For example: &lt;code&gt;${fileBasename}&lt;/code&gt;. The full list of available variables can be found in the official documentation &lt;a href="https://code.visualstudio.com/docs/editor/variables-reference"&gt;here&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Now open the Command Palette again, select "Tasks: Run Task", then "No configured tasks. Configure Tasks..." and choose the task you want to configure. This would create and open a new file: &lt;code&gt;.vscode/tasks.json&lt;/code&gt; in your project. You can either add this file to &lt;code&gt;.gitignore&lt;/code&gt; or commit it, so your team would be able to use those tasks as well.&lt;/p&gt;

&lt;p&gt;Once you have added replacement variable, the configuration should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "npm",
            "script": "test ${fileBasename} --auto-watch --no-single-run",
            "problemMatcher": [],
            "label": "npm: test opened file",
            "detail": "npm test"
        }
    ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And, voilà. Your custom task is now on the list that you can run from Command Palette. Now open the test file you want to run, e.g. &lt;code&gt;my-component-test.js&lt;/code&gt;. Run &lt;code&gt;Cmd + Shift + P&lt;/code&gt; -&amp;gt; "Tasks: Run Task" and you should see your newly configured task: "npm: test opened file". Select it, and it should run &lt;code&gt;npm test my-component-test.js --auto-watch --no-single-run&lt;/code&gt; in the Terminal. You can also customize the presentation of the script results. Say, I want to open a new Terminal for this type of command. For that, you just need to provide an additional "presentation" config.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    ...
    "presentation": {
        "panel": "dedicated",
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can see multiple terminal windows opened, that you can switch between.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qCt2p6bC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/sbozfz00r9g2ydi5quva.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qCt2p6bC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/sbozfz00r9g2ydi5quva.png" alt="Multiple shells"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Configure Shell Tasks
&lt;/h1&gt;

&lt;p&gt;If you want to execute additional shell commands, VSCode supports that too. Now, instead of using &lt;code&gt;npm&lt;/code&gt; type, we can use &lt;code&gt;shell&lt;/code&gt;. E.g.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Run Cypress",
      "type": "shell",
      "command": "cd tests/e2e/cypress/ &amp;amp;&amp;amp; npm run cypress",
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Based on the example above you can configure your custom development workflow within minutes, and enjoy the fully integrated experience of running scripts and seeing their results directly in the editor. &lt;/p&gt;

&lt;p&gt;Please leave a comment, if this helped to improve your development workflow or you have any questions! Have fun!&lt;/p&gt;

</description>
      <category>vscode</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
