• Stars
    star
    186
  • Rank 199,843 (Top 5 %)
  • Language
    TypeScript
  • License
    Apache License 2.0
  • Created over 6 years ago
  • Updated about 2 years ago

Reviews

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

Repository Details

nativescript, mobile, schematics, angular

NativeScript Schematics Build Status

This repository contains schematics for generating components in NativeScript Angular apps using the Angular CLI.

Installation

Install Angular CLI

You should be using @angular/[email protected] or newer.

npm i -g @angular/cli

Install NativeScript Schematics

npm i -g @nativescript/schematics

Usage

Creating a new project

To generate new NativeScript Angular project, you can use ng new with @nativescript/schematics specified as the schematics collection.

NativeScript Only

ng new --collection=@nativescript/schematics my-mobile-app

You can specify the following options when generating new applications:

Option Description Default
prefix The prefix to apply to generated selectors. app
theme Specifies whether the {N} css theme should be included. true
style Specifies whether the app should use 'css' or 'scss' files for styling. css
webpack Specifies whether the app will be ready for building with webpack. true

Web + Mobile Code Sharing project

ng new --collection=@nativescript/schematics my-shared-app --shared

You can specify the following options when generating new applications:

Option Description Default
sourceDir The name of the source directory. src
prefix The prefix to apply to generated selectors. app
theme Specifies whether the {N} css theme should be included. true
style Specifies whether the app should use 'css' or 'scss' files for styling. css
sample Generates an eagerly loaded module and master-detail navigation. false

Prerequisites for using @nativescript/schematics in an existing project

You need to add an angular.json configuration file to your NativeScript project root directory. That will allow you to use Angular CLI for generating components.

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "cli": {
    "defaultCollection": "@nativescript/schematics"
  },
  "projects": {
    "project-name": {
      "root": "",
      "sourceRoot": ".",
      "projectType": "application",
      "prefix": "app",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        }
      }
    }
  },
  "defaultProject": "project-name"
}

Note: If you created your project with ng new, your project already has angular.json.

Generate angular.json

You can generate it the configuration using Schematics. Install Schematics globally

npm install -g @angular-devkit/schematics-cli

From inside your project call:

schematics @nativescript/schematics:angular-json --name=project-name

Generating Components, Modules, Directives, etc.

You can use the ng generate (or just ng g) command to generate pretty much any Angular building unit - components, modules, directives, classes and so on. For the full list, check out the Angular CLI repo. Some of these generators are overwritten in NativeScript Schematics to suite the needs of a NativeScript Angular application.

To generate a component, call:

ng g c component-name

To generate a module, call:

ng g m module-name

To generate a component in an existing module folder, call:

ng g c module-name/component-name

Migrating ng Project to a shared project

Migrating Web Components to a Shared Components

You can use ng generate migrate-component to convert a web Component to a shared component. This includes the following steps:

  • add component-name.component.tns.html
  • add the component to its .tns parent module - note that the module-name.module.tns.ts need to exist before you execute the command, or just use the --skipModule flag

Params:

  • name - required - name of the component to be migrated - do not include the word Component
  • componentPath - optional - the location of the component file, do not include src/app, i.e. home/home.component.ts - use if the componentPath cannot be derived from the parent module
  • module - optional - the name of the parent module - do not include the word Module, leave empty if using the default EntryModule (AppModule)
  • modulePath - optional - the location of the parent module file, do not include src/app, i.e. home/home.module.ts - use if the module is not located at the root/app (by default: src/app)
  • skipModule - optional - use if you don't want the module to be used for finding the component, and if you don't want to add the Component to Modules providers

Migrating Web Modules to Shared Modules

You can use ng generate migrate-module to convert a Web Module to a Shared Module and also convert all of its Components. This includes the following steps:

  • add module-name.component.tns.ts
  • convert all of modules' components, by using migrate-component schematic
  • copy over all providers from the web module

Code sharing: Build

In a code sharing project to build:

  • a web app call: ng serve,
  • an iOS app call: tns run ios,
  • an Android app call: tns run android

Templates

Master Detail template

To generate a Master Detail module, you can use the following command ng g master-detail --master=dogs --detail=dog

The above command will generate the following file structure

  • dogs
  • dog-detail
    • dog-detail component files
  • dogs
    • dogs component files
  • data.service.ts
  • dogs.module.ts

Options

Option Description
master The name of the master component and the name of the module.
detail The name of the detail component

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

nativescript-cli

Command-line interface for building NativeScript apps
JavaScript
1,036
star
4

android

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

sample-Groceries

๐Ÿ ๐Ÿ ๐Ÿ“ A NativeScript-built iOS and Android app for managing grocery lists
TypeScript
484
star
6

docs-v7

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

nativescript-marketplace-demo

NativeScript kitchen sink demo. All of NativeScriptโ€™s functionality in one app.
TypeScript
325
star
8

ios-jsc

NativeScript for iOS using JavaScriptCore
JavaScript
295
star
9

nativescript-sdk-examples-ng

NativeScript and Angular code samples.
TypeScript
293
star
10

nativescript-app-templates

Monorepo for NativeScript app templates
TypeScript
216
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