Skip to content

Commit

Permalink
Merge 7bd47e4 into f8e735b
Browse files Browse the repository at this point in the history
  • Loading branch information
fthouraud committed Aug 17, 2021
2 parents f8e735b + 7bd47e4 commit 4e697a1
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jspm_packages
.DS_Store
.idea
*.iml
bin
bin/*
_doc
/examples/features/file_system/files/generated
/examples/features/file_system/files/deeply
Expand All @@ -50,3 +50,5 @@ _doc
!.yarn/sdks
!.yarn/versions
.pnp.*

!bin/veggies.js
3 changes: 3 additions & 0 deletions bin/veggies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

require('../src/cli')
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"url": "https://github.com/ekino/veggies.git"
},
"main": "src/index.js",
"bin": "./bin/veggies.js",
"author": "plouc <https://github.com/plouc>",
"maintainers": [
{
Expand All @@ -38,7 +39,8 @@
"natural-compare": "1.4",
"pretty-format": "27.0",
"request": "2.88",
"tough-cookie": "4.0"
"tough-cookie": "4.0",
"yargs": "17.1.1"
},
"devDependencies": {
"@commitlint/config-conventional": "12.x",
Expand Down
57 changes: 57 additions & 0 deletions src/cli/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'use strict'

const yargs = require('yargs')
const CucumberCli = require('@cucumber/cucumber/lib/cli').default

const veggiesArguments = ['cleanSnapshots', 'preventSnapshotsCreation', 'u', 'updateSnapshots']

const getValue = (value) => {
switch (typeof value) {
case 'string':
return ` "${value}"`
case 'number':
case 'bigint':
return ` ${value.toString(10)}`
default:
return undefined
}
}

const getCucumberArgs = (argv) => {
const { args, $0: cliName, _: nonPrefixedArgs, ...cliArgs } = argv

return Object.entries(cliArgs).reduce(
(allArgs, [arg, value]) => {
if (!veggiesArguments.includes(arg)) {
const argument = `-${arg.length > 1 ? '-' : ''}${arg}`
if (Array.isArray(value)) {
value.forEach((it) => {
allArgs.push(argument, getValue(it))
})
} else {
allArgs.push(argument)
const preparedValue = getValue(value)
if (preparedValue) allArgs.push(preparedValue)
}
}
return allArgs
},
[process.argv[0], cliName, ...nonPrefixedArgs]
)
}

yargs
.scriptName('veggies')
.usage('$0 [cucumber-args]')
.command('$0 [args]', "Run 'cucumber-cli' after having removed custom options", async function (
argv
) {
const cucumberArgs = getCucumberArgs(argv.argv)

await new CucumberCli({
argv: cucumberArgs,
cwd: process.cwd(),
stdout: process.stdout,
}).run()
})
.help().argv
18 changes: 18 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -963,8 +963,11 @@ __metadata:
request: 2.88
sinon: 11.x
tough-cookie: 4.0
yargs: 17.1.1
peerDependencies:
"@cucumber/cucumber": ">=7.0.0"
bin:
veggies: ./bin/veggies.js
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -7911,6 +7914,21 @@ fsevents@^2.3.2:
languageName: node
linkType: hard

"yargs@npm:17.1.1":
version: 17.1.1
resolution: "yargs@npm:17.1.1"
dependencies:
cliui: ^7.0.2
escalade: ^3.1.1
get-caller-file: ^2.0.5
require-directory: ^2.1.1
string-width: ^4.2.0
y18n: ^5.0.5
yargs-parser: ^20.2.2
checksum: c2a16b61eb0db8882becd0aa382a5c59b87afcd17b35dd7077b3c9d83f77a3ad3de1526e4f1cf940f9481d7ce537e883af7c16879c33258724a09bc43a04e8ea
languageName: node
linkType: hard

"yargs@npm:^16.0.3, yargs@npm:^16.2.0":
version: 16.2.0
resolution: "yargs@npm:16.2.0"
Expand Down

0 comments on commit 4e697a1

Please sign in to comment.