fix: tauri npm scripts (#955)

This commit is contained in:
lin onetwo 2023-02-14 14:51:05 +08:00 committed by GitHub
parent 36e6da52a5
commit b69eb3437b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 65 additions and 33 deletions

View File

@ -16,24 +16,66 @@ on:
- 'README.md'
- '.vscode'
permissions:
actions: write
contents: write
security-events: write
concurrency:
group: release-ci-group
cancel-in-progress: true
jobs:
MacOS:
runs-on: macos-latest
create-release:
runs-on: ubuntu-latest
outputs:
RELEASE_UPLOAD_ID: ${{ steps.create_release.outputs.id }}
steps:
- uses: actions/checkout@v2
- name: Query version number
id: get_version
shell: bash
run: |
echo "using version tag ${GITHUB_REF:10}"
echo "version=${GITHUB_REF:10}" >> $GITHUB_ENV
- name: Create Release
id: create_release
if: startsWith(github.ref, 'refs/tags/')
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
draft: true
tag_name: '${{ env.version }}'
release_name: 'AFFiNE ${{ env.version }}'
body: 'See the assets to download this version and install.'
build-tauri:
needs: create-release
strategy:
fail-fast: false
matrix:
platform: [macos-latest, ubuntu-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: 'true'
- name: install dependencies (ubuntu only)
if: matrix.platform == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: install Rust stable
uses: dtolnay/rust-toolchain@stable
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
@ -55,7 +97,7 @@ jobs:
- name: Install dependencies
run: pnpm i -r
- name: Make macOS (x64)
- name: Make App Binary
run: pnpm build:app
working-directory: apps/desktop
env:
@ -63,12 +105,8 @@ jobs:
CI_PULL_REQUEST: ${{ github.event_name == 'pull_request' }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
draft: true
generate_release_notes: true
files: apps/desktop/src-tauri/target/release/bundle/dmg/*.dmg
- uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
releaseId: ${{ needs.create-release.outputs.RELEASE_UPLOAD_ID }}

View File

@ -1,13 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="/src/style.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>AFFiNE</title>
</head>
<body>
<div id="react-root" />
<script type="module" src="/src/main.tsx"></script>
</body>
</html>

View File

@ -6,9 +6,8 @@
"license": "MPL-2.0",
"module": "true",
"scripts": {
"dev:app": "pnpm build:preload && cross-env NODE_ENV=development tauri dev",
"dev:prerequisite": "concurrently \"cd ../packages/data-center && pnpm dev\" \"cd ../apps/web && pnpm dev\"",
"build:prerequisite": "pnpm build:submodules && pnpm build:rs-types && pnpm build:affine && pnpm build:preload",
"dev:app": "cross-env NODE_ENV=development tauri dev",
"dev:prerequisite": "cd ../../ && pnpm build && concurrently \"cd packages/data-center && pnpm dev\" \"cd apps/web && pnpm dev\"",
"build:rs-types": "zx scripts/generateTsTypingsFromJsonSchema.mjs",
"build:submodules": "zx scripts/buildSubModules.mjs",
"build:affine": "zx scripts/buildAffine.mjs",

View File

@ -14,6 +14,8 @@ const publicAffineOutDirectory = path.join(
'affine-out'
);
if (process.platform === 'win32') $.shell = 'pwsh';
/**
* Build affine dist html
*/
@ -21,7 +23,7 @@ cd(repoDirectory);
await $`pnpm i -r`;
await $`pnpm build`;
cd(affineSrcDirectory);
$.env.BASE_PATH = '/affine-out';
$.env.NEXT_BASE_PATH = '/affine-out';
await $`pnpm build`;
await $`pnpm export`;
await fs.remove(publicAffineOutDirectory);

View File

@ -8,6 +8,7 @@ mod state;
use dotenvy::dotenv;
use state::AppState;
use std::env;
#[cfg(target_os = "macos")]
use tauri::TitleBarStyle;
use tokio::sync::Mutex;
@ -17,7 +18,9 @@ async fn main() {
dotenv().ok();
let preload = include_str!("../../public/preload/index.js");
let is_dev = env::var("NODE_ENV").unwrap_or_default() == "development";
// this only work in production mode, in dev mode, we load `devPath` in tauri.conf.json
let initial_path = if is_dev {
// just a place holder here
"index.html"
} else {
"affine-out/index.html"
@ -32,10 +35,13 @@ async fn main() {
tauri::WindowBuilder::new(app, "label", tauri::WindowUrl::App(initial_path.into()))
.title("AFFiNE")
.inner_size(1000.0, 800.0)
.title_bar_style(TitleBarStyle::Overlay)
.hidden_title(true)
.initialization_script(&preload)
.build()?;
.initialization_script(&preload);
// fix `title_bar_style` found for struct `WindowBuilder` in the current scope
#[cfg(target_os = "macos")]
let _window = _window
.hidden_title(true)
.title_bar_style(TitleBarStyle::Overlay);
let _window = _window.build()?;
#[cfg(debug_assertions)]
_window.open_devtools();
Ok(())

View File

@ -1,6 +1,6 @@
{
"build": {
"beforeDevCommand": "pnpm dev:prerequisite",
"beforeDevCommand": "pnpm build:preload && pnpm dev:prerequisite",
"beforeBuildCommand": "pnpm build:preload && pnpm build:affine",
"devPath": "http://localhost:8080",
"distDir": "../public",

View File

@ -69,7 +69,7 @@ const nextConfig = {
printer.info(`API request proxy to [${desc} Server]: ` + target);
return profile;
},
basePath: process.env.BASE_PATH,
basePath: process.env.NEXT_BASE_PATH,
experimental: {
forceSwcTransforms: true,
},