aboutsummaryrefslogtreecommitdiff
path: root/node_modules/nexe/index.js
blob: b28edffa090fd73a079378424724978550a578e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env node
const options = require('./lib/options')
if (require.main === module) {
  //fast path for help/version
  const argv = options.argv
  const eol = require('os').EOL
  const showHelp = argv.help || argv._.some(x => x === 'help')
  const showVersion = argv.version || argv._.some(x => x === 'version')
  if (showHelp || showVersion) {    
    process.stderr.write(showHelp ? options.help : options.version + eol)
  } else {
    const nexe = require('./lib/nexe')
    nexe.compile(argv).catch((error) => {
      const NexeError = require('./lib/compiler').NexeError
      const chalk = require('chalk')
      const isSilent = Boolean(argv.silent === true || argv.loglevel === 'silent')
      if (!isSilent) {
        if (error instanceof NexeError) {
          process.stderr.write(eol + chalk.red('Error: ') + error.message + eol
            + eol + 'See nexe -h for usage..' + eol + eol
          )
        } else {
          process.stderr.write(error.stack + eol)
        }
      }

      process.exit(1)
    })
  }
} else {
  module.exports = require('./lib/nexe')
}