#!/usr/bin/env node

/**
 * Start all apps on debug mode.
 *
 * Generated by {{generator}} on {{today}},
 * from a template provided by {{ pkg.name }}.
 *
 * @see https://github.com/visionmedia/debug
 */

'use strict'

process.chdir(`${__dirname}/{{{cwd}}}`)

/** Names of debugs to enable */
const DEBUG = [
  'apeman:*',  // Apeman buildin
  'project:*' // Project specific
].join(',')

process.env.DEBUG = process.env.DEBUG || DEBUG

const apeman = require('apeman')
const all = require.resolve('../app/all')

/** Start and debug all apps. */
function debugAll (onStart, onRestart) {
  let app = apeman.frk(all) // Make restartable
  apeman
    .wtch({})
    .on('ready', () => app.start(onStart))
    .on('fired', () => app.restartWithDelay(300, onRestart))
}

// Invoke when executed as main.
if (!module.parent) {
  debugAll(() => {
    // All apps started.
  }, () => {
    // All apps restarted.
  })
}