Skip to content

Commit c686882

Browse files
author
Benjamin E. Coe
authored
refactor!: upgrade deps drop Node 6/8 (#71)
1 parent 48b16a9 commit c686882

File tree

5 files changed

+785
-529
lines changed

5 files changed

+785
-529
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
node: [6, 8, 10, 14]
13+
node: [10, 12, 14]
1414
steps:
1515
- uses: actions/checkout@v1
1616
- uses: actions/setup-node@v1

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ If you `coerce` in weird ways, things might not work correctly.
7575
`$ npm test`
7676
`$ npm test -- --watch` during development
7777

78+
## Supported Node.js Versions
79+
80+
Libraries in this ecosystem make a best effort to track
81+
[Node.js' release schedule](https://nodejs.org/en/about/releases/). Here's [a
82+
post on why we think this is important](https://medium.com/the-node-js-collection/maintainers-should-consider-following-node-js-release-schedule-ab08ed4de71a).
7883

7984
## License
8085

index.js

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
const yargs = require('yargs/yargs');
43
const flatten = require('flat');
54
const camelcase = require('camelcase');
65
const decamelize = require('decamelize');
@@ -24,6 +23,40 @@ function keyToFlag(key) {
2423
return key.length === 1 ? `-${key}` : `--${key}`;
2524
}
2625

26+
function parseCommand(cmd) {
27+
const extraSpacesStrippedCommand = cmd.replace(/\s{2,}/g, ' ');
28+
const splitCommand = extraSpacesStrippedCommand.split(/\s+(?![^[]*]|[^<]*>)/);
29+
const bregex = /\.*[\][<>]/g;
30+
const firstCommand = splitCommand.shift();
31+
32+
if (!firstCommand) { throw new Error(`No command found in: ${cmd}`); }
33+
const parsedCommand = {
34+
cmd: firstCommand.replace(bregex, ''),
35+
demanded: [],
36+
optional: [],
37+
};
38+
39+
splitCommand.forEach((cmd, i) => {
40+
let variadic = false;
41+
42+
cmd = cmd.replace(/\s/g, '');
43+
if (/\.+[\]>]/.test(cmd) && i === splitCommand.length - 1) { variadic = true; }
44+
if (/^\[/.test(cmd)) {
45+
parsedCommand.optional.push({
46+
cmd: cmd.replace(bregex, '').split('|'),
47+
variadic,
48+
});
49+
} else {
50+
parsedCommand.demanded.push({
51+
cmd: cmd.replace(bregex, '').split('|'),
52+
variadic,
53+
});
54+
}
55+
});
56+
57+
return parsedCommand;
58+
}
59+
2760
function unparseOption(key, value, unparsed) {
2861
if (typeof value === 'string') {
2962
unparsed.push(keyToFlag(key), value);
@@ -54,9 +87,7 @@ function unparsePositional(argv, options, unparsed) {
5487
// e.g.: build <first> <second> <rest...>
5588
if (options.command) {
5689
const { 0: cmd, index } = options.command.match(/[^<[]*/);
57-
const { demanded, optional } = yargs()
58-
.getCommandInstance()
59-
.parseCommand(`foo ${options.command.substr(index + cmd.length)}`);
90+
const { demanded, optional } = parseCommand(`foo ${options.command.substr(index + cmd.length)}`);
6091

6192
// Push command (can be a deep command)
6293
unparsed.push(...cmd.trim().split(/\s+/));

0 commit comments

Comments
 (0)