serve.d.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /// <reference types="node" />
  2. /// <reference types="node" />
  3. /// <reference types="node" />
  4. /// <reference types="node" />
  5. import { PromptModule } from '@ionic/cli-framework-prompts';
  6. import { NetworkInterface } from '@ionic/utils-network';
  7. import { EventEmitter } from 'events';
  8. import * as stream from 'stream';
  9. import { CommandLineInputs, CommandLineOptions, CommandMetadata, CommandMetadataOption, IConfig, ILogger, IProject, IShell, IonicEnvironmentFlags, NpmClient, Runner, ServeDetails, ServeOptions } from '../definitions';
  10. export declare const DEFAULT_DEV_LOGGER_PORT = 53703;
  11. export declare const DEFAULT_LIVERELOAD_PORT = 35729;
  12. export declare const DEFAULT_SERVER_PORT = 8100;
  13. export declare const DEFAULT_DEVAPP_COMM_PORT = 53233;
  14. export declare const DEFAULT_ADDRESS = "localhost";
  15. export declare const BIND_ALL_ADDRESS = "0.0.0.0";
  16. export declare const LOCAL_ADDRESSES: string[];
  17. export declare const BROWSERS: string[];
  18. export declare const SERVE_SCRIPT = "ionic:serve";
  19. export declare const COMMON_SERVE_COMMAND_OPTIONS: readonly CommandMetadataOption[];
  20. export interface ServeRunnerDeps {
  21. readonly config: IConfig;
  22. readonly flags: IonicEnvironmentFlags;
  23. readonly log: ILogger;
  24. readonly project: IProject;
  25. readonly prompt: PromptModule;
  26. readonly shell: IShell;
  27. }
  28. export declare abstract class ServeRunner<T extends ServeOptions> implements Runner<T, ServeDetails> {
  29. protected devAppConnectionMade: boolean;
  30. protected abstract readonly e: ServeRunnerDeps;
  31. abstract getCommandMetadata(): Promise<Partial<CommandMetadata>>;
  32. abstract serveProject(options: T): Promise<ServeDetails>;
  33. abstract modifyOpenUrl(url: string, options: T): string;
  34. getPkgManagerServeCLI(): PkgManagerServeCLI;
  35. createOptionsFromCommandLine(inputs: CommandLineInputs, options: CommandLineOptions): ServeOptions;
  36. determineEngineFromCommandLine(options: CommandLineOptions): string;
  37. beforeServe(options: T): Promise<void>;
  38. run(options: T): Promise<ServeDetails>;
  39. afterServe(options: T, details: ServeDetails): Promise<void>;
  40. scheduleAfterServe(options: T, details: ServeDetails): void;
  41. getUsedPorts(options: T, details: ServeDetails): number[];
  42. selectExternalIP(options: T): Promise<[string, NetworkInterface[]]>;
  43. }
  44. export interface ServeCLIOptions {
  45. readonly host: string;
  46. readonly port: number;
  47. }
  48. export interface ServeCLI<T extends ServeCLIOptions> {
  49. emit(event: 'compile', chunks: number): boolean;
  50. emit(event: 'ready'): boolean;
  51. on(event: 'compile', handler: (chunks: number) => void): this;
  52. on(event: 'ready', handler: () => void): this;
  53. once(event: 'compile', handler: (chunks: number) => void): this;
  54. once(event: 'ready', handler: () => void): this;
  55. }
  56. export declare abstract class ServeCLI<T extends ServeCLIOptions> extends EventEmitter {
  57. protected readonly e: ServeRunnerDeps;
  58. /**
  59. * The pretty name of this Serve CLI.
  60. */
  61. abstract readonly name: string;
  62. /**
  63. * The npm package of this Serve CLI.
  64. */
  65. abstract readonly pkg: string;
  66. /**
  67. * The bin program to use for this Serve CLI.
  68. */
  69. abstract readonly program: string;
  70. /**
  71. * The prefix to use for log statements.
  72. */
  73. abstract readonly prefix: string;
  74. /**
  75. * If specified, `package.json` is inspected for this script to use instead
  76. * of `program`.
  77. */
  78. abstract readonly script?: string;
  79. /**
  80. * If true, the Serve CLI will not prompt to be installed.
  81. */
  82. readonly global: boolean;
  83. private _resolvedProgram?;
  84. constructor(e: ServeRunnerDeps);
  85. get resolvedProgram(): string;
  86. /**
  87. * Build the arguments for starting this Serve CLI. Called by `this.start()`.
  88. */
  89. protected abstract buildArgs(options: T): Promise<string[]>;
  90. /**
  91. * Build the environment variables to be passed to the Serve CLI. Called by `this.start()`;
  92. */
  93. protected buildEnvVars(options: T): Promise<NodeJS.ProcessEnv>;
  94. /**
  95. * Called whenever a line of stdout is received.
  96. *
  97. * If `false` is returned, the line is not emitted to the log.
  98. *
  99. * By default, the CLI is considered ready whenever stdout is emitted. This
  100. * method should be overridden to more accurately portray readiness.
  101. *
  102. * @param line A line of stdout.
  103. */
  104. protected stdoutFilter(line: string): boolean;
  105. /**
  106. * Called whenever a line of stderr is received.
  107. *
  108. * If `false` is returned, the line is not emitted to the log.
  109. */
  110. protected stderrFilter(line: string): boolean;
  111. resolveScript(): Promise<string | undefined>;
  112. serve(options: T): Promise<void>;
  113. protected spawnWrapper(options: T): Promise<void>;
  114. protected spawn(options: T): Promise<void>;
  115. protected createLoggerStream(): NodeJS.WritableStream;
  116. protected resolveProgram(): Promise<string>;
  117. protected createStreamFilter(filter: (line: string) => boolean): stream.Transform;
  118. protected promptToInstall(): Promise<boolean>;
  119. }
  120. declare abstract class PkgManagerServeCLI extends ServeCLI<ServeOptions> {
  121. readonly abstract program: NpmClient;
  122. readonly global = true;
  123. readonly script = "ionic:serve";
  124. protected resolveProgram(): Promise<string>;
  125. protected buildArgs(options: ServeOptions): Promise<string[]>;
  126. }
  127. export declare class NpmServeCLI extends PkgManagerServeCLI {
  128. readonly name = "npm CLI";
  129. readonly pkg = "npm";
  130. readonly program = "npm";
  131. readonly prefix = "npm";
  132. }
  133. export declare class PnpmServeCLI extends PkgManagerServeCLI {
  134. readonly name = "pnpm CLI";
  135. readonly pkg = "pnpm";
  136. readonly program = "pnpm";
  137. readonly prefix = "pnpm";
  138. }
  139. export declare class YarnServeCLI extends PkgManagerServeCLI {
  140. readonly name = "Yarn";
  141. readonly pkg = "yarn";
  142. readonly program = "yarn";
  143. readonly prefix = "yarn";
  144. }
  145. export {};