Skip to content

Commit

Permalink
ZIP plugin files for easy use
Browse files Browse the repository at this point in the history
  • Loading branch information
saertna committed Nov 27, 2023
1 parent 2e9f352 commit b41aa01
Showing 1 changed file with 40 additions and 21 deletions.
61 changes: 40 additions & 21 deletions preprelease.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
import os
import json
import shutil
import zipfile
from urllib.parse import urlparse


def zip_files(source_folder, output_zip_path, files_to_zip):
with zipfile.ZipFile(output_zip_path, 'w') as zip_file:
for file_to_zip in files_to_zip:
file_path = os.path.join(source_folder, file_to_zip)
zip_file.write(file_path, arcname=file_to_zip)



def get_current_version_from_link(content):
link_start = content.find('https://github.com/saertna/obsidian-gamified-pkm/releases/tag/')
if link_start == -1:
return None
link_start = content.find('https://github.com/saertna/obsidian-gamified-pkm/releases/tag/')
if link_start == -1:
return None

link_end = content.find(')', link_start)
if link_end == -1:
link_end = content.find(']', link_start)
if link_end == -1:
link_end = len(content)
link_end = content.find(')', link_start)
if link_end == -1:
link_end = content.find(']', link_start)
if link_end == -1:
link_end = len(content)

link = content[link_start:link_end]
parsed_url = urlparse(link)
path_parts = parsed_url.path.split('/')
current_version = path_parts[-1]
return current_version
link = content[link_start:link_end]
parsed_url = urlparse(link)
path_parts = parsed_url.path.split('/')
current_version = path_parts[-1]
return current_version


def update_readme_version(readme_path, new_version):
Expand Down Expand Up @@ -49,13 +58,13 @@ def update_json_version(file_path, new_version):
with open(file_path, 'w') as json_file:
json.dump(data, json_file, indent=2)

def zip_files(source_folder, output_zip_path):
with shutil.ZipFile(output_zip_path, 'w') as zip_file:
for root, dirs, files in os.walk(source_folder):
for file in files:
file_path = os.path.join(root, file)
arcname = os.path.relpath(file_path, source_folder)
zip_file.write(file_path, arcname=arcname)
#def zip_files(source_folder, output_zip_path):
# with shutil.ZipFile(output_zip_path, 'w') as zip_file:
# for root, dirs, files in os.walk(source_folder):
# for file in files:
# file_path = os.path.join(root, file)
# arcname = os.path.relpath(file_path, source_folder)
# zip_file.write(file_path, arcname=arcname)

def main(new_version):
plugin_folder = '.'
Expand All @@ -75,7 +84,17 @@ def main(new_version):
# Zip files
files_to_zip = ['main.js', 'manifest.json', 'styles.css']
zip_folder = os.path.join(plugin_folder, f'obsidian-gamified-pkm.zip')
zip_files(plugin_folder, zip_folder)
zip_files(plugin_folder, zip_folder, files_to_zip)

# Move the zip archive to the 'install-zip' subfolder
install_zip_folder = os.path.join(plugin_folder, 'obsidian-gamified-pkm')
os.makedirs(install_zip_folder, exist_ok=True)

# Create the new path for the zip archive in the 'install-zip' folder
new_zip_path = os.path.join(install_zip_folder, f'obsidian-gamified-pkm.zip')

# Move the zip archive
shutil.move(zip_folder, new_zip_path)

if __name__ == "__main__":
new_version = input("Enter the new version: ")
Expand Down

0 comments on commit b41aa01

Please sign in to comment.