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]:
|
def get_all_input_files(input_dir: str) -> List[str]:
|
||||||
filenames = next(os.walk(input_dir), (None, None, []))[2]
|
filenames = next(os.walk(input_dir), (None, None, []))[2]
|
||||||
files = filter(lambda f: (f.endswith("yaml")
|
files = filter(lambda f: (f.endswith("yaml") or f.endswith("yml")), filenames)
|
||||||
or f.endswith("yml")), filenames)
|
|
||||||
return list(files)
|
return list(files)
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,14 +16,16 @@ def ensure_output_dir(output_dir: str):
|
||||||
os.makedirs(output_dir)
|
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:
|
if not prefix:
|
||||||
prefix = ""
|
prefix = ""
|
||||||
output[f"{prefix}{key}"] = obj[key]
|
output[f"{prefix}{key}"] = obj[key]
|
||||||
|
|
||||||
|
|
||||||
def get_color_dict(input_dir: str, file_name: str) -> Dict[str, str]:
|
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)
|
loaded_theme = yaml.safe_load(file)
|
||||||
output = {}
|
output = {}
|
||||||
add_color_to_dict(output, loaded_theme, "accent")
|
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:
|
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("_")
|
split = file_name.split("_")
|
||||||
output = []
|
output = []
|
||||||
|
@ -62,14 +63,16 @@ def gen_svg_for_theme(color_dict: Dict[str, str], svg_template: str) -> str:
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description='Generate README.md with embedded SVG previews.')
|
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(
|
||||||
parser.add_argument('output_dir', type=str, help='Where to save README.md')
|
"input_dir", type=str, help="Directory from which to read in all Warp themes."
|
||||||
parser.add_argument("svg_path", type=str,
|
)
|
||||||
help="Path to svg template file.")
|
parser.add_argument("output_dir", type=str, help="Where to save README.md")
|
||||||
parser.add_argument("intro_file", type=str,
|
parser.add_argument("svg_path", type=str, help="Path to svg template file.")
|
||||||
help="What should go on top of README.md.")
|
parser.add_argument(
|
||||||
|
"intro_file", type=str, help="What should go on top of README.md."
|
||||||
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
ensure_output_dir(args.output_dir)
|
ensure_output_dir(args.output_dir)
|
||||||
|
@ -78,11 +81,11 @@ def main():
|
||||||
markdown = []
|
markdown = []
|
||||||
markdown.append("|Theme name | Preview|")
|
markdown.append("|Theme name | Preview|")
|
||||||
markdown.append("| --- | --- |")
|
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")
|
svg_dir = os.path.join(args.output_dir, "previews")
|
||||||
os.makedirs(svg_dir, exist_ok=True)
|
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):
|
for input_file in sorted(filenames):
|
||||||
print(f"Generating for {input_file}")
|
print(f"Generating for {input_file}")
|
||||||
|
@ -90,13 +93,13 @@ def main():
|
||||||
color_dict = get_color_dict(args.input_dir, input_file)
|
color_dict = get_color_dict(args.input_dir, input_file)
|
||||||
theme_svg = gen_svg_for_theme(color_dict, svg)
|
theme_svg = gen_svg_for_theme(color_dict, svg)
|
||||||
theme_svg_path = os.path.join(svg_dir, f"{input_file}.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)
|
svg_out.write(theme_svg)
|
||||||
cell += f"<img src='previews/{input_file}.svg' width='300'>|"
|
cell += f"<img src='previews/{input_file}.svg' width='300'>|"
|
||||||
markdown.append(cell)
|
markdown.append(cell)
|
||||||
|
|
||||||
output_str = intro + "\n".join(markdown)
|
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)
|
output.write(output_str)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 145">
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 145">
|
||||||
<rect width="300" height="145" class="Dynamic" fill="{background}" rx="5" />
|
<rect width="300" height="145" class="Dynamic" fill="{background}" rx="5" />
|
||||||
|
|
||||||
<!-- first command -->
|
<!-- first command -->
|
||||||
<text x="15" y="15" fill="{foreground}" font-size="0.6em" font-family="monospace" class="Dynamic">ls</text>
|
<text x="15" y="15" fill="{foreground}" font-size="0.6em" font-family="monospace" class="Dynamic">ls</text>
|
||||||
|
@ -88,4 +88,3 @@ git(
|
||||||
<!-- cursor -->
|
<!-- cursor -->
|
||||||
<line x1="15" y1="120" x2="15" y2="130" style="stroke-width:2" class="Dynamic" stroke="{accent}" />
|
<line x1="15" y1="120" x2="15" y2="130" style="stroke-width:2" class="Dynamic" stroke="{accent}" />
|
||||||
</svg>
|
</svg>
|
||||||
|
|
||||||
|
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.5 KiB |
Loading…
Add table
Add a link
Reference in a new issue