Skip to content

Commit

Permalink
feat: item prices script (#4252)
Browse files Browse the repository at this point in the history
* feat: item prices script

* fix: update script version
  • Loading branch information
scarf005 authored Feb 28, 2024
1 parent 0b5331a commit ebdb547
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 5 deletions.
50 changes: 50 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion import_map.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"$std/": "https://deno.land/std@0.208.0/",
"$asynciter/": "https://deno.land/x/asynciter@0.0.18/",
"$zod/": "https://deno.land/x/zod@v3.22.4/",
"$catjazz/": "https://deno.land/x/catjazz@v0.0.3/",
"$catjazz/": "https://deno.land/x/catjazz@v0.0.5/",
"$ts-reset/": "https://raw.githubusercontent.com/total-typescript/ts-reset/b2df073b6b0fcb9f9599408d88cf559344c10586/src/",
"$outdent/": "https://deno.land/x/outdent@v0.8.0/"
},
Expand Down
8 changes: 4 additions & 4 deletions scripts/migrate_legacy_unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Command } from "$catjazz/deps/cliffy.ts"
import { timeit } from "$catjazz/utils/timeit.ts"
import { applyRecursively } from "$catjazz/utils/transform.ts"
import { fmtJsonRecursively } from "$catjazz/utils/json_fmt.ts"
import { CataEntry, Entry, parseCataJson, readRecursively } from "$catjazz/utils/parse.ts"
import { CataEntry, Entry, parseCataJson, readJSONsRec } from "$catjazz/utils/parse.ts"
import { match, P } from "$catjazz/deps/ts_pattern.ts"
import { id } from "$catjazz/utils/id.ts"
import { deepMerge } from "$catjazz/deps/std/collection.ts"
Expand Down Expand Up @@ -122,11 +122,11 @@ export const schemasTransformer = (schemas: z.ZodTypeAny[]) => {
}
const main = () =>
new Command()
.option(...cliOptions.path)
.option(...cliOptions.paths)
.option(...cliOptions.quiet)
.option(...cliOptions.format)
.description(desc)
.action(async ({ path, format, quiet = false }) => {
.action(async ({ paths, format, quiet = false }) => {
const timeIt = timeit(quiet)

const transformer = schemasTransformer(schemas)
Expand All @@ -142,7 +142,7 @@ const main = () =>

const recursiveTransformer = applyRecursively(mapgenIgnoringTransformer)

const entries = await timeIt({ name: "reading JSON", val: readRecursively(path) })
const entries = await timeIt({ name: "reading JSON", val: readJSONsRec(paths) })

await timeIt({ name: "transform", val: recursiveTransformer(entries) })

Expand Down
33 changes: 33 additions & 0 deletions scripts/prices.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @module
*
* Extracts all item prices from given path recursively.
*/

import { z } from "https://deno.land/x/catjazz@v0.0.5/deps/zod.ts"
import { queryCli } from "https://deno.land/x/catjazz@v0.0.5/mod.ts"
import { type Currency, toCents } from "https://deno.land/x/catjazz@v0.0.5/units/mod.ts"
import { type Column, stringify } from "https://deno.land/std@0.217.0/csv/stringify.ts"

const parseCurrency = z.string().transform((c) => toCents(c as Currency))

const schema = z.object({
id: z.string(),
price_postapoc: parseCurrency,
})

const columns: Column[] = ["id", "price_postapoc"]

if (import.meta.main) {
const main = queryCli({
desc: "item prices",
schema,
map: (xs) => {
console.table(xs)
const csv = stringify(xs, { columns })
return csv
},
})

await main().parse(Deno.args)
}

0 comments on commit ebdb547

Please sign in to comment.