1
- #!/usr/bin/env -S deno run --allow-read --allow-run=git,cargo --allow-env=DENOEXEC_STRING_LITERAL_DEBUG
1
+ #!/usr/bin/env -S deno run --allow-read --allow-run=bash, git,cargo --allow-env --allow-sys
2
2
3
- import * as toml from "jsr:@std/toml"
4
- import { $ , _ } from "https://deno.land/x/[email protected] /mod.ts" ;
3
+ import * as zx from 'npm:zx'
5
4
6
5
interface CargoToml {
7
6
package : {
8
- name : string
7
+ name : string ,
8
+ description : string
9
9
}
10
10
}
11
11
12
- const dirname = import . meta. dirname
13
- const decoder = new TextDecoder ( ) ;
14
- const theCargoTomlText = await Deno . readTextFile ( `${ dirname } /Cargo.toml` )
15
- const theCargoToml = toml . parse ( theCargoTomlText ) as unknown as CargoToml
16
- const packageName = theCargoToml . package . name
17
- const bin = packageName
18
- const help = await new Deno . Command ( "cargo" , {
19
- args : [ 'run' , '--bin' , bin , '--' , '--help' ]
20
- } ) . output ( ) ;
21
- if ( ! help . success ) throw help
22
- const repo = await getGitHubRepo ( )
23
-
24
- async function getGitHubRepo ( ) {
25
- const url = ( await $ ( _ `git remote get-url origin` ) ) . trim ( ) ;
26
- const match = url . match ( / g i t h u b \. c o m [: \/ ] ( [ ^ . ] + ) / ) ;
27
- if ( match ) {
28
- return match [ 1 ]
29
- } else {
30
- throw new Error ( `Could not extract org/repo from ${ url } ` )
31
- }
12
+ interface Repo {
13
+ url : string
32
14
}
33
15
16
+ const $ = zx . $ ( {
17
+ cwd : import . meta. dirname
18
+ } )
19
+
20
+ const parse = ( input : { toString : ( ) => string } ) => JSON . parse ( input . toString ( ) )
21
+
22
+ const theCargoToml : CargoToml = parse ( await $ `yj -t < Cargo.toml` )
23
+ const name = theCargoToml . package . name
24
+ const bin = name
25
+ const description = theCargoToml . package . description
26
+ const help = await $ `cargo run --quiet --bin ${ bin } -- --help`
27
+ const repo : Repo = parse ( await $ `gh repo view --json url` )
28
+
34
29
const autogenerated = `
35
30
<!-- DO NOT EDIT -->
36
31
<!-- This file is automatically generated by README.ts. -->
@@ -42,12 +37,12 @@ ${autogenerated}
42
37
43
38
# Create Rust GitHub repo
44
39
45
- [](https://github.com/ ${ repo } )
46
- [](https://docs.rs/${ packageName } )
40
+ [](${ repo . url } )
41
+ [](https://docs.rs/${ name } )
47
42
48
43
## Overview
49
44
50
- \` ${ bin } \` is a CLI program that creates a new repository on GitHub, clones it locally, initializes a Rust project, copies the configs from a pre-existing directory.
45
+ ${ description }
51
46
52
47
## Examples
53
48
@@ -77,13 +72,13 @@ ${bin} --name my-new-project --cargo-init-args '--lib'
77
72
## Installation
78
73
79
74
\`\`\`shell
80
- cargo install ${ packageName }
75
+ cargo install ${ name }
81
76
\`\`\`
82
77
83
78
## Usage
84
79
85
80
\`\`\`
86
- ${ decoder . decode ( help . stdout ) . trim ( ) }
81
+ ${ help . stdout . trim ( ) }
87
82
\`\`\`
88
83
89
84
## License
0 commit comments