refactor: remove scripts used to migrate from mxGraph (#167)
parent
171c8f8134
commit
3d1d68afd7
|
@ -1,32 +0,0 @@
|
|||
import re
|
||||
from pathlib import Path
|
||||
|
||||
MODE_BETWEEN_COMMENTS = 0
|
||||
MODE_COMMENT_START = 1
|
||||
MODE_PARAMS_START = 2
|
||||
|
||||
for path in Path('.').rglob('*.js'):
|
||||
out_lines = []
|
||||
cur_mode = MODE_BETWEEN_COMMENTS
|
||||
|
||||
with open(path, 'r', encoding='utf-8') as f:
|
||||
for line in f:
|
||||
if line.strip() == '/**' and cur_mode == MODE_BETWEEN_COMMENTS:
|
||||
cur_mode = MODE_COMMENT_START
|
||||
out_lines.append(line)
|
||||
elif line.strip() == '* Parameters:' and cur_mode == MODE_COMMENT_START:
|
||||
cur_mode = MODE_PARAMS_START
|
||||
elif cur_mode == MODE_PARAMS_START:
|
||||
if line.strip() == '*/':
|
||||
cur_mode = MODE_BETWEEN_COMMENTS
|
||||
out_lines.append(line)
|
||||
elif line.strip() != '*':
|
||||
# e.g. * node - DOM node whose siblings should be removed.
|
||||
line = re.sub(r'(\s*?)\* ([A-z0-9_]+) - ', '\\1* @param \\2 ', line)
|
||||
#print(line)
|
||||
out_lines.append(line)
|
||||
else:
|
||||
out_lines.append(line)
|
||||
|
||||
with open(path, 'w', encoding='utf-8', newline='\n') as f:
|
||||
f.write(''.join(out_lines))
|
|
@ -1,48 +0,0 @@
|
|||
import re
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
with open('typed_mxgraph_defs.json', 'r', encoding='utf-8') as f:
|
||||
defs = json.loads(f.read())
|
||||
|
||||
|
||||
for path in list(Path('.').rglob('./*/*.js')) + list(Path('.').rglob('./*/*.ts')):
|
||||
print(path)
|
||||
with open(path, 'r', encoding='utf-8') as f:
|
||||
text = f.read()
|
||||
|
||||
clsname = path.name.split('.')[0]
|
||||
if clsname in defs:
|
||||
#print(defs[clsname])
|
||||
assert not '\r\n' in text
|
||||
|
||||
if defs[clsname][0]:
|
||||
pattern = r'(/\*(?:(?!\*/).)*\*/)\s*\nclass %s\b' % clsname
|
||||
replace_with = '\n'.join(defs[clsname][0])
|
||||
replace_with += '\nclass %s' % clsname
|
||||
replace_with = replace_with.replace('\\u', '').replace('\\x', '')
|
||||
text = re.sub(pattern, replace_with, text, flags=re.DOTALL)
|
||||
|
||||
for k, v in defs[clsname][1].items():
|
||||
if not v[1]: continue
|
||||
elif not k.strip().strip('();'): continue
|
||||
k = k.strip('\\;')
|
||||
|
||||
pattern = r' (/\*(?:(?!\*/).)*\*/)\n %s\b' % k
|
||||
replace_with = '\n'.join(' '+i for i in v[1])
|
||||
replace_with += '\n // '+v[0]+'\n'
|
||||
replace_with += ' %s' % k
|
||||
replace_with = replace_with.replace('\\u', '').replace('\\x', '')
|
||||
|
||||
#print(pattern, re.findall(pattern, text, re.DOTALL))
|
||||
text = re.sub(pattern, replace_with, text, flags=re.DOTALL)
|
||||
|
||||
print(text)
|
||||
|
||||
with open(path, 'w', encoding='utf-8') as f:
|
||||
f.write(text)
|
||||
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue