-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a3dcabb
commit 341281b
Showing
3 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,42 @@ | ||
import { Plugin, PluginName } from "./types.ts"; | ||
|
||
export const GITHUB_PLUGIN_PREFIX = "github:"; | ||
|
||
export async function loadPlugin(pluginName: PluginName): Promise<Plugin> { | ||
switch (pluginName) { | ||
case "derive-debug": | ||
return (await import("./derive-debug.ts")).plugin; | ||
case "serde-derive": | ||
return (await import("./serde-derive.ts")).plugin; | ||
default: | ||
return (await import(pluginName)).plugin; | ||
return await loadThirdPartyPlugin(pluginName); | ||
} | ||
} | ||
|
||
export async function loadThirdPartyPlugin( | ||
pluginName: string, | ||
): Promise<Plugin> { | ||
if (pluginName.startsWith(GITHUB_PLUGIN_PREFIX)) { | ||
return await loadGithubPlugin(pluginName); | ||
} | ||
|
||
return (await import(pluginName)).plugin; | ||
} | ||
|
||
export async function loadGithubPlugin( | ||
pluginName: string, | ||
): Promise<Plugin> { | ||
const moduleSpecifier = pluginName.slice(GITHUB_PLUGIN_PREFIX.length); | ||
const [branch, rest] = moduleSpecifier.includes("@") | ||
? moduleSpecifier.split("@") | ||
: [null, moduleSpecifier]; | ||
const [owner, repo, ...path] = rest.split("/"); | ||
|
||
const { plugin } = await import( | ||
`https://raw.githubusercontent.com/${owner}/${repo}/${branch || "main"}/${ | ||
path ? path.join("/") : "mod.ts" | ||
}` | ||
); | ||
|
||
return plugin; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters