piral-cli
Version:
The standard CLI for creating and building a Piral instance or a Pilet.
82 lines (81 loc) • 2.76 kB
TypeScript
import { IncomingHttpHeaders } from 'http';
import { EventEmitter } from 'events';
import { KrasInjector, KrasRequest, KrasInjectorConfig, KrasConfiguration, KrasResult } from 'kras';
import { Bundler } from '../types';
export interface PiletInjectorConfig extends KrasInjectorConfig {
/**
* The pilets to serve.
*/
pilets: Array<Pilet>;
/**
* The base URL for the app shell / portal to be used.
*/
publicUrl: string;
/**
* The base URL for the pilet assets to be used.
*/
assetUrl?: string;
/**
* Defines if properties from the feed (if given) meta response should be taken over to local pilets.
*/
mergeConfig?: boolean;
/**
* The additional metadata file to consider for the pilets.
*/
meta: string;
/**
* The API path - usually somethin like `/$pilet-api`.
*/
api: string;
/**
* The directory of the app (usually Piral instance emulator) to serve.
*/
app?: string;
/**
* The remote feed to merge into.
*/
feed?: string;
/**
* The additional headers to include.
*/
headers?: Record<string, string>;
}
interface Pilet {
bundler: Bundler;
root: string;
dispose(): void;
getMeta(basePath: string): PiletMetadata;
}
interface PiletMetadata {
name?: string;
config?: Record<string, any>;
[key: string]: unknown;
}
export default class PiletInjector implements KrasInjector {
readonly config: PiletInjectorConfig;
private readonly serverConfig;
private readonly indexPath;
private readonly cbs;
private proxyInfo?;
constructor(config: PiletInjectorConfig, serverConfig: KrasConfiguration, core: EventEmitter);
private setupBundler;
private teardownBundler;
get active(): boolean;
set active(value: boolean);
get name(): string;
getOptions(): {};
setOptions(options: any): void;
getPiletApi(baseUrl: string): string;
getPiletMeta(baseUrl: string, pilet: Pilet): string;
getIndexMeta(baseUrl: string, headers: IncomingHttpHeaders): Promise<string>;
loadRemoteFeed(rawHeaders: IncomingHttpHeaders, feed?: string | Array<string>): Promise<Array<Array<PiletMetadata>>>;
mergePilets(localPilets: Array<PiletMetadata>, remoteFeeds: Array<Array<PiletMetadata>>): PiletMetadata[];
sendContent(content: Buffer | string, type: string, url: string): KrasResult;
sendFile(target: string, url: string): Promise<KrasResult>;
sendResponse(path: string, req: KrasRequest, baseUrl: string): Promise<KrasResult>;
sendIndexFile(target: string, url: string, baseUrl: string): Promise<KrasResult>;
private download;
private shouldLoad;
handle(req: KrasRequest): Promise<KrasResult>;
}
export {};