Merge pull request #558 from kidylee/master

refractory build script
This commit is contained in:
Tw93
2023-08-27 16:47:55 +08:00
committed by GitHub
15 changed files with 454 additions and 638 deletions

View File

@@ -1,85 +0,0 @@
name: Build App
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'V*'
jobs:
build:
name: build
runs-on: ${{ matrix.os }}
strategy:
matrix:
build: [linux, windows, macos]
include:
- build: linux
os: ubuntu-20.04
rust: stable
target: x86_64-unknown-linux-musl
- build: windows
os: windows-latest
rust: stable-x86_64-msvc
target: x86_64-pc-windows-msvc
- build: macos
os: macos-latest
rust: stable
target: x86_64-apple-darwin
fail-fast: false
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: install node
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
- name: install dependencies (ubuntu only)
if: matrix.os == 'ubuntu-20.04'
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: libwebkit2gtk-4.0-dev build-essential curl wget libssl-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev gnome-video-effects gnome-video-effects-extra
version: 1.1
- name: rust cache restore
uses: actions/cache/restore@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
src-tauri/target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: build for Ubuntu
if: matrix.os == 'ubuntu-20.04'
run: npm run build:all-unix
- name: build for MacOS
if: matrix.os == 'macos-latest'
run: |
rustup target add aarch64-apple-darwin
npm run build:all-unix
- name: build for windows
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
npm run build:all-windows
- name: Upload files
# arg info: https://github.com/ncipollo/release-action#release-action
uses: ncipollo/release-action@v1
with:
allowUpdates: true
artifacts: 'output/*/*.*'
token: ${{ secrets.GITHUB_TOKEN }}

36
.github/workflows/pake_build_next.yaml vendored Normal file
View File

@@ -0,0 +1,36 @@
name: Build App Next
on:
push:
tags:
- "V*"
jobs:
read_apps_config:
name: Read Apps Config
runs-on: ubuntu-latest
outputs:
apps_name: ${{ steps.read-apps-config.outputs.apps_name }}
apps_config: ${{ steps.read-apps-config.outputs.apps_config }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Get Apps Config
id: read-apps-config
run: |
echo "apps_name=$(jq -c '[.apps| .[] | .name]' apps.conf.json)" >> $GITHUB_OUTPUT
echo "apps_config=$(jq -c '[.apps | .[]]' apps.conf.json)" >> $GITHUB_OUTPUT
trigger_build:
needs: read_apps_config
name: ${{ matrix.title }}
strategy:
matrix:
name: ${{ fromJson(needs.read_apps_config.outputs.apps_name) }}
include: ${{ fromJSON(needs.read_apps_config.outputs.apps_config) }}
uses: ./.github/workflows/pake_build_single_app.yaml@master
with:
name: ${{ matrix.name }}
title: ${{ matrix.title }}
name_zh: ${{ matrix.name_zh }}
url: ${{ matrix.url }}

View File

@@ -0,0 +1,160 @@
name: Build Single App
on:
workflow_dispatch:
inputs:
name:
description: "app name"
required: true
default: "twitter"
title:
description: "app title"
required: true
default: "Twitter"
name_zh:
description: "app name in Chinese"
required: true
default: "推特"
url:
description: "app url"
required: true
default: "https://twitter.com/"
workflow_call:
inputs:
name:
description: "app name"
type: string
required: true
default: "twitter"
title:
description: "app title"
required: true
type: string
default: "Twitter"
name_zh:
description: "app name in Chinese"
required: true
type: string
default: "推特"
url:
description: "app url"
required: true
type: string
default: "https://twitter.com/"
jobs:
build_single_app:
name: ${{ inputs.title }} (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
build: [linux, macos, windows]
include:
- build: linux
os: ubuntu-latest
rust: stable
target: x86_64-unknown-linux-musl
- build: windows
os: windows-latest
rust: stable-x86_64-msvc
target: x86_64-pc-windows-msvc
- build: macos
os: macos-latest
rust: stable
target: x86_64-apple-darwin
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
- name: install dependencies (ubuntu only)
if: matrix.os == 'ubuntu-latest'
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: libwebkit2gtk-4.0-dev build-essential curl wget libssl-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev gnome-video-effects gnome-video-effects-extra
version: 1.1
- name: rust cache restore
id: cache_store
uses: actions/cache/restore@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
src-tauri/target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Config App
env:
NAME: ${{ inputs.name }}
TITLE: ${{ inputs.title }}
NAME_ZH: ${{ inputs.name_zh }}
URL: ${{ inputs.url }}
run: |
npm install
npm run build:app:config
- name: Build for Ubuntu
if: matrix.os == 'ubuntu-latest'
run: |
npm run tauri build
mkdir -p output/linux
mv src-tauri/target/release/bundle/deb/*.deb output/linux/${{inputs.title}}_`arch`.deb
mv src-tauri/target/release/bundle/appimage/*.AppImage output/linux/"${{inputs.title}}"_`arch`.AppImage
- name: Build for Macos
if: matrix.os == 'macos-latest'
run: |
rustup target add aarch64-apple-darwin
rustup target add x86_64-apple-darwin
npm run tauri build -- --target universal-apple-darwin
mkdir -p output/macos
mv src-tauri/target/universal-apple-darwin/release/bundle/dmg/*.dmg output/macos/"${{inputs.title}}".dmg
- name: Build for Windows
if: matrix.os == 'windows-latest'
run: |
npm run tauri build -- --target x86_64-pc-windows-msvc
New-Item -Path "output\windows" -ItemType Directory
Move-Item -Path "src-tauri\target\x86_64-pc-windows-msvc\release\bundle\msi\*.msi" -Destination "output\windows\${{inputs.title}}_x64.msi"
- name: Restore Cargo Lock File(Windows Only)
if: matrix.os == 'windows-latest'
run: |
git checkout -- src-tauri/Cargo.lock
- name: rust cache store
uses: actions/cache/save@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
src-tauri/target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Upload For Single Build
uses: actions/upload-artifact@v3
if: startsWith(github.ref, 'refs/tags/') != true
with:
path: "output/*/*.*"
- name: Upload For Release
# arg info: https://github.com/ncipollo/release-action#release-action
uses: ncipollo/release-action@v1
if: startsWith(github.ref, 'refs/tags/') == true
with:
allowUpdates: true
artifacts: "output/*/*.*"
token: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -1,110 +0,0 @@
name: Build App with Cache
on:
workflow_dispatch:
inputs:
version:
description: 'tag version'
required: true
default: 'V0.0.1'
is_pre_release:
description: 'pre-release or release, if true, is pre-release'
required: true
type: boolean
default: true
jobs:
build:
name: build
runs-on: ${{ matrix.os }}
strategy:
matrix:
build: [linux, windows, macos]
include:
- build: linux
os: ubuntu-20.04
rust: stable
target: x86_64-unknown-linux-musl
# archive-name: target-linux.tar.gz
- build: windows
os: windows-latest
rust: stable-x86_64-msvc
target: x86_64-pc-windows-msvc
# archive-name: target-windows.tar.gz
- build: macos
os: macos-latest
rust: stable
target: x86_64-apple-darwin
# archive-name: target-macos.tar.gz
fail-fast: false
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: install node
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
- name: install dependencies (ubuntu only)
if: matrix.os == 'ubuntu-20.04'
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: libwebkit2gtk-4.0-dev build-essential curl wget libssl-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev gnome-video-effects gnome-video-effects-extra
version: 1.1
- name: rust cache restore
uses: actions/cache/restore@v3
id: cache_store
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
src-tauri/target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: build for Ubuntu
if: matrix.os == 'ubuntu-20.04'
run: npm run build:all-unix
- name: build for MacOS
if: matrix.os == 'macos-latest'
run: |
rustup target add aarch64-apple-darwin
npm run build:all-unix
- name: build for windows
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
npm run build:all-windows
- name: Upload files
# arg info: https://github.com/ncipollo/release-action#release-action
uses: ncipollo/release-action@v1
with:
allowUpdates: true
prerelease: ${{ inputs.is_pre_release }}
artifacts: 'output/*/*.*'
tag: ${{ inputs.version }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: rust cache store
uses: actions/cache/save@v3
if: steps.cache_store.outputs.cache-hit != 'true'
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
src-tauri/target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

14
app.csv
View File

@@ -1,14 +0,0 @@
name(Linux),name(Mac/Windows),name_zh,url
programmusic,ProgramMusic,ProgramMusic,https://musicforprogramming.net/
twitter,Twitter,推特,https://twitter.com/
youtube,YouTube,YouTube,https://www.youtube.com
reference,Reference,Reference,https://quickref.me/zh-CN/
coderunner,CodeRunner,CodeRunner,https://riju.codes/
chatgpt,ChatGPT,ChatGPT,https://chat.openai.com/chat
flomo,Flomo,浮墨,https://v.flomoapp.com/mine
qwerty,Qwerty,Qwerty,https://qwerty.kaiyi.cool/
lizhi,LiZhi,李志,https://lizhi.turkyden.com/?from=pake
xiaohongshu,XiaoHongShu,小红书,https://www.xiaohongshu.com/explore
poe,Poe,Poe,https://poe.com/
youtubemusic,YouTubeMusic,YouTubeMusic,https://music.youtube.com/
weread,WeRead,微信阅读,https://weread.qq.com/
1 name(Linux) name(Mac/Windows) name_zh url
2 programmusic ProgramMusic ProgramMusic https://musicforprogramming.net/
3 twitter Twitter 推特 https://twitter.com/
4 youtube YouTube YouTube https://www.youtube.com
5 reference Reference Reference https://quickref.me/zh-CN/
6 coderunner CodeRunner CodeRunner https://riju.codes/
7 chatgpt ChatGPT ChatGPT https://chat.openai.com/chat
8 flomo Flomo 浮墨 https://v.flomoapp.com/mine
9 qwerty Qwerty Qwerty https://qwerty.kaiyi.cool/
10 lizhi LiZhi 李志 https://lizhi.turkyden.com/?from=pake
11 xiaohongshu XiaoHongShu 小红书 https://www.xiaohongshu.com/explore
12 poe Poe Poe https://poe.com/
13 youtubemusic YouTubeMusic YouTubeMusic https://music.youtube.com/
14 weread WeRead 微信阅读 https://weread.qq.com/

82
apps.conf.json Normal file
View File

@@ -0,0 +1,82 @@
{
"apps": [
{
"name": "programmusic",
"title": "ProgramMusic",
"name_zh": "ProgramMusic",
"url": "https://musicforprogramming.net/"
},
{
"name": "twitter",
"title": "Twitter",
"name_zh": "推特",
"url": "https://twitter.com/"
},
{
"name": "youtube",
"title": "YouTube",
"name_zh": "YouTube",
"url": "https://www.youtube.com"
},
{
"name": "reference",
"title": "Reference",
"name_zh": "Reference",
"url": "https://quickref.me/zh-CN/"
},
{
"name": "coderunner",
"title": "CodeRunner",
"name_zh": "CodeRunner",
"url": "https://riju.codes/"
},
{
"name": "chatgpt",
"title": "ChatGPT",
"name_zh": "ChatGPT",
"url": "https://chat.openai.com/chat"
},
{
"name": "flomo",
"title": "Flomo",
"name_zh": "浮墨",
"url": "https://v.flomoapp.com/mine"
},
{
"name": "qwerty",
"title": "Qwerty",
"name_zh": "Qwerty",
"url": "https://qwerty.kaiyi.cool/"
},
{
"name": "lizhi",
"title": "LiZhi",
"name_zh": "李志",
"url": "https://lizhi.turkyden.com/?from=pake"
},
{
"name": "xiaohongshu",
"title": "XiaoHongShu",
"name_zh": "小红书",
"url": "https://www.xiaohongshu.com/explore"
},
{
"name": "poe",
"title": "Poe",
"name_zh": "Poe",
"url": "https://poe.com/"
},
{
"name": "youtubemusic",
"title": "YouTubeMusic",
"name_zh": "YouTubeMusic",
"url": "https://music.youtube.com/"
},
{
"name": "weread",
"title": "WeRead",
"name_zh": "微信阅读",
"url": "https://weread.qq.com/"
}
]
}

View File

@@ -33,10 +33,9 @@
"start": "npm run dev",
"dev": "npm run tauri dev",
"build": "npm run tauri build --release",
"build:app:config": "chmod +x ./script/app_config.mjs && node ./script/app_config.mjs",
"build:debug": "npm run tauri build -- --debug",
"build:mac": "npm run tauri build -- --target universal-apple-darwin",
"build:all-unix": "chmod +x ./script/build.sh && ./script/build.sh",
"build:all-windows": "pwsh ./script/build.ps1",
"analyze": "cd src-tauri && cargo bloat --release --crates",
"tauri": "tauri",
"cli": "rollup -c rollup.config.js --watch",

174
script/app_config.mjs vendored Executable file
View File

@@ -0,0 +1,174 @@
import pakeJson from '../src-tauri/pake.json' assert { type: 'json' };
import tauriJson from '../src-tauri/tauri.conf.json' assert { type: 'json' };
import windowsJson from '../src-tauri/tauri.windows.conf.json' assert { type: 'json' };
import macosJson from '../src-tauri/tauri.macos.conf.json' assert { type: 'json' };
import linuxJson from '../src-tauri/tauri.linux.conf.json' assert { type: 'json' };
import { writeFileSync, existsSync, copyFileSync } from 'fs';
import os from 'os';
const desktopEntry = `[Desktop Entry]
Encoding=UTF-8
Categories=Office
Exec=com-pake-${process.env.NAME}
Icon=com-pake-${process.env.NAME}
Name=com-pake-${process.env.NAME}
Name[zh_CN]=${process.env.NAME_ZH}
StartupNotify=true
Terminal=false
Type=Application
`;
const variables = {
url: process.env.URL,
name: process.env.NAME,
title: process.env.TITLE,
nameZh: process.env.NAME_ZH,
pakeConfigPath: 'src-tauri/pake.json',
tauriConfigPath: 'src-tauri/tauri.conf.json',
identifier: `com.pake.${process.env.NAME}`,
linux: {
configFilePath: 'src-tauri/tauri.linux.conf.json',
iconPath: `src-tauri/png/${process.env.NAME}_512.png`,
productName: `com-pake-${process.env.NAME}`,
defaultIconPath: 'src-tauri/png/icon_512.png',
icon: [`png/${process.env.NAME}_512.png`],
desktopEntry,
desktopEntryPath: `src-tauri/assets/com-pake-${process.env.NAME}.desktop`,
desktopEntryConfig: {
configKey: `/usr/share/applications/com-pake-${process.env.NAME}.desktop`,
configValue: `assets/com-pake-${process.env.NAME}.desktop`,
},
},
macos: {
configFilePath: 'src-tauri/tauri.macos.conf.json',
iconPath: `src-tauri/icons/${process.env.NAME}.icns`,
defaultPath: 'src-tauri/icons/icon.icns',
icon: [`icons/${process.env.NAME}.icns`],
},
windows: {
configFilePath: 'src-tauri/tauri.windows.conf.json',
iconPath: `src-tauri/png/${process.env.NAME}_32.ico`,
defaultPath: 'src-tauri/png/icon_32.ico',
hdIconPath: `src-tauri/png/${process.env.NAME}_256.ico`,
hdDefaultPath: 'src-tauri/png/icon_256.ico',
icon: [`png/${process.env.NAME}_256.ico`, `png/${process.env.NAME}_32.ico`],
resources: [`png/${process.env.NAME}_32.ico`]
},
};
validate();
updatePakeJson();
updateTauriJson();
let platformVariables;
let platformConfig;
switch (os.platform()) {
case 'linux':
platformVariables = variables.linux;
platformConfig = linuxJson;
updateDesktopEntry();
break;
case 'darwin':
platformVariables = variables.macos;
platformConfig = macosJson;
break;
case 'win32':
platformConfig = windowsJson;
platformVariables = variables.windows;
updateResources()
updateIconFile(platformVariables.hdIconPath, platformVariables.hdDefaultPath);
break;
}
updateIconFile(platformVariables.iconPath, platformVariables.defaultIconPath);
updatePlatformConfig(platformConfig, platformVariables);
save();
function validate() {
if ('URL' in process.env === false) {
console.log('URL is not set');
process.exit(1);
}
console.log(`URL: ${process.env.URL}`);
if ('NAME' in process.env === false) {
console.log('NAME is not set');
process.exit(1);
}
console.log(`NAME: ${process.env.NAME}`);
if ('TITLE' in process.env === false) {
console.log('TITLE is not set');
process.exit(1);
}
console.log(`TITLE: ${process.env.TITLE}`);
if ('NAME_ZH' in process.env === false) {
console.log('NAME_ZH is not set');
process.exit(1);
}
console.log(`NAME_ZH: ${process.env.NAME_ZH}`);
}
function updatePakeJson() {
pakeJson.windows[0].url = variables.url;
}
function updateTauriJson() {
const url = new URL(variables.url);
tauriJson.tauri.security.dangerousRemoteDomainIpcAccess[0].domain = url.hostname;
tauriJson.package.productName = variables.title;
writeFileSync('src-tauri/tauri.conf.json', JSON.stringify(tauriJson, null, 2));
}
function updateIconFile(iconPath, defaultIconPath) {
if (!existsSync(iconPath)) {
console.warn(`Icon for ${process.env.NAME} not found, will use default icon`);
copyFileSync(defaultIconPath, iconPath);
}
}
function updatePlatformConfig(platformConfig, platformVariables) {
platformConfig.tauri.bundle['icon'] = platformVariables.icon;
platformConfig.tauri.bundle['identifier'] = variables.identifier;
}
function save() {
writeFileSync(variables.pakeConfigPath, JSON.stringify(pakeJson, null, 2));
writeFileSync(variables.tauriConfigPath, JSON.stringify(tauriJson, null, 2));
writeFileSync(variables.linux.configFilePath, JSON.stringify(linuxJson, null, 2));
writeFileSync(platformVariables.configFilePath, JSON.stringify(platformConfig, null, 2));
writeFileSync(variables.macos.configFilePath, JSON.stringify(macosJson, null, 2));
writeFileSync(variables.windows.configFilePath, JSON.stringify(windowsJson, null, 2));
}
function updateDesktopEntry() {
linuxJson.tauri.bundle.deb.files = {};
linuxJson.tauri.bundle.deb.files[variables.linux.desktopEntryConfig.configKey] =
variables.linux.desktopEntryConfig.configValue;
writeFileSync(variables.linux.desktopEntryPath, variables.linux.desktopEntry);
}
function updateResources(){
windowsJson.tauri.bundle.resources = variables.windows.resources;
}

99
script/build.bat vendored
View File

@@ -1,99 +0,0 @@
@echo off
chcp 65001
if not exist node_modules (
call npm i
)
if not exist output (
mkdir output
)
if not exist output\windows (
mkdir output\windows
)
echo.
echo =======================
echo "build for windows"
echo =======================
echo.
:: total package number
set /A index=1
for /f %%a in (' find /c /v "" ^<"app.csv" ') do set /A total=%%a
:: ignore first header line
set /A total=total-1
set old_name=weread
set old_title=WeRead
set old_zh_name=微信阅读
set old_url=https://weread.qq.com/
:: set init name, we will recovery code to init when build finish.
set init_name=%old_name%
set init_title=%old_title%
set init_zh_name=%old_zh_name%
set init_url=%old_url%
:: for windows, we need replace package name to title
:: .\script\sd.exe "\"productName\": \"weread\"" "\"productName\": \"WeRead\"" src-tauri\tauri.conf.json
for /f "skip=1 tokens=1-4 delims=," %%i in (app.csv) do (
setlocal enabledelayedexpansion
set name=%%i
set title=%%j
set name_zh=%%k
set url=%%l
@echo on
::echo name is !name! !name_zh! !url!
:: replace url
.\script\sd.exe -s !old_url! !url! src-tauri\pake.json
::replace package name
.\script\sd.exe !old_title! !title! src-tauri\tauri.conf.json
.\script\sd.exe !old_name! !name! src-tauri\tauri.conf.json
.\script\sd.exe !old_name! !name! src-tauri\tauri.windows.conf.json
echo.
::update package info
set old_zh_name=!name_zh!
set old_name=!name!
set old_title=!title!
set old_url=!url!
::build package
echo building package !index!/!total!
echo package name is !name! !name_zh!
echo npm run build:windows
@echo off
call npm run tauri build -- --target x86_64-pc-windows-msvc
move src-tauri\target\x86_64-pc-windows-msvc\release\bundle\msi\*.msi output\windows\!title!_x64.msi
::rm cache
del /q /f /s src-tauri\target\x86_64-pc-windows-msvc\release\*.exe
del /q /f /s src-tauri\target\x86_64-pc-windows-msvc\release\resources\*.ico
del /q /f /s src-tauri\target\x86_64-pc-windows-msvc\release\png\*.ico
del /q /f /s src-tauri\target\x86_64-pc-windows-msvc\release\wix\*.*
del /q /f /s src-tauri\target\x86_64-pc-windows-msvc\release\app.*
rd /s /q src-tauri\target\x86_64-pc-windows-msvc\release\resources
rd /s /q src-tauri\target\x86_64-pc-windows-msvc\release\png
rd /s /q src-tauri\target\x86_64-pc-windows-msvc\release\wix
@echo on
echo package build success!
echo.
echo.
set /A index=index+1
@echo off
)
:: for windows, we need replace package name to lower again
:: .\script\sd.exe "\"productName\": \"WeRead\"" "\"productName\": \"weread\"" src-tauri\tauri.conf.json
echo "output dir is output\windows"
::recovery code
.\script\sd.exe %url% %init_url% src-tauri\pake.json
.\script\sd.exe %title% %init_title% src-tauri\tauri.conf.json
.\script\sd.exe %name% %init_name% src-tauri\tauri.conf.json
.\script\sd.exe %name% %init_name% src-tauri\tauri.windows.conf.json

138
script/build.ps1 vendored
View File

@@ -1,138 +0,0 @@
chcp 65001 | Out-Null
if (-not (Test-Path node_modules)) {
npm i
}
if (-not (Test-Path output)) {
New-Item -ItemType Directory -Path output
}
if (-not (Test-Path output\windows)) {
New-Item -ItemType Directory -Path output\windows
} else {
Remove-Item output\windows -Recurse -Force
New-Item -ItemType Directory -Path output\windows
}
Write-Host "`n======================="
Write-Host "build for windows"
Write-Host "make ture powershell == 7.2.10"
Write-Host "powershell 7.2.10 download url: https://github.com/PowerShell/PowerShell/releases/tag/v7.2.10"
Write-Host "Powershell info in your localhost "
$PSVersionTable
Write-Host "=======================`n"
$identifier_prefix = "com.pake"
# total package number
$index = 1
$total = (Get-Content ./app.csv | Measure-Object -Line).Lines
$pake_conf_path = "src-tauri/pake.json"
$common_conf_path = "src-tauri/tauri.conf.json"
$windows_conf_path = "src-tauri/tauri.windows.conf.json"
# ignore first header line
$total = $total - 1
# for windows, we need replace package name to title
ForEach ($line in (Get-Content -Path .\app.csv | Select-Object -Skip 1)) {
$name, $title, $name_zh, $url = $line.Split(",")
$domain = ([Uri]$url).Host
Write-Host "building package ${index}/${total}"
Write-Host "package name is ${name} ${name_zh}"
Write-Host "=========================="
Write-Host "building Args is:"
Write-Host "name = ${name}"
Write-Host "title = ${title}"
Write-Host "name_zh = ${name_zh}"
Write-Host "url = ${url}"
Write-Host "=========================="
# -- replace url -- #
# clear url with regex
(Get-Content -Path $pake_conf_path -Raw) -replace '"url":\s*"[^"]*"', '"url": ""' | Set-Content -Path $pake_conf_path
# replace url with no regex
(Get-Content -Path $pake_conf_path -Raw) | ForEach-Object { $_.Replace('"url": ""', "`"url`": `"${url}`"") } | Set-Content $pake_conf_path
# -- replace domain -- #
(Get-Content -Path $common_conf_path -Raw) -replace '"domain":\s*"[^"]*"', '"domain": ""' | Set-Content -Path $common_conf_path
(Get-Content -Path $common_conf_path -Raw) | ForEach-Object { $_.Replace('"domain": ""', "`"domain`": `"${domain}`"") } | Set-Content $common_conf_path
# -- replace package name -- #
# clear package_name with regex
(Get-Content -Path $common_conf_path -Raw) -replace '"productName":\s*"[^"]*"', '"productName": ""' | Set-Content -Path $common_conf_path
# replace package_name with no regex
(Get-Content -Path $common_conf_path -Raw) | ForEach-Object { $_.Replace('"productName": ""', "`"productName`": `"${title}`"") } | Set-Content $common_conf_path
# -- replace systemTray iconPath -- #
# clear systemTray iconPath with regex
(Get-Content -Path $common_conf_path -Raw) -replace '"iconPath":\s*"[^"]*"', '"iconPath": ""' | Set-Content -Path $common_conf_path
# replace systemTray iconPath with no regex
(Get-Content -Path $common_conf_path -Raw) | ForEach-Object { $_.Replace('"iconPath": ""', "`"iconPath`": `"png/${name}_32.ico`"") } | Set-Content $common_conf_path
# -- replace icon --
# clear icon path with regex
(Get-Content -Path $windows_conf_path -Raw) -replace '(?s)"icon":\s*\[[^\]]*\]', '"icon": []' | Set-Content -Path $windows_conf_path
# replace icon path with no regex
(Get-Content -Path $windows_conf_path -Raw) | ForEach-Object { $_.Replace('"icon": []', "`"icon`": [`"png/${name}_256.ico`", `"png/${name}_32.ico`"]") } | Set-Content $windows_conf_path
# -- replace identifier --
# clear identifier with regex
(Get-Content -Path $windows_conf_path -Raw) -replace '"identifier":\s*"[^"]*"', '"identifier": ""' | Set-Content -Path $windows_conf_path
# -- replace identifier with no regex --
(Get-Content -Path $windows_conf_path -Raw) | ForEach-Object { $_.Replace('"identifier": ""', "`"identifier`": `"${identifier_prefix}.${name}`"") } | Set-Content $windows_conf_path
# -- replace icon resources --
# clear resources with regex
(Get-Content -Path $windows_conf_path -Raw) -replace '(?s)"resources":\s*\[[^\]]*\]', '"resources": []' | Set-Content -Path $windows_conf_path
# replace resources with no regex
(Get-Content -Path $windows_conf_path -Raw) | ForEach-Object { $_.Replace('"resources": []', "`"resources`": [`"png/${name}_32.ico`"]") } | Set-Content $windows_conf_path
if (-not (Test-Path "src-tauri\png\${name}_32.ico")) {
Copy-Item "src-tauri\png\icon_32.ico" "src-tauri\png\${name}_32.ico"
}
if (-not (Test-Path "src-tauri\png\${name}_256.ico")) {
Copy-Item "src-tauri\png\icon_256.ico" "src-tauri\png\${name}_256.ico"
}
# build package
Write-Host "npm run build:windows"
npm run tauri build -- --target x86_64-pc-windows-msvc
Move-Item -Path "src-tauri\target\x86_64-pc-windows-msvc\release\bundle\msi\*.msi" -Destination "output\windows\${title}_x64.msi"
#rm cache
Remove-Item -Path "src-tauri\target\x86_64-pc-windows-msvc\release\*.exe" -Recurse -Force
Remove-Item -Path "src-tauri\target\x86_64-pc-windows-msvc\release\resources\*.ico" -Recurse -Force
Remove-Item -Path "src-tauri\target\x86_64-pc-windows-msvc\release\png\*.ico" -Recurse -Force
Remove-Item -Path "src-tauri\target\x86_64-pc-windows-msvc\release\wix\*.*" -Recurse -Force
Remove-Item -Path "src-tauri\target\x86_64-pc-windows-msvc\release\app.*" -Force
Remove-Item -Path "src-tauri\target\x86_64-pc-windows-msvc\release\resources" -Recurse -Force
Write-Host "package build success!"
Write-Host ""
$index++
# strip blank line for common_conf_path
$lines = Get-Content ${common_conf_path}
$lastNonEmptyLineIndex = ($lines.Count - 1)
while ($lastNonEmptyLineIndex -ge 0 -and -not $lines[$lastNonEmptyLineIndex].Trim()) {
$lastNonEmptyLineIndex--
}
if ($lastNonEmptyLineIndex -lt ($lines.Count - 1)) {
$lines = $lines[0..$lastNonEmptyLineIndex]
}
Set-Content -Path ${common_conf_path} -Value $lines
# strip blank line for windows conf_path
$lines = Get-Content ${windows_conf_path}
$lastNonEmptyLineIndex = ($lines.Count - 1)
while ($lastNonEmptyLineIndex -ge 0 -and -not $lines[$lastNonEmptyLineIndex].Trim()) {
$lastNonEmptyLineIndex--
}
if ($lastNonEmptyLineIndex -lt ($lines.Count - 1)) {
$lines = $lines[0..$lastNonEmptyLineIndex]
}
Set-Content -Path ${windows_conf_path} -Value $lines
}
Write-Host "output dir is output\windows"

189
script/build.sh vendored
View File

@@ -1,189 +0,0 @@
#!/bin/bash
if [ ! -d "node_modules" ]; then
npm i
fi
if [ ! -d "output" ]; then
mkdir output
fi
if [[ "$OSTYPE" =~ ^linux ]]; then
if [ ! -d "output/linux" ]; then
mkdir output/linux
fi
fi
if [[ "$OSTYPE" =~ ^darwin ]]; then
if [ ! -d "output/macos" ]; then
mkdir output/macos
fi
fi
SHELL_FOLDER=$(cd "$(dirname "$0")" || exit 1; pwd)
PROJECT_FOLDER=`dirname ${SHELL_FOLDER}`
echo "shell folder is ${SHELL_FOLDER}"
echo "project folder is ${PROJECT_FOLDER}"
# total app number, ignore first line
total=$(sed -n '$=' app.csv)
export total=$((total-1))
export index=1
export package_prefix="com-pake"
export identifier_prefix="com.pake"
if [[ "$OSTYPE" =~ ^linux ]]; then
echo "==============="
echo "Build for Linux"
echo "==============="
export sd=${SHELL_FOLDER}/sd-linux-`arch`
chmod +x "$sd"
export desktop_file="src-tauri/assets/*.desktop"
fi
if [[ "$OSTYPE" =~ ^darwin ]]; then
echo "==============="
echo "Build for MacOS"
echo "==============="
export sd=${SHELL_FOLDER}/sd-apple-x64
chmod +x "$sd"
fi
tail -n +2 app.csv | while IFS=, read -r -a arr;
do
package_name=${arr[0]}
package_title=${arr[1]}
package_zh_name=${arr[2]}
url=${arr[3]}
domain=${url//http*:\/\//}
domain=${domain%%/*}
# replace package info
# clear url with regex
$sd "\"url\": \"(.*?)\"," "\"url\": \"\"," src-tauri/pake.json
# replace url with no regex
$sd -s "\"url\": \"\"," "\"url\": \"${url}\"," src-tauri/pake.json
# replace dangerousRemoteDomainIpcAccess domain
$sd "\"domain\": \"(.*?)\"," "\"domain\": \"\"," src-tauri/tauri.conf.json
$sd -s "\"domain\": \"\"," "\"domain\": \"${domain}\"," src-tauri/tauri.conf.json
# for apple, need replace title
if [[ "$OSTYPE" =~ ^darwin ]]; then
# update icon
# if icon exists, change icon path
if [ ! -f "src-tauri/icons/${package_name}.icns" ]; then
# else, replace icon to default
echo "warning"
echo "icon for MacOS not exist, will use default icon to replace it"
echo "warning"
cp "src-tauri/icons/icon.icns" "src-tauri/icons/${package_name}.icns"
fi
# clear package_name with regex
$sd "\"productName\": \"(.*?)\"," "\"productName\": \"\"," src-tauri/tauri.conf.json
# replace package_name with no regex
$sd -s "\"productName\": \"\"," "\"productName\": \"${package_title}\"," src-tauri/tauri.conf.json
# clear icon path with regex
$sd "\"icon\": \[\"(.*?)\"\]," "\"icon\": [\"\"]," src-tauri/tauri.macos.conf.json
# replace icon path with no regex
$sd -s "\"icon\": [\"\"]," "\"icon\": [\"icons/${package_name}.icns\"]," src-tauri/tauri.macos.conf.json
# clear identifier with regex
$sd "\"identifier\": \"(.*?)\"," "\"identifier\": \"\"," src-tauri/tauri.macos.conf.json
# replace identifier with not regex
$sd -s "\"identifier\": \"\"," "\"identifier\": \"${identifier_prefix}.${package_name}\"," src-tauri/tauri.macos.conf.json
fi
# echo "update ico with 32x32 picture"
# cp "src-tauri/png/${package_name}_32.ico" "src-tauri/icons/icon.ico"
if [[ "$OSTYPE" =~ ^linux ]]; then
# update icon
# if icon exists, change icon path
if [ ! -f "src-tauri/png/${package_name}_512.png" ]; then
# else, replace icon to default
echo "warning"
echo "icon for linux not exist, will use default icon to replace it"
echo "warning"
cp "src-tauri/png/icon_512.png" "src-tauri/png/${package_name}_512.png"
fi
# -- replace package name -- #
# clear package_name with regex
$sd "\"productName\": \"(.*?)\"," "\"productName\": \"\"," src-tauri/tauri.conf.json
# replace package_name with no regex
$sd -s "\"productName\": \"\"," "\"productName\": \"${package_prefix}-${package_name}\"," src-tauri/tauri.conf.json
# -- replace systemTray iconPath -- #
# clear systemTray iconPath with regex
$sd "\"iconPath\": \"(.*?)\"," "\"iconPath\": \"\"," src-tauri/tauri.conf.json
# replace systemTray iconPath with no regex
$sd -s "\"iconPath\": \"\"," "\"iconPath\": \"png/${package_name}_512.png\"," src-tauri/tauri.conf.json
# -- replace icon -- #
# clear icon path with regex
$sd "\"icon\": \[\"(.*?)\"\]," "\"icon\": [\"\"]," src-tauri/tauri.linux.conf.json
# replace icon path with no regex
$sd -s "\"icon\": [\"\"]," "\"icon\": [\"png/${package_name}_512.png\"]," src-tauri/tauri.linux.conf.json
# -- replace identifier -- #
# clear identifier with regex
$sd "\"identifier\": \"(.*?)\"," "\"identifier\": \"\"," src-tauri/tauri.linux.conf.json
# replace identifier with not regex
$sd -s "\"identifier\": \"\"," "\"identifier\": \"${identifier_prefix}.${package_name}\"," src-tauri/tauri.linux.conf.json
echo "update desktop"
new_desktop="${PROJECT_FOLDER}/src-tauri/assets/${package_prefix}-${package_name}.desktop"
new_desktop_map_path="/usr/share/applications/${package_prefix}-${package_name}.desktop"
for file in `ls ${PROJECT_FOLDER}/src-tauri/assets/*.desktop`
do
mv "${file}" "${new_desktop}"
echo mv "${file}" "${new_desktop}"
done
# clear desktop file with regex
$sd "\"files\": \{\"(.*)\"\}" "\"files\": \{\"\"\}" src-tauri/tauri.linux.conf.json
# replace desktop file with no regex
$sd -s "\"files\": \{\"\"\}" "\"files\": {\"${new_desktop_map_path}\": \"${new_desktop}\"}" src-tauri/tauri.linux.conf.json
# clear desktop content with regex
$sd "Exec=.*" "Exec=" "${new_desktop}"
$sd "Icon=.*" "Icon=" "${new_desktop}"
$sd "Name=.*" "Name=" "${new_desktop}"
$sd "Name\[zh_CN\]=.*" "Name[zh_CN]=" "${new_desktop}"
# replace desktop content with no reg
$sd -s "Exec=" "Exec=${package_prefix}-${package_name}" "${new_desktop}"
$sd -s "Icon=" "Icon=${package_prefix}-${package_name}" "${new_desktop}"
$sd -s "Name=" "Name=${package_title}" "${new_desktop}"
$sd -s "Name[zh_CN]=" "Name[zh_CN]=${package_zh_name}" "${new_desktop}"
fi
echo "building package ${index}/${total}"
echo "package name is ${package_name} (${package_zh_name})"
if [[ "$OSTYPE" =~ ^linux ]]; then
npm run tauri build
mv src-tauri/target/release/bundle/deb/${package_prefix}-"${package_name}"*.deb output/linux/"${package_title}"_`arch`.deb
mv src-tauri/target/release/bundle/appimage/${package_prefix}-"${package_name}"*.AppImage output/linux/"${package_title}"_`arch`.AppImage
echo clear cache
rm src-tauri/target/release
rm -rf src-tauri/target/release/bundle
fi
if [[ "$OSTYPE" =~ ^darwin ]]; then
npm run tauri build -- --target universal-apple-darwin
mv src-tauri/target/universal-apple-darwin/release/bundle/dmg/*.dmg output/macos/"${package_title}".dmg
echo clear cache
rm -rf src-tauri/target/universal-apple-darwin
rm src-tauri/target/aarch64-apple-darwin/release
rm src-tauri/target/x86_64-apple-darwin/release
fi
echo "package build success!"
index=$((index+1))
done
echo "build all package success!"
echo "you run 'rm src-tauri/assets/*.desktop && git checkout src-tauri' to recovery code"

BIN
script/sd-apple-x64 vendored

Binary file not shown.

Binary file not shown.

BIN
script/sd-linux-x86_64 vendored

Binary file not shown.

View File

@@ -18,7 +18,7 @@ tauri-build = { version = "1.4.0", features = [] }
serde_json = "1.0.96"
serde = { version = "1.0.163", features = ["derive"] }
tauri = { version = "1.4.1", features = ["api-all", "system-tray"] }
tauri-plugin-window-state = "0.1"
tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
[dev-dependencies]
cargo-bloat = "0.11.1"