2.4 Using the Cordova CLI
Now that we have Cordova installed, we can start to get familiar with the Cordova command line interface. In this lesson, I'll show you some key commands and tools.
1.Introduction1 lesson, 00:51
2.Getting to Know Cordova7 lessons, 37:35
3.Creating a Cordova App6 lessons, 26:18
4.Conclusion1 lesson, 00:40
2.4 Using the Cordova CLI
Hello everyone, this is Reggie Dawson. Welcome to the Building an app with Cordova course for Tuts+. In this video, we are going to learn how to use the Cordova command line interface. I mentioned before that we're going to use a cross-platform workflow to develop our app. Using the command line interface in Cordova is how we do this, since each platform also has its own environment to develop in. For example, instead of using the command line interface, we could create and build our project with the Android shell tools. Of course, this will limit us to being able to build our project for one platform. At any rate, we can use the Cordova command line interface to manage our entire project. Once we have our SDK installed as well as Cordova, we can now use the command line interface from our command prompt. First we need to navigate to where we wanna create our project. I have a folder called projects I set up for this, so I'm going to navigate to that folder. Once I am in the correct folder, I'm going to run the cordova create command. The command I used, cordova create sample, creates a project called sample. It also creates a folder called sample that contains our project. This is the basic form of this command. We can also run this command with two optional arguments. This command is cordova create sample1 com.tutsplus.cordova mySampleApp. Again, the first argument represents the name of the folder created for the project. The second argument is a reverse domain identifier, usually in your config.xml file. When we didn't run the optional argument in our first example, a default value was written to this file. The third argument is the application's title, again written to the config.xml file. This also provides a default value if we don't add this argument. We can't use this argument if we don't use our reverse domain identifier. After we run the command a folder should be created with the name we provided. If we take a look inside the sample1 folder we should see a config.xml file and multiple folders. We will build our project inside of the www folder. Inside of that we have our css, img and js folders. We also have our index.html file in this folder. This is a very familiar folder structure for anyone who has done web development. In order to run other commands we need to be inside of the project folder. Let's change directories into our folder. Once we are inside of our folder we are going to run, cordova platform add android will add the Android platform as a target you can build your app for. In order to add a platform you must have the same platform's SDK installed on your system. When we run this command it adds an android folder in the platforms folder. This folder contains the native code for the Android platform. We can list installed platforms by using, cordova platform list. This will display the installed platforms as well as any available platforms to install. The commands cordova platforms, And cordova platform ls will work the same. In order to remove a platform, cordova platform remove and the platform name, in this case android. We can also use the alias of cordova platform rm and the platform name. When we run this command, the respective folder is removed from the platforms folder. And cordova platform list confirms that it has been removed. The last command I wanna talk to you about is help. If you are unsure what commands you can run you can always type, To see what commands you can run and what they can do. You can also type, cordova and the command name with the --help option will give you detailed help on a command. You may have noticed some additional commands we didn't talk about. I am not going to cover the serve, emulate, or run commands as we will look at these in a later video. I also did not cover the plugin commands for the same reason. As far as the commands to build an app, those will be discussed in the companion course to this one on packaging and publishing an app to the respective app store. That's everything you need to know to set up a project in the command line interface. In the next video we will look at the config.xml file.