diff --git a/config.yaml b/config.yaml index 0738c71..525099d 100644 --- a/config.yaml +++ b/config.yaml @@ -15,3 +15,8 @@ RelevantObjects: screen: [OnVisible] text: [OnSelect] #typedDataCard: [DataField, Default, Update] + +ScreenFlow: + # By default all screens from CanvasManifest.json will be used in same sequence. + # If screens shall be excluded from the graph, list them here. + ExcludeScreens: [] \ No newline at end of file diff --git a/powerapps_docstring/documentation.py b/powerapps_docstring/documentation.py index e3e8a4e..7ed066d 100644 --- a/powerapps_docstring/documentation.py +++ b/powerapps_docstring/documentation.py @@ -12,16 +12,21 @@ def __init__(self, source, output, config) -> None: self.output_path = output self.parser = Parser(self.source_path) self.config = config + self.manifest_file = self.parser.get_canvas_manifest() self.relevant_objects = self.config["RelevantObjects"] self.relevant_object_keys = [f" As {x}" for x in self.relevant_objects.keys()] def _get_screen_files(self): screen_files = [] screens_path = self.source_path + "/Src/" - for file in os.listdir(screens_path): - if os.path.isfile(screens_path + file) & file.endswith(".yaml"): - if file != "App.fx.yaml": - screen_files.append(file) + + # read screen order from manifest and check if files exists + screen_order = self.manifest_file["ScreenOrder"] + for screen in screen_order: + screen_file_name = screen + ".fx.yaml" + if screen_file_name in os.listdir(screens_path): + if screen_file_name != "App.fx.yaml": + screen_files.append(screen_file_name) return screen_files @@ -119,29 +124,32 @@ def get_recursively(search_dict, field): screen_files = self._get_screen_files() screens_path = self.source_path + "/Src/" + for screen in screen_files: - screen_obj = self.parser.get_screen_objects(screen) - from_screen = screen_obj[0] - list_of_onselects = get_recursively(screen_obj[1], "OnSelect") - - for item in list_of_onselects: - if "Navigate(" in item: - - item = item.strip().replace("\n", "").replace("\t", "").replace(" ", "") - navigate_occurences = [m.start() for m in re.finditer('Navigate\(', item)] - - for occurence in navigate_occurences: - #print(occurence) - start = occurence + len("Navigate(") - #print(start) - end = item[start:].find(",") - if end == -1: - end = item[start:].find(")") - end = end + start - to_screen = item[start:end] - if to_screen != None and to_screen != "" and not to_screen.startswith("[@"): - to_screen = to_screen.replace("\n", "").replace("\t", "").replace(" ", "").replace(")", "") - screenflow_list.append(from_screen + " ==> " + to_screen.replace("\n", "").replace("\t", "").replace(" ", "")) + # check if screen has been excluded + if screen.replace(".fx.yaml", "") not in self.config["ScreenFlow"]["ExcludeScreens"]: + screen_obj = self.parser.get_screen_objects(screen) + from_screen = screen_obj[0] + list_of_onselects = get_recursively(screen_obj[1], "OnSelect") + + for item in list_of_onselects: + if "Navigate(" in item: + + item = item.strip().replace("\n", "").replace("\t", "").replace(" ", "") + navigate_occurences = [m.start() for m in re.finditer('Navigate\(', item)] + + for occurence in navigate_occurences: + #print(occurence) + start = occurence + len("Navigate(") + #print(start) + end = item[start:].find(",") + if end == -1: + end = item[start:].find(")") + end = end + start + to_screen = item[start:end] + if to_screen != None and to_screen != "" and not to_screen.startswith("[@") and to_screen not in self.config["ScreenFlow"]["ExcludeScreens"]: + to_screen = to_screen.replace("\n", "").replace("\t", "").replace(" ", "").replace(")", "") + screenflow_list.append(from_screen + " ==> " + to_screen.replace("\n", "").replace("\t", "").replace(" ", "")) #print(screenflow_list) @@ -158,7 +166,7 @@ def create_documentation(self, format=None): # instantiate the md file # TODO: get title from docstring variable - app_name = self.parser.get_app_name() + app_name = self.manifest_file["PublishInfo"]["AppName"] self.md_file = MdUtils(file_name=self.output_path + f'/{app_name}-doc', title='Power App Documentation') @@ -215,11 +223,9 @@ def create_documentation(self, format=None): # loop thru all screens and create markdown screens_path = self.source_path + "/Src/" - for file in os.listdir(screens_path): - if os.path.isfile(screens_path + file) & file.endswith(".yaml"): - if file != "App.fx.yaml": - screen_objects = self.parser.get_screen_objects(file) - self._extract_screen_content_to_markdown(screen_objects) + for file in self._get_screen_files(): + screen_objects = self.parser.get_screen_objects(file) + self._extract_screen_content_to_markdown(screen_objects) # write toc + file self.md_file.new_table_of_contents(table_title='Contents', depth=2) diff --git a/powerapps_docstring/parser.py b/powerapps_docstring/parser.py index 0c852a1..b0bdd64 100644 --- a/powerapps_docstring/parser.py +++ b/powerapps_docstring/parser.py @@ -34,12 +34,11 @@ def get_screen_objects(self, screen_name) -> tuple: screen_name = list(screen_content.keys())[0].split(" ")[0] return screen_name, screen_content - def get_app_name(self): + def get_canvas_manifest(self): app_name = "PowerApp_Documentation" # get name from CanvasManifest.json if os.path.isfile(self.source_path + "CanvasManifest.json"): with open(self.source_path + "CanvasManifest.json", "r", encoding="utf-8") as file: canvas_manifest = json.load(file) - app_name = canvas_manifest["PublishInfo"]["AppName"] - return app_name + return canvas_manifest