Skip to content

Commit 858fc01

Browse files
doc: improve README.ts
1 parent d313154 commit 858fc01

File tree

2 files changed

+25
-30
lines changed

2 files changed

+25
-30
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.ts

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,31 @@
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
22

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'
54

65
interface CargoToml {
76
package: {
8-
name: string
7+
name: string,
8+
description: string
99
}
1010
}
1111

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(/github\.com[:\/]([^.]+)/);
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
3214
}
3315

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+
3429
const autogenerated = `
3530
<!-- DO NOT EDIT -->
3631
<!-- This file is automatically generated by README.ts. -->
@@ -42,12 +37,12 @@ ${autogenerated}
4237
4338
# Create Rust GitHub repo
4439
45-
[![Build](https://github.com/${repo}/actions/workflows/ci.yml/badge.svg)](https://github.com/${repo})
46-
[![Documentation](https://docs.rs/${packageName}/badge.svg)](https://docs.rs/${packageName})
40+
[![Build](${repo.url}/actions/workflows/ci.yml/badge.svg)](${repo.url})
41+
[![Documentation](https://docs.rs/${name}/badge.svg)](https://docs.rs/${name})
4742
4843
## Overview
4944
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}
5146
5247
## Examples
5348
@@ -77,13 +72,13 @@ ${bin} --name my-new-project --cargo-init-args '--lib'
7772
## Installation
7873
7974
\`\`\`shell
80-
cargo install ${packageName}
75+
cargo install ${name}
8176
\`\`\`
8277
8378
## Usage
8479
8580
\`\`\`
86-
${decoder.decode(help.stdout).trim()}
81+
${help.stdout.trim()}
8782
\`\`\`
8883
8984
## License

0 commit comments

Comments
 (0)