mirror of
https://github.com/ethauvin/warp-themes.git
synced 2025-04-25 09:07:11 -07:00
scripts
This commit is contained in:
parent
337e2dcd4b
commit
1ad1ec51ad
2 changed files with 21 additions and 19 deletions
|
@ -7,8 +7,7 @@ from pathlib import Path
|
|||
|
||||
def get_all_input_files(input_dir: str) -> List[str]:
|
||||
filenames = next(os.walk(input_dir), (None, None, []))[2]
|
||||
files = filter(lambda f: (f.endswith("yaml")
|
||||
or f.endswith("yml")), filenames)
|
||||
files = filter(lambda f: (f.endswith("yaml") or f.endswith("yml")), filenames)
|
||||
return list(files)
|
||||
|
||||
|
||||
|
@ -17,14 +16,16 @@ def ensure_output_dir(output_dir: str):
|
|||
os.makedirs(output_dir)
|
||||
|
||||
|
||||
def add_color_to_dict(output: Dict[str, str], obj: Dict[str, str], key: str, prefix: Optional[str] = None):
|
||||
def add_color_to_dict(
|
||||
output: Dict[str, str], obj: Dict[str, str], key: str, prefix: Optional[str] = None
|
||||
):
|
||||
if not prefix:
|
||||
prefix = ""
|
||||
output[f"{prefix}{key}"] = obj[key]
|
||||
|
||||
|
||||
def get_color_dict(input_dir: str, file_name: str) -> Dict[str, str]:
|
||||
file = open(os.path.join(input_dir, file_name), 'r')
|
||||
file = open(os.path.join(input_dir, file_name), "r")
|
||||
loaded_theme = yaml.safe_load(file)
|
||||
output = {}
|
||||
add_color_to_dict(output, loaded_theme, "accent")
|
||||
|
@ -43,7 +44,7 @@ def get_color_dict(input_dir: str, file_name: str) -> Dict[str, str]:
|
|||
|
||||
|
||||
def file_name_to_display(file_name: str) -> str:
|
||||
file_name = Path(file_name).with_suffix('').name
|
||||
file_name = Path(file_name).with_suffix("").name
|
||||
|
||||
split = file_name.split("_")
|
||||
output = []
|
||||
|
@ -62,14 +63,16 @@ def gen_svg_for_theme(color_dict: Dict[str, str], svg_template: str) -> str:
|
|||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Generate README.md with embedded SVG previews.')
|
||||
parser.add_argument('input_dir', type=str,
|
||||
help='Directory from which to read in all Warp themes.')
|
||||
parser.add_argument('output_dir', type=str, help='Where to save README.md')
|
||||
parser.add_argument("svg_path", type=str,
|
||||
help="Path to svg template file.")
|
||||
parser.add_argument("intro_file", type=str,
|
||||
help="What should go on top of README.md.")
|
||||
description="Generate README.md with embedded SVG previews."
|
||||
)
|
||||
parser.add_argument(
|
||||
"input_dir", type=str, help="Directory from which to read in all Warp themes."
|
||||
)
|
||||
parser.add_argument("output_dir", type=str, help="Where to save README.md")
|
||||
parser.add_argument("svg_path", type=str, help="Path to svg template file.")
|
||||
parser.add_argument(
|
||||
"intro_file", type=str, help="What should go on top of README.md."
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
ensure_output_dir(args.output_dir)
|
||||
|
@ -78,11 +81,11 @@ def main():
|
|||
markdown = []
|
||||
markdown.append("|Theme name | Preview|")
|
||||
markdown.append("| --- | --- |")
|
||||
svg = open(args.svg_path, 'r').read()
|
||||
svg = open(args.svg_path, "r").read()
|
||||
svg_dir = os.path.join(args.output_dir, "previews")
|
||||
os.makedirs(svg_dir, exist_ok=True)
|
||||
|
||||
intro = open(args.intro_file, 'r').read()
|
||||
intro = open(args.intro_file, "r").read()
|
||||
|
||||
for input_file in sorted(filenames):
|
||||
print(f"Generating for {input_file}")
|
||||
|
@ -90,13 +93,13 @@ def main():
|
|||
color_dict = get_color_dict(args.input_dir, input_file)
|
||||
theme_svg = gen_svg_for_theme(color_dict, svg)
|
||||
theme_svg_path = os.path.join(svg_dir, f"{input_file}.svg")
|
||||
with open(theme_svg_path, 'w') as svg_out:
|
||||
with open(theme_svg_path, "w") as svg_out:
|
||||
svg_out.write(theme_svg)
|
||||
cell += f"<img src='previews/{input_file}.svg' width='300'>|"
|
||||
markdown.append(cell)
|
||||
|
||||
output_str = intro + "\n".join(markdown)
|
||||
with open(os.path.join(args.output_dir, "README.md"), 'w') as output:
|
||||
with open(os.path.join(args.output_dir, "README.md"), "w") as output:
|
||||
output.write(output_str)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue