node-cc-runner
Client for Closure Compiler web runner.
Install
npm install cc-runner
Usage
var runner = require('cc-runner');
var compiler = runner.create();
compiler.on('listening', () => {
compiler.status((error, res) => {
console.log(res);
});
compiler.compile({
optimizations: {
level: "SIMPLE_OPTIMIZATIONS"
},
sources: [{
fileName: 'bar.js',
code: '(console.log(function(){return 42-9;}));'
}]
}, (error, res) => {
console.log(res);
});
});API
create()
Returns compiler instance. Compiler is EventEmitter.
compiler
Event: 'online'
Emitted when Closure Compiler child process is started.
Event: 'listening'
Emitted when Closure Compiler runner server is listening for connections.
Event: 'error'
Forwards all errors.
compiler.status(options, callback)
Options:
levelString - is of type CompilationLevel, compilation leveldebugBoolean - whether to callsetDebugOptionsForCompilationLeveltypeBasedBoolean - whether to callsetTypeBasedOptimizationOptionswrappedOutputBoolean - whether to callsetWrappedOutputOptimizations
Callback arguments:
errorobjectoptionsObject - is of type CompilerOptions, compiler optionscompilerVersionsString - Closure Compiler version
compile.externs(callback)
Callback arguments:
errorobjectexternsArray - is of type List<SourceFile>, array of extern files
compiler.compile(data, callback)
Data:
externsArray -[{ fileName: String, code: String }], array of extern filessourcesArray -[{ fileName: String, code: String }], array of source files to compileoptimizationslevelString - is of type CompilationLevel, compilation leveldebugBoolean - whether to callsetDebugOptionsForCompilationLeveltypeBasedBoolean - whether to callsetTypeBasedOptimizationOptionswrappedOutputBoolean - whether to callsetWrappedOutputOptimizations
optionsObject - is of type CompilerOptions, compiler options
Callback arguments:
errorobjectresultObject - is of type Result, compilations resultssourceString - compiled sourcestatusString - SUCCESS|ERRORmessageString - error message if status is 'ERROR'exceptionObject - is of type Throwable, occurred exception
compiler.kill()
Kill Closure Compiler child process.
License
ISC