@synaptic-simulations/mach
Version:
The last MSFS instrument bundler you'll ever need.
163 lines (162 loc) • 6.62 kB
TypeScript
import type { BuildOptions, BuildResult, LogLevel, Plugin } from "esbuild";
import { z } from "zod";
export type BuildResultWithMeta = BuildResult<{
metafile: true;
}>;
interface PackageSettings {
/**
* Specifies type of instrument.
* - `React` instruments will be created with a `BaseInstrument` harness that exposes an `MSFS_REACT_MOUNT` element for mounting.
* - `BaseInstrument` instruments must specify the `instrumentId` and `mountElementId` to match the instrument configuration.
*/
type: string;
/** Final template filename. Defaults to `instrument`. */
fileName?: string;
/** Simulator packages to import in the HTML template. */
imports?: string[];
/** Paths to custom HTML template files */
htmlTemplate?: string;
}
interface ReactInstrumentPackageSettings extends PackageSettings {
type: "react";
/** Optional parameter to specify template ID. Defaults to `Instrument.name`. */
templateId?: string;
/** Whether the instrument is interactive or not. Defaults to `true`. */
isInteractive?: boolean;
/** Paths to custom JavaScript template files */
jsTemplate?: string;
}
interface BaseInstrumentPackageSettings extends PackageSettings {
type: "baseInstrument";
/**
* Required for `BaseInstrument` instruments.
* This value must match the return value from the `BaseInstrument.templateID()` function.
* */
templateId: string;
/**
* Required for `BaseInstrument` instruments.
* This value must match the ID in your call to `FSComponent.render()`..
*/
mountElementId: string;
}
export interface Instrument {
/** Instrument name, used as directory name for bundles and packages. */
name: string;
/** Entrypoint filename for instrument. */
index: string;
/** When passed a configuration object, enables a simulator package export. */
simulatorPackage?: ReactInstrumentPackageSettings | BaseInstrumentPackageSettings;
/** Instruments to import as ESM modules. */
modules?: Instrument[];
/** (Required for instruments included as `modules`) Import name to resolve to the bundled module. */
resolve?: string;
}
export interface MachConfig {
/** Name of package, used for bundling simulator packages. */
packageName: string;
/** Path to directory containing `html_ui`. */
packageDir: string;
/**
* esbuild configuration overrides (<https://esbuild.github.io/api/>)
* `entryPoints`, `outfile`, `format`, `metafile`, and `bundle` are not overridable.
*/
esbuild?: BuildOptions;
/** All instruments to be bundled by Mach. */
instruments: Instrument[];
}
export interface MachArgs {
/** Build configuration. */
config: MachConfig;
/** Path to bundle output directory. Defaults to `./bundles` */
bundles?: string;
/** Treat all ESBuild warnings as errors. */
werror?: boolean;
/** Instrument names to include. */
filter?: RegExp;
/** Minify bundled code. */
minify?: boolean;
/** Output additional build debug info. */
verbose?: boolean;
/** Output `build_meta.json` file to bundle directory. */
outputMetafile?: boolean;
/** Generate source maps. */
sourcemaps?: "linked" | "external" | "inline" | "both";
/** Skip writing simulator package files. */
skipSimulatorPackage?: boolean;
}
export declare const PluginSchema: z.ZodType<Plugin>;
export declare const InstrumentSchema: z.ZodType<Instrument>;
export declare const MachConfigSchema: z.ZodObject<{
packageName: z.ZodString;
packageDir: z.ZodString;
esbuild: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
instruments: z.ZodArray<z.ZodType<Instrument, z.ZodTypeDef, Instrument>, "many">;
}, "strip", z.ZodTypeAny, {
packageName: string;
packageDir: string;
instruments: Instrument[];
esbuild?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
}, {
packageName: string;
packageDir: string;
instruments: Instrument[];
esbuild?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
}>;
export declare const MachArgsSchema: z.ZodObject<{
config: z.ZodObject<{
packageName: z.ZodString;
packageDir: z.ZodString;
esbuild: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
instruments: z.ZodArray<z.ZodType<Instrument, z.ZodTypeDef, Instrument>, "many">;
}, "strip", z.ZodTypeAny, {
packageName: string;
packageDir: string;
instruments: Instrument[];
esbuild?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
}, {
packageName: string;
packageDir: string;
instruments: Instrument[];
esbuild?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
}>;
bundles: z.ZodOptional<z.ZodString>;
werror: z.ZodOptional<z.ZodBoolean>;
filter: z.ZodOptional<z.ZodType<RegExp, z.ZodTypeDef, RegExp>>;
minify: z.ZodOptional<z.ZodBoolean>;
verbose: z.ZodOptional<z.ZodBoolean>;
outputMetafile: z.ZodOptional<z.ZodBoolean>;
sourcemaps: z.ZodOptional<z.ZodEnum<["linked", "external", "inline", "both"]>>;
skipSimulatorPackage: z.ZodOptional<z.ZodBoolean>;
}, "strip", z.ZodTypeAny, {
config: {
packageName: string;
packageDir: string;
instruments: Instrument[];
esbuild?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
};
filter?: RegExp | undefined;
bundles?: string | undefined;
werror?: boolean | undefined;
minify?: boolean | undefined;
verbose?: boolean | undefined;
outputMetafile?: boolean | undefined;
sourcemaps?: "linked" | "external" | "inline" | "both" | undefined;
skipSimulatorPackage?: boolean | undefined;
}, {
config: {
packageName: string;
packageDir: string;
instruments: Instrument[];
esbuild?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
};
filter?: RegExp | undefined;
bundles?: string | undefined;
werror?: boolean | undefined;
minify?: boolean | undefined;
verbose?: boolean | undefined;
outputMetafile?: boolean | undefined;
sourcemaps?: "linked" | "external" | "inline" | "both" | undefined;
skipSimulatorPackage?: boolean | undefined;
}>;
export declare const ESBUILD_ERRORS: Record<string, LogLevel>;
export {};