-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpub.py
280 lines (225 loc) · 9.15 KB
/
pub.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
import json
import os
import subprocess
import time
class ParticleBase:
def update_pubspec_dependency(self):
with open(self.package_path, 'r') as file:
data = json.load(file)
dependencies = data.get('dependencies')
if self.beta_mode:
if "@particle-network/rn-base" in dependencies or "rn-base-beta" in dependencies:
if("@particle-network/rn-base" in dependencies):
data['dependencies'].pop('@particle-network/rn-base')
if "rn-base-beta" in dependencies:
if data['dependencies']['rn-base-beta'] != "file:..":
data['dependencies']['rn-base-beta'] = self.version
else:
data['dependencies']['rn-base-beta'] = self.version
if "@particle-network/rn-connect" in dependencies or "rn-connect-beta" in dependencies:
if "@particle-network/rn-connect" in dependencies:
data['dependencies'].pop('@particle-network/rn-connect')
if "@particle-network/rn-connect-beta" in dependencies:
if (data['dependencies']['rn-connect-beta'] != "file:.."):
data['dependencies']['rn-connect-beta'] = self.version
else:
data['dependencies']['rn-connect-beta'] = self.version
if "@particle-network/rn-wallet" in dependencies or "rn-wallet-beta" in dependencies:
if "@particle-network/rn-wallet" in dependencies:
data['dependencies'].pop('@particle-network/rn-wallet')
if "@particle-network/rn-wallet-beta" in dependencies:
if data['dependencies']['rn-wallet-beta'] != "file:..":
data['dependencies']['rn-wallet-beta'] = self.version
else:
data['dependencies']['rn-wallet-beta'] = self.version
if "@particle-network/rn-auth-core" in dependencies or "rn-auth-core-beta" in dependencies:
if "@particle-network/rn-auth-core" in dependencies:
data['dependencies'].pop('@particle-network/rn-auth-core')
if "@particle-network/rn-auth-core-beta" in dependencies:
if data['dependencies']['rn-auth-core-beta'] != "file:..":
data['dependencies']['rn-auth-core-beta'] = self.version
else:
data['dependencies']['rn-auth-core-beta'] = self.version
if "@particle-network/rn-aa" in dependencies or "rn-aa-beta" in dependencies:
if "@particle-network/rn-aa" in dependencies:
data['dependencies'].pop('@particle-network/rn-aa')
if "@particle-network/rn-aa-beta" in dependencies:
if data['dependencies']['rn-aa-beta'] != "file:..":
data['dependencies']['rn-aa-beta'] = self.version
else:
data['dependencies']['rn-aa-beta'] = self.version
else:
if "rn-base-beta" in dependencies or "@particle-network/rn-base" in dependencies:
if "rn-base-beta" in dependencies:
data['dependencies'].pop('rn-base-beta')
if "@particle-network/rn-base" in dependencies:
if data['dependencies']['@particle-network/rn-base'] != "file:..":
data['dependencies']['@particle-network/rn-base'] = self.version
else:
data['dependencies']['@particle-network/rn-base'] = self.version
if "rn-connect-beta" in dependencies or "@particle-network/rn-connect" in dependencies:
if "rn-connect-beta" in dependencies:
data['dependencies'].pop('rn-connect-beta')
if "@particle-network/rn-connect" in dependencies:
if data['dependencies']['@particle-network/rn-connect'] != "file:..":
data['dependencies']['@particle-network/rn-connect'] = self.version
else:
data['dependencies']['@particle-network/rn-connect'] = self.version
if "rn-wallet-beta" in dependencies or "@particle-network/rn-wallet" in dependencies:
if "rn-wallet-beta" in dependencies:
data['dependencies'].pop('rn-wallet-beta')
if "@particle-network/rn-wallet" in dependencies:
if data['dependencies']['@particle-network/rn-wallet'] != "file:..":
data['dependencies']['@particle-network/rn-wallet'] = self.version
else:
data['dependencies']['@particle-network/rn-wallet'] = self.version
if "rn-auth-core-beta" in dependencies or "@particle-network/rn-auth-core" in dependencies:
if "rn-auth-core-beta" in dependencies:
data['dependencies'].pop('rn-auth-core-beta')
if "@particle-network/rn-auth-core" in dependencies:
if data['dependencies']['@particle-network/rn-auth-core'] != "file:..":
data['dependencies']['@particle-network/rn-auth-core'] = self.version
else:
data['dependencies']['@particle-network/rn-auth-core'] = self.version
if "rn-aa-beta" in dependencies or "@particle-network/rn-aa" in dependencies:
if "rn-aa-beta" in dependencies:
data['dependencies'].pop('rn-aa-beta')
if "@particle-network/rn-aa" in dependencies:
if data['dependencies']['@particle-network/rn-aa'] != "file:..":
data['dependencies']['@particle-network/rn-aa'] = self.version
else:
data['dependencies']['@particle-network/rn-aa'] = self.version
with open(self.package_path, 'w') as file:
json.dump(data, file, indent=2)
def __init__(self, version):
self.version = version
self.package_path = 'package.json'
def replace_name_version(self):
key_version = "version"
value_version = self.version
key_name = "name"
if not self.beta_mode:
value_name = self.production_name
else:
value_name = self.beta_name
print(value_name)
with open(self.package_path, 'r') as file:
data = json.load(file)
if key_version in data:
data[key_version] = value_version
else:
print(f"Key {key_version} not found in file {self.package_path}")
if key_name in data:
data[key_name] = value_name
else:
print(f"Key {key_name} not found in file {self.package_path}")
with open(self.package_path, 'w') as file:
json.dump(data, file, indent=2)
def rn_publish_dry_run(self):
subprocess.run(['npm', 'publish', '--dry-run'])
pass
def rn_publish(self):
subprocess.run(['npm', 'publish'])
pass
def rn_get(self):
subprocess.run(['npm', 'install'])
pass
def close(self):
os.chdir("..")
def prepare(self):
self.replace_name_version()
def self_prepare(self):
self.update_pubspec_dependency()
os.chdir("example")
self.update_pubspec_dependency()
os.chdir("..")
class ParticleBaseModule(ParticleBase):
beta_name = "rn-base-beta"
production_name = "@particle-network/rn-base"
def __init__(self, version, beta_mode):
os.chdir("particle-base")
self.beta_mode = beta_mode
super().__init__(version)
def publish(self):
self.prepare()
self.rn_publish()
self.close()
def publish_dry_run(self):
self.prepare()
self.rn_publish_dry_run()
self.close()
class ParticleConnectModule(ParticleBase):
beta_name = "rn-connect-beta"
production_name = "@particle-network/rn-connect"
def __init__(self, version, beta_mode):
os.chdir("particle-connect")
self.beta_mode = beta_mode
super().__init__(version)
def publish(self):
self.prepare()
self.self_prepare()
self.rn_get()
self.rn_publish()
self.close()
class ParticleAuthCoreModule(ParticleBase):
beta_name = "rn-auth-core-beta"
production_name = "@particle-network/rn-auth-core"
def __init__(self, version, beta_mode):
os.chdir("particle-auth-core")
self.beta_mode = beta_mode
super().__init__(version)
def publish(self):
self.prepare()
self.self_prepare()
self.rn_get()
self.rn_publish()
self.close()
class ParticleAAModule(ParticleBase):
beta_name = "rn-aa-beta"
production_name = "@particle-network/rn-aa"
def __init__(self, version, beta_mode):
os.chdir("particle-aa")
self.beta_mode = beta_mode
super().__init__(version)
def publish(self):
self.prepare()
self.self_prepare()
self.rn_get()
self.rn_publish()
self.close()
class ParticleWalletModule(ParticleBase):
beta_name = "rn-wallet-beta"
production_name = "@particle-network/rn-wallet"
def __init__(self, version, beta_mode):
os.chdir("particle-wallet")
self.beta_mode = beta_mode
super().__init__(version)
def publish(self):
self.prepare()
self.self_prepare()
self.rn_get()
self.rn_publish()
self.close()
if __name__ == "__main__":
version = '2.0.5'
betaMode = False
sleep_time = 0
print("Base Start")
ParticleBaseModule(version, betaMode).publish()
print("Base Finish")
time.sleep(sleep_time)
print("AuthCore Start")
ParticleAuthCoreModule(version, betaMode).publish()
print("AuthCore Finish")
time.sleep(sleep_time)
print("Connect Start")
ParticleConnectModule(version, betaMode).publish()
print("Connect Finish")
time.sleep(sleep_time)
print("ParticleAA Start")
ParticleAAModule(version, betaMode).publish()
print("ParticleAA Finish")
time.sleep(sleep_time)
print("ParticleWallet Start")
ParticleWalletModule(version, betaMode).publish()
print("ParticleWallet Finish")