Watch API for apeman


Keywords
apeman, api
License
MIT
Install
npm install apeman-api-watch@2.0.9

Documentation

apeman-api-watch

Build Status Code Climate Code Coverage npm Version JS Standard

Watch API for apeman

Installation

$ npm install apeman-api-watch --save

Usage

Define a module in Apemanfile and run the server.

/** Example of Apemanfile.js */

'use strict'

const co = require('co')

let { NODE_ENV } = process.env

module.exports = {
  $cwd: __dirname,
  $pkg: { /* ... */ },
  $proto: [ /* ... */ ],
  $api: {
    // Define APIs
    'watch01': require('apeman-api-watch')(
      {
        logging: NODE_ENV === 'development'
      }
    )
  }
}

Then, call the module from client script

#!/usr/bin/env node

/**
 * Example client
 */
'use strict'

const co = require('co')
const apemanApiClient = require('apeman-api-client')
const EventSource = require('eventsource')

co(function * () {
  // Setup an client
  let api = yield apemanApiClient('/api')

  // Connect to a module
  let watch01 = yield api.connect('watch01')
  let pong = yield watch01.ping()
  /* ... */

  let es = api.eventSource('watch01')
  es.addEventListener('change', (event, filename) => {
    /* ... */
  })

  yield watch01.start('src/**/*.jsx')
})

Methods

The following methods are provided by the API.

.ping(pong)

Test the reachability of the api.

Param Type Description
pong string Pong message to return

.default()

.start(pattern)

Start watching

Param Type Description
pattern string Glob file name pattern

.stop(pattern)

Stop watching

Param Type Description
pattern string Glob file name pattern

.list()

.stopAll()

Stop all watches

License

This software is released under the MIT License.

Links