<commit_before>#!/usr/bin/env node

// Native
const path = require('path')

// Packages
const micro = require('micro')
const args = require('args')
const compress = require('micro-compress')
const detect = require('detect-port')
const { coroutine } = require('bluebird')
const updateNotifier = require('update-notifier')
const { red } = require('chalk')
const nodeVersion = require('node-version')

// Ours
const pkg = require('../package')
const listening = require('../lib/listening')
const serverHandler = require('../lib/server')
const { options, minimist } = require('../lib/options')

// Throw an error if node version is too low
if (nodeVersion.major < 6) {
  console.error(
    `${red(
      'Error!'
    )} Serve requires at least version 6 of Node. Please upgrade!`
  )
  process.exit(1)
}

// Let user know if there's an update
// This isn't important when deployed to production
if (process.env.NODE_ENV !== 'production' && pkg.dist) {
  updateNotifier({ pkg }).notify()
}

// Register the list of options
args.options(options)

// And initialize `args`
const flags = args.parse(process.argv, { minimist })

// Figure out the content directory
const directory = args.sub[0]

// Don't log anything to the console if silent mode is enabled
if (flags.silent) {
  console.log = () => {}
}

process.env.ASSET_DIR = '/' + Math.random().toString(36).substr(2, 10)

let current = process.cwd()

if (directory) {
  current = path.resolve(process.cwd(), directory)
}

let ignoredFiles = ['.DS_Store', '.git/']

if (flags.ignore && flags.ignore.length > 0) {
  ignoredFiles = ignoredFiles.concat(flags.ignore.split(','))
}

const handler = coroutine(function*(req, res) {
  yield serverHandler(req, res, flags, current, ignoredFiles)
})

const server = flags.unzipped ? micro(handler) : micro(compress(handler))
let port = flags.port

detect(port).then(open => {
  let inUse = open !== port

  if (inUse) {
    port = open

    inUse = {
      old: flags.port,
      open
    }
  }

  server.listen(
    port,
    coroutine(function*() {
      yield listening(
        server,
        current,
        inUse,
        flags.noClipboard !== true,
        flags.open
      )
    })
  )
})<commit_msg>Ensure that success message adapts when using `--clipless`<commit_after>#!/usr/bin/env node

// Native
const path = require('path')

// Packages
const micro = require('micro')
const args = require('args')
const compress = require('micro-compress')
const detect = require('detect-port')
const { coroutine } = require('bluebird')
const updateNotifier = require('update-notifier')
const { red } = require('chalk')
const nodeVersion = require('node-version')

// Ours
const pkg = require('../package')
const listening = require('../lib/listening')
const serverHandler = require('../lib/server')
const { options, minimist } = require('../lib/options')

// Throw an error if node version is too low
if (nodeVersion.major < 6) {
  console.error(
    `${red(
      'Error!'
    )} Serve requires at least version 6 of Node. Please upgrade!`
  )
  process.exit(1)
}

// Let user know if there's an update
// This isn't important when deployed to production
if (process.env.NODE_ENV !== 'production' && pkg.dist) {
  updateNotifier({ pkg }).notify()
}

// Register the list of options
args.options(options)

// And initialize `args`
const flags = args.parse(process.argv, { minimist })

// Figure out the content directory
const directory = args.sub[0]

// Don't log anything to the console if silent mode is enabled
if (flags.silent) {
  console.log = () => {}
}

process.env.ASSET_DIR = '/' + Math.random().toString(36).substr(2, 10)

let current = process.cwd()

if (directory) {
  current = path.resolve(process.cwd(), directory)
}

let ignoredFiles = ['.DS_Store', '.git/']

if (flags.ignore && flags.ignore.length > 0) {
  ignoredFiles = ignoredFiles.concat(flags.ignore.split(','))
}

const handler = coroutine(function*(req, res) {
  yield serverHandler(req, res, flags, current, ignoredFiles)
})

const server = flags.unzipped ? micro(handler) : micro(compress(handler))
let port = flags.port

detect(port).then(open => {
  let inUse = open !== port

  if (inUse) {
    port = open

    inUse = {
      old: flags.port,
      open
    }
  }

  const listenArgs = [
    server,
    current,
    inUse,
    flags.clipless !== true,
    flags.open
  ]

  server.listen(
    port,
    coroutine(function*() {
      yield listening(...listenArgs)
    })
  )
})
{'fraction_non_alphanumeric': 0.1527403414195867, 'fraction_numerical': 0.004492362982929021, 'mean_word_length': 3.453, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4171529', 'n_tokens_mistral': 1426, 'n_tokens_neox': 1396, 'n_words': 389}