forked from cucumber/gherkin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-cli.mjs
24 lines (21 loc) · 974 Bytes
/
test-cli.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { IdGenerator } from '@cucumber/messages'
import { Command } from 'commander'
import { readFileSync } from "fs";
import { generateMessages, makeSourceEnvelope } from './dist/src/index.js'
const program = new Command()
program.option('--no-source', 'Do not output Source messages')
program.option('--no-ast', 'Do not output GherkinDocument messages')
program.option('--no-pickles', 'Do not output Pickle messages')
program.parse(process.argv)
const [path] = program.args
const options = {
defaultDialect: 'en',
includeSource: program.opts().source,
includeGherkinDocument: program.opts().ast,
includePickles: program.opts().pickles,
newId: IdGenerator.incrementing()
}
const content = readFileSync(path, { encoding: 'utf-8' })
const { source: { data, uri, mediaType } } = makeSourceEnvelope(content, path)
const results = generateMessages(data, uri, mediaType, options)
process.stdout.write(results.map(item => JSON.stringify(item)).join('\n'))