cli.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env node
  2. 'use strict'
  3. var nodeVersionInfo = process.versions.node.split('.').map(function (n) { return Number(n) })
  4. if (nodeVersionInfo < [4, 0, 0]) {
  5. console.error('CANNOT RUN WITH NODE ' + process.versions.node)
  6. console.error('Electron Packager requires Node 4.0 or above.')
  7. process.exit(1)
  8. }
  9. // Not consts so that this file can load in Node < 4.0
  10. var common = require('./common')
  11. var fs = require('fs')
  12. var packager = require('./')
  13. var path = require('path')
  14. var usage = fs.readFileSync(path.join(__dirname, 'usage.txt')).toString()
  15. var args = common.parseCLIArgs(process.argv.slice(2))
  16. // temporary fix for https://github.com/nodejs/node/issues/6456
  17. var stdioWriters = [process.stdout, process.stderr]
  18. stdioWriters.forEach(function (stdioWriter) {
  19. if (stdioWriter._handle && stdioWriter._handle.setBlocking) {
  20. stdioWriter._handle.setBlocking(true)
  21. }
  22. })
  23. function printUsageAndExit (isError) {
  24. var print = isError ? console.error : console.log
  25. print(usage)
  26. process.exit(isError ? 1 : 0)
  27. }
  28. if (args.help) {
  29. printUsageAndExit(false)
  30. } else if (!args.dir) {
  31. printUsageAndExit(true)
  32. }
  33. packager(args, function done (err, appPaths) {
  34. if (err) {
  35. if (err.message) console.error(err.message)
  36. else console.error(err, err.stack)
  37. process.exit(1)
  38. }
  39. if (appPaths.length > 1) console.error('Wrote new apps to:\n' + appPaths.join('\n'))
  40. else if (appPaths.length === 1) console.error('Wrote new app to', appPaths[0])
  41. })