命令插件开发
steamer-plugin-example
开发插件
npm i -g steamerjssteamer develop --plugin [plugin name xxx]// 或steamer develop -p [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 -c 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"
