-
Notifications
You must be signed in to change notification settings - Fork 1
/
install-extension.sh
executable file
·70 lines (59 loc) · 3.01 KB
/
install-extension.sh
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
69
70
#!/bin/bash
##############################################################
# Script Name : Install Extension
# Description : Installs the Poppy Extension to Scratch files
##############################################################
ITALIC="\033[3m"
GREEN="\033[92m"
YELLOW="\033[93m"
CLEAR="\033[0m"
installation_folder=".."
##############################################################
# Function add_require()
# Adds a require line to a js file, if line does not already exist.
# It first scans the 'file' for 'search' arg. If 'search' is not found,
# it replaces 'where' arg by 'replace' arg.
#
# ARGUMENTS:
# $1: search = line(s) to add, to check if it already exists
# $2: where = where to put it ?
# $3: replace = where "+" search
# $4: file
#
# OUTPUTS:
# Some echos of the progress of the script
##############################################################
add_require () {
echo -e "Adding a require to ${ITALIC}$4${CLEAR}"
if grep -q "$1" "$4"
then
# code if found
echo -e "${GREEN}Require already satisfied!${CLEAR}"
else
# code if not found
echo -e "${YELLOW}Require not satisfied!${CLEAR}"
sed -i "s/$2/$3/" "$4"
echo -e "${GREEN}Require has been added!${CLEAR}"
fi
}
find="poppy: () => require('..\/extensions\/scratch3_poppy'),"
where="boost: () => require('..\/extensions\/scratch3_boost'),"
replace="$where\n $find"
file="$installation_folder/scratch-vm/src/extension-support/extension-manager.js"
add_require "$find" "$where" "$replace" "$file"
find="import poppyInsetIconURL from '.\/poppy\/poppy-small.png';"
where="import boostConnectionTipIconURL from '.\/boost\/boost-button-illustration.svg';"
replace="$where\n\nimport poppyIconURL from '.\/poppy\/poppy.png';\n$find"
file="$installation_folder/scratch-gui/src/lib/libraries/extensions/index.jsx"
add_require "$find" "$where" "$replace" "$file"
find='extensionId: "poppy",'
where="export default \["
replace='export default [\n {\n name: "Poppy",\n extensionId: "poppy",\n collaborator: "Poppy-Station",\n iconURL: poppyIconURL,\n insetIconURL: poppyInsetIconURL,\n description: (\n <FormattedMessage\n defaultMessage="Control your Poppy robot"\n description="Poppy controller extension"\n id="gui.extension.poppy.description"\n \/>\n ),\n featured: true,\n disabled: false,\n internetConnectionRequired: true,\n bluetoothRequired: false,\n },'
file="$installation_folder/scratch-gui/src/lib/libraries/extensions/index.jsx"
add_require "$find" "$where" "$replace" "$file"
echo -e "\nCopying Poppy extension code to ${ITALIC}scratch-vm${CLEAR}... \c"
cp -r ./scratch_vm_files/scratch3_poppy $installation_folder/scratch-vm/src/extensions
echo -e "${GREEN}DONE!${CLEAR}"
echo -e "Copying Poppy images to ${ITALIC}scratch-gui${CLEAR}... \c"
cp -r ./scratch_gui_files/poppy $installation_folder/scratch-gui/src/lib/libraries/extensions
echo -e "${GREEN}DONE!${CLEAR}"