File tree Expand file tree Collapse file tree 3 files changed +47
-2
lines changed Expand file tree Collapse file tree 3 files changed +47
-2
lines changed Original file line number Diff line number Diff line change @@ -349,6 +349,21 @@ entype \
349
349
fixtures/datapack/blockstates/* .json
350
350
```
351
351
352
+ Alternatively, the ` github: ` qualifier can be used:
353
+
354
+ ``` sh
355
+ entype \
356
+ --allow-unstable \
357
+ --lang rust \
358
+ --plugin " github:bcheidemann/entype/lib/plugins/derive-debug.ts" \
359
+ fixtures/datapack/blockstates/* .json
360
+ ```
361
+
362
+ The format is ` github:<branch>@<owner>/<repo>/<path> ` , where ` branch ` defaults
363
+ to ` main ` and ` path ` defaults to ` mod.ts ` . The plugin speicifier
364
+ ` github:bcheidemann/entype-plugin-example ` would be resolved to
365
+ ` https://raw.githubusercontent.com/bcheidemann/entype-plugin-example/main/mod.ts ` .
366
+
352
367
## How it works
353
368
354
369
Entype tries to generate the simplest possible type that accurately describes
Original file line number Diff line number Diff line change 1
1
import { Plugin , PluginName } from "./types.ts" ;
2
2
3
+ export const GITHUB_PLUGIN_PREFIX = "github:" ;
4
+
3
5
export async function loadPlugin ( pluginName : PluginName ) : Promise < Plugin > {
4
6
switch ( pluginName ) {
5
7
case "derive-debug" :
6
8
return ( await import ( "./derive-debug.ts" ) ) . plugin ;
7
9
case "serde-derive" :
8
10
return ( await import ( "./serde-derive.ts" ) ) . plugin ;
9
11
default :
10
- return ( await import ( pluginName ) ) . plugin ;
12
+ return await loadThirdPartyPlugin ( pluginName ) ;
11
13
}
12
14
}
15
+
16
+ export async function loadThirdPartyPlugin (
17
+ pluginName : string ,
18
+ ) : Promise < Plugin > {
19
+ if ( pluginName . startsWith ( GITHUB_PLUGIN_PREFIX ) ) {
20
+ return await loadGithubPlugin ( pluginName ) ;
21
+ }
22
+
23
+ return ( await import ( pluginName ) ) . plugin ;
24
+ }
25
+
26
+ export async function loadGithubPlugin (
27
+ pluginName : string ,
28
+ ) : Promise < Plugin > {
29
+ const moduleSpecifier = pluginName . slice ( GITHUB_PLUGIN_PREFIX . length ) ;
30
+ const [ branch , rest ] = moduleSpecifier . includes ( "@" )
31
+ ? moduleSpecifier . split ( "@" )
32
+ : [ null , moduleSpecifier ] ;
33
+ const [ owner , repo , ...path ] = rest . split ( "/" ) ;
34
+
35
+ const { plugin } = await import (
36
+ `https://raw.githubusercontent.com/${ owner } /${ repo } /${ branch || "main" } /${
37
+ path ? path . join ( "/" ) : "mod.ts"
38
+ } `
39
+ ) ;
40
+
41
+ return plugin ;
42
+ }
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ async function main(args: string[]): Promise<0 | 1> {
27
27
}
28
28
29
29
if ( "version" in config ) {
30
- console . log ( "1.1 .0" ) ;
30
+ console . log ( "1.2 .0" ) ;
31
31
return 0 ;
32
32
}
33
33
You can’t perform that action at this time.
0 commit comments