-
Notifications
You must be signed in to change notification settings - Fork 1
/
activate_wrapper.py
65 lines (52 loc) · 2.08 KB
/
activate_wrapper.py
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
# Script to add pixel_wrapper functionality code to pixel.js
f = open('./source/js/plugins/pixel.js/source/pixel.js', 'r')
lines = f.readlines()
f.close()
import_flag = True
construct_flag = True
activate_flag = True
deactivate_flag = True
import_code = "import {PixelWrapper} from '../../pixel-wrapper';\n"
construct_code = "\t\tthis.pixelWrapper = null;\n"
activate_code = """\n\t\t// Activate wrapper
\t\tif (this.pixelWrapper === null)
\t\t\tthis.pixelWrapper = new PixelWrapper(this);
\t\tthis.pixelWrapper.activate();\n"""
deactivate_code = "\t\t// Deactivate wrapper\n\t\tthis.pixelWrapper.deactivate();\n\n"
if import_code in lines:
print("The wrapper code has already been added!")
raise SystemExit
f = open('./source/js/plugins/pixel.js/source/pixel.js', 'w')
for i in range(len(lines)):
if ('import {' in lines[i] and import_flag):
lines.insert(i, import_code)
import_flag = False
if ('constructor' in lines[i] and construct_flag):
lines.insert(i+2, construct_code)
construct_flag = False
if ('new Tutorial();' in lines[i] and activate_flag):
lines.insert(i+1, activate_code)
activate_flag = False
if ('deactivatePlugin ()' in lines[i] and deactivate_flag):
lines.insert(i+2, deactivate_code)
deactivate_Flag = False
# Write to file
for i in range(len(lines)):
f.write(lines[i])
f.close()
# Remove the index.html copying line from pixel.sh, which is incompatible with pixel_wrapper
f = open('./source/js/plugins/pixel.js/pixel.sh', 'r')
lines = f.readlines()
f.close()
f = open('./source/js/plugins/pixel.js/pixel.sh', 'w')
for i in range(len(lines)):
if ('scp ./index.html ../../../../' in lines[i]):
lines[i] = '# scp ./index.html ../../../../\n'
if ('echo "> gulp"' in lines[i]):
lines[i] = 'echo "> gulp develop:rodan"\n'
lines[i+1] = 'gulp develop:rodan\n'
if ('echo "> npm install -g gulp webpack"' in lines[i]):
lines[i] = 'echo "> npm install -g gulp@4.0.0 webpack"\n'
lines[i+1] = 'sudo npm install -g gulp@4.0.0 webpack\n'
f.write(lines[i])
f.close()