@scriptables/manifest
Version:
Utilities to generate, parse, and update manifest headers in Scriptable scripts.
60 lines (50 loc) • 1.78 kB
text/typescript
// Helper type utilities
type CamelToKebab<S extends string> = S extends `${infer T}${infer U}`
? `${T extends Capitalize<T> ? `-${Lowercase<T>}` : T}${CamelToKebab<U>}`
: S;
type CamelToSnake<S extends string> = S extends `${infer T}${infer U}`
? `${T extends Capitalize<T> ? `_${Lowercase<T>}` : T}${CamelToSnake<U>}`
: S;
type KeysToCaseVariants<T> = {
[K in keyof T as K extends string ? K | CamelToKebab<K> | CamelToSnake<K> : K]: T[K];
};
export type ScriptableShareSheetInputs = Array<'file-url' | 'url' | 'image' | 'plain-text'>;
/**
* Base manifest type with camelCase keys
*/
export interface ScriptableManifest {
name?: string;
alwaysRunInApp?: boolean;
shareSheetInputs?: ScriptableShareSheetInputs;
iconColor?: string;
iconGlyph?: string;
}
/**
* Extended manifest type supporting all naming conventions
*/
export type CompatibleScriptableManifest = KeysToCaseVariants<ScriptableManifest>;
/**
* All valid key names for the Scriptable manifest (camel format)
*/
export const SCRIPTABLE_MANIFEST_KEYS = [
'name',
'alwaysRunInApp',
'shareSheetInputs',
'iconColor',
'iconGlyph',
] as const;
/**
* All valid key names for the Scriptable manifest (for banner formatting)
*/
export const SCRIPTABLE_BANNER_KEYS = ['always-run-in-app', 'share-sheet-inputs', 'icon-color', 'icon-glyph'] as const;
export type ScriptableManifestKey = (typeof SCRIPTABLE_MANIFEST_KEYS)[number];
export type ScriptableBannerKey = (typeof SCRIPTABLE_BANNER_KEYS)[number];
/**
* Banner format, keeping the hyphen format in order to conform to the Scriptable specification
*/
export interface ScriptableBannerManifest {
'always-run-in-app'?: boolean | string;
'share-sheet-inputs'?: string;
'icon-color'?: string;
'icon-glyph'?: string;
}