File tree Expand file tree Collapse file tree 1 file changed +25
-21
lines changed Expand file tree Collapse file tree 1 file changed +25
-21
lines changed Original file line number Diff line number Diff line change 1
1
#!/usr/bin/env -S deno run --allow-read --allow-run=bash,git,cargo --allow-env --allow-sys
2
2
3
3
import * as zx from 'npm:zx'
4
+ import { z , ZodSchema } from "https://deno.land/x/[email protected] /mod.ts" ;
5
+
6
+ const CargoToml = z . object ( {
7
+ package : z . object ( {
8
+ name : z . string ( ) ,
9
+ description : z . string ( ) ,
10
+ metadata : z . object ( {
11
+ details : z . object ( {
12
+ title : z . string ( ) ,
13
+ tagline : z . string ( ) ,
14
+ summary : z . string ( ) ,
15
+ } )
16
+ } )
17
+ } )
18
+ } )
19
+
20
+ type CargoToml = z . infer < typeof CargoToml > ;
4
21
5
- interface CargoToml {
6
- package : {
7
- name : string ,
8
- description : string ,
9
- metadata : {
10
- details : {
11
- title : string ,
12
- tagline : string ,
13
- summary : string
14
- }
15
- }
16
- }
17
- }
18
-
19
- interface Repo {
20
- url : string
21
- }
22
+ const Repo = z . object ( {
23
+ url : z . string ( ) . url ( ) ,
24
+ } )
25
+
26
+ type Repo = z . infer < typeof Repo > ;
22
27
23
28
const $ = zx . $ ( {
24
29
cwd : import . meta. dirname
25
30
} )
26
-
27
- const parse = ( input : { toString : ( ) => string } ) => JSON . parse ( input . toString ( ) )
31
+ const parse = < T > ( schema : ZodSchema < T > , input : { toString : ( ) => string } ) => schema . parse ( JSON . parse ( input . toString ( ) ) )
28
32
const renderMarkdownList = ( items : string [ ] ) => items . map ( bin => `* ${ bin } ` ) . join ( '\n' )
29
33
30
- const theCargoToml : CargoToml = parse ( await $ `yj -t < Cargo.toml` )
34
+ const theCargoToml : CargoToml = parse ( CargoToml , await $ `yj -t < Cargo.toml` )
31
35
const { package : { name, description, metadata : { details : { title} } } } = theCargoToml
32
36
const bin = name
33
37
const help = await $ `cargo run --quiet --bin ${ bin } -- --help`
34
- const repo : Repo = parse ( await $ `gh repo view --json url` )
38
+ const repo : Repo = parse ( Repo , await $ `gh repo view --json url` )
35
39
const extraBins = ( await $ `find src/bin/*.rs -type f -exec basename {} .rs \\;` ) . valueOf ( ) . split ( "\n" )
36
40
37
41
const autogenerated = `
You can’t perform that action at this time.
0 commit comments