From 167b142486c3a6bd759944b8411a04fd4b4ddb94 Mon Sep 17 00:00:00 2001 From: Denis Gorbachev <829578+DenisGorbachev@users.noreply.github.com> Date: Sun, 21 Jul 2024 12:37:35 +0700 Subject: [PATCH] ci: fix parsing --- README.ts | 23 ++++++++++++----------- deno.json | 13 +++++++++++++ 2 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 deno.json diff --git a/README.ts b/README.ts index 81ed614..08c63e5 100755 --- a/README.ts +++ b/README.ts @@ -20,7 +20,7 @@ const CargoToml = z.object({ }), }) -type CargoToml = z.infer; +type CargoToml = z.infer const CargoMetadataSchema = z.object({ packages: z.array(z.object({ @@ -31,32 +31,33 @@ const CargoMetadataSchema = z.object({ })), }) -type CargoMetadata = z.infer; +type CargoMetadata = z.infer const Repo = z.object({ url: z.string().url(), }) -type Repo = z.infer; +type Repo = z.infer const $ = zx.$({ cwd: import.meta.dirname, }) -const parse = (schema: ZodSchema, input: { toString: () => string }) => schema.parse(JSON.parse(input.toString())) -const renderMarkdownList = (items: string[]) => items.map(bin => `* ${bin}`).join('\n') + +const parse = (schema: ZodSchema, input: zx.ProcessOutput) => schema.parse(JSON.parse(input.stdout)) +const renderMarkdownList = (items: string[]) => items.map((bin) => `* ${bin}`).join("\n") const theCargoToml: CargoToml = parse(CargoToml, await $`yj -t < Cargo.toml`) -const { package: { name, description, metadata: { details: { title } } } } = theCargoToml +const { package: { name, metadata: { details: { title } } } } = theCargoToml const bin = name const help = await $`cargo run --quiet --bin ${bin} -- --help` const theCargoMetadata: CargoMetadata = parse(CargoMetadataSchema, await $`cargo metadata --format-version 1`) -const thePackageMetadata = theCargoMetadata.packages.find(p => p.name == name) -assert(thePackageMetadata, 'Could not find package metadata') +const thePackageMetadata = theCargoMetadata.packages.find((p) => p.name == name) +assert(thePackageMetadata, "Could not find package metadata") const target = thePackageMetadata.targets[0] -assert(target, 'Could not find package first target') +assert(target, "Could not find package first target") const doc = await $`cargo doc2readme --template README.jl --target-name ${target.name} --out -` const repo: Repo = parse(Repo, await $`gh repo view --json url`) -const extraBins = (await $`find src/bin/*.rs -type f -exec basename {} .rs \\;`).valueOf().split('\n') +const extraBins = (await $`find src/bin/*.rs -type f -exec basename {} .rs \\;`).valueOf().split("\n") assertEquals(repo.url, theCargoToml.package.repository) @@ -90,7 +91,7 @@ ${help.stdout.trim()} ## Additional binaries -${renderMarkdownList(extraBins.map(bin => `\`${bin}\``))} +${renderMarkdownList(extraBins.map((bin) => `\`${bin}\``))} ## Gratitude diff --git a/deno.json b/deno.json new file mode 100644 index 0000000..363eded --- /dev/null +++ b/deno.json @@ -0,0 +1,13 @@ +{ + "fmt": { + "lineWidth": 100500, + "semiColons": false + }, + "compilerOptions": { + "strict": true, + "noErrorTruncation": true, + "exactOptionalPropertyTypes": true, + "noFallthroughCasesInSwitch": true, + "noUncheckedIndexedAccess": true + } +}