Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

Expose a JS API #80

Open
Andarist opened this issue Nov 14, 2018 · 5 comments
Open

Expose a JS API #80

Andarist opened this issue Nov 14, 2018 · 5 comments

Comments

@Andarist
Copy link

Requested Update

Expose a JS API so the module can be required and used as a function.

Why Is This Update Needed?

Currently this module is only a CLI tool, but it would be great to use it programatically too.

Are There Examples Of This Requested Update Elsewhere?

n/a

@yowainwright
Copy link
Contributor

@Andarist great thinking.

@hamidzr
Copy link

hamidzr commented Dec 19, 2018

this feature would help with using this module in unit tests with eg "mocha"

@Reeywhaar
Copy link

Yep, integration into build process seems more error-prone rather than checking each time manually, and wrap this lib into exec seems overload. I can make a PR, though I am not sure about api yet.

@nemoDreamer
Copy link

You've already got an API by using Caporal.
All you need is to not run .parse in the module's index.js entry-point, and instead export prog.
Then, add a bin entry to your package.json that's a script that imports prog and runs .parse(process.argv) on it.

Then, non-CLI users will be able to simply execute your Caporal prog by doing:
(see https://github.com/mattallty/Caporal.js#programmatic-caporal-usage)

const esCheck = require('es-check');

esCheck.exec(['es5', 'my/files/**/*.js', {
  module: true,
  allowHashBang: false,
  not: 'glob/to/ignore'
});

Of course ideally, you'd wrap the prog export up in a nicer method so that folks can do:

const esCheck = require('es-check');

esCheck.run({
  es: 'es5',
  files: [
    'my/files/**/*.js',
    'some/other/**/*.{js,jsx}'
  ],
  module: true,
  allowHashBang: false,
  not: 'glob/to/ignore'
});

@nemoDreamer
Copy link

Note: I just wrote a script to capture the output of es-check using child_process's spawnSync, and then do some fancy clean-up to remove all the stack traces and only end up with a list of "erroring files". Problem is: it seems that very large Buffers get cut off?! Might need to move to consume the Buffer as it's getting written, with spawn instead.

But that does highlight the need for a --name-only flag, or have Caporal's built-in verbosity handle it: only dump the stack traces with logger.debug or something.

Might spin up a PR 😜

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants