antonmedv / jsize

Find out minified and gzipped npm package size
MIT License
178 stars 12 forks source link

Add better parse function #27

Closed antonmedv closed 7 years ago

antonmedv commented 7 years ago

To support this: jsize react + react-dom

DylanPiercey commented 7 years ago

What about using something as simple as:

/**
 * Normalizes cli arguments list.
 * Replaces `jsize react + react-dom`
 * With `jsize react+react-dom`
 */
process.argv.forEach((arg, i, args) => {
  if (arg === '+') {
    const prev = args[i - 1]
    const next = args[i + 1]
    args.splice(i - 1, 3, prev + '+' + next)
  }
})

Before passing the args to commander?

It's also pretty easily extended if we add support for other operations:

/**
 * Normalizes cli arguments list.
 * Replaces `jsize react + react-dom`
 * With `jsize react+react-dom`
 */
process.argv.forEach((arg, i, args) => {
  const prev = args[i - 1]
  const next = args[i + 1]

  switch (arg) {
    case '+':
      args.splice(i - 1, 3, prev + '+' + next)
      break
    case '-':
      // Normalize to something else.
      break
  }
})
antonmedv commented 7 years ago

I think we can merge your PR first and then I'll rebase my PR.

My implementation allow any format:

And it's simple bottom-up parsing algorithm. Can be easily extended.