-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from lib.build_app import * | ||
|
||
if __name__ == '__main__': | ||
build_app_macos('aarch64-apple-darwin', 'macos-aarch64') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from lib.build_app import * | ||
|
||
if __name__ == '__main__': | ||
build_app_macos('x86_64-apple-darwin', 'macos-x86_64') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from lib.build_app import * | ||
|
||
if __name__ == '__main__': | ||
build_app_windows('x86_64-pc-windows-msvc', 'windows-x86_64') |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
# encoding=utf8 | ||
|
||
import subprocess | ||
import platform | ||
import os | ||
import shutil | ||
import re | ||
|
||
APP_NAME = "Etcd Workbench" | ||
BUNDLE_NAME = "etcd-workbench" | ||
ENCODING = "gbk" if platform.system().lower() == 'windows' else 'utf-8' | ||
|
||
def execute(command, print_output = True): | ||
print(f"calling: {command}") | ||
subprocess.call(command, shell=True, encoding=ENCODING) | ||
|
||
def build_app_windows(target, build_platform): | ||
os.chdir('../') | ||
root_path = os.getcwd() | ||
os.chdir('./app/') | ||
app_path = os.getcwd() | ||
|
||
execute(f'pnpm tauri build --target {target}') | ||
|
||
to_dir = os.path.join(root_path, 'bin', 'app', build_platform) | ||
bundle_path = os.path.join(app_path, f'src-tauri/target/{target}/release/bundle/nsis') | ||
|
||
files = os.listdir(bundle_path) | ||
app_version = None | ||
for file in files: | ||
file_path = os.path.join(bundle_path, file) | ||
filename = None | ||
if file.endswith('.exe'): | ||
if app_version is None: | ||
app_version = re.findall(r".*(\d+\.\d+\.\d+).*", file)[0] | ||
print(f'parsed app version {app_version}') | ||
filename = f"{BUNDLE_NAME}-{app_version}-{build_platform}.exe" | ||
elif file.endswith('.nsis.zip'): | ||
if app_version is None: | ||
app_version = re.findall(r".*(\d+\.\d+\.\d+).*", file)[0] | ||
print(f'parsed app version {app_version}') | ||
filename = f"{BUNDLE_NAME}-{app_version}-{build_platform}.nsis.zip" | ||
elif file.endswith('.nsis.zip.sig'): | ||
if app_version is None: | ||
app_version = re.findall(r".*(\d+\.\d+\.\d+).*", file)[0] | ||
print(f'parsed app version {app_version}') | ||
filename = f"{BUNDLE_NAME}-{app_version}-{build_platform}.nsis.zip.sig" | ||
|
||
if filename is not None: | ||
copy_bundle_files(file_path, to_dir, filename) | ||
os.chdir('../scripts/') | ||
|
||
def build_app_macos(target, build_platform): | ||
os.chdir('../') | ||
root_path = os.getcwd() | ||
os.chdir('./app/') | ||
app_path = os.getcwd() | ||
|
||
execute(f'pnpm tauri build --target {target}') | ||
|
||
to_dir = os.path.join(root_path, 'bin', 'app', build_platform) | ||
|
||
dmg_bg_file = os.path.join(app_path, f'src-tauri/icons/macos/dmg-bg.png') | ||
dmg_icon_file = os.path.join(app_path, f'src-tauri/icons/macos/icon.icns') | ||
macos_path = os.path.join(app_path, f'src-tauri/target/{target}/release/bundle/macos') | ||
dmg_path = os.path.join(app_path, f'src-tauri/target/{target}/release/bundle/dmg') | ||
|
||
app_version = None | ||
for file in os.listdir(dmg_path): | ||
if file.endswith(".dmg"): | ||
app_version = re.findall(r".*(\d+\.\d+\.\d+).*", file)[0] | ||
print(f'parsed app version {app_version}') | ||
break | ||
|
||
app_file = None | ||
for file in os.listdir(macos_path): | ||
|
||
file_path = os.path.join(macos_path, file) | ||
|
||
if file.endswith('.app'): | ||
app_file = file_path | ||
continue | ||
|
||
filename = None | ||
|
||
if file.endswith('.app.tar.gz'): | ||
filename = f"{BUNDLE_NAME}-{app_version}-{build_platform}.app.tar.gz" | ||
elif file.endswith('.app.tar.gz.sig'): | ||
filename = f"{BUNDLE_NAME}-{app_version}-{build_platform}.app.tar.gz.sig" | ||
|
||
if filename is not None: | ||
copy_bundle_files(file_path, to_dir, filename) | ||
|
||
dmg_file = os.path.join(to_dir, f"{BUNDLE_NAME}-{app_version}-{build_platform}.dmg") | ||
create_dmg_cmd = f""" | ||
create-dmg \\ | ||
--volname "{APP_NAME}" \\ | ||
--volicon "{dmg_icon_file}" \\ | ||
--background "{dmg_bg_file}" \\ | ||
--window-pos 200 200 \\ | ||
--window-size 900 600 \\ | ||
--icon-size 128 \\ | ||
--icon "{APP_NAME}" 232 338 \\ | ||
--hide-extension "{APP_NAME}" \\ | ||
--app-drop-link 688 338 \\ | ||
"{dmg_file}" \\ | ||
"{app_file}" | ||
""" | ||
|
||
execute(create_dmg_cmd) | ||
print(f'create dmg: {dmg_file}') | ||
|
||
def copy_bundle_files(from_file, to_dir, filename): | ||
|
||
if not os.path.exists(to_dir): | ||
os.makedirs(to_dir) | ||
|
||
to_file = os.path.join(to_dir, filename) | ||
shutil.copyfile(from_file, to_file) | ||
|
||
print(f'copied file {to_file}') |