Skip to content

Commit

Permalink
feat: generate casts in storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
cfoust committed Jan 12, 2024
1 parent 64fb6bd commit a7dba83
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
2 changes: 2 additions & 0 deletions docs/src/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ If your terminal is wider than 80 columns, you'll notice that the pane does not

All actions in `cy`, such as creating panes and switching between them, are triggered by sequences of keys.

{{story cast cy/viewport}}

Here are a few you can try:

1. To make the pane fill the entire viewport, type `ctrl+a` `g`. (Repeat to center it again.)
Expand Down
25 changes: 17 additions & 8 deletions docs/storybook.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import sys
from pathlib import Path

STORY_REGEX = re.compile("{{story ((\w+).)?(png|gif) (.+)}}")
STORY_REGEX = re.compile("{{story ((\w+).)?(png|gif|cast) (.+)}}")

COMMON = """
Set FontSize 15
Set FontSize 18
Set Width 1300
Set Height 650
Set Padding 0
Expand Down Expand Up @@ -57,14 +57,20 @@ def transform_chapter(chapter):
h.update(command.encode('utf-8'))
filename = h.hexdigest()[:12]

original = filename

filename += "." + type_
filename = "images/" + filename

replacement = f"![{command}]({filename})"
if filename.endswith("cast"):
replacement = f"<div data-cast=\"{original}\"></div>"

replace.append(
(
ref.start(0),
ref.end(0),
f"![{command}]({filename})",
replacement,
)
)

Expand Down Expand Up @@ -107,7 +113,7 @@ def transform_chapter(chapter):
Enter
Sleep 500ms
Show
Sleep 8s
Sleep 15s
"""
elif filename.endswith(".png"):
script = f"""
Expand All @@ -120,6 +126,12 @@ def transform_chapter(chapter):
Sleep 1s
Screenshot {filename}
"""
elif filename.endswith(".cast"):
subprocess.check_call(
f"./storybook --cast {filename} -s {command}",
shell=True
)
continue

tape = (
filename.replace("png", "tape")
Expand All @@ -133,14 +145,11 @@ def transform_chapter(chapter):
vhs = "./vhs"

while not os.path.exists(filename):
code = subprocess.call(
subprocess.check_call(
f"{vhs} -q {tape}",
shell=True
)

if code != 0:
raise Exception(code)

os.unlink(tape)
if not os.path.exists(filename):
raise Exception(f"failed to produce {filename}")
Expand Down

0 comments on commit a7dba83

Please sign in to comment.