Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Commit

Permalink
78 fix windows create-kunkun (#85)
Browse files Browse the repository at this point in the history
* fix(create-kunkun): replace Bun.spawn with exec to fix refresh extension bug

* chore(create-kunkun): improve cicd, add prepublish script to create-kunkun to avoid version out of date

* fix(create-kunkun): fix windows cross-device copy error

* fix(create-kunkun): fix the build script copySync with dereference

* bump: bump create-kunkun

* bump: publish all dep, including latest @kksh/api

* feat: re-enable server-based dev extension refresh. deep link force focus switch to app

* fix(cli): test

* fix(cli): test

* ci: add debug msg

* fix: trying to fix test

* ci: upgrade ci bun version to 1.1.33
  • Loading branch information
HuakunShen authored Oct 28, 2024
1 parent 1ef93fd commit cb97ea9
Show file tree
Hide file tree
Showing 22 changed files with 146 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": ["@kksh/desktop"]
"ignore": ["@kksh/desktop", "tauri-plugin-jarvis-api"]
}
2 changes: 1 addition & 1 deletion .github/workflows/beta-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ jobs:

- uses: oven-sh/setup-bun@v1
with:
bun-version: 1.1.17
bun-version: 1.1.33
- name: Init Environment Variables
env:
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
# run: curl -fsSL https://d2lang.com/install.sh | sh -s --
- uses: oven-sh/setup-bun@v1
with:
bun-version: 1.1.17
bun-version: 1.1.33
- name: Init Environment Variables
env:
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/desktop-publish-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
workspaces: "./apps/desktop/src-tauri -> target"
- uses: oven-sh/setup-bun@v1
with:
bun-version: 1.1.17
bun-version: 1.1.33
- name: Init Environment Variables
env:
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
Expand Down
16 changes: 16 additions & 0 deletions apps/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# @kksh/cli

## 0.0.20

### Patch Changes

- Re-enable server-based dev extension refresh. Deep Link forces switch focus to kunkun
- Updated dependencies
- @kksh/api@0.0.21

## 0.0.19

### Patch Changes

- Fix Some Windows incompatibilities
- Updated dependencies
- @kksh/api@0.0.20

## 0.0.12

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@kksh/cli",
"module": "dist/cli.js",
"version": "0.0.18",
"version": "0.0.20",
"type": "module",
"bin": {
"@kksh/cli": "./dist/cli.js",
Expand Down
22 changes: 22 additions & 0 deletions apps/create-kunkun/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# create-kunkun

## 0.1.28

### Patch Changes

- Re-enable server-based dev extension refresh. Deep Link forces switch focus to kunkun
- Updated dependencies
- @kksh/api@0.0.21

## 0.1.27

### Patch Changes

- Fix Some Windows incompatibilities
- Updated dependencies
- @kksh/api@0.0.20

## 0.1.26

### Patch Changes

- Fix windows compatibility errors

## 0.1.23

### Patch Changes
Expand Down
3 changes: 2 additions & 1 deletion apps/create-kunkun/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ await $`rm -rf dist`
await $`bun build index.ts --outfile=dist/index.mjs --target node`.env({
NODE_ENV: "production"
})
// await $`pnpm rolldown -c`

/* -------------------------------------------------------------------------- */
/* Post Build */
Expand All @@ -29,7 +30,7 @@ fs.emptyDirSync(tmpDistTemplatesPath)
console.log(getRootDir())

const templatesPath = path.join(getRootDir(), "../..", "templates")
await fs.copy(templatesPath, tmpDistTemplatesPath)
fs.copySync(templatesPath, tmpDistTemplatesPath, { dereference: true })

/* -------------------------------------------------------------------------- */
/* Clean Dist Folder */
Expand Down
5 changes: 3 additions & 2 deletions apps/create-kunkun/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "create-kunkun",
"type": "module",
"version": "0.1.25",
"version": "0.1.28",
"bin": {
"create-akun": "dist/index.mjs"
"create-kunkun": "dist/index.mjs"
},
"scripts": {
"prepublishOnly": "bun build.ts",
"build": "bun build.ts",
"test": "bun test --coverage"
},
Expand Down
2 changes: 1 addition & 1 deletion apps/create-kunkun/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export function tarExtract(src: string, dest: string) {
process.exit(1)
}
// move intermediateDest to dest
fs.renameSync(intermediateDest, dest)
fs.copySync(intermediateDest, dest)
// remove tmp dir
fs.rmSync(tmpDir, { recursive: true })
})
Expand Down
2 changes: 2 additions & 0 deletions apps/desktop/components/settings/ExtensionsTab.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang="ts">
import IconMultiplexer from "@/components/IconMultiplexer.vue"
import { TListGroup, type TListItem } from "@/lib/types/list"
import { emitRefreshExt } from "~/lib/utils/tauri-events"
import { useAppConfigStore } from "~/stores/appConfig"
// import { useDevExtStore, useExtStore } from "~/stores/extensionLoader"
import { useExtensionStore } from "~/stores/extension"
Expand All @@ -24,6 +25,7 @@ function refreshListing() {
return extStore
.load()
.then(() => {
emitRefreshExt()
return extStore.groups()
})
.then((groups) => {
Expand Down
33 changes: 22 additions & 11 deletions apps/desktop/layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,23 @@ import { attachConsole, debug, error, info, warn } from "@tauri-apps/plugin-log"
import { initDeeplink } from "~/lib/init/deeplink"
import { useRegisterAppShortcuts } from "~/lib/utils/hotkey"
import { initStores } from "~/lib/utils/stores"
import { listenToRefreshConfig } from "~/lib/utils/tauri-events"
import {
listenToRefreshConfig,
listenToRefreshDevExt,
listenToRefreshExt
} from "~/lib/utils/tauri-events"
import { useAppConfigStore } from "~/stores/appConfig"
import { useWindowExtMapStore } from "~/stores/windowExtMap"
import { fixPathEnv } from "tauri-plugin-shellx-api"
const appConfig = useAppConfigStore()
const appWindow = getCurrentWebviewWindow()
const extStore = useExtensionStore()
const isMainWindow = appWindow.label === "main"
let unlistenRefreshConfig: UnlistenFn
let unlistenRefreshExtensionList: UnlistenFn
let detach: UnlistenFn
useGoToSettingShortcuts()
usePreventExit()
useTestDB()
unlistenRefreshConfig = await listenToRefreshConfig(async () => {
debug("Refreshing config")
await appConfig.init()
appConfig.refreshWindowStyles()
initStores()
// useRegisterAppShortcuts()
})
const windowExtMapStore = useWindowExtMapStore()
if (appWindow.label === "main") {
Expand All @@ -50,6 +46,21 @@ onMounted(async () => {
initDeeplink()
await appConfig.init()
appConfig.refreshWindowStyles()
useGoToSettingShortcuts()
usePreventExit()
unlistenRefreshConfig = await listenToRefreshConfig(async () => {
debug("Refreshing config")
await appConfig.init()
appConfig.refreshWindowStyles()
initStores()
// useRegisterAppShortcuts()
})
unlistenRefreshExtensionList = await listenToRefreshExt(async () => {
debug("Refreshing extension list")
extStore.load()
})
useRegisterAppShortcuts()
.then((hotkeyStr) => {
info(`Shortcuts registered (${hotkeyStr})`)
Expand Down
9 changes: 4 additions & 5 deletions apps/desktop/lib/utils/tauri-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ export const FileDrag = "tauri://drag"
export const FileDragCancelled = "tauri://drag-cancelled"
export const FileDragOver = "tauri://drag-over"
export const NewClipboardItemAddedEvent = "new_clipboard_item_added"
export const RefreshConfigEvent = "kksh://refresh-config"
export const RefreshExtEvent = "kksh://refresh-extensions"
export const RefreshDevExtEvent = `kksh://${DEEP_LINK_PATH_REFRESH_DEV_EXTENSION}`
export const RefreshConfigEvent = "kunkun://refresh-config"
export const RefreshExtEvent = "kunkun://refresh-extensions"

export function listenToFileDrop(cb: EventCallback<{ paths: string[] }>) {
return listen<{ paths: string[] }>(FileDrop, cb)
Expand Down Expand Up @@ -51,9 +50,9 @@ export function listenToRefreshExt(cb: EventCallback<null>) {
}

export function emitRefreshDevExt() {
return emit(RefreshDevExtEvent)
return emit(DEEP_LINK_PATH_REFRESH_DEV_EXTENSION)
}

export function listenToRefreshDevExt(cb: EventCallback<null>) {
return listen(RefreshDevExtEvent, cb)
return listen(DEEP_LINK_PATH_REFRESH_DEV_EXTENSION, cb)
}
6 changes: 3 additions & 3 deletions apps/desktop/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default defineNuxtConfig({
colorMode: {
classSuffix: ""
},
// app: {
// pageTransition: { name: "page", mode: "out-in" }
// }
app: {
pageTransition: { name: "page", mode: "out-in" }
}
})
23 changes: 14 additions & 9 deletions extensions/demo-worker-template-ext/build.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import { watch } from "fs"
import { join } from "path"
import { refreshTemplateWorkerExtension } from "@kksh/api/dev"
import { $, build as bunBuild } from "bun"
import { $ } from "bun"

async function build() {
await $`bun build --minify --target=browser --outdir=./dist ./src/index.ts`
// await bunBuild({
// entrypoints: ["./src/index.ts"],
// minify: false,
// target: "browser",
// outdir: "./dist"
// })
await refreshTemplateWorkerExtension()
try {
// await $`bun build --minify --target=browser --outdir=./dist ./src/index.ts`
const output = await Bun.build({
entrypoints: ["./src/index.ts"],
outdir: "./dist",
minify: true,
target: "browser"
})
console.log(output)
await refreshTemplateWorkerExtension()
} catch (error) {
console.error(error)
}
}

const srcDir = join(import.meta.dir, "src")
Expand Down
12 changes: 12 additions & 0 deletions packages/api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# @kksh/api

## 0.0.21

### Patch Changes

- Re-enable server-based dev extension refresh. Deep Link forces switch focus to kunkun

## 0.0.20

### Patch Changes

- Fix Some Windows incompatibilities

## 0.0.20

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kksh/api",
"version": "0.0.19",
"version": "0.0.21",
"type": "module",
"exports": {
".": "./src/index.ts",
Expand Down
30 changes: 25 additions & 5 deletions packages/api/src/dev/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { exec } from "child_process"
import os from "node:os"
import {
DEEP_LINK_PATH_REFRESH_DEV_EXTENSION,
Expand Down Expand Up @@ -33,31 +34,50 @@ export async function findLocalhostKunkunPorts(): Promise<number[]> {
return onlinePorts
}

export async function refreshTemplateWorkerExtension() {
export async function refreshTemplateWorkerExtensionViaServer() {
const ports = await findLocalhostKunkunPorts()
console.log("Kunkun ports", ports)
if (ports.length === 0) {
console.error("Failed to find localhost kunkun ports")
return
} else if (ports.length > 1) {
console.warn("Found multiple localhost kunkun ports", ports)
console.warn("Will Refresh Every Instance")
}
for (const port of ports) {
fetch(`http://localhost:${port}/refresh-worker-extension`, { method: "POST" }).catch((err) => {
console.error("Failed to send refresh worker extension request", err)
})
}
}

export async function refreshTemplateWorkerExtensionViaDeepLink() {
console.log("Send Refresh Worker Extension Request")

const platform = await os.platform()
try {
switch (platform) {
case "darwin":
await Bun.spawn(["open", `kunkun://${DEEP_LINK_PATH_REFRESH_DEV_EXTENSION}`])
exec(`open ${DEEP_LINK_PATH_REFRESH_DEV_EXTENSION}`)
break
case "win32":
await Bun.spawn(["start", `kunkun://${DEEP_LINK_PATH_REFRESH_DEV_EXTENSION}`])
exec(`start ${DEEP_LINK_PATH_REFRESH_DEV_EXTENSION}`)
break
case "linux":
await Bun.spawn(["xdg-open", `kunkun://${DEEP_LINK_PATH_REFRESH_DEV_EXTENSION}`])
exec(`xdg-open ${DEEP_LINK_PATH_REFRESH_DEV_EXTENSION}`)
break
}
} catch (error) {
console.error("Failed to refresh worker extension:", error)
}
}

export const refreshTemplateWorkerExtension = refreshTemplateWorkerExtensionViaServer

export function kununWorkerTemplateExtensionRollupPlugin() {
return {
async writeBundle() {
await refreshTemplateWorkerExtension()
await refreshTemplateWorkerExtensionViaDeepLink()
}
}
}
1 change: 1 addition & 0 deletions packages/tauri-plugin-jarvis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "tauri-plugin-jarvis-api",
"version": "0.0.2",
"author": "Huakun",
"private": true,
"description": "",
"type": "module",
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion packages/tauri-plugin-jarvis/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ pub const KUNKUN_DEV_EXT_IDENTIFIER: &str = "sh.kunkun.ext.dev";
/* -------------------------------------------------------------------------- */
/* Kunkun Builtin Events */
/* -------------------------------------------------------------------------- */
// pub const KUNKUN_REFRESH_WORKER_EXTENSION: &str = "kksh://refresh-worker-ext";
pub const KUNKUN_REFRESH_WORKER_EXTENSION: &str = "kunkun://refresh-dev-extension";
8 changes: 4 additions & 4 deletions packages/tauri-plugin-jarvis/src/server/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ async fn start_server(
.add_service(GreeterServer::new(greeter))
.into_router();
let mut rest_router = axum::Router::new()
// .route(
// "/refresh-worker-extension",
// post(super::rest::refresh_worker_extension),
// )
.route(
"/refresh-worker-extension",
post(super::rest::refresh_worker_extension),
)
.route("/info", get(super::rest::get_server_info))
.layer(CorsLayer::permissive())
.with_state(server_state);
Expand Down
Loading

0 comments on commit cb97ea9

Please # to comment.