Skip to content

Commit cd01f24

Browse files
author
radeva
authored
Merge branch 'master' into radeva/tsc-watch
2 parents ddf071a + eff2f09 commit cd01f24

File tree

7 files changed

+181
-58
lines changed

7 files changed

+181
-58
lines changed

.github/pull_request_template.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!--
2+
We, the rest of the NativeScript community, thank you for your
3+
contribution!
4+
To help the rest of the community review your change, please follow the instructions in the template.
5+
-->
6+
7+
<!-- PULL REQUEST TEMPLATE -->
8+
<!-- (Update "[ ]" to "[x]" to check a box) -->
9+
10+
## PR Checklist
11+
12+
- [ ] The PR title follows our guidelines: https://github.com/NativeScript/NativeScript/blob/master/CONTRIBUTING.md#commit-messages.
13+
- [ ] There is an issue for the bug/feature this PR is for. To avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it.
14+
- [ ] All existing tests are passing
15+
- [ ] Tests for the changes are included
16+
17+
## What is the current behavior?
18+
<!-- Please describe the current behavior that you are modifying, or link to a relevant issue. -->
19+
20+
## What is the new behavior?
21+
<!-- Describe the changes. -->
22+
23+
Fixes/Implements/Closes #[Issue Number].
24+
25+
<!-- If this PR contains a breaking change, please describe the impact and migration path for existing applications below. -->
26+
27+
<!--
28+
BREAKING CHANGES:
29+
30+
31+
[Describe the impact of the changes here.]
32+
33+
Migration steps:
34+
[Provide a migration path for existing applications.]
35+
-->
36+

CONTRIBUTING.md

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Contributing to NativeScript Plugin Seed
2+
3+
:+1: First of all, thank you for taking the time to contribute! :+1:
4+
5+
Here are some guides on how to do that:
6+
7+
<!-- TOC depthFrom:2 -->
8+
9+
- [Code of Conduct](#code-of-conduct)
10+
- [Reporting Bugs](#reporting-bugs)
11+
- [Requesting Features](#requesting-features)
12+
- [Submitting a PR](#submitting-a-pr)
13+
- [Where to Start](#where-to-start)
14+
15+
<!-- /TOC -->
16+
17+
## Code of Conduct
18+
Help us keep a healthy and open community. We expect all participants in this project to adhere to the [NativeScript Code Of Conduct](https://github.com/NativeScript/codeofconduct).
19+
20+
21+
## Reporting Bugs
22+
23+
1. Always update to the most recent master release; the bug may already be resolved.
24+
2. Search for similar issues in the issues list for this repo; it may already be an identified problem.
25+
3. If this is a bug or problem that is clear, simple, and is unlikely to require any discussion -- it is OK to open an issue on GitHub with a reproduction of the bug including workflows and screenshots. If possible, submit a Pull Request with a failing test, entire application or module. If you'd rather take matters into your own hands, fix the bug yourself (jump down to the [Submitting a PR](#submitting-a-pr) section).
26+
27+
## Requesting Features
28+
29+
1. Use Github Issues to submit feature requests.
30+
2. First, search for a similar request and extend it if applicable. This way it would be easier for the community to track the features.
31+
3. When requesting a new feature, please provide as much detail as possible about why you need the feature in your apps. We prefer that you explain a need rather than explain a technical solution for it. That might trigger a nice conversation on finding the best and broadest technical solution to a specific need.
32+
33+
## Submitting a PR
34+
35+
Before you begin:
36+
* Make sure there is an issue for the bug or feature you will be working on.
37+
38+
Following these steps is the best way to get your code included in the project:
39+
40+
1. Fork and clone the nativescript-plugin-seed repo:
41+
```bash
42+
git clone https://github.com/<your-git-username>/nativescript-plugin-seed.git
43+
# Navigate to the newly cloned directory
44+
cd nativescript-plugin-seed
45+
# Add an "upstream" remote pointing to the original repo.
46+
git remote add upstream https://github.com/NativeScript/nativescript-plugin-seed.git
47+
```
48+
2. Create a branch for your PR
49+
```bash
50+
git checkout -b <my-fix-branch> master
51+
```
52+
53+
3. The fun part! Make your code changes. Make sure you:
54+
- Follow the [code conventions guide](https://github.com/NativeScript/NativeScript/blob/master/CodingConvention.md).
55+
- Follow the [commit message guidelines](https://github.com/NativeScript/NativeScript/blob/pr-template/CONTRIBUTING.md#commit-messages)
56+
- Setup your development workflow. The seed itself is a plugin so you can follow the [development setup][https://github.com/NativeScript/nativescript-plugin-seed#development-setup] described in the README.
57+
- Write unit tests for your fix or feature. If this is not possible, explain how your change can be tested.
58+
> NOTE: For changes in the postclone step, make sure you create tests in `seed-tests/postclone.tests.js`!
59+
60+
4. Before you submit your PR:
61+
- Rebase your changes to the latest master: `git pull --rebase upstream master`.
62+
- Ensure all unit test are green. How?
63+
- Go to `seed-tests`
64+
- Run `npm install`
65+
- Run `npm run test.ios` or `npm run test.android`
66+
- Ensure your changes pass tslint validation. (run `npm run tslint` in the root of the repo).
67+
68+
6. Push your fork. If you have rebased you might have to use force-push your branch:
69+
```
70+
git push origin <my-fix-branch> --force
71+
```
72+
73+
7. [Submit your pull request](https://github.com/NativeScript/nativescript-plugin-seed/compare) and compare to `NativeScript/nativescript-plugin-seed`. Please, fill in the Pull Request template - it will help us better understand the PR and increase the chances of it getting merged quickly.
74+
75+
It's our turn from there on! We will review the PR and discuss changes you might have to make before merging it! Thanks!
76+
77+
## Where to Start
78+
79+
If you want to contribute, but you are not sure where to start - look for issues labeled [`help wanted`](https://github.com/NativeScript/nativescript-plugin-seed/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22).

README.md

+55-30
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,38 @@
22

33
> This repo is heavily based on [@NathanWalker](https://github.com/NathanWalker)'s [Plugin Seed](https://github.com/NathanWalker/nativescript-plugin-seed). Thanks, Nathan!
44
5-
<!-- vscode-markdown-toc -->
6-
* [TL;DR](#TLDR)
7-
* [Long Description](#LongDescription)
8-
* [What is NativeScript plugin seed?](#WhatisNativeScriptpluginseed)
9-
* [Plugin folder structure](#Pluginfolderstructure)
10-
* [Getting started](#Gettingstarted)
11-
* [Development setup](#Developmentsetup)
12-
* [Linking to CocoaPod or Android Arsenal plugins](#LinkingtoCocoaPodorAndroidArsenalplugins)
13-
* [Unittesting](#Unittesting)
14-
* [Publish to NPM](#PublishtoNPM)
15-
* [TravisCI](#TravisCI)
16-
* [Referring tns-core-modules in the Plugin](#ReferringtnscoremodulesinthePlugin)
17-
18-
<!-- vscode-markdown-toc-config
19-
numbering=false
20-
autoSave=true
21-
/vscode-markdown-toc-config -->
22-
<!-- /vscode-markdown-toc -->
23-
24-
## <a name='TLDR'></a>TL;DR
5+
<!-- TOC depthFrom:2 -->
6+
7+
- [TL;DR](#tldr)
8+
- [Long Description](#long-description)
9+
- [What is NativeScript plugin seed?](#what-is-nativescript-plugin-seed)
10+
- [Plugin folder structure](#plugin-folder-structure)
11+
- [Getting started](#getting-started)
12+
- [Development setup](#development-setup)
13+
- [Linking to CocoaPod or Android Arsenal plugins](#linking-to-cocoapod-or-android-arsenal-plugins)
14+
- [Generating typings for iOS](#generating-typings-for-ios)
15+
- [Generating typings for Android](#generating-typings-for-android)
16+
- [Clean plugin and demo files](#clean-plugin-and-demo-files)
17+
- [Unittesting](#unittesting)
18+
- [Publish to NPM](#publish-to-npm)
19+
- [TravisCI](#travisci)
20+
- [Referring tns-core-modules in the Plugin](#referring-tns-core-modules-in-the-plugin)
21+
- [Contribute](#contribute)
22+
- [Get Help](#get-help)
23+
24+
<!-- /TOC -->
25+
26+
## TL;DR
2527
The NativeScript plugin seed is built to be used as a starting point by NativeScript plugin developers. To bootstrap your plugin development execute the following:
2628

2729
1. `git clone https://github.com/NativeScript/nativescript-plugin-seed nativescript-yourplugin` where `nativescript-yourplugin` is the name of your plugin.
2830
2. `cd nativescript-yourplugin/src`
2931
3. `npm run postclone`
3032
4. `npm run demo.ios` or `npm run demo.android` to run the demo. This will automatically watch for TypeScript changes also in your plugin and do the transpilation.
3133

32-
## <a name='LongDescription'></a>Long Description
34+
## Long Description
3335

34-
### <a name='WhatisNativeScriptpluginseed'></a>What is NativeScript plugin seed?
36+
### What is NativeScript plugin seed?
3537

3638
The NativeScript plugin seed is built to be used as a starting point by NativeScript plugin developers. It expands on several things [presented here](http://developer.telerik.com/featured/creating-nativescript-plugins-in-typescript/).
3739
What does the seed give you out of the box?
@@ -46,7 +48,7 @@ What does the seed give you out of the box?
4648

4749
![Plugin seed demo](https://github.com/NativeScript/nativescript-plugin-seed/blob/master/screenshots/demo.png?raw=true)
4850

49-
### <a name='Pluginfolderstructure'></a>Plugin folder structure
51+
### Plugin folder structure
5052

5153
|Folder/File name| Description
5254
|---|---|
@@ -59,7 +61,7 @@ What does the seed give you out of the box?
5961
|src/scripts|The postclone script run when you execute `npm run postclone`. Feel free to delete it after you have executed the postclone step from the [Getting started](#Gettingstarted) section|
6062
|publish|Contains a shell script to create and publish your package. Read more on creating a package and publishing in the [Publish to NPM](#Publishtonpm) section|
6163

62-
### <a name='Gettingstarted'></a>Getting started
64+
### Getting started
6365

6466
1. Open a command prompt/terminal and execute `git clone https://github.com/NativeScript/nativescript-plugin-seed nativescript-yourplugin` to clone the plugin seed repository into the `nativescript-yourplugin` folder where `nativescript-yourplugin` is the name of your plugin..
6567
2. Open a command prompt/terminal and navigate to `nativescript-yourplugin/src` folder using `cd nativescript-yourplugin/src`
@@ -72,7 +74,7 @@ What does the seed give you out of the box?
7274

7375
Now you can continue with the development of your plugin by using the [Development setup](#Developmentsetup) described below.
7476

75-
#### <a name='Developmentsetup'></a>Development setup
77+
#### Development setup
7678
For easier development and debugging purposes continue with the following steps:
7779

7880
1. Open a command prompt/terminal, navigate to `src` folder and run `npm run demo.ios` or `npm run demo.android` to run the demo.
@@ -82,7 +84,7 @@ Now go and make a change to your plugin. It will be automatically applied to the
8284

8385
NOTE: If you need to use a native library in your plugin or do some changes in Info.plist/AndroidManifest.xml, these cannot be applied to the demo project only by npm link. In such scenario, you need to use `tns plugin add ../src` from the `demo` so that the native libraries and changes in the above-mentioned files are applied in the demo. Then you can link again the code of your plugin in the demo by using `npm run plugin.link` from the `src`.
8486

85-
### <a name='LinkingtoCocoaPodorAndroidArsenalplugins'></a>Linking to CocoaPod or Android Arsenal plugins
87+
### Linking to CocoaPod or Android Arsenal plugins
8688

8789
You will want to create these folders and files in the `src` folder in order to use native APIs:
8890

@@ -101,6 +103,23 @@ Take a look at these existing plugins for how that can be done very simply:
101103
* [nativescript-cardview](https://github.com/bradmartin/nativescript-cardview/tree/master/platforms)
102104
* [nativescript-floatingactionbutton](https://github.com/bradmartin/nativescript-floatingactionbutton/tree/master/src/platforms)
103105

106+
It's highly recommended to generate typings for the native libraries used in your plugin. By generating typings you'll be able to see what APIs exactly are exposed to Javascript and use them easily in your plugin code
107+
108+
#### Generating typings for iOS
109+
110+
- Run the command for typings generation as explained in the [documentation](https://docs.nativescript.org/runtimes/ios/how-to/Use-Native-Libraries#troubleshooting)
111+
- Open `demo/typings/x86_64` and copy the `d.ts` files that you plan to use in your plugin to `src\platforms\ios\typings`
112+
- Open `src\references.d.ts` and add a reference to each of the files added to `src\platforms\ios\typings`
113+
114+
**NOTE**: Swift APIs that are not exported to Objective-C are not supported. This means that you can only call APIs from JavaScript that are visible to the Objective-C runtime. This include all Objective-C APIs and only the subset of all Swift APIs that are exposed to Objective-C. So, to use a Swift API (class/function/method etc.) from NativeScript, first make sure that it can be used from Objective-C code. For more information which Swfit APIs can be exposed to Objective-C, see [here](https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithObjective-CAPIs.html#//apple_ref/doc/uid/TP40014216-CH4-ID53).
115+
116+
#### Generating typings for Android
117+
118+
- Clone [Android DTS Generator repo](https://github.com/NativeScript/android-dts-generator)
119+
- Follow the steps in the [README](https://github.com/NativeScript/android-dts-generator/blob/master/README.md)
120+
- Copy the generated d.ts files in `src\platforms\android\typings`. Feel free to rename the generated files for readablity.
121+
- Open `src\references.d.ts` and add a reference to each of the files added to `src\platforms\android\typings`
122+
104123
### Clean plugin and demo files
105124

106125
Sometimes you may need to wipe away the `node_modules` and `demo/platforms` folders to reinstall them fresh.
@@ -115,7 +134,7 @@ Sometimes you may need to ensure plugin files are updated in the demo:
115134

116135
* Run `npm run plugin.prepare` will do a fresh build of the plugin then remove itself from the demo and add it back for assurance.
117136

118-
### <a name='Unittesting'></a>Unittesting
137+
### Unittesting
119138
The plugin seed automatically adds Jasmine-based unittest support to your plugin.
120139
Open `demo/app/tests/tests.js` and adjust its contents so the tests become meaningful in the context of your plugin and its features.
121140

@@ -128,7 +147,7 @@ npm run test.ios
128147
npm run test.android
129148
```
130149

131-
### <a name='PublishtoNPM'></a>Publish to NPM
150+
### Publish to NPM
132151

133152
When you have everything ready to publish:
134153

@@ -139,13 +158,13 @@ If you just want to create a package, go to `publish` folder and execute `pack.s
139158

140159
**NOTE**: To run bash script on Windows you can install [GIT SCM](https://git-for-windows.github.io/) and use Git Bash.
141160

142-
### <a name='TravisCI'></a>TravisCI
161+
### TravisCI
143162

144163
The plugin structure comes with a fully functional .travis.yml file that deploys the testing app on Android emulator and iOS simulator and as a subsequent step runs the tests from [UnitTesting section](#Unittesting). All you have to do, after cloning the repo and implementing your plugin and tests, is to sign up at [https://travis-ci.org/](https://travis-ci.org/). Then enable your plugin's repo on "https://travis-ci.org/profile/<your github user\>" and that's it. Next time a PR is opened or change is committed to a branch TravisCI will trigger a build testing the code.
145164

146165
To properly show current build status you will have to edit the badge at the start of the README.md file so it matches your repo, user and branch.
147166

148-
### <a name='ReferringtnscoremodulesinthePlugin'></a>Referring tns-core-modules in the Plugin
167+
### Referring tns-core-modules in the Plugin
149168
We recommend to use full imports of `tns-core-modules` due to [an issue in Angular CLI](https://github.com/angular/angular-cli/issues/5618#issuecomment-306479219). Read more detailed explanation in [this discussion](https://github.com/NativeScript/nativescript-plugin-seed/pull/32#discussion_r131147787).
150169

151170
Ultimately after the issue in Angular CLI is fixed this would not be a restriction, but till then the recommended approach is to import from `tns-core-modules` using full path. Here is an example:
@@ -176,3 +195,9 @@ import * as app from 'application';
176195
````
177196
import * as app from 'tns-core-modules/application';
178197
````
198+
199+
## Contribute
200+
We love PRs! Check out the [contributing guidelines](CONTRIBUTING.md). If you want to contribute, but you are not sure where to start - look for issues labeled [`help wanted`](https://github.com/NativeScript/tns-core-modules-widgets/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22).
201+
202+
## Get Help
203+
Please, use [github issues](https://github.com/NativeScript/tns-core-modules-widgets/issues) strictly for [reporting bugs](CONTRIBUTING.md#reporting-bugs) or [requesting features](CONTRIBUTING.md#requesting-new-features). For general questions and support, check out the [NativeScript community forum](https://discourse.nativescript.org/) or ask our experts in [NativeScript community Slack channel](http://developer.telerik.com/wp-login.php?action=slack-invitation).

seed-tests/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"devDependencies": {
33
"async": "^2.4.1",
4+
"cross-env": "^5.1.3",
45
"glob": "^7.1.2",
56
"jasmine": "^2.6.0",
67
"ncp": "^2.0.0",
78
"rimraf": "^2.6.1"
89
},
910
"scripts": {
10-
"test.android": "ANDROID=true jasmine --config=jasmine.config.json",
11-
"test.ios": "IOS=true jasmine --config=jasmine.config.json"
11+
"test.android": "cross-env ANDROID=true jasmine --config=jasmine.config.json",
12+
"test.ios": "cross-env IOS=true jasmine --config=jasmine.config.json"
1213
},
1314
"dependencies": {}
14-
}
15+
}

seed-tests/postclone.tests.js

-19
Original file line numberDiff line numberDiff line change
@@ -133,25 +133,6 @@ describe('postclone', function () {
133133
});
134134
});
135135

136-
it('should create an npm link to the src folder', function (done) {
137-
testUtils.getNpmLinks(function (links) {
138-
var expectedLink = links.filter(function (item) {
139-
return item.startsWith("nativescript-" + constants.TEST_PLUGIN_NAME + "@1.0.0") && item.endsWith(constants.SEED_COPY_LOCATION + "/src");
140-
});
141-
142-
expect(expectedLink.length).toEqual(1);
143-
done();
144-
});
145-
});
146-
147-
it('should link the plugin in the demo folder', function (done) {
148-
var demoPluginPackageJson = constants.SEED_COPY_LOCATION + "/demo/node_modules/nativescript-" + constants.TEST_PLUGIN_NAME + "/package.json";
149-
var srcPluginPackageJson = constants.SEED_COPY_LOCATION + "/src/package.json";
150-
151-
expect(fs.realpathSync(demoPluginPackageJson)).toEqual(fs.realpathSync(srcPluginPackageJson));
152-
done();
153-
});
154-
155136
it('should prepare a working demo with passing tests', function (done) {
156137
var testsCommand = "cd " + constants.SEED_COPY_LOCATION + "/src && npm run test";
157138
testsCommand += testUtils.isAndroid() ? ".android" : ".ios";

seed-tests/tests.utils.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ exports.copySeedDir = function copySeedDir(seedLocation, copyLocation, callback)
5151
rimraf.sync(copyLocation);
5252

5353
ncp(seedLocation, copyLocation, {
54-
filter: function (fileName) {
55-
if (fileName.indexOf("seed-tests/" + constants.SEED_COPY_LOCATION) > -1 ||
56-
fileName.indexOf("demo/node_modules") > -1 ||
57-
fileName.indexOf("src/node_modules") > -1 ||
58-
fileName.indexOf("demo/platforms") > -1) {
54+
filter: function (fileName) {
55+
if ((fileName.indexOf("seed-tests") > -1 && fileName.indexOf(constants.SEED_COPY_LOCATION) > -1) ||
56+
(fileName.indexOf("demo") > -1 && fileName.indexOf("node_modules") > -1)||
57+
(fileName.indexOf("seed-tests") > -1 && fileName.indexOf("node_modules") > -1) ||
58+
(fileName.indexOf("src") > -1 && fileName.indexOf("node_modules") > -1) ||
59+
(fileName.indexOf("demo") > -1 && fileName.indexOf("platforms") > -1)) {
5960
return false;
6061
}
6162

src/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
},
1313
"scripts": {
1414
"tsc": "tsc -skipLibCheck",
15-
"build": "npm i && tsc",
15+
"build": "npm i && tsc",
1616
"postclone": "npm i && node scripts/postclone.js && cd ../demo && npm i && cd ../src && npm run plugin.link",
1717
"test.android": "npm i && npm run tsc && npm run tslint && cd ../demo && tns build android && tns test android --justlaunch",
1818
"test.ios": "npm i && npm run tsc && npm run tslint && cd ../demo && tns build ios && tns test ios --justlaunch",

0 commit comments

Comments
 (0)