Skip to content
This repository was archived by the owner on Feb 7, 2019. It is now read-only.

Commit c8392df

Browse files
authored
Merge pull request #199 from NativeScript/lini/add-development-workflow
docs: add development workflow and update scripts
2 parents e865951 + 1c3caaa commit c8392df

5 files changed

Lines changed: 88 additions & 13 deletions

File tree

DevelopmentWorkflow.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Development Workflow
2+
3+
<!-- TOC depthFrom:2 -->
4+
5+
- [Prerequisites](#prerequisites)
6+
- [Develop locally](#develop-locally)
7+
- [Build the plugin](#build-the-plugin)
8+
- [Testing the plugin](#testing-the-plugin)
9+
10+
<!-- /TOC -->
11+
12+
## Prerequisites
13+
14+
- Install your native toolchain and NativeScript as [described in the docs](https://docs.nativescript.org/start/quick-setup)
15+
16+
- Review [NativeScript plugins documentation](https://docs.nativescript.org/plugins/plugins) for more details on plugins development
17+
18+
## Develop locally
19+
20+
For local development we recommend using the npm commands provided in the plugin's package.json
21+
22+
To run and develop using TypeScript demo:
23+
24+
```bash
25+
# Go to demo directory
26+
cd push-plugin/demo
27+
# Build the plugin. This compiles all TypeScript files in the plugin directory, which is referenced in the demo's package.json
28+
npm run build.plugin
29+
# Install demo dependencies
30+
npm i
31+
# Run the demo for iOS or Android.
32+
tns run ios
33+
tns run android
34+
```
35+
36+
After all the changes are done make sure to test them in all the demo app.
37+
38+
Available npm commands from the plugin source directory:
39+
40+
- `build` - builds the plugin so it can be used in the demo app.
41+
- `tslint` - check plugin's TypeScript sources for linting errors.
42+
- `clean` - clean the demo and plugin directories.
43+
44+
## Build the plugin
45+
46+
In order to build the native projects in the `native-src` directory, you need to have Xcode for the ios native project and Java or Android Studio for the Gradle build of the Android native project. Note that this is not required if you don't plan to update the native code - prebuilt binaries for iOS and Android are included in the `src/platforms` directory.
47+
48+
## Testing the plugin
49+
50+
Before building and running the demo for the first time, you should change the application ID (set by default to `org.nativescript.ppTest`) in the `demo/package.json` file to match your application in Firebase and/or provision in iOS. For Android, you should also update the `demo/app/App_Resources/Android/app.gradle` file with the new application ID.
51+
52+
- Android - make sure you have added your `google-services.json` file to the `demo/app/App_Resources/Android` directory and that you have updated the `demo/app/main-view-model.ts` file with the sender ID of from your Firebase configuration. After the demo app is started the console will show the registration token of the device. For example:
53+
54+
w7ycrQS0sU:APA91bHCAxiFqonJb77cc785txYZ_0nrWe_sLRZm_nG32h4lhaJhZw-mquBh0rlmaoRVQBhnRsWiMTOWOcbCzuvGCOVKo7UAxog8JEufQO-nOJo3C2cMpPsT9RfiZVgaDc2tK9ezRUf9
55+
56+
To test push notifications for the device, you can use the following web request:
57+
58+
curl -X POST --header "Authorization: key=<YOUR_SERVER_KEY_HERE>" --Header "Content-Type: application/json" https://fcm.googleapis.com/fcm/send -d "{\"notification\":{\"title\": \"My title\", \"text\": \"My text\", \"badge\": \"1\", \"sound\": \"default\"}, \"data\":{\"foo\":\"bar\"}, \"priority\": \"High\", \"to\": \"<YOUR_DEVICE_TOKEN_HERE>\"}"
59+
60+
where <YOUR_SERVER_KEY_HERE> is the Server key from the Firebase Cloud Messaging Settings page and <YOUR_DEVICE_TOKEN_HERE> is the token you copied from the console.
61+
62+
- iOS - make sure that you are using the correct provisioning profile and app ID with enabled APNs. After the application is started the console will show the registration token for the device. For example:
63+
64+
7058206f33224ff472976d5a80a1c913b4133c5815cca829d2e4d92a82e1c3b6
65+
66+
To test push notifications for the device, you can use a third party app like [Pusher](https://github.com/noodlewerk/NWPusher). Open the app, load the correct push certificate and use the device ID from the console to send a message.
67+
68+
For details on plugins development workflow, read [NativeScript plugins documentation](https://docs.nativescript.org/plugins/building-plugins#step-2-set-up-a-development-workflow) covering that topic.

demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"license": "Apache-2.0",
1818
"dependencies": {
19-
"nativescript-push-notifications": "../publish/package/nativescript-push-notifications-1.1.0.tgz",
19+
"nativescript-push-notifications": "../src",
2020
"nativescript-theme-core": "^1.0.4",
2121
"tns-core-modules": "^3.3.0"
2222
},

src/package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,15 @@
2929
]
3030
},
3131
"scripts": {
32-
"tsc": "tsc -skipLibCheck",
33-
"build": "npm i --ignore-scripts && tsc && cd ../publish && ./pack.sh",
32+
"build": "npm i && tsc",
3433
"tslint": "cd .. && tslint \"**/*.ts\" --config tslint.json --exclude \"**/node_modules/**\"",
35-
"clean": "cd ../demo && rimraf hooks node_modules platforms && cd ../src && rimraf node_modules && npm run plugin.link",
36-
"ci.tslint": "npm i --ignore-scripts && tslint '**/*.ts' --config ../tslint.json --exclude '**/node_modules/**'",
34+
"clean": "cd ../demo && rimraf hooks node_modules platforms && cd ../src && rimraf node_modules",
35+
"ci.tslint": "npm i && tslint '**/*.ts' --config ../tslint.json --exclude '**/node_modules/**'",
3736
"postinstall": "node scripts/postinstall.js",
3837
"preuninstall": "node scripts/preuninstall.js"
3938
},
4039
"dependencies": {
41-
"nativescript-hook": "0.2.2"
40+
"nativescript-hook": "^0.2.0"
4241
},
4342
"devDependencies": {
4443
"rimraf": "^2.6.2",

src/scripts/postinstall.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
var path = require('path');
22
var utils = require('../hooks/utils');
3-
var projDir = path.resolve(__dirname, '../../../');
4-
require('nativescript-hook')(path.resolve(__dirname, '../')).postinstall();
3+
var hook = require('nativescript-hook')(path.resolve(__dirname, '../'));
4+
var projDir = hook.findProjectDir();
55

6-
utils.checkForGoogleServicesJson(projDir, path.join(projDir, 'app', 'App_Resources'));
7-
utils.addOnPluginInstall(path.join(projDir, 'platforms'));
6+
hook.postinstall();
7+
8+
if (projDir) {
9+
utils.checkForGoogleServicesJson(projDir, path.join(projDir, 'app', 'App_Resources'));
10+
utils.addOnPluginInstall(path.join(projDir, 'platforms'));
11+
}

src/scripts/preuninstall.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
var path = require('path');
22
var utils = require('../hooks/utils');
3-
var platformsDir = path.resolve(__dirname, '../../../platforms');
4-
require('nativescript-hook')(path.resolve(__dirname, '../')).preuninstall();
3+
var hook = require('nativescript-hook')(path.resolve(__dirname, '../'));
4+
var projDir = hook.findProjectDir();
55

6-
utils.removeIfPresent(platformsDir);
6+
hook.preuninstall();
7+
8+
if (projDir) {
9+
utils.removeIfPresent(path.join(projDir, 'platforms'));
10+
}

0 commit comments

Comments
 (0)