tools: Add TypeScript to the dependency visualizer.

The dependency visualizer currently only supports JavaScript files,
such as in the `get_js_edges` function, where only the ".js" extension
is supported. Update the visualizer to support ".ts" files as well and
to output modules without their extensions.
This commit is contained in:
Marco Burstein 2019-03-28 10:26:12 -07:00 committed by Tim Abbott
parent 57ffc3fe74
commit ce7d2fde70
1 changed files with 7 additions and 4 deletions

View File

@ -36,9 +36,9 @@ def get_js_edges():
names = set() names = set()
modules = [] # type: List[Dict[str, Any]] modules = [] # type: List[Dict[str, Any]]
for js_file in os.listdir(JS_FILES_DIR): for js_file in os.listdir(JS_FILES_DIR):
if not js_file.endswith('.js'): if not js_file.endswith('.js') and not js_file.endswith('.ts'):
continue continue
name = js_file[:-3] # remove .js name = js_file[:-3] # Remove .js or .ts
path = os.path.join(JS_FILES_DIR, js_file) path = os.path.join(JS_FILES_DIR, js_file)
names.add(name) names.add(name)
modules.append(dict( modules.append(dict(
@ -266,11 +266,14 @@ def report_roadmap(edges, methods):
callers[(child, method)].add(parent) callers[(child, method)].add(parent)
for child in sorted(child_modules): for child in sorted(child_modules):
print(child + '.js') # Since children are found using the regex pattern, it is difficult
# to know if they are JS or TS files without checking which files
# exist. Instead, just print the name of the module.
print(child)
for method in module_methods[child]: for method in module_methods[child]:
print(' ' + child + '.' + method) print(' ' + child + '.' + method)
for caller in sorted(callers[(child, method)]): for caller in sorted(callers[(child, method)]):
print(' ' + caller + '.js') print(' ' + caller)
print() print()
print() print()