UNPKG

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