mirror of
https://github.com/NaN72dev/kunkun-ext-string-utils.git
synced 2025-04-03 17:56:45 +00:00
feat(camel): add camel command
This commit is contained in:
parent
ef45838954
commit
8463818c16
177
.gitignore
vendored
Normal file
177
.gitignore
vendored
Normal file
@ -0,0 +1,177 @@
|
|||||||
|
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
|
||||||
|
logs
|
||||||
|
_.log
|
||||||
|
npm-debug.log_
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
.pnpm-debug.log*
|
||||||
|
|
||||||
|
# Caches
|
||||||
|
|
||||||
|
.cache
|
||||||
|
|
||||||
|
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||||
|
|
||||||
|
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
|
||||||
|
|
||||||
|
# Runtime data
|
||||||
|
|
||||||
|
pids
|
||||||
|
_.pid
|
||||||
|
_.seed
|
||||||
|
*.pid.lock
|
||||||
|
|
||||||
|
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||||
|
|
||||||
|
lib-cov
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
|
||||||
|
coverage
|
||||||
|
*.lcov
|
||||||
|
|
||||||
|
# nyc test coverage
|
||||||
|
|
||||||
|
.nyc_output
|
||||||
|
|
||||||
|
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||||
|
|
||||||
|
.grunt
|
||||||
|
|
||||||
|
# Bower dependency directory (https://bower.io/)
|
||||||
|
|
||||||
|
bower_components
|
||||||
|
|
||||||
|
# node-waf configuration
|
||||||
|
|
||||||
|
.lock-wscript
|
||||||
|
|
||||||
|
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||||
|
|
||||||
|
build/Release
|
||||||
|
|
||||||
|
# Dependency directories
|
||||||
|
|
||||||
|
node_modules/
|
||||||
|
jspm_packages/
|
||||||
|
|
||||||
|
# Snowpack dependency directory (https://snowpack.dev/)
|
||||||
|
|
||||||
|
web_modules/
|
||||||
|
|
||||||
|
# TypeScript cache
|
||||||
|
|
||||||
|
*.tsbuildinfo
|
||||||
|
|
||||||
|
# Optional npm cache directory
|
||||||
|
|
||||||
|
.npm
|
||||||
|
|
||||||
|
# Optional eslint cache
|
||||||
|
|
||||||
|
.eslintcache
|
||||||
|
|
||||||
|
# Optional stylelint cache
|
||||||
|
|
||||||
|
.stylelintcache
|
||||||
|
|
||||||
|
# Microbundle cache
|
||||||
|
|
||||||
|
.rpt2_cache/
|
||||||
|
.rts2_cache_cjs/
|
||||||
|
.rts2_cache_es/
|
||||||
|
.rts2_cache_umd/
|
||||||
|
|
||||||
|
# Optional REPL history
|
||||||
|
|
||||||
|
.node_repl_history
|
||||||
|
|
||||||
|
# Output of 'npm pack'
|
||||||
|
|
||||||
|
*.tgz
|
||||||
|
|
||||||
|
# Yarn Integrity file
|
||||||
|
|
||||||
|
.yarn-integrity
|
||||||
|
|
||||||
|
# dotenv environment variable files
|
||||||
|
|
||||||
|
.env
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
|
.env.local
|
||||||
|
|
||||||
|
# parcel-bundler cache (https://parceljs.org/)
|
||||||
|
|
||||||
|
.parcel-cache
|
||||||
|
|
||||||
|
# Next.js build output
|
||||||
|
|
||||||
|
.next
|
||||||
|
out
|
||||||
|
|
||||||
|
# Nuxt.js build / generate output
|
||||||
|
|
||||||
|
.nuxt
|
||||||
|
dist
|
||||||
|
|
||||||
|
# Gatsby files
|
||||||
|
|
||||||
|
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||||
|
|
||||||
|
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||||
|
|
||||||
|
# public
|
||||||
|
|
||||||
|
# vuepress build output
|
||||||
|
|
||||||
|
.vuepress/dist
|
||||||
|
|
||||||
|
# vuepress v2.x temp and cache directory
|
||||||
|
|
||||||
|
.temp
|
||||||
|
|
||||||
|
# Docusaurus cache and generated files
|
||||||
|
|
||||||
|
.docusaurus
|
||||||
|
|
||||||
|
# Serverless directories
|
||||||
|
|
||||||
|
.serverless/
|
||||||
|
|
||||||
|
# FuseBox cache
|
||||||
|
|
||||||
|
.fusebox/
|
||||||
|
|
||||||
|
# DynamoDB Local files
|
||||||
|
|
||||||
|
.dynamodb/
|
||||||
|
|
||||||
|
# TernJS port file
|
||||||
|
|
||||||
|
.tern-port
|
||||||
|
|
||||||
|
# Stores VSCode versions used for testing VSCode extensions
|
||||||
|
|
||||||
|
.vscode-test
|
||||||
|
|
||||||
|
# yarn v2
|
||||||
|
|
||||||
|
.yarn/cache
|
||||||
|
.yarn/unplugged
|
||||||
|
.yarn/build-state.yml
|
||||||
|
.yarn/install-state.gz
|
||||||
|
.pnp.*
|
||||||
|
|
||||||
|
# IntelliJ based IDEs
|
||||||
|
.idea
|
||||||
|
|
||||||
|
# Finder (MacOS) folder config
|
||||||
|
.DS_Store
|
||||||
|
extensions_support/
|
||||||
|
|
43
CHANGELOG.md
Normal file
43
CHANGELOG.md
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
# template-ext-worker
|
||||||
|
|
||||||
|
## 0.0.8
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @kksh/api@0.1.2
|
||||||
|
|
||||||
|
## 0.0.7
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @kksh/api@0.1.1
|
||||||
|
|
||||||
|
## 0.0.6
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @kksh/api@0.1.0
|
||||||
|
|
||||||
|
## 0.0.5
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @kksh/api@0.0.53
|
||||||
|
|
||||||
|
## 0.0.4
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @kksh/api@0.0.48
|
||||||
|
|
||||||
|
## 0.0.3
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @kksh/api@0.0.47
|
85
README.md
Normal file
85
README.md
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
# Kunkun Template UI Extension
|
||||||
|
|
||||||
|
This is a template for a template UI extension. (UI follows pre-defined template)
|
||||||
|
|
||||||
|
[./src/index.ts](./src/index.ts) is the default entrypoint for the extension. You can import any other files in this file, but the build process will bundle them into a single file.
|
||||||
|
|
||||||
|
## Pros and Cons
|
||||||
|
|
||||||
|
This type of extension is suitable for simple use cases, such as a list or form. All components are pre-defined, so there is not much room for customization. If you want more flexibility on the UI, consider using [Custom UI Extension](https://docs.kunkun.sh/extensions/custom-ui-ext/), which requires some frontend knowledge but gives you full control over the UI.
|
||||||
|
|
||||||
|
Read documentation at https://docs.kunkun.sh/extensions/worker-template/
|
||||||
|
|
||||||
|
Make sure you understand what this type of extension is capable of.
|
||||||
|
|
||||||
|
### Pros
|
||||||
|
|
||||||
|
- Simple to develop, no need for any frontend knowledge.
|
||||||
|
- Small bundle size (~40KB)
|
||||||
|
- [Custom UI Extension](https://docs.kunkun.sh/extensions/custom-ui-ext/) are usually larger than 300KB.
|
||||||
|
|
||||||
|
### Cons
|
||||||
|
|
||||||
|
- Limited UI customization. Not suitable for complex use cases.
|
||||||
|
|
||||||
|
Consider [Custom UI Extension](https://docs.kunkun.sh/extensions/custom-ui-ext/) if you need more complex UI.
|
||||||
|
|
||||||
|
## Development
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm install
|
||||||
|
```
|
||||||
|
|
||||||
|
Start extension in development mode. Every save will trigger a hot reload in Kunkun.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm dev
|
||||||
|
```
|
||||||
|
|
||||||
|
- During development, right click in Kunkun to open the developer tools.
|
||||||
|
- Error messages will be shown in the console.
|
||||||
|
- If you got any permission error while calling Kunknu's APIs, make sure you've declared the permission in `package.json`. Then go back to home page and enter the extension again to re-apply the permission.
|
||||||
|
- To develop and preview the extension in Kunkun, you need to run the `Add Dev Extension` command in Kunkun, and register this extension's path.
|
||||||
|
|
||||||
|
Build the extension. Your extension source code can contain many files, but the build process will bundle them into a single file.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm build
|
||||||
|
# Due to Bun's bug, if you are on windows, and install dependencies with pnpm, you may get error during build.
|
||||||
|
# Try install dependencies with bun or npm instead.
|
||||||
|
```
|
||||||
|
|
||||||
|
## i18n
|
||||||
|
|
||||||
|
[./src/i18n](./src/i18n/) contains optional internationalization support starter code.
|
||||||
|
|
||||||
|
If you want to support i18n, you can use the `t` function to translate the strings in the extension.
|
||||||
|
|
||||||
|
User's language setting is available via `app.language()`.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { app } from "@kksh/api/ui/template"
|
||||||
|
import { setupI18n, t } from "./src/i18n"
|
||||||
|
|
||||||
|
setupI18n("zh")
|
||||||
|
console.log(t("welcome"))
|
||||||
|
|
||||||
|
setupI18n(await app.language())
|
||||||
|
console.log(t("welcome"))
|
||||||
|
```
|
||||||
|
|
||||||
|
## Add More Commands
|
||||||
|
|
||||||
|
If you want to add more template worker extension commands, simply modify the `entrypoints` array in [./build.ts](./build.ts).
|
||||||
|
|
||||||
|
Then in `package.json`, register the new command.
|
||||||
|
|
||||||
|
## Verify Build and Publish
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm build # make sure the build npm script works
|
||||||
|
npx kksh@latest verify # Verify some basic settings
|
||||||
|
npx kksh@latest verify --publish # Verify some basic settings before publishing
|
||||||
|
```
|
||||||
|
|
||||||
|
See [Documentation](https://docs.kunkun.sh/guides/extensions/publish/design/) for more details on how to publish your extension. You will need to publish your extension package to npm or jsr first with GitHub actioin, then register it on Kunkun's website.
|
30
build.ts
Normal file
30
build.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import { watch } from "fs"
|
||||||
|
import { join } from "path"
|
||||||
|
import { refreshTemplateWorkerCommand } from "@kksh/api/dev"
|
||||||
|
import { $ } from "bun"
|
||||||
|
|
||||||
|
const entrypoints = ["./src/index.ts"]
|
||||||
|
|
||||||
|
async function build() {
|
||||||
|
try {
|
||||||
|
for (const entrypoint of entrypoints) {
|
||||||
|
await $`bun build --minify --target=browser --outdir=./dist ${entrypoint}`
|
||||||
|
}
|
||||||
|
if (Bun.argv.includes("dev")) {
|
||||||
|
await refreshTemplateWorkerCommand()
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const srcDir = join(import.meta.dir, "src")
|
||||||
|
|
||||||
|
await build()
|
||||||
|
|
||||||
|
if (Bun.argv.includes("dev")) {
|
||||||
|
console.log(`Watching ${srcDir} for changes...`)
|
||||||
|
watch(srcDir, { recursive: true }, async (event, filename) => {
|
||||||
|
await build()
|
||||||
|
})
|
||||||
|
}
|
51
package.json
Normal file
51
package.json
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://schema.kunkun.sh",
|
||||||
|
"name": "kunkun-ext-string-utils",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"license": "MIT",
|
||||||
|
"type": "module",
|
||||||
|
"kunkun": {
|
||||||
|
"name": "String Utils",
|
||||||
|
"shortDescription": "A string utility headless Extension",
|
||||||
|
"longDescription": "A string utility headless Extension",
|
||||||
|
"identifier": "kunkun-ext-string-utils",
|
||||||
|
"permissions": [
|
||||||
|
"clipboard:write-text",
|
||||||
|
"clipboard:read-text"
|
||||||
|
],
|
||||||
|
"demoImages": [],
|
||||||
|
"icon": {
|
||||||
|
"type": "iconify",
|
||||||
|
"value": "tabler:code"
|
||||||
|
},
|
||||||
|
"headlessCmds": [
|
||||||
|
{
|
||||||
|
"name": "Convert clipboard text to Camel Case",
|
||||||
|
"main": "dist/index.js",
|
||||||
|
"cmds": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"dev": "bun build.ts dev",
|
||||||
|
"build": "bun build.ts"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@kksh/api": "0.1.3",
|
||||||
|
"i18next": "^23.15.1",
|
||||||
|
"lodash": "^4.17.21",
|
||||||
|
"lodash.camelcase": "^4.3.0",
|
||||||
|
"uuid": "^11.0.3"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/bun": "latest",
|
||||||
|
"@types/lodash": "^4.17.15"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"typescript": "^5.0.0"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"./dist",
|
||||||
|
".gitignore"
|
||||||
|
]
|
||||||
|
}
|
2252
pnpm-lock.yaml
generated
Normal file
2252
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
17
src/index.ts
Normal file
17
src/index.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { clipboard, expose, HeadlessCommand, toast } from "@kksh/api/headless"
|
||||||
|
import _ from "lodash"
|
||||||
|
|
||||||
|
class CamelCaseExt extends HeadlessCommand {
|
||||||
|
async load() {
|
||||||
|
if (!await clipboard.hasText()) return;
|
||||||
|
|
||||||
|
const clipboardText = await clipboard.readText();
|
||||||
|
const convertedText = _.camelCase(clipboardText);
|
||||||
|
|
||||||
|
await clipboard.writeText(convertedText);
|
||||||
|
await toast.success(`Copied: "${convertedText}"`);
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
expose(new CamelCaseExt())
|
27
tsconfig.json
Normal file
27
tsconfig.json
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
// Enable latest features
|
||||||
|
"lib": [
|
||||||
|
"ESNext",
|
||||||
|
"DOM"
|
||||||
|
],
|
||||||
|
"target": "ESNext",
|
||||||
|
"module": "ESNext",
|
||||||
|
"moduleDetection": "force",
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
"allowJs": true,
|
||||||
|
// Bundler mode
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"allowImportingTsExtensions": false,
|
||||||
|
"verbatimModuleSyntax": true,
|
||||||
|
"noEmit": true,
|
||||||
|
// Best practices
|
||||||
|
"strict": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
// Some stricter flags (disabled by default)
|
||||||
|
"noUnusedLocals": false,
|
||||||
|
"noUnusedParameters": false,
|
||||||
|
"noPropertyAccessFromIndexSignature": false
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user