UNPKG

@iobroker/create-adapter

Version:

Command line utility to create customized ioBroker adapters

375 lines (374 loc) 7.48 kB
import type { SpecificPromptOptions } from "enquirer"; import type { CheckResult } from "./actionsAndTransformers"; import type { LicenseType } from "./licenses"; import type { MigrationContextBase } from "./migrationContextBase"; declare const __misused: unique symbol; type QuestionAction<T> = (value: T, options?: unknown) => CheckResult | Promise<CheckResult>; export type AnswerValue = string | boolean | number; export type Condition = { /** * */ name: string; } & ({ /** * */ value: AnswerValue | AnswerValue[]; } | { /** * */ contains: AnswerValue; } | { /** * */ doesNotContain: AnswerValue; } | { /** * */ [__misused]: undefined; }); /** * * @param condition * @param answers */ export declare function testCondition(condition: Condition | Condition[] | undefined, answers: Record<string, any>): boolean; export type MigrateFunc = (context: MigrationContextBase, answers: Record<string, any>, question: Question) => Promise<AnswerValue | AnswerValue[] | undefined> | AnswerValue | AnswerValue[] | undefined; export type TransformResult = (val: AnswerValue | AnswerValue[]) => AnswerValue | AnswerValue[] | undefined | Promise<AnswerValue | AnswerValue[] | undefined>; /** * */ export interface QuestionMeta { /** * */ label: string; /** One or more conditions that need(s) to be fulfilled for this question to be asked */ condition?: Condition | Condition[]; /** * */ replay?: (answers: Record<string, any>) => void; /** * */ migrate?: MigrateFunc; /** * */ resultTransform?: TransformResult; /** * */ action?: QuestionAction<undefined | AnswerValue | AnswerValue[]>; /** Whether an answer for this question is optional */ optional?: boolean; /** * Whether this question should only be asked in expert mode. * In non-expert mode, the initial answer will be used. */ expert?: true; } export type Question = SpecificPromptOptions & QuestionMeta; /** * */ export interface QuestionGroup { /** * */ title: string; /** * */ headline: string; /** * */ questions: Question[]; } /** All questions and the corresponding text lines */ export declare const questionGroups: QuestionGroup[]; /** Only the questions */ export declare const questions: Question[]; /** * */ export interface BaseAdapterSettings<T> { /** * */ key: string; /** * */ label?: string; /** * */ defaultValue?: T; } /** * */ export interface StringAdapterSettings extends BaseAdapterSettings<string> { /** * */ inputType: "text"; } /** * */ export interface NumberAdapterSettings extends BaseAdapterSettings<number> { /** * */ inputType: "number"; } /** * */ export interface BooleanAdapterSettings extends BaseAdapterSettings<boolean> { /** * */ inputType: "checkbox"; } /** * */ export interface AdapterSelectOption { /** * */ value: string; /** * */ text: string; } /** * */ export interface SelectAdapterSettings extends BaseAdapterSettings<string> { /** * */ inputType: "select"; /** * */ options: AdapterSelectOption[]; } export type AdapterSettings = StringAdapterSettings | NumberAdapterSettings | BooleanAdapterSettings | SelectAdapterSettings; /** * An icon in binary or base64-encoded format. */ export interface UploadedIcon { /** The data icon in binary or base64-encoded format. */ data: string | Buffer; /** The file extension to use with the icon. */ extension: string; } /** * License information */ export interface LicenseInformation { /** Use 'paid' for adapters which do not work without a paid license. Use 'commercial' for adapters which require a license for commercial use only. Use 'limited' if some functionalities are not available without a paid license. */ type: "free" | "paid" | "commercial" | "limited"; /** Hyperlink, where information about the license can be found. This is required if the license type is different from 'free'. */ link?: string; /** The license this software is published under. */ license?: LicenseType; } /** * */ export interface Answers { /** false is used in the portal */ cli: boolean; /** "github" and "zip" are used in the portal */ target: "directory" | "github" | "zip"; /** * */ adapterName: string; /** * */ description?: string; /** * */ keywords?: string[]; /** * */ expert?: "yes" | "no"; /** * */ authorName: string; /** * */ authorEmail: string; /** * */ authorGithub: string; /** * */ contributors?: string[]; /** * */ language?: "JavaScript" | "TypeScript" | "TypeScript (without build)"; /** * */ features: ("adapter" | "vis")[]; /** * */ adminFeatures?: ("tab" | "custom")[]; /** * */ tools?: ("ESLint" | "Prettier" | "type checking" | "code coverage" | "devcontainer")[]; /** * */ eslintConfig?: "official" | "custom"; /** * */ nodeVersion?: "20" | "22" | "24"; /** * */ title?: string; /** * */ license?: string; /** * */ licenseInformation?: LicenseInformation; /** * */ type: string; /** * */ widgetIsMainFunction?: "main" | "additional"; /** * */ adminUi?: "json" | "html" | "react" | "none"; /** * */ tabReact?: "yes" | "no"; /** * */ i18n?: "words.js" | "JSON"; /** * */ releaseScript?: "yes" | "no"; /** * */ devServer?: "global" | "local" | "no"; /** * */ devServerPort?: number; /** * */ indentation?: "Tab" | "Space (4)"; /** * */ quotes?: "single" | "double"; /** * */ gitRemoteProtocol: "HTTPS" | "SSH"; /** * */ gitCommit?: "yes" | "no"; /** * */ defaultBranch?: "main" | "master"; /** * */ dependabot?: "yes" | "no"; /** * */ startMode?: "daemon" | "schedule" | "once" | "none"; /** * */ scheduleStartOnChange?: "yes" | "no"; /** * */ connectionIndicator?: "yes" | "no"; /** * */ connectionType?: "cloud" | "local"; /** * */ dataSource?: "poll" | "push" | "assumption"; /** * */ icon?: UploadedIcon; /** An array of predefined adapter options */ adapterSettings?: AdapterSettings[]; } /** * * @param answers */ export declare function checkAnswers(answers: Partial<Answers>): void; /** * * @param answers */ export declare function formatAnswers(answers: Record<string, any>): Promise<Record<string, any>>; /** * * @param answers * @param disableValidation */ export declare function validateAnswers(answers: Answers, disableValidation?: (keyof Answers)[]): Promise<void>; /** * * @param key */ export declare function getDefaultAnswer<T extends keyof Answers>(key: T): Answers[T] | undefined; /** * * @param answers */ export declare function getIconName(answers: Answers): string; export {};