Skip to content

Commit

Permalink
chore: add contribution guide, add setup script
Browse files Browse the repository at this point in the history
  • Loading branch information
HuakunShen committed Oct 26, 2024
1 parent b212b22 commit 104780a
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 44 deletions.
30 changes: 30 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Contributing

If you are interested in contributing to the project, please read the following guidelines.

## Development

### Prerequisites

- Node.js LTS
- pnpm
- Bun
- Deno
- Rust

### Setup

```bash
pnpm run setup
pnpm install
pnpm --filter @kksh/gql build
```

### Run Desktop App

```bash
pnpm --filter @kksh/desktop tauri dev
# or run it within the desktop app directory
cd apps/desktop
pnpm tauri dev
```
7 changes: 2 additions & 5 deletions apps/desktop/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,8 @@ export default defineNuxtConfig({
.describe("SUPABASE_GRAPHQL_ENDPOINT")
.parse(process.env.SUPABASE_GRAPHQL_ENDPOINT),
isDev: process.env.NODE_ENV === "development",
posthogPublicKey: z
.string()
.describe("POSTHOG_PUBLIC_KEY")
.parse(process.env.POSTHOG_PUBLIC_KEY),
posthogHost: z.string().describe("POSTHOG_HOST").parse(process.env.POSTHOG_HOST)
posthogPublicKey: process.env.POSTHOG_PUBLIC_KEY,
posthogHost: process.env.POSTHOG_HOST
}
},
colorMode: {
Expand Down
13 changes: 7 additions & 6 deletions apps/desktop/pages/store/[identifier].vue
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,13 @@ async function uninstallExt() {
}
</script>
<template>
<div>
<Button variant="outline" size="icon" class="absolute left-2 top-2 z-50" @click="onBack">
<div class="h-screen">
<Button variant="outline" size="icon" class="fixed left-2 top-2 z-50" @click="onBack">
<ArrowLeftIcon />
</Button>
<div data-tauri-drag-region class="h-14"></div>
<main class="px-10">

<main class="px-10 pb-10">
<div data-tauri-drag-region class="h-14"></div>
<div class="flex items-center gap-4">
<IconMultiplexer v-if="manifest" :icon="manifest?.icon" class="h-12 w-12" />
<div>
Expand Down Expand Up @@ -194,7 +195,7 @@ async function uninstallExt() {
</main>

<Button
class="absolute bottom-0 flex w-full space-x-2 rounded-none bg-green-700 text-white hover:bg-green-600"
class="fixed bottom-0 flex w-full space-x-2 rounded-none bg-green-700 text-white hover:bg-green-600"
v-if="!isInstalled"
:disabled="installLoading"
@click="installExt"
Expand All @@ -208,7 +209,7 @@ async function uninstallExt() {
<Icon v-else name="mi:enter" class="h-5 w-5" />
</Button>
<Button
class="absolute bottom-0 w-full space-x-2 rounded-none bg-red-600 hover:bg-red-500"
class="fixed bottom-0 w-full space-x-2 rounded-none bg-red-600 hover:bg-red-500"
v-else
:disabled="uninstallLoading"
variant="destructive"
Expand Down
3 changes: 3 additions & 0 deletions apps/desktop/plugins/posthog.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export default defineNuxtPlugin((nuxtApp) => {
if (runtimeConfig.public.isDev) {
return
}
if (!(runtimeConfig.public.posthogPublicKey && runtimeConfig.public.posthogHost)) {
return
}
const posthogClient = posthog.init(runtimeConfig.public.posthogPublicKey, {
api_host: runtimeConfig.public.posthogHost || "https://us.i.posthog.com",
person_profiles: "identified_only",
Expand Down
31 changes: 1 addition & 30 deletions apps/desktop/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,39 +95,10 @@ fn main() {
.unwrap(),
}
})
.register_uri_scheme_protocol("dev-ext", |app, request| {
let app_handle = app.app_handle();
let app_state = app_handle.state::<tauri_plugin_jarvis::model::app_state::AppState>();
let win_label = app.webview_label();
let jarvis_state = app_handle.state::<tauri_plugin_jarvis::JarvisState>();
let window_ext_map = jarvis_state.window_label_ext_map.lock().unwrap();
match window_ext_map.get(win_label) {
Some(ext) => {
// let app_state = app_handle.state::<tauri_plugin_jarvis::model::app_state::AppState>();
// let extension_path = app_state.extension_path.lock().unwrap().clone();
// tauri_file_server(app_handle, request, extension_path)
tauri_file_server(app_handle, request, ext.path.clone(), ext.dist.clone())
}
None => tauri::http::Response::builder()
.status(tauri::http::StatusCode::NOT_FOUND)
.header("Access-Control-Allow-Origin", "*")
.body("Extension Not Found".as_bytes().to_vec())
.unwrap(),
}
// if let Some(path) = dev_extension_path {
// tauri_file_server(app_handle, request, path)
// } else {
// tauri::http::Response::builder()
// .status(tauri::http::StatusCode::NOT_FOUND)
// .header("Access-Control-Allow-Origin", "*")
// .body("Dev Extension Folder Not Found".as_bytes().to_vec())
// .unwrap()
// }
})
.setup(|app| {
setup::window::setup_window(app.handle());
setup::tray::create_tray(app.handle())?;
#[cfg(debug_assertions)] // only include this code on debug builds
#[cfg(all(not(target_os = "macos"), debug_assertions))]
{
app.deep_link().register("kunkun")?;
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"dev": "turbo run dev",
"develop": "turbo run develop",
"lint": "turbo run lint",
"setup": "bun scripts/init-env.ts",
"format:apps": "bun --bun prettier --write \"./apps/**/*.{ts,tsx,md,vue,json,yaml,yml,svelte}\"",
"format:packages": "bun --bun prettier --write \"./packages/**/*.{ts,tsx,md,vue,json,yaml,yml,svelte}\"",
"format": "npm run format:apps && npm run format:packages",
Expand Down
37 changes: 34 additions & 3 deletions scripts/init-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,42 @@
import { writeFileSync } from "fs"
import { resolve } from "path"

const envContent = `SUPABASE_ANON_KEY=${process.env.SUPABASE_ANON_KEY}
SUPABASE_GRAPHQL_ENDPOINT=${process.env.SUPABASE_GRAPHQL_ENDPOINT}
SUPABASE_URL=${process.env.SUPABASE_URL}
const defaultEnvUrl = `https://storage.kunkun.sh/env.json`
const res = await fetch(defaultEnvUrl)
const env = await res.json()

let envContent = ""

if (!process.env.SUPABASE_ANON_KEY) {
process.env.SUPABASE_ANON_KEY = env.SUPABASE_ANON_KEY
}
if (!process.env.SUPABASE_PROJECT_ID) {
process.env.SUPABASE_PROJECT_ID = env.SUPABASE_PROJECT_ID
}

if (process.env.SUPABASE_ANON_KEY) {
envContent += `SUPABASE_ANON_KEY=${process.env.SUPABASE_ANON_KEY}\n`
}
if (process.env.SUPABASE_PROJECT_ID) {
const supabaseUrl = `https://${process.env.SUPABASE_PROJECT_ID}.supabase.co`
const supabaseGraphqlEndpoint = `${supabaseUrl}/graphql/v1`
envContent += `
SUPABASE_GRAPHQL_ENDPOINT=${supabaseGraphqlEndpoint}
SUPABASE_URL=${supabaseUrl}
`
}
if (process.env.SUPABASE_SERVICE_ROLE_KEY) {
envContent += `\nSUPABASE_SERVICE_ROLE_KEY=${process.env.SUPABASE_SERVICE_ROLE_KEY}\n`
}
if (process.env.POSTHOG_PUBLIC_KEY && process.env.POSTHOG_HOST) {
envContent += `
POSTHOG_PUBLIC_KEY=${process.env.POSTHOG_PUBLIC_KEY}
POSTHOG_HOST=${process.env.POSTHOG_HOST}
`
}
console.log(".env files written")
console.log(envContent)

writeFileSync(resolve(__dirname, "../apps/desktop/.env"), envContent)
writeFileSync(resolve(__dirname, "../packages/gql/.env"), envContent)
writeFileSync(resolve(__dirname, "../packages/schema/.env"), envContent)

0 comments on commit 104780a

Please sign in to comment.