-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
109 lines (99 loc) · 3 KB
/
index.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { Command, Option } from "commander"
import {
slateToLexical as legacySlateToLexical,
slateToHtml as legacySlateToHtml,
} from "./src/legacyConverter"
import {
slateToHtml,
slateToLexical,
batchSlateToHtml,
batchSlateToLexical,
} from "./src/converter"
import { strainFetcher } from "./src/retriever"
const program = new Command()
program
.name("convert")
.description("CLI to convert slatejs json to lexical format")
.version("1.0.0")
program
.command("slate-to-html")
.description("convert slatejs format to html")
.requiredOption("-f, --file <input>", "input file in slatejs format")
.action(async (options) => {
console.log(await slateToHtml(options.file))
})
program
.command("batch-slate-to-html")
.description("convert a folder of slatejs format files to html")
.requiredOption(
"-i, --input <input>",
"input folder with slatejs format files",
)
.requiredOption(
"-o, --output <output>",
"output folder where html files will be written",
)
.action(async (options) => {
await batchSlateToHtml(options.input, options.output)
})
program
.command("slate-to-lexical")
.description("convert slatejs to lexical format")
.requiredOption("-f, --file <input>", "input file in slatejs format")
.action(async (options) => {
console.log(await slateToLexical(options.file))
})
program
.command("batch-slate-to-lexical")
.description("convert a folder of slatejs files to lexical format")
.requiredOption(
"-i, --input <input>",
"input folder with slatejs format files",
)
.requiredOption(
"-o, --output <output>",
"output folder where lexical files will be written",
)
.action(async (options) => {
await batchSlateToLexical(options.input, options.output)
})
program
.command("legacy-slate-to-html")
.description("convert legacy slatejs format to html")
.requiredOption("-f, --file <input>", "input file in legacy slatejs format")
.action(async (options) => {
console.log(await legacySlateToHtml(options.file))
})
program
.command("legacy-slate-to-lexical")
.description("convert legacy slatejs to lexical format")
.requiredOption("-f, --file <input>", "input file in legacy slatejs format")
.action(async (options) => {
console.log(await legacySlateToLexical(options.file))
})
program
.command("strain-info")
.description("retrieve strain information from stock grpc service")
.requiredOption("-i, --id <identifier>", "strain identifier or DBS id")
.addOption(
new Option("-a, --host <address>", "host address of stock grpc service")
.default("stock-api")
.env("STOCK_API_SERVICE_HOST"),
)
.addOption(
new Option("-p, --port <port>", "port of stock grpc service").env(
"STOCK_API_SERVICE_PORT",
),
)
.action(async (options) => {
try {
const output = await strainFetcher(
`http://${options.host}:${options.port}`,
options.id,
)()
console.log(output)
} catch (error) {
console.log(error)
}
})
await program.parseAsync()