-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d313154
commit 858fc01
Showing
2 changed files
with
25 additions
and
30 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,31 @@ | ||
#!/usr/bin/env -S deno run --allow-read --allow-run=git,cargo --allow-env=DENOEXEC_STRING_LITERAL_DEBUG | ||
#!/usr/bin/env -S deno run --allow-read --allow-run=bash,git,cargo --allow-env --allow-sys | ||
|
||
import * as toml from "jsr:@std/toml" | ||
import { $, _ } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import * as zx from 'npm:zx' | ||
|
||
interface CargoToml { | ||
package: { | ||
name: string | ||
name: string, | ||
description: string | ||
} | ||
} | ||
|
||
const dirname = import.meta.dirname | ||
const decoder = new TextDecoder(); | ||
const theCargoTomlText = await Deno.readTextFile(`${dirname}/Cargo.toml`) | ||
const theCargoToml = toml.parse(theCargoTomlText) as unknown as CargoToml | ||
const packageName = theCargoToml.package.name | ||
const bin = packageName | ||
const help = await new Deno.Command("cargo", { | ||
args: ['run', '--bin', bin, '--', '--help'] | ||
}).output(); | ||
if (!help.success) throw help | ||
const repo = await getGitHubRepo() | ||
|
||
async function getGitHubRepo() { | ||
const url = (await $(_`git remote get-url origin`)).trim(); | ||
const match = url.match(/github\.com[:\/]([^.]+)/); | ||
if (match) { | ||
return match[1] | ||
} else { | ||
throw new Error(`Could not extract org/repo from ${url}`) | ||
} | ||
interface Repo { | ||
url: string | ||
} | ||
|
||
const $ = zx.$({ | ||
cwd: import.meta.dirname | ||
}) | ||
|
||
const parse = (input: { toString: () => string }) => JSON.parse(input.toString()) | ||
|
||
const theCargoToml: CargoToml = parse(await $`yj -t < Cargo.toml`) | ||
const name = theCargoToml.package.name | ||
const bin = name | ||
const description = theCargoToml.package.description | ||
const help = await $`cargo run --quiet --bin ${bin} -- --help` | ||
const repo: Repo = parse(await $`gh repo view --json url`) | ||
|
||
const autogenerated = ` | ||
<!-- DO NOT EDIT --> | ||
<!-- This file is automatically generated by README.ts. --> | ||
|
@@ -42,12 +37,12 @@ ${autogenerated} | |
# Create Rust GitHub repo | ||
[](https://github.com/${repo}) | ||
[](https://docs.rs/${packageName}) | ||
[](${repo.url}) | ||
[](https://docs.rs/${name}) | ||
## Overview | ||
\`${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. | ||
${description} | ||
## Examples | ||
|
@@ -77,13 +72,13 @@ ${bin} --name my-new-project --cargo-init-args '--lib' | |
## Installation | ||
\`\`\`shell | ||
cargo install ${packageName} | ||
cargo install ${name} | ||
\`\`\` | ||
## Usage | ||
\`\`\` | ||
${decoder.decode(help.stdout).trim()} | ||
${help.stdout.trim()} | ||
\`\`\` | ||
## License | ||
|