Compare commits
76 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bcb2c91823 | |||
| 9058f209dd | |||
| 1f172d583e | |||
| 439b4757df | |||
| 9f8809bd51 | |||
| 4e326650cc | |||
| e27be27692 | |||
| 88eb2a1897 | |||
| 8c84ef73c8 | |||
| 859e49f16c | |||
| 14ba8b0a23 | |||
| d7c70f75f3 | |||
| 2760e3ea08 | |||
| f2f041fe55 | |||
| 9ec9700ed4 | |||
| c6b047fc02 | |||
| 6727264e39 | |||
| d1a5fe234d | |||
| e84c7cd276 | |||
| 087813fab9 | |||
| 3a4e7398c6 | |||
| 1630fd7e71 | |||
| 4aa99beaff | |||
| eaa0ba28d8 | |||
| 3f3e1120b2 | |||
| 89d7a2c740 | |||
| 56c31f0204 | |||
| 338cfb5be2 | |||
| 43f6fe664b | |||
| 209c9fb7f7 | |||
| a562f67e8d | |||
| ef0fe5a425 | |||
| b50902d23e | |||
| 55490579ec | |||
| 957d08701f | |||
| 61e1aed35d | |||
| 2034f0ef5f | |||
| fcb92c7f0b | |||
| 28ea1ca1df | |||
| ebc1a458a9 | |||
| df92ef5296 | |||
| 253e0a8378 | |||
| a9fbe4eddd | |||
| cfccc638c6 | |||
| 9f1460cc26 | |||
| f0a4541420 | |||
| d0ce482680 | |||
| 40e2734a4e | |||
| 8552796343 | |||
| 6d72ffb876 | |||
| 65faaf0183 | |||
| 7f7c2e8d6f | |||
| 3be491baa7 | |||
| 48b974ae58 | |||
| c394898fcd | |||
| f22249f3e9 | |||
| 120cec52e9 | |||
| 535cc6b3d9 | |||
| 18a060e2bf | |||
| 7b8165cee6 | |||
| 6331eb64e6 | |||
| 3c38b551f0 | |||
| 8e761347f2 | |||
| e2d44e0e6a | |||
| 607da92c71 | |||
| ae0427604e | |||
| 2aa981c581 | |||
| 5d8ec82502 | |||
| fc9bb52c41 | |||
| 3224e4138f | |||
| 7ea28c4fd3 | |||
| acb5567f6a | |||
| cc877c7c11 | |||
| 87bdddf7cf | |||
| d939b64d64 | |||
| 3f64f71947 |
@@ -59,6 +59,7 @@
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
"@typescript-eslint/no-deprecated": "error",
|
||||||
"@typescript-eslint/no-empty-function": "error",
|
"@typescript-eslint/no-empty-function": "error",
|
||||||
"@typescript-eslint/no-empty-interface": "error",
|
"@typescript-eslint/no-empty-interface": "error",
|
||||||
"@typescript-eslint/no-explicit-any": "off",
|
"@typescript-eslint/no-explicit-any": "off",
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
## Description
|
|
||||||
A clear and concise description of what the bug is.
|
|
||||||
|
|
||||||
## Expected behaviour
|
|
||||||
A clear and concise description of what you expected to happen.
|
|
||||||
|
|
||||||
## How to reproduce
|
|
||||||
Steps to reproduce the behavior:
|
|
||||||
|
|
||||||
## Screenshots
|
|
||||||
If applicable, add screenshots to help explain your problem.
|
|
||||||
|
|
||||||
## Tooling and environment
|
|
||||||
- Tuono version [e.g. 0.4.0]
|
|
||||||
- OS: [e.g. MacOS, Windows]
|
|
||||||
- Browser: [e.g. chrome, safari]
|
|
||||||
- Node version: [e.g. 20.0.0]
|
|
||||||
- Rust version: [e.g. 1.79.0]
|
|
||||||
- Crate version: [e.g. 1.78.0]
|
|
||||||
- Node Package Manger version: [e.g. pnpm: 9.5.0]
|
|
||||||
|
|
||||||
## Additional context
|
|
||||||
Add any other context about the problem here.
|
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
name: Bug report
|
||||||
|
description: File a bug report
|
||||||
|
title: '[Bug]: '
|
||||||
|
labels: ['bug']
|
||||||
|
|
||||||
|
body:
|
||||||
|
- type: textarea
|
||||||
|
id: description
|
||||||
|
attributes:
|
||||||
|
label: Description
|
||||||
|
description: A clear and concise description of what the bug is.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: expected-behaviour
|
||||||
|
attributes:
|
||||||
|
label: Expected behaviour
|
||||||
|
description: A clear and concise description of what you expected to happen.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: steps
|
||||||
|
attributes:
|
||||||
|
label: How to reproduce
|
||||||
|
description: Steps to reproduce the behavior (code, example repository)
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: screenshots
|
||||||
|
attributes:
|
||||||
|
label: Screenshots
|
||||||
|
description: If applicable, add screenshots to help explain your problem.
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
|
- type: input
|
||||||
|
id: tuono-version
|
||||||
|
attributes:
|
||||||
|
label: Tuono version
|
||||||
|
placeholder: '[e.g. 0.4.0]'
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
|
- type: input
|
||||||
|
id: os-version
|
||||||
|
attributes:
|
||||||
|
label: OS
|
||||||
|
placeholder: '[e.g. MacOS, Windows]'
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
|
- type: input
|
||||||
|
id: browser-version
|
||||||
|
attributes:
|
||||||
|
label: Browser
|
||||||
|
placeholder: '[e.g. chrome, safari]'
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
|
- type: input
|
||||||
|
id: node-version
|
||||||
|
attributes:
|
||||||
|
label: Node version
|
||||||
|
placeholder: '[e.g. 20.0.0]'
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
|
- type: input
|
||||||
|
id: rust-version
|
||||||
|
attributes:
|
||||||
|
label: Rust version
|
||||||
|
placeholder: '[e.g. 1.79.0]'
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
|
- type: input
|
||||||
|
id: create-version
|
||||||
|
attributes:
|
||||||
|
label: Crate version
|
||||||
|
placeholder: '[e.g. 1.78.0]'
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
|
- type: input
|
||||||
|
id: node-package-manager-version
|
||||||
|
attributes:
|
||||||
|
label: Node Package Manger version
|
||||||
|
placeholder: '[e.g. pnpm: 9.5.0] '
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
|
- type: textarea
|
||||||
|
id: additional-context
|
||||||
|
attributes:
|
||||||
|
label: Additional context
|
||||||
|
description: Add any other context about the bug here.
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
---
|
|
||||||
name: Feature request
|
|
||||||
about: Suggest an idea for this project
|
|
||||||
title: ''
|
|
||||||
labels: enhancement
|
|
||||||
assignees: ''
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Is your feature request related to a problem? Please describe.**
|
|
||||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
|
||||||
|
|
||||||
**Describe the solution you'd like**
|
|
||||||
A clear and concise description of what you want to happen.
|
|
||||||
|
|
||||||
**Describe alternatives you've considered**
|
|
||||||
A clear and concise description of any alternative solutions or features you've considered.
|
|
||||||
|
|
||||||
**Additional context**
|
|
||||||
Add any other context or screenshots about the feature request here.
|
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
name: Feature request
|
||||||
|
description: Suggest an idea for this project
|
||||||
|
title: '[Feature request]: '
|
||||||
|
labels: ['enhancement']
|
||||||
|
|
||||||
|
body:
|
||||||
|
- type: textarea
|
||||||
|
id: description
|
||||||
|
attributes:
|
||||||
|
label: Is your feature request related to a problem? Please describe.
|
||||||
|
description: A clear and concise description of what the problem is.
|
||||||
|
placeholder: I'm always frustrated when [...]
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: solution
|
||||||
|
attributes:
|
||||||
|
label: Describe the solution you'd like
|
||||||
|
description: A clear and concise description of what you want to happen.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: alternatives
|
||||||
|
attributes:
|
||||||
|
label: Describe alternatives you've considered
|
||||||
|
description: A clear and concise description of any alternative solutions or features you've considered.
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
|
- type: textarea
|
||||||
|
id: additional-context
|
||||||
|
attributes:
|
||||||
|
label: Additional context
|
||||||
|
description: Add any other context or screenshots about the feature request here.
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
name: Install NodeJS Dependencies
|
||||||
|
description: This is a composite GitHub Action that sets up pnpm, node and installs the project's dependencies.
|
||||||
|
|
||||||
|
inputs:
|
||||||
|
node-version:
|
||||||
|
description: 'Explicit node version. Otherwise fallback reading `.nvmrc`. Use in conjunction with matrix'
|
||||||
|
required: false
|
||||||
|
registry-url:
|
||||||
|
description: 'https://github.com/actions/setup-node?tab=readme-ov-file#usage'
|
||||||
|
required: false
|
||||||
|
default: ''
|
||||||
|
|
||||||
|
runs:
|
||||||
|
using: composite
|
||||||
|
steps:
|
||||||
|
- name: Install pnpm
|
||||||
|
uses: pnpm/action-setup@v4
|
||||||
|
|
||||||
|
- name: Setup Node.js (via input)
|
||||||
|
if: ${{ inputs.node-version }}
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: ${{ inputs.node-version }}
|
||||||
|
registry-url: ${{ inputs.registry-url }}
|
||||||
|
cache: 'pnpm'
|
||||||
|
|
||||||
|
- name: Setup Node.js (via .nvmrc)
|
||||||
|
if: ${{ !inputs.node-version }}
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version-file: '.nvmrc'
|
||||||
|
registry-url: ${{ inputs.registry-url }}
|
||||||
|
cache: 'pnpm'
|
||||||
|
|
||||||
|
- name: Install Dependencies
|
||||||
|
shell: bash
|
||||||
|
run: pnpm install --frozen-lockfile
|
||||||
@@ -13,63 +13,45 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
|
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
|
||||||
|
name: Check build
|
||||||
timeout-minutes: 15
|
timeout-minutes: 15
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
working-directory: ./apps/documentation
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
|
||||||
fetch-depth: 2
|
|
||||||
|
|
||||||
- name: Setup Node.js environment
|
- name: Install NodeJS Dependencies
|
||||||
uses: actions/setup-node@v4
|
uses: ./.github/actions/install-node-dependencies
|
||||||
with:
|
|
||||||
node-version: 20
|
|
||||||
|
|
||||||
- name: Setup rust
|
- name: Setup rust
|
||||||
uses: actions-rust-lang/setup-rust-toolchain@v1
|
uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
|
||||||
- name: Install tuono
|
- name: Install tuono
|
||||||
run: cargo install tuono@0.10.4
|
run: cargo install tuono@0.12.3
|
||||||
|
|
||||||
- name: Install pnpm
|
|
||||||
run: npm i -g pnpm
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: pnpm install --ignore-workspace
|
|
||||||
|
|
||||||
- name: Build project
|
- name: Build project
|
||||||
|
working-directory: ./apps/documentation
|
||||||
run: tuono build --static
|
run: tuono build --static
|
||||||
|
|
||||||
fmt-lint-and-types:
|
fmt-lint-and-types:
|
||||||
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
|
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
|
||||||
|
name: Check format and lint
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 15
|
timeout-minutes: 15
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
working-directory: ./apps/documentation
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
|
||||||
fetch-depth: 2
|
|
||||||
|
|
||||||
- name: Install pnpm
|
- name: Install NodeJS Dependencies
|
||||||
run: npm i -g pnpm
|
uses: ./.github/actions/install-node-dependencies
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: pnpm install --ignore-workspace
|
|
||||||
|
|
||||||
- name: Check formatting
|
- name: Check formatting
|
||||||
run: pnpm format:check
|
run: pnpm docs:format:check
|
||||||
|
|
||||||
- name: Lint
|
- name: Lint
|
||||||
run: pnpm lint
|
run: pnpm docs:lint
|
||||||
|
|
||||||
- name: Types
|
- name: Types
|
||||||
run: pnpm types
|
run: pnpm docs:types
|
||||||
|
|||||||
@@ -10,36 +10,25 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
deploy-documentation:
|
deploy-documentation:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
working-directory: ./apps/documentation
|
|
||||||
env:
|
env:
|
||||||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
|
||||||
fetch-depth: 2
|
|
||||||
|
|
||||||
- name: Setup Node.js environment
|
- name: Install NodeJS Dependencies
|
||||||
uses: actions/setup-node@v4
|
uses: ./.github/actions/install-node-dependencies
|
||||||
with:
|
|
||||||
node-version: 20
|
|
||||||
|
|
||||||
- name: Setup rust
|
- name: Setup rust
|
||||||
uses: actions-rust-lang/setup-rust-toolchain@v1
|
uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
|
||||||
- name: Install tuono
|
- name: Install tuono
|
||||||
run: cargo install tuono@0.10.4
|
run: cargo install tuono@0.12.3
|
||||||
|
|
||||||
- name: Install pnpm
|
|
||||||
run: npm i -g pnpm
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: pnpm install --ignore-workspace
|
|
||||||
|
|
||||||
- name: Build project
|
- name: Build project
|
||||||
|
working-directory: ./apps/documentation
|
||||||
run: tuono build --static
|
run: tuono build --static
|
||||||
|
|
||||||
- name: Deploy
|
- name: Deploy
|
||||||
|
|||||||
@@ -7,24 +7,14 @@ jobs:
|
|||||||
publish-on-npm-dry-run:
|
publish-on-npm-dry-run:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Install Node.js
|
- name: Install NodeJS Dependencies
|
||||||
uses: actions/setup-node@v4
|
uses: ./.github/actions/install-node-dependencies
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
|
||||||
registry-url: 'https://registry.npmjs.org'
|
registry-url: 'https://registry.npmjs.org'
|
||||||
|
|
||||||
- uses: pnpm/action-setup@v3
|
|
||||||
name: Install pnpm
|
|
||||||
with:
|
|
||||||
version: 8
|
|
||||||
run_install: false
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: pnpm install
|
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: pnpm build
|
run: pnpm build
|
||||||
|
|
||||||
@@ -36,11 +26,14 @@ jobs:
|
|||||||
publish-on-crates-dry-run:
|
publish-on-crates-dry-run:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- uses: actions-rs/toolchain@v1
|
- uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: stable
|
toolchain: stable
|
||||||
override: true
|
override: true
|
||||||
|
|
||||||
- uses: katyo/publish-crates@v2
|
- uses: katyo/publish-crates@v2
|
||||||
with:
|
with:
|
||||||
path: './crates/tuono'
|
path: './crates/tuono'
|
||||||
@@ -52,27 +45,17 @@ jobs:
|
|||||||
needs: [publish-on-crates-dry-run, publish-on-npm-dry-run]
|
needs: [publish-on-crates-dry-run, publish-on-npm-dry-run]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Install Node.js
|
- name: Install NodeJS Dependencies
|
||||||
uses: actions/setup-node@v4
|
uses: ./.github/actions/install-node-dependencies
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
|
||||||
registry-url: 'https://registry.npmjs.org'
|
registry-url: 'https://registry.npmjs.org'
|
||||||
|
|
||||||
- uses: pnpm/action-setup@v3
|
|
||||||
name: Install pnpm
|
|
||||||
with:
|
|
||||||
version: 8
|
|
||||||
run_install: false
|
|
||||||
|
|
||||||
- name: Clone root README.md on tuono package
|
- name: Clone root README.md on tuono package
|
||||||
run: cp README.md packages/tuono/README.md
|
run: cp README.md packages/tuono/README.md
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: pnpm install
|
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: pnpm build
|
run: pnpm build
|
||||||
|
|
||||||
@@ -85,11 +68,14 @@ jobs:
|
|||||||
needs: [publish-on-crates-dry-run, publish-on-npm-dry-run]
|
needs: [publish-on-crates-dry-run, publish-on-npm-dry-run]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- uses: actions-rs/toolchain@v1
|
- uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: stable
|
toolchain: stable
|
||||||
override: true
|
override: true
|
||||||
|
|
||||||
- uses: katyo/publish-crates@v2
|
- uses: katyo/publish-crates@v2
|
||||||
with:
|
with:
|
||||||
path: './crates/tuono'
|
path: './crates/tuono'
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
name: Repo root CI
|
||||||
|
# All workflows are triggered based on specific paths,
|
||||||
|
# the root repository is something that is not applicable to rust nor typescript
|
||||||
|
# so it has been moved in a standalone workflow
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
paths:
|
||||||
|
- '.github/**'
|
||||||
|
- './*'
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- '.github/**'
|
||||||
|
- './*'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-test:
|
||||||
|
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
|
||||||
|
name: Check format
|
||||||
|
timeout-minutes: 15
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install NodeJS Dependencies
|
||||||
|
uses: ./.github/actions/install-node-dependencies
|
||||||
|
|
||||||
|
- name: Test project
|
||||||
|
run: pnpm repo:root:format:check
|
||||||
@@ -14,27 +14,40 @@ env:
|
|||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint_and_fmt:
|
|
||||||
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- run: cargo fmt --all -- --check
|
|
||||||
- run: cargo clippy -- -D warnings
|
|
||||||
|
|
||||||
build_and_test:
|
build_and_test:
|
||||||
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
|
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
|
||||||
name: Build and test rust crates
|
name: Build and test rust crates
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
strategy:
|
||||||
|
fail-fast: true
|
||||||
matrix:
|
matrix:
|
||||||
|
os:
|
||||||
|
- 'ubuntu-latest'
|
||||||
|
- 'macos-latest'
|
||||||
|
- 'windows-latest'
|
||||||
toolchain:
|
toolchain:
|
||||||
- stable
|
- stable
|
||||||
- beta
|
- beta
|
||||||
- nightly
|
- nightly
|
||||||
|
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
|
- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
|
||||||
- run: cargo build --verbose
|
- run: cargo build --verbose
|
||||||
- run: cargo test --verbose
|
- run: cargo test --verbose
|
||||||
|
|
||||||
|
lint_and_fmt:
|
||||||
|
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
|
||||||
|
name: Check format and lint rust crates
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- run: cargo fmt --all -- --check
|
||||||
|
- run: cargo clippy -- -D warnings
|
||||||
|
|||||||
@@ -1,21 +1,66 @@
|
|||||||
name: Spell Checker
|
name: Spell Checker
|
||||||
|
|
||||||
on: [pull_request]
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
pull_request:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
spell_checking:
|
spell_checking:
|
||||||
name: runner / LanguageTools
|
name: LanguageTool
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
checks: write
|
||||||
|
contents: read
|
||||||
|
pull-requests: write
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- name: Checkout code
|
||||||
- uses: reviewdog/action-languagetool@v1
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
github_token: ${{ secrets.REVIEWDOG_TOKEN }}
|
# Keep this value in order to show the error comments
|
||||||
|
# also on edited files.
|
||||||
|
fetch-depth: 2
|
||||||
|
|
||||||
|
# If the workflow is triggered by a push use check reporter
|
||||||
|
#
|
||||||
|
# If the workflow is triggered by a PR coming from the
|
||||||
|
# same repository, the author has write access so we can
|
||||||
|
# use pr-review reporter since the GITHUB_TOKEN will have review
|
||||||
|
# write permissions
|
||||||
|
#
|
||||||
|
# Otherwise use annotation reporter that do not require any
|
||||||
|
# particular permission
|
||||||
|
#
|
||||||
|
# Why this?
|
||||||
|
# https://github.com/Valerioageno/tuono/pull/137#pullrequestreview-2455455272
|
||||||
|
- name: Set reporter
|
||||||
|
id: reporter
|
||||||
|
env:
|
||||||
|
EVENT_NAME: ${{ github.event_name }}
|
||||||
|
FROM_MAIN_REPO: ${{ github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name }}
|
||||||
|
run: |
|
||||||
|
echo "EVENT_NAME: $EVENT_NAME FROM_MAIN_REPO: $FROM_MAIN_REPO"
|
||||||
|
if [ "$EVENT_NAME" == 'push' ]; then
|
||||||
|
echo "name=github-check" >> $GITHUB_OUTPUT
|
||||||
|
elif [ "$FROM_MAIN_REPO" == 'true' ]; then
|
||||||
|
echo "name=github-pr-review" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "name=github-pr-annotations" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Review dog languagetool
|
||||||
|
uses: reviewdog/action-languagetool@v1
|
||||||
|
with:
|
||||||
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
# Change reviewdog reporter if you need [github-pr-check,github-check,github-pr-review].
|
# Change reviewdog reporter if you need [github-pr-check,github-check,github-pr-review].
|
||||||
reporter: 'github-pr-review'
|
reporter: ${{ steps.reporter.outputs.name }}
|
||||||
# Change reporter level if you need.
|
# Change reporter level if you need.
|
||||||
level: 'error'
|
level: 'warning'
|
||||||
patterns: '**/*.md **/*.txt **/*.mdx'
|
patterns: '**/*.md **/*.txt **/*.mdx'
|
||||||
#enabled_categories: 'STYLE,PLAIN_ENGLISH,WHITESPACE_RULE,EN_QUOTES,DASH_RULE,WORD_CONTAINS_UNDERSCORE,UPPERCASE_SENTENCE_START,ARROWS,COMMA_PARENTHESIS_WHITESPACE,UNLIKELY_OPENING_PUNCTUATION,SENTENCE_WHITESPACE,EN_UNPAIRED_BRACKETS,PHRASE_REPETITION,PUNCTUATION_PARAGRAPH_END'
|
# enabled_categories: "STYLE,PLAIN_ENGLISH,WHITESPACE_RULE,EN_QUOTES,DASH_RULE,WORD_CONTAINS_UNDERSCORE,UPPERCASE_SENTENCE_START,ARROWS,COMMA_PARENTHESIS_WHITESPACE,UNLIKELY_OPENING_PUNCTUATION,SENTENCE_WHITESPACE,EN_UNPAIRED_BRACKETS,PHRASE_REPETITION,PUNCTUATION_PARAGRAPH_END"
|
||||||
disabled_categories: ''
|
disabled_categories: ''
|
||||||
disabled_rules: ''
|
disabled_rules: ''
|
||||||
|
|||||||
@@ -11,27 +11,27 @@ on:
|
|||||||
- 'packages/**'
|
- 'packages/**'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-test:
|
build_and_test:
|
||||||
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
|
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
|
||||||
|
name: Check build and test
|
||||||
timeout-minutes: 15
|
timeout-minutes: 15
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: true
|
||||||
|
matrix:
|
||||||
|
os:
|
||||||
|
- 'ubuntu-latest'
|
||||||
|
- 'macos-latest'
|
||||||
|
- 'windows-latest'
|
||||||
|
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
|
||||||
fetch-depth: 2
|
|
||||||
|
|
||||||
- name: Setup Node.js environment
|
- name: Install NodeJS Dependencies
|
||||||
uses: actions/setup-node@v4
|
uses: ./.github/actions/install-node-dependencies
|
||||||
with:
|
|
||||||
node-version: 20
|
|
||||||
|
|
||||||
- name: Install pnpm
|
|
||||||
run: npm i -g pnpm
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: pnpm install
|
|
||||||
|
|
||||||
- name: Build project
|
- name: Build project
|
||||||
run: pnpm build
|
run: pnpm build
|
||||||
@@ -39,22 +39,18 @@ jobs:
|
|||||||
- name: Test project
|
- name: Test project
|
||||||
run: pnpm test
|
run: pnpm test
|
||||||
|
|
||||||
fmt-lint-and-types:
|
lint_and_fmt:
|
||||||
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
|
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
|
||||||
|
name: Check format and lint
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 15
|
timeout-minutes: 15
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
|
||||||
fetch-depth: 2
|
|
||||||
|
|
||||||
- name: Install pnpm
|
- name: Install NodeJS Dependencies
|
||||||
run: npm i -g pnpm
|
uses: ./.github/actions/install-node-dependencies
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: pnpm install
|
|
||||||
|
|
||||||
- name: Check formatting
|
- name: Check formatting
|
||||||
run: pnpm format:check
|
run: pnpm format:check
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
|
## Node related ignores
|
||||||
|
|
||||||
node_modules/
|
node_modules/
|
||||||
dist/
|
dist/
|
||||||
.turbo/
|
.turbo/
|
||||||
|
|
||||||
*/**/routeTree.gen.ts
|
*/**/routeTree.gen.ts
|
||||||
|
|
||||||
pnpm-lock.yaml
|
examples/*/pnpm-lock.yaml
|
||||||
|
|
||||||
examples/playground/
|
|
||||||
|
|
||||||
## Rust related ignores
|
## Rust related ignores
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
pnpm-lock.yaml
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"$schema": "https://json.schemastore.org/prettierrc",
|
||||||
"semi": false,
|
"semi": false,
|
||||||
"singleQuote": true,
|
"singleQuote": true,
|
||||||
"trailingComma": "all"
|
"trailingComma": "all"
|
||||||
|
|||||||
@@ -17,23 +17,23 @@ diverse, inclusive, and healthy community.
|
|||||||
Examples of behavior that contributes to a positive environment for our
|
Examples of behavior that contributes to a positive environment for our
|
||||||
community include:
|
community include:
|
||||||
|
|
||||||
* Demonstrating empathy and kindness toward other people
|
- Demonstrating empathy and kindness toward other people
|
||||||
* Being respectful of differing opinions, viewpoints, and experiences
|
- Being respectful of differing opinions, viewpoints, and experiences
|
||||||
* Giving and gracefully accepting constructive feedback
|
- Giving and gracefully accepting constructive feedback
|
||||||
* Accepting responsibility and apologizing to those affected by our mistakes,
|
- Accepting responsibility and apologizing to those affected by our mistakes,
|
||||||
and learning from the experience
|
and learning from the experience
|
||||||
* Focusing on what is best, not just for us as individuals, but for the
|
- Focusing on what is best, not just for us as individuals, but for the
|
||||||
overall community
|
overall community
|
||||||
|
|
||||||
Examples of unacceptable behavior include:
|
Examples of unacceptable behavior include:
|
||||||
|
|
||||||
* The use of sexualized language or imagery, and sexual attention or
|
- The use of sexualized language or imagery, and sexual attention or
|
||||||
Advances of any kind
|
Advances of any kind
|
||||||
* Trolling, insulting or derogatory comments, and personal or political attacks
|
- Trolling, insulting or derogatory comments, and personal or political attacks
|
||||||
* Public or private harassment
|
- Public or private harassment
|
||||||
* Publishing others' private information, such as a physical or email
|
- Publishing others' private information, such as a physical or email
|
||||||
address, without their explicit permission
|
address, without their explicit permission
|
||||||
* Other conduct that could reasonably be considered inappropriate in a
|
- Other conduct that could reasonably be considered inappropriate in a
|
||||||
professional setting
|
professional setting
|
||||||
|
|
||||||
## Enforcement Responsibilities
|
## Enforcement Responsibilities
|
||||||
|
|||||||
@@ -5,17 +5,20 @@
|
|||||||
# How to Contribute to Tuono
|
# How to Contribute to Tuono
|
||||||
|
|
||||||
## Contributions
|
## Contributions
|
||||||
|
|
||||||
Any feature contribution or suggestion is strongly appreciated.
|
Any feature contribution or suggestion is strongly appreciated.
|
||||||
Since the current project size, there isn't yet a defined way to start a discussion. Consider [opening a new issue](https://github.com/Valerioageno/tuono/issues/new)
|
Since the current project size, there isn't yet a defined way to start a discussion. Consider [opening a new issue](https://github.com/Valerioageno/tuono/issues/new/choose)
|
||||||
or to reach me using my email address, [valerioageno@yahoo.it](mailto:valerioageno@ahoo.it). I'm also available on Twitter (X); DM @valerioageno.
|
or to reach me using my email address, [valerioageno@yahoo.it](mailto:valerioageno@ahoo.it). I'm also available on Twitter (X); DM @valerioageno.
|
||||||
|
|
||||||
## Bugs
|
## Bugs
|
||||||
|
|
||||||
**Did you find a bug?**
|
**Did you find a bug?**
|
||||||
|
|
||||||
- Ensure the bug was not already reported by searching on GitHub under [Issues](https://github.com/Valerioageno/tuono/issues).
|
- Ensure the bug was not already reported by searching on GitHub under [Issues](https://github.com/Valerioageno/tuono/issues).
|
||||||
- If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/Valerioageno/tuono/issues/new). Be sure to include a title and clear description, as much relevant information as possible, and a code sample or an executable test case demonstrating the expected behavior that is not occurring.
|
- If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/Valerioageno/tuono/issues/new/choose). Be sure to include a title and clear description, as much relevant information as possible, and a code sample or an executable test case demonstrating the expected behavior that is not occurring.
|
||||||
|
|
||||||
**Did you write a patch that fixes a bug?**
|
**Did you write a patch that fixes a bug?**
|
||||||
|
|
||||||
- Open a new GitHub pull request with the patch.
|
- Open a new GitHub pull request with the patch.
|
||||||
- Ensure the PR description clearly describes the problem and solution. Include the relevant issue number, if applicable.
|
- Ensure the PR description clearly describes the problem and solution. Include the relevant issue number, if applicable.
|
||||||
- The pull requests must pass all the CI pipelines
|
- The pull requests must pass all the CI pipelines
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ members = [
|
|||||||
]
|
]
|
||||||
exclude = [
|
exclude = [
|
||||||
"apps/documentation",
|
"apps/documentation",
|
||||||
"examples/mdx",
|
"examples/wit-mdx",
|
||||||
"examples/tuono",
|
"examples/tuono-app",
|
||||||
"examples/tutorial",
|
"examples/tuono-tutorial",
|
||||||
"benches/tuono"
|
"benches/tuono"
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[Documentation](https://tuono.dev) | [Tutorial](https://tuono.dev/documentation/tutorial) |
|
[Documentation](https://tuono.dev) | [Tutorial](https://tuono.dev/documentation/tutorial) |
|
||||||
[✨Contributing](https://tuono.dev/documentation/contributing)
|
[Discord](https://discord.com/invite/khQzPa654B) | [✨Contributing](https://tuono.dev/documentation/contributing)
|
||||||
|
|
||||||
# Tuono
|
# Tuono
|
||||||
|
|
||||||
@@ -8,15 +8,18 @@
|
|||||||

|

|
||||||

|

|
||||||
|
|
||||||
**Tuono is the fastest React framework out there**
|
**Tuono is a full-stack web framework for building React applications using Rust as the backend with
|
||||||
|
a strong focus on usability and performance.**
|
||||||
|
|
||||||
Tuono (Italian word for "thunder", pronounced /2 Oh No/).
|
Tuono (Italian word for "thunder", pronounced /2 Oh No/).
|
||||||
Why Tuono? Just a badass name.
|
Why Tuono? Just a badass name.
|
||||||
|
|
||||||
|
If you have experience with [Next.js](https://nextjs.org/) you will feel home here.
|
||||||
|
|
||||||
Some of its features are:
|
Some of its features are:
|
||||||
|
|
||||||
- 🟦 Native Typescript
|
- 🟦 Native Typescript
|
||||||
- 🌐 NextJs like Routing
|
- 🌐 Next.js like Routing
|
||||||
- 🍭 CSS/SCSS modules
|
- 🍭 CSS/SCSS modules
|
||||||
- 🧬 Server Side Rendering
|
- 🧬 Server Side Rendering
|
||||||
- 🔥 Hot Module Reload
|
- 🔥 Hot Module Reload
|
||||||
@@ -40,10 +43,14 @@ Tuono provides a collection of utilities to handle the server side code seamless
|
|||||||
Each server-side route is managed in a separate file alongside the React route. The routing is handled
|
Each server-side route is managed in a separate file alongside the React route. The routing is handled
|
||||||
by Tuono based on the files defined within the `./src/routes` directory.
|
by Tuono based on the files defined within the `./src/routes` directory.
|
||||||
|
|
||||||
## Getting started
|
**How is Tuono different from Next.js?**
|
||||||
|
|
||||||
As already mentioned above, I strongly suggest you take a look at the
|
The Tuono API tries to stick as much as possible to the Next.js one (or at least takes a huge inspiration
|
||||||
[tutorial](https://github.com/Valerioageno/tuono/blob/main/docs/tutorial.md).
|
from it). The major difference is the backend system. While Next.js relies entirely on Node/Deno/Bun,
|
||||||
|
Tuono runs the server without any intermediary runtime. This enables impressive performance improvements
|
||||||
|
(check the benchmarks [here](https://github.com/Valerioageno/tuono/tree/main/benches)).
|
||||||
|
|
||||||
|
## Getting started
|
||||||
|
|
||||||
Tuono is the CLI that provides all the needed commands to handle the full-stack project.
|
Tuono is the CLI that provides all the needed commands to handle the full-stack project.
|
||||||
To download it is required [cargo](https://doc.rust-lang.org/cargo/), which is the [rust](https://www.rust-lang.org/)
|
To download it is required [cargo](https://doc.rust-lang.org/cargo/), which is the [rust](https://www.rust-lang.org/)
|
||||||
@@ -56,7 +63,7 @@ To list all the available commands, run `tuono -h`
|
|||||||
To create a new project, run `tuono new [NAME]` (optionally, you can pass the `--template` (or `-t`) flag - check the
|
To create a new project, run `tuono new [NAME]` (optionally, you can pass the `--template` (or `-t`) flag - check the
|
||||||
[examples](https://github.com/Valerioageno/tuono/tree/main/examples) folder).
|
[examples](https://github.com/Valerioageno/tuono/tree/main/examples) folder).
|
||||||
|
|
||||||
Then, to run the local development environment, run it inside the project folder `tuono dev`
|
Then, to run the local development environment, install the JS dependencies (`npm install`) and run inside the project folder `tuono dev`
|
||||||
|
|
||||||
Finally, when the project is ready to be deployed, just run `tuono build` to create the final React assets
|
Finally, when the project is ready to be deployed, just run `tuono build` to create the final React assets
|
||||||
and to set the server project in `production` mode.
|
and to set the server project in `production` mode.
|
||||||
@@ -64,6 +71,7 @@ and to set the server project in `production` mode.
|
|||||||
Now to execute it just run `cargo run --release`.
|
Now to execute it just run `cargo run --release`.
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
Any help or suggestion will be appreciated and encouraged.
|
Any help or suggestion will be appreciated and encouraged.
|
||||||
Check the [✨Contributing](https://tuono.dev/documentation/contributing) page
|
Check the [✨Contributing](https://tuono.dev/documentation/contributing) page
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,7 @@
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
"@typescript-eslint/no-deprecated": "error",
|
||||||
"@typescript-eslint/no-empty-function": "error",
|
"@typescript-eslint/no-empty-function": "error",
|
||||||
"@typescript-eslint/no-empty-interface": "error",
|
"@typescript-eslint/no-empty-interface": "error",
|
||||||
"@typescript-eslint/no-explicit-any": "off",
|
"@typescript-eslint/no-explicit-any": "off",
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ name = "tuono"
|
|||||||
path = ".tuono/main.rs"
|
path = ".tuono/main.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tuono_lib = "0.11.1"
|
tuono_lib = "0.12.3"
|
||||||
glob = "0.3.1"
|
glob = "0.3.1"
|
||||||
time = { version = "0.3", features = ["macros"] }
|
time = { version = "0.3", features = ["macros"] }
|
||||||
serde = { version = "1.0.202", features = ["derive"] }
|
serde = { version = "1.0.202", features = ["derive"] }
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "tuono",
|
"name": "documentation",
|
||||||
"description": "The react/rust fullstack framework",
|
"description": "The react/rust fullstack framework documentation",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "eslint --ext .ts,.tsx ./src -c .eslintrc",
|
"lint": "eslint --ext .ts,.tsx ./src -c .eslintrc",
|
||||||
"format": "prettier -u --write --ignore-unknown './src/**/*'",
|
"format": "prettier -u --write --ignore-unknown './src/**/*'",
|
||||||
@@ -17,24 +18,14 @@
|
|||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"react": "18.3.1",
|
"react": "18.3.1",
|
||||||
"react-dom": "18.3.1",
|
"react-dom": "18.3.1",
|
||||||
"tuono": "0.11.1"
|
"tuono": "npm:tuono@0.12.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/mdx": "^2.0.13",
|
"@types/mdx": "^2.0.13",
|
||||||
"@types/react": "^18.3.3",
|
"@types/react": "^18.3.3",
|
||||||
"@types/react-dom": "^18.3.0",
|
"@types/react-dom": "^18.3.0",
|
||||||
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
||||||
"@typescript-eslint/parser": "^8.0.0",
|
|
||||||
"eslint": "^8.56.0",
|
|
||||||
"eslint-config-prettier": "^9.1.0",
|
|
||||||
"eslint-import-resolver-typescript": "^3.6.1",
|
|
||||||
"eslint-plugin-import": "^2.29.1",
|
|
||||||
"eslint-plugin-react": "^7.33.2",
|
|
||||||
"eslint-plugin-react-hooks": "^5.0.0",
|
|
||||||
"postcss": "^8.4.39",
|
"postcss": "^8.4.39",
|
||||||
"postcss-preset-mantine": "^1.17.0",
|
"postcss-preset-mantine": "^1.17.0",
|
||||||
"postcss-simple-vars": "^7.0.1",
|
"postcss-simple-vars": "^7.0.1"
|
||||||
"prettier": "^3.2.4",
|
|
||||||
"typescript": "^5.5.4"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 314 KiB After Width: | Height: | Size: 42 KiB |
@@ -1,3 +1,4 @@
|
|||||||
|
import type { JSX } from 'react'
|
||||||
import { Breadcrumbs, Button } from '@mantine/core'
|
import { Breadcrumbs, Button } from '@mantine/core'
|
||||||
import { Link, Head } from 'tuono'
|
import { Link, Head } from 'tuono'
|
||||||
|
|
||||||
@@ -18,29 +19,34 @@ export default function TuonoBreadcrumbs({
|
|||||||
<>
|
<>
|
||||||
<Head>
|
<Head>
|
||||||
<script type="application/ld+json">
|
<script type="application/ld+json">
|
||||||
{`[
|
{`{
|
||||||
{
|
|
||||||
"@context": "https://schema.org",
|
"@context": "https://schema.org",
|
||||||
"@type": "BreadcrumbList",
|
"@type": "BreadcrumbList",
|
||||||
"itemListElement": [
|
"itemListElement": [
|
||||||
{
|
{
|
||||||
'@type': "ListItem",
|
"@type": "ListItem",
|
||||||
"position": 1,
|
"position": 1,
|
||||||
|
"name": "Tuono - The React/Rust fullstack framework",
|
||||||
|
"item": "https://tuono.dev"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"@type": "ListItem",
|
||||||
|
"position": 2,
|
||||||
"name": "Tuono - Documentation",
|
"name": "Tuono - Documentation",
|
||||||
"item": "https://tuono.dev/documentation",
|
"item": "https://tuono.dev/documentation"
|
||||||
}${breadcrumbs.length > 0 ? ',' : ''}
|
}${breadcrumbs.length > 0 ? ',' : ''}
|
||||||
${breadcrumbs
|
${breadcrumbs
|
||||||
.map((br, i) =>
|
.map((br, i) =>
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
'@type': 'ListItem',
|
'@type': 'ListItem',
|
||||||
position: i + 2,
|
position: i + 3,
|
||||||
name: br.label,
|
name: br.label,
|
||||||
item: br.href ? `https://tuono.dev${br.href}` : undefined,
|
item: br.href ? `https://tuono.dev${br.href}` : undefined,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.join(',')}]
|
.join(',')}]
|
||||||
}
|
}
|
||||||
]`}
|
`}
|
||||||
</script>
|
</script>
|
||||||
</Head>
|
</Head>
|
||||||
<Breadcrumbs
|
<Breadcrumbs
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type { JSX } from 'react'
|
||||||
import { Button } from '@mantine/core'
|
import { Button } from '@mantine/core'
|
||||||
import { IconEdit } from '@tabler/icons-react'
|
import { IconEdit } from '@tabler/icons-react'
|
||||||
import { useRouter } from 'tuono'
|
import { useRouter } from 'tuono'
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type { JSX } from 'react'
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Center,
|
Center,
|
||||||
@@ -15,7 +16,7 @@ export default function Hero(): JSX.Element {
|
|||||||
return (
|
return (
|
||||||
<Container size={1100} my={100}>
|
<Container size={1100} my={100}>
|
||||||
<Center>
|
<Center>
|
||||||
<Title order={1}>The React/Rust full-stack framework</Title>
|
<Title order={1}>Superfast fullstack react framework</Title>
|
||||||
</Center>
|
</Center>
|
||||||
<Center mt={50}>
|
<Center mt={50}>
|
||||||
<Text fz="18px">
|
<Text fz="18px">
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type { JSX } from 'react'
|
||||||
import { Text, type TextProps } from '@mantine/core'
|
import { Text, type TextProps } from '@mantine/core'
|
||||||
|
|
||||||
export default function MdxBold(props: TextProps): JSX.Element {
|
export default function MdxBold(props: TextProps): JSX.Element {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type { JSX } from 'react'
|
||||||
import { Code } from '@mantine/core'
|
import { Code } from '@mantine/core'
|
||||||
import type { HTMLAttributes } from 'react'
|
import type { HTMLAttributes } from 'react'
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { AnchorHTMLAttributes } from 'react'
|
import type { JSX, AnchorHTMLAttributes } from 'react'
|
||||||
import { Button } from '@mantine/core'
|
import { Button } from '@mantine/core'
|
||||||
import { Link } from 'tuono'
|
import { Link } from 'tuono'
|
||||||
import { IconExternalLink } from '@tabler/icons-react'
|
import { IconExternalLink } from '@tabler/icons-react'
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type { JSX } from 'react'
|
||||||
import { CodeHighlight } from '@mantine/code-highlight'
|
import { CodeHighlight } from '@mantine/code-highlight'
|
||||||
import styles from './mdx-pre.module.css'
|
import styles from './mdx-pre.module.css'
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type { JSX } from 'react'
|
||||||
import { MDXProvider } from '@mdx-js/react'
|
import { MDXProvider } from '@mdx-js/react'
|
||||||
|
|
||||||
import MdxLink from './mdx-link'
|
import MdxLink from './mdx-link'
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
import type { JSX, HTMLAttributes } from 'react'
|
||||||
import { Blockquote, Space } from '@mantine/core'
|
import { Blockquote, Space } from '@mantine/core'
|
||||||
import type { HTMLAttributes } from 'react'
|
|
||||||
|
|
||||||
export default function MdxQuote(
|
export default function MdxQuote(
|
||||||
props: HTMLAttributes<HTMLQuoteElement>,
|
props: HTMLAttributes<HTMLQuoteElement>,
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type { JSX } from 'react'
|
||||||
import { Title, type TitleProps } from '@mantine/core'
|
import { Title, type TitleProps } from '@mantine/core'
|
||||||
|
|
||||||
export default function MdxTitle(props: TitleProps): JSX.Element {
|
export default function MdxTitle(props: TitleProps): JSX.Element {
|
||||||
|
|||||||
@@ -36,6 +36,11 @@ export default function MetaTags({
|
|||||||
<meta property="og:description" content={description} />
|
<meta property="og:description" content={description} />
|
||||||
<meta property="og:site_name" content="Tuono" />
|
<meta property="og:site_name" content="Tuono" />
|
||||||
<meta property="og:locale" content="en_US" />
|
<meta property="og:locale" content="en_US" />
|
||||||
|
<meta name="twitter:card" content="summary_large_image" />
|
||||||
|
<meta name="twitter:site" content="@tuono_dev" />
|
||||||
|
<meta name="twitter:title" content={title} />
|
||||||
|
<meta name="twitter:description" content={description} />
|
||||||
|
<meta name="twitter:image" content="https://tuono.dev/og-cover.png" />
|
||||||
</Head>
|
</Head>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,22 @@
|
|||||||
|
import type { JSX } from 'react'
|
||||||
import { Flex, Button, ActionIcon, Group } from '@mantine/core'
|
import { Flex, Button, ActionIcon, Group } from '@mantine/core'
|
||||||
import { IconBrandGithub, IconBook, IconBrandX } from '@tabler/icons-react'
|
import {
|
||||||
import ThemeBtn from '../theme-btn'
|
IconBrandGithub,
|
||||||
|
IconBook,
|
||||||
|
IconBrandDiscord,
|
||||||
|
} from '@tabler/icons-react'
|
||||||
import { Link } from 'tuono'
|
import { Link } from 'tuono'
|
||||||
|
|
||||||
|
import ThemeBtn from '../theme-btn'
|
||||||
|
|
||||||
export default function Actions(): JSX.Element {
|
export default function Actions(): JSX.Element {
|
||||||
return (
|
return (
|
||||||
<Flex gap={8}>
|
<Flex gap={8}>
|
||||||
<Group gap={8} visibleFrom="sm">
|
<Group gap={8}>
|
||||||
<Button
|
<Button
|
||||||
href="/documentation"
|
|
||||||
component={Link}
|
component={Link}
|
||||||
|
href="/documentation"
|
||||||
|
visibleFrom="sm"
|
||||||
size="compact-lg"
|
size="compact-lg"
|
||||||
rightSection={<IconBook />}
|
rightSection={<IconBook />}
|
||||||
autoContrast
|
autoContrast
|
||||||
@@ -29,12 +36,12 @@ export default function Actions(): JSX.Element {
|
|||||||
<ActionIcon
|
<ActionIcon
|
||||||
variant="default"
|
variant="default"
|
||||||
size="lg"
|
size="lg"
|
||||||
aria-label="We are also on X!"
|
aria-label="Join the Tuono's community on Discord!"
|
||||||
href="https://x.com/tuono_dev"
|
href="https://discord.com/invite/khQzPa654B"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
component="a"
|
component="a"
|
||||||
>
|
>
|
||||||
<IconBrandX />
|
<IconBrandDiscord />
|
||||||
</ActionIcon>
|
</ActionIcon>
|
||||||
</Group>
|
</Group>
|
||||||
<ThemeBtn />
|
<ThemeBtn />
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
import type { JSX } from 'react'
|
||||||
import { AppShell, Burger, Button, Flex } from '@mantine/core'
|
import { AppShell, Burger, Button, Flex } from '@mantine/core'
|
||||||
import { Link, useRouter } from 'tuono'
|
import { Link, useRouter } from 'tuono'
|
||||||
|
|
||||||
import Actions from './actions'
|
import Actions from './actions'
|
||||||
|
|
||||||
interface NavbarProps {
|
interface NavbarProps {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type { JSX } from 'react'
|
||||||
import { Box, Button, Text, Title, Flex } from '@mantine/core'
|
import { Box, Button, Text, Title, Flex } from '@mantine/core'
|
||||||
import { Link } from 'tuono'
|
import { Link } from 'tuono'
|
||||||
import { IconArrowRight, IconArrowLeft } from '@tabler/icons-react'
|
import { IconArrowRight, IconArrowLeft } from '@tabler/icons-react'
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
import type { JSX, ReactNode } from 'react'
|
||||||
|
import { useState } from 'react'
|
||||||
import { NavLink, type NavLinkProps } from '@mantine/core'
|
import { NavLink, type NavLinkProps } from '@mantine/core'
|
||||||
import { useState, type ReactNode } from 'react'
|
|
||||||
import { Link, useRouter } from 'tuono'
|
import { Link, useRouter } from 'tuono'
|
||||||
import { IconChevronRight } from '@tabler/icons-react'
|
import { IconChevronRight } from '@tabler/icons-react'
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,20 @@
|
|||||||
|
import type { JSX } from 'react'
|
||||||
import { AppShell } from '@mantine/core'
|
import { AppShell } from '@mantine/core'
|
||||||
|
|
||||||
import SidebarLink from './sidebar-link'
|
import SidebarLink from './sidebar-link'
|
||||||
|
|
||||||
export default function Sidebar({ close }: { close: () => void }): JSX.Element {
|
interface SidebarProps {
|
||||||
|
close: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Sidebar({ close }: SidebarProps): JSX.Element {
|
||||||
return (
|
return (
|
||||||
<AppShell.Navbar p="md">
|
<AppShell.Navbar p="md">
|
||||||
<SidebarLink href="/documentation" label="Overview" onClick={close} />
|
<SidebarLink
|
||||||
|
href="/documentation"
|
||||||
|
label="Getting started"
|
||||||
|
onClick={close}
|
||||||
|
/>
|
||||||
<SidebarLink
|
<SidebarLink
|
||||||
href="/documentation/installation"
|
href="/documentation/installation"
|
||||||
label="Installation"
|
label="Installation"
|
||||||
@@ -63,6 +73,12 @@ export default function Sidebar({ close }: { close: () => void }): JSX.Element {
|
|||||||
/>
|
/>
|
||||||
</SidebarLink>
|
</SidebarLink>
|
||||||
<SidebarLink href="/documentation/cli" label="CLI" onClick={close} />
|
<SidebarLink href="/documentation/cli" label="CLI" onClick={close} />
|
||||||
|
<SidebarLink
|
||||||
|
label="Application state"
|
||||||
|
href="/documentation/application-state"
|
||||||
|
onClick={close}
|
||||||
|
/>
|
||||||
|
|
||||||
<SidebarLink
|
<SidebarLink
|
||||||
label="Routing"
|
label="Routing"
|
||||||
href="/documentation/routing"
|
href="/documentation/routing"
|
||||||
@@ -74,12 +90,19 @@ export default function Sidebar({ close }: { close: () => void }): JSX.Element {
|
|||||||
onClick={close}
|
onClick={close}
|
||||||
/>
|
/>
|
||||||
</SidebarLink>
|
</SidebarLink>
|
||||||
|
|
||||||
<SidebarLink
|
<SidebarLink
|
||||||
label="Contributing"
|
label="Contributing"
|
||||||
href="/documentation/contributing"
|
href="/documentation/contributing"
|
||||||
onClick={close}
|
|
||||||
leftSection="✨"
|
leftSection="✨"
|
||||||
|
onClick={close}
|
||||||
|
>
|
||||||
|
<SidebarLink
|
||||||
|
href="/documentation/contributing/local-development"
|
||||||
|
label="Local development"
|
||||||
|
onClick={close}
|
||||||
/>
|
/>
|
||||||
|
</SidebarLink>
|
||||||
</AppShell.Navbar>
|
</AppShell.Navbar>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Component inspired by: https://github.com/mantinedev/mantine/tree/master/apps/mantine.dev/src/components/TableOfContents
|
* Component inspired by: https://github.com/mantinedev/mantine/tree/master/apps/mantine.dev/src/components/TableOfContents
|
||||||
*/
|
*/
|
||||||
|
import type { JSX } from 'react'
|
||||||
import { useEffect, useRef, useState } from 'react'
|
import { useEffect, useRef, useState } from 'react'
|
||||||
import { useRouter, Link } from 'tuono'
|
import { useRouter, Link } from 'tuono'
|
||||||
import { IconList } from '@tabler/icons-react'
|
import { IconList } from '@tabler/icons-react'
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type { JSX } from 'react'
|
||||||
import {
|
import {
|
||||||
ActionIcon,
|
ActionIcon,
|
||||||
useMantineColorScheme,
|
useMantineColorScheme,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { ReactNode } from 'react'
|
import type { ReactNode, JSX } from 'react'
|
||||||
import {
|
import {
|
||||||
ColorSchemeScript,
|
ColorSchemeScript,
|
||||||
createTheme,
|
createTheme,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { ReactNode } from 'react'
|
import type { ReactNode, JSX } from 'react'
|
||||||
import { AppShell, Container } from '@mantine/core'
|
import { AppShell, Container } from '@mantine/core'
|
||||||
|
|
||||||
import MdxProvider from '../../components/mdx-provider'
|
import MdxProvider from '../../components/mdx-provider'
|
||||||
import EditPage from '../../components/edit-page'
|
import EditPage from '../../components/edit-page'
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
import MetaTags from '../../components/meta-tags'
|
||||||
|
|
||||||
|
<MetaTags
|
||||||
|
title="Tuono - Application state"
|
||||||
|
canonical="https://tuono.dev/documentation/application-state"
|
||||||
|
description="Learn how to add features to your Tuono application"
|
||||||
|
/>
|
||||||
|
|
||||||
|
import Breadcrumbs, { Element } from '../../components/breadcrumbs'
|
||||||
|
|
||||||
|
<Breadcrumbs breadcrumbs={[{ label: 'Application state' }]} />
|
||||||
|
|
||||||
|
# Application state
|
||||||
|
|
||||||
|
The main reason Tuono is fast is that it loads just the features that are needed for the project.
|
||||||
|
|
||||||
|
To define them, you need to fill the `ApplicationState` struct in the `./src/app.rs` file, and
|
||||||
|
they will be automatically available in all the handlers you will define across the application.
|
||||||
|
|
||||||
|
```rs
|
||||||
|
// src/app.rs
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct ApplicationState {
|
||||||
|
pub website_name: String,
|
||||||
|
pub base_path: String
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn main() -> ApplicationState {
|
||||||
|
let website_name = "tuono".to_string();
|
||||||
|
let base_path = "http://localhost:3000".to_string();
|
||||||
|
|
||||||
|
ApplicationState {
|
||||||
|
website_name,
|
||||||
|
base_path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
> For the sake of simplicity here we just enable a `String` but you can add Database connections or
|
||||||
|
> HTTP clients (take a look [here](/documentation/tutorial/api-fetching) for an example with an HTTP client).
|
||||||
|
|
||||||
|
Now the `ApplicationState` is available on all the handlers as following:
|
||||||
|
|
||||||
|
```rs
|
||||||
|
// src/routes/index.rs
|
||||||
|
|
||||||
|
#[tuono_lib::handler]
|
||||||
|
// The first argument always is the Request
|
||||||
|
// The ApplicationState arguments are optional. You can use just the ones you need
|
||||||
|
// to use in the handler (with no specific order).
|
||||||
|
async fn my_handler(req: Request, website_name: String) -> Response {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
import MetaTags from '../../../components/meta-tags'
|
||||||
|
|
||||||
|
<MetaTags
|
||||||
|
title="Tuono - Contributing"
|
||||||
|
canonical="https://tuono.dev/documentation/contributing"
|
||||||
|
description="The project is massive - if you like it, do consider contributing!"
|
||||||
|
/>
|
||||||
|
|
||||||
|
import Breadcrumbs, { Element } from '../../../components/breadcrumbs'
|
||||||
|
|
||||||
|
<Breadcrumbs breadcrumbs={[{ label: '✨ Contributing' }]} />
|
||||||
|
|
||||||
|
# Contributing
|
||||||
|
|
||||||
|
## TL;DR
|
||||||
|
|
||||||
|
The project is massive - if you like it, do consider contributing!
|
||||||
|
|
||||||
|
## Getting started
|
||||||
|
|
||||||
|
The `tuono` project can mostly be split into the following subdomains:
|
||||||
|
|
||||||
|
- The CLI
|
||||||
|
- The Rust backend
|
||||||
|
- The React frontend
|
||||||
|
- The documentation website (which is written with tuono 🚀)
|
||||||
|
|
||||||
|
To check what the knowledge requirements are for each domain, check the
|
||||||
|
[requirements](#requirements) section below.
|
||||||
|
|
||||||
|
Currently, I'm keeping a private dashboard to prioritize new features and bug fixes, but if you
|
||||||
|
want to propose something, please open a new issue on GitHub or reach out to me using
|
||||||
|
my email address [valerioageno@yahoo.it](mailto:valerioageno@yahoo.it). I'm also available
|
||||||
|
on Twitter (X) DMs `@valerioageno`, [Linkedin](https://www.linkedin.com/in/valerioageno)
|
||||||
|
and discord `@__v__v__`.
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
It's not strictly required to know both React (& typescript) and Rust (even though it
|
||||||
|
would be a great nice to have).
|
||||||
|
|
||||||
|
Without taking into account specific cases, we can mostly split the domain requirements by:
|
||||||
|
|
||||||
|
- The `CLI` needs Rust knowledge (even though a couple of scenarios might also need Typescript)
|
||||||
|
- The Backend needs just `Rust`
|
||||||
|
- The Frontend needs just `React` & `Typescript`
|
||||||
|
- The documentation website needs just `React` & `Typescript` (or even less, since most of the
|
||||||
|
code is markdown).
|
||||||
|
|
||||||
|
import NavigationButtons from '../../../components/navigation-buttons'
|
||||||
|
|
||||||
|
<NavigationButtons
|
||||||
|
next={{
|
||||||
|
title: 'Local development',
|
||||||
|
href: '/documentation/contributing/local-development',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
import MetaTags from '../../../components/meta-tags'
|
||||||
|
|
||||||
|
<MetaTags
|
||||||
|
title="Tuono - Contributing - Local development"
|
||||||
|
canonical="https://tuono.dev/documentation/contributing/local-development"
|
||||||
|
description="Contribute to Tuono. Learn here how to setup the repository for local development"
|
||||||
|
/>
|
||||||
|
|
||||||
|
import Breadcrumbs, { Element } from '../../../components/breadcrumbs'
|
||||||
|
|
||||||
|
<Breadcrumbs
|
||||||
|
breadcrumbs={[
|
||||||
|
{ label: '✨ Contributing', href: '/documentation/contributing' },
|
||||||
|
{ label: 'Local development' },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
|
||||||
|
# Local development
|
||||||
|
|
||||||
|
Thanks for your interest! In this page, you find the instructions to set up `tuono` on your local environment!
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
### Fork and clone repository
|
||||||
|
|
||||||
|
After [forking the repo on GitHub](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo):
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git clone https://github.com/<your-name-here>/tuono
|
||||||
|
cd tuono
|
||||||
|
```
|
||||||
|
|
||||||
|
### Rust tool chain
|
||||||
|
|
||||||
|
Install the Rust programming language tool chain (`rust` and `cargo`).
|
||||||
|
Follows instructions in the official [docs](https://rustup.rs/)
|
||||||
|
|
||||||
|
### Node.js — runtime
|
||||||
|
|
||||||
|
Install `Node.js`.
|
||||||
|
You can follow the instructions from the [Node official site](https://nodejs.org/en/download/package-manager)
|
||||||
|
|
||||||
|
> 💡 This project has a `.nvmrc` file to specify the node version used in development.
|
||||||
|
>
|
||||||
|
> Consider to use [nvm](https://github.com/nvm-sh/nvm) so you can run
|
||||||
|
>
|
||||||
|
> ```sh
|
||||||
|
> nvm use
|
||||||
|
> ```
|
||||||
|
>
|
||||||
|
> to simply pick up the correct version!
|
||||||
|
|
||||||
|
### Node.js — package manager
|
||||||
|
|
||||||
|
We use [`pnpm`](https://pnpm.io) as Node.js package manager.
|
||||||
|
|
||||||
|
You can see which version of yarn we use by checking the `packageManager` field in the root `package.json`.
|
||||||
|
|
||||||
|
### Pre-flight checks
|
||||||
|
|
||||||
|
To check that everything is working properly, run:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
turbo run check-all
|
||||||
|
cargo build
|
||||||
|
```
|
||||||
|
|
||||||
|
## Tuono development
|
||||||
|
|
||||||
|
1. Start tuono frontend build using
|
||||||
|
|
||||||
|
```sh
|
||||||
|
turbo run dev
|
||||||
|
```
|
||||||
|
|
||||||
|
2. In another terminal run
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cargo build
|
||||||
|
```
|
||||||
|
|
||||||
|
To automatically rebuild crates on code change, consider using `cargo-watch` crate
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cargo watch -x build -w crates/
|
||||||
|
```
|
||||||
|
|
||||||
|
3. You can now use the binary inside `/target/debug/tuono` in another folder on your local machine
|
||||||
|
|
||||||
|
> Consider adding an alias to your shell setup file
|
||||||
|
>
|
||||||
|
> ```sh
|
||||||
|
> alias t="/path-to-repo/target/debug/tuono"
|
||||||
|
> ```
|
||||||
|
|
||||||
|
## Documentation development
|
||||||
|
|
||||||
|
1. Change the current working directory to the documentation folder:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cd apps/documentation
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Run
|
||||||
|
|
||||||
|
```sh
|
||||||
|
tuono dev
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Open the localhost URL.
|
||||||
|
|
||||||
|
> On the documentation remember that `tuono` `npm` package is installed from the registry and
|
||||||
|
> it is not linked to the repository.
|
||||||
@@ -12,39 +12,43 @@ import Breadcrumbs from '../../components/breadcrumbs'
|
|||||||
|
|
||||||
# Tuono
|
# Tuono
|
||||||
|
|
||||||
Tuono is a full-stack framework for building React applications using Rust as the
|
Tuono is a full-stack web framework for building React applications using Rust as the
|
||||||
backend.
|
backend with a strong focus on usability and performance.
|
||||||
|
|
||||||
Tuono (Italian word for "thunder", pronounced /2 Oh No/). Why Tuono? Just a badass name.
|
Tuono (Italian word for "thunder", pronounced /2 Oh No/). Why Tuono? Just a badass name.
|
||||||
|
|
||||||
## Introduction
|
If you have experience with [Next.js](https://nextjs.org/) you will feel home here.
|
||||||
|
|
||||||
NodeJs/Deno/Bun are the only runtimes that allow a React app to be full-stack right? (no)
|
|
||||||
|
|
||||||
Tuono is a full-stack React framework with the server side written in Rust.
|
|
||||||
Because of this, Tuono is extremely fast and, the requests are handled by a multithreaded Rust server.
|
|
||||||
React is still React - it is just superpowered.
|
|
||||||
|
|
||||||
Rust is a hard language, then writing server side code is hard as well, right? (no again)
|
|
||||||
|
|
||||||
Tuono provides a collection of utilities to handle the server side code seamlessly with
|
|
||||||
the React code. Each server side route is managed in a separate file alongside the React route.
|
|
||||||
The routing is handled by Tuono based on the files defined within the `./src/routes` directory.
|
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
Some of its features include:
|
- 🟦 Native Typescript
|
||||||
|
- 🌐 Next.js like Routing
|
||||||
- 🟦 Full typescript support
|
- 🍭 CSS/SCSS modules
|
||||||
- 🌐 File system based routing
|
|
||||||
- 🔥 Hot Module Reload
|
|
||||||
- 🍭 SCSS/CSS modules
|
|
||||||
- 🧬 Server Side Rendering
|
- 🧬 Server Side Rendering
|
||||||
- 🧵 Multi-threaded backend
|
- 🔥 Hot Module Reload
|
||||||
- ⌨️ MDX support
|
|
||||||
- ⚙️ Build optimizations
|
|
||||||
- Custom APIs\*
|
|
||||||
- Image optimization\*
|
|
||||||
- Server streamed content\*
|
|
||||||
|
|
||||||
> \*development in progress
|
## Introduction
|
||||||
|
|
||||||
|
Tuono addresses the following two limits:
|
||||||
|
|
||||||
|
- Enable React server-side rendering projects without using JS runtimes (Node, Deno)
|
||||||
|
- Ease the web development using a typically hard language like Rust.
|
||||||
|
|
||||||
|
#### NodeJs/Deno/Bun are the only runtimes that allow a React app to be server-side rendered (SSR)? (no)
|
||||||
|
|
||||||
|
Tuono is the first full-stack React framework with the server side written in Rust (check the [ssr-rs](https://github.com/Valerioageno/ssr-rs) crate).
|
||||||
|
Because of this, Tuono is extremely fast, and the requests are handled by a multithreaded Rust server.
|
||||||
|
React is still React - it is just superpowered.
|
||||||
|
|
||||||
|
#### Rust is a hard language, then writing server side code is hard as well, right? (no again)
|
||||||
|
|
||||||
|
Tuono provides a collection of utilities to handle server-side code seamlessly with
|
||||||
|
the React code. Each server side route is managed in a separate file alongside the React route.
|
||||||
|
The routing is handled by Tuono based on the files defined within the `./src/routes` directory.
|
||||||
|
|
||||||
|
#### How is Tuono different from Next.js?
|
||||||
|
|
||||||
|
The Tuono API tries to stick as much as possible to the Next.js one (or at least takes a huge inspiration
|
||||||
|
from it). The major difference is the backend system. While Next.js relies entirely on Node/Deno/Bun,
|
||||||
|
Tuono runs the server without any intermediary runtime. This enables impressive performance improvements
|
||||||
|
(check the benchmarks [here](https://github.com/Valerioageno/tuono/tree/main/benches)).
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ Clear the `index.rs` file and paste:
|
|||||||
```rust
|
```rust
|
||||||
// src/routes/index.rs
|
// src/routes/index.rs
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use tuono_lib::reqwest::Client;
|
use reqwest::Client;
|
||||||
use tuono_lib::{Props, Request, Response};
|
use tuono_lib::{Props, Request, Response};
|
||||||
|
|
||||||
const ALL_POKEMON: &str = "https://pokeapi.co/api/v2/pokemon?limit=151";
|
const ALL_POKEMON: &str = "https://pokeapi.co/api/v2/pokemon?limit=151";
|
||||||
@@ -56,10 +56,80 @@ async fn get_all_pokemons(_req: Request, fetch: Client) -> Response {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> The first argument is always the request `req: Request` which contains all the request's data like the query parameters and the HTTP headers.
|
||||||
|
> The rest of the arguments represents the [ApplicationState](/documentation/application-state) and are optional.
|
||||||
|
|
||||||
|
The terminal will complain now for two reasons:
|
||||||
|
|
||||||
|
1. We don't have imported any `reqwest` crate
|
||||||
|
2. The second argument `fetch: Client` has not been defined yet as global state.
|
||||||
|
|
||||||
|
Let's fix these in the next section.
|
||||||
|
|
||||||
|
## Application state
|
||||||
|
|
||||||
|
Compared to the common Javascript runtimes, Tuono is fast because only the features you need for your project will be loaded.
|
||||||
|
|
||||||
|
You can load them in the `ApplicationState` of your app inside the `./src/app.rs` file. This is the file that will be executed just once at the very beginning of your application.
|
||||||
|
|
||||||
|
> For the tutorial we will use [Reqwest](https://docs.rs/reqwest/latest/reqwest/) which is one of the most famous HTTP library.
|
||||||
|
|
||||||
|
To install it just run in your terminal:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo add reqwest
|
||||||
|
```
|
||||||
|
|
||||||
|
A new entry has just been added to your `Cargo.toml` file.
|
||||||
|
|
||||||
|
```diff
|
||||||
|
[package]
|
||||||
|
name = "tuono"
|
||||||
|
version = "0.0.1"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "tuono"
|
||||||
|
path = ".tuono/main.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
tuono_lib = "0.14.0" # the version might be different
|
||||||
|
serde = { version = "1.0.202", features = ["derive"] }
|
||||||
|
++ reqwest = "0.12.9" # the version might be different
|
||||||
|
```
|
||||||
|
|
||||||
|
> The `Cargo.toml` is the manifest file of your application, in which you handle Rust's dependencies
|
||||||
|
> (similarly as the package.json for Javascript).
|
||||||
|
|
||||||
|
Now let's define the `ApplicationState` in the `./src/app.rs` file.
|
||||||
|
|
||||||
|
```rs
|
||||||
|
// Import here the just added reqwest library
|
||||||
|
use reqwest::Client;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
// Extend this struct with the feature you will need for your application
|
||||||
|
pub struct ApplicationState {
|
||||||
|
// This will be available to all your route handlers
|
||||||
|
pub fetch: Client,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn main() -> ApplicationState {
|
||||||
|
let fetch = Client::new();
|
||||||
|
return ApplicationState { fetch };
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Now the `fetch: Client` argument is available in the above defined handler, and the terminal should not complain anymore.
|
||||||
|
Let's see in the next section how to show the fetched data on the browser.
|
||||||
|
|
||||||
|
## Handling the page UI
|
||||||
|
|
||||||
Now the Pokémon are correctly fetched and hydrated on the client side, so we can actually use them. Clear the `index.tsx` file and paste:
|
Now the Pokémon are correctly fetched and hydrated on the client side, so we can actually use them. Clear the `index.tsx` file and paste:
|
||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
// src/routes/index.tsx
|
// src/routes/index.tsx
|
||||||
|
import type { JSX } from 'react'
|
||||||
import type { TuonoProps } from 'tuono'
|
import type { TuonoProps } from 'tuono'
|
||||||
|
|
||||||
interface Pokemon {
|
interface Pokemon {
|
||||||
@@ -72,9 +142,9 @@ interface IndexProps {
|
|||||||
|
|
||||||
export default function IndexPage({
|
export default function IndexPage({
|
||||||
data,
|
data,
|
||||||
}: TuonoProps<IndexProps>): JSX.Element {
|
}: TuonoProps<IndexProps>): JSX.Element | null {
|
||||||
if (!data?.results) {
|
if (!data?.results) {
|
||||||
return <></>
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ Create the following file `src/components/PokemonLink.tsx` and fill the content
|
|||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
// src/components/PokemonLink.tsx
|
// src/components/PokemonLink.tsx
|
||||||
|
import type { JSX } from 'react'
|
||||||
import { Link } from 'tuono'
|
import { Link } from 'tuono'
|
||||||
|
|
||||||
interface Pokemon {
|
interface Pokemon {
|
||||||
@@ -109,8 +110,9 @@ Then import the styles into the `PokemonLink` component as following:
|
|||||||
|
|
||||||
```diff
|
```diff
|
||||||
// src/components/PokemonLink.tsx
|
// src/components/PokemonLink.tsx
|
||||||
import { Link } from "tuono";
|
import type { JSX } from 'react'
|
||||||
import type { Pokemon } from "./../types/pokemon";
|
import { Link } from "tuono"
|
||||||
|
import type { Pokemon } from "./../types/pokemon"
|
||||||
++ import styles from './PokemonLink.module.css'
|
++ import styles from './PokemonLink.module.css'
|
||||||
|
|
||||||
export default function PokemonLink({
|
export default function PokemonLink({
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import Breadcrumbs, { Element } from '../../../components/breadcrumbs'
|
|||||||
|
|
||||||
The homepage is ready. We have the full list of Pokémon and they are all links. Great!
|
The homepage is ready. We have the full list of Pokémon and they are all links. Great!
|
||||||
|
|
||||||
Now we want to make those links actually point to a real page. Let’s create the \_\_ route.
|
Now we want to make those links actually point to a real page. Let’s create the dynamic route.
|
||||||
|
|
||||||
Create the folder `routes/pokemons` and then create the two files `[pokemon].tsx` and `[pokemon].rs`.
|
Create the folder `routes/pokemons` and then create the two files `[pokemon].tsx` and `[pokemon].rs`.
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ Let’s first work on the server side file. Paste into the new `[pokemon].rs` fi
|
|||||||
```rust
|
```rust
|
||||||
// src/routes/pokemons/[pokemon].rs
|
// src/routes/pokemons/[pokemon].rs
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use tuono_lib::reqwest::Client;
|
use reqwest::Client;
|
||||||
use tuono_lib::{Props, Request, Response};
|
use tuono_lib::{Props, Request, Response};
|
||||||
|
|
||||||
const POKEMON_API: &str = "https://pokeapi.co/api/v2/pokemon";
|
const POKEMON_API: &str = "https://pokeapi.co/api/v2/pokemon";
|
||||||
@@ -63,6 +63,7 @@ async fn get_pokemon(req: Request, fetch: Client) -> Response {
|
|||||||
Then let’s work on the frontend. Paste into the `[pokemon].tsx` file the following code:
|
Then let’s work on the frontend. Paste into the `[pokemon].tsx` file the following code:
|
||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
|
import type { JSX } from 'react'
|
||||||
import { TuonoProps } from 'tuono'
|
import { TuonoProps } from 'tuono'
|
||||||
import PokemonView from '../../components/PokemonView'
|
import PokemonView from '../../components/PokemonView'
|
||||||
|
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ Let's see how it works!
|
|||||||
```diff
|
```diff
|
||||||
// src/routes/pokemons/[pokemon].rs
|
// src/routes/pokemons/[pokemon].rs
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
-- use tuono_lib::reqwest::Client;
|
-- use reqwest::Client;
|
||||||
++ use tuono_lib::reqwest::{Client, StatusCode};
|
++ use reqwest::{Client, StatusCode};
|
||||||
use tuono_lib::{Props, Request, Response};
|
use tuono_lib::{Props, Request, Response};
|
||||||
|
|
||||||
const POKEMON_API: &str = "https://pokeapi.co/api/v2/pokemon";
|
const POKEMON_API: &str = "https://pokeapi.co/api/v2/pokemon";
|
||||||
@@ -69,8 +69,8 @@ async fn get_pokemon(req: Request, fetch: Client) -> Response {
|
|||||||
```diff
|
```diff
|
||||||
// src/routes/index.rs
|
// src/routes/index.rs
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
-- use tuono_lib::reqwest::Client;
|
-- use reqwest::Client;
|
||||||
++ use tuono_lib::reqwest::{Client, StatusCode};
|
++ use reqwest::{Client, StatusCode};
|
||||||
use tuono_lib::{Props, Request, Response};
|
use tuono_lib::{Props, Request, Response};
|
||||||
|
|
||||||
const ALL_POKEMON: &str = "https://pokeapi.co/api/v2/pokemon?limit=151";
|
const ALL_POKEMON: &str = "https://pokeapi.co/api/v2/pokemon?limit=151";
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ This tutorial is not meant for people who don't know React - in that case, I sug
|
|||||||
If you prefer to just read the code rather than write you can download the finished tutorial project with:
|
If you prefer to just read the code rather than write you can download the finished tutorial project with:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ tuono new tutorial --template tutorial
|
$ tuono new tutorial --template tuono-tutorial
|
||||||
```
|
```
|
||||||
|
|
||||||
> I'd love to hear your thoughts about the framework and the tutorial - feel free to reach me at [valerioageno@yahoo.it](mailto:valerioageno@ahoo.it)
|
> I'd love to hear your thoughts about the framework and the tutorial - feel free to reach me at [valerioageno@yahoo.it](mailto:valerioageno@ahoo.it)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import MetaTags from '../../../components/meta-tags'
|
|||||||
|
|
||||||
<MetaTags
|
<MetaTags
|
||||||
title="Tuono - Redirection"
|
title="Tuono - Redirection"
|
||||||
canonical="https://tuono.dev/documentation/tutorial/redirection"
|
canonical="https://tuono.dev/documentation/tutorial/redirections"
|
||||||
description="Learn how to redirect to different route from the server"
|
description="Learn how to redirect to different route from the server"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@@ -25,10 +25,10 @@ First, let's create a new route by just creating a new file `/pokemons/GOAT.rs`
|
|||||||
|
|
||||||
```rs
|
```rs
|
||||||
// src/routes/pokemons/GOAT.rs
|
// src/routes/pokemons/GOAT.rs
|
||||||
use tuono_lib::{reqwest::Client, Request, Response};
|
use tuono_lib::{Request, Response};
|
||||||
|
|
||||||
#[tuono_lib::handler]
|
#[tuono_lib::handler]
|
||||||
async fn redirect_to_goat(_: Request, _: Client) -> Response {
|
async fn redirect_to_goat(_req: Request) -> Response {
|
||||||
// Of course the GOAT is mewtwo - feel free to select your favourite 😉
|
// Of course the GOAT is mewtwo - feel free to select your favourite 😉
|
||||||
Response::Redirect("/pokemons/mewtwo".to_string())
|
Response::Redirect("/pokemons/mewtwo".to_string())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import MetaTags from '../../../components/meta-tags'
|
|||||||
|
|
||||||
<MetaTags
|
<MetaTags
|
||||||
title="Tuono - SEO and meta tags"
|
title="Tuono - SEO and meta tags"
|
||||||
canonical="https://tuono.dev/documentation/tutorial/eeo"
|
canonical="https://tuono.dev/documentation/tutorial/seo"
|
||||||
description="Learn how to handle meaningful meta tags for your Tuono project"
|
description="Learn how to handle meaningful meta tags for your Tuono project"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@@ -26,6 +26,7 @@ To do so `tuono` also exposes the `<Head />` component useful exactly for handli
|
|||||||
|
|
||||||
```diff
|
```diff
|
||||||
// src/routes/index.tsx
|
// src/routes/index.tsx
|
||||||
|
import type { JSX } from 'react'
|
||||||
import type { TuonoProps } from "tuono";
|
import type { TuonoProps } from "tuono";
|
||||||
++ import { Head } from "tuono"
|
++ import { Head } from "tuono"
|
||||||
|
|
||||||
@@ -80,6 +81,7 @@ export default function IndexPage({
|
|||||||
|
|
||||||
```diff
|
```diff
|
||||||
// src/routes/pokemons/[pokemon].tsx
|
// src/routes/pokemons/[pokemon].tsx
|
||||||
|
import type { JSX } from 'react'
|
||||||
-- import { TuonoProps } from "tuono";
|
-- import { TuonoProps } from "tuono";
|
||||||
++ import { TuonoProps, Head } from "tuono";
|
++ import { TuonoProps, Head } from "tuono";
|
||||||
import PokemonView from "../../components/PokemonView";
|
import PokemonView from "../../components/PokemonView";
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import type { JSX } from 'react'
|
||||||
|
|
||||||
import Hero from '../components/hero'
|
import Hero from '../components/hero'
|
||||||
import MetaTags from '../components/meta-tags'
|
import MetaTags from '../components/meta-tags'
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use tuono_lib::reqwest::{Client, StatusCode};
|
use tuono_lib::reqwest::StatusCode;
|
||||||
use tuono_lib::{Request, Response};
|
use tuono_lib::{Request, Response};
|
||||||
use tuono_lib::axum::http::{header, HeaderMap};
|
use tuono_lib::axum::http::{header, HeaderMap};
|
||||||
use glob::glob;
|
use glob::glob;
|
||||||
@@ -36,7 +36,7 @@ fn clean_path(value: String) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tuono_lib::handler]
|
#[tuono_lib::handler]
|
||||||
async fn generate_sitemap(_req: Request, _fetch: Client) -> Response {
|
async fn generate_sitemap(_req: Request) -> Response {
|
||||||
let mut headers = HeaderMap::new();
|
let mut headers = HeaderMap::new();
|
||||||
headers.insert(header::CONTENT_TYPE, "text/xml".parse().unwrap());
|
headers.insert(header::CONTENT_TYPE, "text/xml".parse().unwrap());
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "tuono"
|
name = "tuono"
|
||||||
version = "0.11.2"
|
version = "0.14.3"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["V. Ageno <valerioageno@yahoo.it>"]
|
authors = ["V. Ageno <valerioageno@yahoo.it>"]
|
||||||
description = "The react/rust fullstack framework"
|
description = "Superfast React fullstack framework"
|
||||||
|
homepage = "https://tuono.dev"
|
||||||
keywords = [ "react", "typescript", "fullstack", "web", "ssr"]
|
keywords = [ "react", "typescript", "fullstack", "web", "ssr"]
|
||||||
repository = "https://github.com/Valerioageno/tuono"
|
repository = "https://github.com/Valerioageno/tuono"
|
||||||
readme = "../../README.md"
|
readme = "../../README.md"
|
||||||
@@ -20,9 +21,9 @@ path = "src/lib.rs"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "4.5.4", features = ["derive", "cargo"] }
|
clap = { version = "4.5.4", features = ["derive", "cargo"] }
|
||||||
watchexec = "4.0.0"
|
watchexec = "5.0.0"
|
||||||
miette = "7.2.0"
|
miette = "7.2.0"
|
||||||
watchexec-signals = "3.0.0"
|
watchexec-signals = "4.0.0"
|
||||||
tokio = { version = "1", features = ["full"] }
|
tokio = { version = "1", features = ["full"] }
|
||||||
serde = { version = "1.0.202", features = ["derive"] }
|
serde = { version = "1.0.202", features = ["derive"] }
|
||||||
watchexec-supervisor = "3.0.0"
|
watchexec-supervisor = "3.0.0"
|
||||||
@@ -31,3 +32,4 @@ regex = "1.10.4"
|
|||||||
reqwest = {version = "0.12.4", features =["blocking", "json"]}
|
reqwest = {version = "0.12.4", features =["blocking", "json"]}
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
fs_extra = "1.3.0"
|
fs_extra = "1.3.0"
|
||||||
|
http = "1.1.0"
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
use glob::glob;
|
use glob::glob;
|
||||||
use glob::GlobError;
|
use glob::GlobError;
|
||||||
|
use http::Method;
|
||||||
|
use std::collections::hash_set::HashSet;
|
||||||
use std::collections::{hash_map::Entry, HashMap};
|
use std::collections::{hash_map::Entry, HashMap};
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::prelude::*;
|
||||||
|
use std::io::BufReader;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::Child;
|
use std::process::Child;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
@@ -11,19 +16,39 @@ use crate::route::Route;
|
|||||||
const IGNORE_EXTENSIONS: [&str; 3] = ["css", "scss", "sass"];
|
const IGNORE_EXTENSIONS: [&str; 3] = ["css", "scss", "sass"];
|
||||||
const IGNORE_FILES: [&str; 1] = ["__root"];
|
const IGNORE_FILES: [&str; 1] = ["__root"];
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
const ROUTES_FOLDER_PATH: &str = "\\src\\routes";
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
const BUILD_JS_SCRIPT: &str = ".\\node_modules\\.bin\\tuono-build-prod.cmd";
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
const ROUTES_FOLDER_PATH: &str = "/src/routes";
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
const BUILD_JS_SCRIPT: &str = "./node_modules/.bin/tuono-build-prod";
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct App {
|
pub struct App {
|
||||||
pub route_map: HashMap<String, Route>,
|
pub route_map: HashMap<String, Route>,
|
||||||
pub base_path: PathBuf,
|
pub base_path: PathBuf,
|
||||||
|
pub has_app_state: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn has_app_state(base_path: PathBuf) -> std::io::Result<bool> {
|
||||||
|
let file = File::open(base_path.join("src/app.rs"))?;
|
||||||
|
let mut buf_reader = BufReader::new(file);
|
||||||
|
let mut contents = String::new();
|
||||||
|
buf_reader.read_to_string(&mut contents)?;
|
||||||
|
Ok(contents.contains("pub fn main"))
|
||||||
}
|
}
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let base_path = std::env::current_dir().unwrap();
|
let base_path = std::env::current_dir().expect("Failed to read current_dir");
|
||||||
|
|
||||||
let mut app = App {
|
let mut app = App {
|
||||||
route_map: HashMap::new(),
|
route_map: HashMap::new(),
|
||||||
base_path,
|
base_path: base_path.clone(),
|
||||||
|
has_app_state: has_app_state(base_path).unwrap_or(false),
|
||||||
};
|
};
|
||||||
|
|
||||||
app.collect_routes();
|
app.collect_routes();
|
||||||
@@ -32,7 +57,12 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn collect_routes(&mut self) {
|
fn collect_routes(&mut self) {
|
||||||
glob(self.base_path.join("src/routes/**/*.*").to_str().unwrap())
|
glob(
|
||||||
|
self.base_path
|
||||||
|
.join("src/routes/**/*.*")
|
||||||
|
.to_str()
|
||||||
|
.expect("Failed to glob routes folder"),
|
||||||
|
)
|
||||||
.expect("Failed to read glob pattern")
|
.expect("Failed to read glob pattern")
|
||||||
.for_each(|entry| {
|
.for_each(|entry| {
|
||||||
if self.should_collect_route(&entry) {
|
if self.should_collect_route(&entry) {
|
||||||
@@ -42,8 +72,16 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn should_collect_route(&self, entry: &Result<PathBuf, GlobError>) -> bool {
|
fn should_collect_route(&self, entry: &Result<PathBuf, GlobError>) -> bool {
|
||||||
let file_extension = entry.as_ref().unwrap().extension().unwrap();
|
let file_extension = entry
|
||||||
let file_name = entry.as_ref().unwrap().file_stem().unwrap();
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.extension()
|
||||||
|
.expect("Failed to read file extension");
|
||||||
|
let file_name = entry
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.file_stem()
|
||||||
|
.expect("Failed to read file name");
|
||||||
|
|
||||||
if IGNORE_EXTENSIONS.iter().any(|val| val == &file_extension) {
|
if IGNORE_EXTENSIONS.iter().any(|val| val == &file_extension) {
|
||||||
return false;
|
return false;
|
||||||
@@ -56,17 +94,23 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn collect_route(&mut self, path_buf: Result<PathBuf, GlobError>) {
|
fn collect_route(&mut self, path_buf: Result<PathBuf, GlobError>) {
|
||||||
let entry = path_buf.unwrap();
|
let entry = path_buf.expect("Failed to read glob path");
|
||||||
let base_path_str = self.base_path.to_str().unwrap();
|
|
||||||
|
let base_path_str = self
|
||||||
|
.base_path
|
||||||
|
.to_str()
|
||||||
|
.expect("Failed to read as str base_path");
|
||||||
let path = entry
|
let path = entry
|
||||||
.to_str()
|
.to_str()
|
||||||
.unwrap()
|
.expect("Failed to read entry as str")
|
||||||
.replace(&format!("{base_path_str}/src/routes"), "")
|
.replace(&format!("{base_path_str}{ROUTES_FOLDER_PATH}"), "")
|
||||||
|
// Cleanup windows paths
|
||||||
|
.replace("\\", "/")
|
||||||
.replace(".rs", "")
|
.replace(".rs", "")
|
||||||
.replace(".mdx", "")
|
.replace(".mdx", "")
|
||||||
.replace(".tsx", "");
|
.replace(".tsx", "");
|
||||||
|
|
||||||
if entry.extension().unwrap() == "rs" {
|
if entry.extension().expect("failed to read entry extension") == "rs" {
|
||||||
if let Entry::Vacant(route_map) = self.route_map.entry(path.clone()) {
|
if let Entry::Vacant(route_map) = self.route_map.entry(path.clone()) {
|
||||||
let mut route = Route::new(path);
|
let mut route = Route::new(path);
|
||||||
route.update_axum_info();
|
route.update_axum_info();
|
||||||
@@ -88,7 +132,7 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_react_prod(&self) {
|
pub fn build_react_prod(&self) {
|
||||||
Command::new("./node_modules/.bin/tuono-build-prod")
|
Command::new(BUILD_JS_SCRIPT)
|
||||||
.output()
|
.output()
|
||||||
.expect("Failed to build the react source");
|
.expect("Failed to build the react source");
|
||||||
}
|
}
|
||||||
@@ -102,6 +146,24 @@ impl App {
|
|||||||
.spawn()
|
.spawn()
|
||||||
.expect("Failed to run the rust server")
|
.expect("Failed to run the rust server")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_used_http_methods(&self) -> HashSet<Method> {
|
||||||
|
let mut acc = HashSet::new();
|
||||||
|
|
||||||
|
for (_, route) in self.route_map.clone().into_iter() {
|
||||||
|
if route.axum_info.is_some() {
|
||||||
|
acc.insert(Method::GET);
|
||||||
|
}
|
||||||
|
if !route.is_api() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for method in route.api_data.unwrap().methods.into_iter() {
|
||||||
|
acc.insert(method);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
acc
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@@ -112,13 +174,34 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn should_collect_routes() {
|
fn should_collect_routes() {
|
||||||
let mut app = App::new();
|
let mut app = App::new();
|
||||||
app.base_path = "/home/user/Documents/tuono".into();
|
#[cfg(target_os = "windows")]
|
||||||
|
let base_path = "\\home\\user\\Documents\\tuono";
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
let base_path = "/home/user/Documents/tuono";
|
||||||
|
|
||||||
|
app.base_path = base_path.into();
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
let routes = [
|
||||||
|
"\\home\\user\\Documents\\tuono\\src\\routes\\about.rs",
|
||||||
|
"\\home\\user\\Documents\\tuono\\src\\routes\\index.rs",
|
||||||
|
"\\home\\user\\Documents\\tuono\\src\\routes\\posts\\index.rs",
|
||||||
|
"\\home\\user\\Documents\\tuono\\src\\routes\\posts\\[post].rs",
|
||||||
|
"\\home\\user\\Documents\\tuono\\src\\routes\\posts\\handle-this.rs",
|
||||||
|
"\\home\\user\\Documents\\tuono\\src\\routes\\posts\\handle-this\\[post].rs",
|
||||||
|
"\\home\\user\\Documents\\tuono\\src\\routes\\posts\\UPPERCASE.rs",
|
||||||
|
"\\home\\user\\Documents\\tuono\\src\\routes\\sitemap.xml.rs",
|
||||||
|
];
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
let routes = [
|
let routes = [
|
||||||
"/home/user/Documents/tuono/src/routes/about.rs",
|
"/home/user/Documents/tuono/src/routes/about.rs",
|
||||||
"/home/user/Documents/tuono/src/routes/index.rs",
|
"/home/user/Documents/tuono/src/routes/index.rs",
|
||||||
"/home/user/Documents/tuono/src/routes/posts/index.rs",
|
"/home/user/Documents/tuono/src/routes/posts/index.rs",
|
||||||
"/home/user/Documents/tuono/src/routes/posts/[post].rs",
|
"/home/user/Documents/tuono/src/routes/posts/[post].rs",
|
||||||
|
"/home/user/Documents/tuono/src/routes/posts/handle-this.rs",
|
||||||
|
"/home/user/Documents/tuono/src/routes/posts/handle-this/[post].rs",
|
||||||
"/home/user/Documents/tuono/src/routes/posts/UPPERCASE.rs",
|
"/home/user/Documents/tuono/src/routes/posts/UPPERCASE.rs",
|
||||||
"/home/user/Documents/tuono/src/routes/sitemap.xml.rs",
|
"/home/user/Documents/tuono/src/routes/sitemap.xml.rs",
|
||||||
];
|
];
|
||||||
@@ -132,6 +215,11 @@ mod tests {
|
|||||||
("/about", "about"),
|
("/about", "about"),
|
||||||
("/posts/index", "posts_index"),
|
("/posts/index", "posts_index"),
|
||||||
("/posts/[post]", "posts_dyn_post"),
|
("/posts/[post]", "posts_dyn_post"),
|
||||||
|
("/posts/handle-this", "posts_handle_hyphen_this"),
|
||||||
|
(
|
||||||
|
"/posts/handle-this/[post]",
|
||||||
|
"posts_handle_hyphen_this_dyn_post",
|
||||||
|
),
|
||||||
("/posts/UPPERCASE", "posts_uppercase"),
|
("/posts/UPPERCASE", "posts_uppercase"),
|
||||||
("/sitemap.xml", "sitemap_dot_xml"),
|
("/sitemap.xml", "sitemap_dot_xml"),
|
||||||
];
|
];
|
||||||
@@ -153,8 +241,25 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn should_create_multi_level_axum_paths() {
|
fn should_create_multi_level_axum_paths() {
|
||||||
let mut app = App::new();
|
let mut app = App::new();
|
||||||
app.base_path = "/home/user/Documents/tuono".into();
|
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
let base_path = "\\home\\user\\Documents\\tuono";
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
let base_path = "/home/user/Documents/tuono";
|
||||||
|
|
||||||
|
app.base_path = base_path.into();
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
let routes = [
|
||||||
|
"\\home\\user\\Documents\\tuono\\src\\routes\\about.rs",
|
||||||
|
"\\home\\user\\Documents\\tuono\\src\\routes\\index.rs",
|
||||||
|
"\\home\\user\\Documents\\tuono\\src\\routes\\posts\\index.rs",
|
||||||
|
"\\home\\user\\Documents\\tuono\\src\\routes\\posts\\any-post.rs",
|
||||||
|
"\\home\\user\\Documents\\tuono\\src\\routes\\posts\\[post].rs",
|
||||||
|
];
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
let routes = [
|
let routes = [
|
||||||
"/home/user/Documents/tuono/src/routes/about.rs",
|
"/home/user/Documents/tuono/src/routes/about.rs",
|
||||||
"/home/user/Documents/tuono/src/routes/index.rs",
|
"/home/user/Documents/tuono/src/routes/index.rs",
|
||||||
@@ -179,7 +284,7 @@ mod tests {
|
|||||||
assert_eq!(
|
assert_eq!(
|
||||||
app.route_map
|
app.route_map
|
||||||
.get(path)
|
.get(path)
|
||||||
.unwrap()
|
.expect("Failed to get route path")
|
||||||
.axum_info
|
.axum_info
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@@ -231,8 +336,23 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn should_correctly_parse_routes_with_server_handler() {
|
fn should_correctly_parse_routes_with_server_handler() {
|
||||||
let mut app = App::new();
|
let mut app = App::new();
|
||||||
app.base_path = "/home/user/Documents/tuono".into();
|
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
let base_path = "\\home\\user\\Documents\\tuono";
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
let base_path = "/home/user/Documents/tuono";
|
||||||
|
|
||||||
|
app.base_path = base_path.into();
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
let routes = [
|
||||||
|
"\\home\\user\\Documents\\tuono\\src\\routes\\about.rs",
|
||||||
|
"\\home\\user\\Documents/tuono\\src\\routes\\about.tsx",
|
||||||
|
"\\home\\user\\Documents\\tuono\\src\\routes\\index.tsx",
|
||||||
|
];
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
let routes = [
|
let routes = [
|
||||||
"/home/user/Documents/tuono/src/routes/about.rs",
|
"/home/user/Documents/tuono/src/routes/about.rs",
|
||||||
"/home/user/Documents/tuono/src/routes/about.tsx",
|
"/home/user/Documents/tuono/src/routes/about.tsx",
|
||||||
@@ -249,9 +369,19 @@ mod tests {
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.for_each(|(path, expected_has_server_handler)| {
|
.for_each(|(path, expected_has_server_handler)| {
|
||||||
if expected_has_server_handler {
|
if expected_has_server_handler {
|
||||||
assert!(app.route_map.get(path).unwrap().axum_info.is_some())
|
assert!(app
|
||||||
|
.route_map
|
||||||
|
.get(path)
|
||||||
|
.expect("Failed to get route path")
|
||||||
|
.axum_info
|
||||||
|
.is_some())
|
||||||
} else {
|
} else {
|
||||||
assert!(app.route_map.get(path).unwrap().axum_info.is_none())
|
assert!(app
|
||||||
|
.route_map
|
||||||
|
.get(path)
|
||||||
|
.expect("Failed to get route path")
|
||||||
|
.axum_info
|
||||||
|
.is_none())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ use crate::scaffold_project;
|
|||||||
use crate::source_builder::{bundle_axum_source, check_tuono_folder, create_client_entry_files};
|
use crate::source_builder::{bundle_axum_source, check_tuono_folder, create_client_entry_files};
|
||||||
use crate::watch;
|
use crate::watch;
|
||||||
|
|
||||||
|
const TUONO_PORT: u16 = 3000;
|
||||||
|
const VITE_PORT: u16 = 3001;
|
||||||
|
|
||||||
#[derive(Subcommand, Debug)]
|
#[derive(Subcommand, Debug)]
|
||||||
enum Actions {
|
enum Actions {
|
||||||
/// Start the development environment
|
/// Start the development environment
|
||||||
@@ -47,12 +50,41 @@ fn init_tuono_folder(mode: Mode) -> std::io::Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn check_ports(mode: Mode) {
|
||||||
|
let rust_listener = std::net::TcpListener::bind(format!("0.0.0.0:{TUONO_PORT}"));
|
||||||
|
|
||||||
|
if let Err(_e) = rust_listener {
|
||||||
|
eprintln!("Error: Failed to bind to port {}", TUONO_PORT);
|
||||||
|
eprintln!(
|
||||||
|
"Please ensure that port {} is not already in use by another process or application.",
|
||||||
|
TUONO_PORT
|
||||||
|
);
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if mode == Mode::Dev {
|
||||||
|
let vite_listener = std::net::TcpListener::bind(format!("0.0.0.0:{VITE_PORT}"));
|
||||||
|
|
||||||
|
if let Err(_e) = vite_listener {
|
||||||
|
eprintln!("Error: Failed to bind to port {}", VITE_PORT);
|
||||||
|
eprintln!(
|
||||||
|
"Please ensure that port {} is not already in use by another process or application.",
|
||||||
|
VITE_PORT
|
||||||
|
);
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn app() -> std::io::Result<()> {
|
pub fn app() -> std::io::Result<()> {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
match args.action {
|
match args.action {
|
||||||
Actions::Dev => {
|
Actions::Dev => {
|
||||||
|
check_ports(Mode::Dev);
|
||||||
|
|
||||||
init_tuono_folder(Mode::Dev)?;
|
init_tuono_folder(Mode::Dev)?;
|
||||||
|
|
||||||
watch::watch().unwrap();
|
watch::watch().unwrap();
|
||||||
}
|
}
|
||||||
Actions::Build { ssg } => {
|
Actions::Build { ssg } => {
|
||||||
@@ -68,6 +100,8 @@ pub fn app() -> std::io::Result<()> {
|
|||||||
app.build_react_prod();
|
app.build_react_prod();
|
||||||
|
|
||||||
if ssg {
|
if ssg {
|
||||||
|
check_ports(Mode::Prod);
|
||||||
|
|
||||||
println!("SSG: generation started");
|
println!("SSG: generation started");
|
||||||
|
|
||||||
let static_dir = PathBuf::from("out/static");
|
let static_dir = PathBuf::from("out/static");
|
||||||
|
|||||||
@@ -1,17 +1,19 @@
|
|||||||
use fs_extra::dir::create_all;
|
use fs_extra::dir::create_all;
|
||||||
|
use http::Method;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use reqwest::blocking::Client;
|
use reqwest::blocking::Client;
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
fn has_dynamic_path(route: &str) -> bool {
|
fn has_dynamic_path(route: &str) -> bool {
|
||||||
let regex = Regex::new(r"\[(.*?)\]").expect("Failed to create the regex");
|
let regex = Regex::new(r"\[(.*?)\]").expect("Failed to create the regex");
|
||||||
regex.is_match(route)
|
regex.is_match(route)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||||
pub struct AxumInfo {
|
pub struct AxumInfo {
|
||||||
// Path for importing the module
|
// Path for importing the module
|
||||||
pub module_import: String,
|
pub module_import: String,
|
||||||
@@ -32,6 +34,7 @@ impl AxumInfo {
|
|||||||
.to_string()
|
.to_string()
|
||||||
.replace('/', "_")
|
.replace('/', "_")
|
||||||
.replace('.', "_dot_")
|
.replace('.', "_dot_")
|
||||||
|
.replace('-', "_hyphen_")
|
||||||
.to_lowercase();
|
.to_lowercase();
|
||||||
|
|
||||||
if axum_route.is_empty() {
|
if axum_route.is_empty() {
|
||||||
@@ -47,6 +50,7 @@ impl AxumInfo {
|
|||||||
.as_str()
|
.as_str()
|
||||||
.to_string()
|
.to_string()
|
||||||
.replace('/', "_")
|
.replace('/', "_")
|
||||||
|
.replace('-', "_hyphen_")
|
||||||
.replace('[', "dyn_")
|
.replace('[', "dyn_")
|
||||||
.replace(']', ""),
|
.replace(']', ""),
|
||||||
axum_route: axum_route.replace('[', ":").replace(']', ""),
|
axum_route: axum_route.replace('[', ":").replace(']', ""),
|
||||||
@@ -63,11 +67,56 @@ impl AxumInfo {
|
|||||||
// TODO: to be extended with common scenarios
|
// TODO: to be extended with common scenarios
|
||||||
const NO_HTML_EXTENSIONS: [&str; 1] = ["xml"];
|
const NO_HTML_EXTENSIONS: [&str; 1] = ["xml"];
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
// TODO: Refine this function to catch
|
||||||
|
// if the methods are commented.
|
||||||
|
fn read_http_methods_from_file(path: &String) -> Vec<Method> {
|
||||||
|
let regex = Regex::new(r"tuono_lib::api\((.*?)\)]").expect("Failed to create API regex");
|
||||||
|
|
||||||
|
let file = fs_extra::file::read_to_string(path).expect("Failed to read API file");
|
||||||
|
|
||||||
|
regex
|
||||||
|
.find_iter(&file)
|
||||||
|
.map(|proc_macro| {
|
||||||
|
let http_method = proc_macro
|
||||||
|
.as_str()
|
||||||
|
// Extract just the element surrounded by the phrantesist.
|
||||||
|
.replace("tuono_lib::api(", "")
|
||||||
|
.replace(")]", "");
|
||||||
|
Method::from_str(http_method.as_str()).unwrap_or(Method::GET)
|
||||||
|
})
|
||||||
|
.collect::<Vec<Method>>()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||||
|
pub struct ApiData {
|
||||||
|
pub methods: Vec<Method>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ApiData {
|
||||||
|
pub fn new(path: &String) -> Option<Self> {
|
||||||
|
if !path.starts_with("/api/") {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let base_path = std::env::current_dir().expect("Failed to get the base_path");
|
||||||
|
|
||||||
|
let file_path = base_path
|
||||||
|
.join(format!("src/routes{path}.rs"))
|
||||||
|
.to_str()
|
||||||
|
.unwrap()
|
||||||
|
.to_string();
|
||||||
|
let methods = read_http_methods_from_file(&file_path);
|
||||||
|
|
||||||
|
Some(ApiData { methods })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||||
pub struct Route {
|
pub struct Route {
|
||||||
path: String,
|
path: String,
|
||||||
pub is_dynamic: bool,
|
pub is_dynamic: bool,
|
||||||
pub axum_info: Option<AxumInfo>,
|
pub axum_info: Option<AxumInfo>,
|
||||||
|
pub api_data: Option<ApiData>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Route {
|
impl Route {
|
||||||
@@ -76,9 +125,14 @@ impl Route {
|
|||||||
path: cleaned_path.clone(),
|
path: cleaned_path.clone(),
|
||||||
axum_info: None,
|
axum_info: None,
|
||||||
is_dynamic: has_dynamic_path(&cleaned_path),
|
is_dynamic: has_dynamic_path(&cleaned_path),
|
||||||
|
api_data: ApiData::new(&cleaned_path),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_api(&self) -> bool {
|
||||||
|
self.api_data.is_some()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn update_axum_info(&mut self) {
|
pub fn update_axum_info(&mut self) {
|
||||||
self.axum_info = Some(AxumInfo::new(self.path.clone()))
|
self.axum_info = Some(AxumInfo::new(self.path.clone()))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ pub fn create_new_project(folder_name: Option<String>, template: Option<String>)
|
|||||||
let folder = folder_name.unwrap_or(".".to_string());
|
let folder = folder_name.unwrap_or(".".to_string());
|
||||||
|
|
||||||
// In case of missing select the tuono example
|
// In case of missing select the tuono example
|
||||||
let template = template.unwrap_or("tuono".to_string());
|
let template = template.unwrap_or("tuono-app".to_string());
|
||||||
|
|
||||||
let client = blocking::Client::builder()
|
let client = blocking::Client::builder()
|
||||||
.user_agent("")
|
.user_agent("")
|
||||||
@@ -63,11 +63,17 @@ pub fn create_new_project(folder_name: Option<String>, template: Option<String>)
|
|||||||
.collect::<Vec<&GithubFile>>();
|
.collect::<Vec<&GithubFile>>();
|
||||||
|
|
||||||
if new_project_files.is_empty() {
|
if new_project_files.is_empty() {
|
||||||
println!("Template not found: {template}");
|
eprintln!("Error: Template '{template}' not found");
|
||||||
return;
|
println!("Hint: you can view the available templates at https://github.com/Valerioageno/tuono/tree/main/examples");
|
||||||
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if folder != "." {
|
if folder != "." {
|
||||||
|
if Path::new(&folder).exists() {
|
||||||
|
eprintln!("Error: Directory '{folder}' already exists");
|
||||||
|
println!("Hint: you can scaffold a tuono project within an existing folder with 'cd {folder} && tuono new .'");
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
create_dir(&folder).unwrap();
|
create_dir(&folder).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,12 +42,17 @@ const MODE: Mode = /*MODE*/;
|
|||||||
|
|
||||||
// MODULE_IMPORTS
|
// MODULE_IMPORTS
|
||||||
|
|
||||||
|
//MAIN_FILE_IMPORT//
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
println!("\n ⚡ Tuono v/*VERSION*/");
|
println!("\n ⚡ Tuono v/*VERSION*/");
|
||||||
|
|
||||||
|
//MAIN_FILE_DEFINITION//
|
||||||
|
|
||||||
let router = Router::new()
|
let router = Router::new()
|
||||||
// ROUTE_BUILDER
|
// ROUTE_BUILDER
|
||||||
;
|
//MAIN_FILE_USAGE//;
|
||||||
|
|
||||||
Server::init(router, MODE).start().await
|
Server::init(router, MODE).start().await
|
||||||
}
|
}
|
||||||
@@ -77,13 +82,23 @@ fn create_routes_declaration(routes: &HashMap<String, Route>) -> String {
|
|||||||
module_import,
|
module_import,
|
||||||
} = axum_info.as_ref().unwrap();
|
} = axum_info.as_ref().unwrap();
|
||||||
|
|
||||||
|
if !route.is_api() {
|
||||||
route_declarations.push_str(&format!(
|
route_declarations.push_str(&format!(
|
||||||
r#".route("{axum_route}", get({module_import}::route))"#
|
r#".route("{axum_route}", get({module_import}::route))"#
|
||||||
));
|
));
|
||||||
let slash = if axum_route.ends_with('/') { "" } else { "/" };
|
let slash = if axum_route.ends_with('/') { "" } else { "/" };
|
||||||
|
|
||||||
route_declarations.push_str(&format!(
|
route_declarations.push_str(&format!(
|
||||||
r#".route("/__tuono/data{axum_route}{slash}data.json", get({module_import}::api))"#
|
r#".route("/__tuono/data{axum_route}{slash}data.json", get({module_import}::api))"#
|
||||||
));
|
));
|
||||||
|
} else {
|
||||||
|
for method in route.api_data.as_ref().unwrap().methods.clone() {
|
||||||
|
let method = method.to_string().to_lowercase();
|
||||||
|
route_declarations.push_str(&format!(
|
||||||
|
r#".route("{axum_route}", {method}({module_import}::{method}__tuono_internal_api))"#
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,22 +146,44 @@ fn generate_axum_source(app: &App, mode: Mode) -> String {
|
|||||||
&create_modules_declaration(&app.route_map),
|
&create_modules_declaration(&app.route_map),
|
||||||
)
|
)
|
||||||
.replace("/*VERSION*/", crate_version!())
|
.replace("/*VERSION*/", crate_version!())
|
||||||
.replace("/*MODE*/", mode.as_str());
|
.replace("/*MODE*/", mode.as_str())
|
||||||
|
.replace(
|
||||||
let has_server_handlers = app
|
"//MAIN_FILE_IMPORT//",
|
||||||
.route_map
|
if app.has_app_state {
|
||||||
.iter()
|
r#"#[path="../src/app.rs"]
|
||||||
.filter(|(_, route)| route.axum_info.is_some())
|
mod tuono_main_state;
|
||||||
.collect::<Vec<(&String, &Route)>>()
|
"#
|
||||||
.is_empty();
|
} else {
|
||||||
|
""
|
||||||
if !has_server_handlers {
|
},
|
||||||
return src.replace(
|
)
|
||||||
"// AXUM_GET_ROUTE_HANDLER",
|
.replace(
|
||||||
"use tuono_lib::axum::routing::get;",
|
"//MAIN_FILE_DEFINITION//",
|
||||||
|
if app.has_app_state {
|
||||||
|
"let user_custom_state = tuono_main_state::main();"
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.replace(
|
||||||
|
"//MAIN_FILE_USAGE//",
|
||||||
|
if app.has_app_state {
|
||||||
|
".with_state(user_custom_state)"
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let mut import_http_handler = String::new();
|
||||||
|
|
||||||
|
let used_http_methods = app.get_used_http_methods();
|
||||||
|
|
||||||
|
for method in used_http_methods.into_iter() {
|
||||||
|
let method = method.to_string().to_lowercase();
|
||||||
|
import_http_handler.push_str(&format!("use tuono_lib::axum::routing::{method};\n"))
|
||||||
}
|
}
|
||||||
src
|
|
||||||
|
src.replace("// AXUM_GET_ROUTE_HANDLER", &import_http_handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_tuono_folder() -> io::Result<()> {
|
pub fn check_tuono_folder() -> io::Result<()> {
|
||||||
|
|||||||
@@ -9,10 +9,20 @@ use watchexec_supervisor::job::{start_job, Job};
|
|||||||
use crate::mode::Mode;
|
use crate::mode::Mode;
|
||||||
use crate::source_builder::bundle_axum_source;
|
use crate::source_builder::bundle_axum_source;
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
const DEV_WATCH_BIN_SRC: &str = "node_modules\\.bin\\tuono-dev-watch.cmd";
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
const DEV_SSR_BIN_SRC: &str = "node_modules\\.bin\\tuono-dev-ssr.cmd";
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
const DEV_WATCH_BIN_SRC: &str = "node_modules/.bin/tuono-dev-watch";
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
const DEV_SSR_BIN_SRC: &str = "node_modules/.bin/tuono-dev-ssr";
|
||||||
|
|
||||||
fn watch_react_src() -> Job {
|
fn watch_react_src() -> Job {
|
||||||
start_job(Arc::new(Command {
|
start_job(Arc::new(Command {
|
||||||
program: Program::Exec {
|
program: Program::Exec {
|
||||||
prog: "node_modules/.bin/tuono-dev-watch".into(),
|
prog: DEV_WATCH_BIN_SRC.into(),
|
||||||
args: vec![],
|
args: vec![],
|
||||||
},
|
},
|
||||||
options: Default::default(),
|
options: Default::default(),
|
||||||
@@ -34,7 +44,7 @@ fn build_rust_src() -> Job {
|
|||||||
fn build_react_ssr_src() -> Job {
|
fn build_react_ssr_src() -> Job {
|
||||||
start_job(Arc::new(Command {
|
start_job(Arc::new(Command {
|
||||||
program: Program::Exec {
|
program: Program::Exec {
|
||||||
prog: "node_modules/.bin/tuono-dev-ssr".into(),
|
prog: DEV_SSR_BIN_SRC.into(),
|
||||||
args: vec![],
|
args: vec![],
|
||||||
},
|
},
|
||||||
options: Default::default(),
|
options: Default::default(),
|
||||||
@@ -77,7 +87,7 @@ pub async fn watch() -> Result<()> {
|
|||||||
if should_reload_rust_server {
|
if should_reload_rust_server {
|
||||||
println!(" Reloading...");
|
println!(" Reloading...");
|
||||||
run_server.stop();
|
run_server.stop();
|
||||||
bundle_axum_source(Mode::Dev).expect("Failed to bunlde rust source");
|
bundle_axum_source(Mode::Dev).expect("Failed to bundle rust source");
|
||||||
run_server.start();
|
run_server.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "tuono_lib"
|
name = "tuono_lib"
|
||||||
version = "0.11.2"
|
version = "0.14.3"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["V. Ageno <valerioageno@yahoo.it>"]
|
authors = ["V. Ageno <valerioageno@yahoo.it>"]
|
||||||
description = "The react/rust fullstack framework"
|
description = "Superfast React fullstack framework"
|
||||||
|
homepage = "https://tuono.dev"
|
||||||
keywords = [ "react", "typescript", "fullstack", "web", "ssr"]
|
keywords = [ "react", "typescript", "fullstack", "web", "ssr"]
|
||||||
repository = "https://github.com/Valerioageno/tuono"
|
repository = "https://github.com/Valerioageno/tuono"
|
||||||
readme = "../../README.md"
|
readme = "../../README.md"
|
||||||
@@ -14,9 +15,6 @@ include = [
|
|||||||
"Cargo.toml"
|
"Cargo.toml"
|
||||||
]
|
]
|
||||||
|
|
||||||
[lib]
|
|
||||||
name = "tuono_lib"
|
|
||||||
path = "src/lib.rs"
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ssr_rs = "0.7.0"
|
ssr_rs = "0.7.0"
|
||||||
@@ -33,9 +31,12 @@ either = "1.13.0"
|
|||||||
tower-http = {version = "0.6.0", features = ["fs"]}
|
tower-http = {version = "0.6.0", features = ["fs"]}
|
||||||
colored = "2.1.0"
|
colored = "2.1.0"
|
||||||
|
|
||||||
tuono_lib_macros = {path = "../tuono_lib_macros", version = "0.11.2"}
|
tuono_lib_macros = {path = "../tuono_lib_macros", version = "0.14.3"}
|
||||||
# Match the same version used by axum
|
# Match the same version used by axum
|
||||||
tokio-tungstenite = "0.24.0"
|
tokio-tungstenite = "0.24.0"
|
||||||
futures-util = { version = "0.3", default-features = false, features = ["sink", "std"] }
|
futures-util = { version = "0.3", default-features = false, features = ["sink", "std"] }
|
||||||
tungstenite = "0.24.0"
|
tungstenite = "0.24.0"
|
||||||
|
http = "1.1.0"
|
||||||
|
pin-project = "1.1.7"
|
||||||
|
tower = "0.5.1"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
mod catch_all;
|
mod catch_all;
|
||||||
|
mod logger;
|
||||||
mod manifest;
|
mod manifest;
|
||||||
mod mode;
|
mod mode;
|
||||||
mod payload;
|
mod payload;
|
||||||
@@ -14,9 +15,8 @@ pub use payload::Payload;
|
|||||||
pub use request::Request;
|
pub use request::Request;
|
||||||
pub use response::{Props, Response};
|
pub use response::{Props, Response};
|
||||||
pub use server::Server;
|
pub use server::Server;
|
||||||
pub use tuono_lib_macros::handler;
|
pub use tuono_lib_macros::{api, handler};
|
||||||
|
|
||||||
// Re-exports
|
// Re-exports
|
||||||
pub use axum;
|
pub use axum;
|
||||||
pub use reqwest;
|
|
||||||
pub use tokio;
|
pub use tokio;
|
||||||
|
|||||||
@@ -0,0 +1,106 @@
|
|||||||
|
use colored::Colorize;
|
||||||
|
use http::{method::Method, Request, Response};
|
||||||
|
use pin_project::pin_project;
|
||||||
|
use std::fmt::Debug;
|
||||||
|
use std::future::Future;
|
||||||
|
use std::pin::Pin;
|
||||||
|
use std::task::{Context, Poll};
|
||||||
|
use tokio::time::Instant;
|
||||||
|
use tower::{Layer, Service};
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct LoggerLayer {}
|
||||||
|
|
||||||
|
impl LoggerLayer {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
LoggerLayer {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S> Layer<S> for LoggerLayer {
|
||||||
|
type Service = Logger<S>;
|
||||||
|
|
||||||
|
fn layer(&self, inner: S) -> Self::Service {
|
||||||
|
Logger::new(inner)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct Logger<S> {
|
||||||
|
inner: S,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S> Logger<S> {
|
||||||
|
pub fn new(inner: S) -> Self {
|
||||||
|
Logger { inner }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S, ReqBody, ResBody> Service<Request<ReqBody>> for Logger<S>
|
||||||
|
where
|
||||||
|
S: Service<Request<ReqBody>, Response = Response<ResBody>>,
|
||||||
|
ResBody: Default,
|
||||||
|
<S as Service<Request<ReqBody>>>::Error: Debug,
|
||||||
|
{
|
||||||
|
type Response = S::Response;
|
||||||
|
type Error = S::Error;
|
||||||
|
type Future = LoggerFuture<S::Future>;
|
||||||
|
|
||||||
|
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||||
|
self.inner.poll_ready(cx)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn call(&mut self, req: Request<ReqBody>) -> Self::Future {
|
||||||
|
let method = req.method().clone();
|
||||||
|
let path = req.uri().path().to_string();
|
||||||
|
|
||||||
|
LoggerFuture {
|
||||||
|
future: self.inner.call(req),
|
||||||
|
method,
|
||||||
|
path,
|
||||||
|
start: Instant::now(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[pin_project]
|
||||||
|
pub struct LoggerFuture<F> {
|
||||||
|
#[pin]
|
||||||
|
future: F,
|
||||||
|
method: Method,
|
||||||
|
path: String,
|
||||||
|
start: Instant,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<F, B, E> Future for LoggerFuture<F>
|
||||||
|
where
|
||||||
|
F: Future<Output = Result<Response<B>, E>>,
|
||||||
|
B: Default,
|
||||||
|
E: Debug,
|
||||||
|
{
|
||||||
|
type Output = Result<Response<B>, E>;
|
||||||
|
|
||||||
|
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||||
|
let this = self.project();
|
||||||
|
let res: F::Output = match this.future.poll(cx) {
|
||||||
|
Poll::Ready(res) => res,
|
||||||
|
Poll::Pending => return Poll::Pending,
|
||||||
|
};
|
||||||
|
|
||||||
|
if this.path.starts_with("/__tuono/data") {
|
||||||
|
return Poll::Ready(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
let status_code = res.as_ref().unwrap().status();
|
||||||
|
|
||||||
|
println!(
|
||||||
|
" {} {} {} in {}ms",
|
||||||
|
this.method,
|
||||||
|
this.path,
|
||||||
|
status_code.as_str().green(),
|
||||||
|
this.start.elapsed().as_millis()
|
||||||
|
);
|
||||||
|
|
||||||
|
Poll::Ready(res)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,9 +3,7 @@ use crate::{ssr::Js, Payload};
|
|||||||
use axum::http::{HeaderMap, StatusCode};
|
use axum::http::{HeaderMap, StatusCode};
|
||||||
use axum::response::{Html, IntoResponse, Redirect};
|
use axum::response::{Html, IntoResponse, Redirect};
|
||||||
use axum::Json;
|
use axum::Json;
|
||||||
use colored::*;
|
|
||||||
use erased_serde::Serialize;
|
use erased_serde::Serialize;
|
||||||
use tokio::time::Instant;
|
|
||||||
|
|
||||||
pub struct Props {
|
pub struct Props {
|
||||||
data: Box<dyn Serialize>,
|
data: Box<dyn Serialize>,
|
||||||
@@ -74,25 +72,13 @@ impl Response {
|
|||||||
pub fn render_to_string(&self, req: Request) -> impl IntoResponse {
|
pub fn render_to_string(&self, req: Request) -> impl IntoResponse {
|
||||||
match self {
|
match self {
|
||||||
Self::Props(Props { data, http_code }) => {
|
Self::Props(Props { data, http_code }) => {
|
||||||
let start = Instant::now();
|
|
||||||
let payload = Payload::new(&req, data).client_payload().unwrap();
|
let payload = Payload::new(&req, data).client_payload().unwrap();
|
||||||
|
|
||||||
let response = match Js::render_to_string(Some(&payload)) {
|
match Js::render_to_string(Some(&payload)) {
|
||||||
Ok(html) => (*http_code, Html(html)),
|
Ok(html) => (*http_code, Html(html)),
|
||||||
Err(_) => (*http_code, Html("500 Internal server error".to_string())),
|
Err(_) => (*http_code, Html("500 Internal server error".to_string())),
|
||||||
}
|
}
|
||||||
.into_response();
|
.into_response()
|
||||||
|
|
||||||
let duration = start.elapsed();
|
|
||||||
|
|
||||||
println!(
|
|
||||||
" GET {} {} in {}ms",
|
|
||||||
req.uri.path(),
|
|
||||||
http_code.as_str().green(),
|
|
||||||
duration.as_millis()
|
|
||||||
);
|
|
||||||
|
|
||||||
response
|
|
||||||
}
|
}
|
||||||
Self::Redirect(to) => Redirect::permanent(to).into_response(),
|
Self::Redirect(to) => Redirect::permanent(to).into_response(),
|
||||||
Self::Custom(response) => response.clone().into_response(),
|
Self::Custom(response) => response.clone().into_response(),
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
use crate::mode::{Mode, GLOBAL_MODE};
|
|
||||||
|
|
||||||
use crate::manifest::load_manifest;
|
use crate::manifest::load_manifest;
|
||||||
|
use crate::mode::{Mode, GLOBAL_MODE};
|
||||||
use axum::routing::{get, Router};
|
use axum::routing::{get, Router};
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use ssr_rs::Ssr;
|
use ssr_rs::Ssr;
|
||||||
use tower_http::services::ServeDir;
|
use tower_http::services::ServeDir;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
catch_all::catch_all, vite_reverse_proxy::vite_reverse_proxy,
|
catch_all::catch_all, logger::LoggerLayer, vite_reverse_proxy::vite_reverse_proxy,
|
||||||
vite_websocket_proxy::vite_websocket_proxy,
|
vite_websocket_proxy::vite_websocket_proxy,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -15,12 +14,12 @@ const DEV_PUBLIC_DIR: &str = "public";
|
|||||||
const PROD_PUBLIC_DIR: &str = "out/client";
|
const PROD_PUBLIC_DIR: &str = "out/client";
|
||||||
|
|
||||||
pub struct Server {
|
pub struct Server {
|
||||||
router: Router<reqwest::Client>,
|
router: Router,
|
||||||
mode: Mode,
|
mode: Mode,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Server {
|
impl Server {
|
||||||
pub fn init(router: Router<reqwest::Client>, mode: Mode) -> Server {
|
pub fn init(router: Router, mode: Mode) -> Server {
|
||||||
Ssr::create_platform();
|
Ssr::create_platform();
|
||||||
|
|
||||||
GLOBAL_MODE.set(mode).unwrap();
|
GLOBAL_MODE.set(mode).unwrap();
|
||||||
@@ -35,17 +34,18 @@ impl Server {
|
|||||||
pub async fn start(&self) {
|
pub async fn start(&self) {
|
||||||
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
|
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
|
||||||
|
|
||||||
let fetch = reqwest::Client::new();
|
|
||||||
|
|
||||||
if self.mode == Mode::Dev {
|
if self.mode == Mode::Dev {
|
||||||
println!(" Ready at: {}\n", "http://localhost:3000".blue().bold());
|
println!(" Ready at: {}\n", "http://localhost:3000".blue().bold());
|
||||||
let router = self
|
let router = self
|
||||||
.router
|
.router
|
||||||
.to_owned()
|
.to_owned()
|
||||||
|
.layer(LoggerLayer::new())
|
||||||
.route("/vite-server/", get(vite_websocket_proxy))
|
.route("/vite-server/", get(vite_websocket_proxy))
|
||||||
.route("/vite-server/*path", get(vite_reverse_proxy))
|
.route("/vite-server/*path", get(vite_reverse_proxy))
|
||||||
.fallback_service(ServeDir::new(DEV_PUBLIC_DIR).fallback(get(catch_all)))
|
.fallback_service(
|
||||||
.with_state(fetch);
|
ServeDir::new(DEV_PUBLIC_DIR)
|
||||||
|
.fallback(get(catch_all).layer(LoggerLayer::new())),
|
||||||
|
);
|
||||||
|
|
||||||
axum::serve(listener, router)
|
axum::serve(listener, router)
|
||||||
.await
|
.await
|
||||||
@@ -58,8 +58,11 @@ impl Server {
|
|||||||
let router = self
|
let router = self
|
||||||
.router
|
.router
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.fallback_service(ServeDir::new(PROD_PUBLIC_DIR).fallback(get(catch_all)))
|
.layer(LoggerLayer::new())
|
||||||
.with_state(fetch);
|
.fallback_service(
|
||||||
|
ServeDir::new(PROD_PUBLIC_DIR)
|
||||||
|
.fallback(get(catch_all).layer(LoggerLayer::new())),
|
||||||
|
);
|
||||||
|
|
||||||
axum::serve(listener, router)
|
axum::serve(listener, router)
|
||||||
.await
|
.await
|
||||||
|
|||||||
@@ -9,6 +9,16 @@ use std::path::PathBuf;
|
|||||||
/// update the SSR result without reloading the whole server.
|
/// update the SSR result without reloading the whole server.
|
||||||
pub struct Js;
|
pub struct Js;
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
const PROD_BUNDLE_PATH: &str = ".\\out\\server\\prod-server.js";
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
const DEV_BUNDLE_PATH: &str = ".\\.tuono\\server\\dev-server.js";
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
const PROD_BUNDLE_PATH: &str = "./out/server/prod-server.js";
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
const DEV_BUNDLE_PATH: &str = "./.tuono/server/dev-server.js";
|
||||||
|
|
||||||
impl Js {
|
impl Js {
|
||||||
pub fn render_to_string(payload: Option<&str>) -> Result<String, SsrError> {
|
pub fn render_to_string(payload: Option<&str>) -> Result<String, SsrError> {
|
||||||
let mode = GLOBAL_MODE.get().expect("Failed to get GLOBAL_MODE");
|
let mode = GLOBAL_MODE.get().expect("Failed to get GLOBAL_MODE");
|
||||||
@@ -27,7 +37,7 @@ impl ProdJs {
|
|||||||
thread_local! {
|
thread_local! {
|
||||||
pub static SSR: RefCell<Ssr<'static, 'static>> = RefCell::new(
|
pub static SSR: RefCell<Ssr<'static, 'static>> = RefCell::new(
|
||||||
Ssr::from(
|
Ssr::from(
|
||||||
read_to_string(PathBuf::from("./out/server/prod-server.js")).expect("Server bundle not found"), ""
|
read_to_string(PathBuf::from(PROD_BUNDLE_PATH)).expect("Server bundle not found"), ""
|
||||||
).unwrap()
|
).unwrap()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -38,8 +48,7 @@ struct DevJs;
|
|||||||
impl DevJs {
|
impl DevJs {
|
||||||
pub fn render_to_string(params: Option<&str>) -> Result<String, SsrError> {
|
pub fn render_to_string(params: Option<&str>) -> Result<String, SsrError> {
|
||||||
Ssr::from(
|
Ssr::from(
|
||||||
read_to_string(PathBuf::from("./.tuono/server/dev-server.js"))
|
read_to_string(PathBuf::from(DEV_BUNDLE_PATH)).expect("Server bundle not found"),
|
||||||
.expect("Server bundle not found"),
|
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use axum::body::Body;
|
use axum::body::Body;
|
||||||
use axum::extract::{Path, State};
|
use axum::extract::Path;
|
||||||
|
|
||||||
use axum::http::{HeaderName, HeaderValue};
|
use axum::http::{HeaderName, HeaderValue};
|
||||||
use axum::response::{IntoResponse, Response};
|
use axum::response::{IntoResponse, Response};
|
||||||
@@ -7,10 +7,9 @@ use reqwest::Client;
|
|||||||
|
|
||||||
const VITE_URL: &str = "http://localhost:3001/vite-server";
|
const VITE_URL: &str = "http://localhost:3001/vite-server";
|
||||||
|
|
||||||
pub async fn vite_reverse_proxy(
|
pub async fn vite_reverse_proxy(Path(path): Path<String>) -> impl IntoResponse {
|
||||||
State(client): State<Client>,
|
let client = Client::new();
|
||||||
Path(path): Path<String>,
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
match client.get(format!("{VITE_URL}/{path}")).send().await {
|
match client.get(format!("{VITE_URL}/{path}")).send().await {
|
||||||
Ok(res) => {
|
Ok(res) => {
|
||||||
let mut response_builder = Response::builder().status(res.status().as_u16());
|
let mut response_builder = Response::builder().status(res.status().as_u16());
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "tuono_lib_macros"
|
name = "tuono_lib_macros"
|
||||||
version = "0.11.2"
|
version = "0.14.3"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "The react/rust fullstack framework"
|
description = "Superfast React fullstack framework"
|
||||||
|
homepage = "https://tuono.dev"
|
||||||
keywords = [ "react", "typescript", "fullstack", "web", "ssr"]
|
keywords = [ "react", "typescript", "fullstack", "web", "ssr"]
|
||||||
repository = "https://github.com/Valerioageno/tuono"
|
repository = "https://github.com/Valerioageno/tuono"
|
||||||
readme = "../../README.md"
|
readme = "../../README.md"
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
use crate::utils::{
|
||||||
|
crate_application_state_extractor, create_struct_fn_arg, import_main_application_state,
|
||||||
|
params_argument, request_argument,
|
||||||
|
};
|
||||||
|
use proc_macro::{Span, TokenStream};
|
||||||
|
use quote::quote;
|
||||||
|
use syn::punctuated::Punctuated;
|
||||||
|
use syn::token::Comma;
|
||||||
|
use syn::{parse_macro_input, FnArg, Ident, ItemFn, Pat};
|
||||||
|
|
||||||
|
pub fn api_core(attrs: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
|
let item = parse_macro_input!(item as ItemFn);
|
||||||
|
let http_method = parse_macro_input!(attrs as Ident)
|
||||||
|
.to_string()
|
||||||
|
.to_lowercase();
|
||||||
|
|
||||||
|
let api_fn_name = Ident::new(
|
||||||
|
&format!("{}__tuono_internal_api", http_method),
|
||||||
|
Span::call_site().into(),
|
||||||
|
);
|
||||||
|
|
||||||
|
let fn_name = &item.sig.ident;
|
||||||
|
let return_type = &item.sig.output;
|
||||||
|
|
||||||
|
let mut argument_names: Punctuated<Pat, Comma> = Punctuated::new();
|
||||||
|
let mut axum_arguments: Punctuated<FnArg, Comma> = Punctuated::new();
|
||||||
|
|
||||||
|
// Fn Arguments minus the first which always is the request
|
||||||
|
for (i, arg) in item.sig.inputs.iter().enumerate() {
|
||||||
|
if i == 0 {
|
||||||
|
axum_arguments.insert(i, params_argument());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if i == 1 {
|
||||||
|
axum_arguments.insert(1, create_struct_fn_arg())
|
||||||
|
}
|
||||||
|
|
||||||
|
if let FnArg::Typed(pat_type) = arg {
|
||||||
|
let index = i - 1;
|
||||||
|
let argument_name = *pat_type.pat.clone();
|
||||||
|
argument_names.insert(index, argument_name.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
axum_arguments.insert(axum_arguments.len(), request_argument());
|
||||||
|
|
||||||
|
let application_state_extractor = crate_application_state_extractor(argument_names.clone());
|
||||||
|
let application_state_import = import_main_application_state(argument_names.clone());
|
||||||
|
|
||||||
|
quote! {
|
||||||
|
#application_state_import
|
||||||
|
|
||||||
|
#item
|
||||||
|
|
||||||
|
pub async fn #api_fn_name(#axum_arguments)#return_type {
|
||||||
|
|
||||||
|
#application_state_extractor
|
||||||
|
|
||||||
|
let pathname = request.uri();
|
||||||
|
let headers = request.headers();
|
||||||
|
|
||||||
|
let req = tuono_lib::Request::new(pathname.to_owned(), headers.to_owned(), params);
|
||||||
|
|
||||||
|
#fn_name(req.clone(), #argument_names).await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.into()
|
||||||
|
}
|
||||||
@@ -1,43 +1,76 @@
|
|||||||
|
use crate::utils::{
|
||||||
|
crate_application_state_extractor, create_struct_fn_arg, import_main_application_state,
|
||||||
|
params_argument, request_argument,
|
||||||
|
};
|
||||||
|
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
use syn::{parse_macro_input, ItemFn};
|
use syn::punctuated::Punctuated;
|
||||||
|
use syn::token::Comma;
|
||||||
|
use syn::{parse_macro_input, FnArg, ItemFn, Pat};
|
||||||
|
|
||||||
pub fn handler_core(_args: TokenStream, item: TokenStream) -> TokenStream {
|
pub fn handler_core(_args: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
let item = parse_macro_input!(item as ItemFn);
|
let item = parse_macro_input!(item as ItemFn);
|
||||||
|
|
||||||
let fn_name = item.clone().sig.ident;
|
let fn_name = &item.sig.ident;
|
||||||
|
|
||||||
|
let mut argument_names: Punctuated<Pat, Comma> = Punctuated::new();
|
||||||
|
let mut axum_arguments: Punctuated<FnArg, Comma> = Punctuated::new();
|
||||||
|
|
||||||
|
// Fn Arguments minus the first which always is the request
|
||||||
|
for (i, arg) in item.sig.inputs.iter().enumerate() {
|
||||||
|
if i == 0 {
|
||||||
|
axum_arguments.insert(i, params_argument());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if i == 1 {
|
||||||
|
axum_arguments.insert(1, create_struct_fn_arg())
|
||||||
|
}
|
||||||
|
|
||||||
|
if let FnArg::Typed(pat_type) = arg {
|
||||||
|
let index = i - 1;
|
||||||
|
let argument_name = *pat_type.pat.clone();
|
||||||
|
argument_names.insert(index, argument_name.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
axum_arguments.insert(axum_arguments.len(), request_argument());
|
||||||
|
|
||||||
|
let application_state_extractor = crate_application_state_extractor(argument_names.clone());
|
||||||
|
let application_state_import = import_main_application_state(argument_names.clone());
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
use tuono_lib::axum::response::IntoResponse;
|
#application_state_import
|
||||||
use std::collections::HashMap;
|
|
||||||
use tuono_lib::axum::extract::{State, Path};
|
|
||||||
|
|
||||||
#item
|
#item
|
||||||
|
|
||||||
pub async fn route(
|
pub async fn route(
|
||||||
Path(params): Path<HashMap<String, String>>,
|
#axum_arguments
|
||||||
State(client): State<tuono_lib::reqwest::Client>,
|
) -> impl tuono_lib::axum::response::IntoResponse {
|
||||||
request: tuono_lib::axum::extract::Request
|
|
||||||
) -> impl IntoResponse {
|
#application_state_extractor
|
||||||
|
|
||||||
let pathname = request.uri();
|
let pathname = request.uri();
|
||||||
let headers = request.headers();
|
let headers = request.headers();
|
||||||
|
|
||||||
let req = tuono_lib::Request::new(pathname.to_owned(), headers.to_owned(), params);
|
let req = tuono_lib::Request::new(pathname.to_owned(), headers.to_owned(), params);
|
||||||
|
|
||||||
#fn_name(req.clone(), client).await.render_to_string(req)
|
#fn_name(req.clone(), #argument_names).await.render_to_string(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn api(
|
pub async fn api(
|
||||||
Path(params): Path<HashMap<String, String>>,
|
#axum_arguments
|
||||||
State(client): State<tuono_lib::reqwest::Client>,
|
) -> impl tuono_lib::axum::response::IntoResponse {
|
||||||
request: tuono_lib::axum::extract::Request
|
|
||||||
) -> impl IntoResponse{
|
#application_state_extractor
|
||||||
|
|
||||||
let pathname = request.uri();
|
let pathname = request.uri();
|
||||||
let headers = request.headers();
|
let headers = request.headers();
|
||||||
|
|
||||||
let req = tuono_lib::Request::new(pathname.to_owned(), headers.to_owned(), params);
|
let req = tuono_lib::Request::new(pathname.to_owned(), headers.to_owned(), params);
|
||||||
|
|
||||||
#fn_name(req.clone(), client).await.json()
|
#fn_name(req.clone(), #argument_names).await.json()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.into()
|
.into()
|
||||||
|
|||||||
@@ -1,9 +1,16 @@
|
|||||||
extern crate proc_macro;
|
extern crate proc_macro;
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
|
|
||||||
|
mod api;
|
||||||
mod handler;
|
mod handler;
|
||||||
|
mod utils;
|
||||||
|
|
||||||
#[proc_macro_attribute]
|
#[proc_macro_attribute]
|
||||||
pub fn handler(args: TokenStream, item: TokenStream) -> TokenStream {
|
pub fn handler(args: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
handler::handler_core(args, item)
|
handler::handler_core(args, item)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[proc_macro_attribute]
|
||||||
|
pub fn api(args: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
|
api::api_core(args, item)
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
use quote::quote;
|
||||||
|
use syn::punctuated::Punctuated;
|
||||||
|
use syn::token::Comma;
|
||||||
|
use syn::{parse2, parse_quote, FnArg, Pat, Stmt};
|
||||||
|
|
||||||
|
pub fn create_struct_fn_arg() -> FnArg {
|
||||||
|
parse2(quote! {
|
||||||
|
tuono_lib::axum::extract::State(state): tuono_lib::axum::extract::State<ApplicationState>
|
||||||
|
})
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn import_main_application_state(argument_names: Punctuated<Pat, Comma>) -> Option<Stmt> {
|
||||||
|
if !argument_names.is_empty() {
|
||||||
|
let local: Stmt = parse_quote!(
|
||||||
|
use crate::tuono_main_state::ApplicationState;
|
||||||
|
);
|
||||||
|
return Some(local);
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn crate_application_state_extractor(argument_names: Punctuated<Pat, Comma>) -> Option<Stmt> {
|
||||||
|
if !argument_names.is_empty() {
|
||||||
|
let use_item: Stmt = parse_quote!(let ApplicationState { #argument_names } = state;);
|
||||||
|
return Some(use_item);
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn params_argument() -> FnArg {
|
||||||
|
parse2(quote! {
|
||||||
|
tuono_lib::axum::extract::Path(params): tuono_lib::axum::extract::Path<
|
||||||
|
std::collections::HashMap<String, String>
|
||||||
|
>
|
||||||
|
})
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn request_argument() -> FnArg {
|
||||||
|
parse2(quote! {
|
||||||
|
request: tuono_lib::axum::extract::Request
|
||||||
|
})
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
@@ -15,14 +15,3 @@ $ tuono new [NAME] --template [TEMPLATE]
|
|||||||
```
|
```
|
||||||
|
|
||||||
`[TEMPLATE]` is the folder name.
|
`[TEMPLATE]` is the folder name.
|
||||||
|
|
||||||
## Troubleshooting for contributors
|
|
||||||
|
|
||||||
There is a common error that happens during example development due to
|
|
||||||
pnpm workspace about the findings of different react versions.
|
|
||||||
|
|
||||||
To overcome this issue run within the single example folder:
|
|
||||||
|
|
||||||
```
|
|
||||||
pnpm install --ignore-workspace && pnpm upgrade --save
|
|
||||||
```
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "tuono"
|
name = "tuono-app"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "tuono",
|
"name": "tuono-app",
|
||||||
"description": "The react/rust fullstack framework",
|
"description": "Basic tuono application",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"react": "18.3.1",
|
"react": "18.3.1",
|
||||||
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 4.6 KiB |
|
Before Width: | Height: | Size: 8.3 KiB After Width: | Height: | Size: 8.3 KiB |
@@ -1,4 +1,4 @@
|
|||||||
import type { ReactNode } from 'react'
|
import type { ReactNode, JSX } from 'react'
|
||||||
|
|
||||||
interface RootRouteProps {
|
interface RootRouteProps {
|
||||||
children: ReactNode
|
children: ReactNode
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
use tuono_lib::Request;
|
||||||
|
use tuono_lib::axum::http::StatusCode;
|
||||||
|
|
||||||
|
#[tuono_lib::api(GET)]
|
||||||
|
pub async fn my_get_request(_req: Request) -> StatusCode {
|
||||||
|
StatusCode::OK
|
||||||
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use tuono_lib::reqwest;
|
|
||||||
use tuono_lib::{Props, Request, Response};
|
use tuono_lib::{Props, Request, Response};
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
@@ -8,7 +7,7 @@ struct MyResponse<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tuono_lib::handler]
|
#[tuono_lib::handler]
|
||||||
async fn get_server_side_props(_req: Request, _fetch: reqwest::Client) -> Response {
|
async fn get_server_side_props(_req: Request) -> Response {
|
||||||
Response::Props(Props::new(MyResponse {
|
Response::Props(Props::new(MyResponse {
|
||||||
subtitle: "The react / rust fullstack framework",
|
subtitle: "The react / rust fullstack framework",
|
||||||
}))
|
}))
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type { JSX } from 'react'
|
||||||
import type { TuonoProps } from 'tuono'
|
import type { TuonoProps } from 'tuono'
|
||||||
|
|
||||||
interface IndexProps {
|
interface IndexProps {
|
||||||
@@ -23,7 +23,7 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
main {
|
main {
|
||||||
width: 673px;
|
max-width: 673px;
|
||||||
margin: 20px auto;
|
margin: 20px auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "tuono"
|
name = "tuono-tutorial"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
@@ -10,4 +10,5 @@ path = ".tuono/main.rs"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
tuono_lib = { path = "../../crates/tuono_lib/"}
|
tuono_lib = { path = "../../crates/tuono_lib/"}
|
||||||
serde = { version = "1.0.202", features = ["derive"] }
|
serde = { version = "1.0.202", features = ["derive"] }
|
||||||
|
reqwest = "0.12.9"
|
||||||
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# Tuono tutorial
|
||||||
|
|
||||||
|
This project is the outcome of the [tuono tutorial](https://tuono.dev/documentation/tutorial)
|
||||||
|
|
||||||
|
If you want to directly install it you can run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ tuono new my-project -t tuono-tutorial
|
||||||
|
```
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "tuono-tutorial",
|
"name": "tuono-tutorial",
|
||||||
"description": "The react/rust fullstack framework",
|
"description": "The basic tutorial for tuono applications",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"react": "18.3.1",
|
"react": "18.3.1",
|
||||||
|
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 39 KiB |
|
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 4.6 KiB |
|
Before Width: | Height: | Size: 8.3 KiB After Width: | Height: | Size: 8.3 KiB |
@@ -0,0 +1,11 @@
|
|||||||
|
use reqwest::Client;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct ApplicationState {
|
||||||
|
pub fetch: Client,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn main() -> ApplicationState {
|
||||||
|
let fetch = Client::new();
|
||||||
|
return ApplicationState { fetch };
|
||||||
|
}
|
||||||