Updates and build chain improvements

This commit is contained in:
Gender Shrapnel 2022-07-27 12:58:22 +02:00
parent 7d42fff1fb
commit 3265015284
Signed by: modzero
GPG Key ID: 4E11A06C6D1E5213
20 changed files with 5865 additions and 207 deletions

14
.eslintignore Normal file
View File

@ -0,0 +1,14 @@
.DS_Store
node_modules
/dist
.env
.env.*
!.env.example
# Ignore files for PNPM, NPM and YARN
pnpm-lock.yaml
package-lock.json
yarn.lock
/src-tauri
/target

24
.eslintrc.cjs Normal file
View File

@ -0,0 +1,24 @@
module.exports = {
root: true,
parser: "@typescript-eslint/parser",
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
],
plugins: ["svelte3", "@typescript-eslint"],
ignorePatterns: ["*.cjs"],
overrides: [{ files: ["*.svelte"], processor: "svelte3/svelte3" }],
settings: {
"svelte3/typescript": () => require("typescript"),
},
parserOptions: {
sourceType: "module",
ecmaVersion: 2020,
},
env: {
browser: true,
es2017: true,
node: true,
},
};

8
.gitignore vendored
View File

@ -8,10 +8,11 @@ pnpm-debug.log*
lerna-debug.log* lerna-debug.log*
node_modules node_modules
dist /dist/*
dist-ssr /dist-ssr/*
*.local *.local
# Editor directories and files # Editor directories and files
.vscode/* .vscode/*
!.vscode/extensions.json !.vscode/extensions.json
@ -24,3 +25,6 @@ dist-ssr
*.njsproj *.njsproj
*.sln *.sln
*.sw? *.sw?
!/**/.gitkeep
/target/

15
.prettierignore Normal file
View File

@ -0,0 +1,15 @@
.DS_Store
node_modules
/build
/package
.env
.env.*
!.env.example
# Ignore files for PNPM, NPM and YARN
pnpm-lock.yaml
package-lock.json
yarn.lock
/src-tauri
/target

View File

@ -1,19 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run" type="CargoCommandRunConfiguration" factoryName="Cargo Command" singleton="false">
<option name="command" value="run --manifest-path ./src-tauri/Cargo.toml --no-default-features" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
<option name="channel" value="DEFAULT" />
<option name="requiredFeatures" value="true" />
<option name="allFeatures" value="false" />
<option name="emulateTerminal" value="false" />
<option name="withSudo" value="false" />
<option name="buildTarget" value="REMOTE" />
<option name="backtrace" value="SHORT" />
<envs />
<option name="isRedirectInput" value="false" />
<option name="redirectInputPath" value="" />
<method v="2">
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
</method>
</configuration>
</component>

View File

@ -1,19 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Tauri Dev" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
<option name="command" value="tauri dev" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
<option name="channel" value="DEFAULT" />
<option name="requiredFeatures" value="true" />
<option name="allFeatures" value="false" />
<option name="emulateTerminal" value="false" />
<option name="withSudo" value="false" />
<option name="buildTarget" value="REMOTE" />
<option name="backtrace" value="SHORT" />
<envs />
<option name="isRedirectInput" value="false" />
<option name="redirectInputPath" value="" />
<method v="2">
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
</method>
</configuration>
</component>

View File

@ -1,12 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="UI Dev Build" type="js.build_tools.npm" singleton="false">
<package-json value="$PROJECT_DIR$/package.json" />
<command value="run" />
<scripts>
<script value="dev" />
</scripts>
<node-interpreter value="project" />
<envs />
<method v="2" />
</configuration>
</component>

78
.vscode/launch.json vendored
View File

@ -1,37 +1,47 @@
{ {
// Use IntelliSense to learn about possible attributes. // Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes. // Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"type": "lldb", "type": "lldb",
"request": "launch", "request": "launch",
"name": "Tauri Development Debug", "name": "Debug Tauri Development",
"cargo": { "cargo": {
"args": [ "args": [
"build", "build",
"--manifest-path=./src-tauri/Cargo.toml", "--bin=ziemniak",
"--no-default-features" "--package=ziemniak",
] "--no-default-features"
}, ]
// task for the `beforeDevCommand` if used, must be configured in `.vscode/tasks.json`
"preLaunchTask": "ui:dev"
}, },
{ // task for the `beforeDevCommand` if used, must be configured in `.vscode/tasks.json`
"type": "lldb", "preLaunchTask": "ui:dev"
"request": "launch", },
"name": "Tauri Production Debug", {
"cargo": { "type": "lldb",
"args": [ "request": "launch",
"build", "name": "Debug Tauri Unit Tests",
"--release", "cargo": {
"--manifest-path=./src-tauri/Cargo.toml" "args": ["test", "--no-run", "--bin=ziemniak", "--package=ziemniak"],
] "filter": {
}, "name": "ziemniak",
// task for the `beforeBuildCommand` if used, must be configured in `.vscode/tasks.json` "kind": "bin"
"preLaunchTask": "ui:build" }
}, },
] "args": [],
} "cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Tauri Production Debug",
"cargo": {
"args": ["build", "--release", "--manifest-path=./src-tauri/Cargo.toml"]
},
// task for the `beforeBuildCommand` if used, must be configured in `.vscode/tasks.json`
"preLaunchTask": "ui:build"
}
]
}

74
.vscode/tasks.json vendored
View File

@ -1,45 +1,33 @@
{ {
// See https://go.microsoft.com/fwlink/?LinkId=733558 // See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format // for the documentation about the tasks.json format
"version": "2.0.0", "version": "2.0.0",
"tasks": [ "tasks": [
{ {
"label": "tauri:dev", "label": "tauri:dev",
"type": "shell", "type": "shell",
"command": "cargo", "command": "cargo",
"problemMatcher": [], "problemMatcher": [],
"args": [ "args": ["tauri", "dev"],
"tauri", "icon": {
"dev" "id": "run"
],
"icon": {
"id": "run"
},
},
{
"label": "ui:dev",
"type": "shell",
"isBackground": true,
"command": "npm",
"problemMatcher": [],
"args": [
"run",
"dev",
"--",
"--clearScreen",
"false"
]
},
{
"label": "ui:build",
"group": "build",
"type": "shell",
"command": "npm",
"problemMatcher": [],
"args": [
"run",
"build"
]
} }
], },
} {
"label": "ui:dev",
"type": "shell",
"isBackground": true,
"command": "npm",
"problemMatcher": [],
"args": ["run", "dev", "--", "--clearScreen", "false"]
},
{
"label": "ui:build",
"group": "build",
"type": "shell",
"command": "npm",
"problemMatcher": [],
"args": ["run", "build"]
}
]
}

3732
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 = ["src-tauri"]

View File

@ -21,8 +21,8 @@ the Free Software Foundation, either version 3 of the License, or
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details. GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.

1948
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -9,22 +9,31 @@
"build": "vite build", "build": "vite build",
"preview": "vite preview", "preview": "vite preview",
"check": "svelte-check --tsconfig ./tsconfig.json", "check": "svelte-check --tsconfig ./tsconfig.json",
"tauri": "tauri" "tauri": "tauri",
"lint": "prettier --check --plugin-search-dir=. . && eslint .",
"format": "prettier --write --plugin-search-dir=. ."
}, },
"devDependencies": { "devDependencies": {
"@sveltejs/vite-plugin-svelte": "^1.0.1", "@sveltejs/vite-plugin-svelte": "^1.0.1",
"@tauri-apps/cli": "^1.0.5", "@tauri-apps/cli": "^1.0.5",
"@typescript-eslint/eslint-plugin": "^5.31.0",
"@typescript-eslint/parser": "^5.31.0",
"@tsconfig/svelte": "^3.0.0", "@tsconfig/svelte": "^3.0.0",
"@types/luxon": "^3.0.0", "@types/luxon": "^3.0.0",
"luxon": "^3.0.1", "eslint": "^8.20.0",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-svelte3": "^4.0.0",
"prettier": "^2.7.1",
"prettier-plugin-svelte": "^2.7.0",
"svelte": "^3.49.0", "svelte": "^3.49.0",
"svelte-check": "^2.8.0", "svelte-check": "^2.8.0",
"svelte-preprocess": "^4.10.7", "svelte-preprocess": "^4.10.7",
"tslib": "^2.4.0", "tslib": "^2.4.0",
"typescript": "^4.6.4", "typescript": "^4.7.4",
"vite": "^3.0.0" "vite": "^3.0.0"
}, },
"dependencies": { "dependencies": {
"@tauri-apps/api": "^1.0.2" "@tauri-apps/api": "^1.0.2",
"luxon": "^3.0.1"
} }
} }

View File

@ -1,3 +0,0 @@
# Generated by Cargo
# will have compiled files and executables
/target/

View File

@ -21,19 +21,19 @@ struct Timer {
impl Timer { impl Timer {
fn new(message: &str, duration: Duration) -> Self { fn new(message: &str, duration: Duration) -> Self {
return Self { Self {
id: Uuid::new_v4(), id: Uuid::new_v4(),
duration: duration, duration,
message: message.to_string(), message: message.to_string(),
..Default::default() ..Default::default()
}; }
} }
fn complete(self: &Self) -> bool { fn complete(&self) -> bool {
return self.elapsed.map_or(false, |e| e >= self.duration); self.elapsed.map_or(false, |e| e >= self.duration)
} }
async fn run(self: &mut Self, window: Window) { async fn run(&mut self, window: Window) {
self.started = Some(Local::now().into()); self.started = Some(Local::now().into());
let mut elapsed = Duration::from_secs(0); let mut elapsed = Duration::from_secs(0);
self.elapsed = Some(elapsed); self.elapsed = Some(elapsed);
@ -45,14 +45,14 @@ impl Timer {
let now = Instant::now(); let now = Instant::now();
let duration = now - last_checked; let duration = now - last_checked;
elapsed = elapsed + duration; elapsed += duration;
self.elapsed = Some(elapsed); self.elapsed = Some(elapsed);
if self.complete() { if self.complete() {
break; break;
} }
if let Err(_) = window.emit("timer-tick", self.clone()) { if window.emit("timer-tick", self.clone()).is_err() {
break; break;
} }
last_checked = now; last_checked = now;
@ -67,7 +67,7 @@ impl Timer {
#[tauri::command] #[tauri::command]
fn start_timer(window: Window, duration: Duration, message: &str) -> Uuid { fn start_timer(window: Window, duration: Duration, message: &str) -> Uuid {
let mut timer = Timer::new(message, duration); let mut timer = Timer::new(message, duration);
let timer_id = timer.id.clone(); let timer_id = timer.id;
spawn(async move { spawn(async move {
timer.run(window).await; timer.run(window).await;

View File

@ -1,25 +1,41 @@
<script> <script type="ts">
import { onDestroy } from 'svelte' import { onDestroy, onMount } from "svelte";
import { invoke } from '@tauri-apps/api' import type { UnlistenFn } from "@tauri-apps/api/event";
import { listen, once } from '@tauri-apps/api/event' import { invoke } from "@tauri-apps/api";
import { listen } from "@tauri-apps/api/event";
let seconds = 5 let seconds = 5;
let timer_tick_unlisten: Promise<UnlistenFn> | null = null;
let timer_done_unlisten: Promise<UnlistenFn> | null = null;
type Timer = {
id: string;
elapsed: {
secs: number;
nsecs: number;
};
};
onMount(() => {
timer_tick_unlisten = listen<Timer>("timer-tick", (event) => {
console.log("Tick!", event.payload.id, event.payload.elapsed);
});
timer_done_unlisten = listen<Timer>("timer-done", (event) => {
console.log("Done!", event.payload.id);
});
});
onDestroy(() => {
timer_tick_unlisten?.then((ttu) => ttu());
timer_done_unlisten?.then((tdu) => tdu());
});
function start_timer() { function start_timer() {
invoke('start_timer', { invoke("start_timer", {
duration: { secs: seconds, nanos: 0 }, duration: { secs: seconds, nanos: 0 },
message: "Hi!", message: "Hi!",
}) });
let timer_tick_unlisten = listen('timer-tick', (event) => {
console.log("Tick!", event.payload.id, event.payload.elapsed)
})
once('timer-done', (event) => {
console.log("Done!", event.payload.id)
timer_tick_unlisten.then(ttu => ttu())
})
} }
</script> </script>
@ -28,5 +44,5 @@
Fire after Fire after
<input type="number" bind:value={seconds} /> <input type="number" bind:value={seconds} />
</label> </label>
<button on:click="{start_timer}">Fire!</button> <button on:click={start_timer}>Fire!</button>
</main> </main>

View File

@ -1,8 +1,10 @@
import './app.css' import "./app.css";
import App from './App.svelte' import App from "./App.svelte";
const app = new App({ const app = new App({
target: document.getElementById('app') target: document.getElementById("app"),
}) });
export default app;
export default app

View File

@ -1,7 +1,7 @@
import sveltePreprocess from 'svelte-preprocess' import sveltePreprocess from "svelte-preprocess";
export default { export default {
// Consult https://github.com/sveltejs/svelte-preprocess // Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors // for more information about preprocessors
preprocess: sveltePreprocess() preprocess: sveltePreprocess(),
} };

View File

@ -1,10 +1,11 @@
import { defineConfig } from 'vite' import { defineConfig } from "vite";
import { svelte } from '@sveltejs/vite-plugin-svelte' import { svelte } from "@sveltejs/vite-plugin-svelte";
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig({
plugins: [svelte()], plugins: [svelte()],
build: { build: {
write: true write: true,
} },
}) });