Structure overhaul and added Github Pages

This commit is contained in:
Simon Hyll
2023-07-01 12:57:33 +02:00
parent 58d66706d0
commit 11558eafcc
63 changed files with 13363 additions and 530 deletions

4
.dockerignore Normal file
View File

@@ -0,0 +1,4 @@
.git/
target/
node_modules/
crates/*/node_modules/

5
.gitattributes vendored
View File

@@ -1,4 +1,5 @@
*.png filter=lfs diff=lfs merge=lfs -text
*.ico filter=lfs diff=lfs merge=lfs -text
*.jpg filter=lfs diff=lfs merge=lfs -text
*.jpeg filter=lfs diff=lfs merge=lfs -text
*.jpg filter=lfs diff=lfs merge=lfs -text
*.icn filter=lfs diff=lfs merge=lfs -text
*.icns filter=lfs diff=lfs merge=lfs -text

59
.github/workflows/pages.yaml vendored Normal file
View File

@@ -0,0 +1,59 @@
name: Deploy site to Pages
on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]
paths:
- "crates/frontend"
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Allow one concurrent deployment
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
jobs:
# Build job
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
lfs: true
- uses: pnpm/action-setup@v2
with:
version: latest
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: "20"
- name: Install dependencies
run: pnpm install -r --frozen-lockfile
- name: Generate project
run: cd crates/frontend && pnpm generate
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
path: ./crates/frontend/dist
# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1

25
.gitignore vendored
View File

@@ -1,23 +1,2 @@
# Nuxt dev/build outputs
.output
.nuxt
.nitro
.cache
dist
# Node dependencies
node_modules
# Logs
logs
*.log
# Misc
.DS_Store
.fleet
.idea
# Local env files
.env
.env.*
!.env.example
target/
node_modules/

4571
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

2
Cargo.toml Normal file
View File

@@ -0,0 +1,2 @@
[workspace]
members = ["crates/backend"]

View File

@@ -1,63 +1,23 @@
# Nuxt 3 Minimal Starter
<div align="center">
Look at the [Nuxt 3 documentation](https://nuxt.com/docs/getting-started/introduction) to learn more.
# Tauri Board Voter
## Setup
A voting system
Make sure to install the dependencies:
</div>
## Getting started
```bash
# npm
npm install
# pnpm
pnpm install
# yarn
yarn install
pnpm i -r
cd crates/backend
pnpm tauri dev
```
## Development Server
## Tests
Start the development server on `http://localhost:3000`:
You can run the projects tests using Docker. You don't need Docker but it's the easiest method by far after you've ran it once.
```bash
# npm
npm run dev
# pnpm
pnpm run dev
# yarn
yarn dev
docker build -f docker/test.dockerfile -t throwaway .
```
## Production
Build the application for production:
```bash
# npm
npm run build
# pnpm
pnpm run build
# yarn
yarn build
```
Locally preview production build:
```bash
# npm
npm run preview
# pnpm
pnpm run preview
# yarn
yarn preview
```
Check out the [deployment documentation](https://nuxt.com/docs/getting-started/deployment) for more information.

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e691280cae6a39417eb198a3a543167222e9bad8b420f0509380c4ba5324f985
size 11165

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:3f03d428590b40380904525cabbf03b2fd07a458169b0dbb48fb3e8ec5772341
size 23892

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:2c42ee26f12de144e7ebeb670cfc8a24c01d80d74e405fb892db9ff0cf2d95d4
size 2233

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:982c7457b999e7f4333f5820fda69eaed56532730f9e4ac5cca62af830bd5a55
size 9234

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:1fa4f63d2bf1e39f1869ddd4aa39d20e975eb7fcb0e585cb7ee5299b4ea56c6f
size 12645

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:09b0dafb677185b65ead0f7a4c2888fa28d44cf8156b42a663563ae849efca91
size 13234

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:d010ab26db476c2b04af09a5625972d7b0c8e0d9708c9f86061253bba8a594f8
size 26727

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:1f96e8d43372f87d3d2f625ebc41becf12d734ef4265f8da8424ff8a08d9200b
size 2081

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:48b1d9504907e50942437a247c5067ad22663d0bc5753076754428e090adedb0
size 29716

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:40e680763ef156e18dfbae7327718b42e0ea9e63a05c5c6f2383de65f4e6651a
size 3432

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:7b2c261bd2c489d64ec391d5904ef86579428b8e7f08b4a132749765646cc642
size 6074

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:ddb8f333601105639afd271917b94c2eddd1c374f2585cb64eaa4885b8690c75
size 7624

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:012bd1a4f97b340a07b91148095ce143edd9e484a3f35bf66fb00529568a918e
size 3991

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:c3f111822990e78caf28176657a19ea1544ea3ea227777f788115afdee172ee9
size 354626

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:2f06824f3dedfbd53655166258c1760afa07f561863737ab21bc92c15211e851
size 49691

View File

@@ -0,0 +1,20 @@
{
"name": "backend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "wdio run wdio.conf.js"
},
"keywords": [
"tauri"
],
"author": "Simon Hyll <hyllsimon@gmail.com>",
"dependencies": {
"@tauri-apps/cli": "^1.4.0",
"@wdio/cli": "^8.11.2",
"@wdio/local-runner": "^8.11.2",
"@wdio/mocha-framework": "^8.11.0",
"@wdio/spec-reporter": "^8.11.2"
}
}

View File

@@ -2,7 +2,7 @@
"$schema": "../node_modules/@tauri-apps/cli/schema.json",
"build": {
"beforeBuildCommand": "pnpm generate",
"beforeDevCommand": "pnpm dev",
"beforeDevCommand": "cd ../frontend && pnpm dev",
"devPath": "http://localhost:3000",
"distDir": "../dist"
},

View File

@@ -0,0 +1,32 @@
// calculates the luma from a hex color `#abcdef`
function luma(hex) {
if (hex.startsWith('#')) {
hex = hex.substring(1)
}
const rgb = parseInt(hex, 16)
const r = (rgb >> 16) & 0xff
const g = (rgb >> 8) & 0xff
const b = (rgb >> 0) & 0xff
return 0.2126 * r + 0.7152 * g + 0.0722 * b
}
describe('Hello Tauri', () => {
it('should be cordial', async () => {
const header = await $('body > h1')
const text = await header.getText()
expect(text).toMatch(/^[hH]ello/)
})
it('should be excited', async () => {
const header = await $('body > h1')
const text = await header.getText()
expect(text).toMatch(/!$/)
})
it('should be easy on the eyes', async () => {
const body = await $('body')
const backgroundColor = await body.getCSSProperty('background-color')
expect(luma(backgroundColor.parsed.hex)).toBeLessThan(100)
})
})

View File

@@ -0,0 +1,39 @@
const os = require('os')
const path = require('path')
const { spawn, spawnSync } = require('child_process')
// keep track of the `tauri-driver` child process
let tauriDriver
exports.config = {
specs: ['./tests/specs/**/*.js'],
maxInstances: 1,
capabilities: [
{
maxInstances: 1,
'tauri:options': {
application: '../../target/debug/app',
},
},
],
reporters: ['spec'],
framework: 'mocha',
mochaOpts: {
ui: 'bdd',
timeout: 60000,
},
// ensure the rust project is built since we expect this binary to exist for the webdriver sessions
onPrepare: () => spawnSync('cargo', ['build']),
// ensure we are running `tauri-driver` before the session starts so that we can proxy the webdriver requests
beforeSession: () =>
(tauriDriver = spawn(
path.resolve(os.homedir(), '.cargo', 'bin', 'tauri-driver'),
[],
{ stdio: [null, process.stdout, process.stderr] }
)),
// clean up the `tauri-driver` process we spawned at the start of the session
afterSession: () => tauriDriver.kill(),
}

4
crates/frontend/.gitattributes vendored Normal file
View File

@@ -0,0 +1,4 @@
*.png filter=lfs diff=lfs merge=lfs -text
*.ico filter=lfs diff=lfs merge=lfs -text
*.jpg filter=lfs diff=lfs merge=lfs -text
*.jpeg filter=lfs diff=lfs merge=lfs -text

23
crates/frontend/.gitignore vendored Normal file
View File

@@ -0,0 +1,23 @@
# Nuxt dev/build outputs
.output
.nuxt
.nitro
.cache
dist
# Node dependencies
node_modules
# Logs
logs
*.log
# Misc
.DS_Store
.fleet
.idea
# Local env files
.env
.env.*
!.env.example

63
crates/frontend/README.md Normal file
View File

@@ -0,0 +1,63 @@
# Nuxt 3 Minimal Starter
Look at the [Nuxt 3 documentation](https://nuxt.com/docs/getting-started/introduction) to learn more.
## Setup
Make sure to install the dependencies:
```bash
# npm
npm install
# pnpm
pnpm install
# yarn
yarn install
```
## Development Server
Start the development server on `http://localhost:3000`:
```bash
# npm
npm run dev
# pnpm
pnpm run dev
# yarn
yarn dev
```
## Production
Build the application for production:
```bash
# npm
npm run build
# pnpm
pnpm run build
# yarn
yarn build
```
Locally preview production build:
```bash
# npm
npm run preview
# pnpm
pnpm run preview
# yarn
yarn preview
```
Check out the [deployment documentation](https://nuxt.com/docs/getting-started/deployment) for more information.

6701
crates/frontend/pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

73
docker/test.dockerfile Normal file
View File

@@ -0,0 +1,73 @@
ARG CRATE=backend
ARG TAURI_DEPENDENCIES="build-essential curl libappindicator3-dev libgtk-3-dev librsvg2-dev libssl-dev libwebkit2gtk-4.1-dev wget libappimage-dev"
ARG EXTRA_DEPENDENCIES="webkit2gtk-driver xvfb"
ARG PNPM_VERSION="8.6.5"
######################################
## Base image
## Installing dependencies
######################################
FROM rust:1.70-slim-bookworm AS chef
WORKDIR /app
# Redefine arguments
ARG TAURI_DEPENDENCIES
ARG EXTRA_DEPENDENCIES
ARG PNPM_VERSION
# Install dependencies
RUN apt update \
&& apt install -yq ${TAURI_DEPENDENCIES} \
&& apt install -yq git openssh-client libssl-dev pkg-config ${EXTRA_DEPENDENCIES} \
&& curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
&& apt install -yq nodejs \
&& corepack enable \
&& corepack prepare pnpm@${PNPM_VERSION} --activate \
&& pnpm config set store-dir /usr/.pnpm-store \
&& cargo install cargo-chef tauri-driver
######################################
## Planner image
## Creating a cargo chef plan
## Done separately because of COPY
######################################
FROM chef AS planner
# Copy source code, doing it here in a separate image because otherwise caching would be broken too early
COPY . .
# Create a recipe.json that cargo-chef uses to know which dependencies to prepare
RUN cargo chef prepare --recipe-path recipe.json
######################################
## Builder image
## Running the tests
######################################
FROM chef AS builder
# Redefine arguments
ARG CRATE
# Copy the pnpm lockfile
COPY pnpm-lock.yaml .npmrc ./
# Copy the recipe
COPY --from=planner /app/recipe.json recipe.json
# Installs all cargo dependencies
RUN cargo chef cook --tests -p ${CRATE} \
# Use pnpm fetch to use the lockfile for getting dependencies
&& pnpm fetch
# Copy source code
COPY . .
# Make sure primarily tauri-driver is available in the root users home dir
RUN ln -s /usr/local/cargo $HOME/.cargo \
# Install pnpm dependencies from the already fetched dependencies
&& pnpm i -r --offline
# Run commands inside the crate
WORKDIR /app/crates/${CRATE}
# Run regular Cargo tests
RUN cargo test
# Use xvfb to enable running headlessly
RUN xvfb-run pnpm test
######################################
## Final
## Ensures the optimizer doesn't skip
## running the other images
######################################
FROM scratch
# Could've been any file but this one we know exists and isn't that large
COPY --from=builder /app/recipe.json recipe.json

2081
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

3
pnpm-workspace.yaml Normal file
View File

@@ -0,0 +1,3 @@
packages:
- crates/backend
- crates/frontend

View File

@@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:eeebf55d8ffe07348786b9057af253e3ca08c56b6a8f8893826381430e3c0b7b
size 11059

View File

@@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:2998b41d0c9278b08e8b3874e094920034fe983a46053c9d62764225f58ab7b0
size 23137

View File

@@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:aaa96d0c53b756b77c7f46aeb72290f42256c786c69be68f6bcdeb9c7492a48e
size 2225

View File

@@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:33446a858d982a529554e562114673f8b15620588137cf0bf6c56a7441c78cd7
size 9202

View File

@@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:633d6dba504faa844b309e01272386e4523cddd4a3639c77c0eb5d2ce3eac752
size 12530

View File

@@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:d90061ad71e6f5882b759d80cf58cc16aa5021fa29ba4b2614adea982a4d7ee5
size 13032

View File

@@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:5feaa4f18f404843551756dd2791d7654ef471b6b007767ae40f60c7aebcad5b
size 25943

View File

@@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:68bc1b585f5685e0922f14b1ca7eb2d618213c684c89e759c6a5eb8578c3fe8d
size 2078

View File

@@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:5df8d779ab57c63ee06ed237b94c3c0954711e88117dccfa72b2aec5d83b0d80
size 28507

View File

@@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:c46208286b1ea1b4841b714972f3cb0a8abc6d3bfa71a29238f7b4d62f511f89
size 3419

View File

@@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:cb0ea93cbd13509d32c6bc06da71687e73d673d166fde91b23061771abe16b86
size 6027

View File

@@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:2208da1d741a20e902a59d7c39a5e58af74ec823db13113bf8ac6f555fa25bca
size 7551

View File

@@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:9f84d0ce09df51bac0a4855042b3e49b190cc2b9761cd5eab61ebec5cd343820
size 3971

Binary file not shown.

View File

@@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e38ca88e1d5490f3dcbc3c3fa525f7fcb7b80fff3cb2f3a4eb1b2d018c0915c1
size 37710

View File

@@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6413bfe9d546e5225fc9256a0ecec48df3a1272ea4bdc91c15b8e000222a95d3
size 49979