refactor: Command class rename (#90)

* refactor: rename WorkerExtension to TemplateUiCommand, HeadlessWorkerExtension to HeadlessCommand

* ci: update npm publish workflow to include refactor branch

* ci: add push trigger for JSR publish workflow and bump API package version

* ci: add pnpm setup to npm publish workflow

* chore: add repository field to package.json for @kksh/api
This commit is contained in:
Huakun Shen 2025-02-05 12:16:33 -05:00 committed by GitHub
parent b4b7851366
commit 46d6872614
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
47 changed files with 194 additions and 72 deletions

View File

@ -1,5 +1,7 @@
name: JSR Publish
on:
push:
branches: [develop, main]
workflow_dispatch:
jobs:

39
.github/workflows/npm-publish.yml vendored Normal file
View File

@ -0,0 +1,39 @@
name: NPM Package Publish
on:
push:
branches: [develop, main, refactor/rename-ext]
release:
types: [created]
workflow_dispatch:
jobs:
publish-npm:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- uses: actions/setup-node@v4
with:
node-version: "22.x"
registry-url: "https://registry.npmjs.org"
- uses: pnpm/action-setup@v4
- run: pnpm install
- run: pnpm build
working-directory: packages/api
- name: Check if version is already published
working-directory: packages/api
run: |
PACKAGE_VERSION=$(node -p "require('./package.json').version")
npm view @kksh/api@$PACKAGE_VERSION
continue-on-error: true
id: check_version
- name: Publish
working-directory: packages/api
if: steps.check_version.outcome != 'success'
run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

View File

@ -1,5 +1,12 @@
# kksh
## 0.0.31
### Patch Changes
- Updated dependencies
- @kksh/api@0.1.0
## 0.0.30
### Patch Changes

View File

@ -1,7 +1,7 @@
{
"name": "kksh",
"module": "dist/cli.js",
"version": "0.0.30",
"version": "0.0.31",
"type": "module",
"bin": {
"kksh": "./dist/cli.js",

View File

@ -1,5 +1,12 @@
# create-kunkun
## 0.1.43
### Patch Changes
- Updated dependencies
- @kksh/api@0.1.0
## 0.1.42
### Patch Changes

View File

@ -1,7 +1,7 @@
{
"name": "create-kunkun",
"type": "module",
"version": "0.1.42",
"version": "0.1.43",
"bin": {
"create-kunkun": "dist/index.mjs"
},

View File

@ -4,7 +4,7 @@ import { winExtMap } from "@/stores/winExtMap"
import { trimSlash } from "@/utils/url"
import { constructExtensionSupportDir } from "@kksh/api"
import { db, spawnExtensionFileServer } from "@kksh/api/commands"
import type { HeadlessWorkerExtension } from "@kksh/api/headless"
import type { HeadlessCommand } from "@kksh/api/headless"
import { CustomUiCmd, ExtPackageJsonExtra, HeadlessCmd, TemplateUiCmd } from "@kksh/api/models"
import { constructJarvisServerAPIWithPermissions, type IApp } from "@kksh/api/ui"
import { launchNewExtWindow, loadExtensionManifestFromDisk } from "@kksh/extension"
@ -101,7 +101,7 @@ export async function onHeadlessCmdSelect(
} satisfies IApp
}
const io = new WorkerParentIO(worker)
const rpc = new RPCChannel<typeof serverAPI2, HeadlessWorkerExtension>(io, {
const rpc = new RPCChannel<typeof serverAPI2, HeadlessCommand>(io, {
expose: serverAPI2
})
const workerAPI = rpc.getAPI()

View File

@ -15,7 +15,7 @@
NodeNameEnum,
toast,
type IComponent,
type WorkerExtension
type TemplateUiCommand
} from "@kksh/api/ui/worker"
import { LoadingBar } from "@kksh/ui"
import { Templates } from "@kksh/ui/extension"
@ -35,7 +35,7 @@
let listviewInputRef = $state<HTMLInputElement | null>(null)
let { loadedExt, scriptPath, extInfoInDB } = $derived(data)
let actionPanelOpen = $state(false)
let workerAPI: WorkerExtension | undefined = undefined
let workerAPI: TemplateUiCommand | undefined = undefined
let unlistenRefreshWorkerExt: UnlistenFn | undefined
let unlistenFileDrop: UnlistenFn | undefined
let worker: Worker | undefined
@ -223,7 +223,7 @@
}
const io = new WorkerParentIO(worker)
const rpc = new RPCChannel<typeof serverAPI2, WorkerExtension>(io, {
const rpc = new RPCChannel<typeof serverAPI2, TemplateUiCommand>(io, {
expose: serverAPI2
})
workerAPI = rpc.getAPI()

View File

@ -1,5 +1,11 @@
# @kksh/api
## 0.1.0
### Minor Changes
- Rename WorkerExtension to TemplateUiCommand, and HeadlessWorkerExtension to HeadlessCommand
## 0.0.53
### Patch Changes

View File

@ -1,9 +1,12 @@
# @kksh/api
![NPM Version](https://img.shields.io/npm/v/%40kksh%2Fapi)
[![NPM Version](https://img.shields.io/npm/v/%40kksh%2Fapi)](https://www.npmjs.com/package/@kksh/api)
[![JSR Badge](https://jsr.io/badges/@kunkun/api)](https://jsr.io/@kunkun/api)
[Kunkun API](https://www.npmjs.com/package/@kksh/api) is an NPM package designed for developers to create extensions for Kunkun.
On NPM this package is published as `@kksh/api`, and on JSR it is published as `@kunkun/api`.
`@kksh/api` provides a set of APIs for extensions to interact with Kunkun and System APIs. The APIs include:
- Clipboard
@ -25,19 +28,4 @@
- UI
- etc.
Read more details in documentation at https://docs.kunkun.sh,
and generated docs at https://docs.api.kunkun.sh/
## Dev
### Dependency Graph
To detect circular dependencies
```bash
pnpm madge ./src/ui/worker/index.ts --circular # detect circular dependencies
pnpm dep-tree ./src/ui/worker/index.ts
pnpm test # this will detect circular dependencies in all files
```
Read more details in documentation at https://docs.kunkun.sh, and generated docs at https://docs.api.kunkun.sh/

View File

@ -1,7 +1,7 @@
{
"$schema": "https://jsr.io/schema/config-file.v1.json",
"name": "@kunkun/api",
"version": "0.0.57",
"version": "0.1.0",
"license": "MIT",
"exports": {
".": "./src/index.ts",

View File

@ -1,7 +1,11 @@
{
"name": "@kksh/api",
"version": "0.0.57",
"version": "0.1.0",
"type": "module",
"repository": {
"type": "git",
"url": "https://github.com/kunkunsh/kunkun.git"
},
"main": "./src/index.ts",
"types": "./src/index.ts",
"module": "./src/index.ts",

View File

@ -41,7 +41,7 @@ export async function findLocalhostKunkunPorts(): Promise<number[]> {
return onlinePorts
}
export async function refreshTemplateWorkerExtensionViaServer() {
export async function refreshTemplateWorkerCommandViaServer() {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"
const ports = await findLocalhostKunkunPorts()
console.log("Kunkun ports", ports)
@ -62,7 +62,7 @@ export async function refreshTemplateWorkerExtensionViaServer() {
}
}
export async function refreshTemplateWorkerExtensionViaDeepLink() {
export async function refreshTemplateWorkerCommandViaDeepLink() {
console.log("Send Refresh Worker Extension Request")
const platform = await os.platform()
@ -83,12 +83,12 @@ export async function refreshTemplateWorkerExtensionViaDeepLink() {
}
}
export const refreshTemplateWorkerExtension = refreshTemplateWorkerExtensionViaServer
export const refreshTemplateWorkerCommand = refreshTemplateWorkerCommandViaServer
export function kununWorkerTemplateExtensionRollupPlugin() {
export function kununWorkerTemplateCommandRollupPlugin() {
return {
async writeBundle() {
await refreshTemplateWorkerExtensionViaDeepLink()
await refreshTemplateWorkerCommandViaDeepLink()
}
}
}

View File

@ -1,4 +1,4 @@
export abstract class HeadlessWorkerExtension {
export abstract class HeadlessCommand {
/**
* Load the extension. Initialize the extension.
* Will be called once when the extension is first loaded.

View File

@ -33,7 +33,7 @@ import { constructPathAPI } from "../api/path"
import type { IShellServer } from "../api/server-types"
import { constructShellAPI } from "../api/shell"
import { constructToastAPI } from "../api/toast"
import type { HeadlessWorkerExtension } from "./ext"
import type { HeadlessCommand } from "./ext"
/* -------------------------------------------------------------------------- */
/* API Interfaces */
@ -53,7 +53,7 @@ export type {
} from "tauri-api-adapter"
export type { ISystem, IToast, IUiIframe, IDb, IKV, IFs, IOpen, IEvent } from "../api/client"
export type { IShell } from "../api/shell"
export { HeadlessWorkerExtension } from "./ext"
export { HeadlessCommand } from "./ext"
/* -------------------------------------------------------------------------- */
/* RPC */
/* -------------------------------------------------------------------------- */
@ -87,7 +87,7 @@ type API = {
const io = new WorkerChildIO()
const rpc = new RPCChannel<{}, API, DestroyableIoInterface>(io, {})
export const api = rpc.getAPI()
export function expose(api: HeadlessWorkerExtension) {
export function expose(api: HeadlessCommand) {
rpc.expose(api)
}

View File

@ -1,4 +1,4 @@
export abstract class WorkerExtension {
export abstract class TemplateUiCommand {
/* -------------------------------------------------------------------------- */
/* Common */
/* -------------------------------------------------------------------------- */

View File

@ -45,7 +45,7 @@ import { constructShellAPI } from "../../api/shell"
import { constructToastAPI } from "../../api/toast"
import type { FormSchema, ListSchema, MarkdownSchema } from "../../models"
import type { IComponent } from "./components"
import type { WorkerExtension } from "./ext"
import type { TemplateUiCommand } from "./ext"
export interface IUiWorker {
render: (view: IComponent<ListSchema.List | FormSchema.Form | MarkdownSchema>) => Promise<void>
@ -58,7 +58,7 @@ export interface IUiWorker {
}
// export { expose, wrap } from "@huakunshen/comlink"
export { WorkerExtension, WorkerExtension as TemplateUiExtension } from "./ext"
export { TemplateUiCommand } from "./ext"
/**
* For the APIs annotated with "inherit from tauri-api-adapter", they inherit the client API completely from tauri-api-adapter
* There may be server API changes for them, but the client API can be inherited
@ -95,7 +95,7 @@ const io = new WorkerChildIO()
const rpc = new RPCChannel<{}, API, DestroyableIoInterface>(io, {})
export const api = rpc.getAPI()
export function expose(api: WorkerExtension) {
export function expose(api: TemplateUiCommand) {
rpc.expose(api)
}

View File

@ -21,7 +21,7 @@ export const breakingChangesVersionCheckpoints = [
const checkpointVersions = breakingChangesVersionCheckpoints.map((c) => c.version)
const sortedCheckpointVersions = sort(checkpointVersions)
export const version = "0.0.57"
export const version = "0.1.0"
export function isVersionBetween(v: string, start: string, end: string) {
const vCleaned = clean(v)

View File

@ -1,5 +1,12 @@
# demo-template-extension
## 0.0.7
### Patch Changes
- Updated dependencies
- @kksh/api@0.1.0
## 0.0.6
### Patch Changes

View File

@ -1,6 +1,6 @@
import { watch } from "fs"
import { join } from "path"
import { refreshTemplateWorkerExtension } from "@kksh/api/dev"
import { refreshTemplateWorkerCommand } from "@kksh/api/dev"
import { $ } from "bun"
async function build() {
@ -12,7 +12,7 @@ async function build() {
minify: true,
target: "browser"
})
await refreshTemplateWorkerExtension()
await refreshTemplateWorkerCommand()
} catch (error) {
console.error(error)
}

View File

@ -1,7 +1,7 @@
{
"$schema": "../../schema/manifest-json-schema.json",
"name": "demo-template-extension",
"version": "0.0.6",
"version": "0.0.7",
"type": "module",
"license": "MIT",
"kunkun": {

View File

@ -1,6 +1,6 @@
import { expose, HeadlessWorkerExtension, toast } from "@kksh/api/headless"
import { expose, HeadlessCommand, toast } from "@kksh/api/headless"
class DemoHeadlessExt extends HeadlessWorkerExtension {
class DemoHeadlessExt extends HeadlessCommand {
load(): Promise<void> {
console.log("Demo Headless Extension Loaded")
toast.info("Demo Headless Extension Loaded")

View File

@ -16,9 +16,9 @@ import {
path,
security,
shell,
TemplateUiCommand,
toast,
ui,
WorkerExtension
ui
} from "@kksh/api/ui/worker"
import { IconType } from "@kunkun/api/models"
@ -34,7 +34,7 @@ const allItems: List.Item[] = itemsTitle.map(
})
)
class ExtensionTemplate extends WorkerExtension {
class ExtensionTemplate extends TemplateUiCommand {
async onBeforeGoBack() {
console.log("onBeforeGoBack")
// console.log(`Try killing pid: ${this.apiProcess?.pid}`)

View File

@ -1,5 +1,12 @@
# template-ext-sveltekit
## 0.0.7
### Patch Changes
- Updated dependencies
- @kksh/api@0.1.0
## 0.0.6
### Patch Changes

View File

@ -1,7 +1,7 @@
{
"$schema": "https://schema.kunkun.sh",
"name": "ext-sveltekit-exp",
"version": "0.0.6",
"version": "0.0.7",
"license": "MIT",
"kunkun": {
"name": "TODO: Change Display Name",

View File

@ -1,6 +1,6 @@
import { watch } from "fs"
import { join } from "path"
import { refreshTemplateWorkerExtension } from "@kksh/api/dev"
import { refreshTemplateWorkerCommand } from "@kksh/api/dev"
import { $ } from "bun"
const entrypoints = ["./src/index.ts"]
@ -11,7 +11,7 @@ async function build() {
await $`bun build --minify --target=browser --outdir=./dist ${entrypoint}`
}
if (Bun.argv.includes("dev")) {
await refreshTemplateWorkerExtension()
await refreshTemplateWorkerCommand()
}
} catch (error) {
console.error(error)

View File

@ -10,12 +10,12 @@ import {
Markdown,
path,
shell,
TemplateUiCommand,
toast,
ui,
WorkerExtension
ui
} from "@kksh/api/ui/worker"
class ExtensionTemplate extends WorkerExtension {
class ExtensionTemplate extends TemplateUiCommand {
async onFormSubmit(value: Record<string, any>): Promise<void> {
console.log("Form submitted", value)
toast.success(`Form submitted: ${JSON.stringify(value)}`)

View File

@ -1,5 +1,12 @@
# template-ext-worker
## 0.0.6
### Patch Changes
- Updated dependencies
- @kksh/api@0.1.0
## 0.0.5
### Patch Changes

View File

@ -1,6 +1,6 @@
import { watch } from "fs"
import { join } from "path"
import { refreshTemplateWorkerExtension } from "@kksh/api/dev"
import { refreshTemplateWorkerCommand } from "@kksh/api/dev"
import { $ } from "bun"
const entrypoints = ["./src/index.ts"]
@ -11,7 +11,7 @@ async function build() {
await $`bun build --minify --target=browser --outdir=./dist ${entrypoint}`
}
if (Bun.argv.includes("dev")) {
await refreshTemplateWorkerExtension()
await refreshTemplateWorkerCommand()
}
} catch (error) {
console.error(error)

View File

@ -1,7 +1,7 @@
{
"$schema": "./node_modules/@kksh/api/dist/schema.json",
"name": "template-ext-headless",
"version": "0.0.5",
"version": "0.0.6",
"license": "MIT",
"type": "module",
"kunkun": {

View File

@ -1,7 +1,7 @@
import { clipboard, expose, HeadlessWorkerExtension, toast } from "@kksh/api/headless"
import { clipboard, expose, HeadlessCommand, toast } from "@kksh/api/headless"
import { v4 as uuidv4 } from "uuid"
class UuidExt extends HeadlessWorkerExtension {
class UuidExt extends HeadlessCommand {
async load() {
const uuid = uuidv4()
return clipboard

View File

@ -1,5 +1,12 @@
# template-ext-next
## 0.1.5
### Patch Changes
- Updated dependencies
- @kksh/api@0.1.0
## 0.1.4
### Patch Changes

View File

@ -1,7 +1,7 @@
{
"$schema": "./node_modules/@kksh/api/dist/schema.json",
"name": "template-ext-next",
"version": "0.1.4",
"version": "0.1.5",
"license": "MIT",
"kunkun": {
"name": "TODO: Change Display Name",

View File

@ -1,5 +1,12 @@
# template-ext-nuxt
## 0.0.7
### Patch Changes
- Updated dependencies
- @kksh/api@0.1.0
## 0.0.6
### Patch Changes

View File

@ -1,7 +1,7 @@
{
"$schema": "./node_modules/@kksh/api/dist/schema.json",
"name": "template-ext-nuxt",
"version": "0.0.6",
"version": "0.0.7",
"type": "module",
"license": "MIT",
"kunkun": {

View File

@ -1,5 +1,12 @@
# template-ext-react
## 0.0.6
### Patch Changes
- Updated dependencies
- @kksh/api@0.1.0
## 0.0.5
### Patch Changes

View File

@ -2,7 +2,7 @@
"$schema": "./node_modules/@kksh/api/dist/schema.json",
"name": "template-ext-react",
"license": "MIT",
"version": "0.0.5",
"version": "0.0.6",
"type": "module",
"kunkun": {
"name": "TODO: Change Display Name",

View File

@ -1,5 +1,12 @@
# template-ext-svelte
## 0.0.6
### Patch Changes
- Updated dependencies
- @kksh/api@0.1.0
## 0.0.5
### Patch Changes

View File

@ -2,7 +2,7 @@
"$schema": "./node_modules/@kksh/api/dist/schema.json",
"name": "template-ext-svelte",
"license": "MIT",
"version": "0.0.5",
"version": "0.0.6",
"type": "module",
"kunkun": {
"name": "TODO: Change Display Name",

View File

@ -1,5 +1,12 @@
# template-ext-sveltekit
## 0.0.7
### Patch Changes
- Updated dependencies
- @kksh/api@0.1.0
## 0.0.6
### Patch Changes

View File

@ -1,7 +1,7 @@
{
"$schema": "./node_modules/@kksh/api/dist/schema.json",
"name": "template-ext-sveltekit",
"version": "0.0.6",
"version": "0.0.7",
"license": "MIT",
"kunkun": {
"name": "TODO: Change Display Name",

View File

@ -1,5 +1,12 @@
# template-ext-vue
## 0.0.4
### Patch Changes
- Updated dependencies
- @kksh/api@0.1.0
## 0.0.3
### Patch Changes

View File

@ -1,7 +1,7 @@
{
"name": "template-ext-vue",
"license": "MIT",
"version": "0.0.3",
"version": "0.0.4",
"type": "module",
"scripts": {
"dev": "vite",

View File

@ -1,5 +1,12 @@
# template-ext-worker
## 0.0.6
### Patch Changes
- Updated dependencies
- @kksh/api@0.1.0
## 0.0.5
### Patch Changes

View File

@ -1,6 +1,6 @@
import { watch } from "fs"
import { join } from "path"
import { refreshTemplateWorkerExtension } from "@kksh/api/dev"
import { refreshTemplateWorkerCommand } from "@kksh/api/dev"
import { $ } from "bun"
const entrypoints = ["./src/index.ts"]
@ -11,7 +11,7 @@ async function build() {
await $`bun build --minify --target=browser --outdir=./dist ${entrypoint}`
}
if (Bun.argv.includes("dev")) {
await refreshTemplateWorkerExtension()
await refreshTemplateWorkerCommand()
}
} catch (error) {
console.error(error)

View File

@ -1,7 +1,7 @@
{
"$schema": "./node_modules/@kksh/api/dist/schema.json",
"name": "template-ext-worker",
"version": "0.0.5",
"version": "0.0.6",
"license": "MIT",
"type": "module",
"kunkun": {

View File

@ -9,13 +9,12 @@ import {
List,
path,
shell,
TemplateUiCommand,
toast,
ui,
WorkerExtension
ui
} from "@kksh/api/ui/worker"
import { setupI18n, t } from "./i18n"
class ExtensionTemplate extends WorkerExtension {
class ExtensionTemplate extends TemplateUiCommand {
async onFormSubmit(value: Record<string, any>): Promise<void> {
console.log("Form submitted", value)
toast.success(`Form submitted: ${JSON.stringify(value)}`)