diff --git a/gulpfile.js b/gulpfile.js index 82bb2d2be..c2e6c1168 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -5,7 +5,8 @@ const gulp = require('gulp'), rename = require("gulp-rename"), tslint = require('gulp-tslint'), decamelize = require('decamelize'), - replace = require('gulp-replace'); + replace = require('gulp-replace'), + _ = require('lodash'); const flagConfig = { string: ['port', 'version', 'ngVersion', 'animations'], @@ -31,16 +32,16 @@ gulp.task('lint', () => { gulp.task('plugin:create', () => { if (flags.n && flags.n !== ''){ - const 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', pluginName)) - .pipe(replace('Plugin Name', pluginNameSpaced)) + .pipe(replace('$PluginName', pluginName)) + .pipe(replace('$Plugin_Name', pluginNameSpaced)) + .pipe(replace('$pluginName', _.lowerFirst(pluginName))) .pipe(rename('index.ts')) - .pipe(gulp.dest('./src/@ionic-native/plugins/' + pluginPackageName)); + .pipe(gulp.dest('./src/@ionic-native/plugins/' + _.kebabCase(pluginName))); } else { console.log("Usage is: gulp plugin:create -n PluginName"); diff --git a/scripts/templates/wrap-min.tmpl b/scripts/templates/wrap-min.tmpl index 363d41e4d..23295c8b8 100644 --- a/scripts/templates/wrap-min.tmpl +++ b/scripts/templates/wrap-min.tmpl @@ -7,18 +7,23 @@ import { Injectable } from '@angular/core'; * * @usage * ``` - * import { PluginName } from 'ionic-native'; + * import { $PluginName } from 'ionic-native'; + * + * + * constructor(private $pluginName: $PluginName) { } + * + * ... * * * ``` */ @Plugin({ - pluginName: 'PluginName', + pluginName: '$PluginName', plugin: '', pluginRef: '', repo: '' }) @Injectable() -export class PluginName { +export class $PluginName { } diff --git a/scripts/templates/wrap.tmpl b/scripts/templates/wrap.tmpl index a9ce28efd..8c13ef559 100644 --- a/scripts/templates/wrap.tmpl +++ b/scripts/templates/wrap.tmpl @@ -15,29 +15,35 @@ import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Observable'; /** - * @name Plugin Name + * @name $Plugin_Name * @description * This plugin does something * * @usage * ``` - * import { PluginName } from 'ionic-native'; + * import { $PluginName } from 'ionic-native'; * - * PluginName.functionName('Hello', 123) - * .then((something: any) => doSomething(something)) - * .catch((error: any) => console.log(error)); + * + * constructor(private $pluginName: $PluginName) { } + * + * ... + * + * + * this.$pluginName.functionName('Hello', 123) + * .then((res: any) => console.log(res)) + * .catch((error: any) => console.error(error)); * * ``` */ @Plugin({ - pluginName: 'PluginName', + pluginName: '$PluginName', plugin: '', // npm package name, example: cordova-plugin-camera pluginRef: '', // the variable reference to call the plugin, example: navigator.geolocation repo: '', // the github repository URL for the plugin install: '' // OPTIONAL install command, in case the plugin requires variables }) @Injectable() -export class PluginName { +export class $PluginName { /** * This function does something