3
3
import * as zx from 'npm:zx'
4
4
import { z , ZodSchema } from 'https://deno.land/x/[email protected] /mod.ts'
5
5
import { assertEquals } from 'https://jsr.io/@std/assert/1.0.0/equals.ts'
6
+ import { assert } from 'https://jsr.io/@std/assert/1.0.0/assert.ts'
6
7
7
8
const CargoToml = z . object ( {
8
9
package : z . object ( {
@@ -21,6 +22,17 @@ const CargoToml = z.object({
21
22
22
23
type CargoToml = z . infer < typeof CargoToml > ;
23
24
25
+ const CargoMetadataSchema = z . object ( {
26
+ packages : z . array ( z . object ( {
27
+ name : z . string ( ) ,
28
+ targets : z . array ( z . object ( {
29
+ name : z . string ( ) ,
30
+ } ) ) ,
31
+ } ) ) ,
32
+ } )
33
+
34
+ type CargoMetadata = z . infer < typeof CargoMetadataSchema > ;
35
+
24
36
const Repo = z . object ( {
25
37
url : z . string ( ) . url ( ) ,
26
38
} )
@@ -37,6 +49,12 @@ const theCargoToml: CargoToml = parse(CargoToml, await $`yj -t < Cargo.toml`)
37
49
const { package : { name, description, metadata : { details : { title } } } } = theCargoToml
38
50
const bin = name
39
51
const help = await $ `cargo run --quiet --bin ${ bin } -- --help`
52
+ const theCargoMetadata : CargoMetadata = parse ( CargoMetadataSchema , await $ `cargo metadata --format-version 1` )
53
+ const thePackageMetadata = theCargoMetadata . packages . find ( p => p . name == name )
54
+ assert ( thePackageMetadata , 'Could not find package metadata' )
55
+ const target = thePackageMetadata . targets [ 0 ]
56
+ assert ( target , 'Could not find package first target' )
57
+ const doc = await $ `cargo doc2readme --template README.jl --target-name ${ target . name } --out -`
40
58
const repo : Repo = parse ( Repo , await $ `gh repo view --json url` )
41
59
const extraBins = ( await $ `find src/bin/*.rs -type f -exec basename {} .rs \\;` ) . valueOf ( ) . split ( '\n' )
42
60
@@ -56,35 +74,7 @@ ${autogenerated}
56
74
[](${ repo . url } )
57
75
[](https://docs.rs/${ name } )
58
76
59
- ## Overview
60
-
61
- ${ description }
62
-
63
- ## Examples
64
-
65
- \`\`\`shell
66
- # Create a GitHub repo & init a Rust project
67
- ${ bin } --name my-new-project
68
-
69
- # Copy configs from existing project
70
- ${ bin } --name my-new-project --copy-configs-from ~/workspace/my-existing-project
71
-
72
- # Clone to a specific directory
73
- ${ bin } --name my-new-project --dir ~/workspace/my-new-project
74
-
75
- # Create a public repo
76
- ${ bin } --name my-new-project --repo-create-cmd "gh repo create --public {{name}}"
77
-
78
- # Create a lib instead of bin
79
- ${ bin } --name my-new-project --project-init-cmd "cargo init --lib"
80
- \`\`\`
81
-
82
- ## Features
83
-
84
- * [x] Uses existing \`gh\`, \`git\`, \`cargo\` commands
85
- * [x] Supports overrides for all commands
86
- * [x] Supports substitutions (see help below)
87
- * [x] Can be used as a library
77
+ ${ doc . stdout . trim ( ) }
88
78
89
79
## Installation
90
80
0 commit comments