Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Command-line interface for building NativeScript apps

License

NotificationsYou must be signed in to change notification settings

NativeScript/nativescript-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 


Nativescript Logo

NativeScript Command-Line Interface

The NativeScript CLI lets you create, build, and deployNativeScript apps.


nativescript -> npm

Get it using:npm install -g nativescript

What is NativeScript

NativeScript provides platform APIs directly to the JavaScript runtime (with strong types) for a rich TypeScript development experience.

Some popular use cases:

  • Building Web, iOS, Android and Vision Pro apps with a shared codebase (aka, cross platform apps)
  • Building native platform apps with portable JavaScript skills
  • Augmenting JavaScript projects with platform API capabilities
  • AndroidTV and Watch development
  • watchOS development
  • Learning native platforms through JavaScript understanding
  • Exploring platform API documentation by trying APIsdirectly from a web browser without requiring a platform development machine setup.

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.

OSNode.js installed fromhttps://nodejs.org/Node.js installed via package manager
Windowsnpm install nativescript -gnpm install nativescript -g
macOSsudo npm install nativescript -g --unsafe-permnpm install nativescript -g
Linuxsudo npm install nativescript -g --unsafe-permnpm 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 proxyset<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 ishttp://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

--insecureThe--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

Runns help to view all available commands in the browser. Runns 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 thetemplate option followed by eithertypescript,angular orvue.

ns create MyApp --template typescriptns create MyApp --template angularns create MyApp --template vue

Or you can simply use the shorthandtsc andng options.

ns create MyApp --tscns create MyApp --ng

With thetemplate 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 toorg.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    └── ...
  • Theapp directory is thedevelopment space for your application. You should modify all common and platform-specific code within this directory. When you runprepare <Platform>, the NativeScript CLI prepares relevant content to the platform-specific folders for each target platform.
  • Theplatforms 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 runprepare <Platform>, the NativeScript CLI prepares relevant content from theapp 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 inapp

Theapp 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 theapp directory, you can useplatform-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 orname.android.extension. For example:main.ios.js ormain.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 inplatforms

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

Modifying Configuration Files

The NativeScript CLI respects any platform configuration files placed insideapp/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 theapp.entitlements file placed insideapp/App_Resources/iOS. When building the project, the defaultapp/App_Resources/iOS/app.entitlements file gets merged with all Plugins entitlement files and a newyourAppName.entitlements is created in the platforms directory. The path would beapp/platforms/ios/<application name>/<application name>.entitlements and will be linked in thebuild.xcconfig file.

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

Back to Top

Build Your Project

You can build it for your target mobile platforms.

ns build androidns 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, seeiOS 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 androidns run ios

Back to Top

Extending the CLI

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

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 theExtending 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 missingJAVA 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 canreport an issue orask the community.

Back to Top

How to Contribute

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

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

To learn how to contribute to the code base, clickhere.

Back to Top

How to Build

git clone https://github.com/NativeScript/nativescript-clicd nativescript-clinpm run setup

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

Back to Top

Get Help

Please, usegithub issues strictly forreporting bugs orrequesting features. For general NativeScript questions and support, check outStack Overflow or ask our experts in theNativeScript community Discord channel.

Back to Top

License

This software is licensed under the Apache 2.0 license, quotedhere.

Back to Top

Sponsor this project

  •  

Packages

No packages published

Contributors105


[8]ページ先頭

©2009-2025 Movatter.jp