Book Image

Getting Started with NativeScript

By : Nathanael J. Anderson
Book Image

Getting Started with NativeScript

By: Nathanael J. Anderson

Overview of this book

NativeScript allows you to build a fast cross-platform application that has a native UI. NativeScript is a true cross-platform framework that generates native speed applications using the native components of the host platform, all using JavaScript. Although NativeScript allows you to build your application in JavaScript, you have full access to the host OS from your code, allowing you to easily tweak or use new platform features instantly at native code speeds. Whether you have already developed multiple applications or zero applications, this book will help you to develop your next application in a cross-platform framework quickly, saving you a massive amount of time and money. This book concisely shows you NativeScript’s built-in framework that allows you to rapidly develop a fully-working compiled cross-platform application in just a few chapters. It starts by laying the foundation of NativeScript and working through the fundamentals to create a basic shell of the application. Moving on, you’ll see how to build a full-fledged application step by step. We’ll show you how to use plugins, and how to communicate with the native OS libraries easily so that you can customize your application as if your app was created in Java or Objective C. We then deal with the issues that arise from being cross platform and compensate for the different screen sizes, screen resolutions, and device abilities. Finally, we progress to testing and deploying your app.
Table of Contents (15 chapters)
Getting Started with NativeScript
Credits
Foreword
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

The NativeScript command line


Now, before we get to the creating a project part, let us have an overview of the commands available from the new nativescript command you just installed. If you forget any of these, you can easily type nativescript alone without any parameters to see a help screen at a console window, or type nativescript /? for a help screen in your browser.

NativeScript commands

These are just some of the most commonly used valid commands for the nativescript command. Several of these we will be covering as we progress in the book.

Command line

Description

nativescript --version

This returns the version of the nativescript command. If you are running an older version, then you can use npm to upgrade your nativescript command like this: npm install -g nativescript.

nativescript create <your project name>

This creates a brand new project.

nativescript platform add <platform>

This adds a target platform to your project.

nativescript platform list

This shows you what platforms you are currently targeting.

nativescript platform remove <platform>

This command is normally not needed, but if you are messing with the platform directory and totally mess up your platform, you can remove and then add it back. Please note this deletes the entire platform directory, so if you have any specific customizations to your Android manifest or iOS Xcode project file, you should back it up before running the remove command.

nativescript platform update <platform>

This is actually a pretty important command. NativeScript is still a very active project under a lot of development. This command upgrades your platform code to the latest version, which typically eliminates bugs and adds lots of new features. Please note this should also be done with an upgrade of the common JavaScript libraries as most of the time, they also are typically in sync with each other.

nativescript build <platform>

This builds the application for that platform.

nativescript deploy <platform>

This builds and deploys the application to a physical or virtual device for that platform.

nativescript emulate <platform>

This builds and deploys the application to an emulator.

nativescript run <platform>

This builds, deploys, and starts the application on a physical device or an emulator. This is the command you will use the majority of the time to run your application and check out the changes.

nativescript debug <platform>

This builds, deploys, and then starts the application on a physical device or an emulator in debug mode. This is probably the second most used command.

nativescript plugin add <plugin>

This allows you to add a third-party plugin or component. These plugins typically include JavaScript based code, but occasionally, they might also contain an actual compiled Java or ObjectiveC library.

nativescript livesync - -watch

This allows you to have the nativescript command watch for changes and automatically push them to the device. This is probably the third most used command if you are not using a better third-party LiveSync system. We call it LiveSync because it automatically syncs all your changes directly to the device in real time, without you having to rebuild the application. This speeds up your development of an application drastically.

nativescript doctor

This allows you to run some diagnostic checks on your environment if the nativescript command does not appear to be working.

nativescript install

This will (re)install any dependencies listed in your package.json file. The package.json file is typically modified by the plugin or library add function, so this is used typically to reinstall the plugins or libraries in the event you add a new platform or reinstall one.

nativescript test [ init | <platform> ]

This allows you to create or run any tests for your application. Using init will initialize the test framework for the application. Then, you just use the platform to run the tests on that platform.

Now that we have described some of the commands, let's use them to create your first mobile app via the nativescript command tool.