ionic 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/usr/bin/env node
  2. 'use strict';
  3. // IMPORTANT: This file uses ES5 syntax to avoid syntax errors in older Node
  4. // versions (mostly 0.12). See https://node.green for syntax support.
  5. process.title = 'ionic';
  6. process.on('unhandledRejection', function(r) { process.stderr.write(String(r)); process.exit(1); });
  7. var events = require('events');
  8. var path = require('path');
  9. var evt = new events.EventEmitter();
  10. var cli;
  11. process.on('message', function(msg) {
  12. evt.once('ready', function() {
  13. cli.receive(msg);
  14. });
  15. });
  16. var semver = require('semver');
  17. var version = semver.parse(process.version);
  18. var minversion = 'v16.0.0';
  19. if (semver.lt(version, minversion)) {
  20. var details = version.major === 10
  21. ? ' Node.js 10 reached end-of-life on 2021-04-30 and is no longer supported.'
  22. : version.major === 12
  23. ? ' Node.js 12 reached end-of-life on 2022-04-30 and is no longer supported.'
  24. : version.major === 14
  25. ? ' Node.js 14 reached end-of-life on 2023-04-30 and is no longer supported.'
  26. : '';
  27. process.stderr.write('ERR: Your Node.js version is ' + version.raw + '.' + details + ' Please update to the latest Node LTS version.\n');
  28. process.exit(1);
  29. }
  30. if (process.argv.includes('--verbose')) {
  31. process.env.DEBUG = '*';
  32. }
  33. if (process.argv.includes('--no-color')) {
  34. process.env.DEBUG_COLORS = '0';
  35. }
  36. var pargv = process.argv.slice(2);
  37. var lib = path.resolve(__dirname, '..');
  38. process.env.IONIC_CLI_BIN = __filename;
  39. process.env.IONIC_CLI_LIB = lib;
  40. var bootstrap = require(path.resolve(lib, 'bootstrap'));
  41. bootstrap.detectLocalCLI()
  42. .then(function(localPath) {
  43. cli = require(localPath);
  44. return cli.run(pargv, process.env);
  45. }, function(err) {
  46. cli = require(lib);
  47. if (typeof err !== 'string') {
  48. throw err;
  49. }
  50. process.env.IONIC_CLI_LOCAL_ERROR = err;
  51. return cli.run(pargv, process.env);
  52. })
  53. .then(function() {
  54. evt.emit('ready');
  55. });