From a93db4eb9f416cac029f540ab121cff0cd639f79 Mon Sep 17 00:00:00 2001 From: "web@ppanel" Date: Sat, 28 Dec 2024 23:24:40 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20chore:=20Update=20changelog,=20e?= =?UTF-8?q?nhance=20prepare=20script,=20and=20add=20openapi=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 4 +- apps/admin/services/admin/index.ts | 2 +- package.json | 1 + scripts/prepare.sh | 76 +++++++++++++++++++++--------- 4 files changed, 59 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd82dea..1e770c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,12 @@ + # Changelog # [1.0.0-beta.3](https://github.com/perfect-panel/ppanel-web/compare/v1.0.0-beta.2...v1.0.0-beta.3) (2024-12-26) - ### ♻ Code Refactoring -* **config**: Simplify environment variable handling and improve build script ([cf54d0f](https://github.com/perfect-panel/ppanel-web/commit/cf54d0f)) +- **config**: Simplify environment variable handling and improve build script ([cf54d0f](https://github.com/perfect-panel/ppanel-web/commit/cf54d0f)) diff --git a/apps/admin/services/admin/index.ts b/apps/admin/services/admin/index.ts index 32cbdf0..944988e 100644 --- a/apps/admin/services/admin/index.ts +++ b/apps/admin/services/admin/index.ts @@ -1,5 +1,5 @@ // @ts-ignore - + // API 更新时间: // API 唯一标识: import * as announcement from './announcement'; diff --git a/package.json b/package.json index 4546a1e..5a56302 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "dev": "turbo dev", "lint": "turbo lint", "locale": "turbo locale && bun prettier", + "openapi": "turbo openapi && bun prettier", "prepare": "./scripts/prepare.sh", "prettier": "prettier --write \"**/*.{ts,tsx,js,jsx,cjs,mjs,md,json}\"", "release": "semantic-release", diff --git a/scripts/prepare.sh b/scripts/prepare.sh index 1a7d294..1c81242 100755 --- a/scripts/prepare.sh +++ b/scripts/prepare.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Skip entire script in CI environment +# Skip script in CI environment if [ "$CI" = "true" ]; then echo "CI environment detected, skipping script execution." exit 0 @@ -12,28 +12,39 @@ if [ ! -d ".git" ]; then exit 1 fi +# Check if .husky folder exists and skip `npx husky install` if it does +if [ -d ".husky" ]; then + echo ".husky folder already exists. Skipping npx husky install." +else + echo "Setting up Husky..." + if npx husky; then + echo "Husky has been successfully set up." + else + echo "Failed to set up Husky. Skipping." + exit 1 + fi +fi + # Function to set up a Husky hook setup_husky_hook() { local hook_name=$1 local hook_content=$2 + local hook_file=".husky/$hook_name" - if [ ! -f ".husky/$hook_name" ]; then - echo "Setting up $hook_name hook..." - echo "$hook_content" > ".husky/$hook_name" || echo "Failed to set up $hook_name hook. Skipping." - chmod +x ".husky/$hook_name" || echo "Failed to make $hook_name hook executable. Skipping." + if [ -f "$hook_file" ]; then + echo "$hook_name hook is already set up. Skipping." + return + fi + + echo "Setting up $hook_name hook..." + echo "$hook_content" > "$hook_file" && chmod +x "$hook_file" + if [ $? -eq 0 ]; then + echo "$hook_name hook has been successfully set up." else - echo "$hook_name hook is already set up." + echo "Failed to set up $hook_name hook. Skipping." fi } -# Ensure Husky is installed and initialized -if [ ! -d ".husky" ]; then - echo "Setting up Husky..." - npx husky || echo "Failed to set up Husky. Skipping." -else - echo "Husky is already set up." -fi - # Set up pre-commit hook setup_husky_hook "pre-commit" "#!/bin/sh . \"\$(dirname \"\$0\")/_/husky.sh\" @@ -50,11 +61,16 @@ npx --no-install commitlint --edit \"\$1\"" install_global_package() { local package_name=$1 - if ! npm list -g --depth=0 "$package_name" > /dev/null 2>&1; then - echo "Installing $package_name globally..." - npm install -g "$package_name" || echo "Failed to install $package_name globally. Skipping." + if npm list -g --depth=0 "$package_name" > /dev/null 2>&1; then + echo "$package_name is already installed. Skipping installation." + return + fi + + echo "Installing $package_name globally..." + if npm install -g "$package_name"; then + echo "$package_name has been successfully installed." else - echo "$package_name is already installed." + echo "Failed to install $package_name globally. Skipping." fi } @@ -62,6 +78,24 @@ install_global_package() { install_global_package "@lobehub/i18n-cli" install_global_package "@lobehub/commit-cli" -# Run lobe-commit interactively -echo "Running lobe-commit -i..." -lobe-commit -i || echo "lobe-commit failed. Skipping." +# Check if .husky/_/prepare-commit-msg exists +if [ -f ".husky/_/prepare-commit-msg" ]; then + echo "prepare-commit-msg hook already exists. Skipping lobe-commit -i." +else + # If the hook does not exist, set it up and run lobe-commit -i + echo "Setting up prepare-commit-msg hook..." + if npx husky add .husky/prepare-commit-msg "exec < /dev/tty && npx lobe-commit -i"; then + echo "prepare-commit-msg hook has been successfully set up." + + # Run lobe-commit interactively + echo "Running lobe-commit -i..." + if lobe-commit -i; then + echo "lobe-commit executed successfully." + else + echo "lobe-commit failed. Skipping." + fi + else + echo "Failed to set up prepare-commit-msg hook. Skipping lobe-commit." + exit 1 + fi +fi