maxGraph/packages/core/replace_comment_params.py

33 lines
1.2 KiB
Python
Raw Normal View History

Finish converting core to ts, JSDoc conversion, consistency+convention changes, example bugfixes (#70) * reorganised directories; removed mx prefix * reduced directory hierarchies; removed mx prefix; type fixes * convert remaining javascript to ts * fix/add types * add type defs * type updates; moved codecs to where they're used * reorganise constants into enums+type additions * removed "Function:" and "Variable:" prefixes from comments, as they aren't needed in JSDoc * removed "Function:", "Variable:" and "Class:" prefixes from comments, as they aren't needed in JSDoc * removed "Function:" prefixes from comments, as they aren't needed in JSDoc * minor changes * convert code example blocks to markdown * module casing updates * converted parameter function documentation to JSDoc * documentation+type updates * removed react subdir (for now) * reorganised various `utils` functions into different files * type updates/bugfixes/workarounds * rename Rubberband and CellEditor to be *Handler to match the other plugins * move codec classes to where they're used to reduce cyclic dependencies * move codec classes to where they're used to reduce cyclic dependencies * type updates/reorganize layout file structure * renamed various files for consistency * import fixes * renamed GraphHandler SelectionHander and various fixes * convert EventObject parameters to objects * add basic better-docs config * update better-docs config * bugfix for shared variables in Graph persisting across instances * fixed accessing handlers in examples; renamed Model to GraphModel * fixed accessing handlers in examples; renamed Model to GraphModel * restored selection model * bugfix * renamed getModel to getDataModel * changed to use graph.batchUpdate() to reduce lines of code * changed to use graph.batchUpdate() to reduce lines of code * finished annotations+added TypeDoc * convert remaining Cell[] instances to CellArray * convert NaturalDocs links to JSDoc
2022-01-08 01:49:35 +00:00
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))