Skip to content

Commit

Permalink
Add copy files script for parsing and assets copy (#4)
Browse files Browse the repository at this point in the history
* parsing script

* resolve comments

* assets

* creative upscale update metadata as well

* resolve comments
  • Loading branch information
weiyanlin117 authored Jun 3, 2024
1 parent 1363d04 commit 89be775
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/json.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
mkdir -p docs
mkdir -p docs/scripts
mv *.json ./docs
find scripts -type f -name "*.js" -exec cp {} ./docs/scripts \;
python3 utils/copy_js_and_assets.py
echo "scripts.drawthings.ai" > ./docs/CNAME
- name: Add and commit documentation
Expand Down
Binary file added scripts/creative-upscale/assets/tree-after.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added scripts/creative-upscale/assets/tree-before.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 8 additions & 2 deletions scripts/creative-upscale/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@
"description": "Generate up to 4x upscaled image from the input with crisp details.",
"tags": [
"image-to-image"
]
}
],
"baseColor": "0x00CC82",
"images": [
{"url": "https://scripts.drawthings.ai/creative-upscale/assets/tree-after.jpg", "tags":["id:tree", "view:after"] },
{"url": "https://scripts.drawthings.ai/creative-upscale/assets/tree-before.jpeg", "tags":["id:tree", "view:before"] }
],
"favicon": "data:image/png;base64,data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEgAAABIBAMAAACnw650AAAAG1BMVEUAAAD////////////////////////////////rTT7CAAAACXRSTlMA/rebJRBsRd+IYbvdAAABRklEQVR4nO2VPU/DMBRFrcSwu+VrTEFijifWdGOECUbo0L1C/AAk+N8kvs+p30eijh1yh1TPPT1x4lfbuSXnm9090qH0VD6WzGWgXKN+z3VbQFUevEV9yHVjQX+oX6eglZzTxoDW8mGidbuWM7U5J6GKGlpthKoX9WMCqoSqFzUKclw1iJyGuGoQGRBTJZEFlaoksqBCBZEJHVUQmdCoIpGA/M8VWPTKJ73q59AVkHt7cfjpGlASuYtvZ6QKybhlt1HZJ79/mmOWnJivbrj6/RxT52VprW9pgWO4wQf6ii+wD78QATpQX23vugKipqOGHFvU6szckGOLWlAc//ukMqCjKKsMKBabCFQaKkWk0lBku1FSKYiLoFIQF0EloSBESWXsmQ2H1FilRVAp6JTN3jyATGjuAKqnDqCPcpITh+KDfJglZ5R/PoY5CcXic14AAAAASUVORK5CYII="
}
49 changes: 49 additions & 0 deletions utils/copy_js_and_assets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import os
import shutil
import json

# Define the paths
scripts_dir = 'scripts' # Replace with the path to your scripts directory
docs_dir = 'docs' # Replace with the path to your docs directory

# Ensure the destination directory exists
if not os.path.exists(docs_dir):
os.makedirs(docs_dir)

for subdir in os.listdir(scripts_dir):
subdir_path = os.path.join(scripts_dir, subdir)

if os.path.isdir(subdir_path):
metadata_path = os.path.join(subdir_path, 'metadata.json')

# Check if metadata.json exists in the subdirectory
if os.path.isfile(metadata_path):
with open(metadata_path, 'r') as f:
metadata = json.load(f)

# Get the script file name from metadata.json
js_file_name = metadata.get('file') # Get the file name from the 'file' key
if js_file_name:
js_file_path = os.path.join(subdir_path, js_file_name)

# Copy the .js file to docs directory
if os.path.isfile(js_file_path):
shutil.copy(js_file_path, docs_dir)

# Copy the assets directory
assets_src_dir = os.path.join(subdir_path, 'assets')
assets_dst_dir = os.path.join(docs_dir, subdir, 'assets')

if os.path.isdir(assets_src_dir):
# Create the destination directory if it doesn't exist
os.makedirs(assets_dst_dir, exist_ok=True)

# Copy the assets directory
for item in os.listdir(assets_src_dir):
s = os.path.join(assets_src_dir, item)
d = os.path.join(assets_dst_dir, item)
if os.path.isdir(s):
shutil.copytree(s, d, dirs_exist_ok=True)
else:
shutil.copy2(s, d)

0 comments on commit 89be775

Please sign in to comment.