mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-10 06:34:20 +00:00
Merge branch 'master' into jk/breaking-merged
This commit is contained in:
commit
2ae3241cc0
211 changed files with 21135 additions and 3770 deletions
150
.github/workflows/main.yml
vendored
150
.github/workflows/main.yml
vendored
|
@ -27,22 +27,30 @@ on:
|
|||
- lib.rs
|
||||
- Cargo.toml
|
||||
|
||||
# workflow_dispatch:
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
CARGO_INCREMENTAL: "0"
|
||||
|
||||
jobs:
|
||||
check:
|
||||
if: github.event.pull_request.draft == false
|
||||
name: Check
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: sudo apt-get update
|
||||
- run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
|
||||
- uses: dtolnay/rust-toolchain@stable
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
with:
|
||||
cache-all-crates: "true"
|
||||
save-if: ${{ github.ref == 'refs/heads/master' }}
|
||||
- uses: ilammy/setup-nasm@v1
|
||||
- run: sudo apt-get update
|
||||
- run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev
|
||||
- uses: actions/checkout@v4
|
||||
- run: cargo check --all --examples --tests
|
||||
|
||||
test:
|
||||
|
@ -50,15 +58,24 @@ jobs:
|
|||
name: Test Suite
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: sudo apt-get update
|
||||
- run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
|
||||
- uses: dtolnay/rust-toolchain@stable
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
with:
|
||||
cache-all-crates: "true"
|
||||
save-if: ${{ github.ref == 'refs/heads/master' }}
|
||||
- uses: ilammy/setup-nasm@v1
|
||||
- run: sudo apt-get update
|
||||
- run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev
|
||||
- uses: davidB/rust-cargo-make@v1
|
||||
- uses: browser-actions/setup-firefox@latest
|
||||
- uses: jetli/wasm-pack-action@v0.4.0
|
||||
- uses: actions/checkout@v4
|
||||
- run: sudo rm -rf /usr/share/dotnet
|
||||
- run: sudo rm -rf "$AGENT_TOOLSDIRECTORY"
|
||||
- run: |
|
||||
df -h
|
||||
sudo rm -rf ${GITHUB_WORKSPACE}/.git
|
||||
df -h
|
||||
- run: cargo make tests
|
||||
|
||||
fmt:
|
||||
|
@ -66,11 +83,15 @@ jobs:
|
|||
name: Rustfmt
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: dtolnay/rust-toolchain@stable
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- uses: ilammy/setup-nasm@v1
|
||||
- run: rustup component add rustfmt
|
||||
- uses: actions/checkout@v4
|
||||
- uses: ilammy/setup-nasm@v1
|
||||
- uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
components: rustfmt
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
with:
|
||||
cache-all-crates: "true"
|
||||
save-if: ${{ github.ref == 'refs/heads/master' }}
|
||||
- run: cargo fmt --all -- --check
|
||||
|
||||
clippy:
|
||||
|
@ -78,17 +99,104 @@ jobs:
|
|||
name: Clippy
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: dtolnay/rust-toolchain@stable
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- uses: ilammy/setup-nasm@v1
|
||||
- uses: actions/checkout@v4
|
||||
- run: sudo apt-get update
|
||||
- run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev
|
||||
- run: rustup component add clippy
|
||||
- uses: actions/checkout@v4
|
||||
- uses: ilammy/setup-nasm@v1
|
||||
- uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
components: rustfmt, clippy
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
with:
|
||||
cache-all-crates: "true"
|
||||
save-if: ${{ github.ref == 'refs/heads/master' }}
|
||||
- run: cargo clippy --workspace --examples --tests -- -D warnings
|
||||
|
||||
miri:
|
||||
if: github.event.pull_request.draft == false
|
||||
name: Miri
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
CARGO_UNSTABLE_SPARSE_REGISTRY: 'true'
|
||||
RUSTFLAGS: -Dwarnings
|
||||
RUST_BACKTRACE: 1
|
||||
MIRIFLAGS: -Zmiri-tag-gc=1
|
||||
# Change to specific Rust release to pin
|
||||
rust_stable: stable
|
||||
rust_nightly: nightly-2023-11-16
|
||||
rust_clippy: 1.70.0
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: ilammy/setup-nasm@v1
|
||||
- name: Install Rust ${{ env.rust_nightly }}
|
||||
uses: dtolnay/rust-toolchain@master
|
||||
with:
|
||||
toolchain: ${{ env.rust_nightly }}
|
||||
components: miri
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
with:
|
||||
cache-all-crates: "true"
|
||||
save-if: ${{ github.ref == 'refs/heads/master' }}
|
||||
- name: miri
|
||||
# Many of tests in tokio/tests and doctests use #[tokio::test] or
|
||||
# #[tokio::main] that calls epoll_create1 that Miri does not support.
|
||||
# run: cargo miri test --features full --lib --no-fail-fast
|
||||
run: |
|
||||
cargo miri test --package dioxus-core -- --exact --nocapture
|
||||
cargo miri test --package dioxus-native-core --test miri_native -- --exact --nocapture
|
||||
env:
|
||||
MIRIFLAGS: -Zmiri-disable-isolation -Zmiri-strict-provenance -Zmiri-retag-fields
|
||||
PROPTEST_CASES: 10
|
||||
|
||||
playwright:
|
||||
if: github.event.pull_request.draft == false
|
||||
name: Playwright Tests
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# Do our best to cache the toolchain and node install steps
|
||||
- uses: actions/checkout@v4
|
||||
- uses: ilammy/setup-nasm@v1
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 16
|
||||
- name: Install Rust
|
||||
uses: dtolnay/rust-toolchain@master
|
||||
with:
|
||||
toolchain: stable
|
||||
targets: x86_64-unknown-linux-gnu,wasm32-unknown-unknown
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
with:
|
||||
cache-all-crates: "true"
|
||||
save-if: ${{ github.ref == 'refs/heads/master' }}
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
working-directory: ./playwright-tests
|
||||
|
||||
- name: Install Playwright
|
||||
run: npm install -D @playwright/test
|
||||
working-directory: ./playwright-tests
|
||||
|
||||
- name: Install Playwright Browsers
|
||||
run: npx playwright install --with-deps
|
||||
working-directory: ./playwright-tests
|
||||
|
||||
- name: Run Playwright tests
|
||||
run: npx playwright test
|
||||
working-directory: ./playwright-tests
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
if: always()
|
||||
with:
|
||||
name: playwright-report
|
||||
path: playwright-report/
|
||||
retention-days: 30
|
||||
|
||||
|
||||
matrix_test:
|
||||
runs-on: ${{ matrix.platform.os }}
|
||||
if: github.event.pull_request.draft == false
|
||||
env:
|
||||
RUST_CARGO_COMMAND: ${{ matrix.platform.cross == true && 'cross' || 'cargo' }}
|
||||
strategy:
|
||||
|
@ -135,20 +243,18 @@ jobs:
|
|||
with:
|
||||
toolchain: ${{ matrix.platform.toolchain }}
|
||||
targets: ${{ matrix.platform.target }}
|
||||
components: rustfmt
|
||||
|
||||
- name: Install cross
|
||||
if: ${{ matrix.platform.cross == true }}
|
||||
|
||||
uses: taiki-e/install-action@cross
|
||||
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
with:
|
||||
workspaces: core -> ../target
|
||||
save-if: ${{ matrix.features.key == 'all' }}
|
||||
|
||||
- name: Install rustfmt
|
||||
run: rustup component add rustfmt
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
key: "${{ matrix.platform.target }}"
|
||||
cache-all-crates: "true"
|
||||
save-if: ${{ github.ref == 'refs/heads/master' }}
|
||||
|
||||
- name: test
|
||||
run: |
|
||||
|
|
133
.github/workflows/miri.yml
vendored
133
.github/workflows/miri.yml
vendored
|
@ -1,133 +0,0 @@
|
|||
name: Miri Tests
|
||||
|
||||
on:
|
||||
push:
|
||||
# Run in PRs and for bors, but not on master.
|
||||
branches:
|
||||
- 'auto'
|
||||
- 'try'
|
||||
paths:
|
||||
- packages/**
|
||||
- examples/**
|
||||
- src/**
|
||||
- .github/**
|
||||
- lib.rs
|
||||
- Cargo.toml
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened, ready_for_review]
|
||||
branches:
|
||||
- 'master'
|
||||
schedule:
|
||||
- cron: '6 6 * * *' # At 6:06 UTC every day.
|
||||
|
||||
env:
|
||||
CARGO_UNSTABLE_SPARSE_REGISTRY: 'true'
|
||||
RUSTFLAGS: -Dwarnings
|
||||
RUST_BACKTRACE: 1
|
||||
# Change to specific Rust release to pin
|
||||
rust_stable: stable
|
||||
rust_nightly: nightly-2023-11-16
|
||||
rust_clippy: 1.70.0
|
||||
# When updating this, also update:
|
||||
# - README.md
|
||||
# - tokio/README.md
|
||||
# - CONTRIBUTING.md
|
||||
# - tokio/Cargo.toml
|
||||
# - tokio-util/Cargo.toml
|
||||
# - tokio-test/Cargo.toml
|
||||
# - tokio-stream/Cargo.toml
|
||||
# rust_min: 1.49.0
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ${{ matrix.os }}
|
||||
env:
|
||||
RUST_BACKTRACE: 1
|
||||
HOST_TARGET: ${{ matrix.host_target }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
host_target: x86_64-unknown-linux-gnu
|
||||
# - os: macos-latest
|
||||
# host_target: x86_64-apple-darwin
|
||||
# - os: windows-latest
|
||||
# host_target: i686-pc-windows-msvc
|
||||
# - os: windows-latest
|
||||
# host_target: i686-pc-windows-msvc
|
||||
# - os: windows-latest
|
||||
# host_target: i686-pc-windows-msvc
|
||||
# - os: windows-latest
|
||||
# host_target: i686-pc-windows-msvc
|
||||
steps:
|
||||
- name: Set the tag GC interval to 1 on linux
|
||||
if: runner.os == 'Linux'
|
||||
run: echo "MIRIFLAGS=-Zmiri-tag-gc=1" >> $GITHUB_ENV
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
- uses: ilammy/setup-nasm@v1
|
||||
- name: Install Rust ${{ env.rust_nightly }}
|
||||
uses: dtolnay/rust-toolchain@master
|
||||
with:
|
||||
toolchain: ${{ env.rust_nightly }}
|
||||
components: miri
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- name: miri
|
||||
# Many of tests in tokio/tests and doctests use #[tokio::test] or
|
||||
# #[tokio::main] that calls epoll_create1 that Miri does not support.
|
||||
# run: cargo miri test --features full --lib --no-fail-fast
|
||||
run: |
|
||||
cargo miri test --package dioxus-core -- --exact --nocapture
|
||||
cargo miri test --package dioxus-native-core --test miri_native -- --exact --nocapture
|
||||
|
||||
# working-directory: tokio
|
||||
env:
|
||||
MIRIFLAGS: -Zmiri-disable-isolation -Zmiri-strict-provenance -Zmiri-retag-fields
|
||||
PROPTEST_CASES: 10
|
||||
|
||||
# Cache the global cargo directory, but NOT the local `target` directory which
|
||||
# we cannot reuse anyway when the nightly changes (and it grows quite large
|
||||
# over time).
|
||||
# - name: Add cache for cargo
|
||||
# id: cache
|
||||
# uses: actions/cache@v3
|
||||
# with:
|
||||
# path: |
|
||||
# # Taken from <https://doc.rust-lang.org/nightly/cargo/guide/cargo-home.html#caching-the-cargo-home-in-ci>.
|
||||
# ~/.cargo/bin
|
||||
# ~/.cargo/registry/index
|
||||
# ~/.cargo/registry/cache
|
||||
# ~/.cargo/git/db
|
||||
# # contains package information of crates installed via `cargo install`.
|
||||
# ~/.cargo/.crates.toml
|
||||
# ~/.cargo/.crates2.json
|
||||
# key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||
# restore-keys: ${{ runner.os }}-cargo
|
||||
|
||||
# - name: Install rustup-toolchain-install-master
|
||||
# if: ${{ steps.cache.outputs.cache-hit != 'true' }}
|
||||
# shell: bash
|
||||
# run: |
|
||||
# cargo install -f rustup-toolchain-install-master
|
||||
# - name: Install "master" toolchain
|
||||
# shell: bash
|
||||
# run: |
|
||||
# if [[ ${{ github.event_name }} == 'schedule' ]]; then
|
||||
# echo "Building against latest rustc git version"
|
||||
# git ls-remote https://github.com/rust-lang/rust/ HEAD | cut -f 1 > rust-version
|
||||
# fi
|
||||
# toolchain --host ${{ matrix.host_target }}
|
||||
# - name: Show Rust version
|
||||
# run: |
|
||||
# rustup show
|
||||
# rustc -Vv
|
||||
# cargo -V
|
||||
# - name: Test
|
||||
# run: |
|
||||
# MIRIFLAGS="-Zmiri-disable-isolation -Zmiri-ignore-leaks" cargo +nightly miri test --package dioxus-core --test miri_stress -- --exact --nocapture
|
||||
# MIRIFLAGS="-Zmiri-disable-isolation -Zmiri-ignore-leaks" cargo +nightly miri test --package dioxus-native-core --test miri_native -- --exact --nocapture
|
52
.github/workflows/playwright.yml
vendored
52
.github/workflows/playwright.yml
vendored
|
@ -1,52 +0,0 @@
|
|||
name: Playwright Tests
|
||||
on:
|
||||
push:
|
||||
branches: [main, master]
|
||||
pull_request:
|
||||
branches: [main, master]
|
||||
defaults:
|
||||
run:
|
||||
working-directory: ./playwright-tests
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
test:
|
||||
if: github.event.pull_request.draft == false
|
||||
timeout-minutes: 60
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# Do our best to cache the toolchain and node install steps
|
||||
- uses: actions/checkout@v4
|
||||
- uses: ilammy/setup-nasm@v1
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 16
|
||||
- name: Install Rust
|
||||
uses: dtolnay/rust-toolchain@master
|
||||
with:
|
||||
toolchain: stable
|
||||
targets: x86_64-unknown-linux-gnu,wasm32-unknown-unknown
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
- name: Install Playwright
|
||||
run: npm install -D @playwright/test
|
||||
- name: Install Playwright Browsers
|
||||
run: npx playwright install --with-deps
|
||||
# Cache the CLI by using cargo run internally
|
||||
# - name: Install Dioxus CLI
|
||||
# uses: actions-rs/cargo@v1
|
||||
# with:
|
||||
# command: install
|
||||
# args: --path packages/cli
|
||||
- name: Run Playwright tests
|
||||
run: npx playwright test
|
||||
- uses: actions/upload-artifact@v4
|
||||
if: always()
|
||||
with:
|
||||
name: playwright-report
|
||||
path: playwright-report/
|
||||
retention-days: 30
|
37
.github/workflows/wipe_cache.yml
vendored
Normal file
37
.github/workflows/wipe_cache.yml
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
name: Clear cache
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
actions: write
|
||||
|
||||
jobs:
|
||||
clear-cache:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Clear cache
|
||||
uses: actions/github-script@v6
|
||||
with:
|
||||
github-token: ${{ secrets.cache_controller }}
|
||||
script: |
|
||||
console.log("About to clear")
|
||||
|
||||
while (true) {
|
||||
const caches = await github.rest.actions.getActionsCacheList({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo
|
||||
})
|
||||
if (caches.data.actions_caches.length === 0) {
|
||||
break
|
||||
}
|
||||
for (const cache of caches.data.actions_caches) {
|
||||
console.log(cache)
|
||||
github.rest.actions.deleteActionsCacheById({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
cache_id: cache.id,
|
||||
})
|
||||
}
|
||||
}
|
||||
console.log("Clear completed")
|
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -2,10 +2,12 @@
|
|||
/playwright-tests/web/dist
|
||||
/playwright-tests/fullstack/dist
|
||||
/dist
|
||||
Cargo.lock
|
||||
.DS_Store
|
||||
/examples/assets/test_video.mp4
|
||||
|
||||
# new recommendation to keep the lockfile in for CI and reproducible builds
|
||||
# Cargo.lock
|
||||
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
|
|
12337
Cargo.lock
generated
Normal file
12337
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
15
Cargo.toml
15
Cargo.toml
|
@ -4,11 +4,13 @@ members = [
|
|||
"packages/dioxus",
|
||||
"packages/core",
|
||||
"packages/cli",
|
||||
"packages/cli-config",
|
||||
"packages/core-macro",
|
||||
"packages/router-macro",
|
||||
"packages/extension",
|
||||
"packages/router",
|
||||
"packages/html",
|
||||
"packages/html-internal-macro",
|
||||
"packages/hooks",
|
||||
"packages/web",
|
||||
"packages/ssr",
|
||||
|
@ -60,6 +62,7 @@ dioxus-core-macro = { path = "packages/core-macro", version = "0.4.0" }
|
|||
dioxus-router = { path = "packages/router", version = "0.4.1" }
|
||||
dioxus-router-macro = { path = "packages/router-macro", version = "0.4.1" }
|
||||
dioxus-html = { path = "packages/html", default-features = false, version = "0.4.0" }
|
||||
dioxus-html-internal-macro = { path = "packages/html-internal-macro", version = "0.4.0" }
|
||||
dioxus-hooks = { path = "packages/hooks", version = "0.4.0" }
|
||||
dioxus-web = { path = "packages/web", version = "0.4.0" }
|
||||
dioxus-ssr = { path = "packages/ssr", version = "0.4.0" }
|
||||
|
@ -77,6 +80,7 @@ dioxus-native-core = { path = "packages/native-core", version = "0.4.0" }
|
|||
dioxus-native-core-macro = { path = "packages/native-core-macro", version = "0.4.0" }
|
||||
rsx-rosetta = { path = "packages/rsx-rosetta", version = "0.4.0" }
|
||||
dioxus-signals = { path = "packages/signals" }
|
||||
dioxus-cli-config = { path = "packages/cli-config", version = "0.4.1" }
|
||||
generational-box = { path = "packages/generational-box", version = "0.4.3" }
|
||||
dioxus-hot-reload = { path = "packages/hot-reload", version = "0.4.0" }
|
||||
dioxus-fullstack = { path = "packages/fullstack", version = "0.4.1" }
|
||||
|
@ -94,6 +98,11 @@ thiserror = "1.0.40"
|
|||
prettyplease = { package = "prettier-please", version = "0.2", features = [
|
||||
"verbatim",
|
||||
] }
|
||||
manganis-cli-support = { git = "https://github.com/DioxusLabs/collect-assets", rev = "e0093a4", features = [
|
||||
"webp",
|
||||
"html",
|
||||
] }
|
||||
manganis = { git = "https://github.com/DioxusLabs/collect-assets", rev = "e0093a4" }
|
||||
|
||||
# This is a "virtual package"
|
||||
# It is not meant to be published, but is used so "cargo run --example XYZ" works properly
|
||||
|
@ -129,12 +138,10 @@ serde_json = "1.0.79"
|
|||
rand = { version = "0.8.4", features = ["small_rng"] }
|
||||
tokio = { version = "1.16.1", features = ["full"] }
|
||||
reqwest = { version = "0.11.9", features = ["json"] }
|
||||
fern = { version = "0.6.0", features = ["colored"] }
|
||||
env_logger = "0.10.0"
|
||||
simple_logger = "4.0.0"
|
||||
thiserror = { workspace = true }
|
||||
|
||||
|
||||
[dependencies]
|
||||
manganis = { workspace = true }
|
||||
tracing-subscriber = "0.3.17"
|
||||
http-range = "0.1.5"
|
||||
|
||||
|
|
|
@ -105,6 +105,8 @@ args = [
|
|||
"dioxus-router",
|
||||
"--exclude",
|
||||
"dioxus-desktop",
|
||||
"--exclude",
|
||||
"dioxus-mobile",
|
||||
]
|
||||
private = true
|
||||
|
||||
|
|
|
@ -139,7 +139,6 @@ Missing Features
|
|||
Missing examples
|
||||
- Shared state
|
||||
- Root-less element groups
|
||||
- Spread props
|
||||
- Custom elements
|
||||
- Component Children: Pass children into child components
|
||||
- Render To string: Render a mounted virtualdom to a string
|
||||
|
|
|
@ -76,7 +76,11 @@ fn app(cx: Scope) -> Element {
|
|||
|
||||
"Hover, click, type or scroll to see the info down below"
|
||||
}
|
||||
div { events.read().iter().map(|event| rsx!( div { "{event:?}" } )) }
|
||||
div {
|
||||
for event in events.read().iter() {
|
||||
div { "{event:?}" }
|
||||
}
|
||||
}
|
||||
}
|
||||
))
|
||||
}
|
||||
|
|
|
@ -6,13 +6,13 @@ This calculator version uses React-style state management. All state is held as
|
|||
use dioxus::events::*;
|
||||
use dioxus::html::input_data::keyboard_types::Key;
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_desktop::{Config, WindowBuilder};
|
||||
use dioxus_desktop::{Config, LogicalSize, WindowBuilder};
|
||||
|
||||
fn main() {
|
||||
let config = Config::new().with_window(
|
||||
WindowBuilder::default()
|
||||
.with_title("Calculator")
|
||||
.with_inner_size(dioxus_desktop::LogicalSize::new(300.0, 500.0)),
|
||||
.with_inner_size(LogicalSize::new(300.0, 500.0)),
|
||||
);
|
||||
|
||||
dioxus_desktop::launch_cfg(app, config);
|
||||
|
@ -58,13 +58,13 @@ fn app(cx: Scope) -> Element {
|
|||
};
|
||||
|
||||
cx.render(rsx!(
|
||||
style { include_str!("./assets/calculator.css") }
|
||||
style { {include_str!("./assets/calculator.css")} }
|
||||
div { id: "wrapper",
|
||||
div { class: "app",
|
||||
div { class: "calculator",
|
||||
tabindex: "0",
|
||||
onkeydown: handle_key_down_event,
|
||||
div { class: "calculator-display", val.to_string() }
|
||||
div { class: "calculator-display", "{val}" }
|
||||
div { class: "calculator-keypad",
|
||||
div { class: "input-keys",
|
||||
div { class: "function-keys",
|
||||
|
@ -103,14 +103,14 @@ fn app(cx: Scope) -> Element {
|
|||
div { class: "digit-keys",
|
||||
button { class: "calculator-key key-0", onclick: move |_| input_digit(0), "0" }
|
||||
button { class: "calculator-key key-dot", onclick: move |_| val.make_mut().push('.'), "●" }
|
||||
(1..10).map(|k| rsx!{
|
||||
for k in 1..10 {
|
||||
button {
|
||||
class: "calculator-key {k}",
|
||||
name: "key-{k}",
|
||||
onclick: move |_| input_digit(k),
|
||||
"{k}"
|
||||
}
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
div { class: "operator-keys",
|
||||
|
|
|
@ -10,7 +10,7 @@ fn app(cx: Scope) -> Element {
|
|||
|
||||
use_future!(cx, || async move {
|
||||
loop {
|
||||
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
|
||||
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
|
||||
count += 1;
|
||||
println!("current: {count}");
|
||||
}
|
||||
|
|
|
@ -32,12 +32,12 @@ fn app(cx: Scope) -> Element {
|
|||
}
|
||||
|
||||
ul {
|
||||
emails_sent.read().iter().map(|message| cx.render(rsx! {
|
||||
for message in emails_sent.read().iter() {
|
||||
li {
|
||||
h3 { "email" }
|
||||
span {"{message}"}
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
@ -15,8 +15,8 @@ fn app(cx: Scope) -> Element {
|
|||
if *running.current() {
|
||||
loop {
|
||||
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
|
||||
if let Some(element) = elements.read().get(focused) {
|
||||
element.set_focus(true);
|
||||
if let Some(element) = elements.with(|f| f.get(focused).cloned()) {
|
||||
_ = element.set_focus(true).await;
|
||||
} else {
|
||||
focused = 0;
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ fn ClientList(cx: Scope) -> Element {
|
|||
Link { to: Route::ClientAdd {}, class: "pure-button pure-button-primary", "Add Client" }
|
||||
Link { to: Route::Settings {}, class: "pure-button", "Settings" }
|
||||
|
||||
clients.read().iter().map(|client| rsx! {
|
||||
for client in clients.read().iter() {
|
||||
div {
|
||||
class: "client",
|
||||
style: "margin-bottom: 50px",
|
||||
|
@ -70,7 +70,7 @@ fn ClientList(cx: Scope) -> Element {
|
|||
p { "Name: {client.first_name} {client.last_name}" }
|
||||
p { "Description: {client.description}" }
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ fn app(cx: Scope) -> Element {
|
|||
p {
|
||||
"This should show an image:"
|
||||
}
|
||||
img { src: mg!(image("examples/assets/logo.png").format(ImageType::Avif)).to_string() }
|
||||
img { src: manganis::mg!(image("examples/assets/logo.png").format(ImageType::Avif)).to_string() }
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -14,9 +14,9 @@ fn app(cx: Scope) -> Element {
|
|||
}
|
||||
|
||||
render! {
|
||||
(0..count).map(|_| rsx!{
|
||||
for _ in 0..count {
|
||||
drop_child {}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,29 +1,25 @@
|
|||
use dioxus::prelude::*;
|
||||
use dioxus_desktop::wry::http::Response;
|
||||
use dioxus_desktop::{use_asset_handler, AssetRequest};
|
||||
use std::path::Path;
|
||||
use dioxus_desktop::{use_asset_handler, wry::http::Response};
|
||||
|
||||
fn main() {
|
||||
dioxus_desktop::launch(app);
|
||||
}
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
use_asset_handler(cx, |request: &AssetRequest| {
|
||||
let path = request.path().to_path_buf();
|
||||
async move {
|
||||
if path != Path::new("logo.png") {
|
||||
return None;
|
||||
}
|
||||
let image_data: &[u8] = include_bytes!("./assets/logo.png");
|
||||
Some(Response::new(image_data.into()))
|
||||
use_asset_handler(cx, "logos", |request, response| {
|
||||
// Note that the "logos" prefix is stripped from the URI
|
||||
//
|
||||
// However, the asset is absolute to its "virtual folder" - meaning it starts with a leading slash
|
||||
if request.uri().path() != "/logo.png" {
|
||||
return;
|
||||
}
|
||||
|
||||
response.respond(Response::new(include_bytes!("./assets/logo.png").to_vec()));
|
||||
});
|
||||
|
||||
cx.render(rsx! {
|
||||
render! {
|
||||
div {
|
||||
img {
|
||||
src: "logo.png"
|
||||
}
|
||||
img { src: "/logos/logo.png" }
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,9 +22,7 @@ fn DemoC(cx: Scope, x: i32) -> Element {
|
|||
|
||||
result.throw()?;
|
||||
|
||||
cx.render(rsx! {
|
||||
h1 {
|
||||
"{x}"
|
||||
}
|
||||
})
|
||||
render! {
|
||||
h1 { "{x}" }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,9 +39,9 @@ fn ChildWithRef(cx: Scope) -> Element {
|
|||
cx.render(rsx! {
|
||||
div {
|
||||
ul {
|
||||
names.read().iter().map(|f| rsx!{
|
||||
li { "hello: {f}" }
|
||||
})
|
||||
for name in names.read().iter() {
|
||||
li { "hello: {name}" }
|
||||
}
|
||||
}
|
||||
button {
|
||||
onclick: move |_| {
|
||||
|
|
|
@ -18,7 +18,7 @@ fn main() {
|
|||
);
|
||||
}
|
||||
|
||||
const _STYLE: &str = mg!(file("./examples/assets/fileexplorer.css"));
|
||||
const _STYLE: &str = manganis::mg!(file("./examples/assets/fileexplorer.css"));
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
let files = use_ref(cx, Files::new);
|
||||
|
@ -28,39 +28,36 @@ fn app(cx: Scope) -> Element {
|
|||
link { href:"https://fonts.googleapis.com/icon?family=Material+Icons", rel:"stylesheet", }
|
||||
header {
|
||||
i { class: "material-icons icon-menu", "menu" }
|
||||
h1 { "Files: ", files.read().current() }
|
||||
h1 { "Files: ", {files.read().current()} }
|
||||
span { }
|
||||
i { class: "material-icons", onclick: move |_| files.write().go_up(), "logout" }
|
||||
}
|
||||
main {
|
||||
files.read().path_names.iter().enumerate().map(|(dir_id, path)| {
|
||||
{files.read().path_names.iter().enumerate().map(|(dir_id, path)| {
|
||||
let path_end = path.split('/').last().unwrap_or(path.as_str());
|
||||
let icon_type = if path_end.contains('.') {
|
||||
"description"
|
||||
} else {
|
||||
"folder"
|
||||
};
|
||||
rsx! (
|
||||
div {
|
||||
class: "folder",
|
||||
key: "{path}",
|
||||
i { class: "material-icons",
|
||||
onclick: move |_| files.write().enter_dir(dir_id),
|
||||
"{icon_type}"
|
||||
if path_end.contains('.') {
|
||||
"description"
|
||||
} else {
|
||||
"folder"
|
||||
}
|
||||
p { class: "cooltip", "0 folders / 0 files" }
|
||||
}
|
||||
h1 { "{path_end}" }
|
||||
}
|
||||
)
|
||||
}),
|
||||
files.read().err.as_ref().map(|err| {
|
||||
rsx! (
|
||||
div {
|
||||
code { "{err}" }
|
||||
button { onclick: move |_| files.write().clear_err(), "x" }
|
||||
}
|
||||
)
|
||||
})
|
||||
})},
|
||||
if let Some(err) = files.read().err.as_ref() {
|
||||
div {
|
||||
code { "{err}" }
|
||||
button { onclick: move |_| files.write().clear_err(), "x" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#![allow(non_snake_case)]
|
||||
use dioxus::html::HasFileData;
|
||||
use dioxus::prelude::*;
|
||||
use tokio::time::sleep;
|
||||
|
||||
|
@ -39,9 +40,30 @@ fn App(cx: Scope) -> Element {
|
|||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
div { "progress: {files_uploaded.read().len()}" },
|
||||
}
|
||||
div {
|
||||
width: "100px",
|
||||
height: "100px",
|
||||
border: "1px solid black",
|
||||
prevent_default: "ondrop dragover dragenter",
|
||||
ondrop: move |evt| {
|
||||
to_owned![files_uploaded];
|
||||
async move {
|
||||
if let Some(file_engine) = &evt.files() {
|
||||
let files = file_engine.files();
|
||||
for file_name in &files {
|
||||
if let Some(file) = file_engine.read_file_to_string(file_name).await{
|
||||
files_uploaded.write().push(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
ondragover: move |event: DragEvent| {
|
||||
event.stop_propagation();
|
||||
},
|
||||
"Drop files here"
|
||||
}
|
||||
|
||||
ul {
|
||||
for file in files_uploaded.read().iter() {
|
||||
|
|
|
@ -66,9 +66,9 @@ fn app(cx: Scope) -> Element {
|
|||
}
|
||||
table {
|
||||
tbody {
|
||||
items.read().iter().enumerate().map(|(id, item)| {
|
||||
let is_in_danger = if (*selected).map(|s| s == id).unwrap_or(false) {"danger"} else {""};
|
||||
rsx!(tr { class: "{is_in_danger}",
|
||||
for (id, item) in items.read().iter().enumerate() {
|
||||
tr {
|
||||
class: if (*selected).map(|s| s == id).unwrap_or(false) { "danger" },
|
||||
td { class:"col-md-1" }
|
||||
td { class:"col-md-1", "{item.key}" }
|
||||
td { class:"col-md-1", onclick: move |_| selected.set(Some(id)),
|
||||
|
@ -80,8 +80,9 @@ fn app(cx: Scope) -> Element {
|
|||
}
|
||||
}
|
||||
td { class: "col-md-6" }
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
span { class: "preloadicon glyphicon glyphicon-remove", aria_hidden: "true" }
|
||||
|
|
|
@ -7,9 +7,9 @@ fn main() {
|
|||
}
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
cx.render(rsx! { generic_child {
|
||||
data: 0i32
|
||||
} })
|
||||
render! {
|
||||
generic_child { data: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Props)]
|
||||
|
@ -18,9 +18,7 @@ struct GenericChildProps<T: Display + PartialEq> {
|
|||
}
|
||||
|
||||
fn generic_child<T: Display + PartialEq>(cx: Scope<GenericChildProps<T>>) -> Element {
|
||||
let data = &cx.props.data;
|
||||
|
||||
cx.render(rsx! { div {
|
||||
"{data}"
|
||||
} })
|
||||
render! {
|
||||
div { "{&cx.props.data}" }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ fn main() {
|
|||
}
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
cx.render(rsx! (
|
||||
render! {
|
||||
div { "Hello, world!" }
|
||||
))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ const FIELDS: &[(&str, &str)] = &[
|
|||
fn app(cx: Scope) -> Element {
|
||||
cx.render(rsx! {
|
||||
div { margin_left: "30px",
|
||||
select_example(cx),
|
||||
{select_example(cx)},
|
||||
div {
|
||||
// handling inputs on divs will catch all input events below
|
||||
// so the value of our input event will be either huey, dewey, louie, or true/false (because of the checkboxe)
|
||||
|
@ -114,7 +114,7 @@ fn app(cx: Scope) -> Element {
|
|||
}
|
||||
}
|
||||
|
||||
FIELDS.iter().map(|(field, value)| rsx! {
|
||||
for (field, value) in FIELDS.iter() {
|
||||
div {
|
||||
input {
|
||||
id: "{field}",
|
||||
|
@ -131,7 +131,7 @@ fn app(cx: Scope) -> Element {
|
|||
}
|
||||
br {}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
3240
examples/mobile_demo/Cargo.lock
generated
Normal file
3240
examples/mobile_demo/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -35,7 +35,7 @@ frameworks = ["WebKit"]
|
|||
[dependencies]
|
||||
anyhow = "1.0.56"
|
||||
log = "0.4.11"
|
||||
wry = "0.34.0"
|
||||
wry = "0.35.0"
|
||||
dioxus = { path = "../../packages/dioxus" }
|
||||
dioxus-desktop = { path = "../../packages/desktop", features = [
|
||||
"tokio_runtime",
|
||||
|
|
|
@ -41,7 +41,7 @@ pub fn LogOut(cx: Scope<ClientProps>) -> Element {
|
|||
}
|
||||
Err(error) => {
|
||||
rsx! {
|
||||
div { format!{"Failed to load disconnection url: {:?}", error} }
|
||||
div { "Failed to load disconnection url: {error:?}" }
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -143,9 +143,9 @@ pub fn LoadClient(cx: Scope) -> Element {
|
|||
}
|
||||
}
|
||||
Err(error) => {
|
||||
log::info! {"Failed to load client: {:?}", error};
|
||||
rsx! {
|
||||
div { format!{"Failed to load client: {:?}", error} }
|
||||
log::info!{"Failed to load client: {:?}", error},
|
||||
div { "Failed to load client: {error:?}" }
|
||||
Outlet::<Route> {}
|
||||
}
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ pub fn AuthHeader(cx: Scope) -> Element {
|
|||
Ok(email) => {
|
||||
rsx! {
|
||||
div {
|
||||
div { email }
|
||||
div { {email} }
|
||||
LogOut { client_id: client_props.client_id, client: client_props.client }
|
||||
Outlet::<Route> {}
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ pub fn AuthHeader(cx: Scope) -> Element {
|
|||
log::info!("Other issue with token");
|
||||
rsx! {
|
||||
div {
|
||||
div { error.to_string() }
|
||||
div { "{error}" }
|
||||
Outlet::<Route> {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@ use dioxus::prelude::*;
|
|||
|
||||
#[component]
|
||||
pub fn NotFound(cx: Scope, route: Vec<String>) -> Element {
|
||||
let routes = route.join("");
|
||||
render! {rsx! {div{routes}}}
|
||||
render! {
|
||||
div{
|
||||
{route.join("")}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ use dioxus::events::*;
|
|||
use dioxus::html::input_data::keyboard_types::Key;
|
||||
use dioxus::html::MouseEvent;
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_desktop::wry::application::dpi::LogicalSize;
|
||||
use dioxus_desktop::tao::dpi::LogicalSize;
|
||||
use dioxus_desktop::{Config, WindowBuilder};
|
||||
|
||||
fn main() {
|
||||
|
@ -35,15 +35,17 @@ fn main() {
|
|||
dioxus_desktop::launch_cfg(app, cfg);
|
||||
}
|
||||
|
||||
const STYLE: &str = include_str!("./assets/calculator.css");
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
let state = use_ref(cx, Calculator::new);
|
||||
|
||||
cx.render(rsx! {
|
||||
style { include_str!("./assets/calculator.css") }
|
||||
style { {STYLE} }
|
||||
div { id: "wrapper",
|
||||
div { class: "app",
|
||||
div { class: "calculator", onkeypress: move |evt| state.write().handle_keydown(evt),
|
||||
div { class: "calculator-display", state.read().formatted_display() }
|
||||
div { class: "calculator-display", {state.read().formatted_display()} }
|
||||
div { class: "calculator-keypad",
|
||||
div { class: "input-keys",
|
||||
div { class: "function-keys",
|
||||
|
@ -74,14 +76,14 @@ fn app(cx: Scope) -> Element {
|
|||
onclick: move |_| state.write().input_dot(),
|
||||
"●"
|
||||
}
|
||||
(1..10).map(move |k| rsx!{
|
||||
for k in 1..10 {
|
||||
CalculatorKey {
|
||||
key: "{k}",
|
||||
name: "key-{k}",
|
||||
onclick: move |_| state.write().input_digit(k),
|
||||
"{k}"
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
div { class: "operator-keys",
|
||||
|
@ -130,7 +132,7 @@ fn CalculatorKey<'a>(cx: Scope<'a, CalculatorKeyProps<'a>>) -> Element {
|
|||
button {
|
||||
class: "calculator-key {cx.props.name}",
|
||||
onclick: move |e| cx.props.onclick.call(e),
|
||||
&cx.props.children
|
||||
{&cx.props.children}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ fn app(cx: Scope) -> Element {
|
|||
cx.render(rsx!(
|
||||
div {
|
||||
h1 {"Select an option"}
|
||||
h3 { "The radio is... ", state.is_playing(), "!" }
|
||||
h3 { "The radio is... ", {state.is_playing()}, "!" }
|
||||
button { onclick: move |_| state.make_mut().reduce(PlayerAction::Pause),
|
||||
"Pause"
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ impl FromQuery for ManualBlogQuerySegments {
|
|||
fn BlogPost(cx: Scope, query_params: ManualBlogQuerySegments) -> Element {
|
||||
render! {
|
||||
div{"This is your blogpost with a query segment:"}
|
||||
div{format!("{:?}", query_params)}
|
||||
div{ "{query_params:?}" }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,7 @@ fn BlogPost(cx: Scope, query_params: ManualBlogQuerySegments) -> Element {
|
|||
fn AutomaticBlogPost(cx: Scope, name: String, surname: String) -> Element {
|
||||
render! {
|
||||
div{"This is your blogpost with a query segment:"}
|
||||
div{format!("name={}&surname={}", name, surname)}
|
||||
div{ "name={name}&surname={surname}" }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,17 +36,17 @@ fn example(cx: Scope) -> Element {
|
|||
div { id: "asd",
|
||||
"your neighborhood spiderman"
|
||||
|
||||
items.iter().cycle().take(5).map(|f| rsx!{
|
||||
div { "{f.a}" }
|
||||
})
|
||||
for item in items.iter().cycle().take(5) {
|
||||
div { "{item.a}" }
|
||||
}
|
||||
|
||||
things_list.iter().map(|f| rsx!{
|
||||
div { "{f.a}" "{f.b}" }
|
||||
})
|
||||
for thing in things_list.iter() {
|
||||
div { "{thing.a}" "{thing.b}" }
|
||||
}
|
||||
|
||||
mything_read.as_ref().map(|f| rsx! {
|
||||
if let Some(f) = mything_read.as_ref() {
|
||||
div { "{f}" }
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
))
|
||||
|
|
|
@ -61,7 +61,7 @@ fn App(cx: Scope) -> Element {
|
|||
h1 {"Some text"}
|
||||
h1 {"Some text with {formatting}"}
|
||||
h1 {"Formatting basic expressions {formatting_tuple.0} and {formatting_tuple.1}"}
|
||||
h1 {"Formatting without interpolation " formatting_tuple.0 "and" formatting_tuple.1 }
|
||||
h1 {"Formatting without interpolation " {formatting_tuple.0} "and" {formatting_tuple.1} }
|
||||
h2 {
|
||||
"Multiple"
|
||||
"Text"
|
||||
|
@ -94,10 +94,10 @@ fn App(cx: Scope) -> Element {
|
|||
}
|
||||
|
||||
// Expressions can be used in element position too:
|
||||
rsx!(p { "More templating!" }),
|
||||
{rsx!(p { "More templating!" })},
|
||||
|
||||
// Iterators
|
||||
(0..10).map(|i| rsx!(li { "{i}" })),
|
||||
{(0..10).map(|i| rsx!(li { "{i}" }))},
|
||||
|
||||
// Iterators within expressions
|
||||
{
|
||||
|
@ -117,24 +117,25 @@ fn App(cx: Scope) -> Element {
|
|||
// Conditional rendering
|
||||
// Dioxus conditional rendering is based around None/Some. We have no special syntax for conditionals.
|
||||
// You can convert a bool condition to rsx! with .then and .or
|
||||
true.then(|| rsx!(div {})),
|
||||
{true.then(|| rsx!(div {}))},
|
||||
|
||||
// Alternatively, you can use the "if" syntax - but both branches must be resolve to Element
|
||||
if false {
|
||||
rsx!(h1 {"Top text"})
|
||||
h1 {"Top text"}
|
||||
} else {
|
||||
rsx!(h1 {"Bottom text"})
|
||||
h1 {"Bottom text"}
|
||||
}
|
||||
|
||||
// Using optionals for diverging branches
|
||||
if true {
|
||||
// Note that since this is wrapped in curlies, it's interpreted as an expression
|
||||
{if true {
|
||||
Some(rsx!(h1 {"Top text"}))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}}
|
||||
|
||||
// returning "None" without a diverging branch is a bit noisy... but rare in practice
|
||||
None as Option<()>,
|
||||
{None as Option<()>},
|
||||
|
||||
// can also just use empty fragments
|
||||
Fragment {}
|
||||
|
@ -169,13 +170,13 @@ fn App(cx: Scope) -> Element {
|
|||
|
||||
// Can pass in props directly as an expression
|
||||
{
|
||||
let props = TallerProps {a: "hello", children: cx.render(rsx!(()))};
|
||||
let props = TallerProps {a: "hello", children: None };
|
||||
rsx!(Taller { ..props })
|
||||
}
|
||||
|
||||
// Spreading can also be overridden manually
|
||||
Taller {
|
||||
..TallerProps { a: "ballin!", children: cx.render(rsx!(()) )},
|
||||
..TallerProps { a: "ballin!", children: None },
|
||||
a: "not ballin!"
|
||||
}
|
||||
|
||||
|
@ -204,16 +205,16 @@ fn App(cx: Scope) -> Element {
|
|||
|
||||
// helper functions
|
||||
// Anything that implements IntoVnode can be dropped directly into Rsx
|
||||
helper(cx, "hello world!")
|
||||
{helper(cx, "hello world!")}
|
||||
|
||||
// Strings can be supplied directly
|
||||
String::from("Hello world!")
|
||||
{String::from("Hello world!")}
|
||||
|
||||
// So can format_args
|
||||
format_args!("Hello {}!", "world")
|
||||
{format_args!("Hello {}!", "world")}
|
||||
|
||||
// Or we can shell out to a helper function
|
||||
format_dollars(10, 50)
|
||||
{format_dollars(10, 50)}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -269,7 +270,7 @@ pub struct TallerProps<'a> {
|
|||
#[component]
|
||||
pub fn Taller<'a>(cx: Scope<'a, TallerProps<'a>>) -> Element {
|
||||
cx.render(rsx! {
|
||||
&cx.props.children
|
||||
{&cx.props.children}
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -22,8 +22,10 @@ fn app(cx: Scope) -> Element {
|
|||
|
||||
button {
|
||||
onclick: move |_| {
|
||||
if let Some(header) = header_element.read().as_ref() {
|
||||
header.scroll_to(ScrollBehavior::Smooth);
|
||||
if let Some(header) = header_element.read().as_ref().cloned() {
|
||||
cx.spawn(async move {
|
||||
let _ = header.scroll_to(ScrollBehavior::Smooth).await;
|
||||
});
|
||||
}
|
||||
},
|
||||
"Scroll to top"
|
||||
|
|
|
@ -51,26 +51,23 @@ pub fn App(cx: Scope) -> Element {
|
|||
|
||||
#[component]
|
||||
fn DataEditor(cx: Scope, id: usize) -> Element {
|
||||
let cool_data = use_shared_state::<CoolData>(cx).unwrap().read();
|
||||
let data = use_shared_state::<CoolData>(cx)?;
|
||||
|
||||
let my_data = &cool_data.view(id).unwrap();
|
||||
|
||||
render!(p {
|
||||
"{my_data}"
|
||||
})
|
||||
render! {
|
||||
p {
|
||||
{data.read().view(id)?}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn DataView(cx: Scope, id: usize) -> Element {
|
||||
let cool_data = use_shared_state::<CoolData>(cx).unwrap();
|
||||
let data = use_shared_state::<CoolData>(cx)?;
|
||||
|
||||
let oninput = |e: FormEvent| cool_data.write().set(*id, e.value());
|
||||
|
||||
let cool_data = cool_data.read();
|
||||
let my_data = &cool_data.view(id).unwrap();
|
||||
|
||||
render!(input {
|
||||
oninput: oninput,
|
||||
value: "{my_data}"
|
||||
})
|
||||
render! {
|
||||
input {
|
||||
oninput: move |e: FormEvent| data.write().set(*id, e.value()),
|
||||
value: data.read().view(id)?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
45
examples/shorthand.rs
Normal file
45
examples/shorthand.rs
Normal file
|
@ -0,0 +1,45 @@
|
|||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
dioxus_desktop::launch(app);
|
||||
}
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
let a = 123;
|
||||
let b = 456;
|
||||
let c = 789;
|
||||
let class = "class";
|
||||
let id = "id";
|
||||
|
||||
// todo: i'd like it for children on elements to be inferred as the children of the element
|
||||
// also should shorthands understand references/dereferences?
|
||||
// ie **a, *a, &a, &mut a, etc
|
||||
let children = render! { "Child" };
|
||||
let onclick = move |_| println!("Clicked!");
|
||||
|
||||
render! {
|
||||
div { class, id, {&children} }
|
||||
Component { a, b, c, children, onclick }
|
||||
Component { a, ..ComponentProps { a: 1, b: 2, c: 3, children: None, onclick: Default::default() } }
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn Component<'a>(
|
||||
cx: Scope<'a>,
|
||||
a: i32,
|
||||
b: i32,
|
||||
c: i32,
|
||||
children: Element<'a>,
|
||||
onclick: EventHandler<'a, ()>,
|
||||
) -> Element {
|
||||
render! {
|
||||
div { "{a}" }
|
||||
div { "{b}" }
|
||||
div { "{c}" }
|
||||
div { {children} }
|
||||
div {
|
||||
onclick: move |_| onclick.call(()),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -31,7 +31,7 @@ fn app(cx: Scope) -> Element {
|
|||
|
||||
// We can do boolean operations on the current signal value
|
||||
if count.value() > 5 {
|
||||
rsx!{ h2 { "High five!" } }
|
||||
h2 { "High five!" }
|
||||
}
|
||||
|
||||
// We can cleanly map signals with iterators
|
||||
|
@ -41,9 +41,9 @@ fn app(cx: Scope) -> Element {
|
|||
|
||||
// We can also use the signal value as a slice
|
||||
if let [ref first, .., ref last] = saved_values.read().as_slice() {
|
||||
rsx! { li { "First and last: {first}, {last}" } }
|
||||
li { "First and last: {first}, {last}" }
|
||||
} else {
|
||||
rsx! { "No saved values" }
|
||||
"No saved values"
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -8,17 +8,17 @@ fn app(cx: Scope) -> Element {
|
|||
cx.render(rsx!(
|
||||
div {
|
||||
// Use Map directly to lazily pull elements
|
||||
(0..10).map(|f| rsx! { "{f}" }),
|
||||
{(0..10).map(|f| rsx! { "{f}" })},
|
||||
|
||||
// Collect into an intermediate collection if necessary, and call into_iter
|
||||
["a", "b", "c", "d", "e", "f"]
|
||||
{["a", "b", "c", "d", "e", "f"]
|
||||
.into_iter()
|
||||
.map(|f| rsx! { "{f}" })
|
||||
.collect::<Vec<_>>()
|
||||
.into_iter(),
|
||||
.into_iter()},
|
||||
|
||||
// Use optionals
|
||||
Some(rsx! { "Some" }),
|
||||
{Some(rsx! { "Some" })},
|
||||
|
||||
// use a for loop where the body itself is RSX
|
||||
for name in 0..10 {
|
||||
|
@ -27,7 +27,7 @@ fn app(cx: Scope) -> Element {
|
|||
|
||||
// Or even use an unterminated conditional
|
||||
if true {
|
||||
rsx!{ "hello world!" }
|
||||
"hello world!"
|
||||
}
|
||||
}
|
||||
))
|
||||
|
|
36
examples/spread.rs
Normal file
36
examples/spread.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
let mut dom = VirtualDom::new(app);
|
||||
let _ = dom.rebuild();
|
||||
let html = dioxus_ssr::render(&dom);
|
||||
|
||||
println!("{}", html);
|
||||
}
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
render! {
|
||||
Component {
|
||||
width: "10px",
|
||||
extra_data: "hello{1}",
|
||||
extra_data2: "hello{2}",
|
||||
height: "10px",
|
||||
left: 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn Component<'a>(cx: Scope<'a, Props<'a>>) -> Element<'a> {
|
||||
render! {
|
||||
audio { ..cx.props.attributes, "1: {cx.props.extra_data}\n2: {cx.props.extra_data2}" }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Props)]
|
||||
struct Props<'a> {
|
||||
#[props(extends = GlobalAttributes)]
|
||||
attributes: Vec<Attribute<'a>>,
|
||||
extra_data: &'a str,
|
||||
extra_data2: &'a str,
|
||||
}
|
33
examples/streams.rs
Normal file
33
examples/streams.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
use dioxus::prelude::*;
|
||||
use dioxus_signals::use_signal;
|
||||
use futures_util::{future, stream, Stream, StreamExt};
|
||||
use std::time::Duration;
|
||||
|
||||
fn main() {
|
||||
dioxus_desktop::launch(app);
|
||||
}
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
let count = use_signal(cx, || 10);
|
||||
|
||||
use_future(cx, (), |_| async move {
|
||||
let mut stream = some_stream();
|
||||
|
||||
while let Some(second) = stream.next().await {
|
||||
count.set(second);
|
||||
}
|
||||
});
|
||||
|
||||
cx.render(rsx! {
|
||||
h1 { "High-Five counter: {count}" }
|
||||
})
|
||||
}
|
||||
|
||||
fn some_stream() -> std::pin::Pin<Box<dyn Stream<Item = i32>>> {
|
||||
Box::pin(
|
||||
stream::once(future::ready(0)).chain(stream::iter(1..).then(|second| async move {
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
second
|
||||
})),
|
||||
)
|
||||
}
|
|
@ -97,7 +97,7 @@ pub fn Die<'a>(cx: Scope<'a, DieProps<'a>>) -> Element {
|
|||
fill: "{fill}",
|
||||
}
|
||||
|
||||
dots
|
||||
{dots}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ publish = false
|
|||
|
||||
[dependencies]
|
||||
dioxus = { path = "../../packages/dioxus" }
|
||||
manganis = { workspace = true }
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
dioxus-desktop = { path = "../../packages/desktop" }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use dioxus::prelude::*;
|
||||
|
||||
const _STYLE: &str = mg!(file("./public/tailwind.css"));
|
||||
const _STYLE: &str = manganis::mg!(file("./public/tailwind.css"));
|
||||
|
||||
fn main() {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
|
|
|
@ -7,8 +7,6 @@ fn main() {
|
|||
dioxus_desktop::launch(app);
|
||||
}
|
||||
|
||||
const _STYLE: &str = mg!(file("./examples/assets/todomvc.css"));
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Copy)]
|
||||
pub enum FilterState {
|
||||
All,
|
||||
|
@ -49,33 +47,34 @@ pub fn app(cx: Scope<()>) -> Element {
|
|||
|
||||
cx.render(rsx! {
|
||||
section { class: "todoapp",
|
||||
style { {include_str!("./assets/todomvc.css")} }
|
||||
TodoHeader { todos: todos }
|
||||
section { class: "main",
|
||||
if !todos.is_empty() {
|
||||
rsx! {
|
||||
input {
|
||||
id: "toggle-all",
|
||||
class: "toggle-all",
|
||||
r#type: "checkbox",
|
||||
onchange: move |_| {
|
||||
let check = active_todo_count != 0;
|
||||
for (_, item) in todos.make_mut().iter_mut() {
|
||||
item.checked = check;
|
||||
}
|
||||
},
|
||||
checked: if active_todo_count == 0 { "true" } else { "false" },
|
||||
}
|
||||
label { r#for: "toggle-all" }
|
||||
input {
|
||||
id: "toggle-all",
|
||||
class: "toggle-all",
|
||||
r#type: "checkbox",
|
||||
onchange: move |_| {
|
||||
let check = active_todo_count != 0;
|
||||
for (_, item) in todos.make_mut().iter_mut() {
|
||||
item.checked = check;
|
||||
}
|
||||
},
|
||||
checked: if active_todo_count == 0 { "true" } else { "false" },
|
||||
}
|
||||
label { r#for: "toggle-all" }
|
||||
}
|
||||
ul { class: "todo-list",
|
||||
filtered_todos.iter().map(|id| rsx!(TodoEntry {
|
||||
key: "{id}",
|
||||
id: *id,
|
||||
todos: todos,
|
||||
}))
|
||||
for id in filtered_todos.iter() {
|
||||
TodoEntry {
|
||||
key: "{id}",
|
||||
id: *id,
|
||||
todos: todos,
|
||||
}
|
||||
}
|
||||
}
|
||||
(!todos.is_empty()).then(|| rsx!(
|
||||
if !todos.is_empty() {
|
||||
ListFooter {
|
||||
active_todo_count: active_todo_count,
|
||||
active_todo_text: active_todo_text,
|
||||
|
@ -83,7 +82,7 @@ pub fn app(cx: Scope<()>) -> Element {
|
|||
todos: todos,
|
||||
filter: filter,
|
||||
}
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
PageFooter {}
|
||||
|
@ -172,7 +171,7 @@ pub fn TodoEntry<'a>(cx: Scope<'a, TodoEntryProps<'a>>) -> Element {
|
|||
prevent_default: "onclick"
|
||||
}
|
||||
}
|
||||
is_editing.then(|| rsx!{
|
||||
if **is_editing {
|
||||
input {
|
||||
class: "edit",
|
||||
value: "{todo.contents}",
|
||||
|
@ -186,7 +185,7 @@ pub fn TodoEntry<'a>(cx: Scope<'a, TodoEntryProps<'a>>) -> Element {
|
|||
}
|
||||
},
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -220,29 +219,27 @@ pub fn ListFooter<'a>(cx: Scope<'a, ListFooterProps<'a>>) -> Element {
|
|||
}
|
||||
ul { class: "filters",
|
||||
for (state , state_text , url) in [
|
||||
(FilterState::All, "All", "#/"),
|
||||
(FilterState::Active, "Active", "#/active"),
|
||||
(FilterState::Completed, "Completed", "#/completed"),
|
||||
] {
|
||||
(FilterState::All, "All", "#/"),
|
||||
(FilterState::Active, "Active", "#/active"),
|
||||
(FilterState::Completed, "Completed", "#/completed"),
|
||||
] {
|
||||
li {
|
||||
a {
|
||||
href: url,
|
||||
class: selected(state),
|
||||
onclick: move |_| cx.props.filter.set(state),
|
||||
prevent_default: "onclick",
|
||||
state_text
|
||||
{state_text}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if cx.props.show_clear_completed {
|
||||
cx.render(rsx! {
|
||||
button {
|
||||
class: "clear-completed",
|
||||
onclick: move |_| cx.props.todos.make_mut().retain(|_, todo| !todo.checked),
|
||||
"Clear completed"
|
||||
}
|
||||
})
|
||||
button {
|
||||
class: "clear-completed",
|
||||
onclick: move |_| cx.props.todos.make_mut().retain(|_, todo| !todo.checked),
|
||||
"Clear completed"
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
@ -3,7 +3,6 @@ use dioxus_desktop::wry::http;
|
|||
use dioxus_desktop::wry::http::Response;
|
||||
use dioxus_desktop::{use_asset_handler, AssetRequest};
|
||||
use http::{header::*, response::Builder as ResponseBuilder, status::StatusCode};
|
||||
use std::borrow::Cow;
|
||||
use std::{io::SeekFrom, path::PathBuf};
|
||||
use tokio::io::AsyncReadExt;
|
||||
use tokio::io::AsyncSeekExt;
|
||||
|
@ -31,28 +30,33 @@ fn main() {
|
|||
}
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
use_asset_handler(cx, move |request: &AssetRequest| {
|
||||
let request = request.clone();
|
||||
async move {
|
||||
use_asset_handler(cx, "videos", move |request, responder| {
|
||||
// Using dioxus::spawn works, but is slower than a dedicated thread
|
||||
tokio::task::spawn(async move {
|
||||
let video_file = PathBuf::from(VIDEO_PATH);
|
||||
let mut file = tokio::fs::File::open(&video_file).await.unwrap();
|
||||
let response: Option<Response<Cow<'static, [u8]>>> =
|
||||
match get_stream_response(&mut file, &request).await {
|
||||
Ok(response) => Some(response.map(Cow::Owned)),
|
||||
Err(err) => {
|
||||
eprintln!("Error: {}", err);
|
||||
None
|
||||
}
|
||||
};
|
||||
response
|
||||
}
|
||||
|
||||
match get_stream_response(&mut file, &request).await {
|
||||
Ok(response) => responder.respond(response),
|
||||
Err(err) => eprintln!("Error: {}", err),
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
render! {
|
||||
div { video { src: "test_video.mp4", autoplay: true, controls: true, width: 640, height: 480 } }
|
||||
div {
|
||||
video {
|
||||
src: "/videos/test_video.mp4",
|
||||
autoplay: true,
|
||||
controls: true,
|
||||
width: 640,
|
||||
height: 480
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// This was taken from wry's example
|
||||
async fn get_stream_response(
|
||||
asset: &mut (impl tokio::io::AsyncSeek + tokio::io::AsyncRead + Unpin + Send + Sync),
|
||||
request: &AssetRequest,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use dioxus::prelude::*;
|
||||
use dioxus_desktop::tao::event::Event as WryEvent;
|
||||
use dioxus_desktop::tao::event::WindowEvent;
|
||||
use dioxus_desktop::use_wry_event_handler;
|
||||
use dioxus_desktop::wry::application::event::Event as WryEvent;
|
||||
use dioxus_desktop::{Config, WindowCloseBehaviour};
|
||||
|
||||
fn main() {
|
||||
|
|
247
flake.lock
Normal file
247
flake.lock
Normal file
|
@ -0,0 +1,247 @@
|
|||
{
|
||||
"nodes": {
|
||||
"crane": {
|
||||
"inputs": {
|
||||
"flake-compat": "flake-compat",
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
],
|
||||
"rust-overlay": "rust-overlay"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1696384830,
|
||||
"narHash": "sha256-j8ZsVqzmj5sOm5MW9cqwQJUZELFFwOislDmqDDEMl6k=",
|
||||
"owner": "ipetkov",
|
||||
"repo": "crane",
|
||||
"rev": "f2143cd27f8bd09ee4f0121336c65015a2a0a19c",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "ipetkov",
|
||||
"repo": "crane",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-compat": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1696267196,
|
||||
"narHash": "sha256-AAQ/2sD+0D18bb8hKuEEVpHUYD1GmO2Uh/taFamn6XQ=",
|
||||
"owner": "edolstra",
|
||||
"repo": "flake-compat",
|
||||
"rev": "4f910c9827911b1ec2bf26b5a062cd09f8d89f85",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "edolstra",
|
||||
"repo": "flake-compat",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-parts": {
|
||||
"inputs": {
|
||||
"nixpkgs-lib": "nixpkgs-lib"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1696343447,
|
||||
"narHash": "sha256-B2xAZKLkkeRFG5XcHHSXXcP7To9Xzr59KXeZiRf4vdQ=",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"rev": "c9afaba3dfa4085dbd2ccb38dfade5141e33d9d4",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1694529238,
|
||||
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-utils_2": {
|
||||
"inputs": {
|
||||
"systems": "systems_2"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1681202837,
|
||||
"narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "cfacdce06f30d2b68473a46042957675eebb3401",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1697009197,
|
||||
"narHash": "sha256-viVRhBTFT8fPJTb1N3brQIpFZnttmwo3JVKNuWRVc3s=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "01441e14af5e29c9d27ace398e6dd0b293e25a54",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"ref": "nixpkgs-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs-lib": {
|
||||
"locked": {
|
||||
"dir": "lib",
|
||||
"lastModified": 1696019113,
|
||||
"narHash": "sha256-X3+DKYWJm93DRSdC5M6K5hLqzSya9BjibtBsuARoPco=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "f5892ddac112a1e9b3612c39af1b72987ee5783a",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"dir": "lib",
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 1681358109,
|
||||
"narHash": "sha256-eKyxW4OohHQx9Urxi7TQlFBTDWII+F+x2hklDOQPB50=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "96ba1c52e54e74c3197f4d43026b3f3d92e83ff9",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixpkgs-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"crane": "crane",
|
||||
"flake-parts": "flake-parts",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"rust-overlay": "rust-overlay_2",
|
||||
"systems": "systems_3"
|
||||
}
|
||||
},
|
||||
"rust-overlay": {
|
||||
"inputs": {
|
||||
"flake-utils": [
|
||||
"crane",
|
||||
"flake-utils"
|
||||
],
|
||||
"nixpkgs": [
|
||||
"crane",
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1696299134,
|
||||
"narHash": "sha256-RS77cAa0N+Sfj5EmKbm5IdncNXaBCE1BSSQvUE8exvo=",
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"rev": "611ccdceed92b4d94ae75328148d84ee4a5b462d",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"rust-overlay_2": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils_2",
|
||||
"nixpkgs": "nixpkgs_2"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1697076655,
|
||||
"narHash": "sha256-NcCtVUOd0X81srZkrdP8qoA1BMsPdO2tGtlZpsGijeU=",
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"rev": "aa7584f5bbf5947716ad8ec14eccc0334f0d28f0",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"systems_2": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"systems_3": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
63
flake.nix
Normal file
63
flake.nix
Normal file
|
@ -0,0 +1,63 @@
|
|||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
|
||||
flake-parts.url = "github:hercules-ci/flake-parts";
|
||||
systems.url = "github:nix-systems/default";
|
||||
|
||||
rust-overlay.url = "github:oxalica/rust-overlay";
|
||||
crane.url = "github:ipetkov/crane";
|
||||
crane.inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
outputs = inputs:
|
||||
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
|
||||
systems = import inputs.systems;
|
||||
|
||||
perSystem = { config, self', pkgs, lib, system, ... }:
|
||||
let
|
||||
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
|
||||
extensions = [
|
||||
"rust-src"
|
||||
"rust-analyzer"
|
||||
"clippy"
|
||||
];
|
||||
};
|
||||
rustBuildInputs = [
|
||||
pkgs.openssl
|
||||
pkgs.libiconv
|
||||
pkgs.pkg-config
|
||||
] ++ lib.optionals pkgs.stdenv.isDarwin (with pkgs.darwin.apple_sdk.frameworks; [
|
||||
IOKit
|
||||
Carbon
|
||||
WebKit
|
||||
Security
|
||||
Cocoa
|
||||
]);
|
||||
|
||||
# This is useful when building crates as packages
|
||||
# Note that it does require a `Cargo.lock` which this repo does not have
|
||||
# craneLib = (inputs.crane.mkLib pkgs).overrideToolchain rustToolchain;
|
||||
in
|
||||
{
|
||||
_module.args.pkgs = import inputs.nixpkgs {
|
||||
inherit system;
|
||||
overlays = [
|
||||
inputs.rust-overlay.overlays.default
|
||||
];
|
||||
};
|
||||
|
||||
devShells.default = pkgs.mkShell {
|
||||
name = "dioxus-dev";
|
||||
buildInputs = rustBuildInputs;
|
||||
nativeBuildInputs = [
|
||||
# Add shell dependencies here
|
||||
rustToolchain
|
||||
];
|
||||
shellHook = ''
|
||||
# For rust-analyzer 'hover' tooltips to work.
|
||||
export RUST_SRC_PATH="${rustToolchain}/lib/rustlib/src/rust/library";
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
|
@ -67,7 +67,7 @@ impl Writer<'_> {
|
|||
}
|
||||
|
||||
// multiline handlers bump everything down
|
||||
if attr_len > 1000 {
|
||||
if attr_len > 1000 || self.out.indent.split_line_attributes() {
|
||||
opt_level = ShortOptimization::NoOpt;
|
||||
}
|
||||
|
||||
|
@ -158,7 +158,7 @@ impl Writer<'_> {
|
|||
|
||||
while let Some(field) = field_iter.next() {
|
||||
if !sameline {
|
||||
self.out.indented_tabbed_line()?;
|
||||
self.out.indented_tabbed_line().unwrap();
|
||||
}
|
||||
|
||||
let name = &field.name;
|
||||
|
@ -182,6 +182,9 @@ impl Writer<'_> {
|
|||
s.source.as_ref().unwrap().to_token_stream()
|
||||
)?;
|
||||
}
|
||||
ContentField::Shorthand(e) => {
|
||||
write!(self.out, "{}", e.to_token_stream())?;
|
||||
}
|
||||
ContentField::OnHandlerRaw(exp) => {
|
||||
let out = prettyplease::unparse_expr(exp);
|
||||
let mut lines = out.split('\n').peekable();
|
||||
|
@ -206,7 +209,7 @@ impl Writer<'_> {
|
|||
|
||||
if let Some(exp) = manual_props {
|
||||
if !sameline {
|
||||
self.out.indented_tabbed_line()?;
|
||||
self.out.indented_tabbed_line().unwrap();
|
||||
}
|
||||
self.write_manual_props(exp)?;
|
||||
}
|
||||
|
@ -223,6 +226,7 @@ impl Writer<'_> {
|
|||
.iter()
|
||||
.map(|field| match &field.content {
|
||||
ContentField::Formatted(s) => ifmt_to_string(s).len() ,
|
||||
ContentField::Shorthand(e) => e.to_token_stream().to_string().len(),
|
||||
ContentField::OnHandlerRaw(exp) | ContentField::ManExpr(exp) => {
|
||||
let formatted = prettyplease::unparse_expr(exp);
|
||||
let len = if formatted.contains('\n') {
|
||||
|
|
|
@ -103,7 +103,7 @@ impl Writer<'_> {
|
|||
}
|
||||
|
||||
// multiline handlers bump everything down
|
||||
if attr_len > 1000 {
|
||||
if attr_len > 1000 || self.out.indent.split_line_attributes() {
|
||||
opt_level = ShortOptimization::NoOpt;
|
||||
}
|
||||
|
||||
|
@ -166,7 +166,7 @@ impl Writer<'_> {
|
|||
|
||||
fn write_attributes(
|
||||
&mut self,
|
||||
attributes: &[ElementAttrNamed],
|
||||
attributes: &[AttributeType],
|
||||
key: &Option<IfmtInput>,
|
||||
sameline: bool,
|
||||
) -> Result {
|
||||
|
@ -188,7 +188,7 @@ impl Writer<'_> {
|
|||
while let Some(attr) = attr_iter.next() {
|
||||
self.out.indent_level += 1;
|
||||
if !sameline {
|
||||
self.write_comments(attr.attr.start())?;
|
||||
self.write_comments(attr.start())?;
|
||||
}
|
||||
self.out.indent_level -= 1;
|
||||
|
||||
|
@ -237,6 +237,9 @@ impl Writer<'_> {
|
|||
ElementAttrValue::AttrLiteral(value) => {
|
||||
write!(self.out, "{value}", value = ifmt_to_string(value))?;
|
||||
}
|
||||
ElementAttrValue::Shorthand(value) => {
|
||||
write!(self.out, "{value}",)?;
|
||||
}
|
||||
ElementAttrValue::AttrExpr(value) => {
|
||||
let out = prettyplease::unparse_expr(value);
|
||||
let mut lines = out.split('\n').peekable();
|
||||
|
@ -262,7 +265,6 @@ impl Writer<'_> {
|
|||
}
|
||||
ElementAttrValue::EventTokens(tokens) => {
|
||||
let out = self.retrieve_formatted_expr(tokens).to_string();
|
||||
|
||||
let mut lines = out.split('\n').peekable();
|
||||
let first = lines.next().unwrap();
|
||||
|
||||
|
@ -289,7 +291,14 @@ impl Writer<'_> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn write_attribute(&mut self, attr: &ElementAttrNamed) -> Result {
|
||||
fn write_attribute(&mut self, attr: &AttributeType) -> Result {
|
||||
match attr {
|
||||
AttributeType::Named(attr) => self.write_named_attribute(attr),
|
||||
AttributeType::Spread(attr) => self.write_spread_attribute(attr),
|
||||
}
|
||||
}
|
||||
|
||||
fn write_named_attribute(&mut self, attr: &ElementAttrNamed) -> Result {
|
||||
self.write_attribute_name(&attr.attr.name)?;
|
||||
write!(self.out, ": ")?;
|
||||
self.write_attribute_value(&attr.attr.value)?;
|
||||
|
@ -297,6 +306,13 @@ impl Writer<'_> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn write_spread_attribute(&mut self, attr: &Expr) -> Result {
|
||||
write!(self.out, "..")?;
|
||||
write!(self.out, "{}", prettyplease::unparse_expr(attr))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// make sure the comments are actually relevant to this element.
|
||||
// test by making sure this element is the primary element on this line
|
||||
pub fn current_span_is_primary(&self, location: Span) -> bool {
|
||||
|
@ -313,6 +329,10 @@ impl Writer<'_> {
|
|||
beginning.is_empty()
|
||||
}
|
||||
|
||||
pub fn is_empty_children(&self, children: &[BodyNode]) -> bool {
|
||||
children.is_empty()
|
||||
}
|
||||
|
||||
// check if the children are short enough to be on the same line
|
||||
// We don't have the notion of current line depth - each line tries to be < 80 total
|
||||
// returns the total line length if it's short
|
||||
|
|
|
@ -8,10 +8,11 @@ pub enum IndentType {
|
|||
pub struct IndentOptions {
|
||||
width: usize,
|
||||
indent_string: String,
|
||||
split_line_attributes: bool,
|
||||
}
|
||||
|
||||
impl IndentOptions {
|
||||
pub fn new(typ: IndentType, width: usize) -> Self {
|
||||
pub fn new(typ: IndentType, width: usize, split_line_attributes: bool) -> Self {
|
||||
assert_ne!(width, 0, "Cannot have an indent width of 0");
|
||||
Self {
|
||||
width,
|
||||
|
@ -19,6 +20,7 @@ impl IndentOptions {
|
|||
IndentType::Tabs => "\t".into(),
|
||||
IndentType::Spaces => " ".repeat(width),
|
||||
},
|
||||
split_line_attributes,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,11 +64,15 @@ impl IndentOptions {
|
|||
}
|
||||
indent
|
||||
}
|
||||
|
||||
pub fn split_line_attributes(&self) -> bool {
|
||||
self.split_line_attributes
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for IndentOptions {
|
||||
fn default() -> Self {
|
||||
Self::new(IndentType::Spaces, 4)
|
||||
Self::new(IndentType::Spaces, 4, false)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,31 +83,31 @@ mod tests {
|
|||
#[test]
|
||||
fn count_indents() {
|
||||
assert_eq!(
|
||||
IndentOptions::new(IndentType::Spaces, 4).count_indents("no indentation here!"),
|
||||
IndentOptions::new(IndentType::Spaces, 4, false).count_indents("no indentation here!"),
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
IndentOptions::new(IndentType::Spaces, 4).count_indents(" v += 2"),
|
||||
IndentOptions::new(IndentType::Spaces, 4, false).count_indents(" v += 2"),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
IndentOptions::new(IndentType::Spaces, 4).count_indents(" v += 2"),
|
||||
IndentOptions::new(IndentType::Spaces, 4, false).count_indents(" v += 2"),
|
||||
2
|
||||
);
|
||||
assert_eq!(
|
||||
IndentOptions::new(IndentType::Spaces, 4).count_indents(" v += 2"),
|
||||
IndentOptions::new(IndentType::Spaces, 4, false).count_indents(" v += 2"),
|
||||
2
|
||||
);
|
||||
assert_eq!(
|
||||
IndentOptions::new(IndentType::Spaces, 4).count_indents("\t\tv += 2"),
|
||||
IndentOptions::new(IndentType::Spaces, 4, false).count_indents("\t\tv += 2"),
|
||||
2
|
||||
);
|
||||
assert_eq!(
|
||||
IndentOptions::new(IndentType::Spaces, 4).count_indents("\t\t v += 2"),
|
||||
IndentOptions::new(IndentType::Spaces, 4, false).count_indents("\t\t v += 2"),
|
||||
2
|
||||
);
|
||||
assert_eq!(
|
||||
IndentOptions::new(IndentType::Spaces, 2).count_indents(" v += 2"),
|
||||
IndentOptions::new(IndentType::Spaces, 2, false).count_indents(" v += 2"),
|
||||
2
|
||||
);
|
||||
}
|
||||
|
|
|
@ -140,7 +140,9 @@ pub fn write_block_out(body: CallBody) -> Option<String> {
|
|||
}
|
||||
|
||||
fn write_body(buf: &mut Writer, body: &CallBody) {
|
||||
if buf.is_short_children(&body.roots).is_some() {
|
||||
let is_short = buf.is_short_children(&body.roots).is_some();
|
||||
let is_empty = buf.is_empty_children(&body.roots);
|
||||
if (is_short && !buf.out.indent.split_line_attributes()) || is_empty {
|
||||
// write all the indents with spaces and commas between
|
||||
for idx in 0..body.roots.len() - 1 {
|
||||
let ident = &body.roots[idx];
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use dioxus_rsx::{BodyNode, ElementAttrNamed, ElementAttrValue, ForLoop};
|
||||
use dioxus_rsx::{AttributeType, BodyNode, ElementAttrValue, ForLoop, IfChain};
|
||||
use proc_macro2::{LineColumn, Span};
|
||||
use quote::ToTokens;
|
||||
use std::{
|
||||
collections::{HashMap, VecDeque},
|
||||
fmt::{Result, Write},
|
||||
};
|
||||
use syn::{spanned::Spanned, Expr, ExprIf};
|
||||
use syn::{spanned::Spanned, Expr};
|
||||
|
||||
use crate::buffer::Buffer;
|
||||
use crate::ifmt_to_string;
|
||||
|
@ -142,6 +142,7 @@ impl<'a> Writer<'a> {
|
|||
}
|
||||
ElementAttrValue::AttrLiteral(lit) => ifmt_to_string(lit).len(),
|
||||
ElementAttrValue::AttrExpr(expr) => expr.span().line_length(),
|
||||
ElementAttrValue::Shorthand(expr) => expr.span().line_length(),
|
||||
ElementAttrValue::EventTokens(tokens) => {
|
||||
let location = Location::new(tokens.span().start());
|
||||
|
||||
|
@ -165,12 +166,12 @@ impl<'a> Writer<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn is_short_attrs(&mut self, attributes: &[ElementAttrNamed]) -> usize {
|
||||
pub(crate) fn is_short_attrs(&mut self, attributes: &[AttributeType]) -> usize {
|
||||
let mut total = 0;
|
||||
|
||||
for attr in attributes {
|
||||
if self.current_span_is_primary(attr.attr.start()) {
|
||||
'line: for line in self.src[..attr.attr.start().start().line - 1].iter().rev() {
|
||||
if self.current_span_is_primary(attr.start()) {
|
||||
'line: for line in self.src[..attr.start().start().line - 1].iter().rev() {
|
||||
match (line.trim().starts_with("//"), line.is_empty()) {
|
||||
(true, _) => return 100000,
|
||||
(_, true) => continue 'line,
|
||||
|
@ -179,16 +180,24 @@ impl<'a> Writer<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
total += match &attr.attr.name {
|
||||
dioxus_rsx::ElementAttrName::BuiltIn(name) => {
|
||||
let name = name.to_string();
|
||||
name.len()
|
||||
match attr {
|
||||
AttributeType::Named(attr) => {
|
||||
let name_len = match &attr.attr.name {
|
||||
dioxus_rsx::ElementAttrName::BuiltIn(name) => {
|
||||
let name = name.to_string();
|
||||
name.len()
|
||||
}
|
||||
dioxus_rsx::ElementAttrName::Custom(name) => name.value().len() + 2,
|
||||
};
|
||||
total += name_len;
|
||||
total += self.attr_value_len(&attr.attr.value);
|
||||
}
|
||||
AttributeType::Spread(expr) => {
|
||||
let expr_len = self.retrieve_formatted_expr(expr).len();
|
||||
total += expr_len + 3;
|
||||
}
|
||||
dioxus_rsx::ElementAttrName::Custom(name) => name.value().len() + 2,
|
||||
};
|
||||
|
||||
total += self.attr_value_len(&attr.attr.value);
|
||||
|
||||
total += 6;
|
||||
}
|
||||
|
||||
|
@ -223,8 +232,49 @@ impl<'a> Writer<'a> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn write_if_chain(&mut self, ifchain: &ExprIf) -> std::fmt::Result {
|
||||
self.write_raw_expr(ifchain.span())
|
||||
fn write_if_chain(&mut self, ifchain: &IfChain) -> std::fmt::Result {
|
||||
// Recurse in place by setting the next chain
|
||||
let mut branch = Some(ifchain);
|
||||
|
||||
while let Some(chain) = branch {
|
||||
let IfChain {
|
||||
if_token,
|
||||
cond,
|
||||
then_branch,
|
||||
else_if_branch,
|
||||
else_branch,
|
||||
} = chain;
|
||||
|
||||
write!(
|
||||
self.out,
|
||||
"{} {} {{",
|
||||
if_token.to_token_stream(),
|
||||
prettyplease::unparse_expr(cond)
|
||||
)?;
|
||||
|
||||
self.write_body_indented(then_branch)?;
|
||||
|
||||
if let Some(else_if_branch) = else_if_branch {
|
||||
// write the closing bracket and else
|
||||
self.out.tabbed_line()?;
|
||||
write!(self.out, "}} else ")?;
|
||||
|
||||
branch = Some(else_if_branch);
|
||||
} else if let Some(else_branch) = else_branch {
|
||||
self.out.tabbed_line()?;
|
||||
write!(self.out, "}} else {{")?;
|
||||
|
||||
self.write_body_indented(else_branch)?;
|
||||
branch = None;
|
||||
} else {
|
||||
branch = None;
|
||||
}
|
||||
}
|
||||
|
||||
self.out.tabbed_line()?;
|
||||
write!(self.out, "}}")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,18 +12,6 @@ rsx! {
|
|||
let blah = 120;
|
||||
true
|
||||
},
|
||||
onclick: move |_| {
|
||||
let blah = 120;
|
||||
true
|
||||
},
|
||||
onclick: move |_| {
|
||||
let blah = 120;
|
||||
true
|
||||
},
|
||||
onclick: move |_| {
|
||||
let blah = 120;
|
||||
true
|
||||
},
|
||||
div {
|
||||
div { "hi" }
|
||||
h2 { class: "asd" }
|
||||
|
|
|
@ -8,17 +8,17 @@ rsx! {
|
|||
"hello world"
|
||||
|
||||
// Comments
|
||||
expr1,
|
||||
{expr1},
|
||||
|
||||
// Comments
|
||||
expr2,
|
||||
{expr2},
|
||||
|
||||
// Comments
|
||||
// Comments
|
||||
// Comments
|
||||
// Comments
|
||||
// Comments
|
||||
expr3,
|
||||
{expr3},
|
||||
|
||||
div {
|
||||
// todo some work in here
|
||||
|
|
|
@ -6,7 +6,7 @@ rsx! {
|
|||
show_user_menu.set(!show_user_menu.get());
|
||||
evt.cancel_bubble();
|
||||
},
|
||||
onclick: move |evt| show_user_menu.set(!show_user_menu.get()),
|
||||
onmousedown: move |evt| show_user_menu.set(!show_user_menu.get()),
|
||||
span { class: "inline-block mr-4", icons::icon_14 {} }
|
||||
span { "Settings" }
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ rsx! {
|
|||
to: "{to}",
|
||||
span { class: "inline-block mr-3", icons::icon_0 {} }
|
||||
span { "{name}" }
|
||||
children.is_some().then(|| rsx! {
|
||||
{children.is_some().then(|| rsx! {
|
||||
span {
|
||||
class: "inline-block ml-auto hover:bg-gray-500",
|
||||
onclick: move |evt| {
|
||||
|
@ -27,9 +27,9 @@ rsx! {
|
|||
},
|
||||
icons::icon_8 {}
|
||||
}
|
||||
})
|
||||
})}
|
||||
}
|
||||
div { class: "px-4", is_current.then(|| rsx!{ children }) }
|
||||
div { class: "px-4", {is_current.then(|| rsx!{ children })} }
|
||||
}
|
||||
|
||||
// No nesting
|
||||
|
@ -48,5 +48,5 @@ rsx! {
|
|||
}
|
||||
}
|
||||
|
||||
div { asdbascasdbasd, asbdasbdabsd, asbdabsdbasdbas }
|
||||
div { "asdbascasdbasd", "asbdasbdabsd", {asbdabsdbasdbas} }
|
||||
}
|
||||
|
|
|
@ -8,6 +8,20 @@ rsx! {
|
|||
// Some ifchain
|
||||
if a > 10 {
|
||||
//
|
||||
rsx! { div {} }
|
||||
div {}
|
||||
} else if a > 20 {
|
||||
h1 {}
|
||||
} else if a > 20 {
|
||||
h1 {}
|
||||
} else if a > 20 {
|
||||
h1 {}
|
||||
} else if a > 20 {
|
||||
h1 {}
|
||||
} else if a > 20 {
|
||||
h1 {}
|
||||
} else if a > 20 {
|
||||
h1 {}
|
||||
} else {
|
||||
h3 {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
fn it_works() {
|
||||
cx.render(rsx!(()))
|
||||
cx.render(rsx!({()}))
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ pub fn Explainer<'a>(
|
|||
// pt-5 sm:pt-24 lg:pt-24
|
||||
|
||||
let mut right = rsx! {
|
||||
div { class: "relative w-1/2", flasher }
|
||||
div { class: "relative w-1/2", {flasher} }
|
||||
};
|
||||
|
||||
let align = match invert {
|
||||
|
@ -24,7 +24,7 @@ pub fn Explainer<'a>(
|
|||
h2 { class: "mb-6 text-3xl leading-tight md:text-4xl md:leading-tight lg:text-3xl lg:leading-tight font-heading font-mono font-bold",
|
||||
"{title}"
|
||||
}
|
||||
content
|
||||
{content}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -34,8 +34,8 @@ pub fn Explainer<'a>(
|
|||
|
||||
cx.render(rsx! {
|
||||
div { class: "flex flex-wrap items-center dark:text-white py-16 border-t font-light",
|
||||
left,
|
||||
right
|
||||
{left},
|
||||
{right}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ rsx! {
|
|||
section { class: "body-font overflow-hidden dark:bg-ideblack",
|
||||
div { class: "container px-6 mx-auto",
|
||||
div { class: "-my-8 divide-y-2 divide-gray-100",
|
||||
POSTS.iter().enumerate().map(|(id, post)| rsx! { BlogPostItem { post: post, id: id } })
|
||||
{POSTS.iter().enumerate().map(|(id, post)| rsx! { BlogPostItem { post: post, id: id } })}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,20 +4,20 @@ rsx! {
|
|||
div {}
|
||||
|
||||
// hi
|
||||
div { abcd, ball, s }
|
||||
div { "abcd", "ball", "s" }
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
div { abcd, ball, s }
|
||||
div { "abcd", "ball", "s" }
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
div {
|
||||
abcd,
|
||||
ball,
|
||||
s,
|
||||
"abcd"
|
||||
"ball"
|
||||
"s"
|
||||
|
||||
//
|
||||
"asdasd"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
fn it_works() {
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
span { "Description: ", package.description.as_deref().unwrap_or("❌❌❌❌ missing") }
|
||||
span { "Description: ", {package.description.as_deref().unwrap_or("❌❌❌❌ missing")} }
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -18,11 +18,11 @@ macro_rules! twoway {
|
|||
};
|
||||
}
|
||||
|
||||
twoway!("comments-4sp" => comments_4sp (IndentOptions::new(IndentType::Spaces, 4)));
|
||||
twoway!("comments-tab" => comments_tab (IndentOptions::new(IndentType::Tabs, 4)));
|
||||
twoway!("comments-4sp" => comments_4sp (IndentOptions::new(IndentType::Spaces, 4, false)));
|
||||
twoway!("comments-tab" => comments_tab (IndentOptions::new(IndentType::Tabs, 4, false)));
|
||||
|
||||
twoway!("multi-4sp" => multi_4sp (IndentOptions::new(IndentType::Spaces, 4)));
|
||||
twoway!("multi-tab" => multi_tab (IndentOptions::new(IndentType::Tabs, 4)));
|
||||
twoway!("multi-4sp" => multi_4sp (IndentOptions::new(IndentType::Spaces, 4, false)));
|
||||
twoway!("multi-tab" => multi_tab (IndentOptions::new(IndentType::Tabs, 4, false)));
|
||||
|
||||
twoway!("multiexpr-4sp" => multiexpr_4sp (IndentOptions::new(IndentType::Spaces, 4)));
|
||||
twoway!("multiexpr-tab" => multiexpr_tab (IndentOptions::new(IndentType::Tabs, 4)));
|
||||
twoway!("multiexpr-4sp" => multiexpr_4sp (IndentOptions::new(IndentType::Spaces, 4, false)));
|
||||
twoway!("multiexpr-tab" => multiexpr_tab (IndentOptions::new(IndentType::Tabs, 4, false)));
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
fn ItWroks() {
|
||||
cx.render(rsx! {
|
||||
div { class: "flex flex-wrap items-center dark:text-white py-16 border-t font-light",
|
||||
left,
|
||||
right
|
||||
{left},
|
||||
{right}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
fn ItWroks() {
|
||||
cx.render(rsx! {
|
||||
div { class: "flex flex-wrap items-center dark:text-white py-16 border-t font-light", left, right }
|
||||
div { class: "flex flex-wrap items-center dark:text-white py-16 border-t font-light", {left}, {right} }
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
fn ItWroks() {
|
||||
cx.render(rsx! {
|
||||
div { class: "flex flex-wrap items-center dark:text-white py-16 border-t font-light",
|
||||
left,
|
||||
right
|
||||
{left},
|
||||
{right}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
fn ItWroks() {
|
||||
cx.render(rsx! {
|
||||
div { class: "flex flex-wrap items-center dark:text-white py-16 border-t font-light", left, right }
|
||||
div { class: "flex flex-wrap items-center dark:text-white py-16 border-t font-light", {left}, {right} }
|
||||
})
|
||||
}
|
||||
|
|
4
packages/cli-config/.gitignore
vendored
Normal file
4
packages/cli-config/.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
/target
|
||||
Cargo.lock
|
||||
.DS_Store
|
||||
.idea/
|
26
packages/cli-config/Cargo.toml
Normal file
26
packages/cli-config/Cargo.toml
Normal file
|
@ -0,0 +1,26 @@
|
|||
[package]
|
||||
name = "dioxus-cli-config"
|
||||
version = "0.4.1"
|
||||
authors = ["Jonathan Kelley"]
|
||||
edition = "2021"
|
||||
description = "Configuration for the Dioxus CLI"
|
||||
repository = "https://github.com/DioxusLabs/dioxus/"
|
||||
license = "MIT OR Apache-2.0"
|
||||
keywords = ["react", "gui", "cli", "dioxus", "wasm"]
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.2", features = ["derive"], optional = true }
|
||||
serde = { version = "1.0.136", features = ["derive"] }
|
||||
serde_json = "1.0.79"
|
||||
toml = { version = "0.5.8", optional = true }
|
||||
cargo_toml = { version = "0.16.0", optional = true }
|
||||
once_cell = "1.18.0"
|
||||
tracing.workspace = true
|
||||
|
||||
# bundling
|
||||
tauri-bundler = { version = "=1.4.0", features = ["native-tls-vendored"], optional = true }
|
||||
tauri-utils = { version = "=1.5.*", optional = true }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
cli = ["tauri-bundler", "tauri-utils", "clap", "toml", "cargo_toml"]
|
5
packages/cli-config/README.md
Normal file
5
packages/cli-config/README.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
<div style="text-align: center">
|
||||
<h1>📦✨ Dioxus CLI Configuration</h1>
|
||||
</div>
|
||||
|
||||
The **dioxus-cli-config** contains the configuration for the **dioxus-cli**.
|
260
packages/cli-config/src/bundle.rs
Normal file
260
packages/cli-config/src/bundle.rs
Normal file
|
@ -0,0 +1,260 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct BundleConfig {
|
||||
pub identifier: Option<String>,
|
||||
pub publisher: Option<String>,
|
||||
pub icon: Option<Vec<String>>,
|
||||
pub resources: Option<Vec<String>>,
|
||||
pub copyright: Option<String>,
|
||||
pub category: Option<String>,
|
||||
pub short_description: Option<String>,
|
||||
pub long_description: Option<String>,
|
||||
pub external_bin: Option<Vec<String>>,
|
||||
pub deb: Option<DebianSettings>,
|
||||
pub macos: Option<MacOsSettings>,
|
||||
pub windows: Option<WindowsSettings>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "cli")]
|
||||
impl From<BundleConfig> for tauri_bundler::BundleSettings {
|
||||
fn from(val: BundleConfig) -> Self {
|
||||
tauri_bundler::BundleSettings {
|
||||
identifier: val.identifier,
|
||||
publisher: val.publisher,
|
||||
icon: val.icon,
|
||||
resources: val.resources,
|
||||
copyright: val.copyright,
|
||||
category: val.category.and_then(|c| c.parse().ok()),
|
||||
short_description: val.short_description,
|
||||
long_description: val.long_description,
|
||||
external_bin: val.external_bin,
|
||||
deb: val.deb.map(Into::into).unwrap_or_default(),
|
||||
macos: val.macos.map(Into::into).unwrap_or_default(),
|
||||
windows: val.windows.map(Into::into).unwrap_or_default(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct DebianSettings {
|
||||
pub depends: Option<Vec<String>>,
|
||||
pub files: HashMap<PathBuf, PathBuf>,
|
||||
pub nsis: Option<NsisSettings>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "cli")]
|
||||
impl From<DebianSettings> for tauri_bundler::DebianSettings {
|
||||
fn from(val: DebianSettings) -> Self {
|
||||
tauri_bundler::DebianSettings {
|
||||
depends: val.depends,
|
||||
files: val.files,
|
||||
desktop_template: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct WixSettings {
|
||||
pub language: Vec<(String, Option<PathBuf>)>,
|
||||
pub template: Option<PathBuf>,
|
||||
pub fragment_paths: Vec<PathBuf>,
|
||||
pub component_group_refs: Vec<String>,
|
||||
pub component_refs: Vec<String>,
|
||||
pub feature_group_refs: Vec<String>,
|
||||
pub feature_refs: Vec<String>,
|
||||
pub merge_refs: Vec<String>,
|
||||
pub skip_webview_install: bool,
|
||||
pub license: Option<PathBuf>,
|
||||
pub enable_elevated_update_task: bool,
|
||||
pub banner_path: Option<PathBuf>,
|
||||
pub dialog_image_path: Option<PathBuf>,
|
||||
pub fips_compliant: bool,
|
||||
}
|
||||
|
||||
#[cfg(feature = "cli")]
|
||||
impl From<WixSettings> for tauri_bundler::WixSettings {
|
||||
fn from(val: WixSettings) -> Self {
|
||||
tauri_bundler::WixSettings {
|
||||
language: tauri_bundler::bundle::WixLanguage({
|
||||
let mut languages: Vec<_> = val
|
||||
.language
|
||||
.iter()
|
||||
.map(|l| {
|
||||
(
|
||||
l.0.clone(),
|
||||
tauri_bundler::bundle::WixLanguageConfig {
|
||||
locale_path: l.1.clone(),
|
||||
},
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
if languages.is_empty() {
|
||||
languages.push(("en-US".into(), Default::default()));
|
||||
}
|
||||
languages
|
||||
}),
|
||||
template: val.template,
|
||||
fragment_paths: val.fragment_paths,
|
||||
component_group_refs: val.component_group_refs,
|
||||
component_refs: val.component_refs,
|
||||
feature_group_refs: val.feature_group_refs,
|
||||
feature_refs: val.feature_refs,
|
||||
merge_refs: val.merge_refs,
|
||||
skip_webview_install: val.skip_webview_install,
|
||||
license: val.license,
|
||||
enable_elevated_update_task: val.enable_elevated_update_task,
|
||||
banner_path: val.banner_path,
|
||||
dialog_image_path: val.dialog_image_path,
|
||||
fips_compliant: val.fips_compliant,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct MacOsSettings {
|
||||
pub frameworks: Option<Vec<String>>,
|
||||
pub minimum_system_version: Option<String>,
|
||||
pub license: Option<String>,
|
||||
pub exception_domain: Option<String>,
|
||||
pub signing_identity: Option<String>,
|
||||
pub provider_short_name: Option<String>,
|
||||
pub entitlements: Option<String>,
|
||||
pub info_plist_path: Option<PathBuf>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "cli")]
|
||||
impl From<MacOsSettings> for tauri_bundler::MacOsSettings {
|
||||
fn from(val: MacOsSettings) -> Self {
|
||||
tauri_bundler::MacOsSettings {
|
||||
frameworks: val.frameworks,
|
||||
minimum_system_version: val.minimum_system_version,
|
||||
license: val.license,
|
||||
exception_domain: val.exception_domain,
|
||||
signing_identity: val.signing_identity,
|
||||
provider_short_name: val.provider_short_name,
|
||||
entitlements: val.entitlements,
|
||||
info_plist_path: val.info_plist_path,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct WindowsSettings {
|
||||
pub digest_algorithm: Option<String>,
|
||||
pub certificate_thumbprint: Option<String>,
|
||||
pub timestamp_url: Option<String>,
|
||||
pub tsp: bool,
|
||||
pub wix: Option<WixSettings>,
|
||||
pub icon_path: Option<PathBuf>,
|
||||
pub webview_install_mode: WebviewInstallMode,
|
||||
pub webview_fixed_runtime_path: Option<PathBuf>,
|
||||
pub allow_downgrades: bool,
|
||||
pub nsis: Option<NsisSettings>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "cli")]
|
||||
impl From<WindowsSettings> for tauri_bundler::WindowsSettings {
|
||||
fn from(val: WindowsSettings) -> Self {
|
||||
tauri_bundler::WindowsSettings {
|
||||
digest_algorithm: val.digest_algorithm,
|
||||
certificate_thumbprint: val.certificate_thumbprint,
|
||||
timestamp_url: val.timestamp_url,
|
||||
tsp: val.tsp,
|
||||
wix: val.wix.map(Into::into),
|
||||
icon_path: val.icon_path.unwrap_or("icons/icon.ico".into()),
|
||||
webview_install_mode: val.webview_install_mode.into(),
|
||||
webview_fixed_runtime_path: val.webview_fixed_runtime_path,
|
||||
allow_downgrades: val.allow_downgrades,
|
||||
nsis: val.nsis.map(Into::into),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct NsisSettings {
|
||||
pub template: Option<PathBuf>,
|
||||
pub license: Option<PathBuf>,
|
||||
pub header_image: Option<PathBuf>,
|
||||
pub sidebar_image: Option<PathBuf>,
|
||||
pub installer_icon: Option<PathBuf>,
|
||||
pub install_mode: NSISInstallerMode,
|
||||
pub languages: Option<Vec<String>>,
|
||||
pub custom_language_files: Option<HashMap<String, PathBuf>>,
|
||||
pub display_language_selector: bool,
|
||||
}
|
||||
|
||||
#[cfg(feature = "cli")]
|
||||
impl From<NsisSettings> for tauri_bundler::NsisSettings {
|
||||
fn from(val: NsisSettings) -> Self {
|
||||
tauri_bundler::NsisSettings {
|
||||
license: val.license,
|
||||
header_image: val.header_image,
|
||||
sidebar_image: val.sidebar_image,
|
||||
installer_icon: val.installer_icon,
|
||||
install_mode: val.install_mode.into(),
|
||||
languages: val.languages,
|
||||
display_language_selector: val.display_language_selector,
|
||||
custom_language_files: None,
|
||||
template: None,
|
||||
compression: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum NSISInstallerMode {
|
||||
CurrentUser,
|
||||
PerMachine,
|
||||
Both,
|
||||
}
|
||||
|
||||
#[cfg(feature = "cli")]
|
||||
impl From<NSISInstallerMode> for tauri_utils::config::NSISInstallerMode {
|
||||
fn from(val: NSISInstallerMode) -> Self {
|
||||
match val {
|
||||
NSISInstallerMode::CurrentUser => tauri_utils::config::NSISInstallerMode::CurrentUser,
|
||||
NSISInstallerMode::PerMachine => tauri_utils::config::NSISInstallerMode::PerMachine,
|
||||
NSISInstallerMode::Both => tauri_utils::config::NSISInstallerMode::Both,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum WebviewInstallMode {
|
||||
Skip,
|
||||
DownloadBootstrapper { silent: bool },
|
||||
EmbedBootstrapper { silent: bool },
|
||||
OfflineInstaller { silent: bool },
|
||||
FixedRuntime { path: PathBuf },
|
||||
}
|
||||
|
||||
#[cfg(feature = "cli")]
|
||||
impl WebviewInstallMode {
|
||||
fn into(self) -> tauri_utils::config::WebviewInstallMode {
|
||||
match self {
|
||||
Self::Skip => tauri_utils::config::WebviewInstallMode::Skip,
|
||||
Self::DownloadBootstrapper { silent } => {
|
||||
tauri_utils::config::WebviewInstallMode::DownloadBootstrapper { silent }
|
||||
}
|
||||
Self::EmbedBootstrapper { silent } => {
|
||||
tauri_utils::config::WebviewInstallMode::EmbedBootstrapper { silent }
|
||||
}
|
||||
Self::OfflineInstaller { silent } => {
|
||||
tauri_utils::config::WebviewInstallMode::OfflineInstaller { silent }
|
||||
}
|
||||
Self::FixedRuntime { path } => {
|
||||
tauri_utils::config::WebviewInstallMode::FixedRuntime { path }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for WebviewInstallMode {
|
||||
fn default() -> Self {
|
||||
Self::OfflineInstaller { silent: false }
|
||||
}
|
||||
}
|
|
@ -1,12 +1,33 @@
|
|||
//! Utilities for working with cargo and rust files
|
||||
use crate::error::{Error, Result};
|
||||
use std::error::Error;
|
||||
use std::{
|
||||
env, fs,
|
||||
env,
|
||||
fmt::{Display, Formatter},
|
||||
fs,
|
||||
path::{Path, PathBuf},
|
||||
process::Command,
|
||||
str,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct CargoError {
|
||||
msg: String,
|
||||
}
|
||||
|
||||
impl CargoError {
|
||||
pub fn new(msg: String) -> Self {
|
||||
Self { msg }
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for CargoError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "CargoError: {}", self.msg)
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for CargoError {}
|
||||
|
||||
/// How many parent folders are searched for a `Cargo.toml`
|
||||
const MAX_ANCESTORS: u32 = 10;
|
||||
|
||||
|
@ -19,7 +40,7 @@ pub struct Metadata {
|
|||
/// Returns the root of the crate that the command is run from
|
||||
///
|
||||
/// If the command is run from the workspace root, this will return the top-level Cargo.toml
|
||||
pub fn crate_root() -> Result<PathBuf> {
|
||||
pub fn crate_root() -> Result<PathBuf, CargoError> {
|
||||
// From the current directory we work our way up, looking for `Cargo.toml`
|
||||
env::current_dir()
|
||||
.ok()
|
||||
|
@ -35,7 +56,7 @@ pub fn crate_root() -> Result<PathBuf> {
|
|||
None
|
||||
})
|
||||
.ok_or_else(|| {
|
||||
Error::CargoError("Failed to find directory containing Cargo.toml".to_string())
|
||||
CargoError::new("Failed to find directory containing Cargo.toml".to_string())
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -53,11 +74,11 @@ fn contains_manifest(path: &Path) -> bool {
|
|||
impl Metadata {
|
||||
/// Returns the struct filled from `cargo metadata` output
|
||||
/// TODO @Jon, find a different way that doesn't rely on the cargo metadata command (it's slow)
|
||||
pub fn get() -> Result<Self> {
|
||||
pub fn get() -> Result<Self, CargoError> {
|
||||
let output = Command::new("cargo")
|
||||
.args(["metadata"])
|
||||
.output()
|
||||
.map_err(|_| Error::CargoError("Manifset".to_string()))?;
|
||||
.map_err(|_| CargoError::new("Manifset".to_string()))?;
|
||||
|
||||
if !output.status.success() {
|
||||
let mut msg = str::from_utf8(&output.stderr).unwrap().trim();
|
||||
|
@ -65,22 +86,22 @@ impl Metadata {
|
|||
msg = &msg[7..];
|
||||
}
|
||||
|
||||
return Err(Error::CargoError(msg.to_string()));
|
||||
return Err(CargoError::new(msg.to_string()));
|
||||
}
|
||||
|
||||
let stdout = str::from_utf8(&output.stdout).unwrap();
|
||||
if let Some(line) = stdout.lines().next() {
|
||||
let meta: serde_json::Value = serde_json::from_str(line)
|
||||
.map_err(|_| Error::CargoError("InvalidOutput".to_string()))?;
|
||||
.map_err(|_| CargoError::new("InvalidOutput".to_string()))?;
|
||||
|
||||
let workspace_root = meta["workspace_root"]
|
||||
.as_str()
|
||||
.ok_or_else(|| Error::CargoError("InvalidOutput".to_string()))?
|
||||
.ok_or_else(|| CargoError::new("InvalidOutput".to_string()))?
|
||||
.into();
|
||||
|
||||
let target_directory = meta["target_directory"]
|
||||
.as_str()
|
||||
.ok_or_else(|| Error::CargoError("InvalidOutput".to_string()))?
|
||||
.ok_or_else(|| CargoError::new("InvalidOutput".to_string()))?
|
||||
.into();
|
||||
|
||||
return Ok(Self {
|
||||
|
@ -89,6 +110,6 @@ impl Metadata {
|
|||
});
|
||||
}
|
||||
|
||||
Err(Error::CargoError("InvalidOutput".to_string()))
|
||||
Err(CargoError::new("InvalidOutput".to_string()))
|
||||
}
|
||||
}
|
492
packages/cli-config/src/config.rs
Normal file
492
packages/cli-config/src/config.rs
Normal file
|
@ -0,0 +1,492 @@
|
|||
use crate::BundleConfig;
|
||||
use crate::CargoError;
|
||||
use core::fmt::{Display, Formatter};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Debug)]
|
||||
#[cfg_attr(feature = "cli", derive(clap::ValueEnum))]
|
||||
pub enum Platform {
|
||||
#[cfg_attr(feature = "cli", clap(name = "web"))]
|
||||
#[serde(rename = "web")]
|
||||
Web,
|
||||
#[cfg_attr(feature = "cli", clap(name = "desktop"))]
|
||||
#[serde(rename = "desktop")]
|
||||
Desktop,
|
||||
#[cfg_attr(feature = "cli", clap(name = "fullstack"))]
|
||||
#[serde(rename = "fullstack")]
|
||||
Fullstack,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct DioxusConfig {
|
||||
pub application: ApplicationConfig,
|
||||
|
||||
pub web: WebConfig,
|
||||
|
||||
#[serde(default)]
|
||||
pub bundle: BundleConfig,
|
||||
|
||||
#[cfg(feature = "cli")]
|
||||
#[serde(default = "default_plugin")]
|
||||
pub plugin: toml::Value,
|
||||
}
|
||||
|
||||
#[cfg(feature = "cli")]
|
||||
fn default_plugin() -> toml::Value {
|
||||
toml::Value::Boolean(true)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct LoadDioxusConfigError {
|
||||
location: String,
|
||||
error: String,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for LoadDioxusConfigError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{} {}", self.location, self.error)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for LoadDioxusConfigError {}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum CrateConfigError {
|
||||
Cargo(CargoError),
|
||||
Io(std::io::Error),
|
||||
#[cfg(feature = "cli")]
|
||||
Toml(toml::de::Error),
|
||||
LoadDioxusConfig(LoadDioxusConfigError),
|
||||
}
|
||||
|
||||
impl From<CargoError> for CrateConfigError {
|
||||
fn from(err: CargoError) -> Self {
|
||||
Self::Cargo(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for CrateConfigError {
|
||||
fn from(err: std::io::Error) -> Self {
|
||||
Self::Io(err)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "cli")]
|
||||
impl From<toml::de::Error> for CrateConfigError {
|
||||
fn from(err: toml::de::Error) -> Self {
|
||||
Self::Toml(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<LoadDioxusConfigError> for CrateConfigError {
|
||||
fn from(err: LoadDioxusConfigError) -> Self {
|
||||
Self::LoadDioxusConfig(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for CrateConfigError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Cargo(err) => write!(f, "{}", err),
|
||||
Self::Io(err) => write!(f, "{}", err),
|
||||
#[cfg(feature = "cli")]
|
||||
Self::Toml(err) => write!(f, "{}", err),
|
||||
Self::LoadDioxusConfig(err) => write!(f, "{}", err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for CrateConfigError {}
|
||||
|
||||
impl DioxusConfig {
|
||||
#[cfg(feature = "cli")]
|
||||
/// Load the dioxus config from a path
|
||||
pub fn load(bin: Option<PathBuf>) -> Result<Option<DioxusConfig>, CrateConfigError> {
|
||||
let crate_dir = crate::cargo::crate_root();
|
||||
|
||||
let crate_dir = match crate_dir {
|
||||
Ok(dir) => {
|
||||
if let Some(bin) = bin {
|
||||
dir.join(bin)
|
||||
} else {
|
||||
dir
|
||||
}
|
||||
}
|
||||
Err(_) => return Ok(None),
|
||||
};
|
||||
let crate_dir = crate_dir.as_path();
|
||||
|
||||
let Some(dioxus_conf_file) = acquire_dioxus_toml(crate_dir) else {
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
let dioxus_conf_file = dioxus_conf_file.as_path();
|
||||
let cfg = toml::from_str::<DioxusConfig>(&std::fs::read_to_string(dioxus_conf_file)?)
|
||||
.map_err(|err| {
|
||||
let error_location = dioxus_conf_file
|
||||
.strip_prefix(crate_dir)
|
||||
.unwrap_or(dioxus_conf_file)
|
||||
.display();
|
||||
CrateConfigError::LoadDioxusConfig(LoadDioxusConfigError {
|
||||
location: error_location.to_string(),
|
||||
error: err.to_string(),
|
||||
})
|
||||
})
|
||||
.map(Some);
|
||||
match cfg {
|
||||
Ok(Some(mut cfg)) => {
|
||||
let name = cfg.application.name.clone();
|
||||
if cfg.bundle.identifier.is_none() {
|
||||
cfg.bundle.identifier = Some(format!("io.github.{name}"));
|
||||
}
|
||||
if cfg.bundle.publisher.is_none() {
|
||||
cfg.bundle.publisher = Some(name);
|
||||
}
|
||||
Ok(Some(cfg))
|
||||
}
|
||||
cfg => cfg,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "cli")]
|
||||
fn acquire_dioxus_toml(dir: &std::path::Path) -> Option<PathBuf> {
|
||||
// prefer uppercase
|
||||
let uppercase_conf = dir.join("Dioxus.toml");
|
||||
if uppercase_conf.is_file() {
|
||||
return Some(uppercase_conf);
|
||||
}
|
||||
|
||||
// lowercase is fine too
|
||||
let lowercase_conf = dir.join("dioxus.toml");
|
||||
if lowercase_conf.is_file() {
|
||||
return Some(lowercase_conf);
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
impl Default for DioxusConfig {
|
||||
fn default() -> Self {
|
||||
let name = default_name();
|
||||
Self {
|
||||
application: ApplicationConfig {
|
||||
name: name.clone(),
|
||||
default_platform: default_platform(),
|
||||
out_dir: out_dir_default(),
|
||||
asset_dir: asset_dir_default(),
|
||||
|
||||
#[cfg(feature = "cli")]
|
||||
tools: Default::default(),
|
||||
|
||||
sub_package: None,
|
||||
},
|
||||
web: WebConfig {
|
||||
app: WebAppConfig {
|
||||
title: default_title(),
|
||||
base_path: None,
|
||||
},
|
||||
proxy: vec![],
|
||||
watcher: Default::default(),
|
||||
resource: WebResourceConfig {
|
||||
dev: WebDevResourceConfig {
|
||||
style: vec![],
|
||||
script: vec![],
|
||||
},
|
||||
style: Some(vec![]),
|
||||
script: Some(vec![]),
|
||||
},
|
||||
https: WebHttpsConfig {
|
||||
enabled: None,
|
||||
mkcert: None,
|
||||
key_path: None,
|
||||
cert_path: None,
|
||||
},
|
||||
},
|
||||
bundle: BundleConfig {
|
||||
identifier: Some(format!("io.github.{name}")),
|
||||
publisher: Some(name),
|
||||
..Default::default()
|
||||
},
|
||||
#[cfg(feature = "cli")]
|
||||
plugin: toml::Value::Table(toml::map::Map::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ApplicationConfig {
|
||||
#[serde(default = "default_name")]
|
||||
pub name: String,
|
||||
#[serde(default = "default_platform")]
|
||||
pub default_platform: Platform,
|
||||
#[serde(default = "out_dir_default")]
|
||||
pub out_dir: PathBuf,
|
||||
#[serde(default = "asset_dir_default")]
|
||||
pub asset_dir: PathBuf,
|
||||
|
||||
#[cfg(feature = "cli")]
|
||||
#[serde(default)]
|
||||
pub tools: std::collections::HashMap<String, toml::Value>,
|
||||
|
||||
#[serde(default)]
|
||||
pub sub_package: Option<String>,
|
||||
}
|
||||
|
||||
fn default_name() -> String {
|
||||
"name".into()
|
||||
}
|
||||
|
||||
fn default_platform() -> Platform {
|
||||
Platform::Web
|
||||
}
|
||||
|
||||
fn asset_dir_default() -> PathBuf {
|
||||
PathBuf::from("public")
|
||||
}
|
||||
|
||||
fn out_dir_default() -> PathBuf {
|
||||
PathBuf::from("dist")
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct WebConfig {
|
||||
#[serde(default)]
|
||||
pub app: WebAppConfig,
|
||||
#[serde(default)]
|
||||
pub proxy: Vec<WebProxyConfig>,
|
||||
#[serde(default)]
|
||||
pub watcher: WebWatcherConfig,
|
||||
#[serde(default)]
|
||||
pub resource: WebResourceConfig,
|
||||
#[serde(default)]
|
||||
pub https: WebHttpsConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct WebAppConfig {
|
||||
#[serde(default = "default_title")]
|
||||
pub title: String,
|
||||
pub base_path: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for WebAppConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
title: default_title(),
|
||||
base_path: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn default_title() -> String {
|
||||
"dioxus | ⛺".into()
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct WebProxyConfig {
|
||||
pub backend: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct WebWatcherConfig {
|
||||
#[serde(default = "watch_path_default")]
|
||||
pub watch_path: Vec<PathBuf>,
|
||||
#[serde(default)]
|
||||
pub reload_html: bool,
|
||||
#[serde(default = "true_bool")]
|
||||
pub index_on_404: bool,
|
||||
}
|
||||
|
||||
impl Default for WebWatcherConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
watch_path: watch_path_default(),
|
||||
reload_html: false,
|
||||
index_on_404: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn watch_path_default() -> Vec<PathBuf> {
|
||||
vec![PathBuf::from("src"), PathBuf::from("examples")]
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct WebResourceConfig {
|
||||
pub dev: WebDevResourceConfig,
|
||||
pub style: Option<Vec<PathBuf>>,
|
||||
pub script: Option<Vec<PathBuf>>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct WebDevResourceConfig {
|
||||
#[serde(default)]
|
||||
pub style: Vec<PathBuf>,
|
||||
#[serde(default)]
|
||||
pub script: Vec<PathBuf>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
|
||||
pub struct WebHttpsConfig {
|
||||
pub enabled: Option<bool>,
|
||||
pub mkcert: Option<bool>,
|
||||
pub key_path: Option<String>,
|
||||
pub cert_path: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct CrateConfig {
|
||||
pub out_dir: PathBuf,
|
||||
pub crate_dir: PathBuf,
|
||||
pub workspace_dir: PathBuf,
|
||||
pub target_dir: PathBuf,
|
||||
pub asset_dir: PathBuf,
|
||||
#[cfg(feature = "cli")]
|
||||
pub manifest: cargo_toml::Manifest<cargo_toml::Value>,
|
||||
pub executable: ExecutableType,
|
||||
pub dioxus_config: DioxusConfig,
|
||||
pub release: bool,
|
||||
pub hot_reload: bool,
|
||||
pub cross_origin_policy: bool,
|
||||
pub verbose: bool,
|
||||
pub custom_profile: Option<String>,
|
||||
pub features: Option<Vec<String>>,
|
||||
pub target: Option<String>,
|
||||
pub cargo_args: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum ExecutableType {
|
||||
Binary(String),
|
||||
Lib(String),
|
||||
Example(String),
|
||||
}
|
||||
|
||||
impl CrateConfig {
|
||||
#[cfg(feature = "cli")]
|
||||
pub fn new(bin: Option<PathBuf>) -> Result<Self, CrateConfigError> {
|
||||
let dioxus_config = DioxusConfig::load(bin.clone())?.unwrap_or_default();
|
||||
|
||||
let crate_root = crate::crate_root()?;
|
||||
|
||||
let crate_dir = if let Some(package) = &dioxus_config.application.sub_package {
|
||||
crate_root.join(package)
|
||||
} else if let Some(bin) = bin {
|
||||
crate_root.join(bin)
|
||||
} else {
|
||||
crate_root
|
||||
};
|
||||
|
||||
let meta = crate::Metadata::get()?;
|
||||
let workspace_dir = meta.workspace_root;
|
||||
let target_dir = meta.target_directory;
|
||||
|
||||
let out_dir = crate_dir.join(&dioxus_config.application.out_dir);
|
||||
|
||||
let cargo_def = &crate_dir.join("Cargo.toml");
|
||||
|
||||
let asset_dir = crate_dir.join(&dioxus_config.application.asset_dir);
|
||||
|
||||
let manifest = cargo_toml::Manifest::from_path(cargo_def).unwrap();
|
||||
|
||||
let mut output_filename = String::from("dioxus_app");
|
||||
if let Some(package) = &manifest.package.as_ref() {
|
||||
output_filename = match &package.default_run {
|
||||
Some(default_run_target) => default_run_target.to_owned(),
|
||||
None => manifest
|
||||
.bin
|
||||
.iter()
|
||||
.find(|b| b.name == manifest.package.as_ref().map(|pkg| pkg.name.clone()))
|
||||
.or(manifest
|
||||
.bin
|
||||
.iter()
|
||||
.find(|b| b.path == Some("src/main.rs".to_owned())))
|
||||
.or(manifest.bin.first())
|
||||
.or(manifest.lib.as_ref())
|
||||
.and_then(|prod| prod.name.clone())
|
||||
.unwrap_or(String::from("dioxus_app")),
|
||||
};
|
||||
}
|
||||
|
||||
let executable = ExecutableType::Binary(output_filename);
|
||||
|
||||
let release = false;
|
||||
let hot_reload = false;
|
||||
let verbose = false;
|
||||
let custom_profile = None;
|
||||
let features = None;
|
||||
let target = None;
|
||||
let cargo_args = vec![];
|
||||
|
||||
Ok(Self {
|
||||
out_dir,
|
||||
crate_dir,
|
||||
workspace_dir,
|
||||
target_dir,
|
||||
asset_dir,
|
||||
#[cfg(feature = "cli")]
|
||||
manifest,
|
||||
executable,
|
||||
release,
|
||||
dioxus_config,
|
||||
hot_reload,
|
||||
cross_origin_policy: false,
|
||||
custom_profile,
|
||||
features,
|
||||
verbose,
|
||||
target,
|
||||
cargo_args,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn as_example(&mut self, example_name: String) -> &mut Self {
|
||||
self.executable = ExecutableType::Example(example_name);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_release(&mut self, release: bool) -> &mut Self {
|
||||
self.release = release;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_hot_reload(&mut self, hot_reload: bool) -> &mut Self {
|
||||
self.hot_reload = hot_reload;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_cross_origin_policy(&mut self, cross_origin_policy: bool) -> &mut Self {
|
||||
self.cross_origin_policy = cross_origin_policy;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_verbose(&mut self, verbose: bool) -> &mut Self {
|
||||
self.verbose = verbose;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_profile(&mut self, profile: String) -> &mut Self {
|
||||
self.custom_profile = Some(profile);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_features(&mut self, features: Vec<String>) -> &mut Self {
|
||||
self.features = Some(features);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_target(&mut self, target: String) -> &mut Self {
|
||||
self.target = Some(target);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_cargo_args(&mut self, cargo_args: Vec<String>) -> &mut Self {
|
||||
self.cargo_args = cargo_args;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
fn true_bool() -> bool {
|
||||
true
|
||||
}
|
58
packages/cli-config/src/lib.rs
Normal file
58
packages/cli-config/src/lib.rs
Normal file
|
@ -0,0 +1,58 @@
|
|||
#![doc = include_str!("../README.md")]
|
||||
#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/79236386")]
|
||||
#![doc(html_favicon_url = "https://avatars.githubusercontent.com/u/79236386")]
|
||||
|
||||
mod config;
|
||||
pub use config::*;
|
||||
mod bundle;
|
||||
pub use bundle::*;
|
||||
mod cargo;
|
||||
pub use cargo::*;
|
||||
|
||||
#[doc(hidden)]
|
||||
pub mod __private {
|
||||
use crate::CrateConfig;
|
||||
|
||||
pub const CONFIG_ENV: &str = "DIOXUS_CONFIG";
|
||||
|
||||
pub fn save_config(config: &CrateConfig) -> CrateConfigDropGuard {
|
||||
std::env::set_var(CONFIG_ENV, serde_json::to_string(config).unwrap());
|
||||
CrateConfigDropGuard
|
||||
}
|
||||
|
||||
/// A guard that removes the config from the environment when dropped.
|
||||
pub struct CrateConfigDropGuard;
|
||||
|
||||
impl Drop for CrateConfigDropGuard {
|
||||
fn drop(&mut self) {
|
||||
std::env::remove_var(CONFIG_ENV);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// An error that occurs when the dioxus CLI was not used to build the application.
|
||||
#[derive(Debug)]
|
||||
pub struct DioxusCLINotUsed;
|
||||
|
||||
impl std::fmt::Display for DioxusCLINotUsed {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str("dioxus CLI was not used to build the application")
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for DioxusCLINotUsed {}
|
||||
|
||||
/// The current crate's configuration.
|
||||
pub static CURRENT_CONFIG: once_cell::sync::Lazy<
|
||||
Result<crate::config::CrateConfig, DioxusCLINotUsed>,
|
||||
> = once_cell::sync::Lazy::new(|| {
|
||||
CURRENT_CONFIG_JSON
|
||||
.and_then(|config| serde_json::from_str(config).ok())
|
||||
.ok_or_else(|| {
|
||||
tracing::error!("A library is trying to access the crate's configuration, but the dioxus CLI was not used to build the application.");
|
||||
DioxusCLINotUsed
|
||||
})
|
||||
});
|
||||
|
||||
/// The current crate's configuration.
|
||||
pub const CURRENT_CONFIG_JSON: Option<&str> = std::option_env!("DIOXUS_CONFIG");
|
|
@ -14,6 +14,7 @@ clap = { version = "4.2", features = ["derive"] }
|
|||
thiserror = { workspace = true }
|
||||
wasm-bindgen-cli-support = "0.2"
|
||||
colored = "2.0.0"
|
||||
dioxus-cli-config = { workspace = true, features = ["cli"] }
|
||||
|
||||
# features
|
||||
log = "0.4.14"
|
||||
|
@ -72,10 +73,10 @@ cargo-generate = "0.18"
|
|||
toml_edit = "0.19.11"
|
||||
|
||||
# bundling
|
||||
tauri-bundler = { version = "=1.3.0", features = ["native-tls-vendored"] }
|
||||
tauri-utils = "=1.4.*"
|
||||
tauri-bundler = { version = "=1.4.*", features = ["native-tls-vendored"] }
|
||||
tauri-utils = "=1.5.*"
|
||||
|
||||
manganis-cli-support= { git = "https://github.com/DioxusLabs/collect-assets", features = ["webp", "html"] }
|
||||
manganis-cli-support = { workspace = true, features = ["webp", "html"] }
|
||||
|
||||
dioxus-autofmt = { workspace = true }
|
||||
dioxus-check = { workspace = true }
|
||||
|
|
|
@ -35,13 +35,13 @@ cargo install --path . --debug
|
|||
|
||||
## Get started
|
||||
|
||||
Use `dx create project-name` to initialize a new Dioxus project.
|
||||
Use `dx create` to initialize a new Dioxus project.
|
||||
It will be cloned from the [dioxus-template](https://github.com/DioxusLabs/dioxus-template) repository.
|
||||
|
||||
Alternatively, you can specify the template path:
|
||||
|
||||
```shell
|
||||
dx create hello --template gh:dioxuslabs/dioxus-template
|
||||
dx create --template gh:dioxuslabs/dioxus-template
|
||||
```
|
||||
|
||||
Run `dx --help` for a list of all the available commands.
|
||||
|
|
|
@ -5,14 +5,9 @@ use std::{env, path::PathBuf, process::Command};
|
|||
fn main() {
|
||||
set_rerun();
|
||||
set_commit_info();
|
||||
if option_env!("CFG_RELEASE").is_none() {
|
||||
println!("cargo:rustc-env=POKE_RA_DEVS=1");
|
||||
}
|
||||
}
|
||||
|
||||
fn set_rerun() {
|
||||
println!("cargo:rerun-if-env-changed=CFG_RELEASE");
|
||||
|
||||
let mut manifest_dir = PathBuf::from(
|
||||
env::var("CARGO_MANIFEST_DIR").expect("`CARGO_MANIFEST_DIR` is always set by cargo."),
|
||||
);
|
||||
|
|
57
packages/cli/src/assets.rs
Normal file
57
packages/cli/src/assets.rs
Normal file
|
@ -0,0 +1,57 @@
|
|||
use std::{fs::File, io::Write, path::PathBuf};
|
||||
|
||||
use crate::Result;
|
||||
use dioxus_cli_config::CrateConfig;
|
||||
use manganis_cli_support::{AssetManifest, AssetManifestExt};
|
||||
|
||||
pub fn asset_manifest(crate_config: &CrateConfig) -> AssetManifest {
|
||||
AssetManifest::load_from_path(
|
||||
crate_config.crate_dir.join("Cargo.toml"),
|
||||
crate_config.workspace_dir.join("Cargo.lock"),
|
||||
)
|
||||
}
|
||||
|
||||
/// Create a head file that contains all of the imports for assets that the user project uses
|
||||
pub fn create_assets_head(config: &CrateConfig, manifest: &AssetManifest) -> Result<()> {
|
||||
let mut file = File::create(config.out_dir.join("__assets_head.html"))?;
|
||||
file.write_all(manifest.head().as_bytes())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Process any assets collected from the binary
|
||||
pub(crate) fn process_assets(config: &CrateConfig, manifest: &AssetManifest) -> anyhow::Result<()> {
|
||||
let static_asset_output_dir = PathBuf::from(
|
||||
config
|
||||
.dioxus_config
|
||||
.web
|
||||
.app
|
||||
.base_path
|
||||
.clone()
|
||||
.unwrap_or_default(),
|
||||
);
|
||||
let static_asset_output_dir = config.out_dir.join(static_asset_output_dir);
|
||||
|
||||
manifest.copy_static_assets_to(static_asset_output_dir)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// A guard that sets up the environment for the web renderer to compile in. This guard sets the location that assets will be served from
|
||||
pub(crate) struct WebAssetConfigDropGuard;
|
||||
|
||||
impl WebAssetConfigDropGuard {
|
||||
pub fn new() -> Self {
|
||||
// Set up the collect asset config
|
||||
manganis_cli_support::Config::default()
|
||||
.with_assets_serve_location("/")
|
||||
.save();
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for WebAssetConfigDropGuard {
|
||||
fn drop(&mut self) {
|
||||
// Reset the config
|
||||
manganis_cli_support::Config::default().save();
|
||||
}
|
||||
}
|
|
@ -1,16 +1,18 @@
|
|||
use crate::{
|
||||
config::{CrateConfig, ExecutableType},
|
||||
assets::{asset_manifest, create_assets_head, process_assets, WebAssetConfigDropGuard},
|
||||
error::{Error, Result},
|
||||
tools::Tool,
|
||||
};
|
||||
use cargo_metadata::{diagnostic::Diagnostic, Message};
|
||||
use dioxus_cli_config::crate_root;
|
||||
use dioxus_cli_config::CrateConfig;
|
||||
use dioxus_cli_config::ExecutableType;
|
||||
use indicatif::{ProgressBar, ProgressStyle};
|
||||
use lazy_static::lazy_static;
|
||||
use manganis_cli_support::AssetManifestExt;
|
||||
use serde::Serialize;
|
||||
use manganis_cli_support::{AssetManifest, ManganisSupportGuard};
|
||||
use std::{
|
||||
fs::{copy, create_dir_all, File},
|
||||
io::{Read, Write},
|
||||
io::Read,
|
||||
panic,
|
||||
path::PathBuf,
|
||||
time::Duration,
|
||||
|
@ -21,10 +23,11 @@ lazy_static! {
|
|||
static ref PROGRESS_BARS: indicatif::MultiProgress = indicatif::MultiProgress::new();
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug, Clone)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct BuildResult {
|
||||
pub warnings: Vec<Diagnostic>,
|
||||
pub elapsed_time: u128,
|
||||
pub assets: Option<AssetManifest>,
|
||||
}
|
||||
|
||||
pub fn build(config: &CrateConfig, _: bool, skip_assets: bool) -> Result<BuildResult> {
|
||||
|
@ -45,12 +48,14 @@ pub fn build(config: &CrateConfig, _: bool, skip_assets: bool) -> Result<BuildRe
|
|||
..
|
||||
} = config;
|
||||
|
||||
let _gaurd = WebAssetConfigDropGuard::new();
|
||||
let _guard = WebAssetConfigDropGuard::new();
|
||||
let _manganis_support = ManganisSupportGuard::default();
|
||||
|
||||
// start to build the assets
|
||||
let ignore_files = build_assets(config)?;
|
||||
|
||||
let t_start = std::time::Instant::now();
|
||||
let _guard = dioxus_cli_config::__private::save_config(config);
|
||||
|
||||
// [1] Build the .wasm module
|
||||
log::info!("🚅 Running build command...");
|
||||
|
@ -152,7 +157,7 @@ pub fn build(config: &CrateConfig, _: bool, skip_assets: bool) -> Result<BuildRe
|
|||
}
|
||||
|
||||
// check binaryen:wasm-opt tool
|
||||
let dioxus_tools = dioxus_config.application.tools.clone().unwrap_or_default();
|
||||
let dioxus_tools = dioxus_config.application.tools.clone();
|
||||
if dioxus_tools.contains_key("binaryen") {
|
||||
let info = dioxus_tools.get("binaryen").unwrap();
|
||||
let binaryen = crate::tools::Tool::Binaryen;
|
||||
|
@ -258,13 +263,18 @@ pub fn build(config: &CrateConfig, _: bool, skip_assets: bool) -> Result<BuildRe
|
|||
}
|
||||
}
|
||||
|
||||
if !skip_assets {
|
||||
process_assets(config)?;
|
||||
}
|
||||
let assets = if !skip_assets {
|
||||
let assets = asset_manifest(config);
|
||||
process_assets(config, &assets)?;
|
||||
Some(assets)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Ok(BuildResult {
|
||||
warnings: warning_messages,
|
||||
elapsed_time: t_start.elapsed().as_millis(),
|
||||
assets,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -277,6 +287,8 @@ pub fn build_desktop(
|
|||
|
||||
let t_start = std::time::Instant::now();
|
||||
let ignore_files = build_assets(config)?;
|
||||
let _guard = dioxus_cli_config::__private::save_config(config);
|
||||
let _manganis_support = ManganisSupportGuard::default();
|
||||
|
||||
let mut cmd = subprocess::Exec::cmd("cargo")
|
||||
.env("CARGO_TARGET_DIR", &config.target_dir)
|
||||
|
@ -312,9 +324,9 @@ pub fn build_desktop(
|
|||
cmd = cmd.args(&config.cargo_args);
|
||||
|
||||
let cmd = match &config.executable {
|
||||
crate::ExecutableType::Binary(name) => cmd.arg("--bin").arg(name),
|
||||
crate::ExecutableType::Lib(name) => cmd.arg("--lib").arg(name),
|
||||
crate::ExecutableType::Example(name) => cmd.arg("--example").arg(name),
|
||||
ExecutableType::Binary(name) => cmd.arg("--bin").arg(name),
|
||||
ExecutableType::Lib(name) => cmd.arg("--lib").arg(name),
|
||||
ExecutableType::Example(name) => cmd.arg("--example").arg(name),
|
||||
};
|
||||
|
||||
let warning_messages = prettier_build(cmd)?;
|
||||
|
@ -326,7 +338,7 @@ pub fn build_desktop(
|
|||
|
||||
let file_name: String;
|
||||
let mut res_path = match &config.executable {
|
||||
crate::ExecutableType::Binary(name) | crate::ExecutableType::Lib(name) => {
|
||||
ExecutableType::Binary(name) | ExecutableType::Lib(name) => {
|
||||
file_name = name.clone();
|
||||
config
|
||||
.target_dir
|
||||
|
@ -334,7 +346,7 @@ pub fn build_desktop(
|
|||
.join(release_type)
|
||||
.join(name)
|
||||
}
|
||||
crate::ExecutableType::Example(name) => {
|
||||
ExecutableType::Example(name) => {
|
||||
file_name = name.clone();
|
||||
config
|
||||
.target_dir
|
||||
|
@ -390,22 +402,20 @@ pub fn build_desktop(
|
|||
}
|
||||
}
|
||||
|
||||
if !skip_assets {
|
||||
let assets = if !skip_assets {
|
||||
let assets = asset_manifest(config);
|
||||
// Collect assets
|
||||
process_assets(config)?;
|
||||
process_assets(config, &assets)?;
|
||||
// Create the __assets_head.html file for bundling
|
||||
create_assets_head(config)?;
|
||||
}
|
||||
create_assets_head(config, &assets)?;
|
||||
Some(assets)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
log::info!(
|
||||
"🚩 Build completed: [./{}]",
|
||||
config
|
||||
.dioxus_config
|
||||
.application
|
||||
.out_dir
|
||||
.clone()
|
||||
.unwrap_or_else(|| PathBuf::from("dist"))
|
||||
.display()
|
||||
config.dioxus_config.application.out_dir.clone().display()
|
||||
);
|
||||
|
||||
println!("build desktop done");
|
||||
|
@ -413,16 +423,10 @@ pub fn build_desktop(
|
|||
Ok(BuildResult {
|
||||
warnings: warning_messages,
|
||||
elapsed_time: t_start.elapsed().as_millis(),
|
||||
assets,
|
||||
})
|
||||
}
|
||||
|
||||
fn create_assets_head(config: &CrateConfig) -> Result<()> {
|
||||
let manifest = config.asset_manifest();
|
||||
let mut file = File::create(config.out_dir.join("__assets_head.html"))?;
|
||||
file.write_all(manifest.head().as_bytes())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn prettier_build(cmd: subprocess::Exec) -> anyhow::Result<Vec<Diagnostic>> {
|
||||
let mut warning_messages: Vec<Diagnostic> = vec![];
|
||||
|
||||
|
@ -479,10 +483,10 @@ fn prettier_build(cmd: subprocess::Exec) -> anyhow::Result<Vec<Diagnostic>> {
|
|||
Ok(warning_messages)
|
||||
}
|
||||
|
||||
pub fn gen_page(config: &CrateConfig, serve: bool, skip_assets: bool) -> String {
|
||||
pub fn gen_page(config: &CrateConfig, manifest: Option<&AssetManifest>, serve: bool) -> String {
|
||||
let _gaurd = WebAssetConfigDropGuard::new();
|
||||
|
||||
let crate_root = crate::cargo::crate_root().unwrap();
|
||||
let crate_root = crate_root().unwrap();
|
||||
let custom_html_file = crate_root.join("index.html");
|
||||
let mut html = if custom_html_file.is_file() {
|
||||
let mut buf = String::new();
|
||||
|
@ -502,8 +506,8 @@ pub fn gen_page(config: &CrateConfig, serve: bool, skip_assets: bool) -> String
|
|||
let mut script_list = resources.script.unwrap_or_default();
|
||||
|
||||
if serve {
|
||||
let mut dev_style = resources.dev.style.clone().unwrap_or_default();
|
||||
let mut dev_script = resources.dev.script.unwrap_or_default();
|
||||
let mut dev_style = resources.dev.style.clone();
|
||||
let mut dev_script = resources.dev.script.clone();
|
||||
style_list.append(&mut dev_style);
|
||||
script_list.append(&mut dev_script);
|
||||
}
|
||||
|
@ -520,13 +524,11 @@ pub fn gen_page(config: &CrateConfig, serve: bool, skip_assets: bool) -> String
|
|||
.application
|
||||
.tools
|
||||
.clone()
|
||||
.unwrap_or_default()
|
||||
.contains_key("tailwindcss")
|
||||
{
|
||||
style_str.push_str("<link rel=\"stylesheet\" href=\"/{base_path}/tailwind.css\">\n");
|
||||
}
|
||||
if !skip_assets {
|
||||
let manifest = config.asset_manifest();
|
||||
if let Some(manifest) = manifest {
|
||||
style_str.push_str(&manifest.head());
|
||||
}
|
||||
|
||||
|
@ -577,13 +579,7 @@ pub fn gen_page(config: &CrateConfig, serve: bool, skip_assets: bool) -> String
|
|||
);
|
||||
}
|
||||
|
||||
let title = config
|
||||
.dioxus_config
|
||||
.web
|
||||
.app
|
||||
.title
|
||||
.clone()
|
||||
.unwrap_or_else(|| "dioxus | ⛺".into());
|
||||
let title = config.dioxus_config.web.app.title.clone();
|
||||
|
||||
replace_or_insert_before("{app_title}", &title, "</title", &mut html);
|
||||
|
||||
|
@ -610,7 +606,7 @@ fn build_assets(config: &CrateConfig) -> Result<Vec<PathBuf>> {
|
|||
let mut result = vec![];
|
||||
|
||||
let dioxus_config = &config.dioxus_config;
|
||||
let dioxus_tools = dioxus_config.application.tools.clone().unwrap_or_default();
|
||||
let dioxus_tools = dioxus_config.application.tools.clone();
|
||||
|
||||
// check sass tool state
|
||||
let sass = Tool::Sass;
|
||||
|
@ -748,42 +744,3 @@ fn build_assets(config: &CrateConfig) -> Result<Vec<PathBuf>> {
|
|||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
/// Process any assets collected from the binary
|
||||
fn process_assets(config: &CrateConfig) -> anyhow::Result<()> {
|
||||
let manifest = config.asset_manifest();
|
||||
|
||||
let static_asset_output_dir = PathBuf::from(
|
||||
config
|
||||
.dioxus_config
|
||||
.web
|
||||
.app
|
||||
.base_path
|
||||
.clone()
|
||||
.unwrap_or_default(),
|
||||
);
|
||||
let static_asset_output_dir = config.out_dir.join(static_asset_output_dir);
|
||||
|
||||
manifest.copy_static_assets_to(static_asset_output_dir)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) struct WebAssetConfigDropGuard;
|
||||
|
||||
impl WebAssetConfigDropGuard {
|
||||
pub fn new() -> Self {
|
||||
// Set up the collect asset config
|
||||
manganis_cli_support::Config::default()
|
||||
.with_assets_serve_location("/")
|
||||
.save();
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for WebAssetConfigDropGuard {
|
||||
fn drop(&mut self) {
|
||||
// Reset the config
|
||||
manganis_cli_support::Config::default().save();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,23 +22,33 @@ pub struct Autoformat {
|
|||
/// Input file
|
||||
#[clap(short, long)]
|
||||
pub file: Option<String>,
|
||||
|
||||
/// Split attributes in lines or not
|
||||
#[clap(short, long, default_value = "false")]
|
||||
pub split_line_attributes: bool,
|
||||
}
|
||||
|
||||
impl Autoformat {
|
||||
// Todo: autoformat the entire crate
|
||||
pub async fn autoformat(self) -> Result<()> {
|
||||
let Autoformat { check, raw, file } = self;
|
||||
let Autoformat {
|
||||
check,
|
||||
raw,
|
||||
file,
|
||||
split_line_attributes,
|
||||
..
|
||||
} = self;
|
||||
|
||||
// Default to formatting the project
|
||||
if raw.is_none() && file.is_none() {
|
||||
if let Err(e) = autoformat_project(check).await {
|
||||
if let Err(e) = autoformat_project(check, split_line_attributes).await {
|
||||
eprintln!("error formatting project: {}", e);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(raw) = raw {
|
||||
let indent = indentation_for(".")?;
|
||||
let indent = indentation_for(".", self.split_line_attributes)?;
|
||||
if let Some(inner) = dioxus_autofmt::fmt_block(&raw, 0, indent) {
|
||||
println!("{}", inner);
|
||||
} else {
|
||||
|
@ -50,15 +60,15 @@ impl Autoformat {
|
|||
|
||||
// Format single file
|
||||
if let Some(file) = file {
|
||||
refactor_file(file)?;
|
||||
refactor_file(file, split_line_attributes)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn refactor_file(file: String) -> Result<(), Error> {
|
||||
let indent = indentation_for(".")?;
|
||||
fn refactor_file(file: String, split_line_attributes: bool) -> Result<(), Error> {
|
||||
let indent = indentation_for(".", split_line_attributes)?;
|
||||
let file_content = if file == "-" {
|
||||
let mut contents = String::new();
|
||||
std::io::stdin().read_to_string(&mut contents)?;
|
||||
|
@ -138,8 +148,8 @@ async fn format_file(
|
|||
/// Runs using Tokio for multithreading, so it should be really really fast
|
||||
///
|
||||
/// Doesn't do mod-descending, so it will still try to format unreachable files. TODO.
|
||||
async fn autoformat_project(check: bool) -> Result<()> {
|
||||
let crate_config = crate::CrateConfig::new(None)?;
|
||||
async fn autoformat_project(check: bool, split_line_attributes: bool) -> Result<()> {
|
||||
let crate_config = dioxus_cli_config::CrateConfig::new(None)?;
|
||||
|
||||
let files_to_format = get_project_files(&crate_config);
|
||||
|
||||
|
@ -147,7 +157,7 @@ async fn autoformat_project(check: bool) -> Result<()> {
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
let indent = indentation_for(&files_to_format[0])?;
|
||||
let indent = indentation_for(&files_to_format[0], split_line_attributes)?;
|
||||
|
||||
let counts = files_to_format
|
||||
.into_iter()
|
||||
|
@ -181,7 +191,10 @@ async fn autoformat_project(check: bool) -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn indentation_for(file_or_dir: impl AsRef<Path>) -> Result<IndentOptions> {
|
||||
fn indentation_for(
|
||||
file_or_dir: impl AsRef<Path>,
|
||||
split_line_attributes: bool,
|
||||
) -> Result<IndentOptions> {
|
||||
let out = std::process::Command::new("cargo")
|
||||
.args(["fmt", "--", "--print-config", "current"])
|
||||
.arg(file_or_dir.as_ref())
|
||||
|
@ -221,6 +234,7 @@ fn indentation_for(file_or_dir: impl AsRef<Path>) -> Result<IndentOptions> {
|
|||
IndentType::Spaces
|
||||
},
|
||||
tab_spaces,
|
||||
split_line_attributes,
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -253,10 +267,10 @@ async fn test_auto_fmt() {
|
|||
let test_rsx = r#"
|
||||
//
|
||||
|
||||
rsx! {
|
||||
|
||||
|
||||
div {}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
|
@ -269,6 +283,7 @@ async fn test_auto_fmt() {
|
|||
check: false,
|
||||
raw: Some(test_rsx),
|
||||
file: None,
|
||||
split_line_attributes: false,
|
||||
};
|
||||
|
||||
fmt.autoformat().await.unwrap();
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
use crate::assets::WebAssetConfigDropGuard;
|
||||
#[cfg(feature = "plugin")]
|
||||
use crate::plugin::PluginManager;
|
||||
use crate::server::fullstack::FullstackServerEnvGuard;
|
||||
use crate::server::fullstack::FullstackWebEnvGuard;
|
||||
use crate::{cfg::Platform, WebAssetConfigDropGuard};
|
||||
use dioxus_cli_config::Platform;
|
||||
|
||||
use super::*;
|
||||
|
||||
|
@ -16,7 +17,7 @@ pub struct Build {
|
|||
|
||||
impl Build {
|
||||
pub fn build(self, bin: Option<PathBuf>, target_dir: Option<&std::path::Path>) -> Result<()> {
|
||||
let mut crate_config = crate::CrateConfig::new(bin)?;
|
||||
let mut crate_config = dioxus_cli_config::CrateConfig::new(bin)?;
|
||||
if let Some(target_dir) = target_dir {
|
||||
crate_config.target_dir = target_dir.to_path_buf();
|
||||
}
|
||||
|
@ -51,12 +52,10 @@ impl Build {
|
|||
// #[cfg(feature = "plugin")]
|
||||
// let _ = PluginManager::on_build_start(&crate_config, &platform);
|
||||
|
||||
match platform {
|
||||
Platform::Web => {
|
||||
crate::builder::build(&crate_config, false, self.build.skip_assets)?;
|
||||
}
|
||||
let build_result = match platform {
|
||||
Platform::Web => crate::builder::build(&crate_config, false, self.build.skip_assets)?,
|
||||
Platform::Desktop => {
|
||||
crate::builder::build_desktop(&crate_config, false, self.build.skip_assets)?;
|
||||
crate::builder::build_desktop(&crate_config, false, self.build.skip_assets)?
|
||||
}
|
||||
Platform::Fullstack => {
|
||||
// Fullstack mode must be built with web configs on the desktop (server) binary as well as the web binary
|
||||
|
@ -86,24 +85,17 @@ impl Build {
|
|||
};
|
||||
let _gaurd =
|
||||
FullstackServerEnvGuard::new(self.build.force_debug, self.build.release);
|
||||
crate::builder::build_desktop(&desktop_config, false, self.build.skip_assets)?;
|
||||
crate::builder::build_desktop(&desktop_config, false, self.build.skip_assets)?
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let temp = gen_page(&crate_config, false, self.build.skip_assets);
|
||||
let temp = gen_page(&crate_config, build_result.assets.as_ref(), false);
|
||||
|
||||
let mut file = std::fs::File::create(
|
||||
crate_config
|
||||
.crate_dir
|
||||
.join(
|
||||
crate_config
|
||||
.dioxus_config
|
||||
.application
|
||||
.out_dir
|
||||
.clone()
|
||||
.unwrap_or_else(|| PathBuf::from("dist")),
|
||||
)
|
||||
.join(crate_config.dioxus_config.application.out_dir.clone())
|
||||
.join("index.html"),
|
||||
)?;
|
||||
file.write_all(temp.as_bytes())?;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use core::panic;
|
||||
use dioxus_cli_config::ExecutableType;
|
||||
use std::{fs::create_dir_all, str::FromStr};
|
||||
|
||||
use tauri_bundler::{BundleSettings, PackageSettings, SettingsBuilder};
|
||||
|
@ -62,7 +63,7 @@ impl From<PackageType> for tauri_bundler::PackageType {
|
|||
|
||||
impl Bundle {
|
||||
pub fn bundle(self, bin: Option<PathBuf>) -> Result<()> {
|
||||
let mut crate_config = crate::CrateConfig::new(bin)?;
|
||||
let mut crate_config = dioxus_cli_config::CrateConfig::new(bin)?;
|
||||
|
||||
// change the release state.
|
||||
crate_config.with_release(self.build.release);
|
||||
|
@ -89,9 +90,9 @@ impl Bundle {
|
|||
let package = crate_config.manifest.package.unwrap();
|
||||
|
||||
let mut name: PathBuf = match &crate_config.executable {
|
||||
crate::ExecutableType::Binary(name)
|
||||
| crate::ExecutableType::Lib(name)
|
||||
| crate::ExecutableType::Example(name) => name,
|
||||
ExecutableType::Binary(name)
|
||||
| ExecutableType::Lib(name)
|
||||
| ExecutableType::Example(name) => name,
|
||||
}
|
||||
.into();
|
||||
if cfg!(windows) {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use clap::ValueEnum;
|
||||
use serde::Serialize;
|
||||
use dioxus_cli_config::Platform;
|
||||
|
||||
use super::*;
|
||||
|
||||
|
@ -154,19 +153,6 @@ pub struct ConfigOptsServe {
|
|||
pub cargo_args: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Serialize, Deserialize, Debug)]
|
||||
pub enum Platform {
|
||||
#[clap(name = "web")]
|
||||
#[serde(rename = "web")]
|
||||
Web,
|
||||
#[clap(name = "desktop")]
|
||||
#[serde(rename = "desktop")]
|
||||
Desktop,
|
||||
#[clap(name = "fullstack")]
|
||||
#[serde(rename = "fullstack")]
|
||||
Fullstack,
|
||||
}
|
||||
|
||||
/// Config options for the bundling system.
|
||||
#[derive(Clone, Debug, Default, Deserialize, Parser)]
|
||||
pub struct ConfigOptsBundle {
|
||||
|
|
|
@ -47,7 +47,7 @@ async fn check_file_and_report(path: PathBuf) -> Result<()> {
|
|||
///
|
||||
/// Doesn't do mod-descending, so it will still try to check unreachable files. TODO.
|
||||
async fn check_project_and_report() -> Result<()> {
|
||||
let crate_config = crate::CrateConfig::new(None)?;
|
||||
let crate_config = dioxus_cli_config::CrateConfig::new(None)?;
|
||||
|
||||
let mut files_to_check = vec![];
|
||||
collect_rs_files(&crate_config.crate_dir, &mut files_to_check);
|
||||
|
|
|
@ -7,7 +7,7 @@ pub struct Clean {}
|
|||
|
||||
impl Clean {
|
||||
pub fn clean(self, bin: Option<PathBuf>) -> Result<()> {
|
||||
let crate_config = crate::CrateConfig::new(bin)?;
|
||||
let crate_config = dioxus_cli_config::CrateConfig::new(bin)?;
|
||||
|
||||
let output = Command::new("cargo")
|
||||
.arg("clean")
|
||||
|
@ -19,11 +19,7 @@ impl Clean {
|
|||
return custom_error!("Cargo clean failed.");
|
||||
}
|
||||
|
||||
let out_dir = crate_config
|
||||
.dioxus_config
|
||||
.application
|
||||
.out_dir
|
||||
.unwrap_or_else(|| PathBuf::from("dist"));
|
||||
let out_dir = crate_config.dioxus_config.application.out_dir;
|
||||
if crate_config.crate_dir.join(&out_dir).is_dir() {
|
||||
remove_dir_all(crate_config.crate_dir.join(&out_dir))?;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use dioxus_cli_config::crate_root;
|
||||
|
||||
use super::*;
|
||||
|
||||
/// Dioxus config file controls
|
||||
|
@ -26,7 +28,7 @@ pub enum Config {
|
|||
|
||||
impl Config {
|
||||
pub fn config(self) -> Result<()> {
|
||||
let crate_root = crate::cargo::crate_root()?;
|
||||
let crate_root = crate_root()?;
|
||||
match self {
|
||||
Config::Init {
|
||||
name,
|
||||
|
@ -48,7 +50,10 @@ impl Config {
|
|||
log::info!("🚩 Init config file completed.");
|
||||
}
|
||||
Config::FormatPrint {} => {
|
||||
println!("{:#?}", crate::CrateConfig::new(None)?.dioxus_config);
|
||||
println!(
|
||||
"{:#?}",
|
||||
dioxus_cli_config::CrateConfig::new(None)?.dioxus_config
|
||||
);
|
||||
}
|
||||
Config::CustomHtml {} => {
|
||||
let html_path = crate_root.join("index.html");
|
||||
|
|
|
@ -15,9 +15,10 @@ use crate::{
|
|||
cfg::{ConfigOptsBuild, ConfigOptsServe},
|
||||
custom_error,
|
||||
error::Result,
|
||||
gen_page, server, CrateConfig, Error,
|
||||
gen_page, server, Error,
|
||||
};
|
||||
use clap::{Parser, Subcommand};
|
||||
use dioxus_cli_config::CrateConfig;
|
||||
use html_parser::Dom;
|
||||
use serde::Deserialize;
|
||||
use std::{
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
use dioxus_cli_config::Platform;
|
||||
use manganis_cli_support::AssetManifest;
|
||||
|
||||
use super::*;
|
||||
use std::{fs::create_dir_all, io::Write, path::PathBuf};
|
||||
|
||||
|
@ -11,7 +14,7 @@ pub struct Serve {
|
|||
|
||||
impl Serve {
|
||||
pub async fn serve(self, bin: Option<PathBuf>) -> Result<()> {
|
||||
let mut crate_config = crate::CrateConfig::new(bin)?;
|
||||
let mut crate_config = dioxus_cli_config::CrateConfig::new(bin)?;
|
||||
let serve_cfg = self.serve.clone();
|
||||
|
||||
// change the relase state.
|
||||
|
@ -32,9 +35,6 @@ impl Serve {
|
|||
crate_config.set_features(self.serve.features.unwrap());
|
||||
}
|
||||
|
||||
// Subdirectories don't work with the server
|
||||
crate_config.dioxus_config.web.app.base_path = None;
|
||||
|
||||
if let Some(target) = self.serve.target {
|
||||
crate_config.set_target(target);
|
||||
}
|
||||
|
@ -47,10 +47,7 @@ impl Serve {
|
|||
.unwrap_or(crate_config.dioxus_config.application.default_platform);
|
||||
|
||||
match platform {
|
||||
cfg::Platform::Web => {
|
||||
// generate dev-index page
|
||||
Serve::regen_dev_page(&crate_config, self.serve.skip_assets)?;
|
||||
|
||||
Platform::Web => {
|
||||
// start the develop server
|
||||
server::web::startup(
|
||||
self.serve.port,
|
||||
|
@ -60,27 +57,25 @@ impl Serve {
|
|||
)
|
||||
.await?;
|
||||
}
|
||||
cfg::Platform::Desktop => {
|
||||
Platform::Desktop => {
|
||||
server::desktop::startup(crate_config.clone(), &serve_cfg).await?;
|
||||
}
|
||||
cfg::Platform::Fullstack => {
|
||||
Platform::Fullstack => {
|
||||
server::fullstack::startup(crate_config.clone(), &serve_cfg).await?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn regen_dev_page(crate_config: &CrateConfig, skip_assets: bool) -> Result<()> {
|
||||
let serve_html = gen_page(crate_config, true, skip_assets);
|
||||
pub fn regen_dev_page(
|
||||
crate_config: &CrateConfig,
|
||||
manifest: Option<&AssetManifest>,
|
||||
) -> anyhow::Result<()> {
|
||||
let serve_html = gen_page(crate_config, manifest, true);
|
||||
|
||||
let dist_path = crate_config.crate_dir.join(
|
||||
crate_config
|
||||
.dioxus_config
|
||||
.application
|
||||
.out_dir
|
||||
.clone()
|
||||
.unwrap_or_else(|| PathBuf::from("dist")),
|
||||
);
|
||||
let dist_path = crate_config
|
||||
.crate_dir
|
||||
.join(crate_config.dioxus_config.application.out_dir.clone());
|
||||
if !dist_path.is_dir() {
|
||||
create_dir_all(&dist_path)?;
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ impl fmt::Display for VersionInfo {
|
|||
|
||||
/// Returns information about cargo's version.
|
||||
pub const fn version() -> VersionInfo {
|
||||
let version = match option_env!("CFG_RELEASE") {
|
||||
let version = match option_env!("CARGO_PKG_VERSION") {
|
||||
Some(x) => x,
|
||||
None => "0.0.0",
|
||||
};
|
||||
|
|
|
@ -1,607 +0,0 @@
|
|||
use crate::{cfg::Platform, error::Result};
|
||||
use manganis_cli_support::AssetManifest;
|
||||
use manganis_cli_support::AssetManifestExt;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct DioxusConfig {
|
||||
pub application: ApplicationConfig,
|
||||
|
||||
pub web: WebConfig,
|
||||
|
||||
#[serde(default)]
|
||||
pub bundle: BundleConfig,
|
||||
|
||||
#[serde(default = "default_plugin")]
|
||||
pub plugin: toml::Value,
|
||||
}
|
||||
|
||||
fn default_plugin() -> toml::Value {
|
||||
toml::Value::Boolean(true)
|
||||
}
|
||||
|
||||
impl DioxusConfig {
|
||||
pub fn load(bin: Option<PathBuf>) -> crate::error::Result<Option<DioxusConfig>> {
|
||||
let crate_dir = crate::cargo::crate_root();
|
||||
|
||||
let crate_dir = match crate_dir {
|
||||
Ok(dir) => {
|
||||
if let Some(bin) = bin {
|
||||
dir.join(bin)
|
||||
} else {
|
||||
dir
|
||||
}
|
||||
}
|
||||
Err(_) => return Ok(None),
|
||||
};
|
||||
let crate_dir = crate_dir.as_path();
|
||||
|
||||
let Some(dioxus_conf_file) = acquire_dioxus_toml(crate_dir) else {
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
let dioxus_conf_file = dioxus_conf_file.as_path();
|
||||
let cfg = toml::from_str::<DioxusConfig>(&std::fs::read_to_string(dioxus_conf_file)?)
|
||||
.map_err(|err| {
|
||||
let error_location = dioxus_conf_file
|
||||
.strip_prefix(crate_dir)
|
||||
.unwrap_or(dioxus_conf_file)
|
||||
.display();
|
||||
crate::Error::Unique(format!("{error_location} {err}"))
|
||||
})
|
||||
.map(Some);
|
||||
match cfg {
|
||||
Ok(Some(mut cfg)) => {
|
||||
let name = cfg.application.name.clone();
|
||||
if cfg.bundle.identifier.is_none() {
|
||||
cfg.bundle.identifier = Some(format!("io.github.{name}"));
|
||||
}
|
||||
if cfg.bundle.publisher.is_none() {
|
||||
cfg.bundle.publisher = Some(name);
|
||||
}
|
||||
Ok(Some(cfg))
|
||||
}
|
||||
cfg => cfg,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn acquire_dioxus_toml(dir: &Path) -> Option<PathBuf> {
|
||||
// prefer uppercase
|
||||
let uppercase_conf = dir.join("Dioxus.toml");
|
||||
if uppercase_conf.is_file() {
|
||||
return Some(uppercase_conf);
|
||||
}
|
||||
|
||||
// lowercase is fine too
|
||||
let lowercase_conf = dir.join("dioxus.toml");
|
||||
if lowercase_conf.is_file() {
|
||||
return Some(lowercase_conf);
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
impl Default for DioxusConfig {
|
||||
fn default() -> Self {
|
||||
let name = "name";
|
||||
Self {
|
||||
application: ApplicationConfig {
|
||||
name: name.into(),
|
||||
default_platform: Platform::Web,
|
||||
out_dir: Some(PathBuf::from("dist")),
|
||||
asset_dir: Some(PathBuf::from("public")),
|
||||
|
||||
tools: None,
|
||||
|
||||
sub_package: None,
|
||||
},
|
||||
web: WebConfig {
|
||||
app: WebAppConfig {
|
||||
title: Some("dioxus | ⛺".into()),
|
||||
base_path: None,
|
||||
},
|
||||
proxy: Some(vec![]),
|
||||
watcher: WebWatcherConfig {
|
||||
watch_path: Some(vec![PathBuf::from("src"), PathBuf::from("examples")]),
|
||||
reload_html: Some(false),
|
||||
index_on_404: Some(true),
|
||||
},
|
||||
resource: WebResourceConfig {
|
||||
dev: WebDevResourceConfig {
|
||||
style: Some(vec![]),
|
||||
script: Some(vec![]),
|
||||
},
|
||||
style: Some(vec![]),
|
||||
script: Some(vec![]),
|
||||
},
|
||||
https: WebHttpsConfig {
|
||||
enabled: None,
|
||||
mkcert: None,
|
||||
key_path: None,
|
||||
cert_path: None,
|
||||
},
|
||||
},
|
||||
bundle: BundleConfig {
|
||||
identifier: Some(format!("io.github.{name}")),
|
||||
publisher: Some(name.into()),
|
||||
..Default::default()
|
||||
},
|
||||
plugin: toml::Value::Table(toml::map::Map::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ApplicationConfig {
|
||||
pub name: String,
|
||||
pub default_platform: Platform,
|
||||
pub out_dir: Option<PathBuf>,
|
||||
pub asset_dir: Option<PathBuf>,
|
||||
|
||||
pub tools: Option<HashMap<String, toml::Value>>,
|
||||
|
||||
pub sub_package: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct WebConfig {
|
||||
pub app: WebAppConfig,
|
||||
pub proxy: Option<Vec<WebProxyConfig>>,
|
||||
pub watcher: WebWatcherConfig,
|
||||
pub resource: WebResourceConfig,
|
||||
#[serde(default)]
|
||||
pub https: WebHttpsConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct WebAppConfig {
|
||||
pub title: Option<String>,
|
||||
pub base_path: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct WebProxyConfig {
|
||||
pub backend: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct WebWatcherConfig {
|
||||
pub watch_path: Option<Vec<PathBuf>>,
|
||||
pub reload_html: Option<bool>,
|
||||
pub index_on_404: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct WebResourceConfig {
|
||||
pub dev: WebDevResourceConfig,
|
||||
pub style: Option<Vec<PathBuf>>,
|
||||
pub script: Option<Vec<PathBuf>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct WebDevResourceConfig {
|
||||
pub style: Option<Vec<PathBuf>>,
|
||||
pub script: Option<Vec<PathBuf>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
|
||||
pub struct WebHttpsConfig {
|
||||
pub enabled: Option<bool>,
|
||||
pub mkcert: Option<bool>,
|
||||
pub key_path: Option<String>,
|
||||
pub cert_path: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct CrateConfig {
|
||||
pub out_dir: PathBuf,
|
||||
pub crate_dir: PathBuf,
|
||||
pub workspace_dir: PathBuf,
|
||||
pub target_dir: PathBuf,
|
||||
pub asset_dir: PathBuf,
|
||||
pub manifest: cargo_toml::Manifest<cargo_toml::Value>,
|
||||
pub executable: ExecutableType,
|
||||
pub dioxus_config: DioxusConfig,
|
||||
pub release: bool,
|
||||
pub hot_reload: bool,
|
||||
pub cross_origin_policy: bool,
|
||||
pub verbose: bool,
|
||||
pub custom_profile: Option<String>,
|
||||
pub features: Option<Vec<String>>,
|
||||
pub target: Option<String>,
|
||||
pub cargo_args: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ExecutableType {
|
||||
Binary(String),
|
||||
Lib(String),
|
||||
Example(String),
|
||||
}
|
||||
|
||||
impl CrateConfig {
|
||||
pub fn new(bin: Option<PathBuf>) -> Result<Self> {
|
||||
let dioxus_config = DioxusConfig::load(bin.clone())?.unwrap_or_default();
|
||||
|
||||
let crate_root = crate::cargo::crate_root()?;
|
||||
|
||||
let crate_dir = if let Some(package) = &dioxus_config.application.sub_package {
|
||||
crate_root.join(package)
|
||||
} else if let Some(bin) = bin {
|
||||
crate_root.join(bin)
|
||||
} else {
|
||||
crate_root
|
||||
};
|
||||
|
||||
let meta = crate::cargo::Metadata::get()?;
|
||||
let workspace_dir = meta.workspace_root;
|
||||
let target_dir = meta.target_directory;
|
||||
|
||||
let out_dir = match dioxus_config.application.out_dir {
|
||||
Some(ref v) => crate_dir.join(v),
|
||||
None => crate_dir.join("dist"),
|
||||
};
|
||||
|
||||
let cargo_def = &crate_dir.join("Cargo.toml");
|
||||
|
||||
let asset_dir = match dioxus_config.application.asset_dir {
|
||||
Some(ref v) => crate_dir.join(v),
|
||||
None => crate_dir.join("public"),
|
||||
};
|
||||
|
||||
let manifest = cargo_toml::Manifest::from_path(cargo_def).unwrap();
|
||||
|
||||
let mut output_filename = String::from("dioxus_app");
|
||||
if let Some(package) = &manifest.package.as_ref() {
|
||||
output_filename = match &package.default_run {
|
||||
Some(default_run_target) => default_run_target.to_owned(),
|
||||
None => manifest
|
||||
.bin
|
||||
.iter()
|
||||
.find(|b| b.name == manifest.package.as_ref().map(|pkg| pkg.name.clone()))
|
||||
.or(manifest
|
||||
.bin
|
||||
.iter()
|
||||
.find(|b| b.path == Some("src/main.rs".to_owned())))
|
||||
.or(manifest.bin.first())
|
||||
.or(manifest.lib.as_ref())
|
||||
.and_then(|prod| prod.name.clone())
|
||||
.unwrap_or(String::from("dioxus_app")),
|
||||
};
|
||||
}
|
||||
|
||||
let executable = ExecutableType::Binary(output_filename);
|
||||
|
||||
let release = false;
|
||||
let hot_reload = false;
|
||||
let verbose = false;
|
||||
let custom_profile = None;
|
||||
let features = None;
|
||||
let target = None;
|
||||
let cargo_args = vec![];
|
||||
|
||||
Ok(Self {
|
||||
out_dir,
|
||||
crate_dir,
|
||||
workspace_dir,
|
||||
target_dir,
|
||||
asset_dir,
|
||||
manifest,
|
||||
executable,
|
||||
release,
|
||||
dioxus_config,
|
||||
hot_reload,
|
||||
cross_origin_policy: false,
|
||||
custom_profile,
|
||||
features,
|
||||
verbose,
|
||||
target,
|
||||
cargo_args,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn asset_manifest(&self) -> AssetManifest {
|
||||
AssetManifest::load_from_path(
|
||||
self.crate_dir.join("Cargo.toml"),
|
||||
self.workspace_dir.join("Cargo.lock"),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn as_example(&mut self, example_name: String) -> &mut Self {
|
||||
self.executable = ExecutableType::Example(example_name);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_release(&mut self, release: bool) -> &mut Self {
|
||||
self.release = release;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_hot_reload(&mut self, hot_reload: bool) -> &mut Self {
|
||||
self.hot_reload = hot_reload;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_cross_origin_policy(&mut self, cross_origin_policy: bool) -> &mut Self {
|
||||
self.cross_origin_policy = cross_origin_policy;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_verbose(&mut self, verbose: bool) -> &mut Self {
|
||||
self.verbose = verbose;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_profile(&mut self, profile: String) -> &mut Self {
|
||||
self.custom_profile = Some(profile);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_features(&mut self, features: Vec<String>) -> &mut Self {
|
||||
self.features = Some(features);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_target(&mut self, target: String) -> &mut Self {
|
||||
self.target = Some(target);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_cargo_args(&mut self, cargo_args: Vec<String>) -> &mut Self {
|
||||
self.cargo_args = cargo_args;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct BundleConfig {
|
||||
pub identifier: Option<String>,
|
||||
pub publisher: Option<String>,
|
||||
pub icon: Option<Vec<String>>,
|
||||
pub resources: Option<Vec<String>>,
|
||||
pub copyright: Option<String>,
|
||||
pub category: Option<String>,
|
||||
pub short_description: Option<String>,
|
||||
pub long_description: Option<String>,
|
||||
pub external_bin: Option<Vec<String>>,
|
||||
pub deb: Option<DebianSettings>,
|
||||
pub macos: Option<MacOsSettings>,
|
||||
pub windows: Option<WindowsSettings>,
|
||||
}
|
||||
|
||||
impl From<BundleConfig> for tauri_bundler::BundleSettings {
|
||||
fn from(val: BundleConfig) -> Self {
|
||||
tauri_bundler::BundleSettings {
|
||||
identifier: val.identifier,
|
||||
publisher: val.publisher,
|
||||
icon: val.icon,
|
||||
resources: val.resources,
|
||||
copyright: val.copyright,
|
||||
category: val.category.and_then(|c| c.parse().ok()),
|
||||
short_description: val.short_description,
|
||||
long_description: val.long_description,
|
||||
external_bin: val.external_bin,
|
||||
deb: val.deb.map(Into::into).unwrap_or_default(),
|
||||
macos: val.macos.map(Into::into).unwrap_or_default(),
|
||||
windows: val.windows.map(Into::into).unwrap_or_default(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct DebianSettings {
|
||||
pub depends: Option<Vec<String>>,
|
||||
pub files: HashMap<PathBuf, PathBuf>,
|
||||
pub nsis: Option<NsisSettings>,
|
||||
}
|
||||
|
||||
impl From<DebianSettings> for tauri_bundler::DebianSettings {
|
||||
fn from(val: DebianSettings) -> Self {
|
||||
tauri_bundler::DebianSettings {
|
||||
depends: val.depends,
|
||||
files: val.files,
|
||||
desktop_template: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct WixSettings {
|
||||
pub language: Vec<(String, Option<PathBuf>)>,
|
||||
pub template: Option<PathBuf>,
|
||||
pub fragment_paths: Vec<PathBuf>,
|
||||
pub component_group_refs: Vec<String>,
|
||||
pub component_refs: Vec<String>,
|
||||
pub feature_group_refs: Vec<String>,
|
||||
pub feature_refs: Vec<String>,
|
||||
pub merge_refs: Vec<String>,
|
||||
pub skip_webview_install: bool,
|
||||
pub license: Option<PathBuf>,
|
||||
pub enable_elevated_update_task: bool,
|
||||
pub banner_path: Option<PathBuf>,
|
||||
pub dialog_image_path: Option<PathBuf>,
|
||||
pub fips_compliant: bool,
|
||||
}
|
||||
|
||||
impl From<WixSettings> for tauri_bundler::WixSettings {
|
||||
fn from(val: WixSettings) -> Self {
|
||||
tauri_bundler::WixSettings {
|
||||
language: tauri_bundler::bundle::WixLanguage({
|
||||
let mut languages: Vec<_> = val
|
||||
.language
|
||||
.iter()
|
||||
.map(|l| {
|
||||
(
|
||||
l.0.clone(),
|
||||
tauri_bundler::bundle::WixLanguageConfig {
|
||||
locale_path: l.1.clone(),
|
||||
},
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
if languages.is_empty() {
|
||||
languages.push(("en-US".into(), Default::default()));
|
||||
}
|
||||
languages
|
||||
}),
|
||||
template: val.template,
|
||||
fragment_paths: val.fragment_paths,
|
||||
component_group_refs: val.component_group_refs,
|
||||
component_refs: val.component_refs,
|
||||
feature_group_refs: val.feature_group_refs,
|
||||
feature_refs: val.feature_refs,
|
||||
merge_refs: val.merge_refs,
|
||||
skip_webview_install: val.skip_webview_install,
|
||||
license: val.license,
|
||||
enable_elevated_update_task: val.enable_elevated_update_task,
|
||||
banner_path: val.banner_path,
|
||||
dialog_image_path: val.dialog_image_path,
|
||||
fips_compliant: val.fips_compliant,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct MacOsSettings {
|
||||
pub frameworks: Option<Vec<String>>,
|
||||
pub minimum_system_version: Option<String>,
|
||||
pub license: Option<String>,
|
||||
pub exception_domain: Option<String>,
|
||||
pub signing_identity: Option<String>,
|
||||
pub provider_short_name: Option<String>,
|
||||
pub entitlements: Option<String>,
|
||||
pub info_plist_path: Option<PathBuf>,
|
||||
}
|
||||
|
||||
impl From<MacOsSettings> for tauri_bundler::MacOsSettings {
|
||||
fn from(val: MacOsSettings) -> Self {
|
||||
tauri_bundler::MacOsSettings {
|
||||
frameworks: val.frameworks,
|
||||
minimum_system_version: val.minimum_system_version,
|
||||
license: val.license,
|
||||
exception_domain: val.exception_domain,
|
||||
signing_identity: val.signing_identity,
|
||||
provider_short_name: val.provider_short_name,
|
||||
entitlements: val.entitlements,
|
||||
info_plist_path: val.info_plist_path,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct WindowsSettings {
|
||||
pub digest_algorithm: Option<String>,
|
||||
pub certificate_thumbprint: Option<String>,
|
||||
pub timestamp_url: Option<String>,
|
||||
pub tsp: bool,
|
||||
pub wix: Option<WixSettings>,
|
||||
pub icon_path: Option<PathBuf>,
|
||||
pub webview_install_mode: WebviewInstallMode,
|
||||
pub webview_fixed_runtime_path: Option<PathBuf>,
|
||||
pub allow_downgrades: bool,
|
||||
pub nsis: Option<NsisSettings>,
|
||||
}
|
||||
|
||||
impl From<WindowsSettings> for tauri_bundler::WindowsSettings {
|
||||
fn from(val: WindowsSettings) -> Self {
|
||||
tauri_bundler::WindowsSettings {
|
||||
digest_algorithm: val.digest_algorithm,
|
||||
certificate_thumbprint: val.certificate_thumbprint,
|
||||
timestamp_url: val.timestamp_url,
|
||||
tsp: val.tsp,
|
||||
wix: val.wix.map(Into::into),
|
||||
icon_path: val.icon_path.unwrap_or("icons/icon.ico".into()),
|
||||
webview_install_mode: val.webview_install_mode.into(),
|
||||
webview_fixed_runtime_path: val.webview_fixed_runtime_path,
|
||||
allow_downgrades: val.allow_downgrades,
|
||||
nsis: val.nsis.map(Into::into),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct NsisSettings {
|
||||
pub template: Option<PathBuf>,
|
||||
pub license: Option<PathBuf>,
|
||||
pub header_image: Option<PathBuf>,
|
||||
pub sidebar_image: Option<PathBuf>,
|
||||
pub installer_icon: Option<PathBuf>,
|
||||
pub install_mode: NSISInstallerMode,
|
||||
pub languages: Option<Vec<String>>,
|
||||
pub custom_language_files: Option<HashMap<String, PathBuf>>,
|
||||
pub display_language_selector: bool,
|
||||
}
|
||||
|
||||
impl From<NsisSettings> for tauri_bundler::NsisSettings {
|
||||
fn from(val: NsisSettings) -> Self {
|
||||
tauri_bundler::NsisSettings {
|
||||
license: val.license,
|
||||
header_image: val.header_image,
|
||||
sidebar_image: val.sidebar_image,
|
||||
installer_icon: val.installer_icon,
|
||||
install_mode: val.install_mode.into(),
|
||||
languages: val.languages,
|
||||
display_language_selector: val.display_language_selector,
|
||||
custom_language_files: None,
|
||||
template: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum NSISInstallerMode {
|
||||
CurrentUser,
|
||||
PerMachine,
|
||||
Both,
|
||||
}
|
||||
|
||||
impl From<NSISInstallerMode> for tauri_utils::config::NSISInstallerMode {
|
||||
fn from(val: NSISInstallerMode) -> Self {
|
||||
match val {
|
||||
NSISInstallerMode::CurrentUser => tauri_utils::config::NSISInstallerMode::CurrentUser,
|
||||
NSISInstallerMode::PerMachine => tauri_utils::config::NSISInstallerMode::PerMachine,
|
||||
NSISInstallerMode::Both => tauri_utils::config::NSISInstallerMode::Both,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum WebviewInstallMode {
|
||||
Skip,
|
||||
DownloadBootstrapper { silent: bool },
|
||||
EmbedBootstrapper { silent: bool },
|
||||
OfflineInstaller { silent: bool },
|
||||
FixedRuntime { path: PathBuf },
|
||||
}
|
||||
|
||||
impl WebviewInstallMode {
|
||||
fn into(self) -> tauri_utils::config::WebviewInstallMode {
|
||||
match self {
|
||||
Self::Skip => tauri_utils::config::WebviewInstallMode::Skip,
|
||||
Self::DownloadBootstrapper { silent } => {
|
||||
tauri_utils::config::WebviewInstallMode::DownloadBootstrapper { silent }
|
||||
}
|
||||
Self::EmbedBootstrapper { silent } => {
|
||||
tauri_utils::config::WebviewInstallMode::EmbedBootstrapper { silent }
|
||||
}
|
||||
Self::OfflineInstaller { silent } => {
|
||||
tauri_utils::config::WebviewInstallMode::OfflineInstaller { silent }
|
||||
}
|
||||
Self::FixedRuntime { path } => {
|
||||
tauri_utils::config::WebviewInstallMode::FixedRuntime { path }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for WebviewInstallMode {
|
||||
fn default() -> Self {
|
||||
Self::OfflineInstaller { silent: false }
|
||||
}
|
||||
}
|
|
@ -72,6 +72,24 @@ impl From<hyper::Error> for Error {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<dioxus_cli_config::LoadDioxusConfigError> for Error {
|
||||
fn from(e: dioxus_cli_config::LoadDioxusConfigError) -> Self {
|
||||
Self::RuntimeError(e.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<dioxus_cli_config::CargoError> for Error {
|
||||
fn from(e: dioxus_cli_config::CargoError) -> Self {
|
||||
Self::CargoError(e.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<dioxus_cli_config::CrateConfigError> for Error {
|
||||
fn from(e: dioxus_cli_config::CrateConfigError) -> Self {
|
||||
Self::RuntimeError(e.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! custom_error {
|
||||
($msg:literal $(,)?) => {
|
||||
|
|
|
@ -4,21 +4,16 @@
|
|||
|
||||
pub const DIOXUS_CLI_VERSION: &str = "0.4.1";
|
||||
|
||||
mod assets;
|
||||
pub mod builder;
|
||||
pub mod server;
|
||||
pub mod tools;
|
||||
|
||||
pub use builder::*;
|
||||
|
||||
pub mod cargo;
|
||||
pub use cargo::*;
|
||||
|
||||
pub mod cli;
|
||||
pub use cli::*;
|
||||
|
||||
pub mod config;
|
||||
pub use config::*;
|
||||
|
||||
pub mod error;
|
||||
pub use error::*;
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use dioxus_cli_config::DioxusConfig;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::anyhow;
|
||||
|
@ -48,7 +49,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
let _dioxus_config = DioxusConfig::load(Some(bin.clone()))
|
||||
.map_err(|e| anyhow!("Failed to load Dioxus config because: {e}"))?
|
||||
.unwrap_or_else(|| {
|
||||
log::warn!("You appear to be creating a Dioxus project from scratch; we will use the default config");
|
||||
log::info!("You appear to be creating a Dioxus project from scratch; we will use the default config");
|
||||
DioxusConfig::default()
|
||||
});
|
||||
|
||||
|
|
|
@ -5,8 +5,11 @@ use crate::{
|
|||
output::{print_console_info, PrettierOptions},
|
||||
setup_file_watcher,
|
||||
},
|
||||
BuildResult, CrateConfig, Result,
|
||||
BuildResult, Result,
|
||||
};
|
||||
use dioxus_cli_config::CrateConfig;
|
||||
use dioxus_cli_config::ExecutableType;
|
||||
|
||||
use dioxus_hot_reload::HotReloadMsg;
|
||||
use dioxus_html::HtmlCtx;
|
||||
use dioxus_rsx::hot_reload::*;
|
||||
|
@ -215,9 +218,9 @@ fn start_desktop(config: &CrateConfig, skip_assets: bool) -> Result<(RAIIChild,
|
|||
let result = crate::builder::build_desktop(config, true, skip_assets)?;
|
||||
|
||||
match &config.executable {
|
||||
crate::ExecutableType::Binary(name)
|
||||
| crate::ExecutableType::Lib(name)
|
||||
| crate::ExecutableType::Example(name) => {
|
||||
ExecutableType::Binary(name)
|
||||
| ExecutableType::Lib(name)
|
||||
| ExecutableType::Example(name) => {
|
||||
let mut file = config.out_dir.join(name);
|
||||
if cfg!(windows) {
|
||||
file.set_extension("exe");
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
use dioxus_cli_config::CrateConfig;
|
||||
|
||||
use crate::{
|
||||
assets::WebAssetConfigDropGuard,
|
||||
cfg::{ConfigOptsBuild, ConfigOptsServe},
|
||||
CrateConfig, Result, WebAssetConfigDropGuard,
|
||||
Result,
|
||||
};
|
||||
|
||||
use super::{desktop, Platform};
|
||||
|
@ -86,7 +89,7 @@ fn build_web(serve: ConfigOptsServe, target_directory: &std::path::Path) -> Resu
|
|||
}
|
||||
None => web_config.features = Some(vec![web_feature]),
|
||||
};
|
||||
web_config.platform = Some(crate::cfg::Platform::Web);
|
||||
web_config.platform = Some(dioxus_cli_config::Platform::Web);
|
||||
|
||||
let _gaurd = FullstackWebEnvGuard::new(&web_config);
|
||||
crate::cli::build::Build { build: web_config }.build(None, Some(target_directory))
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
use crate::{cfg::ConfigOptsServe, BuildResult, CrateConfig, Result};
|
||||
use crate::{cfg::ConfigOptsServe, BuildResult, Result};
|
||||
use dioxus_cli_config::CrateConfig;
|
||||
|
||||
use cargo_metadata::diagnostic::Diagnostic;
|
||||
use dioxus_core::Template;
|
||||
use dioxus_html::HtmlCtx;
|
||||
use dioxus_rsx::hot_reload::*;
|
||||
use notify::{RecommendedWatcher, Watcher};
|
||||
use std::{
|
||||
path::PathBuf,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use tokio::sync::broadcast::{self};
|
||||
|
||||
mod output;
|
||||
|
@ -27,13 +25,7 @@ async fn setup_file_watcher<F: Fn() -> Result<BuildResult> + Send + 'static>(
|
|||
let mut last_update_time = chrono::Local::now().timestamp();
|
||||
|
||||
// file watcher: check file change
|
||||
let allow_watch_path = config
|
||||
.dioxus_config
|
||||
.web
|
||||
.watcher
|
||||
.watch_path
|
||||
.clone()
|
||||
.unwrap_or_else(|| vec![PathBuf::from("src"), PathBuf::from("examples")]);
|
||||
let allow_watch_path = config.dioxus_config.web.watcher.watch_path.clone();
|
||||
|
||||
let watcher_config = config.clone();
|
||||
let mut watcher = notify::recommended_watcher(move |info: notify::Result<notify::Event>| {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use crate::server::Diagnostic;
|
||||
use crate::CrateConfig;
|
||||
use colored::Colorize;
|
||||
use dioxus_cli_config::crate_root;
|
||||
use dioxus_cli_config::CrateConfig;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
|
@ -43,25 +44,19 @@ pub fn print_console_info(
|
|||
profile = config.custom_profile.as_ref().unwrap().to_string();
|
||||
}
|
||||
let hot_reload = if config.hot_reload { "RSX" } else { "Normal" };
|
||||
let crate_root = crate::cargo::crate_root().unwrap();
|
||||
let crate_root = crate_root().unwrap();
|
||||
let custom_html_file = if crate_root.join("index.html").is_file() {
|
||||
"Custom [index.html]"
|
||||
} else {
|
||||
"Default"
|
||||
};
|
||||
let url_rewrite = if config
|
||||
.dioxus_config
|
||||
.web
|
||||
.watcher
|
||||
.index_on_404
|
||||
.unwrap_or(false)
|
||||
{
|
||||
let url_rewrite = if config.dioxus_config.web.watcher.index_on_404 {
|
||||
"True"
|
||||
} else {
|
||||
"False"
|
||||
};
|
||||
|
||||
let proxies = config.dioxus_config.web.proxy.as_ref();
|
||||
let proxies = &config.dioxus_config.web.proxy;
|
||||
|
||||
if options.changed.is_empty() {
|
||||
println!(
|
||||
|
@ -109,12 +104,10 @@ pub fn print_console_info(
|
|||
println!();
|
||||
println!("\t> Profile : {}", profile.green());
|
||||
println!("\t> Hot Reload : {}", hot_reload.cyan());
|
||||
if let Some(proxies) = proxies {
|
||||
if !proxies.is_empty() {
|
||||
println!("\t> Proxies :");
|
||||
for proxy in proxies {
|
||||
println!("\t\t- {}", proxy.backend.blue());
|
||||
}
|
||||
if !proxies.is_empty() {
|
||||
println!("\t> Proxies :");
|
||||
for proxy in proxies {
|
||||
println!("\t\t- {}", proxy.backend.blue());
|
||||
}
|
||||
}
|
||||
println!("\t> Index Template : {}", custom_html_file.green());
|
||||
|
|
|
@ -5,7 +5,7 @@ use crate::{
|
|||
output::{print_console_info, PrettierOptions, WebServerInfo},
|
||||
setup_file_watcher, HotReloadState,
|
||||
},
|
||||
BuildResult, CrateConfig, Result, WebHttpsConfig,
|
||||
BuildResult, Result,
|
||||
};
|
||||
use axum::{
|
||||
body::{Full, HttpBody},
|
||||
|
@ -20,6 +20,8 @@ use axum::{
|
|||
Router,
|
||||
};
|
||||
use axum_server::tls_rustls::RustlsConfig;
|
||||
use dioxus_cli_config::CrateConfig;
|
||||
use dioxus_cli_config::WebHttpsConfig;
|
||||
|
||||
use dioxus_html::HtmlCtx;
|
||||
use dioxus_rsx::hot_reload::*;
|
||||
|
@ -109,6 +111,9 @@ pub async fn serve(
|
|||
) -> Result<()> {
|
||||
let first_build_result = crate::builder::build(&config, false, skip_assets)?;
|
||||
|
||||
// generate dev-index page
|
||||
Serve::regen_dev_page(&config, first_build_result.assets.as_ref())?;
|
||||
|
||||
log::info!("🚀 Starting development server...");
|
||||
|
||||
// WS Reload Watching
|
||||
|
@ -277,12 +282,7 @@ async fn setup_router(
|
|||
.override_response_header(HeaderName::from_static("cross-origin-opener-policy"), coop)
|
||||
.and_then(
|
||||
move |response: Response<ServeFileSystemResponseBody>| async move {
|
||||
let mut response = if file_service_config
|
||||
.dioxus_config
|
||||
.web
|
||||
.watcher
|
||||
.index_on_404
|
||||
.unwrap_or(false)
|
||||
let mut response = if file_service_config.dioxus_config.web.watcher.index_on_404
|
||||
&& response.status() == StatusCode::NOT_FOUND
|
||||
{
|
||||
let body = Full::from(
|
||||
|
@ -321,7 +321,7 @@ async fn setup_router(
|
|||
let mut router = Router::new().route("/_dioxus/ws", get(ws_handler));
|
||||
|
||||
// Setup proxy
|
||||
for proxy_config in config.dioxus_config.web.proxy.unwrap_or_default() {
|
||||
for proxy_config in config.dioxus_config.web.proxy {
|
||||
router = proxy::add_proxy(router, &proxy_config)?;
|
||||
}
|
||||
|
||||
|
@ -335,6 +335,18 @@ async fn setup_router(
|
|||
},
|
||||
));
|
||||
|
||||
router = if let Some(base_path) = config.dioxus_config.web.app.base_path.clone() {
|
||||
let base_path = format!("/{}", base_path.trim_matches('/'));
|
||||
Router::new()
|
||||
.nest(&base_path, axum::routing::any_service(router))
|
||||
.fallback(get(move || {
|
||||
let base_path = base_path.clone();
|
||||
async move { format!("Outside of the base path: {}", base_path) }
|
||||
}))
|
||||
} else {
|
||||
router
|
||||
};
|
||||
|
||||
// Setup routes
|
||||
router = router
|
||||
.route("/_dioxus/hot_reload", get(hot_reload_handler))
|
||||
|
@ -438,14 +450,8 @@ fn build(config: &CrateConfig, reload_tx: &Sender<()>, skip_assets: bool) -> Res
|
|||
let result = builder::build(config, true, skip_assets)?;
|
||||
// change the websocket reload state to true;
|
||||
// the page will auto-reload.
|
||||
if config
|
||||
.dioxus_config
|
||||
.web
|
||||
.watcher
|
||||
.reload_html
|
||||
.unwrap_or(false)
|
||||
{
|
||||
let _ = Serve::regen_dev_page(config, skip_assets);
|
||||
if config.dioxus_config.web.watcher.reload_html {
|
||||
let _ = Serve::regen_dev_page(config, result.assets.as_ref());
|
||||
}
|
||||
let _ = reload_tx.send(());
|
||||
Ok(result)
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue