chore(): fix plugin create command and templtes

This commit is contained in:
Ibby Hadeed 2017-03-25 21:48:45 -04:00
parent 1eebea9df5
commit c52bb832b4
3 changed files with 28 additions and 16 deletions

View File

@ -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");

View File

@ -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 {
}

View File

@ -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