initialize boilerplate with examples

This commit is contained in:
neil 2022-11-17 20:22:51 +08:00
commit c537621942
50 changed files with 6129 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
node_modules
yarn-error.log

18
README.md Normal file
View file

@ -0,0 +1,18 @@
# Tea UI Workspace
This repository includes the tea GUI/Desktop App.
# Requirements
* [pnpm@^7.8](https://pnpm.io/)
* [node@16](https://github.com/tj/n)
* [rust@^1.62](https://www.rust-lang.org/)
* [cargo@^1.62](https://crates.io/)
# Development
Setting up the workspace just run here:
```
$ pnpm install
```
Refer to each package README.md for instructions on how to setup and contribue to them:
* [tea/gui](./packages/gui/README.md)

10
package.json Normal file
View file

@ -0,0 +1,10 @@
{
"name": "@tea/workspace",
"author": "neil molina <neil@tea.xyz>",
"private": true,
"workspaces": {
"packages": [
"packages/*"
]
}
}

View file

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

View file

@ -0,0 +1,20 @@
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
packages/gui/.gitignore vendored Normal file
View file

@ -0,0 +1,8 @@
.DS_Store
node_modules
/build
/.svelte-kit
/package
.env
.env.*
!.env.example

1
packages/gui/.npmrc Normal file
View file

@ -0,0 +1 @@
engine-strict=true

View file

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

9
packages/gui/.prettierrc Normal file
View file

@ -0,0 +1,9 @@
{
"useTabs": true,
"singleQuote": true,
"trailingComma": "none",
"printWidth": 100,
"plugins": ["prettier-plugin-svelte"],
"pluginSearchDirs": ["."],
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
}

View file

@ -0,0 +1,4 @@
*
!src/**/*
!src-tauri/**/*

29
packages/gui/README.md Normal file
View file

@ -0,0 +1,29 @@
# @tea/gui
Desktop app of [tea](https://tea.xyz) for installing packages/softwares
## Developing
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
```bash
pnpm tauri dev
# or start the server and open the app in a new browser tab
pnpm run dev -- --open
```
## Building
To create a production version of your app:
```bash
pnpm run build
```
You can preview the production build with `npm run preview`.
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
## Intuition Building Links
* [Rust module system is weird?](https://www.sheshbabu.com/posts/rust-module-system/)

41
packages/gui/package.json Normal file
View file

@ -0,0 +1,41 @@
{
"name": "@tea/gui",
"version": "0.0.0",
"private": true,
"scripts": {
"tauri": "tauri",
"dev": "vite dev --port 8080",
"build": "vite build",
"preview": "vite preview",
"test": "playwright test",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --plugin-search-dir . --check . && eslint .",
"format": "prettier --plugin-search-dir . --write ."
},
"devDependencies": {
"@playwright/test": "1.25.0",
"@sveltejs/adapter-auto": "next",
"@sveltejs/adapter-static": "1.0.0-next.48",
"@sveltejs/kit": "next",
"@tauri-apps/cli": "1.1.1",
"@typescript-eslint/eslint-plugin": "^5.27.0",
"@typescript-eslint/parser": "^5.27.0",
"eslint": "^8.16.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-svelte3": "^4.0.0",
"prettier": "^2.6.2",
"prettier-plugin-svelte": "^2.7.0",
"svelte": "^3.49.0",
"svelte-check": "^2.8.0",
"svelte-preprocess": "^4.10.7",
"tslib": "^2.3.1",
"typescript": "^4.7.4",
"vite": "^3.1.0"
},
"type": "module",
"dependencies": {
"@tauri-apps/api": "^1.2.0",
"buffer": "^6.0.3"
}
}

View file

@ -0,0 +1,10 @@
import type { PlaywrightTestConfig } from '@playwright/test';
const config: PlaywrightTestConfig = {
webServer: {
command: 'npm run build && npm run preview',
port: 4173
}
};
export default config;

3
packages/gui/src-tauri/.gitignore vendored Normal file
View file

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

3747
packages/gui/src-tauri/Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,33 @@
[package]
name = "app"
version = "0.1.0"
description = "A Tauri App"
authors = ["you"]
license = ""
repository = ""
default-run = "app"
edition = "2021"
rust-version = "1.59"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[build-dependencies]
tauri-build = { version = "1.2.0", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.2.0", features = ["http-all"] }
uuid = "1.2.1"
reqwest = { version = "0.11", features = ["json", "blocking"] }
hyper = { version = "0.14", features = ["full"] }
tokio = { version = "1", features = ["full"] }
futures = "0.3"
[features]
# by default Tauri runs in production mode
# when `tauri dev` runs it is executed with `cargo run --no-default-features` if `devPath` is an URL
default = [ "custom-protocol" ]
# this feature is used for production builds where `devPath` points to the filesystem
# DO NOT remove this
custom-protocol = [ "tauri/custom-protocol" ]

View file

@ -0,0 +1,3 @@
fn main() {
tauri_build::build()
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 974 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 903 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View file

@ -0,0 +1 @@
pub mod packages;

View file

@ -0,0 +1,4 @@
#[tauri::command]
pub fn install_package(package: String) {
println!("installing: {}", package);
}

View file

@ -0,0 +1,15 @@
#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]
mod handlers;
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![
handlers::packages::install_package,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

View file

@ -0,0 +1,70 @@
{
"$schema": "../../../node_modules/@tauri-apps/cli/schema.json",
"build": {
"beforeBuildCommand": "pnpm build",
"beforeDevCommand": "pnpm dev",
"devPath": "http://localhost:8080",
"distDir": "../dist"
},
"package": {
"productName": "gui",
"version": "0.1.0"
},
"tauri": {
"allowlist": {
"http": {
"all": true,
"request": true,
"scope": ["https://api.tea.xyz/v1/*"]
}
},
"bundle": {
"active": true,
"category": "DeveloperTool",
"copyright": "",
"deb": {
"depends": []
},
"externalBin": [],
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
],
"identifier": "com.tauri.dev",
"longDescription": "",
"macOS": {
"entitlements": null,
"exceptionDomain": "",
"frameworks": [],
"providerShortName": null,
"signingIdentity": null
},
"resources": [],
"shortDescription": "",
"targets": "all",
"windows": {
"certificateThumbprint": null,
"digestAlgorithm": "sha256",
"timestampUrl": ""
}
},
"security": {
"csp": null
},
"updater": {
"active": false
},
"windows": [
{
"fullscreen": false,
"height": 600,
"resizable": true,
"title": "gui",
"width": 800
}
]
}
}

9
packages/gui/src/app.d.ts vendored Normal file
View file

@ -0,0 +1,9 @@
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
// and what to do when importing types
declare namespace App {
// interface Locals {}
// interface PageData {}
// interface Error {}
// interface Platform {}
}

12
packages/gui/src/app.html Normal file
View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width" />
%sveltekit.head%
</head>
<body>
<div>%sveltekit.body%</div>
</body>
</html>

View file

@ -0,0 +1,32 @@
import { getClient } from '@tauri-apps/api/http';
import { Buffer } from 'buffer';
const username = 'user';
const password = 'password';
const auth = 'Basic ' + Buffer.from(username + ':' + password).toString('base64');
const base = 'https://api.tea.xyz/v1';
export async function get<T>(path: string){
const client = await getClient();
const uri = join(base, path);
const { data } = await client.get<T>(uri.toString(), {
headers: {
Authorization: auth
}
});
return data;
}
const join = function(...paths: string[]){
return paths.map(function(path){
if(path[0] === "/"){
path = path.slice(1);
}
if(path[path.length - 1] === "/"){
path = path.slice(0, path.length - 1);
}
return path;
}).join("/");
}

View file

@ -0,0 +1,10 @@
export interface S3Package {
slug: string,
version: string,
full_name: string,
name: string,
maintainer: string,
homepage: string,
// key: string,
last_modified: Date | string,
}

View file

@ -0,0 +1,27 @@
<script lang="ts">
import { get } from '../libs/api';
import type { S3Package } from '../libs/types';
let packages: S3Package[] = []
async function loadPackages(){
const data = await get<S3Package[]>('/packages');
console.log(data);
if (packages) {
packages = data;
}
}
</script>
<a href="/others">Go to install package</a>
<button on:click={loadPackages}>Load Packages</button>
<ul>
{#each packages as p}
<li>{p.full_name}</li>
{/each}
</ul>
<style>
ul {
color: green;
}
</style>

View file

@ -0,0 +1,12 @@
<script lang="ts">
import { invoke } from '@tauri-apps/api/tauri'
let pkg = '';
async function installPackage(){
await invoke('install_package', { package: pkg });
}
</script>
<h1>Others</h1>
<input bind:value={pkg}>
<button on:click={installPackage}>install package</button>
<a href="/">Back</a>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -0,0 +1,21 @@
import adapter from '@sveltejs/adapter-static';
import preprocess from 'svelte-preprocess';
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: preprocess(),
kit: {
adapter: adapter({
pages: 'build',
assets: 'build',
fallback: 'app.html',
}),
// ssr: false,
// hydrate the <div id="svelte"> element in src/app.html
// target: '#svelte'
}
};
export default config;

View file

@ -0,0 +1,6 @@
import { expect, test } from '@playwright/test';
test('index page has expected h1', async ({ page }) => {
await page.goto('/');
expect(await page.textContent('h1')).toBe('Welcome to SvelteKit');
});

View file

@ -0,0 +1,17 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true
}
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
//
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
// from the referenced tsconfig.json - TypeScript does not merge them in
}

View file

@ -0,0 +1,8 @@
import { sveltekit } from '@sveltejs/kit/vite';
import type { UserConfig } from 'vite';
const config: UserConfig = {
plugins: [sveltekit()]
};
export default config;

1918
pnpm-lock.yaml Normal file

File diff suppressed because it is too large Load diff

3
pnpm-workspace.yaml Normal file
View file

@ -0,0 +1,3 @@
packages:
- 'packages/*'
- '!**/test/**'