Generate externs for use with Google Closure Compiler
Note from the developer: The externs generator works pretty well for a wide selection of JS libraries, but there are many exceptions (see the issues for examples). I try to respond to and diagnose issues and I am glad to accept Pull Requests, but I am not actively using or maintaining this.
If you find that it couldn't properly generate externs, I would advise:
This is a tool that generates an extern file detailing an object's properties, methods, and prototype. It's specifically meant for use with the Google Closure Compiler, which needs any variables defined outside of your code to be declared so that it won't rename or remove them.
For a more in-depth explanation of Google Closure Compiler advanced compilation and externs, see the Google Documentation.
Install the cli script:
npm install -g externs-generator
curl http://code.jquery.com/jquery-1.9.1.js -o jquery.js
generate-extern -f jquery.js -n jQuery -o jquery-extern.js
curl -O https://cdnjs.cloudflare.com/ajax/libs/react/15.0.2/react.js
curl -O https://cdnjs.cloudflare.com/ajax/libs/react/15.0.2/react-dom.js
curl -O http://cdn.jsdelivr.net/webjars/org.webjars.npm/react-relay/0.8.0/dist/relay.js
generate-extern -f react.js,react-dom.js,relay.js -n Relay -o relay-extern.js
The strategy can be broken into three steps:
lein figwheel dev
lein cljsbuild auto cli
./bin/extern -f .js -n -o extern.js
chmod +x ./bin/externwhen it is recreated
lein doo phantom test
With homebrew, this is as simple as
brew install closure-compiler. For other options, see the Closure Compiler docs
closure-compiler --compilation_level ADVANCED [--externs externs.js,] --js file.js[,] [--js_output_file output.js]
Ideally, it should run successfully and the generated output should not mangle any symbols you are using from the library
Based on http://www.dotnetwise.com/Code/Externs/