项目作者: qtpalmtop

项目描述 :
思路脚手架第一版, 可生成类@ionic-native的api库
高级语言: JavaScript
项目地址: git://github.com/qtpalmtop/ths-cli.git
创建时间: 2020-06-02T06:05:04Z
项目社区:https://github.com/qtpalmtop/ths-cli

开源协议:

下载


ths-cli

思路脚手架第一版, 目前只有create-ionic-native命令,可以创建@ionic-native插件供angular项目使用

  1. Usage: ths-cli <command> [项目名称]
  2. Options:
  3. -V, --version output the version number
  4. -h, --help display help for command
  5. Commands:
  6. create-ionic-native 创建ionic-native插件
  7. help [command] display help for command

安装

  1. npm install ths-cli2 -g

使用

  1. ths-cli create-ionic-native ths-native-toast

create-ionic-native 表示创建ionic-native插件指令

ths-native-toast 表示想要生成的插件id

演示

  1. ths-cli create-ionic-native ths-native-toast
  1. > 正在下载项目模板,源地址:git@github.com:qtpalmtop/templates-ionic-native.git#master
  2. > 插件的名称 (ThsPlugin): ThsToast
  3. > 插件的id (ths-native-plugin): ths-native-toast
  4. > 插件的版本号 (1.0.0): 1.0.0
  5. > 对应的cordova插件的id (cordova-plugin-ths-pluginName): cordova-plugin-ths-toast
  6. > 插件的简介 (A plugin named ThsPlugin): show toast
  7. > 插件的git地址 (https://github.com/apache/cordova-plugin-ths-pluginName): https://github.com/qtpalmtop/cordova-plugin-ths-toast
  8. 正在初始化项目模板:ths-native-toast/ths-native-toast
  9. 创建成功:)

之后当前目录下将会出现ths-native-toast插件

  1. cd ths-native-toast
  2. npm publish

随后在angular项目中即可通过npm install ths-native-toast, 并在app.module.ts中导入插件

  1. // app.mocule.ts
  2. import { ThsToast } from 'ths-native-toast/ngx';
  3. @NgModule({
  4. ...,
  5. providers: [
  6. ...,
  7. ThsToast
  8. ]
  9. })

然后在使用的模块中导入ths-native-toast插件就能直接调用起cordova插件功能,注意导入时需要加‘/ngx’,ionic4以下项目版本才不用

  1. // app.component.ts
  2. import { ThsToast } from 'ths-native-toast/ngx';
  3. export class AppComponent {
  4. constructor(
  5. private thsToast: ThsToast
  6. ) {
  7. this.thsToast.show();
  8. }
  9. }

注意:安装ionic-native插件之前需要先执行指令安装cordova插件

  1. cordova plugin add cordova-plugin-ths-toast
  2. ionic cordova plugin add cordova-plugin-ths-toast

此处的Cordova 插件名称需和脚手架输入的cordova_plugin_id相同

  1. > 对应的cordova插件的id (cordova-plugin-ths-pluginName): cordova-plugin-ths-toast