Пример #1
0
    file.on('finish', function () {
      // will only post image if > iterm 2.9
      // centos fallback does not happen - bug
      try {
        termImg(file.path, fallback);
      } catch(e) {
        // do nothing
      }

    });
Пример #2
0
const splash = flags => {
	if (flags && flags.silent) {
		return
	}

	const logoPath = path.join(__dirname, '..', 'media', 'markserv-logo-term.png')
	termImg(logoPath, {
		width: 12,
		fallback: () => {}
	})

	msg('boot', 'starting Markserv...', flags)
}
Пример #3
0
  img.onload = () => {
    context.drawImage(img, 0, 0, options.row, img.height / img.width * options.row)

    // Pixel art
    let base64Data = drawCanvas(context)
    base64Data = base64Data.toDataURL().substr(base64Data.toDataURL().indexOf(',') + 1)
    const canvasData = new Buffer(base64Data, 'base64')

    termImg(canvasData, {
      width: options.row,
      fallback: () => {
        console.error('Oops!Not supported here!')
        process.exit(1)
      }
    })
  }
Пример #4
0
module.exports = co.wrap(function* post(filePath) {
  // if filePath is url
  // download it and temp-write it to a file
  if (isUrl(filePath)) {
    filePath = yield download(filePath).catch(err => console.log(err.stack));
  }

  // output image in terminal
  yield imgcat(filePath).catch(() => {/* do nothing */});
  const file = fs.createReadStream(path.resolve(filePath));

  // start spinner
  uploadSpin.start();

  // create form
  form.append('smfile', file);
  form.append('ssl', 'true');

  // post form
  const data = yield got.post('https://sm.ms/api/upload', {
    headers: form.getHeaders(),
    body: form,
    json: true
  }).then(res => res.body);

  // stop spinner
  uploadSpin.stop();

  // exit when error occurs
  if (data.code !== 'success') {
    console.log(data.msg.red);
    process.exit(1);
  }

  // return result
  return data.data;
});
Пример #5
0
function * run (context, heroku) {
  const img = require('term-img')
  const sortBy = require('lodash.sortby')
  const path = require('path')

  function favoriteApps () {
    return heroku.request({
      host: 'longboard.heroku.com',
      path: '/favorites',
      headers: {Range: ''}
    }).then((apps) => apps.map((app) => app.app_name))
  }

  function fetchMetrics (apps) {
    const NOW = new Date().toISOString()
    const YESTERDAY = new Date(new Date().getTime() - (24 * 60 * 60 * 1000)).toISOString()
    let date = `start_time=${YESTERDAY}&end_time=${NOW}&step=1h`
    return apps.map((app) => {
      let types = app.formation.map((p) => p.type)
      return {
        dynoErrors: types.map((type) => heroku.request({host: 'api.metrics.herokai.com', path: `/apps/${app.app.name}/formation/${type}/metrics/errors?${date}`, headers: {Range: ''}}).catch(() => null)),
        routerLatency: heroku.request({host: 'api.metrics.herokai.com', path: `/apps/${app.app.name}/router-metrics/latency?${date}&process_type=${types[0]}`, headers: {Range: ''}}).catch(() => null),
        routerErrors: heroku.request({host: 'api.metrics.herokai.com', path: `/apps/${app.app.name}/router-metrics/errors?${date}&process_type=${types[0]}`, headers: {Range: ''}}).catch(() => null),
        routerStatus: heroku.request({host: 'api.metrics.herokai.com', path: `/apps/${app.app.name}/router-metrics/status?${date}&process_type=${types[0]}`, headers: {Range: ''}}).catch(() => null)
      }
    })
  }

  let apps, data, metrics

  yield cli.action('Loading', {clear: true}, co(function * () {
    apps = yield favoriteApps()

    data = yield {
      orgs: heroku.request({path: '/organizations'}),
      notifications: heroku.request({host: 'telex.heroku.com', path: '/user/notifications'}),
      apps: apps.map((app) => ({
        app: heroku.get(`/apps/${app}`),
        formation: heroku.get(`/apps/${app}/formation`),
        pipeline: heroku.get(`/apps/${app}/pipeline-couplings`).catch(() => null)
      }))
    }
    metrics = yield fetchMetrics(data.apps)
  }))

  img(path.join(__dirname, '..', 'assets', 'heroku.png'), {
    fallback: () => cli.console.error()
  })

  if (apps.length > 0) displayApps(data.apps, metrics)
  else cli.warn(`Add apps to this dashboard by favoriting them with ${cli.color.cmd('heroku apps:favorites:add')}`)

  cli.log(`See all add-ons with ${cli.color.cmd('heroku addons')}`)
  let sampleOrg = sortBy(data.orgs.filter((o) => o.role !== 'collaborator'), (o) => new Date(o.created_at))[0]
  if (sampleOrg) cli.log(`See all apps in ${cli.color.yellow.dim(sampleOrg.name)} with ${cli.color.cmd('heroku apps --org ' + sampleOrg.name)}`)
  cli.log(`See all apps with ${cli.color.cmd('heroku apps --all')}`)
  displayNotifications(data.notifications)
  cli.log(`
See other CLI commands with ${cli.color.cmd('heroku help')}
`)
}
Пример #6
0
http.listen(port, function () {
    termImg('logo.png', {fallback})
    console.log('Listening on port '+port+'...')
})