-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathsubstrate-module-new
More file actions
executable file
·68 lines (54 loc) · 1.4 KB
/
substrate-module-new
File metadata and controls
executable file
·68 lines (54 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env bash
COLOR_WHITE=$(tput setaf 7);
COLOR_MAGENTA=$(tput setaf 5);
FONT_BOLD=$(tput bold);
FONT_NORMAL=$(tput sgr0);
echo
echo -e "$COLOR_WHITE $FONT_BOLD Substrate Module Setup $FONT_NORMAL";
name=$1
if [[ "${name/* */}" == "" || "$name" == "-"* ]]
then
echo " Usage: substrate-module-new <NAME>"
echo
exit 1
fi
lname="$(echo $name | tr '[:upper:]' '[:lower:]')"
filename="${lname//[_ ]/-}.rs"
modname="${lname//[- ]/_}"
bold=$(tput bold)
yellow=$(tput setaf 3)
normal=$(tput sgr0)
if [[ -e runtime/src ]]; then
dir=runtime/src
elif [[ -e wasm/src && -e src ]]; then
dir=src
else
dir=.
fi
echo " ${bold}Creating module in ${dir}...${normal}"
pushd $dir >/dev/null
curl https://raw.githubusercontent.com/paritytech/substrate/v1.0/node-template/runtime/src/template.rs -sSf > $filename
git add $filename
echo " ${bold}Customising module...${normal}"
function replace {
find_this="$1"
shift
replace_with="$1"
shift
IFS=$'\n'
TEMP=$(mktemp -d "${TMPDIR:-/tmp/}.XXXXXXXXXXXX")
rmdir $TEMP
for item in $filename
do
sed "s/$find_this/$replace_with/g" "$item" > $TEMP
cat $TEMP > "$item"
done
rm -f $TEMP
}
replace "TemplateModule" "${name}"
echo
echo "${bold}SRML module created as ${yellow}$dir/${filename}${normal}${bold} and added to git.${normal}"
echo "Ensure that you include in your ${bold}${yellow}$dir/lib.rs${normal} the line:"
echo " mod ${modname};"
echo
popd >/dev/null