inisital commit

This commit is contained in:
2022-11-21 15:40:16 +01:00
commit a9e3c19fb9
41 changed files with 2338 additions and 0 deletions

48
src/config.py Normal file
View File

@@ -0,0 +1,48 @@
import os
import jsonschema
import yaml
import flags
import utils
default_config = {
'output': {
'dir': 'generated',
'formats': ['woff2'],
'prefix': '/',
'css': {
'font-display': 'swap',
'font-style': 'normal',
'font-weight': '400',
},
'clean': False,
},
"context": ".",
}
def validate(config):
schema_file = utils.asset_path('config.schema.yaml')
with open(schema_file, 'r') as f:
schema = yaml.safe_load(f)
return jsonschema.validate(config, schema)
def load(path):
# Load config
path = os.path.abspath(path)
with open(path, 'r') as f:
config = yaml.safe_load(f)
# Setting dynamic defaults
default_config['context'] = os.path.dirname(path)
if flags.OUTPUT_DIRECTORY != None:
default_config['output']['dir'] = flags.OUTPUT_DIRECTORY
if flags.CLEAN != None:
default_config['output']['clean'] = flags.CLEAN
if flags.PREFIX != None:
default_config['output']['prefix'] = flags.PREFIX
# Merge defaults
return utils.update_deep(default_config, config)