Giter Site home page Giter Site logo

nativescript / nativescript-cli Goto Github PK

View Code? Open in Web Editor NEW
1.0K 1.0K 194.0 172.05 MB

Command-line interface for building NativeScript apps

Home Page: https://www.npmjs.com/package/nativescript

License: Apache License 2.0

Shell 0.01% JavaScript 72.93% TypeScript 26.97% Batchfile 0.01% HTML 0.01% CSS 0.08%
android cli cross-platform hacktoberfest ios mobile nativescript

nativescript-cli's Introduction


Nativescript Logo

NativeScript Command-Line Interface

The NativeScript CLI lets you create, build, and deploy NativeScript 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 APIs directly 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.

OS Node.js installed from https://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 of ns you can call PATH_TO_CLI_FOLDER/bin/ns. 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

nativescript-cli's People

Contributors

dimitartachev avatar dtopuzov avatar e2l3n avatar enchev avatar erjangavalji avatar etabakov avatar farfromrefug avatar fatme avatar fealebenpae avatar hdeshev avatar ikoevska avatar janoshrubos avatar jasssonpet avatar kristiandd avatar kristinakoeva avatar mitko-kerezov avatar nathanwalker avatar panayotcankov avatar petekanev avatar plamen5kov avatar rigor789 avatar rosen-vladimirov avatar sis0k0 avatar tailsu avatar tdermendjiev avatar teobugslayer avatar tomanikolov avatar tsvetanmilanov avatar tzraikov avatar yyosifov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nativescript-cli's Issues

'$ tns platform list' message is misleading if all available platforms are installed

Current msg: No available platforms found
It should be something else (e.g "All available platforms are installed(added)")

Case 1: No platforms are added
Current:
$ tns platform list Available platforms: android No installed platforms found.
Expected:
$ tns platform list Available platforms for this OS: android No installed platforms found. Use $ tns platform add

Case 2: Platform is added, but the project is not prepared
Current:
$ tns platform list No available platforms found. Installed platforms: android
Expected:
$ tns platform list The project is not prepared for any platform Installed platforms: android

Case 3: Platform is prepared
Current:
$ tns platform list No available platforms found. Installed platforms: android
Expected:
$ tns platform list The project is prepared for: <platform> Installed platforms: android

Error when adding ios platform

./tns create TNS_JS
n
./tns platform add ios --path TNS_JS

Copying template files...
Installing  tns-ios@<0.4.0
[email protected] TNS_JS/platforms/ios/node_modules/tns-ios
Installed  tns-ios@<0.4.0
cp: no such file or directory: /Users/jzhekov/Desktop/Trash/tns-cli/node_modules/.bin/TNS_JS/platforms/ios/node_modules/.DS_Store/framework/*

ENOTDIR, open '/Users/jzhekov/Desktop/Trash/tns-cli/node_modules/.bin/TNS_JS/platforms/ios/node_modules/.DS_Store/package.json'

The .DS_Store file is created by opening the TNS_JS/platforms/ios/node_modules/ in Finder.

'tns emulate android --emulator' fails if real device is also attached

Steps to reproduce:

Start one emulator and connect one real device
So that devices list looks like this:

$ adb devices
List of devices attached
device
emulator-5554 device

tns create TNS_Javascript
tns platform add android --path TNS_Javascript
tns prepare android --path TNS_Javascript
tns emulate android --emulator --path TNS_Javascript

Result:
BUILD SUCCESSFUL
Total time: 1 second
Project successfully built
Using /private/var/lib/jenkins/workspace/CLI-stable-tests-osx/TNS_Javascript/platforms/android/bin/TNS_Javascript-debug.apk
execFile: /private/var/lib/jenkins/workspace/CLI-stable-tests-osx/node_modules/nativescript/resources/platform-tools/android/darwin/adb devices
execFile: /private/var/lib/jenkins/workspace/CLI-stable-tests-osx/node_modules/nativescript/resources/platform-tools/android/darwin/adb devices
waiting for the emulator device to appear
spawn: /private/var/lib/jenkins/workspace/CLI-stable-tests-osx/node_modules/nativescript/resources/platform-tools/android/darwin/adb wait-for-device
Command /private/var/lib/jenkins/workspace/CLI-stable-tests-osx/node_modules/nativescript/resources/platform-tools/android/darwin/adb exited with code 1

Note: Everything works fine if real device is disconnected.

Wrong error messages

Case 1:
This command:
"tns deploy android --device fakeDevice --path TNS_Javascript"
returns following error:
Cannot resolve the specified connected device by the provided index or identifier. To list currently connected devices and verify that the specified index or identifier exists, run 'appbuilder device'.

'appbuilder device' is wrong, it should be replaced with 'tns list-devices'

Case 2:
When all Android devices are disconnected and you call "tns list-devices android" then you see:
Cannot find connected devices. Reconnect any connected devices, verify that your system recognizes them, and run this command again

Then message does not end with '.'.

Prepare android project fail to copy some resources

$ tns platform add android --frameworkPath tns-android-stable-latest.tgz --path CutenessIO
Copying template files...
Installing tns-android-stable-latest.tgz
[email protected] CutenessIO/platforms/android/node_modules/tns-android
Installed tns-android-stable-latest.tgz
cp: no such file or directory: /private/var/lib/jenkins/workspace/CutenessIO/platforms/android/node_modules/tns-android/framework/gen

cp: no such file or directory: /private/var/lib/jenkins/workspace/CutenessIO/platforms/android/node_modules/tns-android/framework/.project

sed: no such file or directory: /private/var/lib/jenkins/workspace/CutenessIO/platforms/android/.project

Autocompletion with [TAB][TAB] on command's arguments, throws exception

$ tns platform add [TAB][TAB]
- - - - -
at CommandDispatcher.completeCommand (c:\Users\tytodorov\AppData\Roaming\npm\node_modules\nativescript\lib\common\dispatchers.js:38:59)
at FiberFuture.Future.wait (c:\Users\tytodorov\AppData\Roaming\npm\node_modules\nativescript\node_modules\fibers\future.js:415:10)
at FiberFuture.Future.wait (c:\Users\tytodorov\AppData\Roaming\npm\node_modules\nativescript\node_modules\fibers\future.js:416:15)
at Function.settle (c:\Users\tytodorov\AppData\Roaming\npm\node_modules\nativescript\node_modules\fibers\future.js:148:26)
at Object.complete (c:\Users\tytodorov\AppData\Roaming\npm\node_modules\nativescript\node_modules\tabtab\lib\completion.js:68:3)
at c:\Users\tytodorov\AppData\Roaming\npm\node_modules\nativescript\lib\common\dispatchers.js:92:35
at c:\Users\tytodorov\AppData\Roaming\npm\node_modules\nativescript\lib\common\services\commands-service.js:136:20
at completeCallback (c:\Users\tytodorov\AppData\Roaming\npm\node_modules\nativescript\lib\common\services\commands-service.js:108:34)
TypeError: undefined is not a function

Executing "$ tns platform add ios" throws exception

Xcode: Version 5.0.2 (5A3005)

TYTODOROVMAC:kolcho tytodorov$ tns platform add ios --log trace
Starting watch on killswitch /Users/tytodorov/.nativescript-cli/KillSwitches/cli
Looking for project in '/Users/tytodorov/nativeclitest/kolcho'
Project directory is '/Users/tytodorov/nativeclitest/kolcho'.
exec: which xcodebuild
exec: xcodebuild -version | head -n 1 | sed -e 's/Xcode //'
Version strings are not in the same format
Usage:
$ tns platform add

Platform-specific usage:
$ tns platform add android
$ tns platform add ios

Creates a new platform specific project. In this version of Telerik NativeScript you can create only ios and android projects.
You can create Android projects on windows and Mac machine. You can create ios projects only on Mac machine.

`Deploy` command

Implement deploy command for all platforms. It should deploy the built application on all connected devices or emulators\simulators.

If the --device option is specified it should deploy only to the connected devices.

If the --emulator option is specific it should deploy only to the target emulator. If there is no running emulator it should be launched and then deployed to.

Command `hooks`

Implement before and after hooks for each command. Those should be scripts that will be loaded and executed before and after each command gets executed. We will need to have a set of default hooks and move our platform-specific files logic as such hook. Custom project hooks will live in the hooks folder of the project.

Prepare ios project fail to copy some resources

Here is what happens when I try to prepare ios:

$ node_modules/.bin/tns prepare ios --path UnitTestApp
cp: copyFileSync: could not write to dest file (code=ENOENT):/private/var/lib/jenkins/workspace/CLI-stable-tests-osx/UnitTestApp/platforms/ios/UnitTestApp/Resources/icons
Project successfully prepared

Support node.js API

Hello, I think it would be nice if you supported Node.js apis out of the box so that you could easily share all the modules that exist in the npm ecosystem.

`platform update` command

Implement platform update command which will update the given platform to the latest (or specified) version.

Info command

Info command should print more detailed information for project:

  • current runtime's version
  • commit sha for runtimes and modules
  • more specified information for each platform (for example apilevel for android)
  • debug information about user's machine setup (useful for debugging purposes)

Executing `$ tns platform` should display the help of 'platform' command

it should be:
$ tns platform
Usage:
$ tns platform

is a related command that extends the platform command. You can run the following related commands:
list - Lists all available and installed platforms.
add - Creates a new platform specific project
{MIsssing} Remove - Removes the platform specific project

Research iOS8

Research how would we react to the iOS8 release.
We may need to support versioning (e.g. builds for iOS7.0 or iOS8.0)
We may need to support two versions of xcode during the migration from iOS7 to iOS8.
The iOS runtime should support iOS8, do we need two builds of the runtime?

'tns run android --emulator' does not work if emulator is not started before that

Description:
'tns run android --emulator' does not work if emulator is not started before that
Expected:
'tns run android --emulator' should start new emulator if emulator is not running

Steps to reproduce:
tns create TNSApp
tns platform add andorid --path TNSApp
tns prepare android --path TNSApp
tns run android --emulator --path TNSApp

Android emulator is not started, last command does not finish, output is:

BUILD SUCCESSFUL
Total time: 4 seconds
Project successfully built
Using c:\Workspaces\cli-tests\TNSApp\platforms\android\bin\TNSApp-debug.apk
Starting Android emulator with image true

More Details:
In task manager I see that "adb wait-for-device" is running
Found on Windows 8.1

Workaround:
Start some existing avd before 'tns run android --emulator --path TNSApp' command and it will deploy and run the app successfully.

Build iOS project fails because of missing icons

Log:

The following build commands failed:
CopyPNGFile /private/var/lib/jenkins/workspace/tns-modules-stable-build-unittests-ipa/UnitTestApp/platforms/ios/build/device/UnitTestApp.app/Default-Landscape.png UnitTestApp/Resources/icons/Default-Landscape.png
CopyPNGFile /private/var/lib/jenkins/workspace/tns-modules-stable-build-unittests-ipa/UnitTestApp/platforms/ios/build/device/UnitTestApp.app/[email protected] UnitTestApp/Resources/icons/[email protected]
CopyPNGFile /private/var/lib/jenkins/workspace/tns-modules-stable-build-unittests-ipa/UnitTestApp/platforms/ios/build/device/UnitTestApp.app/[email protected] UnitTestApp/Resources/icons/[email protected]
CopyPNGFile /private/var/lib/jenkins/workspace/tns-modules-stable-build-unittests-ipa/UnitTestApp/platforms/ios/build/device/UnitTestApp.app/Default-Portrait.png UnitTestApp/Resources/icons/Default-Portrait.png
CopyPNGFile /private/var/lib/jenkins/workspace/tns-modules-stable-build-unittests-ipa/UnitTestApp/platforms/ios/build/device/UnitTestApp.app/[email protected] UnitTestApp/Resources/icons/[email protected]
CopyPNGFile /private/var/lib/jenkins/workspace/tns-modules-stable-build-unittests-ipa/UnitTestApp/platforms/ios/build/device/UnitTestApp.app/Default.png UnitTestApp/Resources/icons/Default.png
CopyPNGFile /private/var/lib/jenkins/workspace/tns-modules-stable-build-unittests-ipa/UnitTestApp/platforms/ios/build/device/UnitTestApp.app/[email protected] UnitTestApp/Resources/icons/[email protected]
CopyPNGFile /private/var/lib/jenkins/workspace/tns-modules-stable-build-unittests-ipa/UnitTestApp/platforms/ios/build/device/UnitTestApp.app/icon-40.png UnitTestApp/Resources/icons/icon-40.png

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.