-
Notifications
You must be signed in to change notification settings - Fork 649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create plugin script #1302
Create plugin script #1302
Conversation
Nice! |
It would be nice to have the script look up used database space ID from other plugins and automatically select a new one. |
I am not very good at bash but created a function in script to detect biggest space_id and sum 1 to it. This number will be used in the template being created. This is at 64505a8 |
libraries/plugins/make_new_plugin.sh
Outdated
for i in * ; do | ||
if [ -d "$i" ] && [ "$i" != "CMakeFiles" ]; then | ||
cd "$i/include/graphene/$i" | ||
result=$(grep -rnw '.' -e '#define [[:alnum:]]*_SPACE_ID') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should use [[:space]]*
after #define
instead of single space
libraries/plugins/make_new_plugin.sh
Outdated
@@ -16,6 +36,10 @@ mv $pluginName/include/graphene/template_plugin $pluginName/include/graphene/$pl | |||
for file in `find $pluginName -type f -name '*template_plugin*'`; do mv $file `sed s/template_plugin/$pluginName/g <<< $file`; done; | |||
echo Renaming in files... | |||
find $pluginName -type f -exec sed -i "s/template_plugin/$pluginName/g" {} \; | |||
echo Assigning next available SPACE_ID... | |||
next_space_id | |||
find $pluginName -type f -exec sed -i "s/0000/$?/g" {} \; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better use something that's recognizable as a placeholder, like @SPACE_ID@
, not a valid integer number.
libraries/plugins/make_new_plugin.sh
Outdated
exit 1 | ||
fi | ||
|
||
pluginName=$1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put double quotes around all strings where variables are expanded.
libraries/plugins/make_new_plugin.sh
Outdated
|
||
echo Copying template... | ||
echo "Copying template..." | ||
cp -r template_plugin $pluginName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please quote $pluginName here and in the following lines.
libraries/plugins/make_new_plugin.sh
Outdated
|
||
echo "Renaming files/directories..." | ||
mv "$pluginName/include/graphene/template_plugin" "$pluginName/include/graphene/$pluginName" | ||
for file in `find "$pluginName" -type f -name '*template_plugin*'`; do mv $file `sed s/template_plugin/"$pluginName"/g <<< $file`; done; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please quote $file
libraries/plugins/make_new_plugin.sh
Outdated
mv "$pluginName/include/graphene/template_plugin" "$pluginName/include/graphene/$pluginName" | ||
for file in `find "$pluginName" -type f -name '*template_plugin*'`; do mv $file `sed s/template_plugin/"$pluginName"/g <<< $file`; done; | ||
echo "Renaming in files..." | ||
find $pluginName -type f -exec sed -i "s/template_plugin/$pluginName/g" {} \; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please quote $pluginName
libraries/plugins/make_new_plugin.sh
Outdated
find $pluginName -type f -exec sed -i "s/template_plugin/$pluginName/g" {} \; | ||
echo "Assigning next available SPACE_ID..." | ||
next_space_id | ||
find $pluginName -type f -exec sed -i "s/@SPACE_ID@/$?/g" {} \; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please quote $pluginName
Excellent, tested successfully. Some of the "next steps" could also be automated, but I think it might be better to leave these as manual steps. |
thanks @pmconrad :) |
When working with plugins the developer find himself doing the same renaming work too many times.
I found a script in eos that actually do the job of automating plugin creation: https://github.com/EOSIO/eos/blob/master/plugins/eosio-make_new_plugin.sh
So i copied over and added some further instructions to get up and running in bitshares after the files are all in place.
The template is a plugin with implementation class, most of our plugins are like that even if there are others that don't follow this pattern i think this is the way most of them can be built.
It haves some minimal functionality on how to add an argument and an onBlock function that will execute every block.
For further examples the developer will check other plugins, unfortunately we have no plugin that exposes api calls in the plugin itself. This is only visible on @xeroc hello plugin:
https://github.com/bitshares/bitshares-core/tree/hello_plugin/libraries/plugins
I think we should encourage the use of the api in the plugin itself rather than adding to
api.cpp
but i didn't added this to template as most plugins will not want it, tried to keep it simple.Sample script output: