-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(devtool): support feflow-plugin dev
- Loading branch information
Showing
6 changed files
with
137 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/feflow-plugin-devtool/templates/plugin-template/LICENSE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
20 changes: 20 additions & 0 deletions
20
packages/feflow-plugin-devtool/templates/plugin-template/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# feflow-plugin-example | ||
|
||
This is an official demo for feflow plugin. It's a simple calculator. | ||
|
||
For example, if you install the plugin, you can input command in terminal like this: | ||
|
||
```sh | ||
feflow add 1 2 3 | ||
# output: 6 | ||
feflow minus 1 2 3 | ||
# output: -4 | ||
feflow multiply 2 2 4 | ||
# output: 16 | ||
feflow divide 2 2 4 | ||
# output: 0.25 | ||
``` | ||
|
||
## License | ||
|
||
[MIT](https://tldrlegal.com/license/mit-license) |
37 changes: 37 additions & 0 deletions
37
packages/feflow-plugin-devtool/templates/plugin-template/lib/calculate.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module.exports = function add(feflow) { | ||
// 原函数逻辑 | ||
return { | ||
add(args) { | ||
const sum = args.reduce((sum, item) => { | ||
return sum + item; | ||
}, 0); | ||
|
||
// console.log(sum) | ||
feflow.logger.info(sum); | ||
return sum; | ||
}, | ||
multiply(args) { | ||
const product = args.reduce((product, item) => { | ||
return product * item; | ||
}, 1); | ||
|
||
// console.log(sum) | ||
feflow.logger.info(product); | ||
return product; | ||
}, | ||
// 减法看成加法计算 | ||
minus(args) { | ||
const _args = args.map((arg, index) => index ? -arg : arg); | ||
return this.add(_args); | ||
}, | ||
// 除法看成乘法来算 | ||
divide(args) { | ||
// 除数不为零 | ||
if (args.slice(1).indexOf(0) > -1) { | ||
return feflow.logger.error('除数不能为零'); | ||
} | ||
const _args = args.map((arg, index) => index ? 1 / arg : arg); | ||
return this.multiply(_args); | ||
} | ||
}; | ||
}; |
22 changes: 22 additions & 0 deletions
22
packages/feflow-plugin-devtool/templates/plugin-template/lib/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const calculate = require('./calculate'); | ||
|
||
module.exports = (context) => { | ||
const calculator = calculate(context); | ||
const { args } = context; | ||
|
||
// 注册一个 add 命令 | ||
context.commander.register('add', '加法运算器', () => { | ||
// args 是 add 后面的参数,已被 minimist 库解析 | ||
// 例如 `feflow add 1 2 3`,args 就是 { _: [1, 2, 3] }, | ||
// 再比如 `feflow add -x 1 -y 2 --z-value 3 4 5 6`,args 就是 { _: [ 4, 5, 6 ], x: 1, y: 2, 'z-value': 3 } | ||
// 调用主要的逻辑 | ||
return calculator.add(args._); | ||
}); | ||
|
||
// 注册乘、除、减三个命令 | ||
context.commander.register('multiply', '乘法运算器', () => calculator.multiply(args._)); | ||
context.commander.register('minus', '减法运算器', () => calculator.minus(args._)); | ||
context.commander.register('divide', '除法运算器', () => calculator.divide(args._)); | ||
}; | ||
|
||
|
14 changes: 14 additions & 0 deletions
14
packages/feflow-plugin-devtool/templates/plugin-template/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "@feflow/feflow-plugin-example", | ||
"version": "1.0.0", | ||
"description": "a simple calculator", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [ | ||
"feflow-plugin" | ||
], | ||
"author": "", | ||
"license": "ISC" | ||
} |