GitHunt
RA

ralder/node-cc-runner

Closure Compiler web runner client

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:

  • level String - is of type CompilationLevel, compilation level
  • debug Boolean - whether to call setDebugOptionsForCompilationLevel
  • typeBased Boolean - whether to call setTypeBasedOptimizationOptions
  • wrappedOutput Boolean - whether to call setWrappedOutputOptimizations

Callback arguments:

  • error
  • object
    • options Object - is of type CompilerOptions, compiler options
    • compilerVersions String - Closure Compiler version

compile.externs(callback)

Callback arguments:

  • error
  • object
    • externs Array - is of type List<SourceFile>, array of extern files

compiler.compile(data, callback)

Data:

  • externs Array - [{ fileName: String, code: String }], array of extern files
  • sources Array - [{ fileName: String, code: String }], array of source files to compile
  • optimizations
    • level String - is of type CompilationLevel, compilation level
    • debug Boolean - whether to call setDebugOptionsForCompilationLevel
    • typeBased Boolean - whether to call setTypeBasedOptimizationOptions
    • wrappedOutput Boolean - whether to call setWrappedOutputOptimizations
  • options Object - is of type CompilerOptions, compiler options

Callback arguments:

  • error
  • object
    • result Object - is of type Result, compilations results
    • source String - compiled source
    • status String - SUCCESS|ERROR
    • message String - error message if status is 'ERROR'
    • exception Object - is of type Throwable, occurred exception

compiler.kill()

Kill Closure Compiler child process.

License

ISC