How to use the @ionic/utils-process.onBeforeExit function in @ionic/utils-process

To help you get started, we’ve selected a few @ionic/utils-process examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ionic-team / ionic-cli / packages / ionic / src / commands / cordova / run.ts View on Github external
*/
    let details: ServeDetails | undefined;
    let serverUrl = options['livereload-url'] ? String(options['livereload-url']) : undefined;

    if (!serverUrl) {
      details = await runner.run(runnerOpts);

      if (details.externallyAccessible === false && !options['native-run']) {
        const extra = LOCAL_ADDRESSES.includes(details.externalAddress) ? '\nEnsure you have proper port forwarding setup from your device to your computer.' : '';
        this.env.log.warn(`Your device or emulator may not be able to access ${strong(details.externalAddress)}.${extra}\n\n`);
      }

      serverUrl = `${details.protocol || 'http'}://${details.externalAddress}:${details.port}`;
    }

    onBeforeExit(async () => {
      conf.resetContentSrc();
      await conf.save();
    });

    conf.writeContentSrc(serverUrl);
    await conf.save();

    const cordovalogws = createPrefixedWriteStream(this.env.log, weak(`[cordova]`));
    const buildOpts: IShellRunOptions = { stream: cordovalogws };
    // ignore very verbose compiler output on stdout unless --verbose
    buildOpts.stdio = options['verbose'] ? 'inherit' : ['pipe', 'ignore', 'pipe'];

    if (options['native-run']) {
      const [ platform ] = inputs;
      const packagePath = await getPackagePath(conf.getProjectInfo().name, platform, { emulator: !options['device'], release: !!options['release'] });
      const forwardedPorts = details ? runner.getUsedPorts(runnerOpts, details) : [];
github ionic-team / ionic-cli / packages / ionic / src / lib / shell.ts View on Github external
promise.p.stdout.pipe(s);
      }

      if (promise.p.stderr) {
        const s = combineStreams(split2(), ws);

        // TODO: https://github.com/angular/angular-cli/issues/10922
        s.on('error', (err: Error) => {
          debug('Error in subprocess stderr pipe: %o', err);
        });

        promise.p.stderr.pipe(s);
      }

      if (killOnExit) {
        onBeforeExit(async () => {
          if (promise.p.pid) {
            await killProcessTree(promise.p.pid);
          }
        });
      }

      await promise;
    } catch (e) {
      if (e instanceof SubprocessError && e.code === ERROR_COMMAND_NOT_FOUND) {
        if (fatalOnNotFound) {
          throw new FatalException(`Command not found: ${input(command)}`, 127);
        } else {
          throw e;
        }
      }
github ionic-team / ionic-cli / packages / ionic / src / commands / capacitor / run.ts View on Github external
let serverUrl = options['livereload-url'] ? String(options['livereload-url']) : undefined;

    if (!serverUrl) {
      const details = await runner.run(runnerOpts);

      if (details.externallyAccessible === false) {
        const extra = LOCAL_ADDRESSES.includes(details.externalAddress) ? '\nEnsure you have proper port forwarding setup from your device to your computer.' : '';
        this.env.log.warn(`Your device or emulator may not be able to access ${strong(details.externalAddress)}.${extra}\n\n`);
      }

      serverUrl = `${details.protocol || 'http'}://${details.externalAddress}:${details.port}`;
    }

    const conf = new CapacitorConfig(path.resolve(this.project.directory, CAPACITOR_CONFIG_FILE));

    onBeforeExit(async () => {
      conf.resetServerUrl();
    });

    conf.setServerUrl(serverUrl);
  }

@ionic/utils-process

Process utils for NodeJS

MIT
Latest version published 7 months ago

Package Health Score

77 / 100
Full package analysis

Similar packages