Skip to content

Commit

Permalink
fix: notes in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Justineo committed Nov 12, 2024
1 parent 33d12e0 commit 284c2cb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ See [built-in plugins](./plugins/src) for more examples.
You can also register the plugin into our [plugin registry file](https://github.com/ecomfe/tempad-dev/blob/main/plugins/available-plugins.json) so that your plugin can be installed by name directly. Come and [add your own awesome plugin](https://github.com/ecomfe/tempad-dev/edit/main/plugins/available-plugins.json)!

> [!NOTE]
> Plugin file must be a valid ES module and have a named export `plugin`.
> Plugin file must be a valid ES module and have the plugin object as the `default` export.
Currently, we support three plugin hooks:

Expand Down
24 changes: 20 additions & 4 deletions components/PluginImporter.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import availablePlugins from '@/plugins/available-plugins.json'
import SNAPSHOT_PLUGINS from '@/plugins/available-plugins.json'
import { codegen } from '@/utils'
import IconButton from './IconButton.vue'
Expand Down Expand Up @@ -31,9 +31,25 @@ function clearValidity() {
const BUILT_IN_SOURCE_RE = /@[a-z\d_-]+/
const plugins = Object.fromEntries(availablePlugins.map(({ name, source }) => [name, source]))
function getRegisteredPluginSource(source: string) {
// plugin registry from the latest commit of the main branch
const REGISTRY_URL =
'https://raw.githubusercontent.com/ecomfe/tempad-dev/refs/heads/main/plugins/available-plugins.json'
async function getRegisteredPluginSource(source: string) {
const name = source.slice(1)
let pluginList = null
try {
pluginList = (await fetch(REGISTRY_URL).then((res) => res.json())) as {
name: string
source: string
}[]
} catch (e) {
pluginList = SNAPSHOT_PLUGINS
}
const plugins = Object.fromEntries(pluginList.map(({ name, source }) => [name, source]))
return (
plugins[name] ??
`https://raw.githubusercontent.com/ecomfe/tempad-dev/refs/heads/main/plugins/dist/${name}.js`
Expand Down Expand Up @@ -88,7 +104,7 @@ async function tryImport() {
installing.value = true
source.value = 'Installing...'
try {
const url = BUILT_IN_SOURCE_RE.test(src) ? getRegisteredPluginSource(src) : src
const url = BUILT_IN_SOURCE_RE.test(src) ? await getRegisteredPluginSource(src) : src
const response = await fetch(url, { signal })
if (response.status !== 200) {
throw new Error('404: Not Found')
Expand Down
1 change: 0 additions & 1 deletion plugins/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,4 @@ async function build() {
}
}

// 执行构建
build()

0 comments on commit 284c2cb

Please sign in to comment.