diff --git a/Documentation/Theming_implementation.md b/Documentation/Theming_implementation.md index 31980d517..c92f32be0 100644 --- a/Documentation/Theming_implementation.md +++ b/Documentation/Theming_implementation.md @@ -97,6 +97,17 @@ font: bold: 'FontName-Bold' ``` +### What's New +The `whitelabel.yaml` configuration may contain the path to a What's New json file, and an existing json file in the project will be replaced with this json file. + +For this function, the configuration must contain the following parameters: +```yaml +whatsnew: + whatsnew_import_file_path: 'path/to/importing/whats_new.json' # path to what's new json file what should be imported to project + project_whatsnew_file_path: 'path/to/json/file/in/project/whats_new.json' # path to existing json-file in project +``` + + ### Log level You can set the log level to 'DEBUG' by adding the `-v` parameter to the script running. The default log level is 'WARN' diff --git a/WhatsNew/WhatsNew/Data/WhatsNewModel.swift b/WhatsNew/WhatsNew/Data/WhatsNewModel.swift index 48302fb62..167cd3ee2 100644 --- a/WhatsNew/WhatsNew/Data/WhatsNewModel.swift +++ b/WhatsNew/WhatsNew/Data/WhatsNewModel.swift @@ -39,10 +39,8 @@ extension WhatsNewModel { let v1 = version1.split(separator: ".").compactMap { Int($0) } let v2 = version2.split(separator: ".").compactMap { Int($0) } - for (a, b) in zip(v1, v2) { - if a != b { - return a < b ? .orderedAscending : .orderedDescending - } + for (a, b) in zip(v1, v2) where a != b { + return a < b ? .orderedAscending : .orderedDescending } return v1.count < v2.count ? .orderedAscending : (v1.count > v2.count ? .orderedDescending : .orderedSame) @@ -55,7 +53,6 @@ extension WhatsNewModel { return latestVersion } - var domain: [WhatsNewPage] { guard let latestVersion = findLatestVersion(self.map { $0.version }) else { return [] } return self.first(where: { $0.version == latestVersion })?.messages.map { diff --git a/WhatsNew/WhatsNewTests/Presentation/WhatsNewTests.swift b/WhatsNew/WhatsNewTests/Presentation/WhatsNewTests.swift index 4f43a51dd..7c6542b16 100644 --- a/WhatsNew/WhatsNewTests/Presentation/WhatsNewTests.swift +++ b/WhatsNew/WhatsNewTests/Presentation/WhatsNewTests.swift @@ -6,21 +6,21 @@ // import XCTest +import Core @testable import WhatsNew final class WhatsNewTests: XCTestCase { func testGetVersion() throws { - let viewModel = WhatsNewViewModel(storage: WhatsNewStorageMock()) + let viewModel = WhatsNewViewModel(storage: WhatsNewStorageMock()) let version = viewModel.getVersion() XCTAssertNotNil(version) XCTAssertTrue(version == "1.0") } func testshouldShowWhatsNew() throws { - let viewModel = WhatsNewViewModel(storage: WhatsNewStorageMock()) + let viewModel = WhatsNewViewModel(storage: WhatsNewStorageMock()) let version = viewModel.getVersion() - XCTAssertNotNil(version) XCTAssertTrue(viewModel.shouldShowWhatsNew()) } diff --git a/config_script/process_config.py b/config_script/process_config.py index dd24319b0..36340bfc3 100644 --- a/config_script/process_config.py +++ b/config_script/process_config.py @@ -68,7 +68,7 @@ def load_config(self): with open(path, 'r') as file: dict = yaml.safe_load(file) if dict is not None: - properties.update(dict) + properties = merge_dicts(properties, dict) except FileNotFoundError: print(f"{path} not found. Skipping.") @@ -82,7 +82,7 @@ def yaml_to_plist(self): with open(path, 'r') as file: yaml_data = yaml.safe_load(file) if yaml_data is not None: - plist_data.update(yaml_data) + plist_data = merge_dicts(plist_data, yaml_data) except FileNotFoundError: print(f"{path} not found. Skipping.") except yaml.YAMLError as e: @@ -117,7 +117,14 @@ def get_info_plist_contents(self, plist_path): except Exception as e: print(f"Error reading plist file: {e}") return None - + +def merge_dicts(d1, d2): + for k, v in d2.items(): + if k in d1: + d1[k] = dict(v,**d1[k]) + else: + d1[k] = v + return d1 class ConfigurationManager: def __init__(self, plist_manager): diff --git a/config_script/whitelabel.py b/config_script/whitelabel.py index fec095f62..d7295d4d9 100644 --- a/config_script/whitelabel.py +++ b/config_script/whitelabel.py @@ -58,6 +58,9 @@ class WhitelabelApp: medium: 'FontName-Medium' semiBold: 'FontName-Semibold' bold: 'FontName-Bold' + whatsnew: + whatsnew_import_file_path: 'path/to/importing/whats_new.json' + project_whatsnew_file_path: 'path/to/json/file/in/project/whats_new.json' """) def __init__(self, **kwargs): @@ -68,17 +71,23 @@ def __init__(self, **kwargs): self.assets = kwargs.get('assets', {}) self.project_config = kwargs.get('project_config', {}) self.font = kwargs.get('font', {}) + self.whatsnew = kwargs.get('whatsnew', {}) - if "project_path" in self.project_config: - self.config_project_path = self.project_config["project_path"] + if self.project_config: + if "project_path" in self.project_config: + self.config_project_path = self.project_config["project_path"] + else: + logging.error("Path to project file is not defined") else: - logging.error("Path to project file is not defined") + logging.debug("Project settings config not found") def whitelabel(self): # Update the properties, resources, and configuration of the current app. self.copy_assets() self.copy_font() - self.set_app_project_config() + self.copy_whatsnew() + if self.project_config: + self.set_app_project_config() def copy_assets(self): if self.assets: @@ -87,7 +96,7 @@ def copy_assets(self): self.replace_colors(asset) self.replace_app_icon(asset) else: - logging.debug("Assets not found") + logging.debug("Assets config not found") def replace_images(self, asset_data): asset = asset_data[1] @@ -425,7 +434,7 @@ def copy_font(self): if "project_font_file_path" in self.font: project_font_file_path = self.font["project_font_file_path"] # if source and destination file exist - self.copy_font_file(font_import_file_path, project_font_file_path) + self.copy_file(font_import_file_path, project_font_file_path, "Font") else: logging.error("'project_font_file_path' not found in config") else: @@ -440,14 +449,14 @@ def copy_font(self): else: logging.debug("Font not found in config") - def copy_font_file(self, file_src, file_dest): - # try to copy font file and show success/error message + def copy_file(self, file_src, file_dest, title): + # try to copy file and show success/error message try: shutil.copy(file_src, file_dest) except IOError as e: logging.error("Unable to copy file. "+e) else: - logging.debug("Font was copied to project") + logging.debug(title+" file was copied to project") def set_font_names(self, font_names): if "project_font_names_json_path" in self.font: @@ -469,6 +478,28 @@ def set_font_names(self, font_names): else: logging.error("'project_font_names_json_path' not found in config") + def copy_whatsnew(self): + # check if whatsnew config exists + if self.whatsnew: + if "whatsnew_import_file_path" in self.whatsnew: + whatsnew_import_file_path = self.whatsnew["whatsnew_import_file_path"] + if "project_whatsnew_file_path" in self.whatsnew: + project_whatsnew_file_path = self.whatsnew["project_whatsnew_file_path"] + # if source and destination file exist + if os.path.exists(whatsnew_import_file_path): + if os.path.exists(project_whatsnew_file_path): + self.copy_file(whatsnew_import_file_path, project_whatsnew_file_path, "What's new") + else: + logging.error(project_whatsnew_file_path+" file doesn't exist") + else: + logging.error(whatsnew_import_file_path+" file doesn't exist") + else: + logging.error("'project_whatsnew_file_path' not found in config") + else: + logging.error("'whatsnew_import_file_path' not found in config") + else: + logging.debug("What's New not found in config") + def main(): """ Parse the command line arguments, and pass them to WhitelabelApp.