import type { Argv, Arguments } from 'yargs'; import type { RuleRunner, PiletRuleContext, PiralRuleContext, LogLevels, SharedDependency } from './common'; export type FlagType = 'string' | 'number' | 'boolean' | 'object'; export interface Flag { name: string; type?: FlagType; alias: Array; values?: Array; describe?: string; default?: any; required?: boolean; ignore?: boolean; filter?: (answer: any, others: Record) => any; validate?: (input: any) => boolean | string | Promise; when?: (answers: Record) => boolean; convert?: (answer: any) => any; } export interface ToolCommandRunner { (args: Arguments): void | Promise; } export interface ToolCommandWrapper { (args: Arguments, runner: ToolCommandRunner): void | Promise; } export interface ToolCommandFlagsSetter { (argv: Argv): Argv; } export interface SelectCommands { (commands: ListCommands): Array>; } export interface ToolCommand { name: string; description: string; arguments: Array; survey?: boolean; flags?: ToolCommandFlagsSetter; alias: Array; run: ToolCommandRunner; } export interface ListCommands { all: Array>; pilet: Array>; piral: Array>; } export interface CliPluginApi { withCommand(command: ToolCommand): CliPluginApi; withoutCommand(commandName: string): CliPluginApi; withFlags(commandName: string, setter: ToolCommandFlagsSetter): CliPluginApi; wrapCommand(commandName: string, wrapper: ToolCommandWrapper): CliPluginApi; beforeCommand(commandName: string, before: ToolCommandRunner): CliPluginApi; afterCommand(commandName: string, after: ToolCommandRunner): CliPluginApi; withPiralRule(ruleName: string, runner: RuleRunner): CliPluginApi; withPiletRule(ruleName: string, runner: RuleRunner): CliPluginApi; withPatcher(packageName: string, patch: PackagePatcher): CliPluginApi; withBundler(bundlerName: string, bundler: BundlerDefinition): CliPluginApi; } export interface CliPlugin { (api: CliPluginApi): void; } export interface PackagePatcher { (rootDir: string): Promise; } export interface PackagePatcher { (rootDir: string): Promise; } export interface BaseBundleParameters { root: string; optimizeModules: boolean; ignored: Array; _: Record; } export interface DebugPiralParameters extends BaseBundleParameters { piralInstances: Array; hmr: boolean; externals: Array; publicUrl: string; outFile: string; outDir: string; entryFiles: string; logLevel: LogLevels; } export interface WatchPiralParameters extends BaseBundleParameters { piralInstances: Array; externals: Array; publicUrl: string; entryFiles: string; logLevel: LogLevels; } export interface BuildPiralParameters extends BaseBundleParameters { piralInstances: Array; emulator: boolean; standalone: boolean; sourceMaps: boolean; watch: boolean; contentHash: boolean; minify: boolean; externals: Array; publicUrl: string; outFile: string; outDir: string; entryFiles: string; logLevel: LogLevels; } export interface DebugPiletParameters extends BaseBundleParameters { piralInstances: Array; hmr: boolean; externals: Array; importmap: Array; targetDir: string; outFile: string; outDir: string; entryModule: string; logLevel: LogLevels; version: PiletSchemaVersion; } export interface BuildPiletParameters extends BaseBundleParameters { piralInstances: Array; sourceMaps: boolean; watch: boolean; contentHash: boolean; minify: boolean; externals: Array; importmap: Array; targetDir: string; outFile: string; outDir: string; entryModule: string; logLevel: LogLevels; version: PiletSchemaVersion; } export interface BundlerPrepareArgs { (args: T): T | Promise; } export interface BaseBundlerDefinition { path: string; exec?: string; prepare?: BundlerPrepareArgs; } export interface WatchPiralBundlerDefinition extends BaseBundlerDefinition { } export interface DebugPiralBundlerDefinition extends BaseBundlerDefinition { flags?: ToolCommandFlagsSetter; } export interface BuildPiralBundlerDefinition extends BaseBundlerDefinition { flags?: ToolCommandFlagsSetter; } export interface DebugPiletBundlerDefinition extends BaseBundlerDefinition { flags?: ToolCommandFlagsSetter; } export interface BuildPiletBundlerDefinition extends BaseBundlerDefinition { flags?: ToolCommandFlagsSetter; } export interface PiralBuildHandler { create(config: { root: string; entryFiles: string; outDir: string; outFile: string; externals: Array; emulator: boolean; sourceMaps: boolean; contentHash: boolean; minify: boolean; publicUrl: string; hmr: boolean; logLevel: LogLevels; watch: boolean; args: any; }): Promise; } export interface PiletBuildHandler { create(config: { root: string; piralInstances: Array; entryModule: string; targetDir: string; outDir: string; outFile: string; externals: Array; importmap: Array; version: PiletSchemaVersion; develop: boolean; sourceMaps: boolean; contentHash: boolean; minify: boolean; logLevel: LogLevels; watch: boolean; args: any; }): Promise; } export interface BundleResult { outDir: string; outFile: string; hash?: string; name?: string; requireRef?: string; } export interface BundleHandlerResponse { onStart(cb: () => void): void; onEnd(cb: (result: BundleResult) => void): void; bundle(): Promise; } export interface BundlerDefinition { debugPiral: DebugPiralBundlerDefinition; watchPiral: WatchPiralBundlerDefinition; buildPiral: BuildPiralBundlerDefinition; debugPilet: DebugPiletBundlerDefinition; buildPilet: BuildPiletBundlerDefinition; } export type ImportmapVersions = 'all' | 'match-major' | 'any-patch' | 'exact'; export type ImportmapMode = 'host' | 'remote'; export type PiletSchemaVersion = 'none' | 'v0' | 'v1' | 'v2' | 'v3' | 'mf'; export interface HeaderAuthConfig { mode: 'header'; key: string; value: string; } export interface HttpAuthConfig { mode: 'http'; username: string; password: string; } export type AuthConfig = HeaderAuthConfig | HttpAuthConfig; export type SourceLanguage = 'js' | 'ts'; export type PublishScheme = 'none' | 'digest' | 'bearer' | 'basic'; export type PiletPublishSource = 'local' | 'npm' | 'remote'; export type PiralBuildType = 'all' | 'release' | 'emulator' | 'emulator-package' | 'emulator-sources' | 'emulator-website'; export type PiralPublishType = 'release' | 'emulator'; export type PiletBuildType = 'default' | 'standalone' | 'manifest'; export type PackageType = 'registry' | 'monorepo' | 'file' | 'git' | 'remote'; export type NpmDirectClientType = 'npm' | 'yarn' | 'pnp' | 'pnpm' | 'bun'; export type NpmWapperClientType = 'lerna' | 'rush'; export type NpmClientType = NpmDirectClientType | NpmWapperClientType; export type Framework = 'piral' | 'piral-core' | 'piral-base'; export interface StandardEnvProps { production?: boolean; debugPiral?: boolean; debugPilet?: boolean; root: string; publicPath?: string; piralInstances?: Array; dependencies?: Array; }