|
| 1 | +# Develop a NativeScript plugin now (w/ TypeScript) |
| 2 | + |
| 3 | +## Getting started |
| 4 | + |
| 5 | +1. `git clone https://github.com/NathanWalker/nativescript-plugin-seed.git myplugin` |
| 6 | +2. `npm install -g typescript` |
| 7 | +3. `cd myplugin` |
| 8 | +4. `npm run postclone` |
| 9 | +5. `npm run setup` |
| 10 | +6. Get to work. |
| 11 | + |
| 12 | +This seed expands on several things [presented here](http://developer.telerik.com/featured/creating-nativescript-plugins-in-typescript/). |
| 13 | + |
| 14 | +## Usage |
| 15 | + |
| 16 | +The seed is prepared to allow you to test and try out your plugin via the `demo` folder. |
| 17 | +Additionally it provides a proper `.gitignore` to keep GitHub tidy as well as `.npmignore` to ensure everyone is happy when you publish your plugin via npm. |
| 18 | + |
| 19 | +### Linking to CocoaPod or Android Arsenal plugins |
| 20 | + |
| 21 | +You will want to create these folders and files in the root: |
| 22 | + |
| 23 | +``` |
| 24 | +platforms -- |
| 25 | + ios -- |
| 26 | + Podfile |
| 27 | + android -- |
| 28 | + include.gradle |
| 29 | +``` |
| 30 | + |
| 31 | +Doing so will open up those native apis to your plugin :) |
| 32 | + |
| 33 | +Take a look at these existing plugins for how that can be done very simply: |
| 34 | + |
| 35 | +* [nativescript-cardview](https://github.com/bradmartin/nativescript-cardview/tree/master/platforms) |
| 36 | +* [nativescript-floatingactionbutton](https://github.com/bradmartin/nativescript-floatingactionbutton/tree/master/platforms) |
| 37 | + |
| 38 | +### Typical development workflow: |
| 39 | + |
| 40 | +1. Make changes to plugin files |
| 41 | +2. Make changes in `demo` that would test those changes out |
| 42 | +3. `npm run demo.ios` or `npm run demo.android` **(must be run from the root directory)** |
| 43 | + |
| 44 | +Those `demo` tasks are just general helpers. You may want to have more granular control on the device and/or emulator you want to run. For that, you can just run things the manual way: |
| 45 | + |
| 46 | +``` |
| 47 | +cd demo |
| 48 | +
|
| 49 | +// when developing, to ensure the latest code is built into the demo, it's a guarantee to remove the plugin and add it back |
| 50 | +tns plugin remove nativescript-https |
| 51 | +tns plugin add .. |
| 52 | +
|
| 53 | +// manual platform adds |
| 54 | +tns platform add ios |
| 55 | +// and/or |
| 56 | +tns platform add android |
| 57 | +``` |
| 58 | + |
| 59 | +Then use any of the available options from the `tns` command line: |
| 60 | + |
| 61 | +* [Emulate your project](https://github.com/NativeScript/nativescript-cli#emulate-your-project) |
| 62 | +* [Run your project](https://github.com/NativeScript/nativescript-cli#run-your-project) |
| 63 | +* [Full list of commands](https://github.com/NativeScript/nativescript-cli#the-commands) |
| 64 | + |
| 65 | +## Unittesting |
| 66 | +This plugin automatically adds Jasmine-based unittest support to your plugin. |
| 67 | +Open `demo/app/tests/tests.js` and adjust its contents. |
| 68 | + |
| 69 | +You can read more about this topic [here](https://docs.nativescript.org/tooling/testing). |
| 70 | + |
| 71 | +Once you're ready to test your plugin's API execute one of these commands in the plugin root: |
| 72 | + |
| 73 | +``` |
| 74 | +npm run test.ios |
| 75 | +npm run test.android |
| 76 | +``` |
| 77 | + |
| 78 | +## Publish |
| 79 | + |
| 80 | +When you have everything ready to publish: |
| 81 | + |
| 82 | +* Bump the version number in `package.json` |
| 83 | +* `npm run build` - **very important** - ensure the latest is built **before** you publish |
| 84 | +* `npm publish` |
| 85 | + |
| 86 | +## Contributing - Want to make the seed better? |
| 87 | + |
| 88 | +Or at least help keep it up to date with NativeScript releases, which would be excellent. |
| 89 | + |
| 90 | +``` |
| 91 | +npm install -g typescript // if you don't already have it |
| 92 | +git clone https://github.com/NathanWalker/nativescript-plugin-seed |
| 93 | +cd nativescript-plugin-seed |
| 94 | +
|
| 95 | +// Improve! |
| 96 | +``` |
0 commit comments