-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
150 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import Ajv from 'https://cdn.skypack.dev/[email protected]'; | ||
|
||
class BrandRemoteSource { | ||
constructor() { | ||
} | ||
|
@@ -133,6 +135,74 @@ class BrandRemoteSource { | |
return JSON.parse(configurations_template); | ||
} | ||
|
||
async getBrandConfigurationsJsonFromDirectory(dirHandle) { | ||
const schema = { | ||
"title": "Brand Configurations Schema", | ||
"type": "object", | ||
"properties": { | ||
"brand": { | ||
"type": "object", | ||
"properties": { | ||
"key": { | ||
"type": "string" | ||
}, | ||
"name": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": ["key", "name"] | ||
}, | ||
"configurations": { | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"key": { | ||
"type": "string" | ||
}, | ||
"name": { | ||
"type": "string" | ||
}, | ||
"inputType": { | ||
"type": "string", | ||
"enum": ["color", "text"] | ||
}, | ||
"content": { | ||
"type": "object", | ||
"additionalProperties": {} | ||
} | ||
}, | ||
"required": ["key", "name", "inputType", "content"] | ||
} | ||
} | ||
}, | ||
"required": ["brand", "configurations"] | ||
}; | ||
|
||
const ajv = new Ajv(); | ||
const validate = ajv.compile(schema); | ||
|
||
const text = await dirHandle.text(); | ||
let json; | ||
|
||
try { | ||
json = JSON.parse(text); | ||
} catch (e) { | ||
console.error("Invalid JSON:", e); | ||
return null | ||
} | ||
|
||
const valid = validate(json); | ||
|
||
if (valid) { | ||
return json; | ||
} else { | ||
console.error("Schema validation failed:", validate.errors); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
async createBrandConfigurationsFromDirectory(dirHandle) { | ||
const configList = []; | ||
const expectedFiles = [ | ||
|