steamer-plugin-example

2.0.3 • Public • Published

steamer-plugin-example

开发插件

npm i -g steamerjs
 
steamer develop --plugin [plugin name xxx]
// 或
steamer develop -[plugin name xxx]
// 命令运行后,会下载 [steamer-plugin-example](https://github.com/steamerjs/steamer-plugin-example)
 
cd steamer-plugin-xxx
 
// 将你的插件链接至全局路径,就可以直接使用 `steamer example`
npm link
 
// 当你完成开发,可以 `unlink` 你的插件
npm unlink
 

steamer plugin 例子

  • 确认是否已安装steamer CLI工具,如果还未安装,请参考https://github.com/steamerjs/steamerjs

完成这个example plugin之后,可以这样使用这个插件:

steamer example -config.js
// 或
steamer example --config config.js

如何写一个 steamerjs 插件

  • 创建一个类,继承 steamer-plugin。此插件有许多辅助方法,请此往插件文件进行查询。
class ExamplePlugin extends SteamerPlugin {
    constructor(args) {
        super(args);
        this.argv = args;
        this.pluginName = 'steamer-plugin-example';
        this.description = 'steamer plugin example';
    }
 
    init() {
        
    }
 
    help() {
        
    }
}

当在终端输入插件命令时,命令的参数将被传入这个函数

更多相关参数的文档,请参考 yargs.

  • init 函数

为类创建 init 方法, 插件命令在启动时会自动调用此函数。

init() {
        
}
// 导出此类
module.exports = ExamplePlugin;
  • help 函数

为插件创建 help 方法

help() {
        
}

当使用命令 steamer [plugin name] -h 或者 steamer [plugin name] --help 时,会自动调用 help 函数,用于输出插件帮助文档。

  • 在package.json中指定入口
"main": "index.js"

Readme

Keywords

Package Sidebar

Install

npm i steamer-plugin-example

Weekly Downloads

4

Version

2.0.3

License

MIT

Unpacked Size

4.07 kB

Total Files

5

Last publish

Collaborators

  • lcxfs1991