cc-runner
v0.1.1
Published
Closure Compiler Runner
Downloads
6
Readme
node-cc-runner
Client for Closure Compiler web runner.
Install
npm install cc-runner
Usage
const runner = require('cc-runner');
const compiler = runner();
compiler.start(err => {
if (err) {
console.error(err.stack);
return;
}
compiler.status((err, res) => {
console.log(err || res);
});
compiler.compile({
optimizations: { level: "SIMPLE_OPTIMIZATIONS" },
sources: [ {
fileName: 'bar.js',
code: '(console.log(function(){return 42-9;}));'
} ]
}, (err, res) => {
console.log(err || res);
});
});
Instantiation
Runner instance will automatically launch child process on first request (if jar
option is not false
) and kill after last response (after timeout
period).
Options
jar
- path to Closure Compiler web runner jar file (default: automatically downloadedcc-web-runner-standalone-1.0.8.jar
).url
- Closure Compiler web runner service URL to be used in API calls (default:http://127.0.0.1:8081/
).timeout
- timeout since last request after which web service is stopped (default:100ms
). Iftimeout
is0
, then web service is not stopped automatically.
const runner = require('cc-runner');
// Custom Closure Compiler web runner build
const customCCWJar = runner({
jar: '/path/to/cc-web-runner.jar',
url: 'http://localhost:9080/'
});
customCCWJar.status((err, res) => {
console.log('Status response from custom build');
console.log(res);
});
// If Closure Compiler web runner is not already listening
// on 8080 port, start and stop methods will fail on this instance.
// `jar: false` option is useful when Closure Compiler web runner
// service is managed from outside of Node.js process,
// e.g. is running on servlet container.
const clientOnly = runner({
jar: false,
url: 'http://localhost:8080/'
});
start([callback])
Start Closure Compiler web runner service. Callback is called after the service started to listen for requests.
Callback arguments:
error
stop([callback])
Stop Closure Compiler web runner service.
status([options,] callback)
Options:
level
String - is of type CompilationLevel, compilation leveldebug
Boolean - whether to callsetDebugOptionsForCompilationLevel
typeBased
Boolean - whether to callsetTypeBasedOptimizationOptions
wrappedOutput
Boolean - whether to callsetWrappedOutputOptimizations
Callback arguments:
error
object
options
Object - is of type CompilerOptions, compiler optionscompilerVersions
String - Closure Compiler version
externs(callback)
Callback arguments:
error
object
externs
Array - is of type List<SourceFile>, array of extern files
compile(data, callback)
Data:
externs
Array -[{ fileName: String, code: String }]
, array of extern filessources
Array -[{ fileName: String, code: String }]
, array of source files to compileoptimizations
level
String - is of type CompilationLevel, compilation leveldebug
Boolean - whether to callsetDebugOptionsForCompilationLevel
typeBased
Boolean - whether to callsetTypeBasedOptimizationOptions
wrappedOutput
Boolean - whether to callsetWrappedOutputOptimizations
options
Object - is of type CompilerOptions, compiler options
Callback arguments:
error
object
result
Object - is of type Result, compilations resultssource
String - compiled sourcestatus
String - SUCCESS|ERRORmessage
String - error message if status is 'ERROR'exception
Object - is of type Throwable, occurred exception
License
ISC