DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Frameworks
  4. A Simple Cordova Task Runner for Visual Studio Code

A Simple Cordova Task Runner for Visual Studio Code

Raymond Camden user avatar by
Raymond Camden
·
May. 21, 15 · Interview
Like (0)
Save
Tweet
Share
2.88K Views

Join the DZone community and get the full member experience.

Join For Free

i’ve been really liking visual studio code lately, so much so that it is now my primary editor. it is still definitely a pre-1.0 release, but it performs really well and i just dig its coding style. i had to step away from brackets a few weeks ago due to a bug ( details ) that impacts angularjs/ionic apps. since that’s what i work with most of the time, brackets simply became too frustrating to use. one of the cool features of visual studio code is the ability to define tasks for a project. you can support one or more different tasks for a project simply by adding a tasks.json file to the .settings subdirectory. vsc will even create a good default with lots of examples for you to modify. even nicer, since vsc supports intellisense for json schemas , you get code hints while building the file. this morning i thought i’d write up a quick example of adding support for emulating cordova app.

i began by following the suggestion in the tasks doc, i typed shift+command+p and then configure task runner , which is slightly different than what the docs say. this created the json file with an initial default task that i immediately commented out.

while you can do a lot with the cordova cli, i really spend most of my time doing cordova emulate . vsc supports multiple tasks, but you can specify just one and doing so let’s you treat it as a build command. that means you can simply type shift+command+b to execute it. here’s my first draft:

{
"version": "0.0.1",
"command": "cordova",
"isshellcommand": true,
"showoutput": "never",
"args":["emulate"]
}

notice i’m not passing a platform. if you have multiple platforms defined than all will be sent to the emulator. this will be a problem that i’ll cover in a second.

also note the showoutput command. you can specify three different values here:

  • never – means what you think it does
  • silent – will show output if you don’t configure problem matchers – you can see an explanation of that here: defining a problem matcher
  • always – means what you think it does

however, in my testing, showoutput:never didn’t actually work. i just made the output window a bit smaller and later today i’ll file a bug report on it. on a larger screen (i.e. not this laptop) i wouldn’t even care. here it is in action.

shot1

so what if you want to specify the platform to emulate? you can define multiple tasks like so:

{
"version": "0.0.1",
"command": "cordova",
"isshellcommand": true,
"args":["emulate"
],
"tasks": [
{
"taskname": "ios",
// make this the default build command.
"isbuildcommand": true,
// show the output window only if unrecognized errors occur.
"showoutput": "silent"
},
{
"taskname": "android",
// make this the default build command.
"isbuildcommand": false,
// show the output window only if unrecognized errors occur.
"showoutput": "silent"
}

]
}

in this case, i’ve defined an ios and android task to pass to the emulate command. note that i’ve still set ios to be the build command so i can use it as a default. one thing i don’t like about this is that i can’t provide a ‘label’ for the tasks. so when i do shift+command+p, run tasks, i see it like so:

shot2

that’s not the end of the world, but i’d like to have a label so i could see “emulate ios” and “emulate android (please wait 2-3 hours for the emulator to start)”.

this works , but has a problem. when emulating android, the cli hangs while the emulator is running. if i run android via vsc, it works (after the emulator finally loads up), but vsc will not let me run another tasks until this one ends. i have to kill the emulator to continue.

ok, so i worked on this a bit more. i don’t actually emulate android as it is way too slow, what i do normally is use genymotion and use the run command instead. yes, this is still emulating, but the command line call is tweaked. i just tried this and it worked!

{
"version": "0.0.1",
"command": "cordova",
"isshellcommand": true,
"args":[
],
"tasks": [
{
"taskname": "ios",
// make this the default build command.
"isbuildcommand": true,
// show the output window only if unrecognized errors occur.
"showoutput": "silent",
"args": [
"emulate"
]
},
{
"taskname": "android",
// make this the default build command.
"isbuildcommand": false,
// show the output window only if unrecognized errors occur.
"showoutput": "silent",
"args": [
"run"
]
}

]
}


so i can now shift+command+b to send to ios as my default, or do shift+command+p, run task, to select android if i need to.

shot3

hope this helps, and i’m going to keep an eye out for other ways to help vsc work with cordova.

Task (computing) Visual Studio Code Apache Cordova

Published at DZone with permission of Raymond Camden, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Why Open Source Is Much More Than Just a Free Tier
  • Why It Is Important To Have an Ownership as a DevOps Engineer
  • Securing VMs, Hosts, Kubernetes, and Cloud Services
  • Why You Should Automate Code Reviews

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: