Skip to content

Commit

Permalink
Refactor configuration management
Browse files Browse the repository at this point in the history
- Moved configuration data to a JSON file for better organization.
- Updated local and remote dependencies to utilize this JSON file.
- Streamlined configuration handling for consistency across environments.
  • Loading branch information
MalekKamel committed Oct 17, 2024
1 parent a01222a commit 6950868
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 216 deletions.
2 changes: 1 addition & 1 deletion solara/lib/core/dashboard/brand/BrandDetailController.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class BrandDetailController {

async addNewBrand() {
this.view.showOnboardBrandForm(async (key, name) => {
const configurations = await this.model.createNewBrandConfogurations()
const configurations = await this.model.createNewBrandConfigurations()
await this.addBrand(key, name, configurations)
})
}
Expand Down
4 changes: 2 additions & 2 deletions solara/lib/core/dashboard/brand/BrandDetailModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class BrandDetailModel {
}
}

async createNewBrandConfogurations() {
return await this.remoteSource.createNewBrandConfogurations();
async createNewBrandConfigurations() {
return await this.remoteSource.createNewBrandConfigurations();
}

async createBrandConfigurationsFromDirectory(dirHandle) {
Expand Down
1 change: 0 additions & 1 deletion solara/lib/core/dashboard/brand/SectionsFormManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class SectionsFormManager {

sectionElement.dataset.key = section.key
sectionElement.dataset.name = section.name
sectionElement.dataset.inputType = section.inputType

const titleContainer = document.createElement('div');
titleContainer.className = 'section-title-container';
Expand Down
167 changes: 36 additions & 131 deletions solara/lib/core/dashboard/brand/source/BrandRemoteSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,124 +4,36 @@ class BrandRemoteSource {
constructor() {
}

async createNewBrandConfogurations() {
const configurations_template = `
[
{
"key": "theme.json",
"name": "Theme Configuration",
"inputType": "color",
"content": {
"colors": {
"primary": "#CAAC16",
"secondary": "#5AC8FA",
"background": "#FFFFFF",
"surface": "#F2F2F7",
"error": "#FF3B30",
"onPrimary": "#FFFFFF",
"onSecondary": "#000000",
"onBackground": "#000000",
"onSurface": "#000000",
"onError": "#FFFFFF"
},
"typography": {
"fontFamily": {
"regular": "",
"medium": "",
"bold": ""
},
"fontSize": {
"small": 12,
"medium": 16,
"large": 20,
"extraLarge": 24
async createNewBrandConfigurations() {
const url = 'https://raw.githubusercontent.com/Solara-Kit/Solara/refs/heads/develop/solara/lib/core/template/configurations.json';

try {
const response = await fetch(url);
if (!response.ok) {
throw new Error('Network response was not ok: ' + response.statusText);
}

const configurations = await response.json();
const contentPromises = configurations.configurations.map(async (config) => {
const contentResponse = await fetch(config.url);
if (!contentResponse.ok) {
throw new Error('Failed to fetch content for ' + config.key);
}
const content = await contentResponse.json();
return {
key: config.key,
name: config.name,
content: content
};
});

// Wait for all content fetch promises to resolve
return await Promise.all(contentPromises);

} catch (error) {
console.error('There was a problem with the fetch operation:', error);
return null; // Return null in case of error
}
},
"spacing": {
"small": 8,
"medium": 16,
"large": 24,
"extraLarge": 32
},
"borderRadius": {
"small": 4,
"medium": 8,
"large": 12
},
"elevation": {
"none": 0,
"low": 2,
"medium": 4,
"high": 8
}
}
},
{
"key": "brand_config.json",
"name": "Brand Configuration",
"inputType": "text",
"content": {}
},
{
"key": "android_config.json",
"name": "Android Configuration",
"inputType": "text",
"content": {
"applicationId": "",
"versionName": "1.0.0",
"versionCode": 1,
"sourceSets": []
}
},
{
"key": "android_signing.json",
"name": "Android Signing",
"inputType": "text",
"content": {
"storeFile": "",
"keyAlias": "",
"storePassword": "",
"keyPassword": ""
}
},
{
"key": "ios_config.json",
"name": "iOS Configuration",
"inputType": "text",
"content": {
"PRODUCT_BUNDLE_IDENTIFIER": "",
"MARKETING_VERSION": "1.0.0",
"BUNDLE_VERSION": 1,
"APL_MRCH_ID": ""
}
},
{
"key": "ios_signing.json",
"name": "iOS Signing",
"inputType": "text",
"content": {
"CODE_SIGN_IDENTITY": "",
"DEVELOPMENT_TEAM": "",
"PROVISIONING_PROFILE_SPECIFIER": "",
"CODE_SIGN_STYLE": "Automatic",
"CODE_SIGN_ENTITLEMENTS": ""
}
},
{
"key": "ios_signing.json",
"name": "iOS Signing",
"inputType": "text",
"content": {
"CODE_SIGN_IDENTITY": "",
"DEVELOPMENT_TEAM": "",
"PROVISIONING_PROFILE_SPECIFIER": "",
"CODE_SIGN_STYLE": "Automatic",
"CODE_SIGN_ENTITLEMENTS": ""
}
}
]
`;
return JSON.parse(configurations_template);
}

async getBrandConfigurationsJsonFromDirectory(dirHandle) {
Expand Down Expand Up @@ -161,7 +73,7 @@ class BrandRemoteSource {
if (!response.ok) {
throw new Error('Network response was not ok: ' + response.statusText);
}
return await response.json(); // Return the data instead of null
return await response.json();
} catch (error) {
console.error('There was a problem with the fetch operation:', error);
return null; // Return null in case of error
Expand All @@ -173,33 +85,27 @@ class BrandRemoteSource {
const expectedFiles = [
{
key: 'theme.json',
name: 'Theme Configuration',
input_type: 'color'
name: 'Theme Configuration'
},
{
key: 'brand_config.json',
name: 'Brand Configuration',
input_type: 'text'
name: 'Brand Configuration'
},
{
key: 'android_config.json',
name: 'Android Configuration',
input_type: 'text'
name: 'Android Configuration'
},
{
key: 'android_signing.json',
name: 'Android Signing',
input_type: 'text'
name: 'Android Signing'
},
{
key: 'ios_config.json',
name: 'iOS Configuration',
input_type: 'text'
name: 'iOS Configuration'
},
{
key: 'ios_signing.json',
name: 'iOS Signing',
input_type: 'text'
name: 'iOS Signing'
}
];

Expand All @@ -210,7 +116,6 @@ class BrandRemoteSource {
configList.push({
key: file.key,
name: file.name,
inputType: file.input_type,
content: JSON.parse(fileContent)
});
}
Expand Down
73 changes: 0 additions & 73 deletions solara/lib/core/dashboard/handler/brand_configurations_manager.rb

This file was deleted.

8 changes: 0 additions & 8 deletions solara/lib/core/doctor/schema/brand_configurations.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@
"name": {
"type": "string"
},
"inputType": {
"type": "string",
"enum": [
"color",
"text"
]
},
"content": {
"type": "object",
"additionalProperties": {}
Expand All @@ -46,7 +39,6 @@
"required": [
"key",
"name",
"inputType",
"content"
]
}
Expand Down
41 changes: 41 additions & 0 deletions solara/lib/core/scripts/brand_configurations_manager.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class BrandConfigurationsManager

def initialize(brand_key)
@brand_key = brand_key
end

def template_with_key(key)
templates.select { |section| section[:key] === key }.first
end

def templates
configurations = JSON.parse(File.read(FilePath.brand_configurations))['configurations']
configurations.map do |config|
{
key: config['key'],
name: config['name'],
path: "#{FilePath.brand(@brand_key)}/#{config['filePath']}"
}
end
end

def create
config_templates = templates

config_templates.map do |template|
create_config_item(
template[:key],
template[:name],
template[:path]
)
end
end

def create_config_item(key, name, path)
{
key: key,
name: name,
content: JSON.parse(File.read(path)),
}
end
end
4 changes: 4 additions & 0 deletions solara/lib/core/scripts/file_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ def self.solara_template
File.join(root, 'core', 'template')
end

def self.brand_configurations
File.join(solara_template, 'configurations.json')
end

def self.solara_aliases_json
File.join(dot_solara, 'aliases', 'aliases.json')
end
Expand Down
Loading

0 comments on commit 6950868

Please sign in to comment.