-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
41 lines (35 loc) · 1.41 KB
/
cli.js
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
#!/usr/bin/env node
const cmd = require('commander')
const gherkin2robot = require('.')
const { readFile, writeFile } = require('fs')
const { promisify } = require('util')
const package = require('./package.json')
cmd
.description('Convert the Gherkin feature file FILE into a Robot Framework test suite')
.version(package.version)
.usage('[options] <FILE>')
.option( '-o, --output <FILE>'
, 'write the Robot Framework version to the given file. Default is the standard output')
.option( '-s, --stepdefs-path <FILE>'
, 'the path to the step definitions, which will be imported. Default is "./stepdefs.robot"')
.parse(process.argv)
const inputFile = cmd.args[0]
const stepdefsPath = cmd.stepdefsPath || './stepdefs.robot'
const outputFile = cmd.output || '-'
if (!inputFile) {
console.error('No input file given')
process.exit(1)
}
const readFileP = promisify(readFile)
const writeFileP = promisify(writeFile)
readFileP(inputFile, { encoding: 'utf-8' })
.then(gherkin => gherkin2robot(gherkin, stepdefsPath))
.then(output => outputFile === '-' ? console.log(output) : writeFileP( outputFile
, output
, { encoding: 'utf-8' }
)
)
.catch(error => {
console.error(error.message);
process.exit(1)
})