From f6a4bae8c6069c3fc489cfbc7f430210b22e536c Mon Sep 17 00:00:00 2001 From: Luis Pater Date: Wed, 1 Oct 2025 01:57:53 +0800 Subject: [PATCH] add auto release script --- .github/workflows/release.yml | 61 + .gitignore | 22 + BUILD_RELEASE.md | 69 ++ build-scripts/prepare-html.js | 30 + bundle-entry.js | 25 + package-lock.json | 2074 ++++++++++++++++++++++++++++++++- package.json | 16 +- webpack.config.js | 64 + 8 files changed, 2356 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 .gitignore create mode 100644 BUILD_RELEASE.md create mode 100644 build-scripts/prepare-html.js create mode 100644 bundle-entry.js create mode 100644 webpack.config.js diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..1fb3087 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,61 @@ +name: Build and Release + +on: + push: + tags: + - 'v*' + +jobs: + build-and-release: + runs-on: ubuntu-latest + + permissions: + contents: write + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Build all-in-one HTML + run: npm run build + + - name: Prepare release assets + run: | + cd dist + mv index.html cli-proxy-api-management-center.html + ls -lh cli-proxy-api-management-center.html + + - name: Create Release + uses: softprops/action-gh-release@v1 + with: + files: dist/cli-proxy-api-management-center.html + body: | + ## CLI Proxy API Management Center - ${{ github.ref_name }} + + ### Download and Usage + 1. Download the `cli-proxy-api-management-center.html` file + 2. Open it directly in your browser + 3. All assets (CSS, JavaScript, images) are bundled into this single file + + ### Features + - Single file, no external dependencies required + - Complete management interface for CLI Proxy API + - Support for local and remote connections + - Multi-language support (Chinese/English) + - Dark/Light theme support + + --- + 🤖 Generated with GitHub Actions + draft: false + prerelease: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..400ba2d --- /dev/null +++ b/.gitignore @@ -0,0 +1,22 @@ +# Node modules +node_modules/ + +# Build output +dist/ + +# Temporary build files +index.build.html + +# npm lock files +package-lock.json + +# IDE and editor files +.vscode/ +.idea/ +*.swp +*.swo +*~ + +# OS files +.DS_Store +Thumbs.db diff --git a/BUILD_RELEASE.md b/BUILD_RELEASE.md new file mode 100644 index 0000000..6250e05 --- /dev/null +++ b/BUILD_RELEASE.md @@ -0,0 +1,69 @@ +# Build and Release Instructions + +## Overview + +This project uses webpack to bundle all HTML, CSS, JavaScript, and images into a single all-in-one HTML file. The GitHub workflow automatically builds and releases this file when you create a new tag. + +## How to Create a Release + +1. Make sure all your changes are committed +2. Create and push a new tag: + ```bash + git tag v1.0.0 + git push origin v1.0.0 + ``` +3. The GitHub workflow will automatically: + - Install dependencies + - Build the all-in-one HTML file using webpack + - Create a new release with the tag + - Upload the bundled HTML file to the release + +## Manual Build + +To build locally: + +```bash +# Install dependencies +npm install + +# Build the all-in-one HTML file +npm run build +``` + +The output will be in the `dist/` directory as `index.html`. + +## How It Works + +1. **build-scripts/prepare-html.js**: Pre-build script + - Reads the original `index.html` + - Removes local CSS and JavaScript references + - Generates temporary `index.build.html` for webpack + +2. **webpack.config.js**: Configures webpack to bundle all assets + - Uses `style-loader` to inline CSS + - Uses `asset/inline` to embed images as base64 + - Uses `html-inline-script-webpack-plugin` to inline JavaScript + - Uses `index.build.html` as template (generated dynamically) + +3. **bundle-entry.js**: Entry point that imports all resources + - Imports CSS files + - Imports JavaScript modules + - Imports and sets logo image + +4. **package.json scripts**: + - `prebuild`: Automatically runs before build to generate `index.build.html` + - `build`: Runs webpack to bundle everything + - `postbuild`: Cleans up temporary `index.build.html` file + +5. **.github/workflows/release.yml**: GitHub workflow + - Triggers on tag push + - Builds the project (prebuild → build → postbuild) + - Creates a release with the bundled HTML file + +## External Dependencies + +The bundled HTML file still relies on these CDN resources: +- Font Awesome (icons) +- Chart.js (charts and graphs) + +These are loaded from CDN to keep the file size reasonable and leverage browser caching. diff --git a/build-scripts/prepare-html.js b/build-scripts/prepare-html.js new file mode 100644 index 0000000..e3f92d8 --- /dev/null +++ b/build-scripts/prepare-html.js @@ -0,0 +1,30 @@ +const fs = require('fs'); +const path = require('path'); + +// Read the original index.html +const indexPath = path.resolve(__dirname, '../index.html'); +const outputPath = path.resolve(__dirname, '../index.build.html'); + +let htmlContent = fs.readFileSync(indexPath, 'utf8'); + +// Remove local CSS reference +htmlContent = htmlContent.replace( + /\n?/g, + '' +); + +// Remove local JavaScript references +htmlContent = htmlContent.replace( + /