• Stars
    star
    1,036
  • Rank 42,675 (Top 0.9 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created almost 10 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Command-line interface for building NativeScript apps


Nativescript Logo

NativeScript Command-Line Interface

The NativeScript CLI lets you create, build, and deploy NativeScript-based apps on iOS and Android devices.


nativescript -> npm

Get it using: npm install -g nativescript

What is NativeScript

NativeScript is a cross-platform JavaScript framework that lets you develop native iOS and Android apps from a single code base. The framework provides JavaScript access to the native APIs, user interface, and rendering engines of iOS and Android. By using JavaScript or TypeScript, you can create one project that builds into an iOS or Android app with completely native user experience.

To learn more about NativeScript, you can check the following resources:

Back to Top

How the NativeScript CLI works

The NativeScript CLI is the command-line interface for interacting with NativeScript. It incorporates several important services. Consider the following diagram:

NativeScript CLI diagram

  • Commands - pretty much what every CLI does - support of different command options, input validation and help
  • Devices Service - provides the communication between NativeScript and devices/emulators/simulators used to run/debug the app. Uses iTunes to talk to iOS and adb for Android
  • LiveSync Service - redeploys applications when code changes during development
  • Hooks Service - executes custom-written hooks in developed application, thus modifying the build process
  • Platforms Service - provides app build functionalities, uses Gradle to build Android packages and Xcode for iOS.

Back to Top

Supported Platforms

With the NativeScript CLI, you can target the following mobile platforms.

  • Android 4.2 or a later stable official release
  • iOS 9.0 or later stable official release

Back to Top

System Requirements

You can install and run the NativeScript CLI on Windows, macOS or Linux.

Installation

Install the NativeScript CLI

The NativeScript CLI is available for installing as an npm package.

In the command prompt, run the following command.

OS Node.js installed from http://nodejs.org/ Node.js installed via package manager
Windows npm install nativescript -g npm install nativescript -g
macOS sudo npm install nativescript -g --unsafe-perm npm install nativescript -g
Linux sudo npm install nativescript -g --unsafe-perm npm install nativescript -g

To check if your system is configured properly, run the following command.

ns doctor

Configure Proxy Settings

If you are working with the NativeScript CLI behind a web proxy, you need to configure your proxy settings.

Set Proxy Settings

ns proxy set <Url> <Username> <Password>

Attributes

<Url> (Required) The full URL of the proxy. The <Url> attribute is required and if you do not provide it when running the command, the NativeScript CLI will prompt you to provide it. An example of a valid proxy URL is http://127.0.0.1:8888.
<Username> and <Password> (Optional) The credentials for the proxy. The <Username> and <Password> attributes are optional, however, if you choose to provide them, you must provide both.

Options

--insecure The --insecure flag allows you to perform insecure SSL connections and transfers. This option is useful when your proxy does not have a CA certificate or the certificate is no longer valid.

Limitations

Display Current Proxy Settings

ns proxy

Clear Proxy Settings

ns proxy clear

Back to Top

Quick Start

The Commands

Run ns help to view all available commands in the browser. Run ns help <Command> to view more information about a selected command in the browser. ns --help opens console help, where help information is shown in the console.

Back to Top

Create Project

To create a new cross-platform project from the default JavaScript template, run the following command.

ns create MyApp --js

To create a new cross-platform project from the default TypeScript, Angular or Vue template, use the template option followed by either typescript, angular or vue.

ns create MyApp --template typescript
ns create MyApp --template angular
ns create MyApp --template vue

Or you can simply use the shorthand tsc and ng options.

ns create MyApp --tsc
ns create MyApp --ng

With the template option you can also specify a local or a remote path to the template that you want to use to create your project. For example, if you want to create a React template, run the following command.

ns create MyApp --template https://github.com/shirakaba/tns-template-blank-react.git

The NativeScript CLI creates a new project and sets the application identifier to org.nativescript.myapp.

The CLI places the project in a new directory in the current directory. The newly created directory has the following structure.

MyApp/
├── app
│   ├── App_Resources
│   └── ...
└── platforms
    └── ...
  • The app directory is the development space for your application. You should modify all common and platform-specific code within this directory. When you run prepare <Platform>, the NativeScript CLI prepares relevant content to the platform-specific folders for each target platform.
  • The platforms directory is created empty. When you add a target platform to your project, the NativeScript CLI creates a new subdirectory with the platform name. The subdirectory contains the ready-to-build resources of your app. When you run prepare <Platform>, the NativeScript CLI prepares relevant content from the app directory to the platform-specific subdirectory for each target platform.

Back to Top

Develop Your Project

Development with NativeScript

For more information about working with NativeScript, see the following resources.

Development in app

The app directory in the root of the project is the development space for your project. Place all your common and platform-specific code in this directory.

In the app directory, you can use platform-specific files to provide customized functionality and design for each target platform. To indicate that a file is platform-specific, make sure that the file name is in the following format: name.ios.extension or name.android.extension. For example: main.ios.js or main.android.js.

You can develop shared functionality or design in common files. To indicate that a file is common, make sure that the file name does not contain a .android. or .ios. string.

Development in platforms

IMPORTANT: Avoid editing files located in the platforms subdirectory because the NativeScript CLI overrides such files.

Modifying Configuration Files

The NativeScript CLI respects any platform configuration files placed inside app/App_Resources.

Modifying Entitlements File (iOS only)

To specify which capabilities are required by your App - Maps, Push Notifications, Wallet etc. you can add or edit the app.entitlements file placed inside app/App_Resources/iOS. When building the project, the default app/App_Resources/iOS/app.entitlements file gets merged with all Plugins entitlement files and a new yourAppName.entitlements is created in the platforms directory. The path would be app/platforms/ios/<application name>/<application name>.entitlements and will be linked in the build.xcconfig file.

You can always override the generated entitlements file, by pointing to your own entitlements file by setting the CODE_SIGN_ENTITLEMENTS property in the app/App_Resources/iOS/build.xcconfig file.

Back to Top

Build Your Project

You can build it for your target mobile platforms.

ns build android
ns build ios

The NativeScript CLI calls the SDK for the selected target platform and uses it to build your app locally.

When you build for iOS, the NativeScript CLI will either build for a device, if there's a device attached, or for the native emulator if there are no devices attached. To trigger a native emulator build when a device is attached, set the --emulator flag.

IMPORTANT: To build your app for an iOS device, you must configure a valid certificate and provisioning profile pair, and have that pair present on your system for code signing your application package. For more information, see iOS Code Signing - A Complete Walkthrough.

Back to Top

Run Your Project

You can test your work in progress on connected Android or iOS devices.

To verify that the NativeScript CLI recognizes your connected devices, run the following command.

ns devices

The NativeScript CLI lists all connected physical devices and running emulators/simulators.

After you have listed the available devices, you can quickly run your app on connected devices by executing:

ns run android
ns run ios

Back to Top

Extending the CLI

The NativeScript CLI lets you extend its behavior and customize it to fit your needs by using hooks.

When you run one of the extendable commands (for example, ns build), the CLI checks for hooks and executes them. Plugins can also use hooks to control the compilation of the application package.

For more information, see the Extending the CLI document

Back to Top

Troubleshooting

If the NativeScript CLI does not behave as expected, you might be facing a configuration issue. For example, a missing JAVA path. To check if your system is configured properly for the NativeScript CLI, run the following command.

ns doctor

This command prints warnings about current configuration issues and provides basic information about how to resolve them.

If addressing the configuration issues does not resolve your problem, you can report an issue or ask the community.

Back to Top

How to Contribute

To learn how to log a bug that you just discovered, click here.

To learn how to suggest a new feature or improvement, click here.

To learn how to contribute to the code base, click here.

Back to Top

How to Build

git clone https://github.com/NativeScript/nativescript-cli
cd nativescript-cli
npm run setup

To use the locally built CLI instead tns you can call PATH_TO_CLI_FOLDER/bin/tns. For example: PATH_TO_CLI_FOLDER/bin/ns run ios|android

Back to Top

Get Help

Please, use github issues strictly for reporting bugs or requesting features. For general NativeScript questions and support, check out Stack Overflow or ask our experts in the NativeScript community Discord channel.

Back to Top

License

This software is licensed under the Apache 2.0 license, quoted here.

Back to Top

More Repositories

1

NativeScript

⚡ Empowering JavaScript with native platform APIs. ✨ Best of all worlds (TypeScript, Swift, Objective C, Kotlin, Java). Use what you love ❤️ Angular, Capacitor, Ionic, React, Solid, Svelte, Vue with: SwiftUI, Jetpack Compose, Flutter and you name it compatible.
TypeScript
23,002
star
2

nativescript-angular

Integrating NativeScript with Angular
TypeScript
1,213
star
3

android

Android runtime for NativeScript (based on V8)
C++
509
star
4

sample-Groceries

🍏 🍍 🍓 A NativeScript-built iOS and Android app for managing grocery lists
TypeScript
484
star
5

docs-v7

Documentation, API reference, and code snippets for NativeScript
CSS
444
star
6

nativescript-marketplace-demo

NativeScript kitchen sink demo. All of NativeScript’s functionality in one app.
TypeScript
325
star
7

ios-jsc

NativeScript for iOS using JavaScriptCore
JavaScript
295
star
8

nativescript-sdk-examples-ng

NativeScript and Angular code samples.
TypeScript
293
star
9

nativescript-app-templates

Monorepo for NativeScript app templates
TypeScript
216
star
10

nativescript-schematics

nativescript, mobile, schematics, angular
TypeScript
186
star
11

plugins

@nativescript plugins to help with your developments.
TypeScript
184
star
12

tailwind

Makes using TailwindCSS in NativeScript a whole lot easier!
JavaScript
140
star
13

theme

The gorgeous default NativeScript theme, currently under active development
SCSS
127
star
14

ios

NativeScript for iOS using V8
JavaScript
124
star
15

push-plugin

Contains the source code for the Push Plugin.
Objective-C
123
star
16

nativescript-app-sync

♻️ Update your app without going through the app store!
C
123
star
17

sample-ng-todomvc

Angular2 + NativeScript TodoMVC example
115
star
18

nativescript-imagepicker

Imagepicker plugin supporting both single and multiple selection.
TypeScript
104
star
19

nativescript-background-http

Background Upload plugin for the NativeScript framework
TypeScript
101
star
20

nativescript-dev-webpack

A package to help with webpacking NativeScript apps.
JavaScript
97
star
21

nativescript-camera

NativeScript plugin to empower using device camera.
TypeScript
92
star
22

canvas

C++
87
star
23

android-dts-generator

A tool that generates TypeScript declaration files (.d.ts) from Jars
Java
87
star
24

nativescript-facebook

NativeScript plugin, wrapper of native Facebook SDK for Android and iOS
TypeScript
78
star
25

nativescript-dev-appium

A package to help with writing and executing e2e Appium tests in NativeScript apps
TypeScript
69
star
26

windows-runtime

NativeScript Runtime for the Universal Windows Platform
C
64
star
27

sample-android-background-services

Using Android Background Services in NativeScript
JavaScript
63
star
28

nx

NativeScript for Nx.
TypeScript
61
star
29

android-v8

Contains the Google's V8 build used in android runtime.
Shell
54
star
30

nativescript-fresco

This repository holds the NativeScript plugin that exposes the functionality of the Fresco image library to NativeScript developers.
TypeScript
52
star
31

nativescript-sdk-examples-js

JavaScript
50
star
32

firebase

Modular Firebase 🔥 implementation for NativeScript. Supports both iOS & Android platforms for all Firebase services.
TypeScript
50
star
33

sample-Angular2

49
star
34

nativescript-canvas

HTML5-like 2D and WebGL canvas implementation for NativeScript
C++
48
star
35

nativescript-dev-sass

SASS CSS pre-processor for NativeScript projects
JavaScript
44
star
36

plugin-seed

TypeScript
42
star
37

angular

TypeScript
37
star
38

sample-ios-background-execution

Running Custom Background Tasks with NativeScript
JavaScript
36
star
39

worker-loader

JavaScript
36
star
40

functional-tests-core

Appium based framework for testing Android and iOS native mobile apps.
Java
36
star
41

nativescript-app-encryption

This plugin encrypts all your app/**.js files during a release build. In experimental state.
JavaScript
35
star
42

capacitor

NativeScript for Capacitor
TypeScript
34
star
43

tutorials

Project source to tutorials presented here: https://docs.nativescript.org/tutorial/
TypeScript
33
star
44

rfcs

RFCs for NativeScript and related tooling
33
star
45

capacitor-docs

JavaScript
30
star
46

payments

In-App Purchase, Subscriptions, Google Pay, Apple Pay for NativeScript
TypeScript
30
star
47

sample-iOS-Profiling

Performance comparison of popular cross-platform frameworks
JavaScript
29
star
48

docs-v8

HTML
29
star
49

sample-Android-Widgets

JavaScript
29
star
50

animation-demo

A sample app demonstrating different kinds of animations achieved with CSS, keyframes and NativeScript.
TypeScript
29
star
51

nativescript-datetimepicker

Plugin with date and time picking fields
TypeScript
26
star
52

nativescript-remote-builds

A NativeScript plugin for remote builds when running and publishing NativeScript apps without env setup.
JavaScript
26
star
53

login-tab-navigation-ng

{N} Angular with login and tabs page navigation
JavaScript
26
star
54

nativescript-ui-charts

NativeScript wrapper around HiCharts library
TypeScript
25
star
55

mlkit

TypeScript
24
star
56

workshop

NativeScript! And workshops! 🎉
TypeScript
23
star
57

nativescript-picker

Plugin that provides a custom TextField which lets you pick a value from a list opened in a modal popup.
TypeScript
22
star
58

nativescript-app-sync-server

JavaScript
22
star
59

sample-ImageUpload

An integration of nativescript-image-picker and nativescript-background-http
JavaScript
22
star
60

nativescript-cordova-support

A NativeScript plugin which enables you to use cordova plugins inside your NativeScript-based project.
Java
21
star
61

nativescript-dev-typescript

TypeScript support for NativeScript projects
JavaScript
20
star
62

sample-ios-embedded

Embedding the NativeScript for iOS runtime in an existing app
Objective-C
19
star
63

nativescript-angular-guide

A guide to building apps with NativeScript and Angular 2
HTML
17
star
64

summer-of-nativescript

Resources for the summer of NativeScript
JavaScript
17
star
65

sample-tvOS

A proof of concept app with the NativeScript runtime running on Apple TV
JavaScript
17
star
66

playground-feedback

Feedback for NativeScript Playground
15
star
67

artwork

NativeScript artwork
JavaScript
14
star
68

ios-device-lib

Allows interaction with iOS devices.
C++
14
star
69

nativescript-hook

Helper module for installing hooks into NativeScript projects
JavaScript
14
star
70

nativescript-ios-imessages

Simple app extension that interact with the Messages app
C
14
star
71

playground-tutorials

NativeScript Playground tutorials content
13
star
72

NativeScript-NEXT-Workshop

Workshop material for teaching NativeScript
13
star
73

nativescript-unit-test-runner

TypeScript
13
star
74

android-compose-example

@nativescript/jetpack-compose Example 🚀📓♥️
Kotlin
13
star
75

tns-core-modules-widgets

Repo for widgets used in NativeScript modules
Java
12
star
76

vue-x-platforms

Vue running on Web, iOS, Android and Vision Pro.
Vue
12
star
77

demo-workers

JavaScript
12
star
78

docs

The NativeScript Docs!
JavaScript
11
star
79

sample-iOS-HealthKit

This sample shows a simple use of the iOS HealthKit APIs.
JavaScript
11
star
80

sample-native-module

Sample native module for NativeScript
C++
11
star
81

examples-best-practices

TypeScript
10
star
82

functional-tests-demo

XSLT
10
star
83

ns-ng-animation-examples

TypeScript
10
star
84

pbxproj-dom

pbxproj object model
TypeScript
10
star
85

ios-metadata-generator

Visit the iOS Runtime repo for instructions and related issues
C++
10
star
86

nativescript-app-sync-web

Web client for the codepush server
JavaScript
9
star
87

ios-sim-portable

A Node.js command-line utility to launch an iOS application bundle (.app) in the Xcode iOS Simulator
TypeScript
9
star
88

visionos-hello-world

Vision Pro 🥽 Hello World tutorial with NativeScript using various flavors - Angular, React, Solid, Svelte, TypeScript and Vue.
Swift
9
star
89

nativescript-dev-coffeescript

JavaScript
9
star
90

nativescript-doctor

Library that helps identifying if the environment can be used for development of {N} apps.
TypeScript
8
star
91

nativescript-dev-jade

JavaScript
8
star
92

eslint-plugin

ESLint plugin for NativeScript projects.
TypeScript
8
star
93

nativescript-cli-tests

NativeScript CLI Integration Tests
Python
8
star
94

androidx-migration-tool

JavaScript
8
star
95

nativescript-dev-debugging

This package allows the developer of a NativeScript plugin to use a workflow that allows to debug both the native iOS (objective-c, swift) and Android (Java) code and the wrapper TypeScript/JavaScript code of the plugin used inside an NativeScript application. This is a powerful "tool" which will rebuild both the native framework (iOS) and arr files (Android) and the TypeScript/JavaScript code of your NativeScript plugin.
JavaScript
8
star
96

widget-example

iOS Home Screen Widget Example
TypeScript
8
star
97

sample-iOS-CameraApp

In this sample we are demonstrating how you can write platform specific code with NativeScript. We are building iOS only app which uses the latest iOS8 camera APIs.
JavaScript
7
star
98

flutter-example

Using Flutter with NativeScript including Bluetooth integration via @nativescript-community/ble
Dart
7
star
99

storybook

📚 Storybook for NativeScript 📲
TypeScript
7
star
100

android-metadata-generator

Contains the source for metadata generation in Android Runtime
7
star