UI for Zipcoin Blue

index.js 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const tslib_1 = require("tslib");
  4. const path = require("path");
  5. const util = require("util");
  6. const chalk_1 = require("chalk");
  7. const cli_utils_1 = require("@ionic/cli-utils");
  8. const errors_1 = require("@ionic/cli-utils/lib/errors");
  9. const init_1 = require("@ionic/cli-utils/lib/init");
  10. const fs_1 = require("@ionic/cli-framework/utils/fs");
  11. const guards_1 = require("@ionic/cli-utils/guards");
  12. const commands_1 = require("./commands");
  13. exports.namespace = new commands_1.IonicNamespace();
  14. function generateRootPlugin() {
  15. return tslib_1.__awaiter(this, void 0, void 0, function* () {
  16. const { getPluginMeta } = yield Promise.resolve().then(() => require('@ionic/cli-utils/lib/plugins'));
  17. return {
  18. namespace: exports.namespace,
  19. meta: yield getPluginMeta(__filename),
  20. };
  21. });
  22. }
  23. exports.generateRootPlugin = generateRootPlugin;
  24. function run(pargv, env) {
  25. return tslib_1.__awaiter(this, void 0, void 0, function* () {
  26. const now = new Date();
  27. let err;
  28. let ienv;
  29. pargv = init_1.modifyArguments(pargv.slice(2));
  30. env['IONIC_CLI_LIB'] = __filename;
  31. const { isSuperAgentError } = yield Promise.resolve().then(() => require('@ionic/cli-utils/guards'));
  32. const { isValidationErrorArray } = yield Promise.resolve().then(() => require('@ionic/cli-framework/guards'));
  33. const plugin = yield generateRootPlugin();
  34. try {
  35. ienv = yield cli_utils_1.generateIonicEnvironment(plugin, pargv, env);
  36. }
  37. catch (e) {
  38. console.error(e.message ? e.message : (e.stack ? e.stack : e));
  39. process.exitCode = 1;
  40. return;
  41. }
  42. try {
  43. const config = yield ienv.config.load();
  44. ienv.log.debug(() => util.inspect(ienv.meta, { breakLength: Infinity, colors: chalk_1.default.enabled }));
  45. if (env['IONIC_EMAIL'] && env['IONIC_PASSWORD']) {
  46. ienv.log.debug(() => `${chalk_1.default.bold('IONIC_EMAIL')} / ${chalk_1.default.bold('IONIC_PASSWORD')} environment variables detected`);
  47. if (config.user.email !== env['IONIC_EMAIL']) {
  48. ienv.log.debug(() => `${chalk_1.default.bold('IONIC_EMAIL')} mismatch with current session--attempting login`);
  49. try {
  50. yield ienv.session.login(env['IONIC_EMAIL'], env['IONIC_PASSWORD']);
  51. }
  52. catch (e) {
  53. ienv.log.error(`Error occurred during automatic login via ${chalk_1.default.bold('IONIC_EMAIL')} / ${chalk_1.default.bold('IONIC_PASSWORD')} environment variables.`);
  54. throw e;
  55. }
  56. }
  57. }
  58. if (ienv.project.directory) {
  59. const nodeModulesExists = yield fs_1.pathExists(path.join(ienv.project.directory, 'node_modules'));
  60. if (!nodeModulesExists) {
  61. const confirm = yield ienv.prompt({
  62. type: 'confirm',
  63. name: 'confirm',
  64. message: `Looks like a fresh checkout! No ${chalk_1.default.green('./node_modules')} directory found. Would you like to install project dependencies?`,
  65. });
  66. if (confirm) {
  67. ienv.log.info('Installing dependencies may take several minutes!');
  68. const { pkgManagerArgs } = yield Promise.resolve().then(() => require('@ionic/cli-utils/lib/utils/npm'));
  69. const [installer, ...installerArgs] = yield pkgManagerArgs(ienv, { command: 'install' });
  70. yield ienv.shell.run(installer, installerArgs, {});
  71. }
  72. }
  73. }
  74. const argv = init_1.parseArgs(pargv, { boolean: true, string: '_' });
  75. // If an legacy command is being executed inform the user that there is a new command available
  76. const foundCommand = init_1.mapLegacyCommand(argv._[0]);
  77. if (foundCommand) {
  78. ienv.log.msg(`The ${chalk_1.default.green(argv._[0])} command has been renamed. To find out more, run:\n\n` +
  79. ` ${chalk_1.default.green(`ionic ${foundCommand} --help`)}\n\n`);
  80. }
  81. else {
  82. const { loadPlugins } = yield Promise.resolve().then(() => require('@ionic/cli-utils/lib/plugins'));
  83. try {
  84. yield loadPlugins(ienv);
  85. }
  86. catch (e) {
  87. if (e.fatal) {
  88. throw e;
  89. }
  90. ienv.log.error(chalk_1.default.red.bold('Error occurred while loading plugins. CLI functionality may be limited.'));
  91. ienv.log.debug(() => chalk_1.default.red(chalk_1.default.bold('Plugin error: ') + (e.stack ? e.stack : e)));
  92. }
  93. if (ienv.flags.interactive) {
  94. if (yield ienv.config.isUpdatingEnabled()) {
  95. const { checkForDaemon } = yield Promise.resolve().then(() => require('@ionic/cli-utils/lib/daemon'));
  96. yield checkForDaemon(ienv);
  97. const { checkForUpdates, getLatestPluginVersion, versionNeedsUpdating } = yield Promise.resolve().then(() => require('@ionic/cli-utils/lib/plugins'));
  98. const latestVersion = yield getLatestPluginVersion(ienv, plugin.meta.name, plugin.meta.version);
  99. if (latestVersion) {
  100. plugin.meta.latestVersion = latestVersion;
  101. plugin.meta.updateAvailable = yield versionNeedsUpdating(plugin.meta.version, latestVersion);
  102. yield checkForUpdates(ienv);
  103. }
  104. }
  105. }
  106. yield ienv.hooks.fire('plugins:init', { env: ienv });
  107. yield exports.namespace.runCommand(ienv, pargv);
  108. config.state.lastCommand = now.toISOString();
  109. }
  110. }
  111. catch (e) {
  112. err = e;
  113. }
  114. try {
  115. yield Promise.all([
  116. ienv.config.save(),
  117. ienv.project.save(),
  118. ienv.daemon.save(),
  119. ]);
  120. }
  121. catch (e) {
  122. ienv.log.error(String(e.stack ? e.stack : e));
  123. }
  124. if (err) {
  125. ienv.tasks.fail();
  126. process.exitCode = 1;
  127. if (isValidationErrorArray(err)) {
  128. for (let e of err) {
  129. ienv.log.error(e.message);
  130. }
  131. ienv.log.msg(`Use the ${chalk_1.default.green('--help')} flag for more details.`);
  132. }
  133. else if (isSuperAgentError(err)) {
  134. const { formatSuperAgentError } = yield Promise.resolve().then(() => require('@ionic/cli-utils/lib/http'));
  135. ienv.log.msg(formatSuperAgentError(err));
  136. }
  137. else if (err.code && err.code === 'ENOTFOUND' || err.code === 'ECONNREFUSED') {
  138. ienv.log.error(`Network connectivity error occurred, are you offline?\n` +
  139. `If you are behind a firewall and need to configure proxy settings, see: ${chalk_1.default.bold('https://ionicframework.com/docs/cli/configuring.html#using-a-proxy')}\n\n` +
  140. chalk_1.default.red(String(err.stack ? err.stack : err)));
  141. }
  142. else if (guards_1.isExitCodeException(err)) {
  143. process.exitCode = err.exitCode;
  144. if (err.message) {
  145. if (err.exitCode > 0) {
  146. ienv.log.error(err.message);
  147. }
  148. else {
  149. ienv.log.msg(err.message);
  150. }
  151. }
  152. }
  153. else if (err instanceof errors_1.Exception) {
  154. ienv.log.error(err.message);
  155. }
  156. else {
  157. ienv.log.msg(chalk_1.default.red(String(err.stack ? err.stack : err)));
  158. if (err.stack) {
  159. ienv.log.debug(() => chalk_1.default.red(String(err.stack)));
  160. }
  161. }
  162. }
  163. yield ienv.close();
  164. });
  165. }
  166. exports.run = run;