UI for Zipcoin Blue

serve.js 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const tslib_1 = require("tslib");
  4. const os = require("os");
  5. const chalk_1 = require("chalk");
  6. const string_1 = require("@ionic/cli-framework/utils/string");
  7. const errors_1 = require("../lib/errors");
  8. const serve_1 = require("../lib/serve");
  9. const WATCH_BEFORE_HOOK = 'watch:before';
  10. const WATCH_BEFORE_SCRIPT = `ionic:${WATCH_BEFORE_HOOK}`;
  11. function serve(env, inputs, options) {
  12. return tslib_1.__awaiter(this, void 0, void 0, function* () {
  13. const { detectAndWarnAboutDeprecatedPlugin } = yield Promise.resolve().then(() => require('../lib/plugins'));
  14. const packageJson = yield env.project.loadPackageJson();
  15. if (packageJson.scripts && packageJson.scripts[WATCH_BEFORE_SCRIPT]) {
  16. env.log.debug(() => `Invoking ${chalk_1.default.cyan(WATCH_BEFORE_SCRIPT)} npm script.`);
  17. yield env.shell.run('npm', ['run', WATCH_BEFORE_SCRIPT], { showExecution: true });
  18. }
  19. if (packageJson.devDependencies) {
  20. if (packageJson.devDependencies['gulp']) {
  21. const { checkGulp, registerWatchEvents, runTask } = yield Promise.resolve().then(() => require('../lib/gulp'));
  22. yield checkGulp(env);
  23. yield registerWatchEvents(env);
  24. yield runTask(env, WATCH_BEFORE_SCRIPT);
  25. }
  26. yield detectAndWarnAboutDeprecatedPlugin(env, '@ionic/cli-plugin-cordova');
  27. yield detectAndWarnAboutDeprecatedPlugin(env, '@ionic/cli-plugin-ionic-angular');
  28. yield detectAndWarnAboutDeprecatedPlugin(env, '@ionic/cli-plugin-ionic1');
  29. yield detectAndWarnAboutDeprecatedPlugin(env, '@ionic/cli-plugin-gulp');
  30. if (packageJson.devDependencies['@ionic/cli-plugin-cordova']) {
  31. const { checkCordova } = yield Promise.resolve().then(() => require('../lib/cordova/utils'));
  32. yield checkCordova(env);
  33. }
  34. }
  35. yield env.hooks.fire('watch:before', { env });
  36. const [platform] = inputs;
  37. let details;
  38. const serveOptions = cliOptionsToServeOptions(options);
  39. const project = yield env.project.load();
  40. const devAppDetails = yield serve_1.gatherDevAppDetails(env, serveOptions);
  41. if (project.type === 'ionic1') {
  42. const { serve } = yield Promise.resolve().then(() => require('../lib/ionic1/serve'));
  43. details = yield serve({ env, options: serveOptions });
  44. }
  45. else if (project.type === 'ionic-angular') {
  46. const { serve } = yield Promise.resolve().then(() => require('../lib/ionic-angular/serve'));
  47. details = yield serve({ env, options: Object.assign({ platform, target: serveOptions.iscordovaserve ? 'cordova' : undefined }, serveOptions) });
  48. }
  49. else {
  50. throw new errors_1.FatalException(`Cannot perform Ionic serve/watch for project type: ${chalk_1.default.bold(project.type)}.\n` +
  51. (project.type === 'custom' ? `Since you're using the ${chalk_1.default.bold('custom')} project type, this command won't work. The Ionic CLI doesn't know how to serve custom projects.\n\n` : '') +
  52. `If you'd like the CLI to try to detect your project type, you can unset the ${chalk_1.default.bold('type')} attribute in ${chalk_1.default.bold('ionic.config.json')}.\n`);
  53. }
  54. if (devAppDetails) {
  55. const devAppName = yield serve_1.publishDevApp(env, serveOptions, Object.assign({ port: details.port }, devAppDetails));
  56. devAppDetails.channel = devAppName;
  57. }
  58. const localAddress = `http://localhost:${details.port}`;
  59. const fmtExternalAddress = (address) => `http://${address}:${details.port}`;
  60. env.log.ok(`Development server running!\n` +
  61. `Local: ${chalk_1.default.bold(localAddress)}\n` +
  62. (details.externalNetworkInterfaces.length > 0 ? `External: ${details.externalNetworkInterfaces.map(v => chalk_1.default.bold(fmtExternalAddress(v.address))).join(', ')}\n` : '') +
  63. (serveOptions.basicAuth ? `Basic Auth: ${chalk_1.default.bold(serveOptions.basicAuth[0])} / ${chalk_1.default.bold(serveOptions.basicAuth[1])}` : '') +
  64. (devAppDetails && devAppDetails.channel ? `DevApp: ${chalk_1.default.bold(devAppDetails.channel)} on ${chalk_1.default.bold(os.hostname())}` : ''));
  65. if (serveOptions.open) {
  66. const openOptions = [localAddress]
  67. .concat(serveOptions.lab ? [serve_1.IONIC_LAB_URL] : [])
  68. .concat(serveOptions.browserOption ? [serveOptions.browserOption] : [])
  69. .concat(platform ? ['?ionicplatform=', platform] : []);
  70. const opn = yield Promise.resolve().then(() => require('opn'));
  71. opn(openOptions.join(''), { app: serveOptions.browser, wait: false });
  72. }
  73. return details;
  74. });
  75. }
  76. exports.serve = serve;
  77. function cliOptionsToServeOptions(options) {
  78. if (options['local']) {
  79. options['address'] = 'localhost';
  80. options['devapp'] = false;
  81. }
  82. const address = options['address'] ? String(options['address']) : serve_1.BIND_ALL_ADDRESS;
  83. const port = string_1.str2num(options['port'], serve_1.DEFAULT_SERVER_PORT);
  84. const livereloadPort = string_1.str2num(options['livereload-port'], serve_1.DEFAULT_LIVERELOAD_PORT);
  85. const notificationPort = string_1.str2num(options['dev-logger-port'], serve_1.DEFAULT_DEV_LOGGER_PORT);
  86. return {
  87. address,
  88. port,
  89. livereloadPort,
  90. notificationPort,
  91. consolelogs: options['consolelogs'] ? true : false,
  92. serverlogs: options['serverlogs'] ? true : false,
  93. livereload: typeof options['livereload'] === 'boolean' ? Boolean(options['livereload']) : true,
  94. proxy: typeof options['proxy'] === 'boolean' ? Boolean(options['proxy']) : true,
  95. lab: options['lab'] ? true : false,
  96. open: options['open'] ? true : false,
  97. browser: options['browser'] ? String(options['browser']) : undefined,
  98. browserOption: options['browseroption'] ? String(options['browseroption']) : undefined,
  99. basicAuth: options['auth'] ? ['ionic', String(options['auth'])] : undefined,
  100. env: options['env'] ? String(options['env']) : undefined,
  101. devapp: typeof options['devapp'] === 'undefined' || options['devapp'] ? true : false,
  102. externalAddressRequired: options['externalAddressRequired'] ? true : false,
  103. iscordovaserve: typeof options['iscordovaserve'] === 'boolean' ? Boolean(options['iscordovaserve']) : false,
  104. };
  105. }
  106. exports.cliOptionsToServeOptions = cliOptionsToServeOptions;