Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace WhatsNew file with Script #254

Merged
merged 10 commits into from
Jan 26, 2024
Merged
11 changes: 11 additions & 0 deletions Documentation/Theming_implementation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
7 changes: 2 additions & 5 deletions WhatsNew/WhatsNew/Data/WhatsNewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions WhatsNew/WhatsNewTests/Presentation/WhatsNewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
13 changes: 10 additions & 3 deletions config_script/process_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
49 changes: 40 additions & 9 deletions config_script/whitelabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand All @@ -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]
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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.
Expand Down
Loading