Skip to content

Commit

Permalink
refactor(): general cleanup (#1193)
Browse files Browse the repository at this point in the history
  • Loading branch information
ihadeed authored Mar 17, 2017
1 parent 18fe9c9 commit 5492239
Show file tree
Hide file tree
Showing 17 changed files with 57 additions and 1,699 deletions.
68 changes: 11 additions & 57 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ First, let's start by creating a new plugin wrapper from template.
// Make sure to capitalize the first letter, or use CamelCase if necessary.
gulp plugin:create -n PluginName
// add -m flag to get a minimal template to start with
gulp plugin:create -m -n PluginName
```


Expand All @@ -22,17 +25,18 @@ Let's take a look at the existing plugin wrapper for Geolocation to see what goe
plugin: 'cordova-plugin-geolocation',
pluginRef: 'navigator.geolocation'
})
@Injectable()
export class Geolocation {
@Cordova()
static getCurrentPosition(options?: GeolocationOptions): Promise<Geoposition> { return }
getCurrentPosition(options?: GeolocationOptions): Promise<Geoposition> { return; }
@Cordova({
callbackOrder: 'reverse',
observable: true,
clearFunction: 'clearWatch'
})
static watchPosition(options?: GeolocationOptions): Observable<Geoposition> { return }
watchPosition(options?: GeolocationOptions): Observable<Geoposition> { return; }
}
```

Expand All @@ -41,6 +45,7 @@ export class Geolocation {
First and foremost, we want to create a class representing our plugin, in this case Geolocation.

```
@Injectable()
class Geolocation {
}
Expand All @@ -57,6 +62,7 @@ For example, the `@Plugin` decorator adds information about the plugin to our Ge
plugin: 'cordova-plugin-geolocation',
pluginRef: 'navigator.geolocation'
})
@Injectable()
export class Geolocation {
}
Expand All @@ -74,7 +80,7 @@ Let's take a look at `getCurrentPosition` first.

```
@Cordova()
static getCurrentPosition(options?: GeolocationOptions): Promise<Geoposition> { return }
getCurrentPosition(options?: GeolocationOptions): Promise<Geoposition> { return }
```

It's just a stub. The `return` is only there to keep the TypeScript type-checker from complaining since we indicate that `getCurrentPosition` returns a `Promise<Geoposition>`.
Expand All @@ -91,7 +97,7 @@ Next, let's look at the `watchPosition` method.
observable: true,
clearFunction: 'clearWatch'
})
static watchPosition(options?: GeolocationOptions): Observable<Geoposition> { return }
watchPosition(options?: GeolocationOptions): Observable<Geoposition> { return }
```

The `@Cordova` decorator has a few more options now.
Expand All @@ -102,58 +108,6 @@ The `@Cordova` decorator has a few more options now.

`clearFunction` is used in conjunction with the `observable` option and indicates the function to be called when the Observable is disposed.

### Updating index.ts

For new plugins, you will need to update `/src/index.ts` to properly export your plugin and make it available for use.

1. Import the plugin class into `index.ts`:

`import {PluginClassName} from ./plugins/filenameForPlugin`

No need to put the `.ts` extension on the filename.

2. Add the plugin class name to the list in the `export` object:

```
export {
ActionSheet,
AdMob,
AndroidFingerprintAuth,
YourPluginClassName,
...
}
```

3. Add the plugin class name to the `window['IonicNative']` object:

```
window['IonicNative'] = {
ActionSheet: ActionSheet,
AdMob: AdMob,
AndroidFingerprintAuth: AndroidFingerprintAuth,
YourPluginClassName: YourPluginClassName,
...
```

4. If your plugin exports any other objects outside of the plugin class, add an export statement for the file:

`export * from './plugins/filenameForPlugin';`

No need to put the `.ts` extension on the filename.

For example, `googlemaps.ts` exports a const outside of the plugin's main `GoogleMap` class:

```
export const GoogleMapsAnimation = {
BOUNCE: 'BOUNCE',
DROP: 'DROP'
};
```

To properly export `GoogleMapsAnimation`, `index.ts` is updated with:

`export * from './plugins/googlemaps';`

### Testing your changes

You need to run `npm run build` in the `ionic-native` project, this will create a `dist` directory. Then, you must go to your ionic application folder and replace your current `node_modules/ionic-native/dist/` with the newly generated one.
Expand All @@ -164,7 +118,7 @@ You need to run `npm run lint` to analyze the code and ensure it's consistency w

### 'Wrapping' Up

That's it! The only thing left to do is rigorously document the plugin and it's usage. Take a look at some of the other plugins for good documentation styles.
That's it! The only thing left to do is rigorously document the plugin and it's usage. Take a look at some of the other plugins for good documentation styles.

## Commit Message Format

Expand Down
3 changes: 1 addition & 2 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
machine:
node:
version: 4.1.0
version: 7.10.0
ruby:
version: 2.1.2

Expand All @@ -17,7 +17,6 @@ dependencies:

test:
override:
- npm test
- npm run build

deployment:
Expand Down
28 changes: 13 additions & 15 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var gulp = require('gulp');
var minimist = require('minimist');
var uglify = require('gulp-uglify');
var rename = require("gulp-rename");
var tslint = require('gulp-tslint');
var decamelize = require('decamelize');
Expand All @@ -17,16 +16,6 @@ var flags = minimist(process.argv.slice(2), flagConfig);
/* Docs tasks */
require('./scripts/docs/gulp-tasks')(gulp, flags);


gulp.task("minify:dist", function(){
gulp.src('./dist/ionic.native.js')
.pipe(uglify())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('./dist'));
});

gulp.task('lint', function() {
gulp.src('src/**/*.ts')
.pipe(tslint({
Expand All @@ -38,12 +27,21 @@ gulp.task('lint', function() {

gulp.task('plugin:create', function(){
if(flags.n && flags.n !== ''){
var src = flags.m?'./scripts/templates/wrap-min.tmpl':'./scripts/templates/wrap.tmpl';

const src = flags.m?'./scripts/templates/wrap-min.tmpl':'./scripts/templates/wrap.tmpl',
pluginName = flags.n,
pluginPackageName = decamelize(pluginName, '-'),
pluginNameSpaced = pluginName.replace(/(?!^)([A-Z])/g, ' $1');

return gulp.src(src)
.pipe(replace('PluginName', flags.n))
.pipe(rename(decamelize(flags.n, '-') + '.ts'))
.pipe(gulp.dest('./src/plugins/'));
.pipe(replace('PluginName', pluginName))
.pipe(replace('Plugin Name', pluginNameSpaced))
.pipe(rename('index.ts'))
.pipe(gulp.dest('./src/@ionic-native/plugins/' + pluginPackageName));

} else {

console.log("Usage is: gulp plugin:create -n PluginName");

}
});
61 changes: 0 additions & 61 deletions karma.conf.ts

This file was deleted.

73 changes: 20 additions & 53 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,39 @@
"name": "ionic-native",
"version": "3.1.0-rc.5",
"description": "Native plugin wrappers for Cordova and Ionic with TypeScript, ES6+, Promise and Observable support",
"main": "dist/es5/index.js",
"module": "dist/esm/index.js",
"typings": "dist/es5/index.d.ts",
"files": [
"dist"
],
"license": "MIT",
"devDependencies": {
"@angular/compiler": "2.4.8",
"@angular/compiler-cli": "2.4.8",
"@angular/core": "2.4.8",
"browserify": "^13.3.0",
"canonical-path": "0.0.2",
"child-process-promise": "^2.2.0",
"conventional-changelog-cli": "^1.2.0",
"conventional-github-releaser": "^1.1.3",
"cpr": "^2.0.2",
"cz-conventional-changelog": "^1.2.0",
"decamelize": "^1.2.0",
"dgeni": "^0.4.7",
"dgeni-packages": "^0.16.10",
"es6-shim": "~0.35.2",
"fs-extra": "^2.0.0",
"fs-extra-promise": "^0.4.1",
"glob": "^7.1.1",
"gulp": "^3.9.1",
"gulp-rename": "^1.2.2",
"gulp-replace": "^0.5.4",
"gulp-tslint": "^6.1.2",
"gulp-uglify": "^2.0.0",
"jasmine-core": "~2.5.2",
"karma": "~1.3.0",
"karma-browserify": "~5.1.0",
"karma-jasmine": "~1.1.0",
"karma-phantomjs-launcher": "~1.0.2",
"child-process-promise": "2.2.0",
"conventional-changelog-cli": "1.2.0",
"cpr": "2.0.2",
"cz-conventional-changelog": "1.2.0",
"decamelize": "1.2.0",
"dgeni": "0.4.7",
"dgeni-packages": "0.16.10",
"fs-extra": "2.0.0",
"fs-extra-promise": "0.4.1",
"gulp": "3.9.1",
"gulp-rename": "1.2.2",
"gulp-replace": "0.5.4",
"gulp-tslint": "6.1.2",
"lodash": "4.17.4",
"minimist": "^1.1.3",
"minimist": "1.1.3",
"node-html-encoder": "0.0.2",
"q": "1.4.1",
"queue": "^4.2.1",
"rimraf": "^2.5.4",
"queue": "4.2.1",
"rimraf": "2.5.4",
"rxjs": "5.0.1",
"semver": "^5.3.0",
"tsify": "~3.0.0",
"tslint": "^3.15.1",
"semver": "5.3.0",
"tslint": "3.15.1",
"tslint-ionic-rules": "0.0.7",
"typescript": "2.0.09",
"watchify": "~3.7.0",
"zone.js": "0.7.2"
},
"scripts": {
"test": "karma start",
"test:watch": "npm test -- --watch",
"start": "npm run test:watch",
"lint": "gulp lint",
"build": "npm run clean && npm run lint && npm run build:core && npm run build:modules",
Expand All @@ -62,25 +43,11 @@
"clean": "rimraf dist",
"shipit": "npm run build && gulp readmes && npm run npmpub",
"npmpub": "node scripts/build/publish.js",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
"plugin:create": "gulp plugin:create"
},
"repository": {
"type": "git",
"url": "https://github.com/driftyco/ionic-native.git"
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/driftyco/ionic-native/issues"
},
"homepage": "https://github.com/driftyco/ionic-native",
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"dependencies": {
"dgeni": "^0.4.7",
"dgeni-packages": "^0.16.10"
}
}
26 changes: 0 additions & 26 deletions scripts/bower.json

This file was deleted.

Loading

0 comments on commit 5492239

Please sign in to comment.