UNPKG

@tywalk/pcf-helper

Version:

Command line helper for building and publishing PCF controls to Dataverse.

110 lines (109 loc) 4.36 kB
/** * Session-specific config values. These mirror the fields supported by the * legacy session.config.json so that callers have a single shape to consume. */ export interface SessionConfig { remoteEnvironmentUrl?: string; remoteScriptToIntercept?: string; remoteStylesheetToIntercept?: string; localCssPath?: string; localBundlePath?: string; startWatch?: boolean; watchRetry?: boolean; } /** * A named bundle of defaults that can feed build/deploy/import/upgrade/init and * (optionally) session. Any field may be omitted; fields left blank fall back * to the enclosing config or CLI-provided values. */ export interface Profile { environment?: string; path?: string; publisherName?: string; publisherPrefix?: string; template?: string; framework?: string; /** Optional session overrides specific to this profile. Layers over the * top-level `session` block in the same file. */ session?: SessionConfig; } /** * The on-disk shape of pcf-helper.config.json (and ~/.pcf-helper/config.json). */ export interface PcfHelperConfig { /** Name of the profile to use when --profile is not passed on the CLI. */ defaultProfile?: string; profiles?: Record<string, Profile>; /** Shared session settings used by the session command. */ session?: SessionConfig; } export interface LoadedConfig { /** * Merged config where project values override global values field-by-field * and profile maps are merged by name (project profile of the same name * wins). This is the only object callers should read from. */ merged: PcfHelperConfig; projectPath: string; globalPath: string; /** Ordered list of files that actually existed and contributed values. */ sources: string[]; } export declare function getGlobalConfigPath(): string; export declare function getProjectConfigPath(cwd?: string): string; /** * Loads the global then project pcf-helper configs and returns a merged view. * Project-level values override global values. Profiles from both files are * merged by name (project wins on collision). * * Missing files are treated as empty objects. Malformed JSON produces a * warning and is also treated as empty. */ export declare function loadPcfHelperConfig(cwd?: string): LoadedConfig; /** * Resolves the profile to use: explicit --profile flag wins, else * `defaultProfile`, else undefined. * * Throws a clear error if a profile name is resolved but the config has no * matching entry. */ export declare function resolveProfile(requestedName: string | undefined, merged: PcfHelperConfig): { name?: string; profile?: Profile; }; /** * Layers session config values highest-wins. Undefined values in later layers * do not overwrite defined values in earlier layers — pass layers from * lowest-precedence to highest-precedence. */ export declare function mergeSessionConfig(...layers: (SessionConfig | undefined)[]): SessionConfig; /** * Options for writing a new or updated profile to a pcf-helper config file. */ export interface WriteProfileOptions { /** If true, write to the global config (~/.pcf-helper/config.json). Default: project-level. */ global?: boolean; /** If true, also set `defaultProfile: <name>` in the target file. */ setDefault?: boolean; /** If true, overwrite an existing profile of the same name. If false (default) and the name already exists, throws. */ force?: boolean; /** Override the working directory (for project-level writes). Mainly useful in tests. */ cwd?: string; } export interface WriteProfileResult { /** Absolute path of the file that was written. */ filePath: string; /** True if the target file did not exist before this call. */ createdFile: boolean; /** True if an existing profile of the same name was replaced. */ replacedProfile: boolean; } /** * Writes a profile into the target pcf-helper config file, merging with any * existing content. Creates the parent directory and the file itself if * neither exists. Writes atomically (temp + rename) so a failed mid-write * cannot corrupt the config. * * Throws if the profile name already exists and `force` is not set. */ export declare function writeProfile(name: string, profile: Profile, options?: WriteProfileOptions): WriteProfileResult;