-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.ts
39 lines (34 loc) · 1.04 KB
/
cli.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { parse } from "https://deno.land/std/flags/mod.ts"
import { pipe } from "./deps.ts"
import { CLArguments } from "./types.ts"
import { processCSV } from "./csv.ts"
import { createSVG } from "./svg.ts"
import {
replaceExtension,
decorateWithOptions,
combineOptions,
logInfo,
} from "./cli-helpers.ts"
import { defaultChartOptions } from "./chart-options.ts"
try {
const {
i: inputFile,
o: outputFile = replaceExtension(inputFile),
...userOptions
} = parse(Deno.args) as CLArguments
if (!inputFile) throw new Error("Please specify input file with -i flag")
const csv = new TextDecoder("utf-8").decode(await Deno.readFile(inputFile))
logInfo({ csv, userOptions, defaultChartOptions })
const img = pipe(
processCSV,
pipe(
combineOptions,
decorateWithOptions
)([userOptions, defaultChartOptions]),
createSVG
)(csv)
await Deno.writeFile(outputFile, new TextEncoder().encode(img))
console.log(`Chart has been successfuly written into file ${outputFile}`)
} catch (err) {
console.error(err)
}